Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve sources checks #883

Merged
merged 1 commit into from Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/utils.js
Expand Up @@ -162,7 +162,7 @@ function getSassOptions(
// options.sourceMapRoot = process.cwd();
options.sourceMapContents = true;
options.omitSourceMapUrl = true;
// options.sourceMapEmbed = false;
options.sourceMapEmbed = false;
}

const { resourcePath } = loaderContext;
Expand Down Expand Up @@ -270,16 +270,19 @@ function getPossibleRequests(
function promiseResolve(callbackResolve) {
return (context, request) =>
new Promise((resolve, reject) => {
callbackResolve(context, request, (err, result) => {
if (err) reject(err);
else resolve(result);
callbackResolve(context, request, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
}

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

/**
* @public
Expand Down Expand Up @@ -373,14 +376,14 @@ function getWebpackResolver(

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

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

if (IS_NATIVE_WIN32_PATH.test(source)) {
return 'path-absolute';
}

return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
}

Expand Down