( mod: Record<string, unknown>, spec: string, kind: PluginKind, mode: PluginMode = "strict", )
| 270 | } |
| 271 | |
| 272 | export function readV1Plugin( |
| 273 | mod: Record<string, unknown>, |
| 274 | spec: string, |
| 275 | kind: PluginKind, |
| 276 | mode: PluginMode = "strict", |
| 277 | ) { |
| 278 | const value = mod.default |
| 279 | if (!isRecord(value)) { |
| 280 | if (mode === "detect") return |
| 281 | throw new TypeError(`Plugin ${spec} must default export an object with ${kind}()`) |
| 282 | } |
| 283 | if (mode === "detect" && !("id" in value) && !("server" in value) && !("tui" in value)) return |
| 284 | |
| 285 | const server = "server" in value ? value.server : undefined |
| 286 | const tui = "tui" in value ? value.tui : undefined |
| 287 | if (server !== undefined && typeof server !== "function") { |
| 288 | throw new TypeError(`Plugin ${spec} has invalid server export`) |
| 289 | } |
| 290 | if (tui !== undefined && typeof tui !== "function") { |
| 291 | throw new TypeError(`Plugin ${spec} has invalid tui export`) |
| 292 | } |
| 293 | if (server !== undefined && tui !== undefined) { |
| 294 | throw new TypeError(`Plugin ${spec} must default export either server() or tui(), not both`) |
| 295 | } |
| 296 | if (kind === "server" && server === undefined) { |
| 297 | throw new TypeError(`Plugin ${spec} must default export an object with server()`) |
| 298 | } |
| 299 | if (kind === "tui" && tui === undefined) { |
| 300 | throw new TypeError(`Plugin ${spec} must default export an object with tui()`) |
| 301 | } |
| 302 | |
| 303 | return value |
| 304 | } |
| 305 | |
| 306 | export async function resolvePluginId( |
| 307 | source: PluginSource, |
no test coverage detected