sass-loader 7.0.3 → 7.3.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/CHANGELOG.md +52 -1
- package/LICENSE +16 -14
- package/README.md +400 -152
- package/dist/cjs.js +5 -0
- package/dist/formatSassError.js +82 -0
- package/dist/getSassOptions.js +106 -0
- package/dist/importsToResolve.js +88 -0
- package/dist/index.js +202 -0
- package/dist/options.json +9 -0
- package/{lib → dist}/proxyCustomImporters.js +14 -12
- package/dist/webpackImporter.js +75 -0
- package/package.json +71 -47
- package/lib/formatSassError.js +0 -73
- package/lib/importsToResolve.js +0 -60
- package/lib/loader.js +0 -95
- package/lib/normalizeOptions.js +0 -78
- package/lib/webpackImporter.js +0 -72
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _os = _interopRequireDefault(require("os"));
|
|
11
|
+
|
|
12
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// A typical sass error looks like this
|
|
17
|
+
// const SassError = {
|
|
18
|
+
// message: "invalid property name",
|
|
19
|
+
// column: 14,
|
|
20
|
+
// line: 1,
|
|
21
|
+
// file: "stdin",
|
|
22
|
+
// status: 1
|
|
23
|
+
// };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Enhances the sass error with additional information about what actually went wrong.
|
|
27
|
+
*
|
|
28
|
+
* @param {SassError} error
|
|
29
|
+
* @param {string} resourcePath
|
|
30
|
+
*/
|
|
31
|
+
function formatSassError(error, resourcePath) {
|
|
32
|
+
// Instruct webpack to hide the JS stack from the console
|
|
33
|
+
// Usually you're only interested in the SASS stack in this case.
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
error.hideStack = true; // The file property is missing in rare cases.
|
|
36
|
+
// No improvement in the error is possible.
|
|
37
|
+
|
|
38
|
+
if (!error.file) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let msg = error.message;
|
|
43
|
+
|
|
44
|
+
if (error.file === 'stdin') {
|
|
45
|
+
// eslint-disable-next-line no-param-reassign
|
|
46
|
+
error.file = resourcePath;
|
|
47
|
+
} // node-sass returns UNIX-style paths
|
|
48
|
+
// eslint-disable-next-line no-param-reassign
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
error.file = _path.default.normalize(error.file); // The 'Current dir' hint of node-sass does not help us, we're providing
|
|
52
|
+
// additional information by reading the err.file property
|
|
53
|
+
|
|
54
|
+
msg = msg.replace(/\s*Current dir:\s*/, ''); // msg = msg.replace(/(\s*)(stdin)(\s*)/, `$1${err.file}$3`);
|
|
55
|
+
// eslint-disable-next-line no-param-reassign
|
|
56
|
+
|
|
57
|
+
error.message = `${getFileExcerptIfPossible(error) + msg.charAt(0).toUpperCase() + msg.slice(1) + _os.default.EOL} in ${error.file} (line ${error.line}, column ${error.column})`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Tries to get an excerpt of the file where the error happened.
|
|
61
|
+
* Uses err.line and err.column.
|
|
62
|
+
*
|
|
63
|
+
* Returns an empty string if the excerpt could not be retrieved.
|
|
64
|
+
*
|
|
65
|
+
* @param {SassError} error
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
function getFileExcerptIfPossible(error) {
|
|
71
|
+
try {
|
|
72
|
+
const content = _fs.default.readFileSync(error.file, 'utf8');
|
|
73
|
+
|
|
74
|
+
return `${_os.default.EOL + content.split(/\r?\n/)[error.line - 1] + _os.default.EOL + new Array(error.column - 1).join(' ')}^${_os.default.EOL} `;
|
|
75
|
+
} catch (ignoreError) {
|
|
76
|
+
// If anything goes wrong here, we don't want any errors to be reported to the user
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var _default = formatSassError;
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _os = _interopRequireDefault(require("os"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _cloneDeep = _interopRequireDefault(require("clone-deep"));
|
|
13
|
+
|
|
14
|
+
var _proxyCustomImporters = _interopRequireDefault(require("./proxyCustomImporters"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function isProductionLikeMode(loaderContext) {
|
|
19
|
+
return loaderContext.mode === 'production' || !loaderContext.mode || loaderContext.minimize;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Derives the sass options from the loader context and normalizes its values with sane defaults.
|
|
23
|
+
*
|
|
24
|
+
* Please note: If loaderContext.query is an options object, it will be re-used across multiple invocations.
|
|
25
|
+
* That's why we must not modify the object directly.
|
|
26
|
+
*
|
|
27
|
+
* @param {LoaderContext} loaderContext
|
|
28
|
+
* @param {string} loaderOptions
|
|
29
|
+
* @param {object} content
|
|
30
|
+
* @returns {Object}
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function getSassOptions(loaderContext, loaderOptions, content) {
|
|
35
|
+
const options = (0, _cloneDeep.default)(loaderOptions);
|
|
36
|
+
const {
|
|
37
|
+
resourcePath
|
|
38
|
+
} = loaderContext; // allow opt.functions to be configured WRT loaderContext
|
|
39
|
+
|
|
40
|
+
if (typeof options.functions === 'function') {
|
|
41
|
+
options.functions = options.functions(loaderContext);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
data
|
|
46
|
+
} = options;
|
|
47
|
+
|
|
48
|
+
if (typeof options.data === 'function') {
|
|
49
|
+
data = options.data(loaderContext);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
options.data = data ? data + _os.default.EOL + content : content; // opt.outputStyle
|
|
53
|
+
|
|
54
|
+
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
|
|
55
|
+
options.outputStyle = 'compressed';
|
|
56
|
+
} // opt.sourceMap
|
|
57
|
+
// Not using the `this.sourceMap` flag because css source maps are different
|
|
58
|
+
// @see https://github.com/webpack/css-loader/pull/40
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if (options.sourceMap) {
|
|
62
|
+
// Deliberately overriding the sourceMap option here.
|
|
63
|
+
// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
|
|
64
|
+
// In case it is a string, options.sourceMap should be a path where the source map is written.
|
|
65
|
+
// But since we're using the data option, the source map will not actually be written, but
|
|
66
|
+
// all paths in sourceMap.sources will be relative to that path.
|
|
67
|
+
// Pretty complicated... :(
|
|
68
|
+
options.sourceMap = _path.default.join(process.cwd(), '/sass.map');
|
|
69
|
+
|
|
70
|
+
if ('sourceMapRoot' in options === false) {
|
|
71
|
+
options.sourceMapRoot = process.cwd();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if ('omitSourceMapUrl' in options === false) {
|
|
75
|
+
// The source map url doesn't make sense because we don't know the output path
|
|
76
|
+
// The css-loader will handle that for us
|
|
77
|
+
options.omitSourceMapUrl = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ('sourceMapContents' in options === false) {
|
|
81
|
+
// If sourceMapContents option is not set, set it to true otherwise maps will be empty/null
|
|
82
|
+
// when exported by webpack-extract-text-plugin.
|
|
83
|
+
options.sourceMapContents = true;
|
|
84
|
+
}
|
|
85
|
+
} // indentedSyntax is a boolean flag.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const ext = _path.default.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (ext && ext.toLowerCase() === '.sass' && 'indentedSyntax' in options === false) {
|
|
92
|
+
options.indentedSyntax = true;
|
|
93
|
+
} else {
|
|
94
|
+
options.indentedSyntax = Boolean(options.indentedSyntax);
|
|
95
|
+
} // Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
options.importer = options.importer ? (0, _proxyCustomImporters.default)(options.importer, resourcePath) : []; // `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file.
|
|
99
|
+
|
|
100
|
+
options.includePaths = options.includePaths || [];
|
|
101
|
+
options.includePaths.push(_path.default.dirname(resourcePath));
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var _default = getSassOptions;
|
|
106
|
+
exports.default = _default;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _loaderUtils = _interopRequireDefault(require("loader-utils"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
// Examples:
|
|
15
|
+
// - ~package
|
|
16
|
+
// - ~package/
|
|
17
|
+
// - ~@org
|
|
18
|
+
// - ~@org/
|
|
19
|
+
// - ~@org/package
|
|
20
|
+
// - ~@org/package/
|
|
21
|
+
const matchModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
|
|
22
|
+
/**
|
|
23
|
+
* When libsass tries to resolve an import, it uses a special algorithm.
|
|
24
|
+
* Since the sass-loader uses webpack to resolve the modules, we need to simulate that algorithm. This function
|
|
25
|
+
* returns an array of import paths to try. The last entry in the array is always the original url
|
|
26
|
+
* to enable straight-forward webpack.config aliases.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} url
|
|
29
|
+
* @returns {Array<string>}
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
function importsToResolve(url) {
|
|
33
|
+
const request = _loaderUtils.default.urlToRequest(url); // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
|
|
34
|
+
// @see https://github.com/webpack-contrib/sass-loader/issues/167
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const ext = _path.default.extname(request); // In case there is module request, send this to webpack resolver
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (matchModuleImport.test(url)) {
|
|
41
|
+
return [request, url];
|
|
42
|
+
} // 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.
|
|
43
|
+
// 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:
|
|
44
|
+
// - imports where the URL ends with .css.
|
|
45
|
+
// - imports where the URL begins http:// or https://.
|
|
46
|
+
// - imports where the URL is written as a url().
|
|
47
|
+
// - imports that have media queries.
|
|
48
|
+
//
|
|
49
|
+
// The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if (ext === '.css') {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const dirname = _path.default.dirname(request);
|
|
57
|
+
|
|
58
|
+
const basename = _path.default.basename(request); // In case there is file extension:
|
|
59
|
+
//
|
|
60
|
+
// 1. Try to resolve `_` file.
|
|
61
|
+
// 2. Try to resolve file without `_`.
|
|
62
|
+
// 3. Send a original url to webpack resolver, maybe it is alias.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if (['.scss', '.sass'].includes(ext)) {
|
|
66
|
+
return [`${dirname}/_${basename}`, `${dirname}/${basename}`, url];
|
|
67
|
+
} // In case there is no file extension and filename starts with `_`:
|
|
68
|
+
//
|
|
69
|
+
// 1. Try to resolve files with `scss`, `sass` and `css` extensions.
|
|
70
|
+
// 2. Try to resolve directory with `_index` or `index` filename.
|
|
71
|
+
// 3. Send the original url to webpack resolver, maybe it's alias.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if (basename.charAt(0) === '_') {
|
|
75
|
+
return [`${request}.scss`, `${request}.sass`, `${request}.css`, request, url];
|
|
76
|
+
} // In case there is no file extension and filename doesn't start with `_`:
|
|
77
|
+
//
|
|
78
|
+
// 1. Try to resolve file starts with `_` and with extensions
|
|
79
|
+
// 2. Try to resolve file with extensions
|
|
80
|
+
// 3. Try to resolve directory with `_index` or `index` filename.
|
|
81
|
+
// 4. Send a original url to webpack resolver, maybe it is alias.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
return [`${dirname}/_${basename}.scss`, `${dirname}/_${basename}.sass`, `${dirname}/_${basename}.css`, `${request}.scss`, `${request}.sass`, `${request}.css`, request, url];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var _default = importsToResolve;
|
|
88
|
+
exports.default = _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _neoAsync = _interopRequireDefault(require("neo-async"));
|
|
11
|
+
|
|
12
|
+
var _pify = _interopRequireDefault(require("pify"));
|
|
13
|
+
|
|
14
|
+
var _semver = _interopRequireDefault(require("semver"));
|
|
15
|
+
|
|
16
|
+
var _loaderUtils = require("loader-utils");
|
|
17
|
+
|
|
18
|
+
var _formatSassError = _interopRequireDefault(require("./formatSassError"));
|
|
19
|
+
|
|
20
|
+
var _webpackImporter = _interopRequireDefault(require("./webpackImporter"));
|
|
21
|
+
|
|
22
|
+
var _getSassOptions = _interopRequireDefault(require("./getSassOptions"));
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
|
|
26
|
+
let nodeSassJobQueue = null; // Very hacky check
|
|
27
|
+
|
|
28
|
+
function hasGetResolve(loaderContext) {
|
|
29
|
+
return loaderContext.getResolve && // eslint-disable-next-line no-underscore-dangle
|
|
30
|
+
loaderContext._compiler && // eslint-disable-next-line no-underscore-dangle
|
|
31
|
+
loaderContext._compiler.resolverFactory && // eslint-disable-next-line no-underscore-dangle
|
|
32
|
+
loaderContext._compiler.resolverFactory._create && /cachedCleverMerge/.test( // eslint-disable-next-line no-underscore-dangle
|
|
33
|
+
loaderContext._compiler.resolverFactory._create.toString());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The sass-loader makes node-sass and dart-sass available to webpack modules.
|
|
37
|
+
*
|
|
38
|
+
* @this {LoaderContext}
|
|
39
|
+
* @param {string} content
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
function loader(content) {
|
|
44
|
+
const options = (0, _loaderUtils.getOptions)(this) || {};
|
|
45
|
+
const callback = this.async();
|
|
46
|
+
|
|
47
|
+
const addNormalizedDependency = file => {
|
|
48
|
+
// node-sass returns POSIX paths
|
|
49
|
+
this.dependency(_path.default.normalize(file));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (typeof callback !== 'function') {
|
|
53
|
+
throw new Error('Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/sass-loader/issues/333');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let resolve = (0, _pify.default)(this.resolve); // Supported since v4.36.0
|
|
57
|
+
|
|
58
|
+
if (hasGetResolve(this)) {
|
|
59
|
+
resolve = this.getResolve({
|
|
60
|
+
mainFields: ['sass', 'style', 'main', '...'],
|
|
61
|
+
mainFiles: ['_index', 'index', '...'],
|
|
62
|
+
extensions: ['.scss', '.sass', '.css', '...']
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const sassOptions = (0, _getSassOptions.default)(this, options, content);
|
|
67
|
+
const shouldUseWebpackImporter = typeof options.webpackImporter === 'boolean' ? options.webpackImporter : true;
|
|
68
|
+
|
|
69
|
+
if (shouldUseWebpackImporter) {
|
|
70
|
+
sassOptions.importer.push((0, _webpackImporter.default)(this.resourcePath, resolve, addNormalizedDependency));
|
|
71
|
+
} // Skip empty files, otherwise it will stop webpack, see issue #21
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if (sassOptions.data.trim() === '') {
|
|
75
|
+
callback(null, '');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const render = getRenderFuncFromSassImpl( // eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
80
|
+
options.implementation || getDefaultSassImpl());
|
|
81
|
+
render(sassOptions, (error, result) => {
|
|
82
|
+
if (error) {
|
|
83
|
+
(0, _formatSassError.default)(error, this.resourcePath);
|
|
84
|
+
|
|
85
|
+
if (error.file) {
|
|
86
|
+
this.dependency(error.file);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
callback(error);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (result.map && result.map !== '{}') {
|
|
94
|
+
// eslint-disable-next-line no-param-reassign
|
|
95
|
+
result.map = JSON.parse(result.map); // result.map.file is an optional property that provides the output filename.
|
|
96
|
+
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
97
|
+
// eslint-disable-next-line no-param-reassign
|
|
98
|
+
|
|
99
|
+
delete result.map.file; // One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input.
|
|
100
|
+
// Now let's override that value with the correct relative path.
|
|
101
|
+
// Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in getSassOptions,
|
|
102
|
+
// we know that this path is relative to process.cwd(). This is how node-sass works.
|
|
103
|
+
// eslint-disable-next-line no-param-reassign
|
|
104
|
+
|
|
105
|
+
const stdinIndex = result.map.sources.findIndex(source => source.indexOf('stdin') !== -1);
|
|
106
|
+
|
|
107
|
+
if (stdinIndex !== -1) {
|
|
108
|
+
// eslint-disable-next-line no-param-reassign
|
|
109
|
+
result.map.sources[stdinIndex] = _path.default.relative(process.cwd(), this.resourcePath);
|
|
110
|
+
} // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
|
|
111
|
+
// This fixes an error on windows where the source-map module cannot resolve the source maps.
|
|
112
|
+
// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
|
|
113
|
+
// eslint-disable-next-line no-param-reassign
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
result.map.sourceRoot = _path.default.normalize(result.map.sourceRoot); // eslint-disable-next-line no-param-reassign
|
|
117
|
+
|
|
118
|
+
result.map.sources = result.map.sources.map(_path.default.normalize);
|
|
119
|
+
} else {
|
|
120
|
+
// eslint-disable-next-line no-param-reassign
|
|
121
|
+
result.map = null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
result.stats.includedFiles.forEach(addNormalizedDependency);
|
|
125
|
+
callback(null, result.css.toString(), result.map);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Verifies that the implementation and version of Sass is supported by this loader.
|
|
130
|
+
*
|
|
131
|
+
* @param {Object} module
|
|
132
|
+
* @returns {Function}
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
function getRenderFuncFromSassImpl(module) {
|
|
137
|
+
const {
|
|
138
|
+
info
|
|
139
|
+
} = module;
|
|
140
|
+
|
|
141
|
+
if (!info) {
|
|
142
|
+
throw new Error('Unknown Sass implementation.');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const components = info.split('\t');
|
|
146
|
+
|
|
147
|
+
if (components.length < 2) {
|
|
148
|
+
throw new Error(`Unknown Sass implementation "${info}".`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const [implementation, version] = components;
|
|
152
|
+
|
|
153
|
+
if (!_semver.default.valid(version)) {
|
|
154
|
+
throw new Error(`Invalid Sass version "${version}".`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (implementation === 'dart-sass') {
|
|
158
|
+
if (!_semver.default.satisfies(version, '^1.3.0')) {
|
|
159
|
+
throw new Error(`Dart Sass version ${version} is incompatible with ^1.3.0.`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return module.render.bind(module);
|
|
163
|
+
} else if (implementation === 'node-sass') {
|
|
164
|
+
if (!_semver.default.satisfies(version, '^4.0.0')) {
|
|
165
|
+
throw new Error(`Node Sass version ${version} is incompatible with ^4.0.0.`);
|
|
166
|
+
} // There is an issue with node-sass when async custom importers are used
|
|
167
|
+
// See https://github.com/sass/node-sass/issues/857#issuecomment-93594360
|
|
168
|
+
// We need to use a job queue to make sure that one thread is always available to the UV lib
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if (nodeSassJobQueue === null) {
|
|
172
|
+
const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);
|
|
173
|
+
nodeSassJobQueue = _neoAsync.default.queue(module.render.bind(module), threadPoolSize - 1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return nodeSassJobQueue.push.bind(nodeSassJobQueue);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
throw new Error(`Unknown Sass implementation "${implementation}".`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getDefaultSassImpl() {
|
|
183
|
+
let sassImplPkg = 'node-sass';
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
require.resolve('node-sass');
|
|
187
|
+
} catch (error) {
|
|
188
|
+
try {
|
|
189
|
+
require.resolve('sass');
|
|
190
|
+
|
|
191
|
+
sassImplPkg = 'sass';
|
|
192
|
+
} catch (ignoreError) {
|
|
193
|
+
sassImplPkg = 'node-sass';
|
|
194
|
+
}
|
|
195
|
+
} // eslint-disable-next-line import/no-dynamic-require, global-require
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
return require(sassImplPkg);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var _default = loader;
|
|
202
|
+
exports.default = _default;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Creates new custom importers that use the given `resourcePath` if libsass calls the custom importer with `prev`
|
|
5
10
|
* being 'stdin'.
|
|
@@ -10,20 +15,17 @@
|
|
|
10
15
|
*
|
|
11
16
|
* We have to fix this behavior in order to provide a consistent experience to the webpack user.
|
|
12
17
|
*
|
|
13
|
-
* @param {
|
|
18
|
+
* @param {Function|Array<Function>} importer
|
|
14
19
|
* @param {string} resourcePath
|
|
15
|
-
* @returns {Array<
|
|
20
|
+
* @returns {Array<Function>}
|
|
16
21
|
*/
|
|
17
22
|
function proxyCustomImporters(importer, resourcePath) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.map((arg, i) => i === 1 && arg === "stdin" ? resourcePath : arg)
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
});
|
|
23
|
+
return [].concat(importer).map( // eslint-disable-next-line no-shadow
|
|
24
|
+
importer => function customImporter() {
|
|
25
|
+
return importer.apply(this, // eslint-disable-next-line prefer-rest-params
|
|
26
|
+
Array.from(arguments).map((arg, i) => i === 1 && arg === 'stdin' ? resourcePath : arg));
|
|
27
|
+
});
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
var _default = proxyCustomImporters;
|
|
31
|
+
exports.default = _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _importsToResolve = _interopRequireDefault(require("./importsToResolve"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @name PromisedResolve
|
|
16
|
+
* @type {Function}
|
|
17
|
+
* @param {string} dir
|
|
18
|
+
* @param {string} request
|
|
19
|
+
* @returns Promise
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @name Importer
|
|
24
|
+
* @type {Function}
|
|
25
|
+
* @param {string} url
|
|
26
|
+
* @param {string} prev
|
|
27
|
+
* @param {Function<Error, string>} done
|
|
28
|
+
*/
|
|
29
|
+
const matchCss = /\.css$/;
|
|
30
|
+
/**
|
|
31
|
+
* Returns an importer that uses webpack's resolving algorithm.
|
|
32
|
+
*
|
|
33
|
+
* It's important that the returned function has the correct number of arguments
|
|
34
|
+
* (based on whether the call is sync or async) because otherwise node-sass doesn't exit.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} resourcePath
|
|
37
|
+
* @param {PromisedResolve} resolve
|
|
38
|
+
* @param {Function<string>} addNormalizedDependency
|
|
39
|
+
* @returns {Importer}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
|
|
43
|
+
function dirContextFrom(fileContext) {
|
|
44
|
+
return _path.default.dirname( // The first file is 'stdin' when we're using the data option
|
|
45
|
+
fileContext === 'stdin' ? resourcePath : fileContext);
|
|
46
|
+
} // eslint-disable-next-line no-shadow
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function startResolving(dir, importsToResolve) {
|
|
50
|
+
return importsToResolve.length === 0 ? Promise.reject() : resolve(dir, importsToResolve[0]).then(resolvedFile => {
|
|
51
|
+
// Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come
|
|
52
|
+
// in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass.
|
|
53
|
+
addNormalizedDependency(resolvedFile);
|
|
54
|
+
return {
|
|
55
|
+
// By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
|
|
56
|
+
file: resolvedFile.replace(matchCss, '')
|
|
57
|
+
};
|
|
58
|
+
}, () => {
|
|
59
|
+
const [, ...tailResult] = importsToResolve;
|
|
60
|
+
return startResolving(dir, tailResult);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (url, prev, done) => {
|
|
65
|
+
startResolving(dirContextFrom(prev), (0, _importsToResolve.default)(url)) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
|
|
66
|
+
.catch(() => {
|
|
67
|
+
return {
|
|
68
|
+
file: url
|
|
69
|
+
};
|
|
70
|
+
}).then(done);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var _default = webpackImporter;
|
|
75
|
+
exports.default = _default;
|