MCPcopy
hub / github.com/anomalyco/opencode / bundleInputs

Function bundleInputs

packages/client/test/import-boundaries.test.ts:33–63  ·  view source on GitHub ↗
(specifier: string, target: "browser" | "bun")

Source from the content-addressed store, hash-verified

31})
32
33async function bundleInputs(specifier: string, target: "browser" | "bun") {
34 const temporary = await mkdtemp(join(import.meta.dir, ".import-boundary-"))
35 const entrypoint = join(temporary, "index.ts")
36 const metafile = join(temporary, "meta.json")
37 try {
38 await Bun.write(entrypoint, `export * from ${JSON.stringify(specifier)}`)
39 const child = Bun.spawn(
40 [
41 process.execPath,
42 "build",
43 entrypoint,
44 `--target=${target}`,
45 "--format=esm",
46 "--packages=bundle",
47 `--metafile=${metafile}`,
48 `--outdir=${join(temporary, "out")}`,
49 ],
50 { cwd: directory, stdout: "pipe", stderr: "pipe" },
51 )
52 const [exitCode, stdout, stderr] = await Promise.all([
53 child.exited,
54 new Response(child.stdout).text(),
55 new Response(child.stderr).text(),
56 ])
57 if (exitCode !== 0) throw new Error(stdout + stderr)
58 const metadata = await Bun.file(metafile).json()
59 return Object.keys(metadata.inputs).map((input) => resolve(directory, input))
60 } finally {
61 await rm(temporary, { recursive: true, force: true })
62 }
63}
64
65function within(inputs: ReadonlyArray<string>, directory: string) {
66 const prefix = directory.endsWith(sep) ? directory : directory + sep

Callers 1

Calls 9

joinFunction · 0.85
writeMethod · 0.80
spawnMethod · 0.80
fileMethod · 0.80
textMethod · 0.65
jsonMethod · 0.65
resolveFunction · 0.50
rmFunction · 0.50
allMethod · 0.45

Tested by

no test coverage detected