Skip to content

Commit f403a4e

Browse files
feat: support the resolve.byDependecy.sass option (#920)
1 parent 1d8c318 commit f403a4e

File tree

10 files changed

+102
-4
lines changed

10 files changed

+102
-4
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"semver": "^7.3.4",
9494
"standard-version": "^9.1.0",
9595
"style-loader": "^2.0.0",
96-
"webpack": "^5.20.0"
96+
"webpack": "^5.20.2"
9797
},
9898
"keywords": [
9999
"sass",

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ function getWebpackResolver(
369369
);
370370
const webpackResolve = promiseResolve(
371371
resolverFactory({
372+
dependencyType: "sass",
372373
conditionNames: ["sass", "style"],
373374
mainFields: ["sass", "style", "main", "..."],
374375
mainFiles: ["_index", "index", "..."],

test/__snapshots__/loader.test.js.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167371,3 +167371,57 @@ exports[`loader should work with the "material-components-web" package without t
167371167371
exports[`loader should work with the "material-components-web" package without the "includePaths" option (dart-sass) (scss): warnings 1`] = `Array []`;
167372167372

167373167373
exports[`loader should work with the "material-components-web" package without the "includePaths" option (dart-sass) (scss): warnings 2`] = `Array []`;
167374+
167375+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): css 1`] = `
167376+
".a {
167377+
color: red;
167378+
}
167379+
167380+
.b {
167381+
color: red;
167382+
}"
167383+
`;
167384+
167385+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): errors 1`] = `Array []`;
167386+
167387+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): warnings 1`] = `Array []`;
167388+
167389+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): css 1`] = `
167390+
".a {
167391+
color: red;
167392+
}
167393+
167394+
.b {
167395+
color: red;
167396+
}"
167397+
`;
167398+
167399+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): errors 1`] = `Array []`;
167400+
167401+
exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): warnings 1`] = `Array []`;
167402+
167403+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): css 1`] = `
167404+
".a {
167405+
color: red; }
167406+
167407+
.b {
167408+
color: red; }
167409+
"
167410+
`;
167411+
167412+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): errors 1`] = `Array []`;
167413+
167414+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): warnings 1`] = `Array []`;
167415+
167416+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): css 1`] = `
167417+
".a {
167418+
color: red; }
167419+
167420+
.b {
167421+
color: red; }
167422+
"
167423+
`;
167424+
167425+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): errors 1`] = `Array []`;
167426+
167427+
exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): warnings 1`] = `Array []`;

test/helpers/getCodeFromSass.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ function getCodeFromSass(testId, options) {
281281
__dirname,
282282
"../../node_modules/@material"
283283
);
284+
const pathToCustomMainFiles = isSass
285+
? path.resolve(testFolder, "sass/custom-main-files/custom.sass")
286+
: path.resolve(testFolder, "scss/custom-main-files/custom.scss");
284287

285288
// Pseudo importer for tests
286289
function testImporter(url) {
@@ -754,6 +757,7 @@ function getCodeFromSass(testId, options) {
754757
pathToPackageWithSameImport
755758
)
756759
.replace(/@material/, pathToMaterial)
760+
.replace(/custom-main-files/, pathToCustomMainFiles)
757761
.replace(/^~/, testNodeModules);
758762
}
759763

test/loader.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,31 @@ describe("loader", () => {
972972
expect(getErrors(stats)).toMatchSnapshot("errors");
973973
});
974974

975+
it(`should work with the 'resolve.byDependecy.sass' option (${implementationName}) (${syntax})`, async () => {
976+
const testId = getTestId("by-dependency", syntax);
977+
const options = {
978+
implementation: getImplementationByName(implementationName),
979+
};
980+
const compiler = getCompiler(testId, {
981+
loader: { options },
982+
resolve: {
983+
byDependency: {
984+
sass: {
985+
mainFiles: ["custom"],
986+
},
987+
},
988+
},
989+
});
990+
const stats = await compile(compiler);
991+
const codeFromBundle = getCodeFromBundle(stats, compiler);
992+
const codeFromSass = getCodeFromSass(testId, options);
993+
994+
expect(codeFromBundle.css).toBe(codeFromSass.css);
995+
expect(codeFromBundle.css).toMatchSnapshot("css");
996+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
997+
expect(getErrors(stats)).toMatchSnapshot("errors");
998+
});
999+
9751000
if (implementation === dartSass) {
9761001
it(`should output an understandable error with a problem in "@use" (${implementationName}) (${syntax})`, async () => {
9771002
const testId = getTestId("error-use", syntax);

test/sass/by-dependency.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import "custom-main-files"
2+
3+
.b
4+
color: red
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.a
2+
color: red

test/scss/by-dependency.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "custom-main-files";
2+
3+
.b {
4+
color: red;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
color: red
3+
}

0 commit comments

Comments
 (0)