@@ -4,29 +4,28 @@ import { Lazy } from "lazy-val"
4
4
import { homedir } from "os"
5
5
import * as path from "path"
6
6
import { Configuration } from "../configuration"
7
- import { executeAppBuilderAndWriteJson } from "./appBuilder"
8
7
import { NodeModuleDirInfo } from "./packageDependencies"
8
+ import * as electronRebuild from "electron-rebuild"
9
+ import { getElectronVersion } from "../electron/electronVersion"
9
10
10
11
export async function installOrRebuild ( config : Configuration , appDir : string , options : RebuildOptions , forceInstall = false ) {
11
- const effectiveOptions = {
12
- buildFromSource : config . buildDependenciesFromSource === true ,
13
- additionalArgs : asArray ( config . npmArgs ) ,
14
- ...options ,
15
- }
16
12
let isDependenciesInstalled = false
17
-
18
13
for ( const fileOrDir of [ "node_modules" , ".pnp.js" ] ) {
19
14
if ( await pathExists ( path . join ( appDir , fileOrDir ) ) ) {
20
15
isDependenciesInstalled = true
21
-
22
16
break
23
17
}
24
18
}
25
19
26
20
if ( forceInstall || ! isDependenciesInstalled ) {
21
+ const effectiveOptions : RebuildOptions = {
22
+ buildFromSource : config . buildDependenciesFromSource === true ,
23
+ additionalArgs : asArray ( config . npmArgs ) ,
24
+ ...options ,
25
+ }
27
26
await installDependencies ( appDir , effectiveOptions )
28
27
} else {
29
- await rebuild ( appDir , effectiveOptions )
28
+ await rebuild ( appDir , config . buildDependenciesFromSource === true , options . arch )
30
29
}
31
30
}
32
31
@@ -119,23 +118,8 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
119
118
} )
120
119
}
121
120
122
- export async function nodeGypRebuild ( platform : NodeJS . Platform , arch : string , frameworkInfo : DesktopFrameworkInfo ) {
123
- log . info ( { platform, arch } , "executing node-gyp rebuild" )
124
- // this script must be used only for electron
125
- const nodeGyp = `node-gyp${ process . platform === "win32" ? ".cmd" : "" } `
126
- const args = [ "rebuild" ]
127
- // headers of old Electron versions do not have a valid config.gypi file
128
- // and --force-process-config must be passed to node-gyp >= 8.4.0 to
129
- // correctly build modules for them.
130
- // see also https://github.com/nodejs/node-gyp/pull/2497
131
- const [ major , minor ] = frameworkInfo . version
132
- . split ( "." )
133
- . slice ( 0 , 2 )
134
- . map ( n => parseInt ( n , 10 ) )
135
- if ( major <= 13 || ( major == 14 && minor <= 1 ) || ( major == 15 && minor <= 2 ) ) {
136
- args . push ( "--force-process-config" )
137
- }
138
- await spawn ( nodeGyp , args , { env : getGypEnv ( frameworkInfo , platform , arch , true ) } )
121
+ export async function nodeGypRebuild ( arch : string ) {
122
+ return rebuild ( process . cwd ( ) , false , arch )
139
123
}
140
124
141
125
function getPackageToolPath ( ) {
@@ -164,17 +148,17 @@ export interface RebuildOptions {
164
148
}
165
149
166
150
/** @internal */
167
- export async function rebuild ( appDir : string , options : RebuildOptions ) {
168
- const configuration : any = {
169
- dependencies : await options . productionDeps ! . value ,
170
- nodeExecPath : process . execPath ,
171
- platform : options . platform || process . platform ,
172
- arch : options . arch || process . arch ,
173
- additionalArgs : options . additionalArgs ,
174
- execPath : process . env . npm_execpath || process . env . NPM_CLI_JS ,
175
- buildFromSource : options . buildFromSource === true ,
151
+ export async function rebuild ( appDir : string , buildFromSource : boolean , arch = process . arch ) {
152
+ log . info ( { appDir, arch } , "executing electron-rebuild" )
153
+ const options : electronRebuild . RebuildOptions = {
154
+ buildPath : appDir ,
155
+ electronVersion : await getElectronVersion ( appDir ) ,
156
+ arch,
157
+ force : true ,
158
+ debug : log . isDebugEnabled ,
176
159
}
177
-
178
- const env = getGypEnv ( options . frameworkInfo , configuration . platform , configuration . arch , options . buildFromSource === true )
179
- await executeAppBuilderAndWriteJson ( [ "rebuild-node-modules" ] , configuration , { env, cwd : appDir } )
160
+ if ( buildFromSource ) {
161
+ options . prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"
162
+ }
163
+ return electronRebuild . rebuild ( options )
180
164
}
0 commit comments