source: frontend/node_modules/sass-loader/dist/utils.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 23.7 KB
RevLine 
[9af201e]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getCompileFn = getCompileFn;
7exports.getModernWebpackImporter = getModernWebpackImporter;
8exports.getSassImplementation = getSassImplementation;
9exports.getSassOptions = getSassOptions;
10exports.getWebpackImporter = getWebpackImporter;
11exports.getWebpackResolver = getWebpackResolver;
12exports.isSupportedFibers = isSupportedFibers;
13exports.normalizeSourceMap = normalizeSourceMap;
14
15var _url = _interopRequireDefault(require("url"));
16
17var _path = _interopRequireDefault(require("path"));
18
19var _full = require("klona/full");
20
21var _neoAsync = _interopRequireDefault(require("neo-async"));
22
23var _SassWarning = _interopRequireDefault(require("./SassWarning"));
24
25function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
27function getDefaultSassImplementation() {
28 let sassImplPkg = "sass";
29
30 try {
31 require.resolve("sass");
32 } catch (ignoreError) {
33 try {
34 require.resolve("node-sass");
35
36 sassImplPkg = "node-sass";
37 } catch (_ignoreError) {
38 try {
39 require.resolve("sass-embedded");
40
41 sassImplPkg = "sass-embedded";
42 } catch (__ignoreError) {
43 sassImplPkg = "sass";
44 }
45 }
46 } // eslint-disable-next-line import/no-dynamic-require, global-require
47
48
49 return require(sassImplPkg);
50}
51/**
52 * This function is not Webpack-specific and can be used by tools wishing to mimic `sass-loader`'s behaviour, so its signature should not be changed.
53 */
54
55
56function getSassImplementation(loaderContext, implementation) {
57 let resolvedImplementation = implementation;
58
59 if (!resolvedImplementation) {
60 try {
61 resolvedImplementation = getDefaultSassImplementation();
62 } catch (error) {
63 loaderContext.emitError(error);
64 return;
65 }
66 }
67
68 if (typeof resolvedImplementation === "string") {
69 try {
70 // eslint-disable-next-line import/no-dynamic-require, global-require
71 resolvedImplementation = require(resolvedImplementation);
72 } catch (error) {
73 loaderContext.emitError(error); // eslint-disable-next-line consistent-return
74
75 return;
76 }
77 }
78
79 const {
80 info
81 } = resolvedImplementation;
82
83 if (!info) {
84 loaderContext.emitError(new Error("Unknown Sass implementation."));
85 return;
86 }
87
88 const infoParts = info.split("\t");
89
90 if (infoParts.length < 2) {
91 loaderContext.emitError(new Error(`Unknown Sass implementation "${info}".`));
92 return;
93 }
94
95 const [implementationName] = infoParts;
96
97 if (implementationName === "dart-sass") {
98 // eslint-disable-next-line consistent-return
99 return resolvedImplementation;
100 } else if (implementationName === "node-sass") {
101 // eslint-disable-next-line consistent-return
102 return resolvedImplementation;
103 } else if (implementationName === "sass-embedded") {
104 // eslint-disable-next-line consistent-return
105 return resolvedImplementation;
106 }
107
108 loaderContext.emitError(new Error(`Unknown Sass implementation "${implementationName}".`));
109}
110/**
111 * @param {any} loaderContext
112 * @returns {boolean}
113 */
114
115
116function isProductionLikeMode(loaderContext) {
117 return loaderContext.mode === "production" || !loaderContext.mode;
118}
119
120function proxyCustomImporters(importers, loaderContext) {
121 return [].concat(importers).map(importer => function proxyImporter(...args) {
122 const self = { ...this,
123 webpackLoaderContext: loaderContext
124 };
125 return importer.apply(self, args);
126 });
127}
128
129function isSupportedFibers() {
130 const [nodeVersion] = process.versions.node.split(".");
131 return Number(nodeVersion) < 16;
132}
133/**
134 * Derives the sass options from the loader context and normalizes its values with sane defaults.
135 *
136 * @param {object} loaderContext
137 * @param {object} loaderOptions
138 * @param {string} content
139 * @param {object} implementation
140 * @param {boolean} useSourceMap
141 * @returns {Object}
142 */
143
144
145async function getSassOptions(loaderContext, loaderOptions, content, implementation, useSourceMap) {
146 const options = (0, _full.klona)(loaderOptions.sassOptions ? typeof loaderOptions.sassOptions === "function" ? loaderOptions.sassOptions(loaderContext) || {} : loaderOptions.sassOptions : {});
147 const isDartSass = implementation.info.includes("dart-sass");
148 const isModernAPI = loaderOptions.api === "modern";
149 options.data = loaderOptions.additionalData ? typeof loaderOptions.additionalData === "function" ? await loaderOptions.additionalData(content, loaderContext) : `${loaderOptions.additionalData}\n${content}` : content;
150
151 if (!options.logger) {
152 // TODO set me to `true` by default in the next major release
153 const needEmitWarning = loaderOptions.warnRuleAsWarning === true;
154 const logger = loaderContext.getLogger("sass-loader");
155
156 const formatSpan = span => `${span.url || "-"}:${span.start.line}:${span.start.column}: `;
157
158 options.logger = {
159 debug(message, loggerOptions) {
160 let builtMessage = "";
161
162 if (loggerOptions.span) {
163 builtMessage = formatSpan(loggerOptions.span);
164 }
165
166 builtMessage += message;
167 logger.debug(builtMessage);
168 },
169
170 warn(message, loggerOptions) {
171 let builtMessage = "";
172
173 if (loggerOptions.deprecation) {
174 builtMessage += "Deprecation ";
175 }
176
177 if (loggerOptions.span && !loggerOptions.stack) {
178 builtMessage = formatSpan(loggerOptions.span);
179 }
180
181 builtMessage += message;
182
183 if (loggerOptions.stack) {
184 builtMessage += `\n\n${loggerOptions.stack}`;
185 }
186
187 if (needEmitWarning) {
188 loaderContext.emitWarning(new _SassWarning.default(builtMessage, loggerOptions));
189 } else {
190 logger.warn(builtMessage);
191 }
192 }
193
194 };
195 }
196
197 const {
198 resourcePath
199 } = loaderContext;
200
201 if (isModernAPI) {
202 options.url = _url.default.pathToFileURL(resourcePath); // opt.outputStyle
203
204 if (!options.style && isProductionLikeMode(loaderContext)) {
205 options.style = "compressed";
206 }
207
208 if (useSourceMap) {
209 options.sourceMap = true;
210 } // If we are compiling sass and indentedSyntax isn't set, automatically set it.
211
212
213 if (typeof options.syntax === "undefined") {
214 const ext = _path.default.extname(resourcePath);
215
216 if (ext && ext.toLowerCase() === ".scss") {
217 options.syntax = "scss";
218 } else if (ext && ext.toLowerCase() === ".sass") {
219 options.syntax = "indented";
220 } else if (ext && ext.toLowerCase() === ".css") {
221 options.syntax = "css";
222 }
223 }
224
225 options.importers = options.importers ? proxyCustomImporters(Array.isArray(options.importers) ? options.importers : [options.importers], loaderContext) : [];
226 } else {
227 options.file = resourcePath;
228
229 if (isDartSass && isSupportedFibers()) {
230 const shouldTryToResolveFibers = !options.fiber && options.fiber !== false;
231
232 if (shouldTryToResolveFibers) {
233 let fibers;
234
235 try {
236 fibers = require.resolve("fibers");
237 } catch (_error) {// Nothing
238 }
239
240 if (fibers) {
241 // eslint-disable-next-line global-require, import/no-dynamic-require
242 options.fiber = require(fibers);
243 }
244 } else if (options.fiber === false) {
245 // Don't pass the `fiber` option for `sass` (`Dart Sass`)
246 delete options.fiber;
247 }
248 } else {
249 // Don't pass the `fiber` option for `node-sass`
250 delete options.fiber;
251 } // opt.outputStyle
252
253
254 if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
255 options.outputStyle = "compressed";
256 }
257
258 if (useSourceMap) {
259 // Deliberately overriding the sourceMap option here.
260 // node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
261 // In case it is a string, options.sourceMap should be a path where the source map is written.
262 // But since we're using the data option, the source map will not actually be written, but
263 // all paths in sourceMap.sources will be relative to that path.
264 // Pretty complicated... :(
265 options.sourceMap = true;
266 options.outFile = _path.default.join(loaderContext.rootContext, "style.css.map");
267 options.sourceMapContents = true;
268 options.omitSourceMapUrl = true;
269 options.sourceMapEmbed = false;
270 }
271
272 const ext = _path.default.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it.
273
274
275 if (ext && ext.toLowerCase() === ".sass" && typeof options.indentedSyntax === "undefined") {
276 options.indentedSyntax = true;
277 } else {
278 options.indentedSyntax = Boolean(options.indentedSyntax);
279 } // Allow passing custom importers to `sass`/`node-sass`. Accepts `Function` or an array of `Function`s.
280
281
282 options.importer = options.importer ? proxyCustomImporters(Array.isArray(options.importer) ? options.importer : [options.importer], loaderContext) : [];
283 options.includePaths = [].concat(process.cwd()).concat( // We use `includePaths` in context for resolver, so it should be always absolute
284 (options.includePaths || []).map(includePath => _path.default.isAbsolute(includePath) ? includePath : _path.default.join(process.cwd(), includePath))).concat(process.env.SASS_PATH ? process.env.SASS_PATH.split(process.platform === "win32" ? ";" : ":") : []);
285
286 if (typeof options.charset === "undefined") {
287 options.charset = true;
288 }
289 }
290
291 return options;
292}
293
294const MODULE_REQUEST_REGEX = /^[^?]*~/; // Examples:
295// - ~package
296// - ~package/
297// - ~@org
298// - ~@org/
299// - ~@org/package
300// - ~@org/package/
301
302const IS_MODULE_IMPORT = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
303/**
304 * When `sass`/`node-sass` tries to resolve an import, it uses a special algorithm.
305 * Since the `sass-loader` uses webpack to resolve the modules, we need to simulate that algorithm.
306 * This function returns an array of import paths to try.
307 * The last entry in the array is always the original url to enable straight-forward webpack.config aliases.
308 *
309 * We don't need emulate `dart-sass` "It's not clear which file to import." errors (when "file.ext" and "_file.ext" files are present simultaneously in the same directory).
310 * This reduces performance and `dart-sass` always do it on own side.
311 *
312 * @param {string} url
313 * @param {boolean} forWebpackResolver
314 * @param {boolean} fromImport
315 * @returns {Array<string>}
316 */
317
318function getPossibleRequests( // eslint-disable-next-line no-shadow
319url, forWebpackResolver = false, fromImport = false) {
320 let request = url; // In case there is module request, send this to webpack resolver
321
322 if (forWebpackResolver) {
323 if (MODULE_REQUEST_REGEX.test(url)) {
324 request = request.replace(MODULE_REQUEST_REGEX, "");
325 }
326
327 if (IS_MODULE_IMPORT.test(url)) {
328 request = request[request.length - 1] === "/" ? request : `${request}/`;
329 return [...new Set([request, url])];
330 }
331 } // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
332 // @see https://github.com/webpack-contrib/sass-loader/issues/167
333
334
335 const extension = _path.default.extname(request).toLowerCase(); // Because @import is also defined in CSS, Sass needs a way of compiling plain CSS @imports without trying to import the files at compile time.
336 // To accomplish this, and to ensure SCSS is as much of a superset of CSS as possible, Sass will compile any @imports with the following characteristics to plain CSS imports:
337 // - imports where the URL ends with .css.
338 // - imports where the URL begins http:// or https://.
339 // - imports where the URL is written as a url().
340 // - imports that have media queries.
341 //
342 // The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
343
344
345 if (extension === ".css") {
346 return [];
347 }
348
349 const dirname = _path.default.dirname(request);
350
351 const normalizedDirname = dirname === "." ? "" : `${dirname}/`;
352
353 const basename = _path.default.basename(request);
354
355 const basenameWithoutExtension = _path.default.basename(request, extension);
356
357 return [...new Set([].concat(fromImport ? [`${normalizedDirname}_${basenameWithoutExtension}.import${extension}`, `${normalizedDirname}${basenameWithoutExtension}.import${extension}`] : []).concat([`${normalizedDirname}_${basename}`, `${normalizedDirname}${basename}`]).concat(forWebpackResolver ? [url] : []))];
358}
359
360function promiseResolve(callbackResolve) {
361 return (context, request) => new Promise((resolve, reject) => {
362 callbackResolve(context, request, (error, result) => {
363 if (error) {
364 reject(error);
365 } else {
366 resolve(result);
367 }
368 });
369 });
370}
371
372async function startResolving(resolutionMap) {
373 if (resolutionMap.length === 0) {
374 return Promise.reject();
375 }
376
377 const [{
378 possibleRequests
379 }] = resolutionMap;
380
381 if (possibleRequests.length === 0) {
382 return Promise.reject();
383 }
384
385 const [{
386 resolve,
387 context
388 }] = resolutionMap;
389
390 try {
391 return await resolve(context, possibleRequests[0]);
392 } catch (_ignoreError) {
393 const [, ...tailResult] = possibleRequests;
394
395 if (tailResult.length === 0) {
396 const [, ...tailResolutionMap] = resolutionMap;
397 return startResolving(tailResolutionMap);
398 } // eslint-disable-next-line no-param-reassign
399
400
401 resolutionMap[0].possibleRequests = tailResult;
402 return startResolving(resolutionMap);
403 }
404}
405
406const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/; // `[drive_letter]:\` + `\\[server]\[sharename]\`
407
408const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
409/**
410 * @public
411 * Create the resolve function used in the custom Sass importer.
412 *
413 * Can be used by external tools to mimic how `sass-loader` works, for example
414 * in a Jest transform. Such usages will want to wrap `resolve.create` from
415 * [`enhanced-resolve`]{@link https://github.com/webpack/enhanced-resolve} to
416 * pass as the `resolverFactory` argument.
417 *
418 * @param {Function} resolverFactory - A factory function for creating a Webpack
419 * resolver.
420 * @param {Object} implementation - The imported Sass implementation, both
421 * `sass` (Dart Sass) and `node-sass` are supported.
422 * @param {string[]} [includePaths] - The list of include paths passed to Sass.
423 *
424 * @throws If a compatible Sass implementation cannot be found.
425 */
426
427function getWebpackResolver(resolverFactory, implementation, includePaths = []) {
428 const isDartSass = implementation && implementation.info.includes("dart-sass"); // We only have one difference with the built-in sass resolution logic and out resolution logic:
429 // First, we look at the files starting with `_`, then without `_` (i.e. `_name.sass`, `_name.scss`, `_name.css`, `name.sass`, `name.scss`, `name.css`),
430 // although `sass` look together by extensions (i.e. `_name.sass`/`name.sass`/`_name.scss`/`name.scss`/`_name.css`/`name.css`).
431 // It shouldn't be a problem because `sass` throw errors:
432 // - on having `_name.sass` and `name.sass` (extension can be `sass`, `scss` or `css`) in the same directory
433 // - on having `_name.sass` and `_name.scss` in the same directory
434 //
435 // Also `sass` prefer `sass`/`scss` over `css`.
436
437 const sassModuleResolve = promiseResolve(resolverFactory({
438 alias: [],
439 aliasFields: [],
440 conditionNames: [],
441 descriptionFiles: [],
442 extensions: [".sass", ".scss", ".css"],
443 exportsFields: [],
444 mainFields: [],
445 mainFiles: ["_index", "index"],
446 modules: [],
447 restrictions: [/\.((sa|sc|c)ss)$/i],
448 preferRelative: true
449 }));
450 const sassImportResolve = promiseResolve(resolverFactory({
451 alias: [],
452 aliasFields: [],
453 conditionNames: [],
454 descriptionFiles: [],
455 extensions: [".sass", ".scss", ".css"],
456 exportsFields: [],
457 mainFields: [],
458 mainFiles: ["_index.import", "_index", "index.import", "index"],
459 modules: [],
460 restrictions: [/\.((sa|sc|c)ss)$/i],
461 preferRelative: true
462 }));
463 const webpackModuleResolve = promiseResolve(resolverFactory({
464 dependencyType: "sass",
465 conditionNames: ["sass", "style"],
466 mainFields: ["sass", "style", "main", "..."],
467 mainFiles: ["_index", "index", "..."],
468 extensions: [".sass", ".scss", ".css"],
469 restrictions: [/\.((sa|sc|c)ss)$/i],
470 preferRelative: true
471 }));
472 const webpackImportResolve = promiseResolve(resolverFactory({
473 dependencyType: "sass",
474 conditionNames: ["sass", "style"],
475 mainFields: ["sass", "style", "main", "..."],
476 mainFiles: ["_index.import", "_index", "index.import", "index", "..."],
477 extensions: [".sass", ".scss", ".css"],
478 restrictions: [/\.((sa|sc|c)ss)$/i],
479 preferRelative: true
480 }));
481 return (context, request, fromImport) => {
482 // See https://github.com/webpack/webpack/issues/12340
483 // Because `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`
484 // custom importer may not return `{ file: '/path/to/name.ext' }` and therefore our `context` will be relative
485 if (!isDartSass && !_path.default.isAbsolute(context)) {
486 return Promise.reject();
487 }
488
489 const originalRequest = request;
490 const isFileScheme = originalRequest.slice(0, 5).toLowerCase() === "file:";
491
492 if (isFileScheme) {
493 try {
494 // eslint-disable-next-line no-param-reassign
495 request = _url.default.fileURLToPath(originalRequest);
496 } catch (ignoreError) {
497 // eslint-disable-next-line no-param-reassign
498 request = request.slice(7);
499 }
500 }
501
502 let resolutionMap = [];
503 const needEmulateSassResolver = // `sass` doesn't support module import
504 !IS_SPECIAL_MODULE_IMPORT.test(request) && // We need improve absolute paths handling.
505 // Absolute paths should be resolved:
506 // - Server-relative URLs - `<context>/path/to/file.ext` (where `<context>` is root context)
507 // - Absolute path - `/full/path/to/file.ext` or `C:\\full\path\to\file.ext`
508 !isFileScheme && !originalRequest.startsWith("/") && !IS_NATIVE_WIN32_PATH.test(originalRequest);
509
510 if (includePaths.length > 0 && needEmulateSassResolver) {
511 // The order of import precedence is as follows:
512 //
513 // 1. Filesystem imports relative to the base file.
514 // 2. Custom importer imports.
515 // 3. Filesystem imports relative to the working directory.
516 // 4. Filesystem imports relative to an `includePaths` path.
517 // 5. Filesystem imports relative to a `SASS_PATH` path.
518 //
519 // `sass` run custom importers before `3`, `4` and `5` points, we need to emulate this behavior to avoid wrong resolution.
520 const sassPossibleRequests = getPossibleRequests(request, false, fromImport); // `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`, so we need emulate this too
521
522 if (!isDartSass) {
523 resolutionMap = resolutionMap.concat({
524 resolve: fromImport ? sassImportResolve : sassModuleResolve,
525 context: _path.default.dirname(context),
526 possibleRequests: sassPossibleRequests
527 });
528 }
529
530 resolutionMap = resolutionMap.concat( // eslint-disable-next-line no-shadow
531 includePaths.map(context => {
532 return {
533 resolve: fromImport ? sassImportResolve : sassModuleResolve,
534 context,
535 possibleRequests: sassPossibleRequests
536 };
537 }));
538 }
539
540 const webpackPossibleRequests = getPossibleRequests(request, true, fromImport);
541 resolutionMap = resolutionMap.concat({
542 resolve: fromImport ? webpackImportResolve : webpackModuleResolve,
543 context: _path.default.dirname(context),
544 possibleRequests: webpackPossibleRequests
545 });
546 return startResolving(resolutionMap);
547 };
548}
549
550const MATCH_CSS = /\.css$/i;
551
552function getModernWebpackImporter() {
553 return {
554 async canonicalize() {
555 return null;
556 },
557
558 load() {// TODO implement
559 }
560
561 };
562}
563
564function getWebpackImporter(loaderContext, implementation, includePaths) {
565 const resolve = getWebpackResolver(loaderContext.getResolve, implementation, includePaths);
566 return function importer(originalUrl, prev, done) {
567 const {
568 fromImport
569 } = this;
570 resolve(prev, originalUrl, fromImport).then(result => {
571 // Add the result as dependency.
572 // Although we're also using stats.includedFiles, this might come in handy when an error occurs.
573 // In this case, we don't get stats.includedFiles from node-sass/sass.
574 loaderContext.addDependency(_path.default.normalize(result)); // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
575
576 done({
577 file: result.replace(MATCH_CSS, "")
578 });
579 }) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
580 .catch(() => {
581 done({
582 file: originalUrl
583 });
584 });
585 };
586}
587
588let nodeSassJobQueue = null;
589/**
590 * Verifies that the implementation and version of Sass is supported by this loader.
591 *
592 * @param {Object} implementation
593 * @param {Object} options
594 * @returns {Function}
595 */
596
597function getCompileFn(implementation, options) {
598 const isNewSass = implementation.info.includes("dart-sass") || implementation.info.includes("sass-embedded");
599
600 if (isNewSass) {
601 if (options.api === "modern") {
602 return sassOptions => {
603 const {
604 data,
605 ...rest
606 } = sassOptions;
607 return implementation.compileStringAsync(data, rest);
608 };
609 }
610
611 return sassOptions => new Promise((resolve, reject) => {
612 implementation.render(sassOptions, (error, result) => {
613 if (error) {
614 reject(error);
615 return;
616 }
617
618 resolve(result);
619 });
620 });
621 }
622
623 if (options.api === "modern") {
624 throw new Error("Modern API is not supported for 'node-sass'");
625 } // There is an issue with node-sass when async custom importers are used
626 // See https://github.com/sass/node-sass/issues/857#issuecomment-93594360
627 // We need to use a job queue to make sure that one thread is always available to the UV lib
628
629
630 if (nodeSassJobQueue === null) {
631 const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);
632 nodeSassJobQueue = _neoAsync.default.queue(implementation.render.bind(implementation), threadPoolSize - 1);
633 }
634
635 return sassOptions => new Promise((resolve, reject) => {
636 nodeSassJobQueue.push.bind(nodeSassJobQueue)(sassOptions, (error, result) => {
637 if (error) {
638 reject(error);
639 return;
640 }
641
642 resolve(result);
643 });
644 });
645}
646
647const ABSOLUTE_SCHEME = /^[A-Za-z0-9+\-.]+:/;
648/**
649 * @param {string} source
650 * @returns {"absolute" | "scheme-relative" | "path-absolute" | "path-absolute"}
651 */
652
653function getURLType(source) {
654 if (source[0] === "/") {
655 if (source[1] === "/") {
656 return "scheme-relative";
657 }
658
659 return "path-absolute";
660 }
661
662 if (IS_NATIVE_WIN32_PATH.test(source)) {
663 return "path-absolute";
664 }
665
666 return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
667}
668
669function normalizeSourceMap(map, rootContext) {
670 const newMap = map; // result.map.file is an optional property that provides the output filename.
671 // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
672 // eslint-disable-next-line no-param-reassign
673
674 if (typeof newMap.file !== "undefined") {
675 delete newMap.file;
676 } // eslint-disable-next-line no-param-reassign
677
678
679 newMap.sourceRoot = ""; // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
680 // This fixes an error on windows where the source-map module cannot resolve the source maps.
681 // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
682 // eslint-disable-next-line no-param-reassign
683
684 newMap.sources = newMap.sources.map(source => {
685 const sourceType = getURLType(source); // Do no touch `scheme-relative`, `path-absolute` and `absolute` types (except `file:`)
686
687 if (sourceType === "absolute" && /^file:/i.test(source)) {
688 return _url.default.fileURLToPath(source);
689 } else if (sourceType === "path-relative") {
690 return _path.default.resolve(rootContext, _path.default.normalize(source));
691 }
692
693 return source;
694 });
695 return newMap;
696}
Note: See TracBrowser for help on using the repository browser.