Skip to content

Commit

Permalink
fix(core): overrideTargets inherit the named maker config in the Forg…
Browse files Browse the repository at this point in the history
…e config (#1549)
  • Loading branch information
malept authored Mar 7, 2020
1 parent da229e8 commit e133b60
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ class MakerImpl extends MakerBase<any> {
defaultPlatforms = [];
}

type MakeTarget = IForgeResolvableMaker | MakerBase<any> | string;

function generateTargets(forgeConfig: ForgeConfig, overrideTargets?: MakeTarget[]) {
if (overrideTargets) {
return overrideTargets.map((target) => {
if (typeof target === 'string') {
return forgeConfig.makers.find(
(maker) => (maker as IForgeResolvableMaker).name === target,
) || { name: target };
}

return target;
});
}
return forgeConfig.makers;
}

export interface MakeOptions {
/**
* The path to the app from which distrubutables are generated
Expand All @@ -42,7 +59,7 @@ export interface MakeOptions {
/**
* An array of make targets to override your forge config
*/
overrideTargets?: (IForgeResolvableMaker | MakerBase<any>)[];
overrideTargets?: MakeTarget[];
/**
* The target architecture
*/
Expand Down Expand Up @@ -90,12 +107,8 @@ export default async ({
const makers: {
[key: number]: MakerBase<any>;
} = {};
let targets = (overrideTargets || forgeConfig.makers).map((target) => {
if (typeof target === 'string') {
return { name: target };
}
return target;
});

let targets = generateTargets(forgeConfig, overrideTargets);

let targetId = 0;
for (const target of targets) {
Expand Down
31 changes: 31 additions & 0 deletions packages/api/core/test/fast/make_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from 'chai';
import * as path from 'path';
import proxyquire from 'proxyquire';

import { MakeOptions } from '../../src/api';

describe('make', () => {
let make: (opts: MakeOptions) => Promise<any[]>;
beforeEach(() => {
const electronPath = path.resolve(__dirname, 'node_modules/electron');
make = proxyquire.noCallThru().load('../../src/api/make', {
'../util/electron-version': {
getElectronModulePath: () => Promise.resolve(electronPath),
getElectronVersion: () => Promise.resolve('1.0.0'),
},
}).default;
});
describe('overrideTargets inherits from forge config', () => {
it('passes config properly', async () => {
const results = await make({
arch: 'x64',
dir: path.resolve(__dirname, '..', 'fixture', 'app-with-custom-maker-config'),
overrideTargets: ['../custom-maker'],
platform: 'linux',
skipPackage: true,
});

expect(results[0].artifacts).to.deep.equal(['from config']);
});
});
});
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "test",
"config": {
"forge": {
"makers": [
{
"name": "../custom-maker",
"config": {
"artifactPath": "from config"
}
},
{
"name": "@electron-forge/non-existent-forge-maker"
}
]
}
},
"devDependencies": {
"electron": "^1.0.0"
}
}
20 changes: 20 additions & 0 deletions packages/api/core/test/fixture/custom-maker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ForgePlatform } from '@electron-forge/shared-types';
import MakerBase from '@electron-forge/maker-base';

interface Config {
artifactPath: string;
}

export default class Maker extends MakerBase<Config> {
name = 'custom-maker';

defaultPlatforms = ['linux'] as ForgePlatform[];

isSupportedOnCurrentPlatform() {
return true;
}

async make() {
return Promise.resolve([this.config.artifactPath || 'default']);
}
}

0 comments on commit e133b60

Please sign in to comment.