From 02981a74f19f60db76c997bb6ab81048dccab5ee Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 11:18:17 -0700 Subject: [PATCH 1/7] fix: Fixes loading scoped plugins to ensure name is preserved --- lib/plugin/factory.js | 11 ++++++++++- test/plugins.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/plugin/factory.js b/lib/plugin/factory.js index e262d481..f40ce542 100644 --- a/lib/plugin/factory.js +++ b/lib/plugin/factory.js @@ -22,6 +22,7 @@ const plugins = { }; const load = async pluginName => { + debugger; let plugin = null; try { const module = await import(pluginName); @@ -37,7 +38,15 @@ const load = async pluginName => { plugin = module.default; } } - return [path.parse(pluginName).name, plugin]; + return [getPluginName(pluginName), plugin]; +}; + +const getPluginName = pluginName => { + if (!pluginName.startsWith('@')) { + return path.parse(pluginName).name; + } + + return pluginName; }; export let getPlugins = async (config, container) => { diff --git a/test/plugins.js b/test/plugins.js index 78f787e4..729391de 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -121,6 +121,51 @@ 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 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.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')); From 611daa09aff94e7c6ac360091b5e2f1f7d7c6907 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 12:01:50 -0700 Subject: [PATCH 2/7] Inverting logic to only path.parse on relative paths --- lib/plugin/factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin/factory.js b/lib/plugin/factory.js index f40ce542..681af5a9 100644 --- a/lib/plugin/factory.js +++ b/lib/plugin/factory.js @@ -42,7 +42,7 @@ const load = async pluginName => { }; const getPluginName = pluginName => { - if (!pluginName.startsWith('@')) { + if (pluginName.startsWith('.')) { return path.parse(pluginName).name; } From b9338009c21020c394b4e6f2d45a063362f7e2be Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 13:03:48 -0700 Subject: [PATCH 3/7] Fixing tests --- test/plugins.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/plugins.js b/test/plugins.js index 729391de..c20b71e7 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -122,6 +122,8 @@ 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( @@ -131,6 +133,10 @@ test.serial('should instantiate plugins and execute all release-cycle methods fo 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`); From 8c52a73f43eb533a5216c7f5118b11ce747d2589 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 13:14:32 -0700 Subject: [PATCH 4/7] Removing debugger --- lib/plugin/factory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/plugin/factory.js b/lib/plugin/factory.js index 681af5a9..33de0277 100644 --- a/lib/plugin/factory.js +++ b/lib/plugin/factory.js @@ -22,7 +22,6 @@ const plugins = { }; const load = async pluginName => { - debugger; let plugin = null; try { const module = await import(pluginName); From 0893ed111cf58217a56793bad90f0885832e768d Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 13:26:16 -0700 Subject: [PATCH 5/7] Adding unit test for plugin name --- lib/plugin/factory.js | 2 +- test/plugin-name.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/plugin-name.js diff --git a/lib/plugin/factory.js b/lib/plugin/factory.js index 33de0277..8e6ed0c6 100644 --- a/lib/plugin/factory.js +++ b/lib/plugin/factory.js @@ -40,7 +40,7 @@ const load = async pluginName => { return [getPluginName(pluginName), plugin]; }; -const getPluginName = pluginName => { +export const getPluginName = pluginName => { if (pluginName.startsWith('.')) { return path.parse(pluginName).name; } 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'); +}); From 90a7c1ec61c5d7dfa437334219c244a83d88313c Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 13:32:48 -0700 Subject: [PATCH 6/7] Empty-Commit From b962c98189870cb9c95ce174505cc6ab459236c2 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Mon, 25 Jul 2022 13:48:26 -0700 Subject: [PATCH 7/7] Bumping timeout up for windows tests --- test/tasks.interactive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 => {