bundle.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bun
  2. import solidPlugin from "./node_modules/@opentui/solid/scripts/solid-plugin"
  3. import path from "path"
  4. import fs from "fs"
  5. const dir = process.cwd()
  6. const parser = fs.realpathSync(path.join(dir, "node_modules/@opentui/core/parser.worker.js"))
  7. const worker = "./src/cli/cmd/tui/worker.ts"
  8. const version = process.env.OPENCODE_VERSION ?? "local"
  9. const channel = process.env.OPENCODE_CHANNEL ?? "local"
  10. fs.rmSync(path.join(dir, "dist"), { recursive: true, force: true })
  11. const result = await Bun.build({
  12. entrypoints: ["./src/index.ts", worker, parser],
  13. outdir: "./dist",
  14. target: "bun",
  15. sourcemap: "none",
  16. tsconfig: "./tsconfig.json",
  17. plugins: [solidPlugin],
  18. external: ["@opentui/core"],
  19. define: {
  20. OPENCODE_VERSION: `'${version}'`,
  21. OPENCODE_CHANNEL: `'${channel}'`,
  22. // Leave undefined so runtime picks bundled/dist worker or fallback in code.
  23. OPENCODE_WORKER_PATH: "undefined",
  24. OTUI_TREE_SITTER_WORKER_PATH: 'new URL("./cli/cmd/tui/parser.worker.js", import.meta.url).href',
  25. },
  26. })
  27. if (!result.success) {
  28. console.error("bundle failed")
  29. for (const log of result.logs) console.error(log)
  30. process.exit(1)
  31. }
  32. const parserOut = path.join(dir, "dist/src/cli/cmd/tui/parser.worker.js")
  33. fs.mkdirSync(path.dirname(parserOut), { recursive: true })
  34. await Bun.write(parserOut, Bun.file(parser))