Skip to content

Commit 9d6eb96

Browse files
wojtkowiakdevelar
authored andcommitted
feat: do not complain on node_modules missing when beforeBuild is set
Close #2551, Close #2556
1 parent 8363b2f commit 9d6eb96

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

docs/configuration/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
114114
---
115115

116116
* <code id="Configuration-afterSign">afterSign</code> (context: AfterPackContext) => Promise | null - The function (or path to file or module id) to be run after pack and sign (but before pack into distributable format).
117-
* <code id="Configuration-beforeBuild">beforeBuild</code> (context: BeforeBuildContext) => Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Resolving to `false` will skip dependencies install or rebuild.
117+
* <code id="Configuration-beforeBuild">beforeBuild</code> (context: BeforeBuildContext) => Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. If provided and `node_modules` are missing it will not invoke production dependencies check. Resolving to `false` will skip dependencies install or rebuild.
118118
* <code id="Configuration-remoteBuild">remoteBuild</code> = `true` Boolean - Whether to build using Electron Build Service if target not supported on current OS.
119119
* <code id="Configuration-includePdb">includePdb</code> = `false` Boolean - Whether to include PDB files.
120120
* <code id="Configuration-removePackageScripts">removePackageScripts</code> = `true` Boolean - Whether to remove `scripts` field from `package.json` files.

packages/electron-builder-lib/src/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ export interface Configuration extends PlatformSpecificBuildOptions {
174174

175175
/**
176176
* The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Resolving to `false` will skip dependencies install or rebuild.
177+
*
178+
* If provided and `node_modules` are missing, it will not invoke production dependencies check.
177179
*/
178180
readonly beforeBuild?: ((context: BeforeBuildContext) => Promise<any>) | string| null
179181

packages/electron-builder-lib/src/packager.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import isCI from "is-ci"
88
import { dump } from "js-yaml"
99
import { Lazy } from "lazy-val"
1010
import * as path from "path"
11+
import { exists } from "builder-util/out/fs"
1112
import { AppInfo } from "./appInfo"
1213
import { readAsarJson } from "./asar/asar"
1314
import { AfterPackContext, Configuration } from "./configuration"
@@ -19,7 +20,7 @@ import { PlatformPackager, resolveFunction } from "./platformPackager"
1920
import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory"
2021
import { computeDefaultAppDirectory, getConfig, validateConfig } from "./util/config"
2122
import { computeElectronVersion, getElectronVersionFromInstalled } from "./util/electronVersion"
22-
import { createLazyProductionDeps, Dependency } from "./util/packageDependencies"
23+
import { Dependency, getProductionDependencies } from "./util/packageDependencies"
2324
import { checkMetadata, readPackageJson } from "./util/packageMetadata"
2425
import { getRepositoryInfo } from "./util/repositoryInfo"
2526
import { getGypEnv, installOrRebuild } from "./util/yarn"
@@ -91,7 +92,15 @@ export class Packager {
9192
get productionDeps(): Lazy<Array<Dependency>> {
9293
let result = this._productionDeps
9394
if (result == null) {
94-
result = createLazyProductionDeps(this.appDir)
95+
// https://github.com/electron-userland/electron-builder/issues/2551
96+
result = new Lazy(async () => {
97+
if (this.config.beforeBuild == null || (await exists(path.join(this.appDir, "node_modules")))) {
98+
return await getProductionDependencies(this.appDir)
99+
}
100+
else {
101+
return []
102+
}
103+
})
95104
this._productionDeps = result
96105
}
97106
return result

test/out/__snapshots__/filesTest.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ Array [
9191
"lib/net45/node.dll",
9292
"lib/net45/pdf_viewer_resources.pak",
9393
"lib/net45/snapshot_blob.bin",
94-
"lib/net45/Test%20App%20%C3%9FW.exe",
95-
"lib/net45/Test%20App%20%C3%9FW_ExecutionStub.exe",
94+
"lib/net45/Test App ßW.exe",
95+
"lib/net45/Test App ßW_ExecutionStub.exe",
9696
"lib/net45/ucrtbase.dll",
9797
"lib/net45/ui_resources_200_percent.pak",
9898
"lib/net45/Update.exe",

0 commit comments

Comments
 (0)