Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent conflict between parallel makers #3519

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 1 addition & 2 deletions packages/maker/dmg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
},
"dependencies": {
"@electron-forge/maker-base": "7.4.0",
"@electron-forge/shared-types": "7.4.0",
"fs-extra": "^10.0.0"
"@electron-forge/shared-types": "7.4.0"
},
"optionalDependencies": {
"electron-installer-dmg": "^4.0.0"
Expand Down
13 changes: 4 additions & 9 deletions packages/maker/dmg/src/MakerDMG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';

import { MakerBase, MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';
import fs from 'fs-extra';

import { MakerDMGConfig } from './Config';

Expand All @@ -18,23 +17,19 @@ export default class MakerDMG extends MakerBase<MakerDMGConfig> {
async make({ dir, makeDir, appName, packageJSON, targetArch }: MakerOptions): Promise<string[]> {
const electronDMG = require('electron-installer-dmg');

const outPath = path.resolve(makeDir, `${this.config.name || appName}.dmg`);
const forgeDefaultOutPath = path.resolve(makeDir, `${appName}-${packageJSON.version}-${targetArch}.dmg`);
const dmgOutName = this.config.name ?? `${appName}-${packageJSON.version}-${targetArch}`;
const outPath = path.resolve(makeDir, dmgOutName);

await this.ensureFile(outPath);
const dmgConfig = {
overwrite: true,
name: appName,
...this.config,
appPath: path.resolve(dir, `${appName}.app`),
out: path.dirname(outPath),
name: dmgOutName,
title: this.config.name ?? appName,
};
const opts = await electronDMG(dmgConfig);
if (!this.config.name) {
await this.ensureFile(forgeDefaultOutPath);
await fs.rename(outPath, forgeDefaultOutPath);
return [forgeDefaultOutPath];
}

return [opts.dmgPath];
}
Expand Down
29 changes: 2 additions & 27 deletions packages/maker/dmg/test/MakerDMG_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ describe('MakerDMG', () => {
.load('../src/MakerDMG', {
'../../util/ensure-output': { ensureFile: ensureFileStub },
'electron-installer-dmg': eidStub,
'fs-extra': {
rename: renameStub,
},
}).default;
createMaker = async () => {
maker = new MakerDMG(config);
Expand All @@ -65,35 +62,13 @@ describe('MakerDMG', () => {
const opts = eidStub.firstCall.args[0];
expect(opts).to.deep.equal({
overwrite: true,
name: appName,
name: `${appName}-${packageJSON.version}-${targetArch}`,
appPath: path.resolve(`${dir}/My Test App.app`),
title: 'My Test App',
out: path.resolve(`${dir.substr(0, dir.length - 4)}/make`),
});
});

it('should attempt to rename the DMG file if no custom name is set', async () => {
await (maker.make as MakeFunction)({
dir,
makeDir,
appName,
targetArch,
packageJSON,
});
expect(renameStub.callCount).to.equal(1);
expect(renameStub.firstCall.args[1]).to.include(`1.2.3-${targetArch}`);
});

it('should rename the DMG file to include the version if no custom name is set', async () => {
await (maker.make as MakeFunction)({
dir,
makeDir,
appName,
targetArch,
packageJSON,
});
expect(renameStub.firstCall.args[1]).to.include(`1.2.3-${targetArch}`);
});

it('should not attempt to rename the DMG file if a custom name is set', async () => {
config.name = 'foobar';
await createMaker();
Expand Down