Skip to content

Commit

Permalink
Also use import when loading plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Oct 18, 2024
1 parent 23f29f3 commit f06401f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/lib/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ export async function loadPlugins(
const pluginDisplay = getPluginDisplayName(plugin);

try {
let instance: any;
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
instance = require(plugin);
} catch (error: any) {
if (error.code === "ERR_REQUIRE_ESM") {
// On Windows, we need to ensure this path is a file path.
// Or we'll get ERR_UNSUPPORTED_ESM_URL_SCHEME
const esmPath = isAbsolute(plugin)
? pathToFileURL(plugin).toString()
: plugin;
instance = await import(esmPath);
} else {
throw error;
}
}
const initFunction = instance.load;
// On Windows, we need to ensure this path is a file path.
// Or we'll get ERR_UNSUPPORTED_ESM_URL_SCHEME
const esmPath = isAbsolute(plugin)
? pathToFileURL(plugin).toString()
: plugin;
let instance: any = await import(esmPath);
const initFunction = instance.load || instance.default?.load;

if (typeof initFunction === "function") {
await initFunction(app);
Expand Down

0 comments on commit f06401f

Please sign in to comment.