diff --git a/docs/Options.md b/docs/Options.md index 86d8a4a046e..e1a5585166b 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -82,7 +82,7 @@ Don't customize paths to background and icon, — just follow conventions. | snap | See [.build.snap](#SnapOptions). | compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly. | afterPack | *programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned. -| beforeBuild | *programmatic API only* The function to be run before dependencies from package.json are installed or rebuilt. Promise must be returned. Resolving to false will skip dependencies install or rebuild. +| beforeBuild | *programmatic API only* The function to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Promise must be returned. Resolving to `false` will skip dependencies install or rebuild. | npmRebuild | Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`. | npmSkipBuildFromSource | Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`. | npmArgs | Additional command line arguments to use when installing app native deps. Defaults to `null`. diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index 2dac838b4ff..3d455cdb207 100755 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -4,7 +4,7 @@ import { MacOptions, DmgOptions, MasBuildOptions } from "./options/macOptions" import { Publish } from "electron-builder-http/out/publishOptions" import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions } from "./options/winOptions" import { LinuxBuildOptions, SnapOptions } from "./options/linuxOptions" -import { Arch } from "electron-builder-core" +import { Arch, Platform } from "electron-builder-core" export interface Metadata { readonly repository?: string | RepositoryInfo | null @@ -198,7 +198,7 @@ export interface BuildMetadata { readonly afterPack?: (context: AfterPackContext) => Promise | null /* - *programmatic API only* The function to be run before dependencies from package.json are installed or rebuilt. Works when `npmRebuild` is set to `true`. Promise must be returned. Resolving to false will skip dependencies install or rebuild. + *programmatic API only* The function to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Promise must be returned. Resolving to `false` will skip dependencies install or rebuild. */ readonly beforeBuild?: (context: BeforeBuildContext) => Promise | null diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index 2125daadd7f..d2268d12821 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -1,7 +1,7 @@ import { AppMetadata, DevMetadata, PlatformSpecificBuildOptions, FileAssociation, BuildMetadata, getDirectoriesConfig } from "./metadata" import BluebirdPromise from "bluebird-lst-c" import * as path from "path" -import { readdir, remove, rename, Stats } from "fs-extra-p" +import { readdir, remove, rename } from "fs-extra-p" import { use, isEmptyOrSpaces, asArray, debug } from "electron-builder-util" import { Packager } from "./packager" import { AsarOptions } from "asar-electron-builder" @@ -183,7 +183,7 @@ export abstract class PlatformPackager return } - const asarOptions = this.computeAsarOptions(platformSpecificBuildOptions) + const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions) const fileMatchOptions: FileMatchOptions = { arch: Arch[arch], os: this.platform.buildConfigurationKey @@ -306,7 +306,7 @@ export abstract class PlatformPackager return null } - private computeAsarOptions(customBuildOptions: DC): AsarOptions | null { + private async computeAsarOptions(customBuildOptions: DC): Promise { function errorMessage(name: string) { return `${name} is deprecated is deprecated and not supported — please use build.asarUnpack` } @@ -322,13 +322,12 @@ export abstract class PlatformPackager const platformSpecific = customBuildOptions.asar const result = platformSpecific == null ? this.config.asar : platformSpecific if (result === false) { - statOrNull(path.join(this.info.appDir, "app.asar")) - .then((appAsarStat: Stats | null) => { - if (!appAsarStat || !appAsarStat.isFile()) { - warn("Packaging using asar archive is disabled — it is strongly not recommended.\n" + - "Please enable asar and use asarUnpack to unpack files that must be externally available.") - } - }) + const appAsarStat = await statOrNull(path.join(this.info.appDir, "app.asar")) + //noinspection ES6MissingAwait + if (appAsarStat == null || !appAsarStat.isFile()) { + warn("Packaging using asar archive is disabled — it is strongly not recommended.\n" + + "Please enable asar and use asarUnpack to unpack files that must be externally available.") + } return null } @@ -444,8 +443,11 @@ export abstract class PlatformPackager if (outStat == null) { throw new Error(`${messagePrefix} "${relativeFile}" does not exist. Seems like a wrong configuration.`) } - else if (!outStat.isFile()) { - throw new Error(`${messagePrefix} "${relativeFile}" is not a file. Seems like a wrong configuration.`) + else { + //noinspection ES6MissingAwait + if (!outStat.isFile()) { + throw new Error(`${messagePrefix} "${relativeFile}" is not a file. Seems like a wrong configuration.`) + } } } } @@ -455,8 +457,11 @@ export abstract class PlatformPackager if (outStat == null) { throw new Error(`Output directory "${appOutDir}" does not exist. Seems like a wrong configuration.`) } - else if (!outStat.isDirectory()) { - throw new Error(`Output directory "${appOutDir}" is not a directory. Seems like a wrong configuration.`) + else { + //noinspection ES6MissingAwait + if (!outStat.isDirectory()) { + throw new Error(`Output directory "${appOutDir}" is not a directory. Seems like a wrong configuration.`) + } } const resourcesDir = this.getResourcesDir(appOutDir) diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index 69c3be21f2a..6e66f06d958 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -192,22 +192,6 @@ test("beforeBuild", () => { }) }) -// ifMac("app-executable-deps", () => { -// return assertPack("app-executable-deps", { -// targets: Platform.current().createTarget(DIR_TARGET), -// }, { -// useTempDir: false, -// packed: async context => { -// const data = await readJson(path.join(context.outDir, "mac/app-executable-deps.app/Contents/Resources/app.asar.unpacked", "node_modules", "node-notifier", "package.json")) -// for (const name of Object.getOwnPropertyNames(data)) { -// if (name[0] === "_") { -// throw new Error("Property name starts with _") -// } -// } -// } -// }) -// }) - test.ifDevOrLinuxCi("smart unpack", () => { return assertPack("test-app-one", { targets: Platform.LINUX.createTarget(DIR_TARGET),