Skip to content

Commit eec5b32

Browse files
mmckeggdevelar
authored andcommitted
feat: add ability to specify additional npm rebuild args (#881)
* feat: add ability to specify additional npm rebuild args
1 parent 3bc99e1 commit eec5b32

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Don't customize paths to background and icon, — just follow conventions.
8484
| 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.
8585
| 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`.
8686
| 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`.
87+
| npmArgs | <a name="BuildMetadata-npmArgs"></a>*two package.json structure only* Additional command line arguments to use when installing app native deps. Defaults to `null`.
8788
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
8889
| 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.
8990
| publish | <a name="BuildMetadata-publish"></a>See [.build.publish](#PublishConfiguration).

src/metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ export interface BuildMetadata {
207207
*/
208208
readonly npmSkipBuildFromSource?: boolean
209209

210+
/*
211+
*two package.json structure only* Additional command line arguments to use when installing app native deps. Defaults to `null`.
212+
*/
213+
readonly npmArgs?: Array<string> | string | null
214+
210215
/*
211216
Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
212217
*/

src/packager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class Packager implements BuildInfo {
241241
log("Skip app dependencies rebuild because platform is different")
242242
}
243243
else {
244-
await installDependencies(this.appDir, this.electronVersion, Arch[arch], forceBuildFromSource, (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild")
244+
await installDependencies(this.appDir, this.electronVersion, Arch[arch], forceBuildFromSource, (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild", this.devMetadata.build.npmArgs)
245245
}
246246
}
247247
}

src/util/util.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const debug7z: Debugger = _debug("electron-builder:7z")
1616

1717
const DEFAULT_APP_DIR_NAMES = ["app", "www"]
1818

19-
export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, forceBuildFromSource: boolean, command: string = "install"): Promise<any> {
20-
return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, forceBuildFromSource, getGypEnv(electronVersion, arch)))
19+
export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, forceBuildFromSource: boolean, command: string = "install", additionalArgs?: any): Promise<any> {
20+
return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, forceBuildFromSource, getGypEnv(electronVersion, arch), additionalArgs))
2121
}
2222

2323
export function getGypEnv(electronVersion: string, arch: string): any {
@@ -32,7 +32,7 @@ export function getGypEnv(electronVersion: string, arch: string): any {
3232
})
3333
}
3434

35-
export function spawnNpmProduction(command: string, appDir: string, forceBuildFromSource: boolean, env?: any): Promise<any> {
35+
export function spawnNpmProduction(command: string, appDir: string, forceBuildFromSource: boolean, env?: any, additionalArgs?: any): Promise<any> {
3636
let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS
3737
const npmExecArgs = [command, "--production"]
3838

@@ -54,6 +54,15 @@ export function spawnNpmProduction(command: string, appDir: string, forceBuildFr
5454
npmExecArgs.push("--build-from-source")
5555
}
5656

57+
if (additionalArgs) {
58+
if (Array.isArray(additionalArgs)) {
59+
additionalArgs.push(...additionalArgs)
60+
}
61+
else {
62+
additionalArgs.push(additionalArgs)
63+
}
64+
}
65+
5766
return spawn(npmExecPath, npmExecArgs, {
5867
cwd: appDir,
5968
env: env || process.env

0 commit comments

Comments
 (0)