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

Function resolvePluginEntrypoint

packages/opencode/src/plugin/shared.ts:136–169  ·  view source on GitHub ↗
(spec: string, target: string, kind: PluginKind, pkg?: PluginPackage)

Source from the content-addressed store, hash-verified

134}
135
136async function resolvePluginEntrypoint(spec: string, target: string, kind: PluginKind, pkg?: PluginPackage) {
137 const source = pluginSource(spec)
138 const hit =
139 pkg ?? (source === "npm" ? await readPluginPackage(target) : await readPluginPackage(target).catch(() => undefined))
140 if (!hit) return target
141
142 const entry = resolvePackageEntrypoint(spec, kind, hit)
143 if (entry) return entry
144
145 const dir = await resolveTargetDirectory(target)
146
147 if (kind === "tui") {
148 if (source === "file" && dir) {
149 const index = await resolveDirectoryIndex(dir)
150 if (index) return pathToFileURL(index).href
151 }
152
153 if (source === "npm") return
154 if (dir) return
155
156 return target
157 }
158
159 if (dir && isRecord(hit.json.exports)) {
160 if (source === "file") {
161 const index = await resolveDirectoryIndex(dir)
162 if (index) return pathToFileURL(index).href
163 }
164
165 return
166 }
167
168 return target
169}
170
171export function isPathPluginSpec(spec: string) {
172 return spec.startsWith("file://") || spec.startsWith(".") || isAbsolutePath(spec)

Callers 1

createPluginEntryFunction · 0.85

Calls 6

isRecordFunction · 0.90
pluginSourceFunction · 0.85
readPluginPackageFunction · 0.85
resolvePackageEntrypointFunction · 0.85
resolveTargetDirectoryFunction · 0.85
resolveDirectoryIndexFunction · 0.85

Tested by

no test coverage detected