Skip to content

Commit

Permalink
Fixes loading scoped plugins to ensure name is preserved (#926)
Browse files Browse the repository at this point in the history
* fix: Fixes loading scoped plugins to ensure name is preserved

* Inverting logic to only path.parse on relative paths

* Fixing tests

* Removing debugger

* Adding unit test for plugin name

* Empty-Commit

* Bumping timeout up for windows tests
  • Loading branch information
scalvert committed Jul 26, 2022
1 parent ce3a726 commit 145fc71
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/plugin/factory.js
Expand Up @@ -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) => {
Expand Down
9 changes: 9 additions & 0 deletions 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');
});
51 changes: 51 additions & 0 deletions test/plugins.js
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion test/tasks.interactive.js
Expand Up @@ -60,7 +60,7 @@ const getHooks = plugins => {
};

test.before(t => {
t.timeout(60 * 1000);
t.timeout(90 * 1000);
});

test.serial.beforeEach(t => {
Expand Down

0 comments on commit 145fc71

Please sign in to comment.