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

refactor: rename some constructor params for MakerBase and PublisherBase #2994

Merged
merged 1 commit into from
Oct 26, 2022
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
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/maker/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"typings": "dist/Maker.d.ts",
"devDependencies": {
"chai": "^4.3.3",
"mocha": "^9.0.1"
"mocha": "^9.0.1",
"sinon": "^13.0.1"
},
"engines": {
"node": ">= 14.17.5"
Expand Down
14 changes: 9 additions & 5 deletions packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export default abstract class Maker<C> implements IForgeMaker {
/** @internal */
__isElectronForgeMaker!: true;

constructor(private configFetcher: C | ((arch: ForgeArch) => C) = {} as C, protected providedPlatforms?: ForgePlatform[]) {
/**
* @param configOrConfigFetcher - Either a configuration object for this maker or a simple method that returns such a configuration for a given target architecture
* @param platformsToMakeOn - If you want this maker to run on platforms different from `defaultPlatforms` you can provide those platforms here
*/
constructor(private configOrConfigFetcher: C | ((arch: ForgeArch) => C) = {} as C, protected platformsToMakeOn?: ForgePlatform[]) {
Object.defineProperty(this, '__isElectronForgeMaker', {
value: true,
enumerable: false,
Expand All @@ -58,17 +62,17 @@ export default abstract class Maker<C> implements IForgeMaker {
}

get platforms(): ForgePlatform[] {
if (this.providedPlatforms) return this.providedPlatforms;
if (this.platformsToMakeOn) return this.platformsToMakeOn;
return this.defaultPlatforms;
}

// TODO: Remove this, it is an eye-sore and is a nasty hack to provide forge
// v5 style functionality in the new API
prepareConfig(targetArch: ForgeArch): void {
if (typeof this.configFetcher === 'function') {
this.config = (this.configFetcher as unknown as (arch: ForgeArch) => C)(targetArch);
if (typeof this.configOrConfigFetcher === 'function') {
this.config = (this.configOrConfigFetcher as unknown as (arch: ForgeArch) => C)(targetArch);
} else {
this.config = this.configFetcher as C;
this.config = this.configOrConfigFetcher as C;
}
}

Expand Down
42 changes: 42 additions & 0 deletions packages/maker/base/test/config-fetcher_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import { stub } from 'sinon';

import MakerBase from '../src/Maker';

class MakerImpl extends MakerBase<{ a: number }> {
name = 'test';

defaultPlatforms = [];
}

describe('prepareConfig', () => {
it('should call the provided configure function', () => {
const fetcher = stub();
fetcher.returns({
a: 123,
});
const maker = new MakerImpl(fetcher, []);
expect(maker.config).to.be.undefined;
expect(fetcher.callCount).to.equal(0);
maker.prepareConfig('x64');
expect(maker.config).to.deep.equal({
a: 123,
});
expect(fetcher.callCount).to.equal(1);
expect(fetcher.firstCall.args).to.deep.equal(['x64']);
});

it('should hand through the provided object', () => {
const maker = new MakerImpl(
{
a: 234,
},
[]
);
expect(maker.config).to.be.undefined;
maker.prepareConfig('x64');
expect(maker.config).to.deep.equal({
a: 234,
});
});
});
8 changes: 6 additions & 2 deletions packages/publisher/base/src/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export default abstract class Publisher<C> implements IForgePublisher {
/** @internal */
__isElectronForgePublisher!: true;

constructor(public config: C, protected providedPlatforms?: ForgePlatform[]) {
/**
* @param config - A configuration object for this publisher
* @param platformsToPublishOn - If you want this maker to run on platforms different from `defaultPlatforms` you can provide those platforms here
*/
constructor(public config: C, protected platformsToPublishOn?: ForgePlatform[]) {
this.config = config;
Object.defineProperty(this, '__isElectronForgePublisher', {
value: true,
Expand All @@ -35,7 +39,7 @@ export default abstract class Publisher<C> implements IForgePublisher {
}

get platforms(): ForgePlatform[] {
if (this.providedPlatforms) return this.providedPlatforms;
if (this.platformsToPublishOn) return this.platformsToPublishOn;
if (this.defaultPlatforms) return this.defaultPlatforms;
return ['win32', 'linux', 'darwin', 'mas'];
}
Expand Down