Skip to content

Commit

Permalink
Normalize plugin loader
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 30, 2021
1 parent 9516010 commit 38dabbe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/plugin/factory.js
Expand Up @@ -8,7 +8,7 @@ import GitLab from './gitlab/GitLab.js';
import GitHub from './github/GitHub.js';
import npm from './npm/npm.js';

const require = createRequire(import.meta.url);
const requireCwd = createRequire(process.cwd());

const debug = _debug('release-it:plugins');

Expand All @@ -25,11 +25,17 @@ const plugins = {
const load = async pluginName => {
let plugin = null;
try {
const module = await import(require.resolve(pluginName));
const module = await import(pluginName);
plugin = module.default;
} catch (err) {
const module = await import(require.resolve(path.resolve(pluginName)));
plugin = module.default;
try {
const module = await import(path.join(process.cwd(), pluginName));
plugin = module.default;
} catch (err) {
// In some cases or tests we might need to support "directory imports" (legacy `require`)
const module = await import(requireCwd.resolve(path.join(process.cwd(), pluginName)));
plugin = module.default;
}
}
return [path.parse(pluginName).name, plugin];
};
Expand Down

0 comments on commit 38dabbe

Please sign in to comment.