pack.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { fileURLToPath } from "node:url"
  4. const dir = fileURLToPath(new URL("..", import.meta.url))
  5. export const pack = async () => {
  6. process.chdir(dir)
  7. await $`bun run build`
  8. const original = await Bun.file("package.json").text()
  9. // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- package.json is validated by the package schema and build checks.
  10. const pkg = JSON.parse(original) as {
  11. readonly version: string
  12. exports: Record<string, string | { readonly import: string; readonly types: string }>
  13. }
  14. for (const [key, value] of Object.entries(pkg.exports)) {
  15. if (key === "./internal") {
  16. delete pkg.exports[key]
  17. continue
  18. }
  19. if (typeof value !== "string") continue
  20. const file = value.replace("./src/", "./dist/").replace(/\.ts$/, "")
  21. pkg.exports[key] = { import: `${file}.js`, types: `${file}.d.ts` }
  22. }
  23. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  24. try {
  25. await $`bun pm pack`
  26. return fileURLToPath(new URL(`../opencode-ai-http-recorder-${pkg.version}.tgz`, import.meta.url))
  27. } finally {
  28. await Bun.write("package.json", original)
  29. }
  30. }
  31. if (import.meta.main) await pack()