Skip to content

Commit

Permalink
refactor: cleanup beforeBuild feat pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 5, 2017
1 parent 35a8cdf commit 1bc808e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Don't customize paths to background and icon, — just follow conventions.
| snap | <a name="BuildMetadata-snap"></a>See [.build.snap](#SnapOptions).
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| 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.
| beforeBuild | <a name="BuildMetadata-beforeBuild"></a>*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 | <a name="BuildMetadata-beforeBuild"></a>*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 | <a name="BuildMetadata-npmRebuild"></a>Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
| npmSkipBuildFromSource | <a name="BuildMetadata-npmSkipBuildFromSource"></a>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 | <a name="BuildMetadata-npmArgs"></a>Additional command line arguments to use when installing app native deps. Defaults to `null`.
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,7 +198,7 @@ export interface BuildMetadata {
readonly afterPack?: (context: AfterPackContext) => Promise<any> | 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<any> | null

Expand Down
33 changes: 19 additions & 14 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -183,7 +183,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return
}

const asarOptions = this.computeAsarOptions(platformSpecificBuildOptions)
const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions)
const fileMatchOptions: FileMatchOptions = {
arch: Arch[arch],
os: this.platform.buildConfigurationKey
Expand Down Expand Up @@ -306,7 +306,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return null
}

private computeAsarOptions(customBuildOptions: DC): AsarOptions | null {
private async computeAsarOptions(customBuildOptions: DC): Promise<AsarOptions | null> {
function errorMessage(name: string) {
return `${name} is deprecated is deprecated and not supported — please use build.asarUnpack`
}
Expand All @@ -322,13 +322,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
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
}

Expand Down Expand Up @@ -444,8 +443,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
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.`)
}
}
}
}
Expand All @@ -455,8 +457,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
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)
Expand Down
16 changes: 0 additions & 16 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1bc808e

Please sign in to comment.