diff --git a/docs/Options.md b/docs/Options.md index 9e90e0a417f..c93f1a0b96c 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -344,7 +344,11 @@ Configuration Options * `rpm` [LinuxTargetSpecificOptions](electron-builder#LinuxTargetSpecificOptions) * `freebsd` [LinuxTargetSpecificOptions](electron-builder#LinuxTargetSpecificOptions) * `p5p` [LinuxTargetSpecificOptions](electron-builder#LinuxTargetSpecificOptions) -* `apk` [LinuxTargetSpecificOptions](electron-builder#LinuxTargetSpecificOptions) +* `apk` [LinuxTargetSpecificOptions](electron-builder#LinuxTargetSpecificOptions) +* `extends` String - The name of a built-in configuration preset. Currently, only `react-cra` is supported. + + If `react-scripts` in the app dev dependencies, `react-cra` will be set automatically. Set to `null` to disable automatic detection. +* `extraMetadata` any ## `Metadata` Some standard fields should be defined in the `package.json`. diff --git a/docs/api/electron-builder-util.md b/docs/api/electron-builder-util.md index a28c3a4c6e7..cea37552379 100644 --- a/docs/api/electron-builder-util.md +++ b/docs/api/electron-builder-util.md @@ -67,12 +67,12 @@ ## electron-builder-util/out/deepAssign -### `electron-builder-util/out/deepAssign.deepAssign(target, objects)` ⇒ any +### `electron-builder-util/out/deepAssign.deepAssign(target, objects)` ⇒ module:electron-builder-util/out/deepAssign.T **Kind**: method of [electron-builder-util/out/deepAssign](#module_electron-builder-util/out/deepAssign) | Param | Type | | --- | --- | -| target | any | +| target | module:electron-builder-util/out/deepAssign.T | | objects | Array<any> | diff --git a/docs/api/electron-builder.md b/docs/api/electron-builder.md index a039e4d9958..0abb5deb958 100644 --- a/docs/api/electron-builder.md +++ b/docs/api/electron-builder.md @@ -1343,7 +1343,7 @@ | Name | Type | | --- | --- | -| options = this.packager.config.dmg| undefined \| null \| [DmgOptions](Options#DmgOptions) | +| options = this.packager.config.dmg || Object.create(null)| [DmgOptions](Options#DmgOptions) | * [.DmgTarget](#DmgTarget) ⇐ [Target](electron-builder-core#Target) diff --git a/packages/electron-builder-util/src/deepAssign.ts b/packages/electron-builder-util/src/deepAssign.ts index 3a5474ce45c..82d9de03a77 100644 --- a/packages/electron-builder-util/src/deepAssign.ts +++ b/packages/electron-builder-util/src/deepAssign.ts @@ -7,19 +7,24 @@ function isObject(x: any) { return type === "object" || type === "function" } -function assignKey(to: any, from: any, key: string) { +function assignKey(target: any, from: any, key: string) { const value = from[key] // https://github.com/electron-userland/electron-builder/pull/562 if (value === undefined) { return } - const prevValue = to[key] - if (prevValue == null || value === null || !isObject(prevValue) || !isObject(value)) { - to[key] = value + const prevValue = target[key] + if (prevValue === null) { + // if explicitly set to null, it means that we want to not use default or inherited value + return + } + + if (prevValue == null || value == null || !isObject(prevValue) || !isObject(value)) { + target[key] = value } else { - to[key] = assign(prevValue, value) + target[key] = assign(prevValue, value) } } @@ -32,7 +37,7 @@ function assign(to: any, from: any) { return to } -export function deepAssign(target: any, ...objects: Array) { +export function deepAssign(target: T, ...objects: Array): T { for (const o of objects) { if (o != null) { assign(target, o) diff --git a/packages/electron-builder/src/appInfo.ts b/packages/electron-builder/src/appInfo.ts index ccffe772c11..ddf47d27b0e 100644 --- a/packages/electron-builder/src/appInfo.ts +++ b/packages/electron-builder/src/appInfo.ts @@ -76,7 +76,7 @@ export class AppInfo { if (copyright != null) { return copyright } - return `Copyright © ${new Date().getFullYear()} ${this.metadata.author!.name || this.productName}` + return `Copyright © ${new Date().getFullYear()} ${this.companyName || this.productName}` } async computePackageUrl(): Promise { diff --git a/packages/electron-builder/src/builder.ts b/packages/electron-builder/src/builder.ts index 684d4f4dd31..3ae1de199f2 100644 --- a/packages/electron-builder/src/builder.ts +++ b/packages/electron-builder/src/builder.ts @@ -10,6 +10,7 @@ import { normalizePlatforms, Packager } from "./packager" import { PackagerOptions } from "./packagerApi" import { PublishManager } from "./publish/PublishManager" +/** @internal */ export interface BuildOptions extends PackagerOptions, PublishOptions { } @@ -29,12 +30,11 @@ export interface CliOptions extends PackagerOptions, PublishOptions { platform?: string project?: string + + extraMetadata?: any } -/** - * @private - * @internal - */ +/** @internal */ export function normalizeOptions(args: CliOptions): BuildOptions { if (args.targets != null) { return args @@ -140,6 +140,7 @@ export function normalizeOptions(args: CliOptions): BuildOptions { delete r._ delete r.version delete r.help + delete r.c delete result.ia32 delete result.x64 @@ -149,6 +150,31 @@ export function normalizeOptions(args: CliOptions): BuildOptions { result.projectDir = result.project } delete result.project + + let config = result.config + if (config != null && !(typeof config === "string")) { + if (typeof config.asar === "string") { + (config).asar = config.asar === "true" + } + } + + if (result.extraMetadata != null) { + if (typeof config === "string") { + // transform to object and specify path to config as extends + config = { + extends: config, + extraMetadata: result.extraMetadata, + }; + (result).config = config + } + else if (config == null) { + config = {}; + (result).config = config + } + (config).extraMetadata = result.extraMetadata + } + delete result.extraMetadata + return result } diff --git a/packages/electron-builder/src/index.ts b/packages/electron-builder/src/index.ts index 745254d37bb..333e2342b48 100644 --- a/packages/electron-builder/src/index.ts +++ b/packages/electron-builder/src/index.ts @@ -1,7 +1,7 @@ export { Packager, BuildResult } from "./packager" export { PackagerOptions, ArtifactCreated, BuildInfo } from "./packagerApi" export { getArchSuffix, Platform, Arch, archFromString, Target, DIR_TARGET } from "electron-builder-core" -export { BuildOptions, build, CliOptions, createTargets } from "./builder" +export { build, CliOptions, createTargets } from "./builder" export { Metadata, Config, AfterPackContext, MetadataDirectories, Protocol, FileAssociation, PlatformSpecificBuildOptions, AuthorMetadata, RepositoryInfo, AsarOptions, FilePattern } from "./metadata" export { MacOptions, DmgOptions, MasBuildOptions, MacOsTargetName, PkgOptions, DmgContent, DmgWindow } from "./options/macOptions" export { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions, NsisWebOptions, PortableOptions, CommonNsisOptions } from "./options/winOptions" diff --git a/packages/electron-builder/src/macPackager.ts b/packages/electron-builder/src/macPackager.ts index 0d9b82e1077..047feda8299 100644 --- a/packages/electron-builder/src/macPackager.ts +++ b/packages/electron-builder/src/macPackager.ts @@ -101,8 +101,9 @@ export default class MacPackager extends PlatformPackager { const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (this.config).mas) if (targetName === "mas-dev") { - deepAssign(masBuildOptions, (this.config)[targetName]) - masBuildOptions.type = "development" + deepAssign(masBuildOptions, (this.config)[targetName], { + type: "development", + }) } const targetOutDir = path.join(outDir, targetName) diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index cf35740698a..ee6e9f0d489 100644 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -299,6 +299,15 @@ export interface Config extends PlatformSpecificBuildOptions { * @private */ readonly icon?: string | null + + /** + * The name of a built-in configuration preset. Currently, only `react-cra` is supported. + * + * If `react-scripts` in the app dev dependencies, `react-cra` will be set automatically. Set to `null` to disable automatic detection. + */ + readonly extends?: string | null + + readonly extraMetadata?: any } export interface AfterPackContext { diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index 9634a0bd1a4..0c623a89cd5 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -16,6 +16,7 @@ import MacPackager from "./macPackager" import { AfterPackContext, Config, Metadata } from "./metadata" import { ArtifactCreated, BuildInfo, PackagerOptions } from "./packagerApi" import { PlatformPackager } from "./platformPackager" +import { reactCra } from "./presets/rect-cra" import { getRepositoryInfo } from "./repositoryInfo" import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory" import { doLoadConfig, getElectronVersion, loadConfig, readPackageJson, validateConfig } from "./util/readPackageJson" @@ -71,6 +72,13 @@ export class Packager implements BuildInfo { //noinspection JSUnusedGlobalSymbols constructor(readonly options: PackagerOptions, readonly cancellationToken: CancellationToken) { + if ("devMetadata" in options) { + throw new Error("devMetadata in the options is deprecated, please use config instead") + } + if ("extraMetadata" in options) { + throw new Error("extraMetadata in the options is deprecated, please use config.extraMetadata instead") + } + this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir) this.prepackaged = options.prepackaged == null ? null : path.resolve(this.projectDir, options.prepackaged) @@ -100,12 +108,6 @@ export class Packager implements BuildInfo { } async build(): Promise { - //noinspection JSDeprecatedSymbols - const devMetadataFromOptions = this.options.devMetadata - if (devMetadataFromOptions != null) { - warn("devMetadata is deprecated, please use config instead") - } - let configPath: string | null = null let configFromOptions = this.options.config if (typeof configFromOptions === "string") { @@ -113,29 +115,21 @@ export class Packager implements BuildInfo { configPath = configFromOptions configFromOptions = null } - - if (devMetadataFromOptions != null) { - if (configFromOptions != null) { - throw new Error("devMetadata and config cannot be used in conjunction") - } - configFromOptions = devMetadataFromOptions.build + else if (configFromOptions != null && configFromOptions.extends != null && configFromOptions.extends.includes(".")) { + configPath = configFromOptions.extends } const projectDir = this.projectDir const fileOrPackageConfig = await (configPath == null ? loadConfig(projectDir) : doLoadConfig(path.resolve(projectDir, configPath), projectDir)) - const config = deepAssign({}, fileOrPackageConfig, configFromOptions) + const config: Config = deepAssign({}, fileOrPackageConfig, configFromOptions) - const extraMetadata = this.options.extraMetadata + const extraMetadata = config.extraMetadata if (extraMetadata != null) { - const extraBuildMetadata = extraMetadata.build - if (extraBuildMetadata != null) { - deepAssign(config, extraBuildMetadata) - delete extraMetadata.build + if (extraMetadata.build != null) { + throw new Error(`--em.build is deprecated, please specify as -c"`) } if (extraMetadata.directories != null) { - warn(`--em.directories is deprecated, please specify as --em.build.directories"`) - deepAssign(config, {directories: extraMetadata.directories}) - delete extraMetadata.directories + throw new Error(`--em.directories is deprecated, please specify as -c.directories"`) } } @@ -152,8 +146,7 @@ export class Packager implements BuildInfo { await this.readProjectMetadata(appPackageFile, extraMetadata) if (this.isTwoPackageJsonProjectLayoutUsed) { - this.devMetadata = deepAssign(await readPackageJson(devPackageFile), devMetadataFromOptions) - + this.devMetadata = await readPackageJson(devPackageFile) debug(`Two package.json structure is used (dev: ${devPackageFile}, app: ${appPackageFile})`) } else { @@ -166,6 +159,22 @@ export class Packager implements BuildInfo { } } + if (config.extends == null && config.extends !== null) { + const devDependencies = (this.devMetadata).devDependencies + if (devDependencies != null && "react-scripts" in devDependencies) { + (config).extends = "react-cra" + } + } + + if (config.extends === "react-cra") { + await reactCra(config, this.projectDir) + + // apply extraMetadata again to metadata because other code expects that appInfo.metadata it is effective metadata, not as on disk (e.g. application entry check) + if (config.extraMetadata != null) { + deepAssign(this.metadata, config.extraMetadata) + } + } + this.checkMetadata(appPackageFile, devPackageFile) if (debug.enabled) { diff --git a/packages/electron-builder/src/packagerApi.ts b/packages/electron-builder/src/packagerApi.ts index 67869b2906c..0891055af73 100644 --- a/packages/electron-builder/src/packagerApi.ts +++ b/packages/electron-builder/src/packagerApi.ts @@ -19,11 +19,6 @@ export interface PackagerOptions { platformPackagerFactory?: ((info: BuildInfo, platform: Platform, cleanupTasks: Array<() => Promise>) => PlatformPackager) | null - /** - * @deprecated Use {@link PackagerOptions#config} instead. - */ - readonly devMetadata?: Metadata - readonly config?: Config | string | null /** @@ -35,8 +30,6 @@ export interface PackagerOptions { readonly effectiveOptionComputed?: (options: any) => Promise - readonly extraMetadata?: any - readonly prepackaged?: string } diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index a318e6290c6..2dc7b850b18 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -183,7 +183,7 @@ export abstract class PlatformPackager const transformer = await createTransformer(appDir, isElectronCompile ? Object.assign({ originalMain: this.info.metadata.main, main: ELECTRON_COMPILE_SHIM_FILENAME, - }, this.packagerOptions.extraMetadata) : this.packagerOptions.extraMetadata) + }, this.config.extraMetadata) : this.config.extraMetadata) let promise if (this.info.isPrepackedAppAsar) { promise = copyDir(appDir, path.join(resourcesPath), filter, transformer) diff --git a/packages/electron-builder/src/presets/rect-cra.ts b/packages/electron-builder/src/presets/rect-cra.ts new file mode 100644 index 00000000000..a8d88000919 --- /dev/null +++ b/packages/electron-builder/src/presets/rect-cra.ts @@ -0,0 +1,22 @@ +import { deepAssign } from "electron-builder-util/out/deepAssign" +import { statOrNull } from "electron-builder-util/out/fs" +import { warn } from "electron-builder-util/out/log" +import * as path from "path" +import { Config } from "../metadata" + +/** @internal */ +export async function reactCra(config: Config, projectDir: string) { + if ((await statOrNull(path.join(projectDir, "public", "electron.js"))) == null) { + warn("public/electron.js not found. Please see https://medium.com/@kitze/%EF%B8%8F-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3") + } + + deepAssign(config, { + directories: { + buildResources: "assets" + }, + files: ["build/**/*"], + extraMetadata: { + main: "build/electron.js" + } + }) +} \ 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 b71ce04c428..d164a98a050 100644 --- a/packages/electron-builder/src/targets/dmg.ts +++ b/packages/electron-builder/src/targets/dmg.ts @@ -1,6 +1,6 @@ import BluebirdPromise from "bluebird-lst" import { Arch, Target } from "electron-builder-core" -import { debug, exec, isEmptyOrSpaces, spawn, use } from "electron-builder-util" +import { debug, exec, isEmptyOrSpaces, spawn } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" import { copyFile, exists, statOrNull } from "electron-builder-util/out/fs" import { log, warn } from "electron-builder-util/out/log" @@ -13,7 +13,7 @@ import { PlatformPackager } from "../platformPackager" import { addLicenseToDmg } from "./dmgLicense" export class DmgTarget extends Target { - readonly options = this.packager.config.dmg + readonly options: DmgOptions = this.packager.config.dmg || Object.create(null) private helperDir = path.join(__dirname, "..", "..", "templates", "dmg") @@ -194,81 +194,83 @@ export class DmgTarget extends Target { // public to test async computeDmgOptions(): Promise { - const specification: any = deepAssign({ - window: { - x: 400, - y: 100, - }, - }, this.options) - // appdmg - const oldPosition = specification.window.position + const appdmgWindow = (this.options.window) || {} + const oldPosition = appdmgWindow.position + const oldSize = appdmgWindow.size + const oldIconSize = (this.options)["icon-size"] + const oldBackgroundColor = (this.options)["background-color"] if (oldPosition != null) { - specification.window.x = oldPosition.x - specification.window.y = oldPosition.y + warn("dmg.window.position is deprecated, please use dmg.window instead") } - - const oldSize = specification.window.size if (oldSize != null) { - specification.window.width = oldSize.width - specification.window.height = oldSize.height + warn("dmg.window.size is deprecated, please use dmg.window instead") } - - if (specification["icon-size"] != null) { - if (specification.iconSize == null) { - specification.iconSize = specification["icon-size"] - } + if (oldIconSize != null) { warn("dmg.icon-size is deprecated, please use dmg.iconSize instead") } + if (oldBackgroundColor != null) { + warn("dmg.background-color is deprecated, please use dmg.backgroundColor instead") + } const packager = this.packager - if (!("icon" in specification)) { - use(await packager.getIconPath(), it => { - specification.icon = it + const specification = deepAssign({ + window: { + x: 400, + y: 100, + }, + iconSize: oldIconSize, + backgroundColor: oldBackgroundColor, + icon: "icon" in this.options ? undefined : await packager.getIconPath() + }, + this.options, + oldPosition == null ? null : { + window: { + x: oldPosition.x, + y: oldPosition.y, + } + }, + oldSize == null ? null : { + window: { + width: oldSize.width, + height: oldSize.height, + } }) - } if (specification.icon != null && isEmptyOrSpaces(specification.icon)) { throw new Error("dmg.icon cannot be specified as empty string") } - if (specification["background-color"] != null) { - if (specification.backgroundColor == null) { - specification.backgroundColor = specification["background-color"] - } - warn("dmg.background-color is deprecated, please use dmg.backgroundColor instead") - } - if (specification.backgroundColor != null) { if (specification.background != null) { throw new Error("Both dmg.backgroundColor and dmg.background are specified — please set the only one") } - specification.backgroundColor = require("parse-color")(specification.backgroundColor).hex + (specification).backgroundColor = require("parse-color")(specification.backgroundColor).hex } if (specification.backgroundColor == null && !("background" in specification)) { const resourceList = await packager.resourceList if (resourceList.includes("background.tiff")) { - specification.background = path.join(packager.buildResourcesDir, "background.tiff") + (specification).background = path.join(packager.buildResourcesDir, "background.tiff") } else if (resourceList.includes("background.png")) { - specification.background = path.join(packager.buildResourcesDir, "background.png") + (specification).background = path.join(packager.buildResourcesDir, "background.png") } else { - specification.background = path.join(this.helperDir, "background.tiff") + (specification).background = path.join(this.helperDir, "background.tiff") } } if (specification.format == null) { if (process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL != null) { - specification.format = "UDZO" + (specification).format = "UDZO" } else if (packager.config.compression === "store") { - specification.format = "UDRO" + (specification).format = "UDRO" } else { - specification.format = packager.config.compression === "maximum" ? "UDBZ" : "UDZO" + (specification).format = packager.config.compression === "maximum" ? "UDBZ" : "UDZO" } } diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 3b13591ce38..56c215541e0 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -4,7 +4,7 @@ import { RequestHeaders } from "electron-builder-http" import { CancellationToken } from "electron-builder-http/out/CancellationToken" import { BintrayOptions, GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, s3Url, VersionInfo } from "electron-builder-http/out/publishOptions" import { EventEmitter } from "events" -import { readFile, writeFile } from "fs-extra-p" +import { outputFile, readFile } from "fs-extra-p" import { safeLoad } from "js-yaml" import * as path from "path" import { eq as isVersionsEqual, gt as isVersionGreaterThan, prerelease as getVersionPreleaseComponents, valid as parseVersion } from "semver" @@ -347,7 +347,7 @@ export abstract class AppUpdater extends EventEmitter { const id = UUID.v5({name: randomBytes(4096), namespace: UUID.namespace.oid}) this._logger.info(`Generated new staging user ID: ${id}`) try { - await writeFile(file, id) + await outputFile(file, id) } catch (e) { this._logger.warn(`Couldn't write out staging user ID: ${e}`) diff --git a/test/out/__snapshots__/BuildTest.js.snap b/test/out/__snapshots__/BuildTest.js.snap index 66ba5ec6e9a..0a244361eea 100644 --- a/test/out/__snapshots__/BuildTest.js.snap +++ b/test/out/__snapshots__/BuildTest.js.snap @@ -20,7 +20,6 @@ exports[`cli 1`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -41,7 +40,6 @@ exports[`cli 2`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -64,7 +62,6 @@ exports[`cli 3`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -87,7 +84,6 @@ exports[`cli 4`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -106,7 +102,6 @@ exports[`cli 5`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -125,7 +120,6 @@ exports[`cli 6`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -154,7 +148,6 @@ exports[`cli 7`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -177,7 +170,6 @@ exports[`cli 8`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -200,7 +192,6 @@ exports[`cli 9`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -223,7 +214,6 @@ exports[`cli 10`] = ` Object { "config": undefined, "draft": undefined, - "extraMetadata": undefined, "prepackaged": undefined, "prerelease": undefined, "projectDir": undefined, @@ -260,6 +250,26 @@ Object { } `; +exports[`extraMetadata and config as path 1`] = ` +Object { + "linux": Array [], +} +`; + +exports[`extraMetadata and config as path 2`] = ` +Object { + "author": "Foo Bar ", + "description": "Test Application (test quite \\" #378)", + "field": "bar.js", + "homepage": "http://foo.example.com", + "license": "MIT", + "name": "TestApp", + "private": true, + "productName": "Test App ßW", + "version": "1.1.0", +} +`; + exports[`relative index 1`] = ` Object { "linux": Array [], diff --git a/test/out/__snapshots__/extraMetadataTest.js.snap b/test/out/__snapshots__/extraMetadataTest.js.snap index f86e390ebc7..b2858b190e9 100644 --- a/test/out/__snapshots__/extraMetadataTest.js.snap +++ b/test/out/__snapshots__/extraMetadataTest.js.snap @@ -23,14 +23,6 @@ Object { } `; -exports[`extra metadata - override icon 1`] = `"Cannot find specified resource \\"dev.icns\\""`; - -exports[`extra metadata - two 1`] = ` -Object { - "linux": Array [], -} -`; - exports[`extra metadata 1`] = ` Object { "linux": Array [], diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index bccd2150e69..fb9d4e10fb4 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -1,9 +1,9 @@ import BluebirdPromise from "bluebird-lst" -import { Arch, BuildOptions, createTargets, DIR_TARGET, Platform } from "electron-builder" +import { Arch, createTargets, DIR_TARGET, Platform } from "electron-builder" import { walk } from "electron-builder-util/out/fs" import { readAsarJson } from "electron-builder/out/asar" import { checkWineVersion } from "electron-builder/out/packager" -import { move, outputJson } from "fs-extra-p" +import { move, outputJson, readJson } from "fs-extra-p" import * as path from "path" import { ELECTRON_VERSION } from "./helpers/config" import { app, appTwo, appTwoThrows, assertPack, modifyPackageJson, packageJson } from "./helpers/packTester" @@ -16,16 +16,15 @@ test("cli", async () => { const yargs = require("yargs") configureBuildCommand(yargs) - function parse(input: string): BuildOptions { + function parse(input: string): any { return normalizeOptions(yargs.parse(input.split(" "))) } - function expected(opt: BuildOptions): object { + function expected(opt: any): object { return Object.assign({ publish: undefined, draft: undefined, prerelease: undefined, - extraMetadata: undefined, }, opt) } @@ -74,6 +73,26 @@ test("relative index", appTwo({ }, true) })) + +test("extraMetadata and config as path", app(Object.assign(require("electron-builder/out/builder").normalizeOptions({ + extraMetadata: { + field: "bar.js" + }, + config: "foo.json", +}), { + targets: linuxDirTarget, +}), { + projectDirCreated: projectDir => { + return outputJson(path.join(projectDir, "foo.json"), { + asar: false + }) + }, + packed: async context => { + const resourceDir = context.getResources(Platform.LINUX) + expect(await readJson(path.join(resourceDir, "app", "package.json"))).toMatchSnapshot() + } +})) + it.ifDevOrLinuxCi("electron version from electron-prebuilt dependency", app({ targets: linuxDirTarget, }, { diff --git a/test/src/extraMetadataTest.ts b/test/src/extraMetadataTest.ts index aa32b562930..8ce1ab1162d 100644 --- a/test/src/extraMetadataTest.ts +++ b/test/src/extraMetadataTest.ts @@ -3,21 +3,21 @@ import { readAsarJson } from "electron-builder/out/asar" import { readJson } from "fs-extra-p" import * as path from "path" import { assertThat } from "./helpers/fileAssert" -import { app, appTwo, appTwoThrows, modifyPackageJson } from "./helpers/packTester" +import { app, modifyPackageJson } from "./helpers/packTester" function createExtraMetadataTest(asar: boolean) { return app({ targets: Platform.LINUX.createTarget(DIR_TARGET), - extraMetadata: { - foo: { - bar: 12, + config: { + asar: asar, + linux: { + executableName: "new-name", }, - build: { - asar: asar, - linux: { - executableName: "new-name", + extraMetadata: { + foo: { + bar: 12, }, - } + }, }, }, { projectDirCreated: projectDir => modifyPackageJson(projectDir, data => { @@ -41,34 +41,4 @@ function createExtraMetadataTest(asar: boolean) { } test.ifDevOrLinuxCi("extra metadata", createExtraMetadataTest(true)) -test.ifDevOrLinuxCi("extra metadata (no asar)", createExtraMetadataTest(false)) - -test.ifDevOrLinuxCi("extra metadata - two", appTwo({ - targets: Platform.LINUX.createTarget(DIR_TARGET), - extraMetadata: { - build: { - linux: { - executableName: "new-name" - } - } - }, - }, { - packed: async context => { - await assertThat(path.join(context.getContent(Platform.LINUX), "new-name")).isFile() - } -})) - -test.ifMac("extra metadata - override icon", appTwoThrows({ - targets: Platform.MAC.createTarget(DIR_TARGET), - extraMetadata: { - build: { - mac: { - icon: "dev" - } - }, - }, -}, { - packed: async context => { - await assertThat(path.join(context.getContent(Platform.LINUX), "new-name")).isFile() - } -})) \ No newline at end of file +test.ifDevOrLinuxCi("extra metadata (no asar)", createExtraMetadataTest(false)) \ No newline at end of file