Skip to content

Commit

Permalink
feat: do not complain on node_modules missing when beforeBuild is set
Browse files Browse the repository at this point in the history
Close #2551, Close #2556
  • Loading branch information
wojtkowiak authored and develar committed Feb 7, 2018
1 parent 8363b2f commit 9d6eb96
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
---

* <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).
* <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.
* <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.
* <code id="Configuration-remoteBuild">remoteBuild</code> = `true` Boolean - Whether to build using Electron Build Service if target not supported on current OS.
* <code id="Configuration-includePdb">includePdb</code> = `false` Boolean - Whether to include PDB files.
* <code id="Configuration-removePackageScripts">removePackageScripts</code> = `true` Boolean - Whether to remove `scripts` field from `package.json` files.
Expand Down
2 changes: 2 additions & 0 deletions packages/electron-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export interface Configuration extends PlatformSpecificBuildOptions {

/**
* 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.
*
* If provided and `node_modules` are missing, it will not invoke production dependencies check.
*/
readonly beforeBuild?: ((context: BeforeBuildContext) => Promise<any>) | string| null

Expand Down
13 changes: 11 additions & 2 deletions packages/electron-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import isCI from "is-ci"
import { dump } from "js-yaml"
import { Lazy } from "lazy-val"
import * as path from "path"
import { exists } from "builder-util/out/fs"
import { AppInfo } from "./appInfo"
import { readAsarJson } from "./asar/asar"
import { AfterPackContext, Configuration } from "./configuration"
Expand All @@ -19,7 +20,7 @@ import { PlatformPackager, resolveFunction } from "./platformPackager"
import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory"
import { computeDefaultAppDirectory, getConfig, validateConfig } from "./util/config"
import { computeElectronVersion, getElectronVersionFromInstalled } from "./util/electronVersion"
import { createLazyProductionDeps, Dependency } from "./util/packageDependencies"
import { Dependency, getProductionDependencies } from "./util/packageDependencies"
import { checkMetadata, readPackageJson } from "./util/packageMetadata"
import { getRepositoryInfo } from "./util/repositoryInfo"
import { getGypEnv, installOrRebuild } from "./util/yarn"
Expand Down Expand Up @@ -91,7 +92,15 @@ export class Packager {
get productionDeps(): Lazy<Array<Dependency>> {
let result = this._productionDeps
if (result == null) {
result = createLazyProductionDeps(this.appDir)
// https://github.com/electron-userland/electron-builder/issues/2551
result = new Lazy(async () => {
if (this.config.beforeBuild == null || (await exists(path.join(this.appDir, "node_modules")))) {
return await getProductionDependencies(this.appDir)
}
else {
return []
}
})
this._productionDeps = result
}
return result
Expand Down
4 changes: 2 additions & 2 deletions test/out/__snapshots__/filesTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ Array [
"lib/net45/node.dll",
"lib/net45/pdf_viewer_resources.pak",
"lib/net45/snapshot_blob.bin",
"lib/net45/Test%20App%20%C3%9FW.exe",
"lib/net45/Test%20App%20%C3%9FW_ExecutionStub.exe",
"lib/net45/Test App ßW.exe",
"lib/net45/Test App ßW_ExecutionStub.exe",
"lib/net45/ucrtbase.dll",
"lib/net45/ui_resources_200_percent.pak",
"lib/net45/Update.exe",
Expand Down

0 comments on commit 9d6eb96

Please sign in to comment.