Skip to content

Commit b2dfcb2

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

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

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

+41-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,52 @@ 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+
const modules = ['node_modules', p.join(source, 'node_modules')].flatMap(
50+
node_modules =>
51+
readdirSync(node_modules)
52+
.filter(dir => dir.startsWith('sass-embedded-'))
53+
.map(dir => p.join(node_modules, dir))
54+
);
55+
if (modules.length > 0) {
56+
console.log(`Removing ${modules.join(', ')}.`);
57+
await Promise.all(
58+
modules.map(module => fs.rm(module, {force: true, recursive: true}))
59+
);
60+
}
61+
62+
await utils.link(p.join(source, 'build/npm'), 'node_modules/sass');
63+
} else {
64+
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
65+
}
4666
}
4767

4868
// Builds the Embedded Dart Sass executable from the source at `repoPath`.
49-
function buildDartSassEmbedded(repoPath: string): void {
69+
function buildDartSassEmbedded(repoPath: string, js: boolean): void {
5070
console.log("Downloading Dart Sass's dependencies.");
5171
shell.exec('dart pub upgrade', {
5272
cwd: repoPath,
5373
silent: true,
5474
});
5575

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-
});
76+
if (js) {
77+
shell.exec('npm install', {
78+
cwd: repoPath,
79+
silent: true,
80+
});
81+
82+
console.log('Building the Dart Sass npm package.');
83+
shell.exec('dart run grinder protobuf pkg-npm-dev', {
84+
cwd: repoPath,
85+
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
86+
});
87+
} else {
88+
console.log('Building the Dart Sass executable.');
89+
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
90+
cwd: repoPath,
91+
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
92+
});
93+
}
6194
}

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)