diff --git a/lib/plugin/factory.js b/lib/plugin/factory.js index e262d481..8e6ed0c6 100644 --- a/lib/plugin/factory.js +++ b/lib/plugin/factory.js @@ -37,7 +37,15 @@ const load = async pluginName => { plugin = module.default; } } - return [path.parse(pluginName).name, plugin]; + return [getPluginName(pluginName), plugin]; +}; + +export const getPluginName = pluginName => { + if (pluginName.startsWith('.')) { + return path.parse(pluginName).name; + } + + return pluginName; }; export let getPlugins = async (config, container) => { diff --git a/test/plugin-name.js b/test/plugin-name.js new file mode 100644 index 00000000..5b2f1bdf --- /dev/null +++ b/test/plugin-name.js @@ -0,0 +1,9 @@ +import test from 'ava'; +import { getPluginName } from '../lib/plugin/factory.js'; + +test('pluginName can return correct name for variants', t => { + t.is(getPluginName('plain-plugin'), 'plain-plugin'); + t.is(getPluginName('@some/scoped-plugin'), '@some/scoped-plugin'); + t.is(getPluginName('@some/nested/scoped-plugin'), '@some/nested/scoped-plugin'); + t.is(getPluginName('./relative-plugin.cjs'), 'relative-plugin'); +}); diff --git a/test/plugins.js b/test/plugins.js index 78f787e4..c20b71e7 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -121,6 +121,57 @@ test.serial('should instantiate plugins and execute all release-cycle methods', }); }); +test.serial('should instantiate plugins and execute all release-cycle methods for scoped plugins', async t => { + const { dir } = t.context; + + const pluginDir = mkTmpDir(); + sh.pushd('-q', pluginDir); + sh.ShellString(JSON.stringify({ name: '@scoped/my-plugin', version: '1.0.0', type: 'module' })).toEnd( + join(pluginDir, 'package.json') + ); + sh.exec(`npm link release-it`); + const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;'; + sh.ShellString(content).toEnd(join(pluginDir, 'index.js')); + + sh.pushd('-q', dir); + sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' })).toEnd( + join(dir, 'package.json') + ); + sh.exec(`npm install ${pluginDir}`); + sh.exec(`npm link release-it`); + + const config = { + plugins: { + '@scoped/my-plugin': { + name: 'foo' + } + } + }; + const container = getContainer(config); + + const result = await runTasks({}, container); + + t.deepEqual(container.log.info.args, [ + ['@scoped/my-plugin:foo:init'], + ['@scoped/my-plugin:foo:getName'], + ['@scoped/my-plugin:foo:getLatestVersion'], + ['@scoped/my-plugin:foo:getIncrement'], + ['@scoped/my-plugin:foo:getIncrementedVersionCI'], + ['@scoped/my-plugin:foo:beforeBump'], + ['@scoped/my-plugin:foo:bump:1.3.0'], + ['@scoped/my-plugin:foo:beforeRelease'], + ['@scoped/my-plugin:foo:release'], + ['@scoped/my-plugin:foo:afterRelease'] + ]); + + t.deepEqual(result, { + changelog: undefined, + name: 'new-project-name', + latestVersion: '1.2.3', + version: '1.3.0' + }); +}); + test.serial('should disable core plugins', async t => { const { dir } = t.context; sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0' })).toEnd(join(dir, 'package.json')); diff --git a/test/tasks.interactive.js b/test/tasks.interactive.js index cbdbefd8..19c77188 100644 --- a/test/tasks.interactive.js +++ b/test/tasks.interactive.js @@ -60,7 +60,7 @@ const getHooks = plugins => { }; test.before(t => { - t.timeout(60 * 1000); + t.timeout(90 * 1000); }); test.serial.beforeEach(t => {