Skip to content

Commit e34f938

Browse files
authoredDec 25, 2023
fix: sass embedded importer detection
1 parent 0084b93 commit e34f938

8 files changed

+54024
-38774
lines changed
 

‎package-lock.json

+5,578-5,018
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils.js

+8
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ async function getSassOptions(
289289
)
290290
: [];
291291

292+
// Regression on the `sass-embedded` side
293+
if (
294+
loaderOptions.webpackImporter === false &&
295+
sassOptions.importer.length === 0
296+
) {
297+
sassOptions.importer = undefined;
298+
}
299+
292300
sassOptions.includePaths = []
293301
.concat(process.cwd())
294302
.concat(

‎test/__snapshots__/loader.test.js.snap

+48,349-33,645
Large diffs are not rendered by default.

‎test/__snapshots__/sassOptions-option.test.js.snap

+39-67
Original file line numberDiff line numberDiff line change
@@ -3942,85 +3942,41 @@ exports[`sassOptions option should work with the "functions" option ('sass-embed
39423942

39433943
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `""`;
39443944

3945-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): css 2`] = `
3946-
".a {
3947-
color: red;
3948-
}
3949-
3950-
.b {
3951-
color: blue;
3952-
}"
3953-
`;
3954-
39553945
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
39563946

3957-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): errors 2`] = `[]`;
3958-
39593947
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
39603948

3961-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'sass' syntax): warnings 2`] = `[]`;
3962-
39633949
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): css 1`] = `""`;
39643950

3965-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): css 2`] = `
3966-
".a {
3967-
color: red;
3968-
}
3969-
3970-
.b {
3971-
color: blue;
3972-
}"
3973-
`;
3974-
39753951
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
39763952

3977-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): errors 2`] = `[]`;
3978-
39793953
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
39803954

3981-
exports[`sassOptions option should work with the "importer" as a array of functions option ('dart-sass', 'legacy' API, 'scss' syntax): warnings 2`] = `[]`;
3982-
39833955
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): css 1`] = `""`;
39843956

3985-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): css 2`] = `
3986-
".a {
3987-
color: red; }
3988-
3989-
.b {
3990-
color: blue; }
3991-
"
3992-
`;
3993-
39943957
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
39953958

3996-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): errors 2`] = `[]`;
3997-
39983959
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
39993960

4000-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'sass' syntax): warnings 2`] = `[]`;
4001-
40023961
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): css 1`] = `""`;
40033962

4004-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): css 2`] = `
4005-
".a {
4006-
color: red; }
3963+
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
40073964

4008-
.b {
4009-
color: blue; }
4010-
"
4011-
`;
3965+
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
40123966

4013-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
3967+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): css 1`] = `""`;
40143968

4015-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): errors 2`] = `[]`;
3969+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
40163970

4017-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
3971+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
40183972

4019-
exports[`sassOptions option should work with the "importer" as a array of functions option ('node-sass', 'legacy' API, 'scss' syntax): warnings 2`] = `[]`;
3973+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): css 1`] = `""`;
40203974

4021-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): css 1`] = `""`;
3975+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
40223976

4023-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): css 2`] = `
3977+
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
3978+
3979+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
40243980
".a {
40253981
color: red;
40263982
}
@@ -4030,17 +3986,11 @@ exports[`sassOptions option should work with the "importer" as a array of functi
40303986
}"
40313987
`;
40323988

4033-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
3989+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
40343990

4035-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): errors 2`] = `[]`;
4036-
4037-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
3991+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
40383992

4039-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 2`] = `[]`;
4040-
4041-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): css 1`] = `""`;
4042-
4043-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): css 2`] = `
3993+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'scss' syntax): css 1`] = `
40443994
".a {
40453995
color: red;
40463996
}
@@ -4050,13 +4000,35 @@ exports[`sassOptions option should work with the "importer" as a array of functi
40504000
}"
40514001
`;
40524002

4053-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
4003+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
40544004

4055-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): errors 2`] = `[]`;
4005+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
40564006

4057-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
4007+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'sass' syntax): css 1`] = `
4008+
".a {
4009+
color: red; }
4010+
4011+
.b {
4012+
color: blue; }
4013+
"
4014+
`;
4015+
4016+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
4017+
4018+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
4019+
4020+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'scss' syntax): css 1`] = `
4021+
".a {
4022+
color: red; }
4023+
4024+
.b {
4025+
color: blue; }
4026+
"
4027+
`;
4028+
4029+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
40584030

4059-
exports[`sassOptions option should work with the "importer" as a array of functions option ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 2`] = `[]`;
4031+
exports[`sassOptions option should work with the "importer" as a array of functions option - glob ('node-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
40604032

40614033
exports[`sassOptions option should work with the "importer" as a single function option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `""`;
40624034

‎test/__snapshots__/warnRuleAsWarning.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ exports[`loader should not emit warning when 'false' used ('sass-embedded', 'leg
737737
"args": [
738738
"My warning message
739739
740-
test/sass/logging.sass 2:1 root stylesheet
740+
file:///<cwd>/sass/logging.sass 2:1 root stylesheet
741741
",
742742
],
743743
"type": "warn",
@@ -769,7 +769,7 @@ exports[`loader should not emit warning when 'false' used ('sass-embedded', 'leg
769769
"args": [
770770
"My warning message
771771
772-
test/scss/logging.scss 2:1 root stylesheet
772+
file:///<cwd>/scss/logging.scss 2:1 root stylesheet
773773
",
774774
],
775775
"type": "warn",

‎test/helpers/normalizeErrors.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function removeCWD(str) {
99
cwd = cwd.replace(/\\/g, "/");
1010
}
1111

12-
return str.replace(new RegExp(cwd, "g"), "").replace("file:////", "file:///");
12+
return str
13+
.replace(new RegExp(cwd, "g"), "")
14+
.replace(/file:\/\/\/\//g, "file:///");
1315
}
1416

1517
export default (errors, needVerbose) =>

‎test/loader.test.js

+41-39
Original file line numberDiff line numberDiff line change
@@ -814,48 +814,50 @@ describe("loader", () => {
814814
});
815815
}
816816

817-
it(`should work with the "foundation-sites" package, import as a package ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
818-
const testId = getTestId("foundation-sites", syntax);
819-
const options = {
820-
implementation,
821-
api,
822-
sassOptions: isModernAPI
823-
? { loadPaths: ["node_modules/foundation-sites/scss"] }
824-
: { includePaths: ["node_modules/foundation-sites/scss"] },
825-
};
826-
const compiler = getCompiler(testId, { loader: { options } });
827-
const stats = await compile(compiler);
828-
const codeFromBundle = getCodeFromBundle(stats, compiler);
829-
const codeFromSass = await getCodeFromSass(testId, options);
817+
if (!isNodeSass) {
818+
it(`should work with the "foundation-sites" package, import as a package ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
819+
const testId = getTestId("foundation-sites", syntax);
820+
const options = {
821+
implementation,
822+
api,
823+
sassOptions: isModernAPI
824+
? { loadPaths: ["node_modules/foundation-sites/scss"] }
825+
: { includePaths: ["node_modules/foundation-sites/scss"] },
826+
};
827+
const compiler = getCompiler(testId, { loader: { options } });
828+
const stats = await compile(compiler);
829+
const codeFromBundle = getCodeFromBundle(stats, compiler);
830+
const codeFromSass = await getCodeFromSass(testId, options);
830831

831-
expect(codeFromBundle.css).toBe(codeFromSass.css);
832-
expect(codeFromBundle.css).toMatchSnapshot("css");
833-
expect(getWarnings(stats)).toMatchSnapshot("warnings");
834-
expect(getErrors(stats)).toMatchSnapshot("errors");
835-
});
832+
expect(codeFromBundle.css).toBe(codeFromSass.css);
833+
expect(codeFromBundle.css).toMatchSnapshot("css");
834+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
835+
expect(getErrors(stats)).toMatchSnapshot("errors");
836+
});
836837

837-
it(`should work with the "foundation-sites" package, adjusting CSS output ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
838-
const testId = getTestId(
839-
"foundation-sites-adjusting-css-output",
840-
syntax
841-
);
842-
const options = {
843-
implementation,
844-
api,
845-
sassOptions: isModernAPI
846-
? { loadPaths: ["node_modules/foundation-sites/scss"] }
847-
: { includePaths: ["node_modules/foundation-sites/scss"] },
848-
};
849-
const compiler = getCompiler(testId, { loader: { options } });
850-
const stats = await compile(compiler);
851-
const codeFromBundle = getCodeFromBundle(stats, compiler);
852-
const codeFromSass = await getCodeFromSass(testId, options);
838+
it(`should work with the "foundation-sites" package, adjusting CSS output ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
839+
const testId = getTestId(
840+
"foundation-sites-adjusting-css-output",
841+
syntax
842+
);
843+
const options = {
844+
implementation,
845+
api,
846+
sassOptions: isModernAPI
847+
? { loadPaths: ["node_modules/foundation-sites/scss"] }
848+
: { includePaths: ["node_modules/foundation-sites/scss"] },
849+
};
850+
const compiler = getCompiler(testId, { loader: { options } });
851+
const stats = await compile(compiler);
852+
const codeFromBundle = getCodeFromBundle(stats, compiler);
853+
const codeFromSass = await getCodeFromSass(testId, options);
853854

854-
expect(codeFromBundle.css).toBe(codeFromSass.css);
855-
expect(codeFromBundle.css).toMatchSnapshot("css");
856-
expect(getWarnings(stats)).toMatchSnapshot("warnings");
857-
expect(getErrors(stats)).toMatchSnapshot("errors");
858-
});
855+
expect(codeFromBundle.css).toBe(codeFromSass.css);
856+
expect(codeFromBundle.css).toMatchSnapshot("css");
857+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
858+
expect(getErrors(stats)).toMatchSnapshot("errors");
859+
});
860+
}
859861

860862
it(`should work and output the "compressed" outputStyle when "mode" is production ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
861863
const testId = getTestId("language", syntax);

‎test/sassOptions-option.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,10 @@ describe("sassOptions option", () => {
299299
});
300300
}
301301

302-
if (!isModernAPI) {
303-
it(`should work with the "importer" as a array of functions option ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
302+
const isSassEmbedded = implementationName === "sass-embedded";
303+
304+
if (!isModernAPI && !isSassEmbedded) {
305+
it(`should work with the "importer" as a array of functions option - glob ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
304306
const testId = getTestId("glob-importer", syntax);
305307
const options = {
306308
implementation,

0 commit comments

Comments
 (0)
Please sign in to comment.