sass-loader 10.4.0 → 10.5.0
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/dist/SassError.js +5 -7
- package/dist/cjs.js +0 -1
- package/dist/index.js +4 -19
- package/dist/utils.js +68 -109
- package/package.json +2 -2
package/dist/SassError.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
class SassError extends Error {
|
|
9
8
|
constructor(sassError) {
|
|
10
9
|
super();
|
|
@@ -13,20 +12,19 @@ class SassError extends Error {
|
|
|
13
12
|
this.loc = {
|
|
14
13
|
line: sassError.line,
|
|
15
14
|
column: sassError.column
|
|
16
|
-
};
|
|
15
|
+
};
|
|
17
16
|
|
|
17
|
+
// Keep original error if `sassError.formatted` is unavailable
|
|
18
18
|
this.message = `${this.name}: ${this.originalSassError.message}`;
|
|
19
|
-
|
|
20
19
|
if (this.originalSassError.formatted) {
|
|
21
|
-
this.message = `${this.name}: ${this.originalSassError.formatted.replace(/^Error: /, "")}`;
|
|
22
|
-
// Usually you're only interested in the SASS stack in this case.
|
|
20
|
+
this.message = `${this.name}: ${this.originalSassError.formatted.replace(/^Error: /, "")}`;
|
|
23
21
|
|
|
22
|
+
// Instruct webpack to hide the JS stack from the console.
|
|
23
|
+
// Usually you're only interested in the SASS stack in this case.
|
|
24
24
|
this.hideStack = true;
|
|
25
25
|
Error.captureStackTrace(this, this.constructor);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
var _default = SassError;
|
|
32
30
|
exports.default = _default;
|
package/dist/cjs.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _schemaUtils = require("schema-utils");
|
|
11
|
-
|
|
12
9
|
var _loaderUtils = require("loader-utils");
|
|
13
|
-
|
|
14
10
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
15
|
-
|
|
16
11
|
var _utils = require("./utils");
|
|
17
|
-
|
|
18
12
|
var _SassError = _interopRequireDefault(require("./SassError"));
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* The sass-loader makes node-sass and dart-sass available to webpack modules.
|
|
24
16
|
*
|
|
@@ -33,23 +25,19 @@ async function loader(content) {
|
|
|
33
25
|
});
|
|
34
26
|
const callback = this.async();
|
|
35
27
|
const implementation = (0, _utils.getSassImplementation)(this, options.implementation);
|
|
36
|
-
|
|
37
28
|
if (!implementation) {
|
|
38
29
|
callback();
|
|
39
30
|
return;
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
|
43
33
|
const sassOptions = await (0, _utils.getSassOptions)(this, options, content, implementation, useSourceMap);
|
|
44
34
|
const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
|
|
45
|
-
|
|
46
35
|
if (shouldUseWebpackImporter) {
|
|
47
36
|
const {
|
|
48
37
|
includePaths
|
|
49
38
|
} = sassOptions;
|
|
50
39
|
sassOptions.importer.push((0, _utils.getWebpackImporter)(this, implementation, includePaths));
|
|
51
40
|
}
|
|
52
|
-
|
|
53
41
|
const render = (0, _utils.getRenderFunctionFromSassImplementation)(implementation);
|
|
54
42
|
render(sassOptions, (error, result) => {
|
|
55
43
|
if (error) {
|
|
@@ -58,21 +46,19 @@ async function loader(content) {
|
|
|
58
46
|
// `node-sass` returns POSIX paths
|
|
59
47
|
this.addDependency(_path.default.normalize(error.file));
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
callback(new _SassError.default(error));
|
|
63
50
|
return;
|
|
64
51
|
}
|
|
52
|
+
let map = result.map ? JSON.parse(result.map) : null;
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
// Modify source paths only for webpack, otherwise we do nothing
|
|
68
55
|
if (map && useSourceMap) {
|
|
69
56
|
map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
result.stats.includedFiles.forEach(includedFile => {
|
|
73
|
-
const normalizedIncludedFile = _path.default.normalize(includedFile);
|
|
74
|
-
|
|
59
|
+
const normalizedIncludedFile = _path.default.normalize(includedFile);
|
|
75
60
|
|
|
61
|
+
// Custom `importer` can return only `contents` so includedFile will be relative
|
|
76
62
|
if (_path.default.isAbsolute(normalizedIncludedFile)) {
|
|
77
63
|
this.addDependency(normalizedIncludedFile);
|
|
78
64
|
}
|
|
@@ -80,6 +66,5 @@ async function loader(content) {
|
|
|
80
66
|
callback(null, result.css.toString(), map);
|
|
81
67
|
});
|
|
82
68
|
}
|
|
83
|
-
|
|
84
69
|
var _default = loader;
|
|
85
70
|
exports.default = _default;
|
package/dist/utils.js
CHANGED
|
@@ -10,49 +10,37 @@ exports.getWebpackImporter = getWebpackImporter;
|
|
|
10
10
|
exports.getWebpackResolver = getWebpackResolver;
|
|
11
11
|
exports.isSupportedFibers = isSupportedFibers;
|
|
12
12
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
13
|
-
|
|
14
13
|
var _url = _interopRequireDefault(require("url"));
|
|
15
|
-
|
|
16
14
|
var _path = _interopRequireDefault(require("path"));
|
|
17
|
-
|
|
18
15
|
var _semver = _interopRequireDefault(require("semver"));
|
|
19
|
-
|
|
20
16
|
var _full = require("klona/full");
|
|
21
|
-
|
|
22
17
|
var _loaderUtils = require("loader-utils");
|
|
23
|
-
|
|
24
18
|
var _neoAsync = _interopRequireDefault(require("neo-async"));
|
|
25
|
-
|
|
26
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
20
|
function getDefaultSassImplementation() {
|
|
29
21
|
let sassImplPkg = "sass";
|
|
30
|
-
|
|
31
22
|
try {
|
|
32
23
|
require.resolve("sass");
|
|
33
24
|
} catch (error) {
|
|
34
25
|
try {
|
|
35
26
|
require.resolve("node-sass");
|
|
36
|
-
|
|
37
27
|
sassImplPkg = "node-sass";
|
|
38
28
|
} catch (ignoreError) {
|
|
39
29
|
sassImplPkg = "sass";
|
|
40
30
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
31
|
+
}
|
|
43
32
|
|
|
33
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
44
34
|
return require(sassImplPkg);
|
|
45
35
|
}
|
|
36
|
+
|
|
46
37
|
/**
|
|
47
38
|
* @public
|
|
48
39
|
* This function is not Webpack-specific and can be used by tools wishing to
|
|
49
40
|
* mimic `sass-loader`'s behaviour, so its signature should not be changed.
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
42
|
function getSassImplementation(loaderContext, implementation) {
|
|
54
43
|
let resolvedImplementation = implementation;
|
|
55
|
-
|
|
56
44
|
if (!resolvedImplementation) {
|
|
57
45
|
try {
|
|
58
46
|
resolvedImplementation = getDefaultSassImplementation();
|
|
@@ -61,59 +49,53 @@ function getSassImplementation(loaderContext, implementation) {
|
|
|
61
49
|
return;
|
|
62
50
|
}
|
|
63
51
|
}
|
|
64
|
-
|
|
65
52
|
const {
|
|
66
53
|
info
|
|
67
54
|
} = resolvedImplementation;
|
|
68
|
-
|
|
69
55
|
if (!info) {
|
|
70
56
|
loaderContext.emitError(new Error("Unknown Sass implementation."));
|
|
71
57
|
return;
|
|
72
58
|
}
|
|
73
|
-
|
|
74
59
|
const infoParts = info.split("\t");
|
|
75
|
-
|
|
76
60
|
if (infoParts.length < 2) {
|
|
77
61
|
loaderContext.emitError(new Error(`Unknown Sass implementation "${info}".`));
|
|
78
62
|
return;
|
|
79
63
|
}
|
|
80
|
-
|
|
81
64
|
const [implementationName, version] = infoParts;
|
|
82
|
-
|
|
83
65
|
if (implementationName === "dart-sass") {
|
|
84
66
|
if (!_semver.default.satisfies(version, "^1.3.0")) {
|
|
85
67
|
loaderContext.emitError(new Error(`Dart Sass version ${version} is incompatible with ^1.3.0.`));
|
|
86
|
-
}
|
|
87
|
-
|
|
68
|
+
}
|
|
88
69
|
|
|
70
|
+
// eslint-disable-next-line consistent-return
|
|
89
71
|
return resolvedImplementation;
|
|
90
72
|
} else if (implementationName === "node-sass") {
|
|
91
|
-
if (!_semver.default.satisfies(version, "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0")) {
|
|
92
|
-
loaderContext.emitError(new Error(`Node Sass version ${version} is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0.`));
|
|
93
|
-
}
|
|
94
|
-
|
|
73
|
+
if (!_semver.default.satisfies(version, "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0")) {
|
|
74
|
+
loaderContext.emitError(new Error(`Node Sass version ${version} is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0.`));
|
|
75
|
+
}
|
|
95
76
|
|
|
77
|
+
// eslint-disable-next-line consistent-return
|
|
78
|
+
return resolvedImplementation;
|
|
79
|
+
} else if (implementationName === "sass-embedded") {
|
|
80
|
+
// eslint-disable-next-line consistent-return
|
|
96
81
|
return resolvedImplementation;
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
loaderContext.emitError(new Error(`Unknown Sass implementation "${implementationName}".`));
|
|
100
84
|
}
|
|
101
|
-
|
|
102
85
|
function isSupportedFibers() {
|
|
103
86
|
const [nodeVersion] = process.versions.node.split(".");
|
|
104
87
|
return Number(nodeVersion) < 16;
|
|
105
88
|
}
|
|
106
|
-
|
|
107
89
|
function isProductionLikeMode(loaderContext) {
|
|
108
90
|
return loaderContext.mode === "production" || !loaderContext.mode;
|
|
109
91
|
}
|
|
110
|
-
|
|
111
92
|
function proxyCustomImporters(importers, loaderContext) {
|
|
112
93
|
return [].concat(importers).map(importer => function proxyImporter(...args) {
|
|
113
94
|
this.webpackLoaderContext = loaderContext;
|
|
114
95
|
return importer.apply(this, args);
|
|
115
96
|
});
|
|
116
97
|
}
|
|
98
|
+
|
|
117
99
|
/**
|
|
118
100
|
* Derives the sass options from the loader context and normalizes its values with sane defaults.
|
|
119
101
|
*
|
|
@@ -124,23 +106,18 @@ function proxyCustomImporters(importers, loaderContext) {
|
|
|
124
106
|
* @param {boolean} useSourceMap
|
|
125
107
|
* @returns {Object}
|
|
126
108
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
109
|
async function getSassOptions(loaderContext, loaderOptions, content, implementation, useSourceMap) {
|
|
130
110
|
const options = (0, _full.klona)(loaderOptions.sassOptions ? typeof loaderOptions.sassOptions === "function" ? loaderOptions.sassOptions(loaderContext) || {} : loaderOptions.sassOptions : {});
|
|
131
111
|
const isDartSass = implementation.info.includes("dart-sass");
|
|
132
|
-
|
|
133
112
|
if (isDartSass && isSupportedFibers()) {
|
|
134
113
|
const shouldTryToResolveFibers = !options.fiber && options.fiber !== false;
|
|
135
|
-
|
|
136
114
|
if (shouldTryToResolveFibers) {
|
|
137
115
|
let fibers;
|
|
138
|
-
|
|
139
116
|
try {
|
|
140
117
|
fibers = require.resolve("fibers");
|
|
141
|
-
} catch (_error) {
|
|
118
|
+
} catch (_error) {
|
|
119
|
+
// Nothing
|
|
142
120
|
}
|
|
143
|
-
|
|
144
121
|
if (fibers) {
|
|
145
122
|
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
146
123
|
options.fiber = require(fibers);
|
|
@@ -153,14 +130,13 @@ async function getSassOptions(loaderContext, loaderOptions, content, implementat
|
|
|
153
130
|
// Don't pass the `fiber` option for `node-sass`
|
|
154
131
|
delete options.fiber;
|
|
155
132
|
}
|
|
156
|
-
|
|
157
133
|
options.file = loaderContext.resourcePath;
|
|
158
|
-
options.data = loaderOptions.additionalData ? typeof loaderOptions.additionalData === "function" ? await loaderOptions.additionalData(content, loaderContext) : `${loaderOptions.additionalData}\n${content}` : content;
|
|
134
|
+
options.data = loaderOptions.additionalData ? typeof loaderOptions.additionalData === "function" ? await loaderOptions.additionalData(content, loaderContext) : `${loaderOptions.additionalData}\n${content}` : content;
|
|
159
135
|
|
|
136
|
+
// opt.outputStyle
|
|
160
137
|
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
|
|
161
138
|
options.outputStyle = "compressed";
|
|
162
139
|
}
|
|
163
|
-
|
|
164
140
|
if (useSourceMap) {
|
|
165
141
|
// Deliberately overriding the sourceMap option here.
|
|
166
142
|
// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
|
|
@@ -174,35 +150,35 @@ async function getSassOptions(loaderContext, loaderOptions, content, implementat
|
|
|
174
150
|
options.omitSourceMapUrl = true;
|
|
175
151
|
options.sourceMapEmbed = false;
|
|
176
152
|
}
|
|
177
|
-
|
|
178
153
|
const {
|
|
179
154
|
resourcePath
|
|
180
155
|
} = loaderContext;
|
|
156
|
+
const ext = _path.default.extname(resourcePath);
|
|
181
157
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
// If we are compiling sass and indentedSyntax isn't set, automatically set it.
|
|
185
159
|
if (ext && ext.toLowerCase() === ".sass" && typeof options.indentedSyntax === "undefined") {
|
|
186
160
|
options.indentedSyntax = true;
|
|
187
161
|
} else {
|
|
188
162
|
options.indentedSyntax = Boolean(options.indentedSyntax);
|
|
189
|
-
}
|
|
190
|
-
|
|
163
|
+
}
|
|
191
164
|
|
|
165
|
+
// Allow passing custom importers to `sass`/`node-sass`. Accepts `Function` or an array of `Function`s.
|
|
192
166
|
options.importer = options.importer ? proxyCustomImporters(Array.isArray(options.importer) ? options.importer : [options.importer], loaderContext) : [];
|
|
193
|
-
options.includePaths = [].concat(process.cwd()).concat(
|
|
167
|
+
options.includePaths = [].concat(process.cwd()).concat(
|
|
168
|
+
// We use `includePaths` in context for resolver, so it should be always absolute
|
|
194
169
|
(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" ? ";" : ":") : []);
|
|
195
170
|
return options;
|
|
196
|
-
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Examples:
|
|
197
174
|
// - ~package
|
|
198
175
|
// - ~package/
|
|
199
176
|
// - ~@org
|
|
200
177
|
// - ~@org/
|
|
201
178
|
// - ~@org/package
|
|
202
179
|
// - ~@org/package/
|
|
203
|
-
|
|
204
|
-
|
|
205
180
|
const isModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
|
|
181
|
+
|
|
206
182
|
/**
|
|
207
183
|
* When `sass`/`node-sass` tries to resolve an import, it uses a special algorithm.
|
|
208
184
|
* Since the `sass-loader` uses webpack to resolve the modules, we need to simulate that algorithm.
|
|
@@ -217,19 +193,23 @@ const isModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+
|
|
|
217
193
|
* @param {string} rootContext
|
|
218
194
|
* @returns {Array<string>}
|
|
219
195
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
196
|
+
function getPossibleRequests(
|
|
197
|
+
// eslint-disable-next-line no-shadow
|
|
222
198
|
url, forWebpackResolver = false, rootContext = false) {
|
|
223
|
-
const request = (0, _loaderUtils.urlToRequest)(url,
|
|
224
|
-
|
|
199
|
+
const request = (0, _loaderUtils.urlToRequest)(url,
|
|
200
|
+
// Maybe it is server-relative URLs
|
|
201
|
+
forWebpackResolver && rootContext);
|
|
225
202
|
|
|
203
|
+
// In case there is module request, send this to webpack resolver
|
|
226
204
|
if (forWebpackResolver && isModuleImport.test(url)) {
|
|
227
205
|
return [...new Set([request, url])];
|
|
228
|
-
}
|
|
229
|
-
// @see https://github.com/webpack-contrib/sass-loader/issues/167
|
|
206
|
+
}
|
|
230
207
|
|
|
208
|
+
// Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
|
|
209
|
+
// @see https://github.com/webpack-contrib/sass-loader/issues/167
|
|
210
|
+
const ext = _path.default.extname(request).toLowerCase();
|
|
231
211
|
|
|
232
|
-
|
|
212
|
+
// 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.
|
|
233
213
|
// 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:
|
|
234
214
|
// - imports where the URL ends with .css.
|
|
235
215
|
// - imports where the URL begins http:// or https://.
|
|
@@ -237,19 +217,13 @@ url, forWebpackResolver = false, rootContext = false) {
|
|
|
237
217
|
// - imports that have media queries.
|
|
238
218
|
//
|
|
239
219
|
// The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
|
|
240
|
-
|
|
241
|
-
|
|
242
220
|
if (ext === ".css") {
|
|
243
221
|
return [];
|
|
244
222
|
}
|
|
245
|
-
|
|
246
223
|
const dirname = _path.default.dirname(request);
|
|
247
|
-
|
|
248
224
|
const basename = _path.default.basename(request);
|
|
249
|
-
|
|
250
225
|
return [...new Set([`${dirname}/_${basename}`, request].concat(forWebpackResolver ? [`${_path.default.dirname(url)}/_${basename}`, url] : []))];
|
|
251
226
|
}
|
|
252
|
-
|
|
253
227
|
function promiseResolve(callbackResolve) {
|
|
254
228
|
return (context, request) => new Promise((resolve, reject) => {
|
|
255
229
|
callbackResolve(context, request, (error, result) => {
|
|
@@ -261,10 +235,10 @@ function promiseResolve(callbackResolve) {
|
|
|
261
235
|
});
|
|
262
236
|
});
|
|
263
237
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
238
|
+
const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/;
|
|
239
|
+
// `[drive_letter]:\` + `\\[server]\[sharename]\`
|
|
267
240
|
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
241
|
+
|
|
268
242
|
/**
|
|
269
243
|
* @public
|
|
270
244
|
* Create the resolve function used in the custom Sass importer.
|
|
@@ -283,42 +257,35 @@ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
|
283
257
|
*
|
|
284
258
|
* @throws If a compatible Sass implementation cannot be found.
|
|
285
259
|
*/
|
|
286
|
-
|
|
287
260
|
function getWebpackResolver(resolverFactory, implementation, includePaths = [], rootContext = false) {
|
|
288
261
|
async function startResolving(resolutionMap) {
|
|
289
262
|
if (resolutionMap.length === 0) {
|
|
290
263
|
return Promise.reject();
|
|
291
264
|
}
|
|
292
|
-
|
|
293
265
|
const [{
|
|
294
266
|
possibleRequests
|
|
295
267
|
}] = resolutionMap;
|
|
296
|
-
|
|
297
268
|
if (possibleRequests.length === 0) {
|
|
298
269
|
return Promise.reject();
|
|
299
270
|
}
|
|
300
|
-
|
|
301
271
|
const [{
|
|
302
272
|
resolve,
|
|
303
273
|
context
|
|
304
274
|
}] = resolutionMap;
|
|
305
|
-
|
|
306
275
|
try {
|
|
307
276
|
return await resolve(context, possibleRequests[0]);
|
|
308
277
|
} catch (_ignoreError) {
|
|
309
278
|
const [, ...tailResult] = possibleRequests;
|
|
310
|
-
|
|
311
279
|
if (tailResult.length === 0) {
|
|
312
280
|
const [, ...tailResolutionMap] = resolutionMap;
|
|
313
281
|
return startResolving(tailResolutionMap);
|
|
314
|
-
}
|
|
315
|
-
|
|
282
|
+
}
|
|
316
283
|
|
|
284
|
+
// eslint-disable-next-line no-param-reassign
|
|
317
285
|
resolutionMap[0].possibleRequests = tailResult;
|
|
318
286
|
return startResolving(resolutionMap);
|
|
319
287
|
}
|
|
320
288
|
}
|
|
321
|
-
|
|
322
289
|
const isDartSass = implementation.info.includes("dart-sass");
|
|
323
290
|
const sassResolve = promiseResolve(resolverFactory({
|
|
324
291
|
alias: [],
|
|
@@ -342,7 +309,6 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
342
309
|
return (context, request) => {
|
|
343
310
|
const originalRequest = request;
|
|
344
311
|
const isFileScheme = originalRequest.slice(0, 5).toLowerCase() === "file:";
|
|
345
|
-
|
|
346
312
|
if (isFileScheme) {
|
|
347
313
|
try {
|
|
348
314
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -352,15 +318,15 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
352
318
|
request = request.slice(7);
|
|
353
319
|
}
|
|
354
320
|
}
|
|
355
|
-
|
|
356
321
|
let resolutionMap = [];
|
|
357
|
-
const needEmulateSassResolver =
|
|
358
|
-
|
|
322
|
+
const needEmulateSassResolver =
|
|
323
|
+
// `sass` doesn't support module import
|
|
324
|
+
!IS_SPECIAL_MODULE_IMPORT.test(request) &&
|
|
325
|
+
// We need improve absolute paths handling.
|
|
359
326
|
// Absolute paths should be resolved:
|
|
360
327
|
// - Server-relative URLs - `<context>/path/to/file.ext` (where `<context>` is root context)
|
|
361
328
|
// - Absolute path - `/full/path/to/file.ext` or `C:\\full\path\to\file.ext`
|
|
362
329
|
!isFileScheme && !originalRequest.startsWith("/") && !IS_NATIVE_WIN32_PATH.test(originalRequest);
|
|
363
|
-
|
|
364
330
|
if (includePaths.length > 0 && needEmulateSassResolver) {
|
|
365
331
|
// The order of import precedence is as follows:
|
|
366
332
|
//
|
|
@@ -371,8 +337,9 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
371
337
|
// 5. Filesystem imports relative to a `SASS_PATH` path.
|
|
372
338
|
//
|
|
373
339
|
// Because `sass`/`node-sass` run custom importers before `3`, `4` and `5` points, we need to emulate this behavior to avoid wrong resolution.
|
|
374
|
-
const sassPossibleRequests = getPossibleRequests(request);
|
|
340
|
+
const sassPossibleRequests = getPossibleRequests(request);
|
|
375
341
|
|
|
342
|
+
// `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`, so we need emulate this too
|
|
376
343
|
if (!isDartSass) {
|
|
377
344
|
resolutionMap = resolutionMap.concat({
|
|
378
345
|
resolve: sassResolve,
|
|
@@ -380,8 +347,8 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
380
347
|
possibleRequests: sassPossibleRequests
|
|
381
348
|
});
|
|
382
349
|
}
|
|
383
|
-
|
|
384
|
-
|
|
350
|
+
resolutionMap = resolutionMap.concat(
|
|
351
|
+
// eslint-disable-next-line no-shadow
|
|
385
352
|
includePaths.map(context => {
|
|
386
353
|
return {
|
|
387
354
|
resolve: sassResolve,
|
|
@@ -390,7 +357,6 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
390
357
|
};
|
|
391
358
|
}));
|
|
392
359
|
}
|
|
393
|
-
|
|
394
360
|
const webpackPossibleRequests = getPossibleRequests(request, true, rootContext);
|
|
395
361
|
resolutionMap = resolutionMap.concat({
|
|
396
362
|
resolve: webpackResolve,
|
|
@@ -400,9 +366,7 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [],
|
|
|
400
366
|
return startResolving(resolutionMap);
|
|
401
367
|
};
|
|
402
368
|
}
|
|
403
|
-
|
|
404
369
|
const matchCss = /\.css$/i;
|
|
405
|
-
|
|
406
370
|
function getWebpackImporter(loaderContext, implementation, includePaths) {
|
|
407
371
|
const resolve = getWebpackResolver(loaderContext.getResolve, implementation, includePaths, loaderContext.rootContext);
|
|
408
372
|
return (originalUrl, prev, done) => {
|
|
@@ -410,12 +374,13 @@ function getWebpackImporter(loaderContext, implementation, includePaths) {
|
|
|
410
374
|
// Add the result as dependency.
|
|
411
375
|
// Although we're also using stats.includedFiles, this might come in handy when an error occurs.
|
|
412
376
|
// In this case, we don't get stats.includedFiles from node-sass/sass.
|
|
413
|
-
loaderContext.addDependency(_path.default.normalize(result));
|
|
414
|
-
|
|
377
|
+
loaderContext.addDependency(_path.default.normalize(result));
|
|
378
|
+
// By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
|
|
415
379
|
done({
|
|
416
380
|
file: result.replace(matchCss, "")
|
|
417
381
|
});
|
|
418
|
-
})
|
|
382
|
+
})
|
|
383
|
+
// Catch all resolving errors, return the original file and pass responsibility back to other custom importers
|
|
419
384
|
.catch(() => {
|
|
420
385
|
done({
|
|
421
386
|
file: originalUrl
|
|
@@ -423,70 +388,64 @@ function getWebpackImporter(loaderContext, implementation, includePaths) {
|
|
|
423
388
|
});
|
|
424
389
|
};
|
|
425
390
|
}
|
|
426
|
-
|
|
427
391
|
let nodeSassJobQueue = null;
|
|
392
|
+
|
|
428
393
|
/**
|
|
429
394
|
* Verifies that the implementation and version of Sass is supported by this loader.
|
|
430
395
|
*
|
|
431
396
|
* @param {Object} implementation
|
|
432
397
|
* @returns {Function}
|
|
433
398
|
*/
|
|
434
|
-
|
|
435
399
|
function getRenderFunctionFromSassImplementation(implementation) {
|
|
436
400
|
const isDartSass = implementation.info.includes("dart-sass");
|
|
437
|
-
|
|
438
401
|
if (isDartSass) {
|
|
439
402
|
return implementation.render.bind(implementation);
|
|
440
|
-
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// There is an issue with node-sass when async custom importers are used
|
|
441
406
|
// See https://github.com/sass/node-sass/issues/857#issuecomment-93594360
|
|
442
407
|
// We need to use a job queue to make sure that one thread is always available to the UV lib
|
|
443
|
-
|
|
444
|
-
|
|
445
408
|
if (nodeSassJobQueue === null) {
|
|
446
409
|
const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);
|
|
447
410
|
nodeSassJobQueue = _neoAsync.default.queue(implementation.render.bind(implementation), threadPoolSize - 1);
|
|
448
411
|
}
|
|
449
|
-
|
|
450
412
|
return nodeSassJobQueue.push.bind(nodeSassJobQueue);
|
|
451
413
|
}
|
|
452
|
-
|
|
453
414
|
const ABSOLUTE_SCHEME = /^[A-Za-z0-9+\-.]+:/;
|
|
454
|
-
|
|
455
415
|
function getURLType(source) {
|
|
456
416
|
if (source[0] === "/") {
|
|
457
417
|
if (source[1] === "/") {
|
|
458
418
|
return "scheme-relative";
|
|
459
419
|
}
|
|
460
|
-
|
|
461
420
|
return "path-absolute";
|
|
462
421
|
}
|
|
463
|
-
|
|
464
422
|
if (IS_NATIVE_WIN32_PATH.test(source)) {
|
|
465
423
|
return "path-absolute";
|
|
466
424
|
}
|
|
467
|
-
|
|
468
425
|
return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
|
|
469
426
|
}
|
|
470
|
-
|
|
471
427
|
function normalizeSourceMap(map, rootContext) {
|
|
472
|
-
const newMap = map;
|
|
428
|
+
const newMap = map;
|
|
429
|
+
|
|
430
|
+
// result.map.file is an optional property that provides the output filename.
|
|
473
431
|
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
474
432
|
// eslint-disable-next-line no-param-reassign
|
|
433
|
+
delete newMap.file;
|
|
475
434
|
|
|
476
|
-
|
|
435
|
+
// eslint-disable-next-line no-param-reassign
|
|
436
|
+
newMap.sourceRoot = "";
|
|
477
437
|
|
|
478
|
-
|
|
438
|
+
// node-sass returns POSIX paths, that's why we need to transform them back to native paths.
|
|
479
439
|
// This fixes an error on windows where the source-map module cannot resolve the source maps.
|
|
480
440
|
// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
|
|
481
441
|
// eslint-disable-next-line no-param-reassign
|
|
482
|
-
|
|
483
442
|
newMap.sources = newMap.sources.map(source => {
|
|
484
|
-
const sourceType = getURLType(source);
|
|
443
|
+
const sourceType = getURLType(source);
|
|
485
444
|
|
|
445
|
+
// Do no touch `scheme-relative`, `path-absolute` and `absolute` types
|
|
486
446
|
if (sourceType === "path-relative") {
|
|
487
447
|
return _path.default.resolve(rootContext, _path.default.normalize(source));
|
|
488
448
|
}
|
|
489
|
-
|
|
490
449
|
return source;
|
|
491
450
|
});
|
|
492
451
|
return newMap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sass-loader",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.0",
|
|
4
4
|
"description": "Sass loader for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/sass-loader",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"fibers": ">= 3.1.0",
|
|
43
|
-
"node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
43
|
+
"node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
44
44
|
"sass": "^1.3.0",
|
|
45
45
|
"webpack": "^4.36.0 || ^5.0.0"
|
|
46
46
|
},
|