From 11edf803c48a0e02ef2b36f3cc857794671ad77e Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Wed, 1 Nov 2023 14:48:35 -0700 Subject: [PATCH] chore: remove `electron-prebuilt-compile` support BREAKING CHANGE: plugin-compile has been discontinued and Forge no longer supports `electron-prebuilt` or `electron-prebuilt-compile`. --- .../api/core/src/util/electron-executable.ts | 33 +------- .../api/core/src/util/upgrade-forge-config.ts | 4 - .../test/fast/electron-executable_spec.ts | 77 +------------------ .../test/fast/upgrade-forge-config_spec.ts | 12 --- .../dummy_default_js_conf/package.json | 2 +- .../dummy_default_ts_conf/package.json | 2 +- .../test/fixture/dummy_js_conf/package.json | 2 +- .../test/fixture/dummy_ts_conf/package.json | 2 +- packages/plugin/compile/README.md | 3 - packages/plugin/compile/package.json | 29 ------- packages/plugin/compile/src/CompilePlugin.ts | 38 --------- packages/plugin/compile/src/Config.ts | 2 - .../plugin/compile/src/lib/compile-hook.ts | 43 ----------- .../utils/core-utils/src/electron-version.ts | 2 +- .../core-utils/test/electron-version_spec.ts | 14 ---- 15 files changed, 7 insertions(+), 258 deletions(-) delete mode 100644 packages/plugin/compile/README.md delete mode 100644 packages/plugin/compile/package.json delete mode 100644 packages/plugin/compile/src/CompilePlugin.ts delete mode 100644 packages/plugin/compile/src/Config.ts delete mode 100644 packages/plugin/compile/src/lib/compile-hook.ts diff --git a/packages/api/core/src/util/electron-executable.ts b/packages/api/core/src/util/electron-executable.ts index d0e7f435bc..3d37e0b2e3 100644 --- a/packages/api/core/src/util/electron-executable.ts +++ b/packages/api/core/src/util/electron-executable.ts @@ -1,43 +1,12 @@ import path from 'path'; import { getElectronModulePath } from '@electron-forge/core-utils'; -import chalk from 'chalk'; import logSymbols from 'log-symbols'; type PackageJSON = Record; -type Dependencies = Record; - -export function pluginCompileExists(packageJSON: PackageJSON): boolean { - if (!packageJSON.devDependencies) { - return false; - } - - const pluginCompileName = '@electron-forge/plugin-compile'; - const findPluginCompile = (packageName: string): boolean => packageName === pluginCompileName; - - if (Object.keys(packageJSON.devDependencies as Dependencies).find(findPluginCompile)) { - return true; - } - - if (Object.keys((packageJSON.dependencies as Dependencies) || {}).find(findPluginCompile)) { - console.warn(logSymbols.warning, chalk.yellow(`${pluginCompileName} was detected in dependencies, it should be in devDependencies`)); - return true; - } - - return false; -} export default async function locateElectronExecutable(dir: string, packageJSON: PackageJSON): Promise { - let electronModulePath: string | undefined = await getElectronModulePath(dir, packageJSON); - if (electronModulePath?.endsWith('electron-prebuilt-compile') && !pluginCompileExists(packageJSON)) { - console.warn( - logSymbols.warning, - chalk.yellow( - 'WARNING: found electron-prebuilt-compile without the Electron Forge compile plugin. Please remove the deprecated electron-prebuilt-compile from your devDependencies.' - ) - ); - electronModulePath = undefined; - } + const electronModulePath: string | undefined = await getElectronModulePath(dir, packageJSON); // eslint-disable-next-line @typescript-eslint/no-var-requires let electronExecPath = require(electronModulePath || path.resolve(dir, 'node_modules/electron')); diff --git a/packages/api/core/src/util/upgrade-forge-config.ts b/packages/api/core/src/util/upgrade-forge-config.ts index a8daddd553..e73f373efd 100644 --- a/packages/api/core/src/util/upgrade-forge-config.ts +++ b/packages/api/core/src/util/upgrade-forge-config.ts @@ -168,9 +168,5 @@ export function updateUpgradedForgeDevDeps(packageJSON: ForgePackageJSON, devDep (forgeConfig.publishers as IForgeResolvablePublisher[]).map((publisher: IForgeResolvablePublisher) => siblingDep(path.basename(publisher.name))) ); - if (Object.keys(packageJSON.devDependencies).find((dep: string) => dep === 'electron-prebuilt-compile')) { - devDeps = devDeps.concat(siblingDep('plugin-compile')); - } - return devDeps; } diff --git a/packages/api/core/test/fast/electron-executable_spec.ts b/packages/api/core/test/fast/electron-executable_spec.ts index ffd72f91b9..d891167225 100644 --- a/packages/api/core/test/fast/electron-executable_spec.ts +++ b/packages/api/core/test/fast/electron-executable_spec.ts @@ -4,7 +4,7 @@ import chai, { expect } from 'chai'; import { createSandbox } from 'sinon'; import sinonChai from 'sinon-chai'; -import locateElectronExecutable, { pluginCompileExists } from '../../src/util/electron-executable'; +import locateElectronExecutable from '../../src/util/electron-executable'; chai.use(sinonChai); @@ -30,79 +30,4 @@ describe('locateElectronExecutable', () => { await expect(locateElectronExecutable(appFixture, packageJSON)).to.eventually.equal('execPath'); expect(console.warn).to.not.have.been.called; }); - - it('warns and returns a hardcoded path to electron if another electron module does not export a string', async () => { - const appFixture = path.join(fixtureDir, 'bad-export'); - const packageJSON = { - devDependencies: { - '@electron-forge/plugin-compile': '^6.0.0-beta.1', - 'electron-prebuilt-compile': '^1.4.0', - }, - }; - - await expect(locateElectronExecutable(appFixture, packageJSON)).to.eventually.equal('execPath'); - expect(console.warn).to.have.been.calledOnce; - }); - - it('warns if prebuilt-compile exists without the corresponding plugin', async () => { - const packageJSON = { - devDependencies: { 'electron-prebuilt-compile': '1.0.0' }, - }; - const compileFixture = path.join(fixtureDir, 'prebuilt-compile'); - - await expect(locateElectronExecutable(compileFixture, packageJSON)).to.eventually.be.rejected; - expect(console.warn).to.have.been.calledOnce; - }); - - it('does not warn if prebuilt-compile exists with the corresponding plugin', async () => { - const packageJSON = { - devDependencies: { - '@electron-forge/plugin-compile': '^6.0.0-beta.1', - 'electron-prebuilt-compile': '1.0.0', - }, - }; - - const compileFixture = path.join(fixtureDir, 'prebuilt-compile'); - await expect(locateElectronExecutable(compileFixture, packageJSON)).to.eventually.be.rejected; - expect(console.warn).to.not.have.been.called; - }); -}); - -describe('pluginCompileExists', () => { - const sandbox = createSandbox(); - - beforeEach(() => { - sandbox.spy(console, 'warn'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('returns false if there is no devDependencies', () => { - expect(pluginCompileExists({})).to.equal(false); - }); - - it('returns false if the plugin is not found in devDependencies', () => { - expect(pluginCompileExists({ devDependencies: {} })).to.equal(false); - }); - - it('returns true if the plugin is found in devDependencies', () => { - const packageJSON = { - devDependencies: { '@electron-forge/plugin-compile': '^6.0.0-beta.1' }, - }; - - expect(pluginCompileExists(packageJSON)).to.equal(true); - expect(console.warn).to.not.have.been.called; - }); - - it('warns and returns true if the plugin is found in dependencies', () => { - const packageJSON = { - dependencies: { '@electron-forge/plugin-compile': '^6.0.0-beta.1' }, - devDependencies: {}, - }; - - expect(pluginCompileExists(packageJSON)).to.equal(true); - expect(console.warn).to.have.been.calledOnce; - }); }); 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 ef04adb0c6..5e95123a64 100644 --- a/packages/api/core/test/fast/upgrade-forge-config_spec.ts +++ b/packages/api/core/test/fast/upgrade-forge-config_spec.ts @@ -168,16 +168,4 @@ describe('updateUpgradedForgeDevDeps', () => { expect(actual.find((dep) => dep.startsWith('@electron-forge/publisher-github'))).to.not.equal(undefined); expect(actual.find((dep) => dep.startsWith('@electron-forge/publisher-snapcraft'))).to.not.equal(undefined); }); - - it('adds electron-compile plugin to devDependencies when electron-prebuilt-compile is in devDependencies', () => { - const packageJSON = merge({}, skeletonPackageJSON, { - devDependencies: { - 'electron-prebuilt-compile': '2.0.0', - }, - }); - - const actual = updateUpgradedForgeDevDeps(packageJSON, []); - expect(actual, JSON.stringify(actual)).to.have.lengthOf(1); - expect(actual[0]).to.match(/^@electron-forge\/plugin-compile/); - }); }); diff --git a/packages/api/core/test/fixture/dummy_default_js_conf/package.json b/packages/api/core/test/fixture/dummy_default_js_conf/package.json index ca2374229b..f59c18baee 100644 --- a/packages/api/core/test/fixture/dummy_default_js_conf/package.json +++ b/packages/api/core/test/fixture/dummy_default_js_conf/package.json @@ -11,6 +11,6 @@ "author": "", "license": "MIT", "devDependencies": { - "electron-prebuilt": "9.9.9" + "electron": "99.99.99" } } diff --git a/packages/api/core/test/fixture/dummy_default_ts_conf/package.json b/packages/api/core/test/fixture/dummy_default_ts_conf/package.json index 6339a1a841..da951252fb 100644 --- a/packages/api/core/test/fixture/dummy_default_ts_conf/package.json +++ b/packages/api/core/test/fixture/dummy_default_ts_conf/package.json @@ -12,6 +12,6 @@ "license": "MIT", "devDependencies": { "@electron-forge/shared-types": "*", - "electron-prebuilt": "9.9.9" + "electron": "99.99.99" } } diff --git a/packages/api/core/test/fixture/dummy_js_conf/package.json b/packages/api/core/test/fixture/dummy_js_conf/package.json index f04c0add9d..65fa32fe5e 100644 --- a/packages/api/core/test/fixture/dummy_js_conf/package.json +++ b/packages/api/core/test/fixture/dummy_js_conf/package.json @@ -14,6 +14,6 @@ "forge": "./forge.different.config.js" }, "devDependencies": { - "electron-prebuilt": "9.9.9" + "electron": "99.99.99" } } diff --git a/packages/api/core/test/fixture/dummy_ts_conf/package.json b/packages/api/core/test/fixture/dummy_ts_conf/package.json index df0eaf8be0..fe524262eb 100644 --- a/packages/api/core/test/fixture/dummy_ts_conf/package.json +++ b/packages/api/core/test/fixture/dummy_ts_conf/package.json @@ -15,6 +15,6 @@ }, "devDependencies": { "@electron-forge/shared-types": "*", - "electron-prebuilt": "9.9.9" + "electron": "99.99.99" } } diff --git a/packages/plugin/compile/README.md b/packages/plugin/compile/README.md deleted file mode 100644 index 40565d70ba..0000000000 --- a/packages/plugin/compile/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## plugin-compile - -_Note: This plugin is deprecated in Forge 6.0.0 and is slated for removal._ diff --git a/packages/plugin/compile/package.json b/packages/plugin/compile/package.json deleted file mode 100644 index d83d6659c2..0000000000 --- a/packages/plugin/compile/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@electron-forge/plugin-compile", - "version": "6.4.2", - "description": "Electron Compile plugin for Electron Forge", - "repository": "https://github.com/electron/forge", - "author": "Samuel Attard", - "license": "MIT", - "main": "dist/CompilePlugin.js", - "typings": "dist/CompilePlugin.d.ts", - "devDependencies": { - "chai": "^4.3.3", - "mocha": "^9.0.1" - }, - "engines": { - "node": ">= 14.17.5" - }, - "dependencies": { - "@electron-forge/plugin-base": "6.4.2", - "@electron-forge/shared-types": "6.4.2", - "fs-extra": "^10.0.0" - }, - "publishConfig": { - "access": "public" - }, - "files": [ - "dist", - "src" - ] -} diff --git a/packages/plugin/compile/src/CompilePlugin.ts b/packages/plugin/compile/src/CompilePlugin.ts deleted file mode 100644 index 88ef84234c..0000000000 --- a/packages/plugin/compile/src/CompilePlugin.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as path from 'path'; - -import { PluginBase, StartOptions } from '@electron-forge/plugin-base'; -import { ForgeHookMap, ResolvedForgeConfig } from '@electron-forge/shared-types'; - -import { CompilePluginConfig } from './Config'; -import { createCompileHook } from './lib/compile-hook'; - -export default class CompileElectronPlugin extends PluginBase { - name = 'electron-compile'; - - private dir!: string; - - constructor(c: CompilePluginConfig) { - super(c); - - this.init = this.init.bind(this); - this.getHooks = this.getHooks.bind(this); - this.startLogic = this.startLogic.bind(this); - } - - init(dir: string, config: ResolvedForgeConfig): void { - super.init(dir, config); - this.dir = dir; - } - - getHooks(): ForgeHookMap { - return { - packageAfterCopy: createCompileHook(this.dir), - }; - } - - async startLogic(_opts: StartOptions): Promise { - return [process.execPath, path.resolve(this.dir, 'node_modules/electron-prebuilt-compile/lib/cli')]; - } -} - -export { CompileElectronPlugin, CompilePluginConfig }; diff --git a/packages/plugin/compile/src/Config.ts b/packages/plugin/compile/src/Config.ts deleted file mode 100644 index 7d06e771af..0000000000 --- a/packages/plugin/compile/src/Config.ts +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface CompilePluginConfig {} diff --git a/packages/plugin/compile/src/lib/compile-hook.ts b/packages/plugin/compile/src/lib/compile-hook.ts deleted file mode 100644 index 88265502e2..0000000000 --- a/packages/plugin/compile/src/lib/compile-hook.ts +++ /dev/null @@ -1,43 +0,0 @@ -import path from 'path'; - -import { ForgeHookFn } from '@electron-forge/shared-types'; -import fs from 'fs-extra'; - -export const createCompileHook = - (originalDir: string): ForgeHookFn<'packageAfterCopy'> => - async (_config, buildPath): Promise => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const compileCLI = require(path.resolve(originalDir, 'node_modules/electron-compile/lib/cli.js')); - - async function compileAndShim(appDir: string) { - for (const entry of await fs.readdir(appDir)) { - if (!entry.match(/^(node_modules|bower_components)$/)) { - const fullPath = path.join(appDir, entry); - - if ((await fs.stat(fullPath)).isDirectory()) { - const { log } = console; - console.log = () => { - /* disable log function for electron-compile */ - }; - await compileCLI.main(appDir, [fullPath]); - console.log = log; - } - } - } - - const packageJSON = await fs.readJson(path.resolve(appDir, 'package.json')); - - const index = packageJSON.main || 'index.js'; - packageJSON.originalMain = index; - packageJSON.main = 'es6-shim.js'; - - await fs.writeFile( - path.join(appDir, 'es6-shim.js'), - await fs.readFile(path.join(path.resolve(originalDir, 'node_modules/electron-compile/lib/es6-shim.js')), 'utf8') - ); - - await fs.writeJson(path.join(appDir, 'package.json'), packageJSON, { spaces: 2 }); - } - - await compileAndShim(buildPath); - }; diff --git a/packages/utils/core-utils/src/electron-version.ts b/packages/utils/core-utils/src/electron-version.ts index 2709800a98..16caf0aac6 100644 --- a/packages/utils/core-utils/src/electron-version.ts +++ b/packages/utils/core-utils/src/electron-version.ts @@ -9,7 +9,7 @@ import { safeYarnOrNpm } from './yarn-or-npm'; const d = debug('electron-forge:electron-version'); -const electronPackageNames = ['electron-prebuilt-compile', 'electron-prebuilt', 'electron-nightly', 'electron']; +const electronPackageNames = ['electron-nightly', 'electron']; type PackageJSONWithDeps = { devDependencies?: Record; diff --git a/packages/utils/core-utils/test/electron-version_spec.ts b/packages/utils/core-utils/test/electron-version_spec.ts index 26838e426d..931715d580 100644 --- a/packages/utils/core-utils/test/electron-version_spec.ts +++ b/packages/utils/core-utils/test/electron-version_spec.ts @@ -54,20 +54,6 @@ describe('getElectronVersion', () => { return expect(getElectronVersion(fixtureDir, { devDependencies: { electron: '^4.0.2' } })).to.eventually.equal('4.0.9'); }); - it('works with electron-prebuilt-compile', () => { - const packageJSON = { - devDependencies: { 'electron-prebuilt-compile': '1.0.0' }, - }; - return expect(getElectronVersion('', packageJSON)).to.eventually.equal('1.0.0'); - }); - - it('works with electron-prebuilt', async () => { - const packageJSON = { - devDependencies: { 'electron-prebuilt': '1.0.0' }, - }; - return expect(await getElectronVersion('', packageJSON)).to.be.equal('1.0.0'); - }); - it('works with electron-nightly', async () => { const packageJSON = { devDependencies: { 'electron-nightly': '5.0.0-nightly.20190107' },