diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index d9c88eef..cb2d82ea 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -61,6 +61,10 @@ jobs: runs-on: ${{ matrix.os }} steps: + - name: Setup Git + if: matrix.os == 'windows-latest' + run: git config --global core.autocrlf input + - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} diff --git a/src/getSassOptions.js b/src/getSassOptions.js index 9d6d388b..978c6ba4 100644 --- a/src/getSassOptions.js +++ b/src/getSassOptions.js @@ -1,4 +1,3 @@ -import os from 'os'; import path from 'path'; import cloneDeep from 'clone-deep'; @@ -60,8 +59,8 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) { options.data = loaderOptions.prependData ? typeof loaderOptions.prependData === 'function' - ? loaderOptions.prependData(loaderContext) + os.EOL + content - : loaderOptions.prependData + os.EOL + content + ? `${loaderOptions.prependData(loaderContext)}\n${content}` + : `${loaderOptions.prependData}\n${content}` : content; // opt.outputStyle diff --git a/test/__snapshots__/prependData-option.test.js.snap b/test/__snapshots__/prependData-option.test.js.snap index b240559a..b6602137 100644 --- a/test/__snapshots__/prependData-option.test.js.snap +++ b/test/__snapshots__/prependData-option.test.js.snap @@ -1,5 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`prependData option should use same EOL on all os (dart-sass) (sass): css 1`] = ` +"a { + color: hotpink; +} + +body { + color: hotpink; +}" +`; + +exports[`prependData option should use same EOL on all os (dart-sass) (sass): errors 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (dart-sass) (sass): warnings 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (dart-sass) (scss): css 1`] = ` +"a { + color: red; +} + +body { + color: hotpink; +}" +`; + +exports[`prependData option should use same EOL on all os (dart-sass) (scss): errors 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (dart-sass) (scss): warnings 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (node-sass) (sass): css 1`] = ` +"a { + color: hotpink; } + +body { + color: hotpink; } +" +`; + +exports[`prependData option should use same EOL on all os (node-sass) (sass): errors 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (node-sass) (sass): warnings 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (node-sass) (scss): css 1`] = ` +"a { + color: red; } + +body { + color: hotpink; } +" +`; + +exports[`prependData option should use same EOL on all os (node-sass) (scss): errors 1`] = `Array []`; + +exports[`prependData option should use same EOL on all os (node-sass) (scss): warnings 1`] = `Array []`; + exports[`prependData option should work with the "data" option as a function (dart-sass) (sass): css 1`] = ` "body { color: hotpink; diff --git a/test/helpers/getCodeFromSass.js b/test/helpers/getCodeFromSass.js index 93bc33eb..930afe23 100644 --- a/test/helpers/getCodeFromSass.js +++ b/test/helpers/getCodeFromSass.js @@ -1,5 +1,4 @@ import path from 'path'; -import os from 'os'; import fs from 'fs'; function getCodeFromSass(testId, options) { @@ -23,10 +22,7 @@ function getCodeFromSass(testId, options) { sassOptions.indentedSyntax = isSass; sassOptions.data = `$prepended-data: hotpink${ sassOptions.indentedSyntax ? '\n' : ';' - }${os.EOL}${fs.readFileSync( - path.resolve(__dirname, '..', testId), - 'utf8' - )}`; + }\n${fs.readFileSync(path.resolve(__dirname, '..', testId), 'utf8')}`; } else { sassOptions.file = path.resolve(__dirname, '..', testId); } diff --git a/test/prependData-option.test.js b/test/prependData-option.test.js index 05e83c6f..40ee5a2d 100644 --- a/test/prependData-option.test.js +++ b/test/prependData-option.test.js @@ -65,6 +65,30 @@ describe('prependData option', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it(`should use same EOL on all os (${implementationName}) (${syntax})`, async () => { + const testId = getTestId('prepending-data', syntax); + const prependData = + syntax === 'sass' + ? `$prepended-data: hotpink +a + color: $prepended-data` + : `$prepended-data: hotpink; +a { + color: red; +}`; + const options = { + implementation: getImplementationByName(implementationName), + prependData, + }; + const compiler = getCompiler(testId, { loader: { options } }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); }); }); });