Skip to content

Commit fe3b33b

Browse files
fix: resolution logic (#830)
1 parent 41e0e45 commit fe3b33b

File tree

8 files changed

+75
-1
lines changed

8 files changed

+75
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function loader(content) {
3636
const resolve = this.getResolve({
3737
mainFields: ['sass', 'style', 'main', '...'],
3838
mainFiles: ['_index', 'index', '...'],
39-
extensions: ['.scss', '.sass', '.css', '...'],
39+
extensions: ['.scss', '.sass', '.css'],
4040
});
4141

4242
const includePaths =

test/__snapshots__/loader.test.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (sass): css 1`] = `
4+
"a {
5+
color: red;
6+
}"
7+
`;
8+
9+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (sass): errors 1`] = `Array []`;
10+
11+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (sass): warnings 1`] = `Array []`;
12+
13+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): css 1`] = `
14+
"a {
15+
color: red;
16+
}"
17+
`;
18+
19+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): errors 1`] = `Array []`;
20+
21+
exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): warnings 1`] = `Array []`;
22+
23+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): css 1`] = `
24+
"a {
25+
color: red; }
26+
"
27+
`;
28+
29+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): errors 1`] = `Array []`;
30+
31+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): warnings 1`] = `Array []`;
32+
33+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): css 1`] = `
34+
"a {
35+
color: red; }
36+
"
37+
`;
38+
39+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): errors 1`] = `Array []`;
40+
41+
exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): warnings 1`] = `Array []`;
42+
343
exports[`loader should output an understandable error (dart-sass) (sass): errors 1`] = `
444
Array [
545
"ModuleBuildError: Module build failed (from ../src/cjs.js):

test/helpers/getCodeFromSass.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ function getCodeFromSass(testId, options) {
248248
testFolder,
249249
'node_modules/package-with-style-field-and-css/scss/package-with-style-field-and-css.scss'
250250
);
251+
const pathToPackageWithJsAndCssMainFiles = path.resolve(
252+
testFolder,
253+
'node_modules/package-with-js-and-css-main-files/index'
254+
);
251255

252256
// Pseudo importer for tests
253257
function testImporter(url) {
@@ -690,6 +694,10 @@ function getCodeFromSass(testId, options) {
690694
.replace(/^~bootstrap$/, pathToBootstrap4Entry)
691695
.replace(/^~module/, pathToModule)
692696
.replace(/^~another/, pathToAnother)
697+
.replace(
698+
/^~package-with-js-and-css-main-files/,
699+
pathToPackageWithJsAndCssMainFiles
700+
)
693701
.replace(/^~/, testNodeModules);
694702
}
695703

test/loader.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,25 @@ describe('loader', () => {
620620
expect(getErrors(stats)).toMatchSnapshot('errors');
621621
});
622622

623+
it(`should load only sass/scss files for the "mainFiles" (${implementationName}) (${syntax})`, async () => {
624+
const testId = getTestId(
625+
'import-package-with-js-and-css-main-files',
626+
syntax
627+
);
628+
const options = {
629+
implementation: getImplementationByName(implementationName),
630+
};
631+
const compiler = getCompiler(testId, { loader: { options } });
632+
const stats = await compile(compiler);
633+
const codeFromBundle = getCodeFromBundle(stats, compiler);
634+
const codeFromSass = getCodeFromSass(testId, options);
635+
636+
expect(codeFromBundle.css).toBe(codeFromSass.css);
637+
expect(codeFromBundle.css).toMatchSnapshot('css');
638+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
639+
expect(getErrors(stats)).toMatchSnapshot('errors');
640+
});
641+
623642
if (implementation === dartSass) {
624643
it(`should output an understandable error with a problem in "@use" (${implementationName}) (${syntax})`, async () => {
625644
const testId = getTestId('error-use', syntax);

test/node_modules/package-with-js-and-css-main-files/_index.js

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

test/node_modules/package-with-js-and-css-main-files/index.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "~package-with-js-and-css-main-files"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "~package-with-js-and-css-main-files";

0 commit comments

Comments
 (0)