Skip to content

Commit

Permalink
fix: resolving .import
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 4, 2020
1 parent 4caf60f commit 307b955
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.js
Expand Up @@ -365,7 +365,7 @@ function getWebpackResolver(
extensions: [".sass", ".scss", ".css"],
exportsFields: [],
mainFields: [],
mainFiles: ["_index", "index"],
mainFiles: ["_index.import", "_index", "index.import", "index"],
modules: [],
restrictions: [/\.((sa|sc|c)ss)$/i],
})
Expand All @@ -374,7 +374,7 @@ function getWebpackResolver(
resolverFactory({
conditionNames: ["sass", "style"],
mainFields: ["sass", "style", "main", "..."],
mainFiles: ["_index", "index", "..."],
mainFiles: ["_index.import", "_index", "index.import", "index", "..."],
extensions: [".sass", ".scss", ".css"],
restrictions: [/\.((sa|sc|c)ss)$/i],
})
Expand Down
40 changes: 40 additions & 0 deletions test/__snapshots__/loader.test.js.snap
@@ -1,5 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`loader should import .import.sass files (dart-sass) (sass): css 1`] = `
"a {
display: block;
}"
`;

exports[`loader should import .import.sass files (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should import .import.sass files (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should import .import.sass files from a package (dart-sass) (sass): css 1`] = `
"a {
display: block;
}"
`;

exports[`loader should import .import.sass files from a package (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should import .import.sass files from a package (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should import .import.scss files (dart-sass) (scss): css 1`] = `
"a {
display: block;
}"
`;

exports[`loader should import .import.scss files (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should import .import.scss files (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should import .import.scss files from a package (dart-sass) (scss): css 1`] = `
"a {
display: block;
}"
`;

exports[`loader should import .import.scss files from a package (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should import .import.scss files from a package (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should load files with underscore in the name (dart-sass) (sass): css 1`] = `
"a {
color: red;
Expand Down
32 changes: 32 additions & 0 deletions test/loader.test.js
Expand Up @@ -1454,6 +1454,38 @@ describe("loader", () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it(`should import .import.${syntax} files (${implementationName}) (${syntax})`, async () => {
const testId = getTestId("import-index-import", syntax);
const options = {
implementation: getImplementationByName(implementationName),
};
const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromSass = getCodeFromSass(testId, options);

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

it(`should import .import.${syntax} files from a package (${implementationName}) (${syntax})`, async () => {
const testId = getTestId("import-index-import-from-package", syntax);
const options = {
implementation: getImplementationByName(implementationName),
};
const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromSass = getCodeFromSass(testId, options);

expect(codeFromBundle.css).toBe(codeFromSass.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
}
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/node_modules/index-import-package/_index.import.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/node_modules/index-import-package/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/sass/import-index-import-from-package.sass
@@ -0,0 +1 @@
@import '~index-import-package'
1 change: 1 addition & 0 deletions test/sass/import-index-import.sass
@@ -0,0 +1 @@
@import 'index-import'
2 changes: 2 additions & 0 deletions test/sass/index-import/_index.import.sass
@@ -0,0 +1,2 @@
a
display: block
1 change: 1 addition & 0 deletions test/scss/import-index-import-from-package.scss
@@ -0,0 +1 @@
@import '~index-import-package';
1 change: 1 addition & 0 deletions test/scss/import-index-import.scss
@@ -0,0 +1 @@
@import 'index-import';
3 changes: 3 additions & 0 deletions test/scss/index-import/_index.import.scss
@@ -0,0 +1,3 @@
a {
display: block;
}

0 comments on commit 307b955

Please sign in to comment.