Skip to content

Commit

Permalink
feat: make a setting for --build-from-option flag
Browse files Browse the repository at this point in the history
Closes #787, #790
  • Loading branch information
0181532686cf4a31163be0bf3e6bb6732bf authored and develar committed Oct 6, 2016
1 parent 956a52d commit 4898eb1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Don't customize paths to background and icon, — just follow conventions.
| 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>*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`.
| 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`.
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
| 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.

Expand Down
5 changes: 5 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ export interface BuildMetadata {
*/
readonly npmRebuild?: boolean

/*
*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`.
*/
readonly npmSkipBuildFromSource?: boolean

/*
Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ export class Packager implements BuildInfo {
log("Skip app dependencies rebuild because npmRebuild is set to false")
}
else if (platform.nodeName === process.platform) {
await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild")
let doSourceBuild = !(this.devMetadata.build.npmSkipBuildFromSource === true)
await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild", doSourceBuild)
}
else {
log("Skip app dependencies rebuild because platform is different")
Expand Down
11 changes: 7 additions & 4 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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 installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install", fromSource: boolean = true): BluebirdPromise<any> {
return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch), fromSource))
}

export function getGypEnv(electronVersion: string, arch: string): any {
Expand All @@ -32,16 +32,19 @@ export function getGypEnv(electronVersion: string, arch: string): any {
})
}

export function spawnNpmProduction(command: string, appDir: string, env?: any): BluebirdPromise<any> {
export function spawnNpmProduction(command: string, appDir: string, env?: any, forceBuild: boolean = true): BluebirdPromise<any> {
let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS
const npmExecArgs = [command, "--production", "--build-from-source", "--cache-min", "999999999"]
let npmExecArgs = [command, "--production", "--cache-min", "999999999"]
if (npmExecPath == null) {
npmExecPath = process.platform === "win32" ? "npm.cmd" : "npm"
}
else {
npmExecArgs.unshift(npmExecPath)
npmExecPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node"
}
if (forceBuild) {
npmExecArgs.push("--build-from-source")
}

return spawn(npmExecPath, npmExecArgs, {
cwd: appDir,
Expand Down

0 comments on commit 4898eb1

Please sign in to comment.