diff --git a/packages/api/core/src/api/make.ts b/packages/api/core/src/api/make.ts index 34b87715b3..8b74d8c59a 100644 --- a/packages/api/core/src/api/make.ts +++ b/packages/api/core/src/api/make.ts @@ -1,7 +1,7 @@ import { asyncOra } from '@electron-forge/async-ora'; import chalk from 'chalk'; import { getHostArch } from '@electron/get'; -import { IForgeResolvableMaker, ForgeConfig, ForgeArch, ForgePlatform, ForgeMakeResult } from '@electron-forge/shared-types'; +import { IForgeResolvableMaker, ForgeConfig, ForgeArch, ForgePlatform, ForgeMakeResult, ForgeConfigMaker } from '@electron-forge/shared-types'; import MakerBase from '@electron-forge/maker-base'; import fs from 'fs-extra'; import path from 'path'; @@ -26,14 +26,13 @@ class MakerImpl extends MakerBase { defaultPlatforms = []; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type MakeTarget = IForgeResolvableMaker | MakerBase | string; +type MakeTargets = ForgeConfigMaker[] | string[]; -function generateTargets(forgeConfig: ForgeConfig, overrideTargets?: MakeTarget[]) { +function generateTargets(forgeConfig: ForgeConfig, overrideTargets?: MakeTargets) { if (overrideTargets) { return overrideTargets.map((target) => { if (typeof target === 'string') { - return forgeConfig.makers.find((maker) => (maker as IForgeResolvableMaker).name === target) || { name: target }; + return forgeConfig.makers.find((maker) => (maker as IForgeResolvableMaker).name === target) || ({ name: target } as IForgeResolvableMaker); } return target; @@ -42,6 +41,12 @@ function generateTargets(forgeConfig: ForgeConfig, overrideTargets?: MakeTarget[ return forgeConfig.makers; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function isElectronForgeMaker(target: MakerBase | unknown): target is MakerBase { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (target as MakerBase).__isElectronForgeMaker; +} + export interface MakeOptions { /** * The path to the app from which distrubutables are generated @@ -58,7 +63,7 @@ export interface MakeOptions { /** * An array of make targets to override your forge config */ - overrideTargets?: MakeTarget[]; + overrideTargets?: MakeTargets; /** * The target architecture */ @@ -110,14 +115,13 @@ export default async ({ let targetId = 0; for (const target of targets) { - /* eslint-disable @typescript-eslint/no-explicit-any */ + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ let maker: MakerBase; - if ((target as MakerBase).__isElectronForgeMaker) { - maker = target as MakerBase; - /* eslint-enable @typescript-eslint/no-explicit-any */ + if (isElectronForgeMaker(target)) { + maker = target; if (!maker.platforms.includes(actualTargetPlatform)) continue; } else { - const resolvableTarget: IForgeResolvableMaker = target as IForgeResolvableMaker; + const resolvableTarget = target as IForgeResolvableMaker; // non-false falsy values should be 'true' if (resolvableTarget.enabled === false) continue; diff --git a/packages/api/core/src/api/package.ts b/packages/api/core/src/api/package.ts index 3ea81350a9..5e25726014 100644 --- a/packages/api/core/src/api/package.ts +++ b/packages/api/core/src/api/package.ts @@ -122,7 +122,7 @@ export default async ({ done(); }, async (buildPath, electronVersion, pPlatform, pArch, done) => { - await rebuildHook(buildPath, electronVersion, pPlatform, pArch, forgeConfig.electronRebuildConfig); + await rebuildHook(buildPath, electronVersion, pPlatform, pArch, forgeConfig.rebuildConfig); packagerSpinner = ora('Packaging Application').start(); done(); }, diff --git a/packages/api/core/src/api/publish.ts b/packages/api/core/src/api/publish.ts index 0a57aaa21b..007e799661 100644 --- a/packages/api/core/src/api/publish.ts +++ b/packages/api/core/src/api/publish.ts @@ -36,7 +36,7 @@ export interface PublishOptions { * The publish targets, by default pulled from forge config, set this prop to * override that list */ - publishTargets?: ForgeConfigPublisher[]; + publishTargets?: ForgeConfigPublisher[] | string[]; /** * Options object to passed through to make() */ diff --git a/packages/api/core/src/api/start.ts b/packages/api/core/src/api/start.ts index 6fbe497115..9317621143 100644 --- a/packages/api/core/src/api/start.ts +++ b/packages/api/core/src/api/start.ts @@ -51,7 +51,7 @@ export default async ({ const platform = process.env.npm_config_platform || process.platform; const arch = process.env.npm_config_arch || process.arch; - await rebuild(dir, await getElectronVersion(dir, packageJSON), platform as ForgePlatform, arch as ForgeArch, forgeConfig.electronRebuildConfig); + await rebuild(dir, await getElectronVersion(dir, packageJSON), platform as ForgePlatform, arch as ForgeArch, forgeConfig.rebuildConfig); await runHook(forgeConfig, 'generateAssets', platform, arch); diff --git a/packages/api/core/src/util/forge-config.ts b/packages/api/core/src/util/forge-config.ts index a6b18d1c80..0c17b0b638 100644 --- a/packages/api/core/src/util/forge-config.ts +++ b/packages/api/core/src/util/forge-config.ts @@ -142,7 +142,7 @@ export default async (dir: string): Promise => { throw new Error('Expected packageJSON.config.forge to be an object or point to a requirable JS file'); } const defaultForgeConfig = { - electronRebuildConfig: {}, + rebuildConfig: {}, packagerConfig: {}, makers: [], publishers: [], diff --git a/packages/api/core/src/util/plugin-interface.ts b/packages/api/core/src/util/plugin-interface.ts index aa58352529..891e5fa270 100644 --- a/packages/api/core/src/util/plugin-interface.ts +++ b/packages/api/core/src/util/plugin-interface.ts @@ -7,6 +7,10 @@ import requireSearch from './require-search'; const d = debug('electron-forge:plugins'); +function isForgePlugin(plugin: IForgePlugin | unknown): plugin is IForgePlugin { + return (plugin as IForgePlugin).__isElectronForgePlugin; +} + export default class PluginInterface implements IForgePluginInterface { private plugins: IForgePlugin[]; @@ -14,23 +18,24 @@ export default class PluginInterface implements IForgePluginInterface { constructor(dir: string, forgeConfig: ForgeConfig) { this.plugins = forgeConfig.plugins.map((plugin) => { - if ((plugin as IForgePlugin).__isElectronForgePlugin) { + if (isForgePlugin(plugin)) { return plugin; } - if (Array.isArray(plugin)) { - const [pluginName, opts = {}] = plugin; + if (typeof plugin === 'object' && 'name' in plugin && 'config' in plugin) { + const { name: pluginName, config: opts } = plugin; if (typeof pluginName !== 'string') { throw new Error(`Expected plugin[0] to be a string but found ${pluginName}`); } // eslint-disable-next-line @typescript-eslint/no-explicit-any const Plugin = requireSearch(dir, [pluginName]); if (!Plugin) { - throw new Error(`Could not find module with name: ${plugin[0]}. Make sure it's listed in the devDependencies of your package.json`); + throw new Error(`Could not find module with name: ${pluginName}. Make sure it's listed in the devDependencies of your package.json`); } return new Plugin(opts); } - throw new Error(`Expected plugin to either be a plugin instance or [string, object] but found ${plugin}`); + + throw new Error(`Expected plugin to either be a plugin instance or a { name, config } object but found ${plugin}`); }); // TODO: fix hack // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/api/core/src/util/upgrade-forge-config.ts b/packages/api/core/src/util/upgrade-forge-config.ts index 053bc7b774..79c440f55d 100644 --- a/packages/api/core/src/util/upgrade-forge-config.ts +++ b/packages/api/core/src/util/upgrade-forge-config.ts @@ -150,7 +150,7 @@ export default function upgradeForgeConfig(forge5Config: Forge5Config): ForgeCon forgeConfig.packagerConfig = forge5Config.electronPackagerConfig; } if (forge5Config.electronRebuildConfig) { - forgeConfig.electronRebuildConfig = forge5Config.electronRebuildConfig; + forgeConfig.rebuildConfig = forge5Config.electronRebuildConfig; } forgeConfig.makers = generateForgeMakerConfig(forge5Config); forgeConfig.publishers = generateForgePublisherConfig(forge5Config); diff --git a/packages/api/core/test/fast/forge-config_spec.ts b/packages/api/core/test/fast/forge-config_spec.ts index 388f764d93..bc6473b7bd 100644 --- a/packages/api/core/test/fast/forge-config_spec.ts +++ b/packages/api/core/test/fast/forge-config_spec.ts @@ -11,7 +11,7 @@ import findConfig, { const defaults = { packagerConfig: {}, - electronRebuildConfig: {}, + rebuildConfig: {}, makers: [], publishers: [], plugins: [], diff --git a/packages/api/core/test/fast/publish_spec.ts b/packages/api/core/test/fast/publish_spec.ts index e1b2b8cb2c..797b13dc02 100644 --- a/packages/api/core/test/fast/publish_spec.ts +++ b/packages/api/core/test/fast/publish_spec.ts @@ -29,7 +29,7 @@ describe('publish', () => { publisherSpy = stub(); voidStub = stub(); nowhereStub = stub(); - publishers = ['@electron-forge/publisher-test']; + publishers = [{ name: '@electron-forge/publisher-test' }]; const fakePublisher = (stub: SinonStub, name = 'default') => class _FakePublisher { private publish: SinonStub; diff --git a/packages/api/core/test/fast/read-package-json_spec.ts b/packages/api/core/test/fast/read-package-json_spec.ts index cbd7afc2ae..9e82bc276a 100644 --- a/packages/api/core/test/fast/read-package-json_spec.ts +++ b/packages/api/core/test/fast/read-package-json_spec.ts @@ -6,7 +6,7 @@ import { readRawPackageJson, readMutatedPackageJson } from '../../src/util/read- const emptyForgeConfig: Partial = { packagerConfig: {}, - electronRebuildConfig: {}, + rebuildConfig: {}, makers: [], publishers: [], plugins: [], diff --git a/packages/api/core/test/fast/upgrade-forge-config_spec.ts b/packages/api/core/test/fast/upgrade-forge-config_spec.ts index aacbf88877..8ffab4a841 100644 --- a/packages/api/core/test/fast/upgrade-forge-config_spec.ts +++ b/packages/api/core/test/fast/upgrade-forge-config_spec.ts @@ -23,7 +23,7 @@ describe('upgradeForgeConfig', () => { const oldConfig = { electronRebuildConfig: { ...rebuildConfig } }; const newConfig = upgradeForgeConfig(oldConfig); - expect(newConfig.electronRebuildConfig).to.deep.equal(rebuildConfig); + expect(newConfig.rebuildConfig).to.deep.equal(rebuildConfig); }); it('converts maker config', () => { @@ -116,7 +116,7 @@ describe('updateUpgradedForgeDevDeps', () => { config: { forge: { packagerConfig: {}, - electronRebuildConfig: {}, + rebuildConfig: {}, makers: [], publishers: [], plugins: [], diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index 76de77461f..4710cdf136 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -161,7 +161,7 @@ export default class WebpackPlugin extends PluginBase { await utils.getElectronVersion(this.projectDir, await fs.readJson(path.join(this.projectDir, 'package.json'))), platform, arch, - config.electronRebuildConfig + config.rebuildConfig ); await this.compileMain(); await this.compileRenderers(); diff --git a/packages/utils/types/src/index.ts b/packages/utils/types/src/index.ts index c5faf6f409..d9f72e3a4c 100644 --- a/packages/utils/types/src/index.ts +++ b/packages/utils/types/src/index.ts @@ -1,5 +1,5 @@ import { ChildProcess } from 'child_process'; -import { ArchOption, Options, TargetPlatform } from 'electron-packager'; +import { ArchOption, Options as ElectronPackagerOptions, TargetPlatform } from 'electron-packager'; import { RebuildOptions } from 'electron-rebuild'; export type ElectronProcess = ChildProcess & { restarted: boolean }; @@ -9,13 +9,18 @@ export type ForgeArch = ArchOption; // Why: hooks have any number/kind of args/return values /* eslint-disable @typescript-eslint/no-explicit-any */ export type ForgeHookFn = (forgeConfig: ForgeConfig, ...args: any[]) => Promise; -export type ForgeConfigPublisher = IForgeResolvablePublisher | IForgePublisher | string; +export type ForgeConfigPublisher = IForgeResolvablePublisher | IForgePublisher; +export type ForgeConfigMaker = IForgeResolvableMaker | IForgeMaker; +export type ForgeConfigPlugin = IForgeResolvablePlugin | IForgePlugin; export interface IForgePluginInterface { triggerHook(hookName: string, hookArgs: any[]): Promise; triggerMutatingHook(hookName: string, item: T): Promise; overrideStartLogic(opts: StartOptions): Promise; } /* eslint-enable @typescript-eslint/no-explicit-any */ + +export type ForgeRebuildOptions = Omit; +export type ForgePackagerOptions = Omit; export interface ForgeConfig { /** * A string to uniquely identify artifacts of this build, will be appended @@ -34,10 +39,10 @@ export interface ForgeConfig { /** * An array of Forge plugins or a tuple consisting of [pluginName, pluginOptions] */ - plugins: (IForgePlugin | [string, Record])[]; - electronRebuildConfig: Partial; - packagerConfig: Partial; - makers: (IForgeResolvableMaker | IForgeMaker)[]; + plugins: ForgeConfigPlugin[]; + rebuildConfig: ForgeRebuildOptions; + packagerConfig: ForgePackagerOptions; + makers: ForgeConfigMaker[]; publishers: ForgeConfigPublisher[]; } export interface ForgeMakeResult { @@ -59,6 +64,11 @@ export interface ForgeMakeResult { arch: ForgeArch; } +export interface IForgeResolvablePlugin { + name: string; + config?: any; // eslint-disable-line @typescript-eslint/no-explicit-any +} + export interface IForgePlugin { /** @internal */ __isElectronForgePlugin: boolean;