Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes loading scoped plugins to ensure name is preserved #926

Merged
merged 7 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/plugin/factory.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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