1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.normalizeOptions = normalizeOptions;
|
---|
7 | exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
|
---|
8 | exports.shouldUseImportPlugin = shouldUseImportPlugin;
|
---|
9 | exports.shouldUseURLPlugin = shouldUseURLPlugin;
|
---|
10 | exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
|
---|
11 | exports.normalizeUrl = normalizeUrl;
|
---|
12 | exports.requestify = requestify;
|
---|
13 | exports.getFilter = getFilter;
|
---|
14 | exports.getModulesOptions = getModulesOptions;
|
---|
15 | exports.getModulesPlugins = getModulesPlugins;
|
---|
16 | exports.normalizeSourceMap = normalizeSourceMap;
|
---|
17 | exports.getPreRequester = getPreRequester;
|
---|
18 | exports.getImportCode = getImportCode;
|
---|
19 | exports.getModuleCode = getModuleCode;
|
---|
20 | exports.getExportCode = getExportCode;
|
---|
21 | exports.resolveRequests = resolveRequests;
|
---|
22 | exports.isUrlRequestable = isUrlRequestable;
|
---|
23 | exports.sort = sort;
|
---|
24 | exports.combineRequests = combineRequests;
|
---|
25 | exports.camelCase = camelCase;
|
---|
26 | exports.stringifyRequest = stringifyRequest;
|
---|
27 | exports.isDataUrl = isDataUrl;
|
---|
28 | exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
|
---|
29 |
|
---|
30 | var _url = require("url");
|
---|
31 |
|
---|
32 | var _path = _interopRequireDefault(require("path"));
|
---|
33 |
|
---|
34 | var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
|
---|
35 |
|
---|
36 | var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
|
---|
37 |
|
---|
38 | var _postcssModulesExtractImports = _interopRequireDefault(require("postcss-modules-extract-imports"));
|
---|
39 |
|
---|
40 | var _postcssModulesScope = _interopRequireDefault(require("postcss-modules-scope"));
|
---|
41 |
|
---|
42 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
43 |
|
---|
44 | /*
|
---|
45 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
46 | Author Tobias Koppers @sokra
|
---|
47 | */
|
---|
48 | const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
|
---|
49 | exports.WEBPACK_IGNORE_COMMENT_REGEXP = WEBPACK_IGNORE_COMMENT_REGEXP;
|
---|
50 | const matchRelativePath = /^\.\.?[/\\]/;
|
---|
51 |
|
---|
52 | function isAbsolutePath(str) {
|
---|
53 | return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
---|
54 | }
|
---|
55 |
|
---|
56 | function isRelativePath(str) {
|
---|
57 | return matchRelativePath.test(str);
|
---|
58 | }
|
---|
59 |
|
---|
60 | function stringifyRequest(loaderContext, request) {
|
---|
61 | const splitted = request.split("!");
|
---|
62 | const {
|
---|
63 | context
|
---|
64 | } = loaderContext;
|
---|
65 | return JSON.stringify(splitted.map(part => {
|
---|
66 | // First, separate singlePath from query, because the query might contain paths again
|
---|
67 | const splittedPart = part.match(/^(.*?)(\?.*)/);
|
---|
68 | const query = splittedPart ? splittedPart[2] : "";
|
---|
69 | let singlePath = splittedPart ? splittedPart[1] : part;
|
---|
70 |
|
---|
71 | if (isAbsolutePath(singlePath) && context) {
|
---|
72 | singlePath = _path.default.relative(context, singlePath);
|
---|
73 |
|
---|
74 | if (isAbsolutePath(singlePath)) {
|
---|
75 | // If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
---|
76 | // In this case, we leave the path platform-specific without replacing any separators.
|
---|
77 | // @see https://github.com/webpack/loader-utils/pull/14
|
---|
78 | return singlePath + query;
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (isRelativePath(singlePath) === false) {
|
---|
82 | // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
---|
83 | singlePath = `./${singlePath}`;
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | return singlePath.replace(/\\/g, "/") + query;
|
---|
88 | }).join("!"));
|
---|
89 | } // We can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
|
---|
90 |
|
---|
91 |
|
---|
92 | const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
---|
93 | const IS_MODULE_REQUEST = /^[^?]*~/;
|
---|
94 |
|
---|
95 | function urlToRequest(url, root) {
|
---|
96 | let request;
|
---|
97 |
|
---|
98 | if (IS_NATIVE_WIN32_PATH.test(url)) {
|
---|
99 | // absolute windows path, keep it
|
---|
100 | request = url;
|
---|
101 | } else if (typeof root !== "undefined" && /^\//.test(url)) {
|
---|
102 | request = root + url;
|
---|
103 | } else if (/^\.\.?\//.test(url)) {
|
---|
104 | // A relative url stays
|
---|
105 | request = url;
|
---|
106 | } else {
|
---|
107 | // every other url is threaded like a relative url
|
---|
108 | request = `./${url}`;
|
---|
109 | } // A `~` makes the url an module
|
---|
110 |
|
---|
111 |
|
---|
112 | if (IS_MODULE_REQUEST.test(request)) {
|
---|
113 | request = request.replace(IS_MODULE_REQUEST, "");
|
---|
114 | }
|
---|
115 |
|
---|
116 | return request;
|
---|
117 | } // eslint-disable-next-line no-useless-escape
|
---|
118 |
|
---|
119 |
|
---|
120 | const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
|
---|
121 | const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
---|
122 |
|
---|
123 | const preserveCamelCase = string => {
|
---|
124 | let result = string;
|
---|
125 | let isLastCharLower = false;
|
---|
126 | let isLastCharUpper = false;
|
---|
127 | let isLastLastCharUpper = false;
|
---|
128 |
|
---|
129 | for (let i = 0; i < result.length; i++) {
|
---|
130 | const character = result[i];
|
---|
131 |
|
---|
132 | if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
---|
133 | result = `${result.slice(0, i)}-${result.slice(i)}`;
|
---|
134 | isLastCharLower = false;
|
---|
135 | isLastLastCharUpper = isLastCharUpper;
|
---|
136 | isLastCharUpper = true;
|
---|
137 | i += 1;
|
---|
138 | } else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
|
---|
139 | result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
|
---|
140 | isLastLastCharUpper = isLastCharUpper;
|
---|
141 | isLastCharUpper = false;
|
---|
142 | isLastCharLower = true;
|
---|
143 | } else {
|
---|
144 | isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
|
---|
145 | isLastLastCharUpper = isLastCharUpper;
|
---|
146 | isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | return result;
|
---|
151 | };
|
---|
152 |
|
---|
153 | function camelCase(input) {
|
---|
154 | let result = input.trim();
|
---|
155 |
|
---|
156 | if (result.length === 0) {
|
---|
157 | return "";
|
---|
158 | }
|
---|
159 |
|
---|
160 | if (result.length === 1) {
|
---|
161 | return result.toLowerCase();
|
---|
162 | }
|
---|
163 |
|
---|
164 | const hasUpperCase = result !== result.toLowerCase();
|
---|
165 |
|
---|
166 | if (hasUpperCase) {
|
---|
167 | result = preserveCamelCase(result);
|
---|
168 | }
|
---|
169 |
|
---|
170 | return result.replace(/^[_.\- ]+/, "").toLowerCase().replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase()).replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
|
---|
171 | }
|
---|
172 |
|
---|
173 | function escape(string) {
|
---|
174 | let output = "";
|
---|
175 | let counter = 0;
|
---|
176 |
|
---|
177 | while (counter < string.length) {
|
---|
178 | // eslint-disable-next-line no-plusplus
|
---|
179 | const character = string.charAt(counter++);
|
---|
180 | let value; // eslint-disable-next-line no-control-regex
|
---|
181 |
|
---|
182 | if (/[\t\n\f\r\x0B]/.test(character)) {
|
---|
183 | const codePoint = character.charCodeAt();
|
---|
184 | value = `\\${codePoint.toString(16).toUpperCase()} `;
|
---|
185 | } else if (character === "\\" || regexSingleEscape.test(character)) {
|
---|
186 | value = `\\${character}`;
|
---|
187 | } else {
|
---|
188 | value = character;
|
---|
189 | }
|
---|
190 |
|
---|
191 | output += value;
|
---|
192 | }
|
---|
193 |
|
---|
194 | const firstChar = string.charAt(0);
|
---|
195 |
|
---|
196 | if (/^-[-\d]/.test(output)) {
|
---|
197 | output = `\\-${output.slice(1)}`;
|
---|
198 | } else if (/\d/.test(firstChar)) {
|
---|
199 | output = `\\3${firstChar} ${output.slice(1)}`;
|
---|
200 | } // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
|
---|
201 | // since they’re redundant. Note that this is only possible if the escape
|
---|
202 | // sequence isn’t preceded by an odd number of backslashes.
|
---|
203 |
|
---|
204 |
|
---|
205 | output = output.replace(regexExcessiveSpaces, ($0, $1, $2) => {
|
---|
206 | if ($1 && $1.length % 2) {
|
---|
207 | // It’s not safe to remove the space, so don’t.
|
---|
208 | return $0;
|
---|
209 | } // Strip the space.
|
---|
210 |
|
---|
211 |
|
---|
212 | return ($1 || "") + $2;
|
---|
213 | });
|
---|
214 | return output;
|
---|
215 | }
|
---|
216 |
|
---|
217 | function gobbleHex(str) {
|
---|
218 | const lower = str.toLowerCase();
|
---|
219 | let hex = "";
|
---|
220 | let spaceTerminated = false; // eslint-disable-next-line no-undefined
|
---|
221 |
|
---|
222 | for (let i = 0; i < 6 && lower[i] !== undefined; i++) {
|
---|
223 | const code = lower.charCodeAt(i); // check to see if we are dealing with a valid hex char [a-f|0-9]
|
---|
224 |
|
---|
225 | const valid = code >= 97 && code <= 102 || code >= 48 && code <= 57; // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
|
---|
226 |
|
---|
227 | spaceTerminated = code === 32;
|
---|
228 |
|
---|
229 | if (!valid) {
|
---|
230 | break;
|
---|
231 | }
|
---|
232 |
|
---|
233 | hex += lower[i];
|
---|
234 | }
|
---|
235 |
|
---|
236 | if (hex.length === 0) {
|
---|
237 | // eslint-disable-next-line no-undefined
|
---|
238 | return undefined;
|
---|
239 | }
|
---|
240 |
|
---|
241 | const codePoint = parseInt(hex, 16);
|
---|
242 | const isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff; // Add special case for
|
---|
243 | // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
|
---|
244 | // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
|
---|
245 |
|
---|
246 | if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
|
---|
247 | return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
|
---|
248 | }
|
---|
249 |
|
---|
250 | return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
|
---|
251 | }
|
---|
252 |
|
---|
253 | const CONTAINS_ESCAPE = /\\/;
|
---|
254 |
|
---|
255 | function unescape(str) {
|
---|
256 | const needToProcess = CONTAINS_ESCAPE.test(str);
|
---|
257 |
|
---|
258 | if (!needToProcess) {
|
---|
259 | return str;
|
---|
260 | }
|
---|
261 |
|
---|
262 | let ret = "";
|
---|
263 |
|
---|
264 | for (let i = 0; i < str.length; i++) {
|
---|
265 | if (str[i] === "\\") {
|
---|
266 | const gobbled = gobbleHex(str.slice(i + 1, i + 7)); // eslint-disable-next-line no-undefined
|
---|
267 |
|
---|
268 | if (gobbled !== undefined) {
|
---|
269 | ret += gobbled[0];
|
---|
270 | i += gobbled[1]; // eslint-disable-next-line no-continue
|
---|
271 |
|
---|
272 | continue;
|
---|
273 | } // Retain a pair of \\ if double escaped `\\\\`
|
---|
274 | // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
|
---|
275 |
|
---|
276 |
|
---|
277 | if (str[i + 1] === "\\") {
|
---|
278 | ret += "\\";
|
---|
279 | i += 1; // eslint-disable-next-line no-continue
|
---|
280 |
|
---|
281 | continue;
|
---|
282 | } // if \\ is at the end of the string retain it
|
---|
283 | // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
|
---|
284 |
|
---|
285 |
|
---|
286 | if (str.length === i + 1) {
|
---|
287 | ret += str[i];
|
---|
288 | } // eslint-disable-next-line no-continue
|
---|
289 |
|
---|
290 |
|
---|
291 | continue;
|
---|
292 | }
|
---|
293 |
|
---|
294 | ret += str[i];
|
---|
295 | }
|
---|
296 |
|
---|
297 | return ret;
|
---|
298 | }
|
---|
299 |
|
---|
300 | function normalizePath(file) {
|
---|
301 | return _path.default.sep === "\\" ? file.replace(/\\/g, "/") : file;
|
---|
302 | } // eslint-disable-next-line no-control-regex
|
---|
303 |
|
---|
304 |
|
---|
305 | const filenameReservedRegex = /[<>:"/\\|?*]/g; // eslint-disable-next-line no-control-regex
|
---|
306 |
|
---|
307 | const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
|
---|
308 |
|
---|
309 | function escapeLocalIdent(localident) {
|
---|
310 | // TODO simplify in the next major release
|
---|
311 | return escape(localident // For `[hash]` placeholder
|
---|
312 | .replace(/^((-?[0-9])|--)/, "_$1").replace(filenameReservedRegex, "-").replace(reControlChars, "-").replace(/\./g, "-"));
|
---|
313 | }
|
---|
314 |
|
---|
315 | function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
|
---|
316 | let relativeMatchResource = ""; // eslint-disable-next-line no-underscore-dangle
|
---|
317 |
|
---|
318 | if (loaderContext._module && loaderContext._module.matchResource) {
|
---|
319 | relativeMatchResource = `${normalizePath( // eslint-disable-next-line no-underscore-dangle
|
---|
320 | _path.default.relative(options.context, loaderContext._module.matchResource))}\x00`;
|
---|
321 | }
|
---|
322 |
|
---|
323 | const relativeResourcePath = normalizePath(_path.default.relative(options.context, loaderContext.resourcePath)); // eslint-disable-next-line no-param-reassign
|
---|
324 |
|
---|
325 | options.content = `${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
|
---|
326 | let {
|
---|
327 | hashFunction,
|
---|
328 | hashDigest,
|
---|
329 | hashDigestLength
|
---|
330 | } = options;
|
---|
331 | const mathes = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
|
---|
332 |
|
---|
333 | if (mathes) {
|
---|
334 | const hashName = mathes[2] || hashFunction;
|
---|
335 | hashFunction = mathes[1] || hashFunction;
|
---|
336 | hashDigest = mathes[3] || hashDigest;
|
---|
337 | hashDigestLength = mathes[4] || hashDigestLength; // `hash` and `contenthash` are same in `loader-utils` context
|
---|
338 | // let's keep `hash` for backward compatibility
|
---|
339 | // eslint-disable-next-line no-param-reassign
|
---|
340 |
|
---|
341 | localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
|
---|
342 | } // eslint-disable-next-line no-underscore-dangle
|
---|
343 |
|
---|
344 |
|
---|
345 | const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
|
---|
346 |
|
---|
347 | const {
|
---|
348 | hashSalt
|
---|
349 | } = options;
|
---|
350 |
|
---|
351 | if (hashSalt) {
|
---|
352 | hash.update(hashSalt);
|
---|
353 | }
|
---|
354 |
|
---|
355 | hash.update(options.content);
|
---|
356 | const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength).replace(/[/+]/g, "_").replace(/^\d/g, "_"); // TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
|
---|
357 |
|
---|
358 | const ext = _path.default.extname(loaderContext.resourcePath);
|
---|
359 |
|
---|
360 | const base = _path.default.basename(loaderContext.resourcePath);
|
---|
361 |
|
---|
362 | const name = base.slice(0, base.length - ext.length);
|
---|
363 | const data = {
|
---|
364 | filename: _path.default.relative(options.context, loaderContext.resourcePath),
|
---|
365 | contentHash: localIdentHash,
|
---|
366 | chunk: {
|
---|
367 | name,
|
---|
368 | hash: localIdentHash,
|
---|
369 | contentHash: localIdentHash
|
---|
370 | }
|
---|
371 | }; // eslint-disable-next-line no-underscore-dangle
|
---|
372 |
|
---|
373 | let result = loaderContext._compilation.getPath(localIdentName, data);
|
---|
374 |
|
---|
375 | if (options.regExp) {
|
---|
376 | const match = loaderContext.resourcePath.match(options.regExp);
|
---|
377 |
|
---|
378 | if (match) {
|
---|
379 | match.forEach((matched, i) => {
|
---|
380 | result = result.replace(new RegExp(`\\[${i}\\]`, "ig"), matched);
|
---|
381 | });
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | return result;
|
---|
386 | }
|
---|
387 |
|
---|
388 | function fixedEncodeURIComponent(str) {
|
---|
389 | return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
|
---|
390 | }
|
---|
391 |
|
---|
392 | function isDataUrl(url) {
|
---|
393 | if (/^data:/i.test(url)) {
|
---|
394 | return true;
|
---|
395 | }
|
---|
396 |
|
---|
397 | return false;
|
---|
398 | }
|
---|
399 |
|
---|
400 | const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
|
---|
401 |
|
---|
402 | function normalizeUrl(url, isStringValue) {
|
---|
403 | let normalizedUrl = url.replace(/^( |\t\n|\r\n|\r|\f)*/g, "").replace(/( |\t\n|\r\n|\r|\f)*$/g, "");
|
---|
404 |
|
---|
405 | if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
|
---|
406 | normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, "");
|
---|
407 | }
|
---|
408 |
|
---|
409 | if (NATIVE_WIN32_PATH.test(url)) {
|
---|
410 | try {
|
---|
411 | normalizedUrl = decodeURI(normalizedUrl);
|
---|
412 | } catch (error) {// Ignore
|
---|
413 | }
|
---|
414 |
|
---|
415 | return normalizedUrl;
|
---|
416 | }
|
---|
417 |
|
---|
418 | normalizedUrl = unescape(normalizedUrl);
|
---|
419 |
|
---|
420 | if (isDataUrl(url)) {
|
---|
421 | // Todo fixedEncodeURIComponent is workaround. Webpack resolver shouldn't handle "!" in dataURL
|
---|
422 | return fixedEncodeURIComponent(normalizedUrl);
|
---|
423 | }
|
---|
424 |
|
---|
425 | try {
|
---|
426 | normalizedUrl = decodeURI(normalizedUrl);
|
---|
427 | } catch (error) {// Ignore
|
---|
428 | }
|
---|
429 |
|
---|
430 | return normalizedUrl;
|
---|
431 | }
|
---|
432 |
|
---|
433 | function requestify(url, rootContext, needToResolveURL = true) {
|
---|
434 | if (needToResolveURL) {
|
---|
435 | if (/^file:/i.test(url)) {
|
---|
436 | return (0, _url.fileURLToPath)(url);
|
---|
437 | }
|
---|
438 |
|
---|
439 | return url.charAt(0) === "/" ? urlToRequest(url, rootContext) : urlToRequest(url);
|
---|
440 | }
|
---|
441 |
|
---|
442 | if (url.charAt(0) === "/" || /^file:/i.test(url)) {
|
---|
443 | return url;
|
---|
444 | } // A `~` makes the url an module
|
---|
445 |
|
---|
446 |
|
---|
447 | if (IS_MODULE_REQUEST.test(url)) {
|
---|
448 | return url.replace(IS_MODULE_REQUEST, "");
|
---|
449 | }
|
---|
450 |
|
---|
451 | return url;
|
---|
452 | }
|
---|
453 |
|
---|
454 | function getFilter(filter, resourcePath) {
|
---|
455 | return (...args) => {
|
---|
456 | if (typeof filter === "function") {
|
---|
457 | return filter(...args, resourcePath);
|
---|
458 | }
|
---|
459 |
|
---|
460 | return true;
|
---|
461 | };
|
---|
462 | }
|
---|
463 |
|
---|
464 | function getValidLocalName(localName, exportLocalsConvention) {
|
---|
465 | if (typeof exportLocalsConvention === "function") {
|
---|
466 | const result = exportLocalsConvention(localName);
|
---|
467 | return Array.isArray(result) ? result[0] : result;
|
---|
468 | }
|
---|
469 |
|
---|
470 | if (exportLocalsConvention === "dashesOnly") {
|
---|
471 | return dashesCamelCase(localName);
|
---|
472 | }
|
---|
473 |
|
---|
474 | return camelCase(localName);
|
---|
475 | }
|
---|
476 |
|
---|
477 | const IS_MODULES = /\.module(s)?\.\w+$/i;
|
---|
478 | const IS_ICSS = /\.icss\.\w+$/i;
|
---|
479 |
|
---|
480 | function getModulesOptions(rawOptions, loaderContext) {
|
---|
481 | if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
---|
482 | return false;
|
---|
483 | }
|
---|
484 |
|
---|
485 | const resourcePath = // eslint-disable-next-line no-underscore-dangle
|
---|
486 | loaderContext._module && loaderContext._module.matchResource || loaderContext.resourcePath;
|
---|
487 | let auto;
|
---|
488 | let rawModulesOptions;
|
---|
489 |
|
---|
490 | if (typeof rawOptions.modules === "undefined") {
|
---|
491 | rawModulesOptions = {};
|
---|
492 | auto = true;
|
---|
493 | } else if (typeof rawOptions.modules === "boolean") {
|
---|
494 | rawModulesOptions = {};
|
---|
495 | } else if (typeof rawOptions.modules === "string") {
|
---|
496 | rawModulesOptions = {
|
---|
497 | mode: rawOptions.modules
|
---|
498 | };
|
---|
499 | } else {
|
---|
500 | rawModulesOptions = rawOptions.modules;
|
---|
501 | ({
|
---|
502 | auto
|
---|
503 | } = rawModulesOptions);
|
---|
504 | } // eslint-disable-next-line no-underscore-dangle
|
---|
505 |
|
---|
506 |
|
---|
507 | const {
|
---|
508 | outputOptions
|
---|
509 | } = loaderContext._compilation;
|
---|
510 | const modulesOptions = {
|
---|
511 | auto,
|
---|
512 | mode: "local",
|
---|
513 | exportGlobals: false,
|
---|
514 | localIdentName: "[hash:base64]",
|
---|
515 | localIdentContext: loaderContext.rootContext,
|
---|
516 | localIdentHashSalt: outputOptions.hashSalt,
|
---|
517 | localIdentHashFunction: outputOptions.hashFunction,
|
---|
518 | localIdentHashDigest: outputOptions.hashDigest,
|
---|
519 | localIdentHashDigestLength: outputOptions.hashDigestLength,
|
---|
520 | // eslint-disable-next-line no-undefined
|
---|
521 | localIdentRegExp: undefined,
|
---|
522 | // eslint-disable-next-line no-undefined
|
---|
523 | getLocalIdent: undefined,
|
---|
524 | namedExport: false,
|
---|
525 | exportLocalsConvention: rawModulesOptions.namedExport === true && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
---|
526 | exportOnlyLocals: false,
|
---|
527 | ...rawModulesOptions
|
---|
528 | };
|
---|
529 |
|
---|
530 | if (typeof modulesOptions.auto === "boolean") {
|
---|
531 | const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
|
---|
532 | let isIcss;
|
---|
533 |
|
---|
534 | if (!isModules) {
|
---|
535 | isIcss = IS_ICSS.test(resourcePath);
|
---|
536 |
|
---|
537 | if (isIcss) {
|
---|
538 | modulesOptions.mode = "icss";
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 | if (!isModules && !isIcss) {
|
---|
543 | return false;
|
---|
544 | }
|
---|
545 | } else if (modulesOptions.auto instanceof RegExp) {
|
---|
546 | const isModules = modulesOptions.auto.test(resourcePath);
|
---|
547 |
|
---|
548 | if (!isModules) {
|
---|
549 | return false;
|
---|
550 | }
|
---|
551 | } else if (typeof modulesOptions.auto === "function") {
|
---|
552 | const isModule = modulesOptions.auto(resourcePath);
|
---|
553 |
|
---|
554 | if (!isModule) {
|
---|
555 | return false;
|
---|
556 | }
|
---|
557 | }
|
---|
558 |
|
---|
559 | if (typeof modulesOptions.mode === "function") {
|
---|
560 | modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
|
---|
561 | }
|
---|
562 |
|
---|
563 | if (modulesOptions.namedExport === true) {
|
---|
564 | if (rawOptions.esModule === false) {
|
---|
565 | throw new Error('The "modules.namedExport" option requires the "esModules" option to be enabled');
|
---|
566 | }
|
---|
567 |
|
---|
568 | if (typeof modulesOptions.exportLocalsConvention === "string" && modulesOptions.exportLocalsConvention !== "camelCaseOnly" && modulesOptions.exportLocalsConvention !== "dashesOnly") {
|
---|
569 | throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
|
---|
570 | }
|
---|
571 | }
|
---|
572 |
|
---|
573 | return modulesOptions;
|
---|
574 | }
|
---|
575 |
|
---|
576 | function normalizeOptions(rawOptions, loaderContext) {
|
---|
577 | const modulesOptions = getModulesOptions(rawOptions, loaderContext);
|
---|
578 | return {
|
---|
579 | url: typeof rawOptions.url === "undefined" ? true : rawOptions.url,
|
---|
580 | import: typeof rawOptions.import === "undefined" ? true : rawOptions.import,
|
---|
581 | modules: modulesOptions,
|
---|
582 | sourceMap: typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap,
|
---|
583 | importLoaders: typeof rawOptions.importLoaders === "string" ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
|
---|
584 | esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule
|
---|
585 | };
|
---|
586 | }
|
---|
587 |
|
---|
588 | function shouldUseImportPlugin(options) {
|
---|
589 | if (options.modules.exportOnlyLocals) {
|
---|
590 | return false;
|
---|
591 | }
|
---|
592 |
|
---|
593 | if (typeof options.import === "boolean") {
|
---|
594 | return options.import;
|
---|
595 | }
|
---|
596 |
|
---|
597 | return true;
|
---|
598 | }
|
---|
599 |
|
---|
600 | function shouldUseURLPlugin(options) {
|
---|
601 | if (options.modules.exportOnlyLocals) {
|
---|
602 | return false;
|
---|
603 | }
|
---|
604 |
|
---|
605 | if (typeof options.url === "boolean") {
|
---|
606 | return options.url;
|
---|
607 | }
|
---|
608 |
|
---|
609 | return true;
|
---|
610 | }
|
---|
611 |
|
---|
612 | function shouldUseModulesPlugins(options) {
|
---|
613 | if (typeof options.modules === "boolean" && options.modules === false) {
|
---|
614 | return false;
|
---|
615 | }
|
---|
616 |
|
---|
617 | return options.modules.mode !== "icss";
|
---|
618 | }
|
---|
619 |
|
---|
620 | function shouldUseIcssPlugin(options) {
|
---|
621 | return Boolean(options.modules);
|
---|
622 | }
|
---|
623 |
|
---|
624 | function getModulesPlugins(options, loaderContext) {
|
---|
625 | const {
|
---|
626 | mode,
|
---|
627 | getLocalIdent,
|
---|
628 | localIdentName,
|
---|
629 | localIdentContext,
|
---|
630 | localIdentHashSalt,
|
---|
631 | localIdentHashFunction,
|
---|
632 | localIdentHashDigest,
|
---|
633 | localIdentHashDigestLength,
|
---|
634 | localIdentRegExp
|
---|
635 | } = options.modules;
|
---|
636 | let plugins = [];
|
---|
637 |
|
---|
638 | try {
|
---|
639 | plugins = [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
---|
640 | mode
|
---|
641 | }), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
|
---|
642 | generateScopedName(exportName) {
|
---|
643 | let localIdent;
|
---|
644 |
|
---|
645 | if (typeof getLocalIdent !== "undefined") {
|
---|
646 | localIdent = getLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
---|
647 | context: localIdentContext,
|
---|
648 | hashSalt: localIdentHashSalt,
|
---|
649 | hashFunction: localIdentHashFunction,
|
---|
650 | hashDigest: localIdentHashDigest,
|
---|
651 | hashDigestLength: localIdentHashDigestLength,
|
---|
652 | regExp: localIdentRegExp
|
---|
653 | });
|
---|
654 | } // A null/undefined value signals that we should invoke the default
|
---|
655 | // getLocalIdent method.
|
---|
656 |
|
---|
657 |
|
---|
658 | if (typeof localIdent === "undefined" || localIdent === null) {
|
---|
659 | localIdent = defaultGetLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
---|
660 | context: localIdentContext,
|
---|
661 | hashSalt: localIdentHashSalt,
|
---|
662 | hashFunction: localIdentHashFunction,
|
---|
663 | hashDigest: localIdentHashDigest,
|
---|
664 | hashDigestLength: localIdentHashDigestLength,
|
---|
665 | regExp: localIdentRegExp
|
---|
666 | });
|
---|
667 | return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
|
---|
668 | }
|
---|
669 |
|
---|
670 | return escapeLocalIdent(localIdent);
|
---|
671 | },
|
---|
672 |
|
---|
673 | exportGlobals: options.modules.exportGlobals
|
---|
674 | })];
|
---|
675 | } catch (error) {
|
---|
676 | loaderContext.emitError(error);
|
---|
677 | }
|
---|
678 |
|
---|
679 | return plugins;
|
---|
680 | }
|
---|
681 |
|
---|
682 | const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
|
---|
683 |
|
---|
684 | function getURLType(source) {
|
---|
685 | if (source[0] === "/") {
|
---|
686 | if (source[1] === "/") {
|
---|
687 | return "scheme-relative";
|
---|
688 | }
|
---|
689 |
|
---|
690 | return "path-absolute";
|
---|
691 | }
|
---|
692 |
|
---|
693 | if (IS_NATIVE_WIN32_PATH.test(source)) {
|
---|
694 | return "path-absolute";
|
---|
695 | }
|
---|
696 |
|
---|
697 | return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
|
---|
698 | }
|
---|
699 |
|
---|
700 | function normalizeSourceMap(map, resourcePath) {
|
---|
701 | let newMap = map; // Some loader emit source map as string
|
---|
702 | // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
|
---|
703 |
|
---|
704 | if (typeof newMap === "string") {
|
---|
705 | newMap = JSON.parse(newMap);
|
---|
706 | }
|
---|
707 |
|
---|
708 | delete newMap.file;
|
---|
709 | const {
|
---|
710 | sourceRoot
|
---|
711 | } = newMap;
|
---|
712 | delete newMap.sourceRoot;
|
---|
713 |
|
---|
714 | if (newMap.sources) {
|
---|
715 | // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
|
---|
716 | // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
|
---|
717 | newMap.sources = newMap.sources.map(source => {
|
---|
718 | // Non-standard syntax from `postcss`
|
---|
719 | if (source.indexOf("<") === 0) {
|
---|
720 | return source;
|
---|
721 | }
|
---|
722 |
|
---|
723 | const sourceType = getURLType(source); // Do no touch `scheme-relative` and `absolute` URLs
|
---|
724 |
|
---|
725 | if (sourceType === "path-relative" || sourceType === "path-absolute") {
|
---|
726 | const absoluteSource = sourceType === "path-relative" && sourceRoot ? _path.default.resolve(sourceRoot, normalizePath(source)) : normalizePath(source);
|
---|
727 | return _path.default.relative(_path.default.dirname(resourcePath), absoluteSource);
|
---|
728 | }
|
---|
729 |
|
---|
730 | return source;
|
---|
731 | });
|
---|
732 | }
|
---|
733 |
|
---|
734 | return newMap;
|
---|
735 | }
|
---|
736 |
|
---|
737 | function getPreRequester({
|
---|
738 | loaders,
|
---|
739 | loaderIndex
|
---|
740 | }) {
|
---|
741 | const cache = Object.create(null);
|
---|
742 | return number => {
|
---|
743 | if (cache[number]) {
|
---|
744 | return cache[number];
|
---|
745 | }
|
---|
746 |
|
---|
747 | if (number === false) {
|
---|
748 | cache[number] = "";
|
---|
749 | } else {
|
---|
750 | const loadersRequest = loaders.slice(loaderIndex, loaderIndex + 1 + (typeof number !== "number" ? 0 : number)).map(x => x.request).join("!");
|
---|
751 | cache[number] = `-!${loadersRequest}!`;
|
---|
752 | }
|
---|
753 |
|
---|
754 | return cache[number];
|
---|
755 | };
|
---|
756 | }
|
---|
757 |
|
---|
758 | function getImportCode(imports, options) {
|
---|
759 | let code = "";
|
---|
760 |
|
---|
761 | for (const item of imports) {
|
---|
762 | const {
|
---|
763 | importName,
|
---|
764 | url,
|
---|
765 | icss,
|
---|
766 | type
|
---|
767 | } = item;
|
---|
768 |
|
---|
769 | if (options.esModule) {
|
---|
770 | if (icss && options.modules.namedExport) {
|
---|
771 | code += `import ${options.modules.exportOnlyLocals ? "" : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
|
---|
772 | } else {
|
---|
773 | code += type === "url" ? `var ${importName} = new URL(${url}, import.meta.url);\n` : `import ${importName} from ${url};\n`;
|
---|
774 | }
|
---|
775 | } else {
|
---|
776 | code += `var ${importName} = require(${url});\n`;
|
---|
777 | }
|
---|
778 | }
|
---|
779 |
|
---|
780 | return code ? `// Imports\n${code}` : "";
|
---|
781 | }
|
---|
782 |
|
---|
783 | function normalizeSourceMapForRuntime(map, loaderContext) {
|
---|
784 | const resultMap = map ? map.toJSON() : null;
|
---|
785 |
|
---|
786 | if (resultMap) {
|
---|
787 | delete resultMap.file;
|
---|
788 | resultMap.sourceRoot = "";
|
---|
789 | resultMap.sources = resultMap.sources.map(source => {
|
---|
790 | // Non-standard syntax from `postcss`
|
---|
791 | if (source.indexOf("<") === 0) {
|
---|
792 | return source;
|
---|
793 | }
|
---|
794 |
|
---|
795 | const sourceType = getURLType(source);
|
---|
796 |
|
---|
797 | if (sourceType !== "path-relative") {
|
---|
798 | return source;
|
---|
799 | }
|
---|
800 |
|
---|
801 | const resourceDirname = _path.default.dirname(loaderContext.resourcePath);
|
---|
802 |
|
---|
803 | const absoluteSource = _path.default.resolve(resourceDirname, source);
|
---|
804 |
|
---|
805 | const contextifyPath = normalizePath(_path.default.relative(loaderContext.rootContext, absoluteSource));
|
---|
806 | return `webpack://./${contextifyPath}`;
|
---|
807 | });
|
---|
808 | }
|
---|
809 |
|
---|
810 | return JSON.stringify(resultMap);
|
---|
811 | }
|
---|
812 |
|
---|
813 | function getModuleCode(result, api, replacements, options, loaderContext) {
|
---|
814 | if (options.modules.exportOnlyLocals === true) {
|
---|
815 | return "";
|
---|
816 | }
|
---|
817 |
|
---|
818 | const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : "";
|
---|
819 | let code = JSON.stringify(result.css);
|
---|
820 | let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "function(i){return i[1]}"});\n`;
|
---|
821 |
|
---|
822 | for (const item of api) {
|
---|
823 | const {
|
---|
824 | url,
|
---|
825 | media,
|
---|
826 | dedupe
|
---|
827 | } = item;
|
---|
828 | beforeCode += url ? `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${media ? `, ${JSON.stringify(media)}` : ""}]);\n` : `___CSS_LOADER_EXPORT___.i(${item.importName}${media ? `, ${JSON.stringify(media)}` : dedupe ? ', ""' : ""}${dedupe ? ", true" : ""});\n`;
|
---|
829 | }
|
---|
830 |
|
---|
831 | for (const item of replacements) {
|
---|
832 | const {
|
---|
833 | replacementName,
|
---|
834 | importName,
|
---|
835 | localName
|
---|
836 | } = item;
|
---|
837 |
|
---|
838 | if (localName) {
|
---|
839 | code = code.replace(new RegExp(replacementName, "g"), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
|
---|
840 | } else {
|
---|
841 | const {
|
---|
842 | hash,
|
---|
843 | needQuotes
|
---|
844 | } = item;
|
---|
845 | const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? "needQuotes: true" : []);
|
---|
846 | const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(", ")} }` : "";
|
---|
847 | beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
|
---|
848 | code = code.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
|
---|
849 | }
|
---|
850 | }
|
---|
851 |
|
---|
852 | return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
|
---|
853 | }
|
---|
854 |
|
---|
855 | function dashesCamelCase(str) {
|
---|
856 | return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
---|
857 | }
|
---|
858 |
|
---|
859 | function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
|
---|
860 | let code = "// Exports\n";
|
---|
861 |
|
---|
862 | if (!needToUseIcssPlugin) {
|
---|
863 | code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
|
---|
864 | return code;
|
---|
865 | }
|
---|
866 |
|
---|
867 | let localsCode = "";
|
---|
868 |
|
---|
869 | const addExportToLocalsCode = (names, value) => {
|
---|
870 | const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
|
---|
871 |
|
---|
872 | for (const name of normalizedNames) {
|
---|
873 | if (options.modules.namedExport) {
|
---|
874 | localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
---|
875 | } else {
|
---|
876 | if (localsCode) {
|
---|
877 | localsCode += `,\n`;
|
---|
878 | }
|
---|
879 |
|
---|
880 | localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
|
---|
881 | }
|
---|
882 | }
|
---|
883 | };
|
---|
884 |
|
---|
885 | for (const {
|
---|
886 | name,
|
---|
887 | value
|
---|
888 | } of exports) {
|
---|
889 | if (typeof options.modules.exportLocalsConvention === "function") {
|
---|
890 | addExportToLocalsCode(options.modules.exportLocalsConvention(name), value); // eslint-disable-next-line no-continue
|
---|
891 |
|
---|
892 | continue;
|
---|
893 | }
|
---|
894 |
|
---|
895 | switch (options.modules.exportLocalsConvention) {
|
---|
896 | case "camelCase":
|
---|
897 | {
|
---|
898 | const modifiedName = camelCase(name);
|
---|
899 | addExportToLocalsCode([name, modifiedName], value);
|
---|
900 | break;
|
---|
901 | }
|
---|
902 |
|
---|
903 | case "camelCaseOnly":
|
---|
904 | {
|
---|
905 | addExportToLocalsCode(camelCase(name), value);
|
---|
906 | break;
|
---|
907 | }
|
---|
908 |
|
---|
909 | case "dashes":
|
---|
910 | {
|
---|
911 | const modifiedName = dashesCamelCase(name);
|
---|
912 | addExportToLocalsCode([name, modifiedName], value);
|
---|
913 | break;
|
---|
914 | }
|
---|
915 |
|
---|
916 | case "dashesOnly":
|
---|
917 | {
|
---|
918 | addExportToLocalsCode(dashesCamelCase(name), value);
|
---|
919 | break;
|
---|
920 | }
|
---|
921 |
|
---|
922 | case "asIs":
|
---|
923 | default:
|
---|
924 | addExportToLocalsCode(name, value);
|
---|
925 | break;
|
---|
926 | }
|
---|
927 | }
|
---|
928 |
|
---|
929 | for (const item of replacements) {
|
---|
930 | const {
|
---|
931 | replacementName,
|
---|
932 | localName
|
---|
933 | } = item;
|
---|
934 |
|
---|
935 | if (localName) {
|
---|
936 | const {
|
---|
937 | importName
|
---|
938 | } = item;
|
---|
939 | localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
|
---|
940 | if (options.modules.namedExport) {
|
---|
941 | return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
|
---|
942 | } else if (options.modules.exportOnlyLocals) {
|
---|
943 | return `" + ${importName}[${JSON.stringify(localName)}] + "`;
|
---|
944 | }
|
---|
945 |
|
---|
946 | return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
|
---|
947 | });
|
---|
948 | } else {
|
---|
949 | localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
|
---|
950 | }
|
---|
951 | }
|
---|
952 |
|
---|
953 | if (options.modules.exportOnlyLocals) {
|
---|
954 | code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
|
---|
955 | return code;
|
---|
956 | }
|
---|
957 |
|
---|
958 | code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
|
---|
959 | code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
|
---|
960 | return code;
|
---|
961 | }
|
---|
962 |
|
---|
963 | async function resolveRequests(resolve, context, possibleRequests) {
|
---|
964 | return resolve(context, possibleRequests[0]).then(result => result).catch(error => {
|
---|
965 | const [, ...tailPossibleRequests] = possibleRequests;
|
---|
966 |
|
---|
967 | if (tailPossibleRequests.length === 0) {
|
---|
968 | throw error;
|
---|
969 | }
|
---|
970 |
|
---|
971 | return resolveRequests(resolve, context, tailPossibleRequests);
|
---|
972 | });
|
---|
973 | }
|
---|
974 |
|
---|
975 | function isUrlRequestable(url) {
|
---|
976 | // Protocol-relative URLs
|
---|
977 | if (/^\/\//.test(url)) {
|
---|
978 | return false;
|
---|
979 | } // `file:` protocol
|
---|
980 |
|
---|
981 |
|
---|
982 | if (/^file:/i.test(url)) {
|
---|
983 | return true;
|
---|
984 | } // Absolute URLs
|
---|
985 |
|
---|
986 |
|
---|
987 | if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !NATIVE_WIN32_PATH.test(url)) {
|
---|
988 | return false;
|
---|
989 | } // `#` URLs
|
---|
990 |
|
---|
991 |
|
---|
992 | if (/^#/.test(url)) {
|
---|
993 | return false;
|
---|
994 | }
|
---|
995 |
|
---|
996 | return true;
|
---|
997 | }
|
---|
998 |
|
---|
999 | function sort(a, b) {
|
---|
1000 | return a.index - b.index;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | function combineRequests(preRequest, url) {
|
---|
1004 | const idx = url.indexOf("!=!");
|
---|
1005 | return idx !== -1 ? url.slice(0, idx + 3) + preRequest + url.slice(idx + 3) : preRequest + url;
|
---|
1006 | } |
---|