Skip to content

Commit cadc75e

Browse files
fix: problem with resolving and the includePaths option (#913)
1 parent 4caf60f commit cadc75e

File tree

10 files changed

+828
-1253
lines changed

10 files changed

+828
-1253
lines changed

package-lock.json

Lines changed: 781 additions & 1220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
"css-loader": "^5.0.1",
7878
"del": "^6.0.0",
7979
"del-cli": "^3.0.1",
80-
"enhanced-resolve": "^5.3.1",
80+
"enhanced-resolve": "^5.5.0",
8181
"eslint": "^7.13.0",
82-
"eslint-config-prettier": "^6.15.0",
82+
"eslint-config-prettier": "^7.1.0",
8383
"eslint-plugin-import": "^2.22.1",
8484
"fibers": "^5.0.0",
8585
"file-loader": "^6.2.0",
@@ -95,7 +95,7 @@
9595
"sass": "^1.29.0",
9696
"standard-version": "^9.0.0",
9797
"style-loader": "^2.0.0",
98-
"webpack": "^5.4.0"
98+
"webpack": "^5.12.2"
9999
},
100100
"keywords": [
101101
"sass",

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ async function loader(content) {
8181
}
8282

8383
result.stats.includedFiles.forEach((includedFile) => {
84-
this.addDependency(path.normalize(includedFile));
84+
const normalizedIncludedFile = path.normalize(includedFile);
85+
86+
// Custom `importer` can return only `contents` so includedFile will be relative
87+
if (path.isAbsolute(normalizedIncludedFile)) {
88+
this.addDependency(normalizedIncludedFile);
89+
}
8590
});
8691

8792
callback(null, result.css.toString(), map);

src/utils.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@ function isProductionLikeMode(loaderContext) {
9494
}
9595

9696
function proxyCustomImporters(importers, loaderContext) {
97-
return [].concat(importers).map((importer) => {
98-
return function proxyImporter(...args) {
99-
this.webpackLoaderContext = loaderContext;
97+
return [].concat(importers).map(
98+
(importer) =>
99+
function proxyImporter(...args) {
100+
this.webpackLoaderContext = loaderContext;
100101

101-
return importer.apply(this, args);
102-
};
103-
});
102+
return importer.apply(this, args);
103+
}
104+
);
104105
}
105106

106107
/**
@@ -205,7 +206,14 @@ async function getSassOptions(
205206

206207
options.includePaths = []
207208
.concat(process.cwd())
208-
.concat(options.includePaths || [])
209+
.concat(
210+
// We use `includePaths` in context for resolver, so it should be always absolute
211+
(options.includePaths || []).map((includePath) =>
212+
path.isAbsolute(includePath)
213+
? includePath
214+
: path.join(process.cwd(), includePath)
215+
)
216+
)
209217
.concat(
210218
process.env.SASS_PATH
211219
? process.env.SASS_PATH.split(process.platform === "win32" ? ";" : ":")
@@ -430,11 +438,13 @@ function getWebpackResolver(
430438

431439
resolutionMap = resolutionMap.concat(
432440
// eslint-disable-next-line no-shadow
433-
includePaths.map((context) => ({
434-
resolve: sassResolve,
435-
context,
436-
possibleRequests: sassPossibleRequests,
437-
}))
441+
includePaths.map((context) => {
442+
return {
443+
resolve: sassResolve,
444+
context,
445+
possibleRequests: sassPossibleRequests,
446+
};
447+
})
438448
);
439449
}
440450

test/helpers/compiler.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default (compiler) => {
2-
return new Promise((resolve, reject) => {
1+
export default (compiler) =>
2+
new Promise((resolve, reject) => {
33
compiler.run((error, stats) => {
44
if (error) {
55
return reject(error);
@@ -8,4 +8,3 @@ export default (compiler) => {
88
return resolve(stats);
99
});
1010
});
11-
};

test/helpers/getErrors.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import normalizeErrors from "./normalizeErrors";
22

3-
export default (stats) => {
4-
return normalizeErrors(stats.compilation.errors.sort());
5-
};
3+
export default (stats) => normalizeErrors(stats.compilation.errors.sort());

test/helpers/getWarnings.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import normalizeErrors from "./normalizeErrors";
22

3-
export default (stats) => {
4-
return normalizeErrors(stats.compilation.warnings.sort());
5-
};
3+
export default (stats) => normalizeErrors(stats.compilation.warnings.sort());

test/helpers/normalizeErrors.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ function removeCWD(str) {
1212
return str.replace(new RegExp(cwd, "g"), "");
1313
}
1414

15-
export default (errors) => {
16-
return errors.map((error) =>
15+
export default (errors) =>
16+
errors.map((error) =>
1717
removeCWD(error.toString().split("\n").slice(0, 2).join("\n"))
1818
);
19-
};

test/loader.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ describe("loader", () => {
903903
const testId = getTestId("import-absolute-path", syntax);
904904
const options = {
905905
implementation: getImplementationByName(implementationName),
906-
additionalData: (content) => {
907-
return content
906+
additionalData: (content) =>
907+
content
908908
.replace(
909909
/\/scss\/language.scss/g,
910910
`file:///${path
@@ -916,8 +916,7 @@ describe("loader", () => {
916916
`file:///${path
917917
.resolve(__dirname, "sass/language.sass")
918918
.replace(/\\/g, "/")}`
919-
);
920-
},
919+
),
921920
};
922921
const compiler = getCompiler(testId, { loader: { options } });
923922
const stats = await compile(compiler);

test/validate-options.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ describe("validate options", () => {
2020
failure: [true, "string"],
2121
},
2222
sassOptions: {
23-
success: [{}, { indentWidth: 6 }, () => ({ indentWidth: 6 })],
23+
success: [
24+
{},
25+
{ indentWidth: 6 },
26+
() => {
27+
return { indentWidth: 6 };
28+
},
29+
],
2430
failure: [true, "string"],
2531
},
2632
additionalData: {

0 commit comments

Comments
 (0)