From f06401f51ad119da3d01b4dc5d5568a86e1f0a02 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Fri, 18 Oct 2024 09:37:40 -0600 Subject: [PATCH] Also use import when loading plugins --- src/lib/utils/plugins.ts | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/lib/utils/plugins.ts b/src/lib/utils/plugins.ts index 44bac97bf..3589241a7 100644 --- a/src/lib/utils/plugins.ts +++ b/src/lib/utils/plugins.ts @@ -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);