Skip to content

Commit

Permalink
chore: remove electron-prebuilt-compile support (#3396)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: plugin-compile has been discontinued and Forge
no longer supports `electron-prebuilt` or `electron-prebuilt-compile`.
  • Loading branch information
erickzhao authored Nov 2, 2023
1 parent 665a911 commit 126867d
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 258 deletions.
33 changes: 1 addition & 32 deletions packages/api/core/src/util/electron-executable.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>;
type Dependencies = Record<string, string>;

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<string> {
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'));
Expand Down
4 changes: 0 additions & 4 deletions packages/api/core/src/util/upgrade-forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
77 changes: 1 addition & 76 deletions packages/api/core/test/fast/electron-executable_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
});
});
12 changes: 0 additions & 12 deletions packages/api/core/test/fast/upgrade-forge-config_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"author": "",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "9.9.9"
"electron": "99.99.99"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"license": "MIT",
"devDependencies": {
"@electron-forge/shared-types": "*",
"electron-prebuilt": "9.9.9"
"electron": "99.99.99"
}
}
2 changes: 1 addition & 1 deletion packages/api/core/test/fixture/dummy_js_conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"forge": "./forge.different.config.js"
},
"devDependencies": {
"electron-prebuilt": "9.9.9"
"electron": "99.99.99"
}
}
2 changes: 1 addition & 1 deletion packages/api/core/test/fixture/dummy_ts_conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
},
"devDependencies": {
"@electron-forge/shared-types": "*",
"electron-prebuilt": "9.9.9"
"electron": "99.99.99"
}
}
3 changes: 0 additions & 3 deletions packages/plugin/compile/README.md

This file was deleted.

29 changes: 0 additions & 29 deletions packages/plugin/compile/package.json

This file was deleted.

38 changes: 0 additions & 38 deletions packages/plugin/compile/src/CompilePlugin.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/plugin/compile/src/Config.ts

This file was deleted.

43 changes: 0 additions & 43 deletions packages/plugin/compile/src/lib/compile-hook.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/utils/core-utils/src/electron-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
Expand Down
14 changes: 0 additions & 14 deletions packages/utils/core-utils/test/electron-version_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit 126867d

Please sign in to comment.