Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a setting for --build-from-option flag #790

Merged
merged 4 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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