From 3e341106c35ed452fd82502c90ac6af42c1cba45 Mon Sep 17 00:00:00 2001 From: develar Date: Thu, 6 Oct 2016 11:07:26 +0200 Subject: [PATCH] fix: make install-app-deps also handle skip build flag Closes #797 --- src/install-app-deps.ts | 2 +- src/packager.ts | 4 ++-- src/util/util.ts | 10 +++++----- test/src/helpers/packTester.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/install-app-deps.ts b/src/install-app-deps.ts index 7dd29dde966..fc7c856c913 100644 --- a/src/install-app-deps.ts +++ b/src/install-app-deps.ts @@ -30,7 +30,7 @@ async function main() { throw new Error("install-app-deps is only useful for two package.json structure") } - await installDependencies(results[0], results[1], args.arch) + await installDependencies(results[0], results[1], args.arch, devMetadata.build.npmSkipBuildFromSource !== true) } main() diff --git a/src/packager.ts b/src/packager.ts index 76b6190e5f8..af389e390bb 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -235,8 +235,8 @@ export class Packager implements BuildInfo { log("Skip app dependencies rebuild because npmRebuild is set to false") } else if (platform.nodeName === process.platform) { - 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) + const forceBuildFromSource = this.devMetadata.build.npmSkipBuildFromSource !== true + await installDependencies(this.appDir, this.electronVersion, Arch[arch], forceBuildFromSource, (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild") } else { log("Skip app dependencies rebuild because platform is different") diff --git a/src/util/util.ts b/src/util/util.ts index 52979edc361..53e56b8287b 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -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", fromSource: boolean = true): BluebirdPromise { - return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch), fromSource)) +export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, forceBuildFromSource: boolean, command: string = "install"): BluebirdPromise { + return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, forceBuildFromSource, getGypEnv(electronVersion, arch))) } export function getGypEnv(electronVersion: string, arch: string): any { @@ -32,9 +32,9 @@ export function getGypEnv(electronVersion: string, arch: string): any { }) } -export function spawnNpmProduction(command: string, appDir: string, env?: any, forceBuild: boolean = true): BluebirdPromise { +export function spawnNpmProduction(command: string, appDir: string, forceBuildFromSource: boolean, env?: any): BluebirdPromise { let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS - let npmExecArgs = [command, "--production", "--cache-min", "999999999"] + const npmExecArgs = [command, "--production", "--cache-min", "999999999"] if (npmExecPath == null) { npmExecPath = process.platform === "win32" ? "npm.cmd" : "npm" } @@ -42,7 +42,7 @@ export function spawnNpmProduction(command: string, appDir: string, env?: any, f npmExecArgs.unshift(npmExecPath) npmExecPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node" } - if (forceBuild) { + if (forceBuildFromSource) { npmExecArgs.push("--build-from-source") } diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index 5329214e476..408bcbbf950 100755 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -95,7 +95,7 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO if (projectDirCreated != null) { await projectDirCreated(projectDir) if (checkOptions.npmInstallBefore) { - await spawnNpmProduction("install", projectDir) + await spawnNpmProduction("install", projectDir, false) } }