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,52 @@ 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
+ 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
+ }
46
66
}
47
67
48
68
// 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 {
50
70
console . log ( "Downloading Dart Sass's dependencies." ) ;
51
71
shell . exec ( 'dart pub upgrade' , {
52
72
cwd : repoPath ,
53
73
silent : true ,
54
74
} ) ;
55
75
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
+ }
61
94
}
0 commit comments