(spec: string, target: string, kind: PluginKind, pkg?: PluginPackage)
| 134 | } |
| 135 | |
| 136 | async 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 | |
| 171 | export function isPathPluginSpec(spec: string) { |
| 172 | return spec.startsWith("file://") || spec.startsWith(".") || isAbsolutePath(spec) |
no test coverage detected