fix: correctly resolve plugins installed globally with npx

This bug affects only plugins defined with the `plugins` option and wrapped in an Array to add a configuration
This commit is contained in:
Pierre Vanduynslager 2018-11-26 18:27:51 -05:00
parent 2b082acc73
commit eafbb343dd
2 changed files with 19 additions and 12 deletions

View File

@ -6,6 +6,7 @@ const debug = require('debug')('semantic-release:config');
const {repoUrl} = require('./git'); const {repoUrl} = require('./git');
const PLUGINS_DEFINITIONS = require('./definitions/plugins'); const PLUGINS_DEFINITIONS = require('./definitions/plugins');
const plugins = require('./plugins'); const plugins = require('./plugins');
const {validatePlugin, parseConfig} = require('./plugins/utils');
const CONFIG_NAME = 'release'; const CONFIG_NAME = 'release';
const CONFIG_FILES = [ const CONFIG_FILES = [
@ -37,17 +38,21 @@ module.exports = async (context, opts) => {
// For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path, // For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path,
// so those plugin will be loaded relatively to the config file // so those plugin will be loaded relatively to the config file
Object.entries(extendsOpts).reduce((pluginsPath, [option, value]) => { Object.entries(extendsOpts)
if (PLUGINS_DEFINITIONS[option] || option === 'plugins') { .filter(([, value]) => Boolean(value))
castArray(value) .reduce((pluginsPath, [option, value]) => {
.filter(plugin => isString(plugin) || (isPlainObject(plugin) && isString(plugin.path))) castArray(value).forEach(plugin => {
.map(plugin => (isString(plugin) ? plugin : plugin.path)) if (option === 'plugins' && validatePlugin(plugin)) {
.forEach(plugin => { pluginsPath[parseConfig(plugin)[0]] = extendPath;
pluginsPath[plugin] = extendPath; } else if (
}); PLUGINS_DEFINITIONS[option] &&
} (isString(plugin) || (isPlainObject(plugin) && isString(plugin.path)))
return pluginsPath; ) {
}, pluginsPath); pluginsPath[isString(plugin) ? plugin : plugin.path] = extendPath;
}
});
return pluginsPath;
}, pluginsPath);
return {...result, ...extendsOpts}; return {...result, ...extendsOpts};
}, {}), }, {}),

View File

@ -212,7 +212,7 @@ test('Read configuration from file path in "extends"', async t => {
branch: 'test_branch', branch: 'test_branch',
repositoryUrl: 'https://host.null/owner/module.git', repositoryUrl: 'https://host.null/owner/module.git',
tagFormat: `v\${version}`, tagFormat: `v\${version}`,
plugins: false, plugins: ['plugin-1', ['plugin-2', {plugin2Opt: 'value'}]],
}; };
// Create package.json and shareable.json in repository root // Create package.json and shareable.json in repository root
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions}); await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
@ -227,6 +227,8 @@ test('Read configuration from file path in "extends"', async t => {
t.deepEqual(t.context.plugins.args[0][1], { t.deepEqual(t.context.plugins.args[0][1], {
analyzeCommits: './shareable.json', analyzeCommits: './shareable.json',
generateNotes: './shareable.json', generateNotes: './shareable.json',
'plugin-1': './shareable.json',
'plugin-2': './shareable.json',
}); });
}); });