From f4398a7225c88880f9dee755b6c14699adf91c27 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 28 Feb 2017 09:47:00 +0100 Subject: [PATCH] fix(dmg): pass -ov flag to overwrite existing dmg Close #1308 --- .idea/dictionaries/develar.xml | 1 + docs/Options.md | 2 +- package.json | 8 +- packages/electron-builder/src/macPackager.ts | 26 ++- packages/electron-builder/src/metadata.ts | 5 +- packages/electron-builder/src/packager.ts | 4 +- packages/electron-builder/src/packagerApi.ts | 3 + .../electron-builder/src/platformPackager.ts | 40 ++-- .../src/publish/PublishManager.ts | 32 ++- packages/electron-builder/src/targets/dmg.ts | 23 ++- packages/electron-publisher-s3/package.json | 2 +- .../__snapshots__/extraMetadataTest.js.snap | 2 +- test/src/helpers/fileAssert.ts | 4 + test/src/helpers/packTester.ts | 2 +- test/src/mac/dmgTest.ts | 54 ++--- yarn.lock | 191 +++--------------- 16 files changed, 166 insertions(+), 233 deletions(-) diff --git a/.idea/dictionaries/develar.xml b/.idea/dictionaries/develar.xml index 47b8df2d426..84ca243227c 100644 --- a/.idea/dictionaries/develar.xml +++ b/.idea/dictionaries/develar.xml @@ -92,6 +92,7 @@ ifmacrodef ifndef iloc + imagekey inno insertmacro installmode diff --git a/docs/Options.md b/docs/Options.md index 10bef47769a..f04d66f9ba9 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -143,7 +143,7 @@ You can use [file macros](#file-macros) in the `from` and `to` fields as well. | publish | See [publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration). | forceCodeSigning | Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct). | electronVersion | The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency. -| artifactName |

The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to ${productName}-${version}.${ext} (some target can have another defaults, see corresponding options).

Currently supported only for pkg, dmg and nsis.

+| artifactName |

The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to ${productName}-${version}.${ext} (some target can have another defaults, see corresponding options).

Currently supported only for mas, pkg, dmg and nsis.

### `appx` diff --git a/package.json b/package.json index f3ee9b241b0..4005bc2256e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "ajv-keywords": "^2.0.1-beta.0", "archiver": "^1.3.0", "asar": "~0.13.0", - "aws-sdk": "^2.20.0", + "aws-sdk": "^2.22.0", "bluebird-lst": "^1.0.1", "chalk": "^1.1.3", "chromium-pickle-js": "^0.2.0", @@ -62,8 +62,7 @@ "yargs": "^6.6.0" }, "devDependencies": { - "@develar/typescript-json-schema": "0.9.3", - "@types/electron": "^1.4.32", + "@types/electron": "^1.4.33", "@types/ini": "^1.3.29", "@types/jest": "^18.1.1", "@types/js-yaml": "^3.5.29", @@ -89,8 +88,9 @@ "path-sort": "^0.1.0", "source-map-support": "^0.4.11", "ts-babel": "^1.4.4", - "tslint": "^4.4.2", + "tslint": "^4.5.0", "typescript": "^2.2.1", + "typescript-json-schema": "0.10.0", "whitespace": "^2.1.0", "xml2js": "^0.4.17" }, diff --git a/packages/electron-builder/src/macPackager.ts b/packages/electron-builder/src/macPackager.ts index ef7b017686f..367cf6c62c1 100644 --- a/packages/electron-builder/src/macPackager.ts +++ b/packages/electron-builder/src/macPackager.ts @@ -4,6 +4,7 @@ import { exec } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" import { log, task, warn } from "electron-builder-util/out/log" import { signAsync, SignOptions } from "electron-macos-sign" +import { ensureDir } from "fs-extra-p" import * as path from "path" import { AppInfo } from "./appInfo" import { appleCertificatePrefixes, CodeSigningInfo, createKeychain, findIdentity } from "./codeSign" @@ -41,7 +42,7 @@ export default class MacPackager extends PlatformPackager { if (iconPath != null && !iconPath.endsWith(".icns")) { iconPath += ".icns" } - return iconPath == null ? await this.getDefaultIcon("icns") : path.resolve(this.projectDir, iconPath) + return iconPath == null ? await this.getDefaultIcon("icns") : await this.getResource(iconPath) } createTargets(targets: Array, mapper: (name: string, factory: (outDir: string) => Target) => void, cleanupTasks: Array<() => Promise>): void { @@ -77,8 +78,8 @@ export default class MacPackager extends PlatformPackager { if (!hasMas || targets.length > 1) { const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged - nonMasPromise = (prepackaged ? BluebirdPromise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions)) - .then(() => this.sign(appPath, null)) + nonMasPromise = (prepackaged ? BluebirdPromise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)) + .then(() => this.sign(appPath, null, null)) .then(() => this.packageInDistributableFormat(appPath, Arch.x64, targets, postAsyncTasks)) } @@ -88,17 +89,20 @@ export default class MacPackager extends PlatformPackager { continue } - const appOutDir = prepackaged || path.join(outDir, targetName) const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (this.config).mas) if (targetName === "mas-dev") { deepAssign(masBuildOptions, (this.config)[targetName]) masBuildOptions.type = "development" } + const targetOutDir = path.join(outDir, targetName) if (prepackaged == null) { - await this.doPack(outDir, appOutDir, "mas", arch, masBuildOptions) + await this.doPack(outDir, targetOutDir, "mas", arch, masBuildOptions, [target]) + await this.sign(path.join(targetOutDir, `${this.appInfo.productFilename}.app`), targetOutDir, masBuildOptions) + } + else { + await this.sign(prepackaged, targetOutDir, masBuildOptions) } - await this.sign(path.join(appOutDir, `${this.appInfo.productFilename}.app`), masBuildOptions) } if (nonMasPromise != null) { @@ -106,7 +110,7 @@ export default class MacPackager extends PlatformPackager { } } - private async sign(appPath: string, masOptions: MasBuildOptions | null): Promise { + private async sign(appPath: string, outDir: string | null, masOptions: MasBuildOptions | null): Promise { if (process.platform !== "darwin") { warn("macOS application code signing is supported only on macOS, skipping.") return @@ -198,12 +202,13 @@ export default class MacPackager extends PlatformPackager { await task(`Signing app (identity: ${name})`, this.doSign(signOptions)) if (masOptions != null) { - const pkg = path.join(path.dirname(appPath), `${this.appInfo.productFilename}-${this.appInfo.version}.pkg`) const certType = "3rd Party Mac Developer Installer" const masInstallerIdentity = await findIdentity(certType, masOptions.identity, keychainName) if (masInstallerIdentity == null) { throw new Error(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`) } + + const pkg = path.join(outDir!, this.expandArtifactNamePattern(masOptions, "pkg")) await this.doFlat(appPath, pkg, masInstallerIdentity, keychainName) this.dispatchArtifactCreated(pkg, null, `${this.appInfo.name}-${this.appInfo.version}.pkg`) } @@ -216,9 +221,12 @@ export default class MacPackager extends PlatformPackager { //noinspection JSMethodCanBeStatic protected async doFlat(appPath: string, outFile: string, identity: string, keychain: string | n): Promise { + // productbuild doesn't created directory for out file + await ensureDir(path.dirname(outFile)) + const args = prepareProductBuildArgs(identity, keychain) args.push("--component", appPath, "/Applications") args.push(outFile) - return exec("productbuild", args) + return await exec("productbuild", args) } } \ No newline at end of file diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index efd4767ffec..977696cd8c0 100755 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -1,4 +1,4 @@ -import { Arch, Platform, TargetSpecificOptions } from "electron-builder-core" +import { Arch, Platform, Target, TargetSpecificOptions } from "electron-builder-core" import { Publish } from "electron-builder-http/out/publishOptions" import { DebOptions, LinuxBuildOptions, SnapOptions } from "./options/linuxOptions" import { DmgOptions, MacOptions, MasBuildOptions, PkgOptions } from "./options/macOptions" @@ -221,7 +221,7 @@ export interface Config extends PlatformSpecificBuildOptions, TargetSpecificOpti /** The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName}-${version}.${ext}` (some target can have another defaults, see corresponding options). - Currently supported only for `pkg`, `dmg` and `nsis`. + Currently supported only for `mas`, `pkg`, `dmg` and `nsis`. */ readonly artifactName?: string | null } @@ -231,6 +231,7 @@ export interface AfterPackContext { readonly packager: PlatformPackager readonly electronPlatformName: string readonly arch: Arch + readonly targets: Array } export interface BeforeBuildContext { diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index 0e5a4378946..3bfb19de55f 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -55,7 +55,7 @@ export class Packager implements BuildInfo { readonly tempDirManager = new TmpDir() - private _repositoryInfo = new Lazy(() => getRepositoryInfo(this.projectDir, this.appInfo.metadata, this.devMetadata)) + private _repositoryInfo = new Lazy(() => getRepositoryInfo(this.projectDir, this.metadata, this.devMetadata)) private readonly afterPackHandlers: Array<(context: AfterPackContext) => Promise | null> = [] @@ -66,7 +66,7 @@ export class Packager implements BuildInfo { readonly prepackaged?: string | null //noinspection JSUnusedGlobalSymbols - constructor(readonly options: PackagerOptions, private readonly cancellationToken: CancellationToken) { + constructor(readonly options: PackagerOptions, readonly cancellationToken: CancellationToken) { this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir) this.prepackaged = options.prepackaged == null ? null : path.resolve(this.projectDir, options.prepackaged) diff --git a/packages/electron-builder/src/packagerApi.ts b/packages/electron-builder/src/packagerApi.ts index 75abb338276..46f591c9a84 100644 --- a/packages/electron-builder/src/packagerApi.ts +++ b/packages/electron-builder/src/packagerApi.ts @@ -1,4 +1,5 @@ import { Arch, Platform, Target } from "electron-builder-core" +import { CancellationToken } from "electron-builder-http/out/CancellationToken" import { PublishConfiguration } from "electron-builder-http/out/publishOptions" import { TmpDir } from "electron-builder-util/out/tmp" import { AppInfo } from "./appInfo" @@ -63,6 +64,8 @@ export interface BuildInfo { readonly prepackaged?: string | null + readonly cancellationToken: CancellationToken + dispatchArtifactCreated(event: ArtifactCreated): void afterPack(context: AfterPackContext): Promise diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index 86c4a24183f..57612034cee 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -1,6 +1,6 @@ import BluebirdPromise from "bluebird-lst" import { Arch, getArchSuffix, Platform, Target, TargetSpecificOptions } from "electron-builder-core" -import { asArray, debug, isEmptyOrSpaces, use } from "electron-builder-util" +import { asArray, debug, isEmptyOrSpaces, Lazy, use } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" import { copyDir, statOrNull, unlinkIfExists } from "electron-builder-util/out/fs" import { log, warn } from "electron-builder-util/out/log" @@ -25,7 +25,19 @@ export abstract class PlatformPackager readonly platformSpecificBuildOptions: DC - readonly resourceList: Promise> + get resourceList(): Promise> { + return this._resourceList.value + } + + private readonly _resourceList = new Lazy>(() => { + return readdir(this.buildResourcesDir) + .catch(e => { + if (e.code !== "ENOENT") { + throw e + } + return [] + }) + }) abstract get platform(): Platform @@ -39,14 +51,6 @@ export abstract class PlatformPackager this.projectDir = info.projectDir this.buildResourcesDir = path.resolve(this.projectDir, this.relativeBuildResourcesDirname) - - this.resourceList = readdir(this.buildResourcesDir) - .catch(e => { - if (e.code !== "ENOENT") { - throw e - } - return [] - }) } abstract get defaultTarget(): Array @@ -95,7 +99,7 @@ export abstract class PlatformPackager async pack(outDir: string, arch: Arch, targets: Array, postAsyncTasks: Array>): Promise { const appOutDir = this.computeAppOutDir(outDir, arch) - await this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions) + await this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets) this.packageInDistributableFormat(appOutDir, arch, targets, postAsyncTasks) } @@ -135,7 +139,7 @@ export abstract class PlatformPackager return matcher } - protected async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC) { + protected async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC, targets: Array) { if (this.info.prepackaged != null) { return } @@ -218,11 +222,16 @@ export abstract class PlatformPackager await copyFiles(extraResourceMatchers) await copyFiles(extraFileMatchers) + if (this.info.cancellationToken.cancelled) { + return + } + await this.info.afterPack({ appOutDir: appOutDir, packager: this, electronPlatformName: platformName, arch: arch, + targets: targets, }) await this.sanityCheckPackage(appOutDir, asarOptions != null) } @@ -517,7 +526,12 @@ export abstract class PlatformPackager } } } - else if (!isEmptyOrSpaces(custom)) { + else if (custom != null && !isEmptyOrSpaces(custom)) { + const resourceList = await this.resourceList + if (resourceList.includes(custom)) { + return path.join(this.buildResourcesDir, custom) + } + let p = path.resolve(this.buildResourcesDir, custom) if (await statOrNull(p) == null) { p = path.resolve(this.projectDir, custom) diff --git a/packages/electron-builder/src/publish/PublishManager.ts b/packages/electron-builder/src/publish/PublishManager.ts index 919c705af5d..fc1a1b59341 100644 --- a/packages/electron-builder/src/publish/PublishManager.ts +++ b/packages/electron-builder/src/publish/PublishManager.ts @@ -1,6 +1,6 @@ import BluebirdPromise from "bluebird-lst" import { createHash } from "crypto" -import { Arch, Platform } from "electron-builder-core" +import { Arch, Platform, Target } from "electron-builder-core" import { CancellationToken } from "electron-builder-http/out/CancellationToken" import { GenericServerOptions, GithubOptions, githubUrl, PublishConfiguration, PublishProvider, S3Options, s3Url, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions" import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util" @@ -60,11 +60,21 @@ export class PublishManager implements PublishContext { } packager.addAfterPackHandler(async event => { - if (this.cancellationToken.cancelled || !(event.electronPlatformName == "darwin" || event.packager.platform === Platform.WINDOWS)) { + const packager = event.packager + if (event.electronPlatformName === "darwin") { + if (!event.targets.some(it => it.name === "zip")) { + return + } + } + else if (packager.platform === Platform.WINDOWS) { + if (!event.targets.some(it => isSuitableWindowsTarget(it))) { + return + } + } + else { return } - const packager = event.packager const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, null)) if (publishConfigs == null || publishConfigs.length === 0) { return @@ -73,12 +83,12 @@ export class PublishManager implements PublishContext { let publishConfig = publishConfigs[0] if ((publishConfig).url != null) { publishConfig = Object.assign({}, publishConfig, { - url: packager.expandMacro((publishConfig).url, packager.platform === Platform.WINDOWS ? null : Arch.x64) + url: packager.expandMacro((publishConfig).url, null) }) } if (packager.platform === Platform.WINDOWS) { - let publisherName = await (packager).computedPublisherName.value + const publisherName = await (packager).computedPublisherName.value if (publisherName != null) { publishConfig = Object.assign({publisherName: publisherName}, publishConfig) } @@ -123,7 +133,7 @@ export class PublishManager implements PublishContext { if (target != null && eventFile != null && !this.cancellationToken.cancelled) { if ((packager.platform === Platform.MAC && target.name === "zip") || - (packager.platform === Platform.WINDOWS && (target.name === "nsis" || target.name.startsWith("nsis-")) && eventFile.endsWith(".exe"))) { + (packager.platform === Platform.WINDOWS && isSuitableWindowsTarget(target) && eventFile.endsWith(".exe"))) { this.addTask(writeUpdateInfo(event, publishConfigs)) } } @@ -368,8 +378,12 @@ export async function getPublishConfigs(packager: PlatformPackager, targetS } } + if (publishers == null) { + return [] + } + debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`) - return >>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it)) + return await >>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it)) } function sha256(file: string) { @@ -397,4 +411,8 @@ function isPullRequest() { } return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS) +} + +function isSuitableWindowsTarget(target: Target) { + return target.name === "nsis" || target.name.startsWith("nsis-") } \ No newline at end of file diff --git a/packages/electron-builder/src/targets/dmg.ts b/packages/electron-builder/src/targets/dmg.ts index 9fa027f05e5..438c8a861aa 100644 --- a/packages/electron-builder/src/targets/dmg.ts +++ b/packages/electron-builder/src/targets/dmg.ts @@ -60,7 +60,7 @@ export class DmgTarget extends Target { await detach(volumePath) } - await attachAndExecute(tempDmg, true, async () => { + const isContinue = await attachAndExecute(tempDmg, true, async () => { const promises = [ specification.background == null ? remove(`${volumePath}/.background`) : unlink(`${volumePath}/.background/DSStorePlaceHolder`), ] @@ -155,14 +155,18 @@ export class DmgTarget extends Target { await exec("sync") - if (packager.packagerOptions.effectiveOptionComputed != null && await packager.packagerOptions.effectiveOptionComputed([volumePath, specification])) { - return - } + return packager.packagerOptions.effectiveOptionComputed == null || !(await packager.packagerOptions.effectiveOptionComputed({volumePath, specification, packager})) }) + if (!isContinue) { + return + } + const artifactPath = path.join(this.outDir, packager.expandArtifactNamePattern(packager.config.dmg, "dmg")) + + // dmg file must not exist otherwise hdiutil failed (https://github.com/electron-userland/electron-builder/issues/1308#issuecomment-282847594), so, -ov must be specified //noinspection SpellCheckingInspection - await spawn("hdiutil", addVerboseIfNeed(["convert", tempDmg, "-format", packager.config.compression === "store" ? "UDRO" : "UDBZ", "-imagekey", "zlib-level=9", "-o", artifactPath])) + await spawn("hdiutil", addVerboseIfNeed(["convert", tempDmg, "-ov", "-format", specification.format!, "-imagekey", "zlib-level=9", "-o", artifactPath])) await exec("hdiutil", addVerboseIfNeed(["internet-enable", "-no"]).concat(artifactPath)) this.packager.dispatchArtifactCreated(artifactPath, this, `${appInfo.name}-${appInfo.version}.dmg`) @@ -249,7 +253,12 @@ export class DmgTarget extends Target { } if (specification.format == null) { - specification.format = packager.config.compression === "store" ? "UDRO" : "UDBZ" + if (packager.config.compression === "store") { + specification.format = "UDRO" + } + else { + specification.format = packager.config.compression === "maximum" ? "UDBZ" : "UDZO" + } } return specification @@ -289,7 +298,7 @@ export async function attachAndExecute(dmgPath: string, readWrite: boolean, task throw new Error(`Cannot mount: ${attachResult}`) } - await executeFinally(task(), () => detach(device)) + return await executeFinally(task(), () => detach(device)) } function addVerboseIfNeed(args: Array): Array { diff --git a/packages/electron-publisher-s3/package.json b/packages/electron-publisher-s3/package.json index 984be911276..bdae7454468 100644 --- a/packages/electron-publisher-s3/package.json +++ b/packages/electron-publisher-s3/package.json @@ -12,7 +12,7 @@ ], "dependencies": { "fs-extra-p": "^4.0.2", - "aws-sdk": "^2.20.0", + "aws-sdk": "^2.22.0", "mime": "^1.3.4", "electron-publish": "~0.0.0-semantic-release", "electron-builder-util": "~0.0.0-semantic-release" diff --git a/test/out/__snapshots__/extraMetadataTest.js.snap b/test/out/__snapshots__/extraMetadataTest.js.snap index e9d9bb28e70..255e8ea8fbc 100644 --- a/test/out/__snapshots__/extraMetadataTest.js.snap +++ b/test/out/__snapshots__/extraMetadataTest.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`extra metadata - override icon 1`] = `"ENOENT: no such file or directory, lstat '/dev.icns'"`; +exports[`extra metadata - override icon 1`] = `"Cannot find specified resource \\"dev.icns\\""`; exports[`extra metadata 1`] = ` Object { diff --git a/test/src/helpers/fileAssert.ts b/test/src/helpers/fileAssert.ts index 95dab80d36d..c87ab13533d 100644 --- a/test/src/helpers/fileAssert.ts +++ b/test/src/helpers/fileAssert.ts @@ -69,6 +69,10 @@ class Assertions { m = m.substring(0, m.indexOf("\n")) } + if (m.startsWith("Cannot find specified resource")) { + m = m.substring(0, m.indexOf(",")) + } + m = m.replace(/\((C:)?(\/|\\)[^(]+(\/|\\)([^(\/\\]+)\)/g, `(/$4)`) m = m.replace(/"(C:)?(\/|\\)[^"]+(\/|\\)([^"\/\\]+)"/g, `"/$4"`) m = m.replace(/'(C:)?(\/|\\)[^']+(\/|\\)([^'\/\\]+)'/g, `'/$4'`) diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index f141211944c..b12c1e63c27 100755 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -481,7 +481,7 @@ export class CheckingMacPackager extends OsXPackager { return await OsXPackager.prototype.pack.call(this, outDir, arch, targets, postAsyncTasks) } - async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, customBuildOptions: MacOptions, postAsyncTasks: Array> = null) { + async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, customBuildOptions: MacOptions, targets: Array) { // skip } diff --git a/test/src/mac/dmgTest.ts b/test/src/mac/dmgTest.ts index 5384c7c5e0e..b41340ff05c 100644 --- a/test/src/mac/dmgTest.ts +++ b/test/src/mac/dmgTest.ts @@ -1,10 +1,11 @@ import BluebirdPromise from "bluebird-lst" import { Platform } from "electron-builder" +import { PlatformPackager } from "electron-builder/out/platformPackager" import { attachAndExecute } from "electron-builder/out/targets/dmg" import { copy, remove } from "fs-extra-p" import * as path from "path" import { assertThat } from "../helpers/fileAssert" -import { app, assertPack, CheckingMacPackager } from "../helpers/packTester" +import { app, assertPack } from "../helpers/packTester" test.ifMac("no build directory", app({ targets: Platform.MAC.createTarget("dmg"), @@ -13,23 +14,20 @@ test.ifMac("no build directory", app({ productName: "NoBuildDirectory", }, effectiveOptionComputed: async it => { - const volumePath = it[0] - const specification = it[1] + const volumePath = it.volumePath await assertThat(path.join(volumePath, ".background", "background.tiff")).isFile() await assertThat(path.join(volumePath, "Applications")).isSymbolicLink() - expect(specification.contents).toMatchSnapshot() + expect(it.specification.contents).toMatchSnapshot() return false }, }, { projectDirCreated: projectDir => remove(path.join(projectDir, "build")), })) -test.ifMac("custom background - new way", () => { - let platformPackager: CheckingMacPackager = null +test.ifAll.ifMac("custom background - new way", () => { const customBackground = "customBackground.png" return assertPack("test-app-one", { targets: Platform.MAC.createTarget(), - platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingMacPackager(packager), config: { mac: { icon: "customIcon" @@ -38,14 +36,21 @@ test.ifMac("custom background - new way", () => { background: customBackground, icon: "foo.icns", }, - } - }, { - projectDirCreated: projectDir => copy(path.join(__dirname, "..", "..", "..", "packages", "electron-builder", "templates", "dmg", "background.tiff"), path.join(projectDir, customBackground)), - packed: async context => { - expect(platformPackager.effectiveDistOptions.background).toEqual(customBackground) - expect(platformPackager.effectiveDistOptions.icon).toEqual("foo.icns") - expect(await platformPackager.getIconPath()).toEqual(path.join(context.projectDir, "customIcon.icns")) }, + effectiveOptionComputed: async it => { + expect(it.specification.background).toEqual(customBackground) + expect(it.specification.icon).toEqual("foo.icns") + const packager: PlatformPackager = it.packager + expect(await packager.getIconPath()).toEqual(path.join(packager.projectDir, "build", "customIcon.icns")) + return true + }, + }, { + projectDirCreated: projectDir => BluebirdPromise.all([ + copy(path.join(__dirname, "..", "..", "..", "packages", "electron-builder", "templates", "dmg", "background.tiff"), path.join(projectDir, customBackground)), + // copy, but not rename to test that default icon is not used + copy(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "customIcon.icns")), + copy(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "foo.icns")), + ]), }) }) @@ -70,15 +75,14 @@ test.ifMac("no Applications link", () => { }, }, effectiveOptionComputed: async it => { - const volumePath = it[0] - const specification = it[1] + const volumePath = it.volumePath await BluebirdPromise.all([ assertThat(path.join(volumePath, ".background", "background.tiff")).isFile(), assertThat(path.join(volumePath, "Applications")).doesNotExist(), assertThat(path.join(volumePath, "TextEdit.app")).isSymbolicLink(), assertThat(path.join(volumePath, "TextEdit.app")).isDirectory(), ]) - expect(specification.contents).toMatchSnapshot() + expect(it.specification.contents).toMatchSnapshot() return false }, }) @@ -123,11 +127,9 @@ test.ifMac("no background", app({ } })) -test.ifMac("disable dmg icon (light), bundleVersion", () => { - let platformPackager: CheckingMacPackager = null +test.ifAll.ifMac("disable dmg icon (light), bundleVersion", () => { return assertPack("test-app-one", { targets: Platform.MAC.createTarget(), - platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingMacPackager(packager), config: { dmg: { icon: null, @@ -135,12 +137,12 @@ test.ifMac("disable dmg icon (light), bundleVersion", () => { mac: { bundleVersion: "50" }, - } - }, { - packed: async () => { - expect(platformPackager.effectiveDistOptions.icon).toBeNull() - expect(await platformPackager.getIconPath()).not.toBeNull() - expect(platformPackager.appInfo.buildVersion).toEqual("50") + }, + effectiveOptionComputed: async it => { + expect(it.specification.icon).toBeNull() + expect(it.packager.appInfo.buildVersion).toEqual("50") + expect(await it.packager.getIconPath()).not.toBeNull() + return true }, }) }) \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 951010d70b9..34f0e46e6ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,22 +22,13 @@ "7zip-bin-mac" "^1.0.1" "7zip-bin-win" "^2.0.2" -"@develar/typescript-json-schema@0.9.3": - version "0.9.3" - resolved "https://registry.yarnpkg.com/@develar/typescript-json-schema/-/typescript-json-schema-0.9.3.tgz#01574486bae0097ccb89ceef9b7a182dca0ee2c5" - dependencies: - glob "~7.1.1" - json-stable-stringify "^1.0.1" - typescript "~2.1.5" - yargs "^6.6.0" - "@types/doctrine@^0.0.3": version "0.0.3" resolved "https://registry.yarnpkg.com/@types/doctrine/-/doctrine-0.0.3.tgz#e892d293c92c9c1d3f9af72c15a554fbc7e0895a" -"@types/electron@^1.4.32": - version "1.4.32" - resolved "https://registry.yarnpkg.com/@types/electron/-/electron-1.4.32.tgz#3c9fce4aa53b26213bc1f1b640206191d449fa76" +"@types/electron@^1.4.33": + version "1.4.33" + resolved "https://registry.yarnpkg.com/@types/electron/-/electron-1.4.33.tgz#10b82bb065115e19a5ef0848e142cf5949435979" dependencies: "@types/node" "*" @@ -259,9 +250,9 @@ asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" -aws-sdk@^2.20.0: - version "2.20.0" - resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.20.0.tgz#e083f33a597661bb91e43911a99bb794797e8ca1" +aws-sdk@^2.22.0: + version "2.22.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.22.0.tgz#f7b67d5ece7e67c36f9d3d55e137872572e5c998" dependencies: buffer "4.9.1" crypto-browserify "1.0.9" @@ -561,20 +552,6 @@ boom@2.x.x: dependencies: hoek "2.x.x" -boxen@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/boxen/-/boxen-0.6.0.tgz#8364d4248ac34ff0ef1b2f2bf49a6c60ce0d81b6" - dependencies: - ansi-align "^1.1.0" - camelcase "^2.1.0" - chalk "^1.1.1" - cli-boxes "^1.0.0" - filled-array "^1.0.0" - object-assign "^4.0.1" - repeating "^2.0.0" - string-width "^1.0.1" - widest-line "^1.0.0" - boxen@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/boxen/-/boxen-1.0.0.tgz#b2694baf1f605f708ff0177c12193b22f29aaaab" @@ -659,7 +636,7 @@ camelcase@^1.0.2: version "1.2.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" -camelcase@^2.0.0, camelcase@^2.1.0: +camelcase@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f" @@ -812,20 +789,6 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -configstore@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/configstore/-/configstore-2.1.0.tgz#737a3a7036e9886102aa6099e47bb33ab1aba1a1" - dependencies: - dot-prop "^3.0.0" - graceful-fs "^4.1.2" - mkdirp "^0.5.0" - object-assign "^4.0.1" - os-tmpdir "^1.0.0" - osenv "^0.1.0" - uuid "^2.0.1" - write-file-atomic "^1.1.2" - xdg-basedir "^2.0.0" - configstore@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.0.0.tgz#e1b8669c1803ccc50b545e92f8e6e79aa80e0196" @@ -864,7 +827,7 @@ crc@^3.4.4: version "3.4.4" resolved "https://registry.yarnpkg.com/crc/-/crc-3.4.4.tgz#9da1e980e3bd44fc5c93bf5ab3da3378d85e466b" -create-error-class@^3.0.0, create-error-class@^3.0.1: +create-error-class@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6" dependencies: @@ -1016,24 +979,12 @@ doctrine@^2.0.0: esutils "^2.0.2" isarray "^1.0.0" -dot-prop@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177" - dependencies: - is-obj "^1.0.0" - dot-prop@^4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.1.1.tgz#a8493f0b7b5eeec82525b5c7587fa7de7ca859c1" dependencies: is-obj "^1.0.0" -duplexer2@^0.1.4: - version "0.1.4" - resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1" - dependencies: - readable-stream "^2.0.2" - duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" @@ -1219,10 +1170,6 @@ fill-range@^2.1.0: repeat-element "^1.1.2" repeat-string "^1.5.2" -filled-array@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/filled-array/-/filled-array-1.1.0.tgz#c3c4f6c663b923459a9aa29912d2d031f1507f84" - find-up@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f" @@ -1368,26 +1315,6 @@ globals@^9.0.0: version "9.16.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.16.0.tgz#63e903658171ec2d9f51b1d31de5e2b8dc01fb80" -got@^5.0.0: - version "5.7.1" - resolved "https://registry.yarnpkg.com/got/-/got-5.7.1.tgz#5f81635a61e4a6589f180569ea4e381680a51f35" - dependencies: - create-error-class "^3.0.1" - duplexer2 "^0.1.4" - is-redirect "^1.0.0" - is-retry-allowed "^1.0.0" - is-stream "^1.0.0" - lowercase-keys "^1.0.0" - node-status-codes "^1.0.0" - object-assign "^4.0.1" - parse-json "^2.1.0" - pinkie-promise "^2.0.0" - read-all-stream "^3.0.0" - readable-stream "^2.0.5" - timed-out "^3.0.0" - unzip-response "^1.0.2" - url-parse-lax "^1.0.0" - got@^6.7.1: version "6.7.1" resolved "https://registry.yarnpkg.com/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0" @@ -1517,8 +1444,8 @@ ini@^1.3.4, ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e" inquirer@^3.0.1: - version "3.0.4" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.0.4.tgz#ed9588020edbcc40fc94c50761ad00dcf8598ff5" + version "3.0.5" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.0.5.tgz#172cabc8eacbfb91d595f5d7c354b446b8141f65" dependencies: ansi-escapes "^1.1.0" chalk "^1.0.0" @@ -2086,12 +2013,6 @@ klaw@^1.0.0, klaw@~1.3.0: optionalDependencies: graceful-fs "^4.1.9" -latest-version@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-2.0.0.tgz#56f8d6139620847b8017f8f1f4d78e211324168b" - dependencies: - package-json "^2.0.0" - latest-version@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-3.0.0.tgz#3104f008c0c391084107f85a344bc61e38970649" @@ -2102,10 +2023,6 @@ lazy-cache@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" -lazy-req@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/lazy-req/-/lazy-req-1.1.0.tgz#bdaebead30f8d824039ce0ce149d4daa07ba1fac" - lazy-req@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/lazy-req/-/lazy-req-2.0.0.tgz#c9450a363ecdda2e6f0c70132ad4f37f8f06f2b4" @@ -2371,10 +2288,6 @@ node-notifier@^5.0.1: shellwords "^0.1.0" which "^1.2.12" -node-status-codes@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f" - nopt@^3.0.1: version "3.0.6" resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" @@ -2497,17 +2410,10 @@ os-locale@^1.4.0: dependencies: lcid "^1.0.0" -os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1: +os-tmpdir@^1.0.1, os-tmpdir@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" -osenv@^0.1.0: - version "0.1.4" - resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.4.tgz#42fe6d5953df06c8064be6f176c3d05aaaa34644" - dependencies: - os-homedir "^1.0.0" - os-tmpdir "^1.0.0" - p-limit@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc" @@ -2518,15 +2424,6 @@ p-locate@^2.0.0: dependencies: p-limit "^1.1.0" -package-json@^2.0.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/package-json/-/package-json-2.4.0.tgz#0d15bd67d1cbbddbb2ca222ff2edb86bcb31a8bb" - dependencies: - got "^5.0.0" - registry-auth-token "^3.0.1" - registry-url "^3.0.3" - semver "^5.1.0" - package-json@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/package-json/-/package-json-3.1.0.tgz#ce281900fe8052150cc6709c6c006c18fdb2f379" @@ -2551,7 +2448,7 @@ parse-glob@^3.0.4: is-extglob "^1.0.0" is-glob "^2.0.0" -parse-json@^2.1.0, parse-json@^2.2.0: +parse-json@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" dependencies: @@ -2709,13 +2606,6 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.1.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -read-all-stream@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/read-all-stream/-/read-all-stream-3.1.0.tgz#35c3e177f2078ef789ee4bfafa4373074eaef4fa" - dependencies: - pinkie-promise "^2.0.0" - readable-stream "^2.0.0" - read-cmd-shim@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/read-cmd-shim/-/read-cmd-shim-1.0.1.tgz#2d5d157786a37c055d22077c32c53f8329e91c7b" @@ -2746,7 +2636,7 @@ readable-stream@^1.1.8, readable-stream@~1.1.9: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@^2.0.0, readable-stream@^2.0.2, readable-stream@^2.0.5: +readable-stream@^2.0.0, readable-stream@^2.0.5: version "2.2.3" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.3.tgz#9cf49463985df016c8ae8813097a9293a9b33729" dependencies: @@ -3158,10 +3048,6 @@ through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" -timed-out@^3.0.0: - version "3.1.3" - resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-3.1.3.tgz#95860bfcc5c76c277f8f8326fd0f5b2e20eba217" - timed-out@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f" @@ -3233,9 +3119,9 @@ ts-babel@^1.4.4: markdown-it "^8.3.0" source-map-support "^0.4.11" -tslint@^4.4.2: - version "4.4.2" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-4.4.2.tgz#b14cb79ae039c72471ab4c2627226b940dda19c6" +tslint@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-4.5.0.tgz#12b384a339d456ee1d3cc665f13f4e759bbe5d64" dependencies: babel-code-frame "^6.20.0" colors "^1.1.2" @@ -3244,7 +3130,12 @@ tslint@^4.4.2: glob "^7.1.1" optimist "~0.6.0" resolve "^1.1.7" - update-notifier "^1.0.2" + tsutils "^1.1.0" + update-notifier "^2.0.0" + +tsutils@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.1.0.tgz#94e0c267624eeb1b63561ba8ec0bcff71b4e2872" tunnel-agent@^0.4.3, tunnel-agent@~0.4.1: version "0.4.3" @@ -3260,6 +3151,15 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" +typescript-json-schema@0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/typescript-json-schema/-/typescript-json-schema-0.10.0.tgz#e05a02c466e9f5998d09e9565dab76f1bf5d6bae" + dependencies: + glob "~7.1.1" + json-stable-stringify "^1.0.1" + typescript "~2.1.5" + yargs "^6.6.0" + typescript@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.1.tgz#4862b662b988a4c8ff691cc7969622d24db76ae9" @@ -3305,28 +3205,11 @@ unique-string@^1.0.0: dependencies: crypto-random-string "^1.0.0" -unzip-response@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-1.0.2.tgz#b984f0877fc0a89c2c773cc1ef7b5b232b5b06fe" - unzip-response@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" -update-notifier@^1.0.2: - version "1.0.3" - resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-1.0.3.tgz#8f92c515482bd6831b7c93013e70f87552c7cf5a" - dependencies: - boxen "^0.6.0" - chalk "^1.0.0" - configstore "^2.0.0" - is-npm "^1.0.0" - latest-version "^2.0.0" - lazy-req "^1.1.0" - semver-diff "^2.0.0" - xdg-basedir "^2.0.0" - -update-notifier@^2.1.0: +update-notifier@^2.0.0, update-notifier@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-2.1.0.tgz#ec0c1e53536b76647a24b77cb83966d9315123d9" dependencies: @@ -3370,10 +3253,6 @@ uuid@3.0.0, uuid@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728" -uuid@^2.0.1: - version "2.0.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" - validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" @@ -3488,12 +3367,6 @@ write-file-atomic@^1.1.2: imurmurhash "^0.1.4" slide "^1.1.5" -xdg-basedir@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-2.0.0.tgz#edbc903cc385fc04523d966a335504b5504d1bd2" - dependencies: - os-homedir "^1.0.0" - xdg-basedir@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4"