Skip to content

Commit 4898eb1

Browse files
feat: make a setting for --build-from-option flag
Closes #787, #790
1 parent 956a52d commit 4898eb1

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Don't customize paths to background and icon, — just follow conventions.
8181
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
8282
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
8383
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>*two package.json structure only* Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
84+
| npmSkipBuildFromSource | <a name="BuildMetadata-npmSkipBuildFromSource"></a>*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
8485
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
8586
| electronDist | <a name="BuildMetadata-electronDist"></a>The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
8687

src/metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ export interface BuildMetadata {
201201
*/
202202
readonly npmRebuild?: boolean
203203

204+
/*
205+
*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
206+
*/
207+
readonly npmSkipBuildFromSource?: boolean
208+
204209
/*
205210
Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
206211
*/

src/packager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ export class Packager implements BuildInfo {
235235
log("Skip app dependencies rebuild because npmRebuild is set to false")
236236
}
237237
else if (platform.nodeName === process.platform) {
238-
await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild")
238+
let doSourceBuild = !(this.devMetadata.build.npmSkipBuildFromSource === true)
239+
await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild", doSourceBuild)
239240
}
240241
else {
241242
log("Skip app dependencies rebuild because platform is different")

src/util/util.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const debug7z = debugFactory("electron-builder:7z")
1616

1717
const DEFAULT_APP_DIR_NAMES = ["app", "www"]
1818

19-
export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install"): BluebirdPromise<any> {
20-
return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch)))
19+
export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install", fromSource: boolean = true): BluebirdPromise<any> {
20+
return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch), fromSource))
2121
}
2222

2323
export function getGypEnv(electronVersion: string, arch: string): any {
@@ -32,16 +32,19 @@ export function getGypEnv(electronVersion: string, arch: string): any {
3232
})
3333
}
3434

35-
export function spawnNpmProduction(command: string, appDir: string, env?: any): BluebirdPromise<any> {
35+
export function spawnNpmProduction(command: string, appDir: string, env?: any, forceBuild: boolean = true): BluebirdPromise<any> {
3636
let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS
37-
const npmExecArgs = [command, "--production", "--build-from-source", "--cache-min", "999999999"]
37+
let npmExecArgs = [command, "--production", "--cache-min", "999999999"]
3838
if (npmExecPath == null) {
3939
npmExecPath = process.platform === "win32" ? "npm.cmd" : "npm"
4040
}
4141
else {
4242
npmExecArgs.unshift(npmExecPath)
4343
npmExecPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node"
4444
}
45+
if (forceBuild) {
46+
npmExecArgs.push("--build-from-source")
47+
}
4548

4649
return spawn(npmExecPath, npmExecArgs, {
4750
cwd: appDir,

0 commit comments

Comments
 (0)