Skip to content
Permalink
Browse files

fix(core): makers, publishers and plugins should be resolved relative…

… to current dir not install dir
  • Loading branch information
MarshallOfSound committed Jul 5, 2018
1 parent bdaf564 commit 74e6ac8d1652c81008a003c246a4a3f136156482
@@ -13,11 +13,14 @@ import { readMutatedPackageJson } from '../util/read-package-json';
import resolveDir from '../util/resolve-dir';
import getCurrentOutDir from '../util/out-dir';
import getElectronVersion from '../util/electron-version';
import requireSearch from '../util/require-search';

import packager from './package';

const { hostArch } = require('electron-packager/targets');

class MakerImpl extends MakerBase<any> { name = 'impl'; defaultPlatforms = []; };

export interface MakeOptions {
/**
* The path to the app from which distrubutables are generated
@@ -98,16 +101,12 @@ export default async ({
if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue;
} else {
const resolvableTarget: IForgeResolvableMaker = target as IForgeResolvableMaker;
let makerModule;
try {
makerModule = require(resolvableTarget.name);
} catch (err) {
console.error(err);
const MakerClass = requireSearch<typeof MakerImpl>(dir, [resolvableTarget.name]);
if (!MakerClass) {
throw `Could not find module with name: ${resolvableTarget.name}`;
}

const MakerClass = makerModule.default || makerModule;
maker = new MakerClass(resolvableTarget.config, resolvableTarget.platforms);
maker = new MakerClass(resolvableTarget.config, resolvableTarget.platforms || undefined);
if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue;
}

@@ -13,6 +13,7 @@ import PublishState from '../util/publish-state';
import getCurrentOutDir from '../util/out-dir';

import make, { MakeOptions } from './make';
import requireSearch from '../util/require-search';

const d = debug('electron-forge:publish');

@@ -149,17 +150,14 @@ const publish = async ({
publisher = publishTarget as any;
} else {
const resolvablePublishTarget = publishTarget as IForgeResolvablePublisher;
let publisherModule: any;
let PublisherClass: any;
await asyncOra(`Resolving publish target: ${`${resolvablePublishTarget.name}`.cyan}`, async () => { // eslint-disable-line no-loop-func
try {
publisherModule = require(resolvablePublishTarget.name);
} catch (err) {
console.error(err);
PublisherClass = requireSearch(dir, [resolvablePublishTarget.name]);
if (!PublisherClass) {
throw `Could not find a publish target with the name: ${resolvablePublishTarget.name}`;
}
});

const PublisherClass = publisherModule.default || publisherModule;
publisher = new PublisherClass(resolvablePublishTarget.config || {}, resolvablePublishTarget.platforms);
}

@@ -1,9 +1,10 @@
import { asyncOra } from '@electron-forge/async-ora';
import PluginBase from '@electron-forge/plugin-base';
import { IForgePluginInterface, ForgeConfig, IForgePlugin } from '@electron-forge/shared-types';
import { ChildProcess } from 'child_process';
import debug from 'debug';

import { StartOptions } from '../api';
import requireSearch from './require-search';

const d = debug('electron-forge:plugins');

@@ -23,8 +24,10 @@ export default class PluginInterface implements IForgePluginInterface {
}
let opts = {};
if (typeof plugin[1] !== 'undefined') opts = plugin[1];
const pluginModule = require(plugin[0]);
const Plugin = pluginModule.default || pluginModule;
const Plugin = requireSearch<any>(dir, [plugin[0]]);
if (!Plugin) {
throw `Could not find module with name: ${plugin[0]}`;
}
return new Plugin(opts);
}
throw `Expected plugin to either be a plugin instance or [string, object] but found ${plugin}`; // eslint-disable-line
@@ -42,9 +42,16 @@ describe('publish', () => {
config.publishers = publishers;
return config;
},
'@electron-forge/publisher-test': fakePublisher(publisherSpy),
void: fakePublisher(voidStub),
nowhere: fakePublisher(nowhereStub),
'../util/require-search': (_: string, [name]: [string]) => {
if (name === 'void') {
return fakePublisher(voidStub);
} else if (name === 'nowhere') {
return fakePublisher(nowhereStub);
} else if (name === '@electron-forge/publisher-test') {
return fakePublisher(publisherSpy);
}
return null;
},
}).default;

publisherSpy.returns(Promise.resolve());

0 comments on commit 74e6ac8

Please sign in to comment.
You can’t perform that action at this time.