Skip to content

Commit 5d51360

Browse files
committed
Add init.ts option for pure js compiler
1 parent 75f77ee commit 5d51360

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Diff for: tool/get-embedded-compiler.ts

+38-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5+
import {promises as fs, readdirSync} from 'fs';
56
import * as p from 'path';
67
import * as shell from 'shelljs';
78

@@ -15,6 +16,7 @@ import * as utils from './utils';
1516
*/
1617
export async function getEmbeddedCompiler(
1718
outPath: string,
19+
js?: boolean,
1820
options?: {ref: string} | {path: string}
1921
): Promise<void> {
2022
const repo = 'dart-sass';
@@ -41,21 +43,49 @@ export async function getEmbeddedCompiler(
4143
await utils.link(languageInHost, languageInCompiler);
4244
}
4345

44-
buildDartSassEmbedded(source);
45-
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
46+
buildDartSassEmbedded(source, js ?? false);
47+
if (js) {
48+
// Remove any dart sass binary packages
49+
await Promise.all(
50+
['node_modules', p.join(source, 'node_modules')].flatMap(node_modules =>
51+
readdirSync(node_modules)
52+
.filter(dir => dir.startsWith('sass-embedded-'))
53+
.map(dir =>
54+
fs.rm(p.join('node_modules', dir), {force: true, recursive: true})
55+
)
56+
)
57+
);
58+
59+
await utils.link(p.join(source, 'build/npm'), 'node_modules/sass');
60+
} else {
61+
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
62+
}
4663
}
4764

4865
// Builds the Embedded Dart Sass executable from the source at `repoPath`.
49-
function buildDartSassEmbedded(repoPath: string): void {
66+
function buildDartSassEmbedded(repoPath: string, js: boolean): void {
5067
console.log("Downloading Dart Sass's dependencies.");
5168
shell.exec('dart pub upgrade', {
5269
cwd: repoPath,
5370
silent: true,
5471
});
5572

56-
console.log('Building the Dart Sass executable.');
57-
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
58-
cwd: repoPath,
59-
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
60-
});
73+
if (js) {
74+
shell.exec('npm install', {
75+
cwd: repoPath,
76+
silent: true,
77+
});
78+
79+
console.log('Building the Dart Sass npm package.');
80+
shell.exec('dart run grinder protobuf pkg-npm-dev', {
81+
cwd: repoPath,
82+
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
83+
});
84+
} else {
85+
console.log('Building the Dart Sass executable.');
86+
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
87+
cwd: repoPath,
88+
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
89+
});
90+
}
6191
}

Diff for: tool/init.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const argv = yargs(process.argv.slice(2))
1818
type: 'string',
1919
description: 'Build the Embedded Dart Sass binary from this Git ref.',
2020
})
21+
.option('compiler-js', {
22+
type: 'boolean',
23+
description: 'Build the Embedded Dart Sass with dart2js.',
24+
})
2125
.option('skip-compiler', {
2226
type: 'boolean',
2327
description: "Don't Embedded Dart Sass at all.",
@@ -55,15 +59,15 @@ void (async () => {
5559

5660
if (!argv['skip-compiler']) {
5761
if (argv['compiler-ref']) {
58-
await getEmbeddedCompiler(outPath, {
62+
await getEmbeddedCompiler(outPath, argv['compiler-js'], {
5963
ref: argv['compiler-ref'],
6064
});
6165
} else if (argv['compiler-path']) {
62-
await getEmbeddedCompiler(outPath, {
66+
await getEmbeddedCompiler(outPath, argv['compiler-js'], {
6367
path: argv['compiler-path'],
6468
});
6569
} else {
66-
await getEmbeddedCompiler(outPath);
70+
await getEmbeddedCompiler(outPath, argv['compiler-js']);
6771
}
6872
}
6973

0 commit comments

Comments
 (0)