Skip to content

Commit

Permalink
Merge ac0432e into 1d8c318
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 5, 2021
2 parents 1d8c318 + ac0432e commit 695055e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -93,7 +93,7 @@
"semver": "^7.3.4",
"standard-version": "^9.1.0",
"style-loader": "^2.0.0",
"webpack": "^5.20.0"
"webpack": "^5.20.2"
},
"keywords": [
"sass",
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Expand Up @@ -369,6 +369,7 @@ function getWebpackResolver(
);
const webpackResolve = promiseResolve(
resolverFactory({
dependencyType: "sass",
conditionNames: ["sass", "style"],
mainFields: ["sass", "style", "main", "..."],
mainFiles: ["_index", "index", "..."],
Expand Down
54 changes: 54 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -167371,3 +167371,57 @@ exports[`loader should work with the "material-components-web" package without t
exports[`loader should work with the "material-components-web" package without the "includePaths" option (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should work with the "material-components-web" package without the "includePaths" option (dart-sass) (scss): warnings 2`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): css 1`] = `
".a {
color: red;
}

.b {
color: red;
}"
`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): css 1`] = `
".a {
color: red;
}

.b {
color: red;
}"
`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): css 1`] = `
".a {
color: red; }

.b {
color: red; }
"
`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): errors 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): css 1`] = `
".a {
color: red; }

.b {
color: red; }
"
`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): errors 1`] = `Array []`;

exports[`loader should work with the 'resolve.byDependecy.sass' option (node-sass) (scss): warnings 1`] = `Array []`;
4 changes: 4 additions & 0 deletions test/helpers/getCodeFromSass.js
Expand Up @@ -281,6 +281,9 @@ function getCodeFromSass(testId, options) {
__dirname,
"../../node_modules/@material"
);
const pathToCustomMainFiles = isSass
? path.resolve(testFolder, "sass/custom-main-files/custom.sass")
: path.resolve(testFolder, "scss/custom-main-files/custom.scss");

// Pseudo importer for tests
function testImporter(url) {
Expand Down Expand Up @@ -754,6 +757,7 @@ function getCodeFromSass(testId, options) {
pathToPackageWithSameImport
)
.replace(/@material/, pathToMaterial)
.replace(/custom-main-files/, pathToCustomMainFiles)
.replace(/^~/, testNodeModules);
}

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

it(`should work with the 'resolve.byDependecy.sass' option (${implementationName}) (${syntax})`, async () => {
const testId = getTestId("by-dependency", syntax);
const options = {
implementation: getImplementationByName(implementationName),
};
const compiler = getCompiler(testId, {
loader: { options },
resolve: {
byDependency: {
sass: {
mainFiles: ["custom"],
},
},
},
});
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
4 changes: 4 additions & 0 deletions test/sass/by-dependency.sass
@@ -0,0 +1,4 @@
@import "custom-main-files"

.b
color: red
2 changes: 2 additions & 0 deletions test/sass/custom-main-files/custom.sass
@@ -0,0 +1,2 @@
.a
color: red
5 changes: 5 additions & 0 deletions test/scss/by-dependency.scss
@@ -0,0 +1,5 @@
@import "custom-main-files";

.b {
color: red;
}
3 changes: 3 additions & 0 deletions test/scss/custom-main-files/custom.scss
@@ -0,0 +1,3 @@
.a {
color: red
}

0 comments on commit 695055e

Please sign in to comment.