diff options
| author | Luke Parker <[email protected]> | 2026-02-24 22:20:57 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-24 22:20:57 +1000 |
| commit | 1af3e9e557a6df4f933a01d0dad2e52e418ebd52 (patch) | |
| tree | d08abf85b5ff476750abf3d8ca3994e87699643e /packages | |
| parent | a292eddeb516ebf1774e68640b4c62ad284472b2 (diff) | |
| download | opencode-1af3e9e557a6df4f933a01d0dad2e52e418ebd52.tar.gz opencode-1af3e9e557a6df4f933a01d0dad2e52e418ebd52.zip | |
fix(win32): fix plugin resolution with createRequire fallback (#14898)
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/config/config.ts | 15 | ||||
| -rw-r--r-- | packages/opencode/test/config/config.test.ts | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index aad0fd76c..71cf43d6d 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -1,6 +1,7 @@ import { Log } from "../util/log" import path from "path" -import { pathToFileURL } from "url" +import { pathToFileURL, fileURLToPath } from "url" +import { createRequire } from "module" import os from "os" import z from "zod" import { Filesystem } from "../util/filesystem" @@ -276,7 +277,6 @@ export namespace Config { "@opencode-ai/plugin": targetVersion, } await Filesystem.writeJson(pkg, json) - await new Promise((resolve) => setTimeout(resolve, 3000)) const gitignore = path.join(dir, ".gitignore") const hasGitIgnore = await Filesystem.exists(gitignore) @@ -1332,7 +1332,16 @@ export namespace Config { const plugin = data.plugin[i] try { data.plugin[i] = import.meta.resolve!(plugin, options.path) - } catch (err) {} + } catch (e) { + try { + // import.meta.resolve sometimes fails with newly created node_modules + const require = createRequire(options.path) + const resolvedPath = require.resolve(plugin) + data.plugin[i] = pathToFileURL(resolvedPath).href + } catch { + // Ignore, plugin might be a generic string identifier like "mcp-server" + } + } } } return data diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 56773570a..2b1ba816e 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -689,7 +689,7 @@ test("resolves scoped npm plugins in config", async () => { const pluginEntries = config.plugin ?? [] const baseUrl = pathToFileURL(path.join(tmp.path, "opencode.json")).href - const expected = import.meta.resolve("@scope/plugin", baseUrl) + const expected = pathToFileURL(path.join(tmp.path, "node_modules", "@scope", "plugin", "index.js")).href expect(pluginEntries.includes(expected)).toBe(true) |
