@@ -15,7 +15,7 @@ export async function installOrRebuild(options: BuildMetadata, appDir: string, e
15
15
}
16
16
}
17
17
18
- export function getGypEnv ( electronVersion : string , arch : string ) : any {
18
+ export function getGypEnv ( electronVersion : string , arch : string ) {
19
19
const gypHome = path . join ( homedir ( ) , ".electron-gyp" )
20
20
return Object . assign ( { } , process . env , {
21
21
npm_config_disturl : "https://atom.io/download/electron" ,
@@ -37,23 +37,23 @@ function computeExtraArgs(options: BuildMetadata) {
37
37
38
38
export function installDependencies ( appDir : string , electronVersion : string , arch : string = process . arch , additionalArgs : Array < string > ) : Promise < any > {
39
39
log ( `Installing app dependencies for arch ${ arch } to ${ appDir } ` )
40
- let npmExecPath = process . env . npm_execpath || process . env . NPM_CLI_JS
40
+ let execPath = process . env . npm_execpath || process . env . NPM_CLI_JS
41
41
const npmExecArgs = [ "install" , "--production" ]
42
42
43
- const isYarn = npmExecPath != null && npmExecPath . includes ( "yarn" )
43
+ const isYarn = isYarnPath ( execPath )
44
44
if ( ! isYarn ) {
45
45
if ( process . env . NPM_NO_BIN_LINKS === "true" ) {
46
46
npmExecArgs . push ( "--no-bin-links" )
47
47
}
48
48
npmExecArgs . push ( "--cache-min" , "999999999" )
49
49
}
50
50
51
- if ( npmExecPath == null ) {
52
- npmExecPath = getPackageToolPath ( )
51
+ if ( execPath == null ) {
52
+ execPath = getPackageToolPath ( )
53
53
}
54
54
else {
55
- npmExecArgs . unshift ( npmExecPath )
56
- npmExecPath = process . env . npm_node_execpath || process . env . NODE_EXE || "node"
55
+ npmExecArgs . unshift ( execPath )
56
+ execPath = process . env . npm_node_execpath || process . env . NODE_EXE || "node"
57
57
}
58
58
59
59
for ( let a of additionalArgs ) {
@@ -62,7 +62,7 @@ export function installDependencies(appDir: string, electronVersion: string, arc
62
62
}
63
63
}
64
64
65
- return spawn ( npmExecPath , npmExecArgs , {
65
+ return spawn ( execPath , npmExecArgs , {
66
66
cwd : appDir ,
67
67
env : getGypEnv ( electronVersion , arch ) ,
68
68
} )
@@ -115,6 +115,10 @@ function getPackageToolPath() {
115
115
}
116
116
}
117
117
118
+ function isYarnPath ( execPath : string | null ) {
119
+ return execPath != null && path . basename ( execPath ) . startsWith ( "yarn" )
120
+ }
121
+
118
122
export async function rebuild ( appDir : string , electronVersion : string , arch : string = process . arch , additionalArgs : Array < string > ) {
119
123
const deps = new Set < string > ( )
120
124
await dependencies ( appDir , false , deps )
@@ -127,27 +131,28 @@ export async function rebuild(appDir: string, electronVersion: string, arch: str
127
131
log ( `Rebuilding native production dependencies for arch ${ arch } ` )
128
132
129
133
let execPath = process . env . npm_execpath || process . env . NPM_CLI_JS
130
- const execArgs = [ "run" , "install" , "--" ]
131
-
134
+ const execArgs : Array < string > = [ ]
132
135
if ( execPath == null ) {
133
136
execPath = getPackageToolPath ( )
134
137
}
135
138
else {
136
- execArgs . unshift ( execPath )
139
+ execArgs . push ( execPath )
137
140
execPath = process . env . npm_node_execpath || process . env . NODE_EXE || "node"
138
141
}
139
142
140
- const gypHome = path . join ( homedir ( ) , ".electron-gyp" )
141
- const env = Object . assign ( { } , process . env , {
142
- HOME : gypHome ,
143
- USERPROFILE : gypHome ,
144
- } )
145
-
146
- execArgs . push ( "--disturl=https://atom.io/download/electron" )
147
- execArgs . push ( `--target=${ electronVersion } ` )
148
- execArgs . push ( "--runtime=electron" )
149
- execArgs . push ( `--arch=${ arch } ` )
150
- execArgs . push ( ...additionalArgs )
151
-
152
- await BluebirdPromise . each ( nativeDeps , it => spawn ( execPath , execArgs , { cwd : it , env : env } ) )
143
+ const env = getGypEnv ( electronVersion , arch )
144
+ if ( isYarnPath ( execPath ) ) {
145
+ execArgs . push ( "run" , "install" , "--" )
146
+ execArgs . push ( "--disturl=https://atom.io/download/electron" )
147
+ execArgs . push ( `--target=${ electronVersion } ` )
148
+ execArgs . push ( "--runtime=electron" )
149
+ execArgs . push ( `--arch=${ arch } ` )
150
+ execArgs . push ( ...additionalArgs )
151
+ await BluebirdPromise . each ( nativeDeps , it => spawn ( execPath , execArgs , { cwd : it , env : env } ) )
152
+ }
153
+ else {
154
+ execArgs . push ( "rebuild" )
155
+ execArgs . push ( ...nativeDeps . map ( it => path . basename ( it ) ) )
156
+ await spawn ( execPath , execArgs , { cwd : appDir , env : env } )
157
+ }
153
158
}
0 commit comments