diff --git a/src/getSassOptions.js b/src/getSassOptions.js index 73ce1435..565637da 100644 --- a/src/getSassOptions.js +++ b/src/getSassOptions.js @@ -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; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 98aad299..f08ffe94 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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 [ diff --git a/test/loader.test.js b/test/loader.test.js index 576c6e6a..272be120 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -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 = @@ -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); diff --git a/test/sass/process-cwd.sass b/test/sass/process-cwd.sass new file mode 100644 index 00000000..bfbaa98f --- /dev/null +++ b/test/sass/process-cwd.sass @@ -0,0 +1 @@ +@import 'test/sass/simple' diff --git a/test/sass/simple.sass b/test/sass/simple.sass new file mode 100644 index 00000000..70364abb --- /dev/null +++ b/test/sass/simple.sass @@ -0,0 +1,6 @@ +$font-stack: Helvetica, sans-serif +$primary-color: #333 + +body + font: 100% $font-stack + color: $primary-color diff --git a/test/scss/process-cwd.scss b/test/scss/process-cwd.scss new file mode 100644 index 00000000..6d2e1cdd --- /dev/null +++ b/test/scss/process-cwd.scss @@ -0,0 +1 @@ +@import 'test/scss/simple';