Skip to content

Commit

Permalink
fix: resolution logic (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Apr 16, 2020
1 parent 41e0e45 commit fe3b33b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -36,7 +36,7 @@ function loader(content) {
const resolve = this.getResolve({
mainFields: ['sass', 'style', 'main', '...'],
mainFiles: ['_index', 'index', '...'],
extensions: ['.scss', '.sass', '.css', '...'],
extensions: ['.scss', '.sass', '.css'],
});

const includePaths =
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 load only sass/scss files for the "mainFiles" (dart-sass) (sass): css 1`] = `
"a {
color: red;
}"
`;

exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): css 1`] = `
"a {
color: red;
}"
`;

exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): css 1`] = `
"a {
color: red; }
"
`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): errors 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): css 1`] = `
"a {
color: red; }
"
`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): errors 1`] = `Array []`;

exports[`loader should load only sass/scss files for the "mainFiles" (node-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should output an understandable error (dart-sass) (sass): errors 1`] = `
Array [
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/getCodeFromSass.js
Expand Up @@ -248,6 +248,10 @@ function getCodeFromSass(testId, options) {
testFolder,
'node_modules/package-with-style-field-and-css/scss/package-with-style-field-and-css.scss'
);
const pathToPackageWithJsAndCssMainFiles = path.resolve(
testFolder,
'node_modules/package-with-js-and-css-main-files/index'
);

// Pseudo importer for tests
function testImporter(url) {
Expand Down Expand Up @@ -690,6 +694,10 @@ function getCodeFromSass(testId, options) {
.replace(/^~bootstrap$/, pathToBootstrap4Entry)
.replace(/^~module/, pathToModule)
.replace(/^~another/, pathToAnother)
.replace(
/^~package-with-js-and-css-main-files/,
pathToPackageWithJsAndCssMainFiles
)
.replace(/^~/, testNodeModules);
}

Expand Down
19 changes: 19 additions & 0 deletions test/loader.test.js
Expand Up @@ -620,6 +620,25 @@ describe('loader', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it(`should load only sass/scss files for the "mainFiles" (${implementationName}) (${syntax})`, async () => {
const testId = getTestId(
'import-package-with-js-and-css-main-files',
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');
});

if (implementation === dartSass) {
it(`should output an understandable error with a problem in "@use" (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('error-use', syntax);
Expand Down

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

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-package-with-js-and-css-main-files.sass
@@ -0,0 +1 @@
@import "~package-with-js-and-css-main-files"
1 change: 1 addition & 0 deletions test/scss/import-package-with-js-and-css-main-files.scss
@@ -0,0 +1 @@
@import "~package-with-js-and-css-main-files";

0 comments on commit fe3b33b

Please sign in to comment.