From f37476bfe8906be77144f4f5dbeb5435b7908003 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 10 Sep 2018 12:54:04 +1000 Subject: [PATCH] fix(core): resolve publisher config correctly when given a publisher name (#568) Fixes #541 --- packages/api/core/src/api/publish.ts | 8 +++++- packages/api/core/test/fast/publish_spec.ts | 31 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/api/core/src/api/publish.ts b/packages/api/core/src/api/publish.ts index 3d1f838dfa..4d52558623 100644 --- a/packages/api/core/src/api/publish.ts +++ b/packages/api/core/src/api/publish.ts @@ -140,7 +140,13 @@ const publish = async ({ // .filter(publisher => (typeof publisher !== 'string' && publisher.platforms) ? publisher.platforms.indexOf(testPlatform) !== -1 : true); } publishTargets = publishTargets.map((target) => { - if (typeof target === 'string') return { name: target }; + if (typeof target === 'string') { + return (forgeConfig.publishers || []).find((p) => { + if (typeof p === 'string') return false; + if ((p as IForgePublisher).__isElectronForgePublisher) return false; + return (p as IForgeResolvablePublisher).name === target; + }) || { name: target }; + } return target; }) as (IForgeResolvablePublisher | IForgePublisher)[]; diff --git a/packages/api/core/test/fast/publish_spec.ts b/packages/api/core/test/fast/publish_spec.ts index 75f58b0db0..3ea0e88ddc 100644 --- a/packages/api/core/test/fast/publish_spec.ts +++ b/packages/api/core/test/fast/publish_spec.ts @@ -14,7 +14,8 @@ describe('publish', () => { let publisherSpy: SinonStub; let voidStub: SinonStub; let nowhereStub: SinonStub; - let publishers: string[]; + let publishers: any[]; + let fooPublisher: { name: string, providedConfig: any }; beforeEach(() => { resolveStub = sinon.stub(); @@ -23,9 +24,11 @@ describe('publish', () => { voidStub = sinon.stub(); nowhereStub = sinon.stub(); publishers = ['@electron-forge/publisher-test']; - const fakePublisher = (stub: SinonStub) => class { + const fakePublisher = (stub: SinonStub, name: string = 'default') => class X { private publish: SinonStub; - constructor() { + public name = name; + constructor(public providedConfig: any) { + fooPublisher = this; this.publish = stub; } }; @@ -52,6 +55,9 @@ describe('publish', () => { if (name === '@electron-forge/publisher-test') { return fakePublisher(publisherSpy); } + if (name === '@electron-forge/publisher-foo') { + return fakePublisher(publisherSpy, name); + } return null; }, }).default; @@ -69,6 +75,25 @@ describe('publish', () => { expect(makeStub.callCount).to.equal(1); }); + it('should resolve publishers from the forge config if provided', async () => { + publishers = [{ + name: 'bad', + config: 'foo', + }, { + name: '@electron-forge/publisher-foo', + config: 'resolved', + }]; + await publish({ + dir: __dirname, + interactive: false, + publishTargets: ['@electron-forge/publisher-foo'], + }); + expect(publisherSpy.callCount).to.equal(1); + + expect(fooPublisher.name).to.equal('@electron-forge/publisher-foo'); + expect(fooPublisher.providedConfig).to.equal('resolved'); + }); + it('should call the resolved publisher with the appropriate args', async () => { makeStub.returns([{ artifacts: ['artifact1', 'artifact2'] }]); await publish({