build.ts 830 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { readdir, rm } from "node:fs/promises"
  4. await rm("dist", { recursive: true, force: true })
  5. await $`bunx tsc --emitDeclarationOnly`
  6. const build = await Bun.build({
  7. entrypoints: ["src/index.ts"],
  8. outdir: "dist",
  9. target: "node",
  10. format: "esm",
  11. packages: "external",
  12. })
  13. if (!build.success) throw new AggregateError(build.logs, "Failed to build @opencode-ai/http-recorder")
  14. await Promise.all(
  15. (await readdir("dist", { recursive: true }))
  16. .filter((file) => file.endsWith(".d.ts") && file !== "index.d.ts" && file !== "api.d.ts")
  17. .map((file) => rm(`dist/${file}`)),
  18. )
  19. for (const file of ["dist/index.d.ts", "dist/api.d.ts"]) {
  20. if ((await Bun.file(file).text()).includes(["import", "("].join("")))
  21. throw new Error(`${file} contains dynamic import syntax`)
  22. }