MCPcopy Index your code
hub / github.com/anomalyco/opencode / resolvePluginSpec

Function resolvePluginSpec

packages/opencode/src/config/plugin.ts:42–60  ·  view source on GitHub ↗
(
  plugin: ConfigPluginV1.Spec,
  configFilepath: string,
)

Source from the content-addressed store, hash-verified

40// Path-like specs are resolved relative to the config file that declared them so merges later on do not
41// accidentally reinterpret `./plugin.ts` relative to some other directory.
42export async function resolvePluginSpec(
43 plugin: ConfigPluginV1.Spec,
44 configFilepath: string,
45): Promise<ConfigPluginV1.Spec> {
46 const spec = pluginSpecifier(plugin)
47 if (!isPathPluginSpec(spec)) return plugin
48
49 const base = path.dirname(configFilepath)
50 const file = (() => {
51 if (spec.startsWith("file://")) return spec
52 if (path.isAbsolute(spec) || /^[A-Za-z]:[\\/]/.test(spec)) return pathToFileURL(spec).href
53 return pathToFileURL(path.resolve(base, spec)).href
54 })()
55
56 const resolved = await resolvePathPluginTarget(file).catch(() => file)
57
58 if (Array.isArray(plugin)) return [resolved, plugin[1]]
59 return resolved
60}
61
62// Dedupe on the load identity (package name for npm specs, exact file URL for local specs), but keep the
63// full Origin so downstream code still knows which config file won and where follow-up writes should go.

Callers

nothing calls this directly

Calls 3

isPathPluginSpecFunction · 0.90
resolvePathPluginTargetFunction · 0.90
pluginSpecifierFunction · 0.85

Tested by

no test coverage detected