Skip to content

Commit

Permalink
feat: support process.cwd() resolution (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Apr 17, 2020
1 parent 8376179 commit 0c8d3b3
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/getSassOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
? process.env.SASS_PATH.split(process.platform === 'win32' ? ';' : ':')
: []
)
.concat(process.cwd())
.concat(path.dirname(resourcePath));

return options;
Expand Down
68 changes: 56 additions & 12 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,51 @@ SassError: expected \\"{\\".",

exports[`loader should output an understandable error with a problem in "@use" (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (sass): css 1`] = `
exports[`loader should respect resolving from "process.cwd()" (dart-sass) (sass): css 1`] = `
"body {
font: 100% Helvetica, sans-serif;
color: #333;
}"
`;

exports[`loader should respect resolving from "process.cwd()" (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (dart-sass) (scss): css 1`] = `
"body {
font: 100% Helvetica, sans-serif;
color: #333;
}"
`;

exports[`loader should respect resolving from "process.cwd()" (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (sass): css 1`] = `
"body {
font: 100% Helvetica, sans-serif;
color: #333; }
"
`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (sass): errors 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (scss): css 1`] = `
"body {
font: 100% Helvetica, sans-serif;
color: #333; }
"
`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (scss): errors 1`] = `Array []`;

exports[`loader should respect resolving from "process.cwd()" (node-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (sass): css 1`] = `
".foo {
color: red;
}
Expand All @@ -234,11 +278,11 @@ exports[`loader should respect the "SASS_PATH" environment variable (dart-sass)
}"
`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (sass): errors 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (sass): errors 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (sass): warnings 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (scss): css 1`] = `
exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (scss): css 1`] = `
".foo {
color: red;
}
Expand All @@ -248,11 +292,11 @@ exports[`loader should respect the "SASS_PATH" environment variable (dart-sass)
}"
`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (scss): errors 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (scss): errors 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (dart-sass) (scss): warnings 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (sass): css 1`] = `
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (sass): css 1`] = `
".foo {
color: red; }

Expand All @@ -261,11 +305,11 @@ exports[`loader should respect the "SASS_PATH" environment variable (node-sass)
"
`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (sass): errors 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (sass): errors 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (sass): warnings 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (sass): warnings 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (scss): css 1`] = `
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (scss): css 1`] = `
".foo {
color: red; }

Expand All @@ -274,9 +318,9 @@ exports[`loader should respect the "SASS_PATH" environment variable (node-sass)
"
`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (scss): errors 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (scss): errors 1`] = `Array []`;

exports[`loader should respect the "SASS_PATH" environment variable (node-sass) (scss): warnings 1`] = `Array []`;
exports[`loader should respect resolving from the "SASS_PATH" environment variable (node-sass) (scss): warnings 1`] = `Array []`;

exports[`loader should throw an error with a explicit file and a file does not exist (dart-sass) (sass): errors 1`] = `
Array [
Expand Down
18 changes: 17 additions & 1 deletion test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ describe('loader', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it(`should respect the "SASS_PATH" environment variable (${implementationName}) (${syntax})`, async () => {
it(`should respect resolving from the "SASS_PATH" environment variable (${implementationName}) (${syntax})`, async () => {
const OLD_SASS_PATH = process.env.SASS_PATH;

process.env.SASS_PATH =
Expand Down Expand Up @@ -688,6 +688,22 @@ describe('loader', () => {
process.env.SASS_PATH = OLD_SASS_PATH;
});

it(`should respect resolving from "process.cwd()" (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('process-cwd', 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
1 change: 1 addition & 0 deletions test/sass/process-cwd.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'test/sass/simple'
6 changes: 6 additions & 0 deletions test/sass/simple.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$font-stack: Helvetica, sans-serif
$primary-color: #333

body
font: 100% $font-stack
color: $primary-color
1 change: 1 addition & 0 deletions test/scss/process-cwd.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'test/scss/simple';

0 comments on commit 0c8d3b3

Please sign in to comment.