| 72 | }; |
| 73 | |
| 74 | const createPackedWorkerBundlerSource = async (distPath: string): Promise<string> => { |
| 75 | const esbuildPath = join(repoRoot, "node_modules/.bun/node_modules/esbuild/lib/main.js"); |
| 76 | if (!existsSync(esbuildPath)) throw new Error(`esbuild not found at ${esbuildPath}`); |
| 77 | const { build } = await import(pathToFileURL(esbuildPath).href); |
| 78 | const result = await build({ |
| 79 | entryPoints: [join(distPath, "index.js")], |
| 80 | bundle: true, |
| 81 | format: "esm", |
| 82 | platform: "browser", |
| 83 | external: ["./esbuild.wasm"], |
| 84 | logLevel: "silent", |
| 85 | write: false, |
| 86 | }); |
| 87 | const source = result.outputFiles[0]?.text; |
| 88 | if (source === undefined) throw new Error("failed to bundle @cloudflare/worker-bundler"); |
| 89 | return source; |
| 90 | }; |
| 91 | |
| 92 | // --------------------------------------------------------------------------- |
| 93 | // Metadata |