Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add init.ts option for pure js compiler
Browse files Browse the repository at this point in the history
ntkme committed Oct 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 75f77ee commit 5d51360
Showing 2 changed files with 45 additions and 11 deletions.
46 changes: 38 additions & 8 deletions tool/get-embedded-compiler.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import {promises as fs, readdirSync} from 'fs';
import * as p from 'path';
import * as shell from 'shelljs';

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

buildDartSassEmbedded(source);
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
buildDartSassEmbedded(source, js ?? false);
if (js) {
// Remove any dart sass binary packages
await Promise.all(
['node_modules', p.join(source, 'node_modules')].flatMap(node_modules =>
readdirSync(node_modules)
.filter(dir => dir.startsWith('sass-embedded-'))
.map(dir =>
fs.rm(p.join('node_modules', dir), {force: true, recursive: true})
)
)
);

await utils.link(p.join(source, 'build/npm'), 'node_modules/sass');
} else {
await utils.link(p.join(source, 'build'), p.join(outPath, repo));
}
}

// Builds the Embedded Dart Sass executable from the source at `repoPath`.
function buildDartSassEmbedded(repoPath: string): void {
function buildDartSassEmbedded(repoPath: string, js: boolean): void {
console.log("Downloading Dart Sass's dependencies.");
shell.exec('dart pub upgrade', {
cwd: repoPath,
silent: true,
});

console.log('Building the Dart Sass executable.');
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
cwd: repoPath,
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
});
if (js) {
shell.exec('npm install', {
cwd: repoPath,
silent: true,
});

console.log('Building the Dart Sass npm package.');
shell.exec('dart run grinder protobuf pkg-npm-dev', {
cwd: repoPath,
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
});
} else {
console.log('Building the Dart Sass executable.');
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
cwd: repoPath,
env: {...process.env, UPDATE_SASS_PROTOCOL: 'false'},
});
}
}
10 changes: 7 additions & 3 deletions tool/init.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@ const argv = yargs(process.argv.slice(2))
type: 'string',
description: 'Build the Embedded Dart Sass binary from this Git ref.',
})
.option('compiler-js', {
type: 'boolean',
description: 'Build the Embedded Dart Sass with dart2js.',
})
.option('skip-compiler', {
type: 'boolean',
description: "Don't Embedded Dart Sass at all.",
@@ -55,15 +59,15 @@ void (async () => {

if (!argv['skip-compiler']) {
if (argv['compiler-ref']) {
await getEmbeddedCompiler(outPath, {
await getEmbeddedCompiler(outPath, argv['compiler-js'], {
ref: argv['compiler-ref'],
});
} else if (argv['compiler-path']) {
await getEmbeddedCompiler(outPath, {
await getEmbeddedCompiler(outPath, argv['compiler-js'], {
path: argv['compiler-path'],
});
} else {
await getEmbeddedCompiler(outPath);
await getEmbeddedCompiler(outPath, argv['compiler-js']);
}
}

0 comments on commit 5d51360

Please sign in to comment.