(binDir: string, targetName: string)
| 105 | * cannot pass as real. |
| 106 | */ |
| 107 | const assertPackedWorkerBundler = async (binDir: string, targetName: string): Promise<void> => { |
| 108 | const stagedDir = join(binDir, WORKER_BUNDLER_DIRNAME); |
| 109 | |
| 110 | const missing = missingWorkerBundlerFiles(stagedDir, existsSync); |
| 111 | if (missing.length > 0) { |
| 112 | throw new Error( |
| 113 | `Packed @cloudflare/worker-bundler is incomplete for ${targetName}: missing ${missing.join(", ")} under ${stagedDir}. ` + |
| 114 | `The compiled binary resolves this package from disk, not from bunfs, so shipping it partial means a runtime failure on the user's machine.`, |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | const bundledEntry = join(stagedDir, "dist", "index.bundled.js"); |
| 119 | const bundledSize = (await Bun.file(bundledEntry).arrayBuffer()).byteLength; |
| 120 | if (bundledSize < 100_000) { |
| 121 | throw new Error( |
| 122 | `Packed worker-bundler entry for ${targetName} is implausibly small (${bundledSize} bytes at ${bundledEntry}). Expected the esbuild-packed bundle.`, |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | const wasmPath = join(stagedDir, "dist", "esbuild.wasm"); |
| 127 | const wasmHead = new Uint8Array((await Bun.file(wasmPath).arrayBuffer()).slice(0, 4)); |
| 128 | if ( |
| 129 | wasmHead[0] !== 0x00 || |
| 130 | wasmHead[1] !== 0x61 || |
| 131 | wasmHead[2] !== 0x73 || |
| 132 | wasmHead[3] !== 0x6d |
| 133 | ) { |
| 134 | throw new Error( |
| 135 | `Staged esbuild.wasm for ${targetName} is not a WebAssembly module (bad magic at ${wasmPath}).`, |
| 136 | ); |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | // --------------------------------------------------------------------------- |
| 141 | // Metadata |
no test coverage detected