sass-loader 10.0.5 → 10.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -60
- package/dist/SassError.js +2 -2
- package/dist/cjs.js +1 -1
- package/dist/index.js +20 -9
- package/dist/utils.js +78 -63
- package/package.json +16 -16
- package/CHANGELOG.md +0 -528
package/dist/utils.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getRenderFunctionFromSassImplementation = getRenderFunctionFromSassImplementation;
|
|
6
7
|
exports.getSassImplementation = getSassImplementation;
|
|
7
8
|
exports.getSassOptions = getSassOptions;
|
|
8
|
-
exports.getWebpackResolver = getWebpackResolver;
|
|
9
9
|
exports.getWebpackImporter = getWebpackImporter;
|
|
10
|
-
exports.
|
|
10
|
+
exports.getWebpackResolver = getWebpackResolver;
|
|
11
|
+
exports.isSupportedFibers = isSupportedFibers;
|
|
11
12
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
12
13
|
|
|
13
14
|
var _url = _interopRequireDefault(require("url"));
|
|
@@ -25,17 +26,17 @@ var _neoAsync = _interopRequireDefault(require("neo-async"));
|
|
|
25
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
27
|
|
|
27
28
|
function getDefaultSassImplementation() {
|
|
28
|
-
let sassImplPkg =
|
|
29
|
+
let sassImplPkg = "sass";
|
|
29
30
|
|
|
30
31
|
try {
|
|
31
|
-
require.resolve(
|
|
32
|
+
require.resolve("sass");
|
|
32
33
|
} catch (error) {
|
|
33
34
|
try {
|
|
34
|
-
require.resolve(
|
|
35
|
+
require.resolve("node-sass");
|
|
35
36
|
|
|
36
|
-
sassImplPkg =
|
|
37
|
+
sassImplPkg = "node-sass";
|
|
37
38
|
} catch (ignoreError) {
|
|
38
|
-
sassImplPkg =
|
|
39
|
+
sassImplPkg = "sass";
|
|
39
40
|
}
|
|
40
41
|
} // eslint-disable-next-line import/no-dynamic-require, global-require
|
|
41
42
|
|
|
@@ -49,12 +50,16 @@ function getDefaultSassImplementation() {
|
|
|
49
50
|
*/
|
|
50
51
|
|
|
51
52
|
|
|
52
|
-
function getSassImplementation(implementation) {
|
|
53
|
+
function getSassImplementation(loaderContext, implementation) {
|
|
53
54
|
let resolvedImplementation = implementation;
|
|
54
55
|
|
|
55
56
|
if (!resolvedImplementation) {
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
try {
|
|
58
|
+
resolvedImplementation = getDefaultSassImplementation();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
loaderContext.emitError(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const {
|
|
@@ -62,44 +67,51 @@ function getSassImplementation(implementation) {
|
|
|
62
67
|
} = resolvedImplementation;
|
|
63
68
|
|
|
64
69
|
if (!info) {
|
|
65
|
-
|
|
70
|
+
loaderContext.emitError(new Error("Unknown Sass implementation."));
|
|
71
|
+
return;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
const infoParts = info.split(
|
|
74
|
+
const infoParts = info.split("\t");
|
|
69
75
|
|
|
70
76
|
if (infoParts.length < 2) {
|
|
71
|
-
|
|
77
|
+
loaderContext.emitError(new Error(`Unknown Sass implementation "${info}".`));
|
|
78
|
+
return;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
const [implementationName, version] = infoParts;
|
|
75
82
|
|
|
76
|
-
if (implementationName ===
|
|
77
|
-
if (!_semver.default.satisfies(version,
|
|
78
|
-
|
|
79
|
-
}
|
|
83
|
+
if (implementationName === "dart-sass") {
|
|
84
|
+
if (!_semver.default.satisfies(version, "^1.3.0")) {
|
|
85
|
+
loaderContext.emitError(new Error(`Dart Sass version ${version} is incompatible with ^1.3.0.`));
|
|
86
|
+
} // eslint-disable-next-line consistent-return
|
|
87
|
+
|
|
80
88
|
|
|
81
89
|
return resolvedImplementation;
|
|
82
|
-
} else if (implementationName ===
|
|
83
|
-
if (!_semver.default.satisfies(version,
|
|
84
|
-
|
|
85
|
-
}
|
|
90
|
+
} else if (implementationName === "node-sass") {
|
|
91
|
+
if (!_semver.default.satisfies(version, "^4.0.0 || ^5.0.0 || ^6.0.0")) {
|
|
92
|
+
loaderContext.emitError(new Error(`Node Sass version ${version} is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0.`));
|
|
93
|
+
} // eslint-disable-next-line consistent-return
|
|
94
|
+
|
|
86
95
|
|
|
87
96
|
return resolvedImplementation;
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
|
|
99
|
+
loaderContext.emitError(new Error(`Unknown Sass implementation "${implementationName}".`));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isSupportedFibers() {
|
|
103
|
+
const [nodeVersion] = process.versions.node.split(".");
|
|
104
|
+
return Number(nodeVersion) < 16;
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
function isProductionLikeMode(loaderContext) {
|
|
94
|
-
return loaderContext.mode ===
|
|
108
|
+
return loaderContext.mode === "production" || !loaderContext.mode;
|
|
95
109
|
}
|
|
96
110
|
|
|
97
111
|
function proxyCustomImporters(importers, loaderContext) {
|
|
98
|
-
return [].concat(importers).map(importer => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return importer.apply(this, args);
|
|
102
|
-
};
|
|
112
|
+
return [].concat(importers).map(importer => function proxyImporter(...args) {
|
|
113
|
+
this.webpackLoaderContext = loaderContext;
|
|
114
|
+
return importer.apply(this, args);
|
|
103
115
|
});
|
|
104
116
|
}
|
|
105
117
|
/**
|
|
@@ -114,18 +126,18 @@ function proxyCustomImporters(importers, loaderContext) {
|
|
|
114
126
|
*/
|
|
115
127
|
|
|
116
128
|
|
|
117
|
-
function getSassOptions(loaderContext, loaderOptions, content, implementation, useSourceMap) {
|
|
118
|
-
const options = (0, _full.klona)(loaderOptions.sassOptions ? typeof loaderOptions.sassOptions ===
|
|
119
|
-
const isDartSass = implementation.info.includes(
|
|
129
|
+
async function getSassOptions(loaderContext, loaderOptions, content, implementation, useSourceMap) {
|
|
130
|
+
const options = (0, _full.klona)(loaderOptions.sassOptions ? typeof loaderOptions.sassOptions === "function" ? loaderOptions.sassOptions(loaderContext) || {} : loaderOptions.sassOptions : {});
|
|
131
|
+
const isDartSass = implementation.info.includes("dart-sass");
|
|
120
132
|
|
|
121
|
-
if (isDartSass) {
|
|
133
|
+
if (isDartSass && isSupportedFibers()) {
|
|
122
134
|
const shouldTryToResolveFibers = !options.fiber && options.fiber !== false;
|
|
123
135
|
|
|
124
136
|
if (shouldTryToResolveFibers) {
|
|
125
137
|
let fibers;
|
|
126
138
|
|
|
127
139
|
try {
|
|
128
|
-
fibers = require.resolve(
|
|
140
|
+
fibers = require.resolve("fibers");
|
|
129
141
|
} catch (_error) {// Nothing
|
|
130
142
|
}
|
|
131
143
|
|
|
@@ -143,10 +155,10 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation, u
|
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
options.file = loaderContext.resourcePath;
|
|
146
|
-
options.data = loaderOptions.additionalData ? typeof loaderOptions.additionalData ===
|
|
158
|
+
options.data = loaderOptions.additionalData ? typeof loaderOptions.additionalData === "function" ? await loaderOptions.additionalData(content, loaderContext) : `${loaderOptions.additionalData}\n${content}` : content; // opt.outputStyle
|
|
147
159
|
|
|
148
160
|
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
|
|
149
|
-
options.outputStyle =
|
|
161
|
+
options.outputStyle = "compressed";
|
|
150
162
|
}
|
|
151
163
|
|
|
152
164
|
if (useSourceMap) {
|
|
@@ -157,7 +169,7 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation, u
|
|
|
157
169
|
// all paths in sourceMap.sources will be relative to that path.
|
|
158
170
|
// Pretty complicated... :(
|
|
159
171
|
options.sourceMap = true;
|
|
160
|
-
options.outFile = _path.default.join(loaderContext.rootContext,
|
|
172
|
+
options.outFile = _path.default.join(loaderContext.rootContext, "style.css.map");
|
|
161
173
|
options.sourceMapContents = true;
|
|
162
174
|
options.omitSourceMapUrl = true;
|
|
163
175
|
options.sourceMapEmbed = false;
|
|
@@ -170,7 +182,7 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation, u
|
|
|
170
182
|
const ext = _path.default.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it.
|
|
171
183
|
|
|
172
184
|
|
|
173
|
-
if (ext && ext.toLowerCase() ===
|
|
185
|
+
if (ext && ext.toLowerCase() === ".sass" && typeof options.indentedSyntax === "undefined") {
|
|
174
186
|
options.indentedSyntax = true;
|
|
175
187
|
} else {
|
|
176
188
|
options.indentedSyntax = Boolean(options.indentedSyntax);
|
|
@@ -178,7 +190,8 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation, u
|
|
|
178
190
|
|
|
179
191
|
|
|
180
192
|
options.importer = options.importer ? proxyCustomImporters(Array.isArray(options.importer) ? options.importer : [options.importer], loaderContext) : [];
|
|
181
|
-
options.includePaths = [].concat(process.cwd()).concat(
|
|
193
|
+
options.includePaths = [].concat(process.cwd()).concat( // We use `includePaths` in context for resolver, so it should be always absolute
|
|
194
|
+
(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" ? ";" : ":") : []);
|
|
182
195
|
return options;
|
|
183
196
|
} // Examples:
|
|
184
197
|
// - ~package
|
|
@@ -226,7 +239,7 @@ url, forWebpackResolver = false, rootContext = false) {
|
|
|
226
239
|
// The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
|
|
227
240
|
|
|
228
241
|
|
|
229
|
-
if (ext ===
|
|
242
|
+
if (ext === ".css") {
|
|
230
243
|
return [];
|
|
231
244
|
}
|
|
232
245
|
|
|
@@ -306,29 +319,29 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
321
|
|
|
309
|
-
const isDartSass = implementation.info.includes(
|
|
322
|
+
const isDartSass = implementation.info.includes("dart-sass");
|
|
310
323
|
const sassResolve = promiseResolve(resolverFactory({
|
|
311
324
|
alias: [],
|
|
312
325
|
aliasFields: [],
|
|
313
326
|
conditionNames: [],
|
|
314
327
|
descriptionFiles: [],
|
|
315
|
-
extensions: [
|
|
328
|
+
extensions: [".sass", ".scss", ".css"],
|
|
316
329
|
exportsFields: [],
|
|
317
330
|
mainFields: [],
|
|
318
|
-
mainFiles: [
|
|
331
|
+
mainFiles: ["_index", "index"],
|
|
319
332
|
modules: [],
|
|
320
333
|
restrictions: [/\.((sa|sc|c)ss)$/i]
|
|
321
334
|
}));
|
|
322
335
|
const webpackResolve = promiseResolve(resolverFactory({
|
|
323
|
-
conditionNames: [
|
|
324
|
-
mainFields: [
|
|
325
|
-
mainFiles: [
|
|
326
|
-
extensions: [
|
|
336
|
+
conditionNames: ["sass", "style"],
|
|
337
|
+
mainFields: ["sass", "style", "main", "..."],
|
|
338
|
+
mainFiles: ["_index", "index", "..."],
|
|
339
|
+
extensions: [".sass", ".scss", ".css"],
|
|
327
340
|
restrictions: [/\.((sa|sc|c)ss)$/i]
|
|
328
341
|
}));
|
|
329
342
|
return (context, request) => {
|
|
330
343
|
const originalRequest = request;
|
|
331
|
-
const isFileScheme = originalRequest.slice(0, 5).toLowerCase() ===
|
|
344
|
+
const isFileScheme = originalRequest.slice(0, 5).toLowerCase() === "file:";
|
|
332
345
|
|
|
333
346
|
if (isFileScheme) {
|
|
334
347
|
try {
|
|
@@ -346,7 +359,7 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
346
359
|
// Absolute paths should be resolved:
|
|
347
360
|
// - Server-relative URLs - `<context>/path/to/file.ext` (where `<context>` is root context)
|
|
348
361
|
// - Absolute path - `/full/path/to/file.ext` or `C:\\full\path\to\file.ext`
|
|
349
|
-
!isFileScheme && !originalRequest.startsWith(
|
|
362
|
+
!isFileScheme && !originalRequest.startsWith("/") && !IS_NATIVE_WIN32_PATH.test(originalRequest);
|
|
350
363
|
|
|
351
364
|
if (includePaths.length > 0 && needEmulateSassResolver) {
|
|
352
365
|
// The order of import precedence is as follows:
|
|
@@ -369,11 +382,13 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
369
382
|
}
|
|
370
383
|
|
|
371
384
|
resolutionMap = resolutionMap.concat( // eslint-disable-next-line no-shadow
|
|
372
|
-
includePaths.map(context =>
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
385
|
+
includePaths.map(context => {
|
|
386
|
+
return {
|
|
387
|
+
resolve: sassResolve,
|
|
388
|
+
context,
|
|
389
|
+
possibleRequests: sassPossibleRequests
|
|
390
|
+
};
|
|
391
|
+
}));
|
|
377
392
|
}
|
|
378
393
|
|
|
379
394
|
const webpackPossibleRequests = getPossibleRequests(request, true, rootContext);
|
|
@@ -398,7 +413,7 @@ function getWebpackImporter(loaderContext, implementation, includePaths) {
|
|
|
398
413
|
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.
|
|
399
414
|
|
|
400
415
|
done({
|
|
401
|
-
file: result.replace(matchCss,
|
|
416
|
+
file: result.replace(matchCss, "")
|
|
402
417
|
});
|
|
403
418
|
}) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
|
|
404
419
|
.catch(() => {
|
|
@@ -418,7 +433,7 @@ let nodeSassJobQueue = null;
|
|
|
418
433
|
*/
|
|
419
434
|
|
|
420
435
|
function getRenderFunctionFromSassImplementation(implementation) {
|
|
421
|
-
const isDartSass = implementation.info.includes(
|
|
436
|
+
const isDartSass = implementation.info.includes("dart-sass");
|
|
422
437
|
|
|
423
438
|
if (isDartSass) {
|
|
424
439
|
return implementation.render.bind(implementation);
|
|
@@ -438,19 +453,19 @@ function getRenderFunctionFromSassImplementation(implementation) {
|
|
|
438
453
|
const ABSOLUTE_SCHEME = /^[A-Za-z0-9+\-.]+:/;
|
|
439
454
|
|
|
440
455
|
function getURLType(source) {
|
|
441
|
-
if (source[0] ===
|
|
442
|
-
if (source[1] ===
|
|
443
|
-
return
|
|
456
|
+
if (source[0] === "/") {
|
|
457
|
+
if (source[1] === "/") {
|
|
458
|
+
return "scheme-relative";
|
|
444
459
|
}
|
|
445
460
|
|
|
446
|
-
return
|
|
461
|
+
return "path-absolute";
|
|
447
462
|
}
|
|
448
463
|
|
|
449
464
|
if (IS_NATIVE_WIN32_PATH.test(source)) {
|
|
450
|
-
return
|
|
465
|
+
return "path-absolute";
|
|
451
466
|
}
|
|
452
467
|
|
|
453
|
-
return ABSOLUTE_SCHEME.test(source) ?
|
|
468
|
+
return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
|
|
454
469
|
}
|
|
455
470
|
|
|
456
471
|
function normalizeSourceMap(map, rootContext) {
|
|
@@ -460,7 +475,7 @@ function normalizeSourceMap(map, rootContext) {
|
|
|
460
475
|
|
|
461
476
|
delete newMap.file; // eslint-disable-next-line no-param-reassign
|
|
462
477
|
|
|
463
|
-
newMap.sourceRoot =
|
|
478
|
+
newMap.sourceRoot = ""; // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
|
|
464
479
|
// This fixes an error on windows where the source-map module cannot resolve the source maps.
|
|
465
480
|
// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
|
|
466
481
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -468,7 +483,7 @@ function normalizeSourceMap(map, rootContext) {
|
|
|
468
483
|
newMap.sources = newMap.sources.map(source => {
|
|
469
484
|
const sourceType = getURLType(source); // Do no touch `scheme-relative`, `path-absolute` and `absolute` types
|
|
470
485
|
|
|
471
|
-
if (sourceType ===
|
|
486
|
+
if (sourceType === "path-relative") {
|
|
472
487
|
return _path.default.resolve(rootContext, _path.default.normalize(source));
|
|
473
488
|
}
|
|
474
489
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sass-loader",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.1",
|
|
4
4
|
"description": "Sass loader for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/sass-loader",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"
|
|
43
|
-
"node-sass": "^4.0.0 || ^5.0.0",
|
|
42
|
+
"fibers": ">= 3.1.0",
|
|
43
|
+
"node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
44
44
|
"sass": "^1.3.0",
|
|
45
|
-
"
|
|
45
|
+
"webpack": "^4.36.0 || ^5.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"node-sass": {
|
|
@@ -70,32 +70,32 @@
|
|
|
70
70
|
"@commitlint/config-conventional": "^11.0.0",
|
|
71
71
|
"@webpack-contrib/defaults": "^6.3.0",
|
|
72
72
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
73
|
-
"babel-jest": "^26.6.
|
|
73
|
+
"babel-jest": "^26.6.3",
|
|
74
74
|
"bootstrap": "^4.5.3",
|
|
75
75
|
"bootstrap-sass": "^3.4.1",
|
|
76
76
|
"cross-env": "^7.0.2",
|
|
77
|
-
"css-loader": "^5.0.
|
|
77
|
+
"css-loader": "^5.0.1",
|
|
78
78
|
"del": "^6.0.0",
|
|
79
79
|
"del-cli": "^3.0.1",
|
|
80
|
-
"enhanced-resolve": "^5.
|
|
81
|
-
"eslint": "^7.
|
|
82
|
-
"eslint-config-prettier": "^
|
|
80
|
+
"enhanced-resolve": "^5.5.0",
|
|
81
|
+
"eslint": "^7.13.0",
|
|
82
|
+
"eslint-config-prettier": "^7.1.0",
|
|
83
83
|
"eslint-plugin-import": "^2.22.1",
|
|
84
84
|
"fibers": "^5.0.0",
|
|
85
|
-
"file-loader": "^6.
|
|
85
|
+
"file-loader": "^6.2.0",
|
|
86
86
|
"foundation-sites": "^6.6.3",
|
|
87
87
|
"husky": "^4.3.0",
|
|
88
|
-
"jest": "^26.6.
|
|
89
|
-
"lint-staged": "^10.
|
|
90
|
-
"material-components-web": "^
|
|
88
|
+
"jest": "^26.6.3",
|
|
89
|
+
"lint-staged": "^10.5.1",
|
|
90
|
+
"material-components-web": "^8.0.0",
|
|
91
91
|
"memfs": "^3.2.0",
|
|
92
|
-
"node-sass": "^
|
|
92
|
+
"node-sass": "^6.0.1",
|
|
93
93
|
"npm-run-all": "^4.1.5",
|
|
94
94
|
"prettier": "^2.1.2",
|
|
95
|
-
"sass": "^1.
|
|
95
|
+
"sass": "^1.29.0",
|
|
96
96
|
"standard-version": "^9.0.0",
|
|
97
97
|
"style-loader": "^2.0.0",
|
|
98
|
-
"webpack": "^5.2
|
|
98
|
+
"webpack": "^5.12.2"
|
|
99
99
|
},
|
|
100
100
|
"keywords": [
|
|
101
101
|
"sass",
|