Skip to content

Commit

Permalink
fix: prevent search nested imports in css files (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Dec 2, 2020
1 parent 569ed00 commit 092e52a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
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

0 comments on commit 092e52a

Please sign in to comment.