feat(plugins): add support for loading ESM plugins (#2688)
Co-authored-by: Matt Travi <programmer@travi.org> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
This commit is contained in:
co-authored by
Gregor Martynus
parent
5df624c6e5
commit
d170f73e0b
+10
-6
@@ -52,14 +52,18 @@ export async function loadPlugin({cwd}, name, pluginsPath) {
|
||||
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
|
||||
: __dirname;
|
||||
|
||||
if (!isFunction(name)) {
|
||||
const file = resolveFrom.silent(basePath, name) || resolveFrom(cwd, name);
|
||||
// See https://github.com/mysticatea/eslint-plugin-node/issues/250
|
||||
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
||||
name = (await import(`file://${file}`)).default;
|
||||
if (isFunction(name)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return name;
|
||||
const file = resolveFrom.silent(basePath, name) || resolveFrom(cwd, name);
|
||||
const { default: cjsExport, ...esmNamedExports } = await import(`file://${file}`);
|
||||
|
||||
if (cjsExport) {
|
||||
return cjsExport;
|
||||
}
|
||||
|
||||
return esmNamedExports;
|
||||
}
|
||||
|
||||
export function parseConfig(plugin) {
|
||||
|
||||
Reference in New Issue
Block a user