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 } from 'fs' ;
56import * as p from 'path' ;
67import * as shell from 'shelljs' ;
78
9+ import { compilerModule } from '../lib/src/compiler-module' ;
810import * as utils from './utils' ;
911
1012/**
@@ -14,7 +16,7 @@ import * as utils from './utils';
1416 * at `path`. By default, checks out the latest revision from GitHub.
1517 */
1618export async function getEmbeddedCompiler (
17- outPath : string ,
19+ js ?: boolean ,
1820 options ?: { ref : string } | { path : string } ,
1921) : Promise < void > {
2022 const repo = 'dart-sass' ;
@@ -41,21 +43,43 @@ 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+
48+ const jsModulePath = p . resolve ( 'node_modules/sass' ) ;
49+ const dartModulePath = p . resolve ( p . join ( 'node_modules' , compilerModule ) ) ;
50+ if ( js ) {
51+ await fs . rm ( dartModulePath , { force : true , recursive : true } ) ;
52+ await utils . link ( p . join ( source , 'build/npm' ) , jsModulePath ) ;
53+ } else {
54+ await fs . rm ( jsModulePath , { force : true , recursive : true } ) ;
55+ await utils . link ( p . join ( source , 'build' ) , p . join ( dartModulePath , repo ) ) ;
56+ }
4657}
4758
4859// Builds the Embedded Dart Sass executable from the source at `repoPath`.
49- function buildDartSassEmbedded ( repoPath : string ) : void {
60+ function buildDartSassEmbedded ( repoPath : string , js : boolean ) : void {
5061 console . log ( "Downloading Dart Sass's dependencies." ) ;
5162 shell . exec ( 'dart pub upgrade' , {
5263 cwd : repoPath ,
5364 silent : true ,
5465 } ) ;
5566
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- } ) ;
67+ if ( js ) {
68+ shell . exec ( 'npm install' , {
69+ cwd : repoPath ,
70+ silent : true ,
71+ } ) ;
72+
73+ console . log ( 'Building the Dart Sass npm package.' ) ;
74+ shell . exec ( 'dart run grinder protobuf pkg-npm-dev' , {
75+ cwd : repoPath ,
76+ env : { ...process . env , UPDATE_SASS_PROTOCOL : 'false' } ,
77+ } ) ;
78+ } else {
79+ console . log ( 'Building the Dart Sass executable.' ) ;
80+ shell . exec ( 'dart run grinder protobuf pkg-standalone-dev' , {
81+ cwd : repoPath ,
82+ env : { ...process . env , UPDATE_SASS_PROTOCOL : 'false' } ,
83+ } ) ;
84+ }
6185}
0 commit comments