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(core): overrideTargets inherit the named maker config in the Forge config #1549

Merged
merged 4 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
});
});
});
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']);
}
}