Skip to content

Commit 32491c1

Browse files
refactor: improve sources checks (#883)
1 parent 7d8b8ab commit 32491c1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/utils.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function getSassOptions(
162162
// options.sourceMapRoot = process.cwd();
163163
options.sourceMapContents = true;
164164
options.omitSourceMapUrl = true;
165-
// options.sourceMapEmbed = false;
165+
options.sourceMapEmbed = false;
166166
}
167167

168168
const { resourcePath } = loaderContext;
@@ -270,16 +270,19 @@ function getPossibleRequests(
270270
function promiseResolve(callbackResolve) {
271271
return (context, request) =>
272272
new Promise((resolve, reject) => {
273-
callbackResolve(context, request, (err, result) => {
274-
if (err) reject(err);
275-
else resolve(result);
273+
callbackResolve(context, request, (error, result) => {
274+
if (error) {
275+
reject(error);
276+
} else {
277+
resolve(result);
278+
}
276279
});
277280
});
278281
}
279282

280-
const isSpecialModuleImport = /^~[^/]+$/;
283+
const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/;
281284
// `[drive_letter]:\` + `\\[server]\[sharename]\`
282-
const isNativeWin32Path = /^[a-zA-Z]:[/\\]|^\\\\/i;
285+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
283286

284287
/**
285288
* @public
@@ -373,14 +376,14 @@ function getWebpackResolver(
373376

374377
const needEmulateSassResolver =
375378
// `sass` doesn't support module import
376-
!isSpecialModuleImport.test(request) &&
379+
!IS_SPECIAL_MODULE_IMPORT.test(request) &&
377380
// We need improve absolute paths handling.
378381
// Absolute paths should be resolved:
379382
// - Server-relative URLs - `<context>/path/to/file.ext` (where `<context>` is root context)
380383
// - Absolute path - `/full/path/to/file.ext` or `C:\\full\path\to\file.ext`
381384
!isFileScheme &&
382385
!originalRequest.startsWith('/') &&
383-
!isNativeWin32Path.test(originalRequest);
386+
!IS_NATIVE_WIN32_PATH.test(originalRequest);
384387

385388
if (includePaths.length > 0 && needEmulateSassResolver) {
386389
// The order of import precedence is as follows:
@@ -497,6 +500,10 @@ function getURLType(source) {
497500
return 'path-absolute';
498501
}
499502

503+
if (IS_NATIVE_WIN32_PATH.test(source)) {
504+
return 'path-absolute';
505+
}
506+
500507
return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
501508
}
502509

0 commit comments

Comments
 (0)