| 91 | ] |
| 92 | |
| 93 | async function main(): Promise<void> { |
| 94 | rmSync(ENTRIES_DIR, { recursive: true, force: true }) |
| 95 | mkdirSync(ENTRIES_DIR, { recursive: true }) |
| 96 | mkdirSync(BUNDLES_DIR, { recursive: true }) |
| 97 | |
| 98 | for (const spec of BUNDLES) { |
| 99 | const entryPath = join(ENTRIES_DIR, `${spec.name}.entry.ts`) |
| 100 | writeFileSync(entryPath, spec.entry, 'utf-8') |
| 101 | |
| 102 | const result = await Bun.build({ |
| 103 | entrypoints: [entryPath], |
| 104 | target: 'browser', |
| 105 | format: 'iife', |
| 106 | minify: true, |
| 107 | sourcemap: 'none', |
| 108 | root: APP_SIM_ROOT, |
| 109 | }) |
| 110 | |
| 111 | if (!result.success) { |
| 112 | for (const log of result.logs) { |
| 113 | logger.error(String(log)) |
| 114 | } |
| 115 | throw new Error(`Failed to build sandbox bundle: ${spec.name}`) |
| 116 | } |
| 117 | |
| 118 | if (result.outputs.length === 0) { |
| 119 | throw new Error(`No output produced for sandbox bundle: ${spec.name}`) |
| 120 | } |
| 121 | |
| 122 | const code = await result.outputs[0].text() |
| 123 | const banner = `// sandbox bundle: ${spec.name}\n// generated by apps/sim/lib/execution/sandbox/bundles/build.ts\n// do not edit by hand. run \`bun run build:sandbox-bundles\` to regenerate.\n` |
| 124 | writeFileSync(join(BUNDLES_DIR, spec.outFile), banner + code, 'utf-8') |
| 125 | logger.info(`built ${spec.outFile} (${code.length.toLocaleString()} chars)`) |
| 126 | } |
| 127 | |
| 128 | rmSync(ENTRIES_DIR, { recursive: true, force: true }) |
| 129 | } |
| 130 | |
| 131 | main().catch((err) => { |
| 132 | logger.error('sandbox bundle build failed', err) |