2
2
// MIT-style license that can be found in the LICENSE file or at
3
3
// https://opensource.org/licenses/MIT.
4
4
5
+ import { promises as fs , readdirSync } from 'fs' ;
5
6
import * as p from 'path' ;
6
7
import * as shell from 'shelljs' ;
7
8
@@ -15,6 +16,7 @@ import * as utils from './utils';
15
16
*/
16
17
export async function getEmbeddedCompiler (
17
18
outPath : string ,
19
+ js ?: boolean ,
18
20
options ?: { ref : string } | { path : string }
19
21
) : Promise < void > {
20
22
const repo = 'dart-sass' ;
@@ -41,21 +43,49 @@ export async function getEmbeddedCompiler(
41
43
await utils . link ( languageInHost , languageInCompiler ) ;
42
44
}
43
45
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
+ }
46
63
}
47
64
48
65
// 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 {
50
67
console . log ( "Downloading Dart Sass's dependencies." ) ;
51
68
shell . exec ( 'dart pub upgrade' , {
52
69
cwd : repoPath ,
53
70
silent : true ,
54
71
} ) ;
55
72
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
+ }
61
91
}
0 commit comments