Skip to content

Commit

Permalink
feat: nodeGypRebuild
Browse files Browse the repository at this point in the history
Closes #683
  • Loading branch information
develar committed Aug 20, 2016
1 parent ef5f146 commit 6d433ad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Here documented only `electron-builder` specific options:
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| 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.
| 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.
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
| 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`.
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.

<a name="MacOptions"></a>
### `.build.mac`
Expand Down
7 changes: 6 additions & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,15 @@ export interface BuildMetadata {
readonly afterPack?: (context: AfterPackContext) => Promise<any> | 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
Expand Down
9 changes: 8 additions & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -215,6 +215,13 @@ export class Packager implements BuildInfo {
}

private async installAppDependencies(platform: Platform, arch: Arch): Promise<any> {
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")
Expand Down
21 changes: 12 additions & 9 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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<any> {
Expand Down

0 comments on commit 6d433ad

Please sign in to comment.