MCPcopy Create free account
hub / github.com/anomalyco/opencode / verifyPackage

Function verifyPackage

packages/http-recorder/script/verify-package.ts:13–66  ·  view source on GitHub ↗
(archive: string)

Source from the content-addressed store, hash-verified

11}
12
13export 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"
23import { NodeSocket } from "@effect/platform-node"
24import { Layer } from "effect"
25import { HttpClient } from "effect/unstable/http"
26import { Socket } from "effect/unstable/socket"
27
28const options: HttpRecorder.RecorderOptions = { redact: { jsonFields: ["access_token"] } }
29HttpRecorder.http("consumer", options) satisfies Layer.Layer<HttpClient.HttpClient>
30HttpRecorder.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
68if (import.meta.main) {
69 const archive = await pack()

Callers 1

verify-package.tsFile · 0.85

Calls 3

runFunction · 0.70
tmpdirFunction · 0.50
rmFunction · 0.50

Tested by

no test coverage detected