(archive: string)
| 11 | } |
| 12 | |
| 13 | export const verifyPackage = async (archive: string) => { |
| 14 | const directory = await mkdtemp(path.join(tmpdir(), "http-recorder-consumer-")) |
| 15 | try { |
| 16 | await writeFile( |
| 17 | path.join(directory, "package.json"), |
| 18 | JSON.stringify({ name: "http-recorder-consumer", private: true, type: "module" }), |
| 19 | ) |
| 20 | await writeFile( |
| 21 | path.join(directory, "consumer.ts"), |
| 22 | `import { HttpRecorder } from "@opencode-ai/http-recorder" |
| 23 | import { NodeSocket } from "@effect/platform-node" |
| 24 | import { Layer } from "effect" |
| 25 | import { HttpClient } from "effect/unstable/http" |
| 26 | import { Socket } from "effect/unstable/socket" |
| 27 | |
| 28 | const options: HttpRecorder.RecorderOptions = { redact: { jsonFields: ["access_token"] } } |
| 29 | HttpRecorder.http("consumer", options) satisfies Layer.Layer<HttpClient.HttpClient> |
| 30 | HttpRecorder.socket("consumer/socket", options).pipe( |
| 31 | Layer.provide(NodeSocket.layerWebSocket("wss://example.test")), |
| 32 | ) satisfies Layer.Layer<Socket.Socket> |
| 33 | `, |
| 34 | ) |
| 35 | await writeFile( |
| 36 | path.join(directory, "tsconfig.json"), |
| 37 | JSON.stringify({ |
| 38 | compilerOptions: { |
| 39 | target: "ES2022", |
| 40 | module: "NodeNext", |
| 41 | moduleResolution: "NodeNext", |
| 42 | strict: true, |
| 43 | noEmit: true, |
| 44 | // Required by effect@4.0.0-beta.74: its schema.d.ts references an undeclared SchemaErrorTypeId. |
| 45 | skipLibCheck: true, |
| 46 | lib: ["ES2022", "DOM", "ESNext.Disposable"], |
| 47 | }, |
| 48 | include: ["consumer.ts"], |
| 49 | }), |
| 50 | ) |
| 51 | |
| 52 | await run(["npm", "install", archive, "typescript@5.8.2"], directory) |
| 53 | await run( |
| 54 | [ |
| 55 | "node", |
| 56 | "--input-type=module", |
| 57 | "-e", |
| 58 | 'import("@opencode-ai/http-recorder").then((module) => { const root = Object.keys(module).sort(); const namespace = Object.keys(module.HttpRecorder).sort(); if (JSON.stringify(root) !== JSON.stringify(["HttpRecorder"])) throw new Error(`Unexpected root exports: ${root}`); if (JSON.stringify(namespace) !== JSON.stringify(["http", "socket"])) throw new Error(`Unexpected namespace exports: ${namespace}`) })', |
| 59 | ], |
| 60 | directory, |
| 61 | ) |
| 62 | await run([path.join(directory, "node_modules", ".bin", "tsc"), "--noEmit"], directory) |
| 63 | } finally { |
| 64 | await rm(directory, { recursive: true, force: true }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | if (import.meta.main) { |
| 69 | const archive = await pack() |
no test coverage detected