source: trip-planner-front/node_modules/mini-css-extract-plugin/dist/utils.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.trueFn = trueFn;
7exports.findModuleById = findModuleById;
8exports.evalModuleCode = evalModuleCode;
9exports.compareModulesByIdentifier = compareModulesByIdentifier;
10exports.stringifyRequest = stringifyRequest;
11exports.AUTO_PUBLIC_PATH = exports.MODULE_TYPE = void 0;
12
13var _module = _interopRequireDefault(require("module"));
14
15var _path = _interopRequireDefault(require("path"));
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19function trueFn() {
20 return true;
21}
22
23function findModuleById(compilation, id) {
24 const {
25 modules,
26 chunkGraph
27 } = compilation;
28
29 for (const module of modules) {
30 const moduleId = typeof chunkGraph !== "undefined" ? chunkGraph.getModuleId(module) : module.id;
31
32 if (moduleId === id) {
33 return module;
34 }
35 }
36
37 return null;
38}
39
40function evalModuleCode(loaderContext, code, filename) {
41 const module = new _module.default(filename, loaderContext);
42 module.paths = _module.default._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
43
44 module.filename = filename;
45
46 module._compile(code, filename); // eslint-disable-line no-underscore-dangle
47
48
49 return module.exports;
50}
51
52function compareIds(a, b) {
53 if (typeof a !== typeof b) {
54 return typeof a < typeof b ? -1 : 1;
55 }
56
57 if (a < b) {
58 return -1;
59 }
60
61 if (a > b) {
62 return 1;
63 }
64
65 return 0;
66}
67
68function compareModulesByIdentifier(a, b) {
69 return compareIds(a.identifier(), b.identifier());
70}
71
72const MODULE_TYPE = "css/mini-extract";
73exports.MODULE_TYPE = MODULE_TYPE;
74const AUTO_PUBLIC_PATH = "__MINI_CSS_EXTRACT_PLUGIN_PUBLIC_PATH__";
75exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
76
77function isAbsolutePath(str) {
78 return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
79}
80
81const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
82
83function isRelativePath(str) {
84 return RELATIVE_PATH_REGEXP.test(str);
85}
86
87function stringifyRequest(loaderContext, request) {
88 const splitted = request.split("!");
89 const {
90 context
91 } = loaderContext;
92 return JSON.stringify(splitted.map(part => {
93 // First, separate singlePath from query, because the query might contain paths again
94 const splittedPart = part.match(/^(.*?)(\?.*)/);
95 const query = splittedPart ? splittedPart[2] : "";
96 let singlePath = splittedPart ? splittedPart[1] : part;
97
98 if (isAbsolutePath(singlePath) && context) {
99 singlePath = _path.default.relative(context, singlePath);
100
101 if (isAbsolutePath(singlePath)) {
102 // If singlePath still matches an absolute path, singlePath was on a different drive than context.
103 // In this case, we leave the path platform-specific without replacing any separators.
104 // @see https://github.com/webpack/loader-utils/pull/14
105 return singlePath + query;
106 }
107
108 if (isRelativePath(singlePath) === false) {
109 // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
110 singlePath = `./${singlePath}`;
111 }
112 }
113
114 return singlePath.replace(/\\/g, "/") + query;
115 }).join("!"));
116}
Note: See TracBrowser for help on using the repository browser.