Load plugins installed from npm by package name

Plugins installed from npm are listed by package name, but the plugin
loader joined that name onto the main and entrypoint paths and imported
the result as a file, which resolves relative to the working directory.
Every npm installed plugin then failed to load. Resolve these paths from
the directory of the plugin's package.json instead.
This commit is contained in:
Danielv123 committed 2026-10-11 13:22:14 +02:00
1 parent b411c5bef8
commit 6e36c02ade
2 files changed
+46 -3

No files matched your search

+3 -2
View File
@@ -51,8 +51,9 @@ export async function loadPluginInfos(pluginList: Map<string, string>) {
try {
pluginPackage = (await import(pathToFileURL(packagePath).href, { with: { type: "json" }})).default;
// pluginPath is a package name for plugins installed from npm, so resolve from the package itself
pluginInfo = (await import(
pathToFileURL(path.posix.join(pluginPath, pluginPackage.main ?? "index.js")).href
pathToFileURL(path.join(path.dirname(packagePath), pluginPackage.main ?? "index.js")).href
)).plugin;
} catch (err: any) {
if (err.code === "InstallationError") {
@@ -106,7 +107,7 @@ export async function loadPlugin<
return;
}
const module = await import(pathToFileURL(path.posix.join(pluginInfo.requirePath, requirePath)).href);
const module = await import(pathToFileURL(path.join(path.dirname(pluginInfo.packagePath), requirePath)).href);
const pluginContext: libPlugin.PluginLoadContext<Context> = {
...context,
plugin: pluginInfo,