| 46 | }; |
| 47 | |
| 48 | const createPackedWorkerBundlerSource = async (distPath: string): Promise<string> => { |
| 49 | const esbuildPath = join(repoRoot, "node_modules/.bun/node_modules/esbuild/lib/main.js"); |
| 50 | if (!existsSync(esbuildPath)) throw new Error(`esbuild not found at ${esbuildPath}`); |
| 51 | const { build } = await import(pathToFileURL(esbuildPath).href); |
| 52 | const result = await build({ |
| 53 | entryPoints: [join(distPath, "index.js")], |
| 54 | bundle: true, |
| 55 | format: "esm", |
| 56 | platform: "browser", |
| 57 | external: ["./esbuild.wasm"], |
| 58 | logLevel: "silent", |
| 59 | write: false, |
| 60 | }); |
| 61 | const source = result.outputFiles[0]?.text; |
| 62 | if (source === undefined) throw new Error("failed to bundle @cloudflare/worker-bundler"); |
| 63 | return source; |
| 64 | }; |
| 65 | |
| 66 | // --------------------------------------------------------------------------- |
| 67 | // Metadata |