Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: disallow searching for nested imports in css files #298

Merged
merged 1 commit into from Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/utils.js
Expand Up @@ -277,6 +277,11 @@ async function getDependencies(
return;
}

// Avoid search nested imports in .css
if (path.extname(dependency) === ".css") {
return;
}

loaderContext.addDependency(dependency);

dependenciesOfDependencies.push(
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -588,6 +588,15 @@ exports[`loader resolve with webpack if stylus can't find it: errors 1`] = `Arra

exports[`loader resolve with webpack if stylus can't find it: warnings 1`] = `Array []`;

exports[`loader resolves broken css with webpack but does not import it: css 1`] = `
"@import \\"css-keyframe.css\\";
"
`;

exports[`loader resolves broken css with webpack but does not import it: errors 1`] = `Array []`;

exports[`loader resolves broken css with webpack but does not import it: warnings 1`] = `Array []`;

exports[`loader resolves css with webpack but does not import it: css 1`] = `
"@import \\"css.css\\";
"
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/css-keyframe.css
@@ -0,0 +1,4 @@
.imported-css {
border: 5px;
}
@keyframes cdk-text-field-autofill-start{/*!*/}
1 change: 1 addition & 0 deletions test/fixtures/import-webpack-css-keyframe.styl
@@ -0,0 +1 @@
@import "css-keyframe.css";
13 changes: 13 additions & 0 deletions test/loader.test.js
Expand Up @@ -509,6 +509,19 @@ describe("loader", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("resolves broken css with webpack but does not import it", async () => {
const testId = "./import-webpack-css-keyframe.styl";
const compiler = getCompiler(testId);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId);

expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it('should work "use" option', async () => {
function plugin() {
return (style) => {
Expand Down