diff --git a/docs/Options.md b/docs/Options.md
index c78d02ed73d..70527acf950 100644
--- a/docs/Options.md
+++ b/docs/Options.md
@@ -67,7 +67,8 @@ Here documented only `electron-builder` specific options:
| linux | See [.build.linux](#LinuxBuildOptions).
| compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | *programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
-| npmRebuild | Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
+| npmRebuild | *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`.
+| nodeGypRebuild | Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
### `.build.mac`
diff --git a/src/metadata.ts b/src/metadata.ts
index 0424f6f6b98..9455507a688 100755
--- a/src/metadata.ts
+++ b/src/metadata.ts
@@ -195,10 +195,15 @@ export interface BuildMetadata {
readonly afterPack?: (context: AfterPackContext) => Promise | null
/*
- Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
+ *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`.
*/
readonly npmRebuild?: boolean
+ /*
+ Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
+ */
+ readonly nodeGypRebuild?: boolean
+
readonly icon?: string | null
// deprecated
diff --git a/src/packager.ts b/src/packager.ts
index 15b8be863ad..b808ed88d91 100644
--- a/src/packager.ts
+++ b/src/packager.ts
@@ -1,7 +1,7 @@
import * as path from "path"
import {
computeDefaultAppDirectory, installDependencies, getElectronVersion, use,
- exec, isEmptyOrSpaces, statOrNull
+ exec, isEmptyOrSpaces, statOrNull, getGypEnv
} from "./util/util"
import { all, executeFinally } from "./util/promise"
import { EventEmitter } from "events"
@@ -215,6 +215,13 @@ export class Packager implements BuildInfo {
}
private async installAppDependencies(platform: Platform, arch: Arch): Promise {
+ if (this.devMetadata.build.nodeGypRebuild === true) {
+ log("Execute node-gyp rebuild")
+ await exec(process.platform === "win32" ? "node-gyp.cmd" : "node-gyp", ["rebuild"], {
+ env: getGypEnv(this.electronVersion, Arch[arch]),
+ })
+ }
+
if (this.isTwoPackageJsonProjectLayoutUsed) {
if (this.devMetadata.build.npmRebuild === false) {
log("Skip app dependencies rebuild because npmRebuild is set to false")
diff --git a/src/util/util.ts b/src/util/util.ts
index de3a09ef1c0..b1d6efd0bff 100644
--- a/src/util/util.ts
+++ b/src/util/util.ts
@@ -17,16 +17,19 @@ export const debug7z = debugFactory("electron-builder:7z")
const DEFAULT_APP_DIR_NAMES = ["app", "www"]
export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install"): BluebirdPromise {
+ return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch)))
+}
+
+export function getGypEnv(electronVersion: string, arch: string): any {
const gypHome = path.join(homedir(), ".electron-gyp")
- return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, Object.assign({}, process.env, {
- npm_config_disturl: "https://atom.io/download/atom-shell",
- npm_config_target: electronVersion,
- npm_config_runtime: "electron",
- npm_config_arch: arch,
- HOME: gypHome,
- USERPROFILE: gypHome,
- })
- ))
+ return Object.assign({}, process.env, {
+ npm_config_disturl: "https://atom.io/download/atom-shell",
+ npm_config_target: electronVersion,
+ npm_config_runtime: "electron",
+ npm_config_arch: arch,
+ HOME: gypHome,
+ USERPROFILE: gypHome,
+ })
}
export function spawnNpmProduction(command: string, appDir: string, env?: any): BluebirdPromise {