Skip to content

Commit 68dd278

Browse files
fix: avoid different content on different os (#832)
1 parent 1655baf commit 68dd278

File tree

5 files changed

+85
-8
lines changed

5 files changed

+85
-8
lines changed

.github/workflows/nodejs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ jobs:
6161
runs-on: ${{ matrix.os }}
6262

6363
steps:
64+
- name: Setup Git
65+
if: matrix.os == 'windows-latest'
66+
run: git config --global core.autocrlf input
67+
6468
- uses: actions/checkout@v2
6569

6670
- name: Use Node.js ${{ matrix.node-version }}

src/getSassOptions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os from 'os';
21
import path from 'path';
32

43
import cloneDeep from 'clone-deep';
@@ -60,8 +59,8 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
6059

6160
options.data = loaderOptions.prependData
6261
? typeof loaderOptions.prependData === 'function'
63-
? loaderOptions.prependData(loaderContext) + os.EOL + content
64-
: loaderOptions.prependData + os.EOL + content
62+
? `${loaderOptions.prependData(loaderContext)}\n${content}`
63+
: `${loaderOptions.prependData}\n${content}`
6564
: content;
6665

6766
// opt.outputStyle

test/__snapshots__/prependData-option.test.js.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`prependData option should use same EOL on all os (dart-sass) (sass): css 1`] = `
4+
"a {
5+
color: hotpink;
6+
}
7+
8+
body {
9+
color: hotpink;
10+
}"
11+
`;
12+
13+
exports[`prependData option should use same EOL on all os (dart-sass) (sass): errors 1`] = `Array []`;
14+
15+
exports[`prependData option should use same EOL on all os (dart-sass) (sass): warnings 1`] = `Array []`;
16+
17+
exports[`prependData option should use same EOL on all os (dart-sass) (scss): css 1`] = `
18+
"a {
19+
color: red;
20+
}
21+
22+
body {
23+
color: hotpink;
24+
}"
25+
`;
26+
27+
exports[`prependData option should use same EOL on all os (dart-sass) (scss): errors 1`] = `Array []`;
28+
29+
exports[`prependData option should use same EOL on all os (dart-sass) (scss): warnings 1`] = `Array []`;
30+
31+
exports[`prependData option should use same EOL on all os (node-sass) (sass): css 1`] = `
32+
"a {
33+
color: hotpink; }
34+
35+
body {
36+
color: hotpink; }
37+
"
38+
`;
39+
40+
exports[`prependData option should use same EOL on all os (node-sass) (sass): errors 1`] = `Array []`;
41+
42+
exports[`prependData option should use same EOL on all os (node-sass) (sass): warnings 1`] = `Array []`;
43+
44+
exports[`prependData option should use same EOL on all os (node-sass) (scss): css 1`] = `
45+
"a {
46+
color: red; }
47+
48+
body {
49+
color: hotpink; }
50+
"
51+
`;
52+
53+
exports[`prependData option should use same EOL on all os (node-sass) (scss): errors 1`] = `Array []`;
54+
55+
exports[`prependData option should use same EOL on all os (node-sass) (scss): warnings 1`] = `Array []`;
56+
357
exports[`prependData option should work with the "data" option as a function (dart-sass) (sass): css 1`] = `
458
"body {
559
color: hotpink;

test/helpers/getCodeFromSass.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'path';
2-
import os from 'os';
32
import fs from 'fs';
43

54
function getCodeFromSass(testId, options) {
@@ -23,10 +22,7 @@ function getCodeFromSass(testId, options) {
2322
sassOptions.indentedSyntax = isSass;
2423
sassOptions.data = `$prepended-data: hotpink${
2524
sassOptions.indentedSyntax ? '\n' : ';'
26-
}${os.EOL}${fs.readFileSync(
27-
path.resolve(__dirname, '..', testId),
28-
'utf8'
29-
)}`;
25+
}\n${fs.readFileSync(path.resolve(__dirname, '..', testId), 'utf8')}`;
3026
} else {
3127
sassOptions.file = path.resolve(__dirname, '..', testId);
3228
}

test/prependData-option.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,30 @@ describe('prependData option', () => {
6565
expect(getWarnings(stats)).toMatchSnapshot('warnings');
6666
expect(getErrors(stats)).toMatchSnapshot('errors');
6767
});
68+
69+
it(`should use same EOL on all os (${implementationName}) (${syntax})`, async () => {
70+
const testId = getTestId('prepending-data', syntax);
71+
const prependData =
72+
syntax === 'sass'
73+
? `$prepended-data: hotpink
74+
a
75+
color: $prepended-data`
76+
: `$prepended-data: hotpink;
77+
a {
78+
color: red;
79+
}`;
80+
const options = {
81+
implementation: getImplementationByName(implementationName),
82+
prependData,
83+
};
84+
const compiler = getCompiler(testId, { loader: { options } });
85+
const stats = await compile(compiler);
86+
const codeFromBundle = getCodeFromBundle(stats, compiler);
87+
88+
expect(codeFromBundle.css).toMatchSnapshot('css');
89+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
90+
expect(getErrors(stats)).toMatchSnapshot('errors');
91+
});
6892
});
6993
});
7094
});

0 commit comments

Comments
 (0)