Skip to content

Commit 28e7da6

Browse files
authoredFeb 7, 2025··
Add option to use modern API in dart-sass (#312)
1 parent abc2397 commit 28e7da6

File tree

8 files changed

+51
-18
lines changed

8 files changed

+51
-18
lines changed
 

‎gruntfile.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const sass = require('node-sass');
2+
const sass = require('sass');
33

44
module.exports = grunt => {
55
grunt.initConfig({
@@ -13,6 +13,15 @@ module.exports = grunt => {
1313
'test/tmp/compile2.css': 'test/fixtures/test.scss'
1414
}
1515
},
16+
modernCompile: {
17+
options: {
18+
api: 'modern'
19+
},
20+
files: {
21+
'test/tmp/modern-compile.css': 'test/fixtures/test.scss',
22+
'test/tmp/modern-compile2.css': 'test/fixtures/test.scss'
23+
}
24+
},
1625
includePaths: {
1726
options: {
1827
includePaths: ['test/fixtures']

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
"libsass"
3030
],
3131
"devDependencies": {
32-
"grunt": "^1.0.3",
32+
"grunt": "^1.6.0",
3333
"grunt-cli": "^1.3.1",
34-
"grunt-contrib-clean": "^2.0.0",
34+
"grunt-contrib-clean": "^2.0.1",
3535
"grunt-contrib-nodeunit": "^2.0.0",
36-
"node-sass": "^4.9.3",
36+
"sass": "1.78.0",
3737
"xo": "^0.23.0"
3838
},
3939
"peerDependencies": {

‎tasks/sass.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ module.exports = grunt => {
1919
(async () => {
2020
await Promise.all(this.files.map(async item => {
2121
const [src] = item.src;
22+
let result;
2223

2324
if (!src || path.basename(src)[0] === '_') {
2425
return;
2526
}
2627

27-
const result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
28-
file: src,
29-
outFile: item.dest
30-
}));
28+
if (options.api === 'modern') {
29+
result = await options.implementation.compileAsync(src, options);
30+
} else {
31+
result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
32+
file: src,
33+
outFile: item.dest
34+
}));
35+
}
3136

3237
grunt.file.write(item.dest, result.css);
3338

‎test/expected/compile.css

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
li {
22
font-family: serif;
33
font-weight: bold;
4-
font-size: 1.2em; }
4+
font-size: 1.2em;
5+
}
56

67
.content-navigation {
78
border-color: #3bbfce;
8-
color: #2ca2af; }
9+
color: #2ca2af;
10+
}
911

1012
.border {
1113
padding: 8px;
1214
margin: 8px;
13-
border-color: #3bbfce; }
15+
border-color: #3bbfce;
16+
}

‎test/expected/include-paths.css

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
li {
22
font-family: serif;
33
font-weight: bold;
4-
font-size: 1.2em; }
4+
font-size: 1.2em;
5+
}
56

67
.content-navigation {
78
border-color: #3bbfce;
8-
color: #2ca2af; }
9+
color: #2ca2af;
10+
}
911

1012
.border {
1113
padding: 8px;
1214
margin: 8px;
13-
border-color: #3bbfce; }
15+
border-color: #3bbfce;
16+
}

‎test/fixtures/include-paths.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:math";
12
@import 'imported';
23

34
$blue: #3bbfce;
@@ -10,7 +11,7 @@ $margin: 16px;
1011
}
1112

1213
.border {
13-
padding: $margin / 2;
14-
margin: $margin / 2;
14+
padding: math.div($margin, 2);
15+
margin: math.div($margin, 2);
1516
border-color: $blue;
1617
}

‎test/fixtures/test.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:math";
12
@import 'imported';
23

34
$blue: #3bbfce;
@@ -10,7 +11,7 @@ $margin: 16px;
1011
}
1112

1213
.border {
13-
padding: $margin / 2;
14-
margin: $margin / 2;
14+
padding: math.div($margin, 2);
15+
margin: math.div($margin, 2);
1516
border-color: $blue;
1617
}

‎test/test.js

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ exports.sass = {
1313

1414
test.done();
1515
},
16+
modernCompile(test) {
17+
test.expect(2);
18+
19+
const actual = grunt.file.read('test/tmp/modern-compile.css');
20+
const actual2 = grunt.file.read('test/tmp/modern-compile2.css');
21+
const expected = grunt.file.read('test/expected/compile.css');
22+
test.equal(actual, expected, 'should compile SCSS to CSS');
23+
test.equal(actual2, expected, 'should compile SCSS to CSS');
24+
25+
test.done();
26+
},
1627
includePaths(test) {
1728
test.expect(1);
1829

0 commit comments

Comments
 (0)
Please sign in to comment.