1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.SINGLE_DOT_PATH_SEGMENT = exports.MODULE_TYPE = exports.AUTO_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = void 0;
|
7 | exports.compareModulesByIdentifier = compareModulesByIdentifier;
|
8 | exports.evalModuleCode = evalModuleCode;
|
9 | exports.findModuleById = findModuleById;
|
10 | exports.getUndoPath = getUndoPath;
|
11 | exports.stringifyRequest = stringifyRequest;
|
12 | exports.trueFn = trueFn;
|
13 |
|
14 | var _module = _interopRequireDefault(require("module"));
|
15 |
|
16 | var _path = _interopRequireDefault(require("path"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | function trueFn() {
|
21 | return true;
|
22 | }
|
23 |
|
24 | function findModuleById(compilation, id) {
|
25 | const {
|
26 | modules,
|
27 | chunkGraph
|
28 | } = compilation;
|
29 |
|
30 | for (const module of modules) {
|
31 | const moduleId = typeof chunkGraph !== "undefined" ? chunkGraph.getModuleId(module) : module.id;
|
32 |
|
33 | if (moduleId === id) {
|
34 | return module;
|
35 | }
|
36 | }
|
37 |
|
38 | return null;
|
39 | }
|
40 |
|
41 | function evalModuleCode(loaderContext, code, filename) {
|
42 | const module = new _module.default(filename, loaderContext);
|
43 | module.paths = _module.default._nodeModulePaths(loaderContext.context);
|
44 |
|
45 | module.filename = filename;
|
46 |
|
47 | module._compile(code, filename);
|
48 |
|
49 |
|
50 | return module.exports;
|
51 | }
|
52 |
|
53 | function compareIds(a, b) {
|
54 | if (typeof a !== typeof b) {
|
55 | return typeof a < typeof b ? -1 : 1;
|
56 | }
|
57 |
|
58 | if (a < b) {
|
59 | return -1;
|
60 | }
|
61 |
|
62 | if (a > b) {
|
63 | return 1;
|
64 | }
|
65 |
|
66 | return 0;
|
67 | }
|
68 |
|
69 | function compareModulesByIdentifier(a, b) {
|
70 | return compareIds(a.identifier(), b.identifier());
|
71 | }
|
72 |
|
73 | const MODULE_TYPE = "css/mini-extract";
|
74 | exports.MODULE_TYPE = MODULE_TYPE;
|
75 | const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
|
76 | exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
|
77 | const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/";
|
78 | exports.ABSOLUTE_PUBLIC_PATH = ABSOLUTE_PUBLIC_PATH;
|
79 | const SINGLE_DOT_PATH_SEGMENT = "__mini_css_extract_plugin_single_dot_path_segment__";
|
80 | exports.SINGLE_DOT_PATH_SEGMENT = SINGLE_DOT_PATH_SEGMENT;
|
81 |
|
82 | function isAbsolutePath(str) {
|
83 | return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
84 | }
|
85 |
|
86 | const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
|
87 |
|
88 | function isRelativePath(str) {
|
89 | return RELATIVE_PATH_REGEXP.test(str);
|
90 | }
|
91 |
|
92 |
|
93 | function stringifyRequest(loaderContext, request) {
|
94 | if (typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function") {
|
95 | return JSON.stringify(loaderContext.utils.contextify(loaderContext.context || loaderContext.rootContext, request));
|
96 | }
|
97 |
|
98 | const splitted = request.split("!");
|
99 | const {
|
100 | context
|
101 | } = loaderContext;
|
102 | return JSON.stringify(splitted.map(part => {
|
103 |
|
104 | const splittedPart = part.match(/^(.*?)(\?.*)/);
|
105 | const query = splittedPart ? splittedPart[2] : "";
|
106 | let singlePath = splittedPart ? splittedPart[1] : part;
|
107 |
|
108 | if (isAbsolutePath(singlePath) && context) {
|
109 | singlePath = _path.default.relative(context, singlePath);
|
110 |
|
111 | if (isAbsolutePath(singlePath)) {
|
112 |
|
113 |
|
114 |
|
115 | return singlePath + query;
|
116 | }
|
117 |
|
118 | if (isRelativePath(singlePath) === false) {
|
119 |
|
120 | singlePath = `./${singlePath}`;
|
121 | }
|
122 | }
|
123 |
|
124 | return singlePath.replace(/\\/g, "/") + query;
|
125 | }).join("!"));
|
126 | }
|
127 |
|
128 | function getUndoPath(filename, outputPath, enforceRelative) {
|
129 | let depth = -1;
|
130 | let append = "";
|
131 |
|
132 | outputPath = outputPath.replace(/[\\/]$/, "");
|
133 |
|
134 | for (const part of filename.split(/[/\\]+/)) {
|
135 | if (part === "..") {
|
136 | if (depth > -1) {
|
137 |
|
138 | depth--;
|
139 | } else {
|
140 | const i = outputPath.lastIndexOf("/");
|
141 | const j = outputPath.lastIndexOf("\\");
|
142 | const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
|
143 |
|
144 | if (pos < 0) {
|
145 | return `${outputPath}/`;
|
146 | }
|
147 |
|
148 | append = `${outputPath.slice(pos + 1)}/${append}`;
|
149 |
|
150 | outputPath = outputPath.slice(0, pos);
|
151 | }
|
152 | } else if (part !== ".") {
|
153 |
|
154 | depth++;
|
155 | }
|
156 | }
|
157 |
|
158 | return depth > 0 ? `${"../".repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
|
159 | } |
\ | No newline at end of file |