| 183 | } |
| 184 | |
| 185 | async function bundleHandler(stagingDir: string): Promise<void> { |
| 186 | const entry = join(packageRoot, "src/handler.ts"); |
| 187 | const outfile = join(stagingDir, "handler.mjs"); |
| 188 | |
| 189 | const workspaceAliasPlugin: esbuild.Plugin = { |
| 190 | name: "workspace-alias", |
| 191 | setup(build) { |
| 192 | build.onResolve({ filter: /^@hyperframes\/producer\/distributed$/ }, () => ({ |
| 193 | path: resolve(monorepoRoot, "packages/producer/src/distributed.ts"), |
| 194 | })); |
| 195 | build.onResolve({ filter: /^@hyperframes\/producer$/ }, () => ({ |
| 196 | path: resolve(monorepoRoot, "packages/producer/src/index.ts"), |
| 197 | })); |
| 198 | build.onResolve({ filter: /^@hyperframes\/engine$/ }, () => ({ |
| 199 | path: resolve(monorepoRoot, "packages/engine/src/index.ts"), |
| 200 | })); |
| 201 | build.onResolve({ filter: /^@hyperframes\/engine\/alpha-blit$/ }, () => ({ |
| 202 | path: resolve(monorepoRoot, "packages/engine/src/utils/alphaBlit.ts"), |
| 203 | })); |
| 204 | build.onResolve({ filter: /^@hyperframes\/engine\/shader-transitions$/ }, () => ({ |
| 205 | path: resolve(monorepoRoot, "packages/engine/src/utils/shaderTransitions.ts"), |
| 206 | })); |
| 207 | build.onResolve({ filter: /^@hyperframes\/core$/ }, () => ({ |
| 208 | path: resolve(monorepoRoot, "packages/core/src/index.ts"), |
| 209 | })); |
| 210 | build.onResolve({ filter: /^@hyperframes\/core\/lint$/ }, () => ({ |
| 211 | path: resolve(monorepoRoot, "packages/core/src/lint/index.ts"), |
| 212 | })); |
| 213 | }, |
| 214 | }; |
| 215 | |
| 216 | await esbuild.build({ |
| 217 | bundle: true, |
| 218 | platform: "node", |
| 219 | target: "node22", |
| 220 | format: "esm", |
| 221 | // Externalise binary-shipped modules so node module resolution picks |
| 222 | // them up at runtime. esbuild would otherwise try to inline their |
| 223 | // postinstall-extracted binaries, which it cannot do. |
| 224 | external: [ |
| 225 | "@sparticuz/chromium", |
| 226 | "puppeteer-core", |
| 227 | "puppeteer", |
| 228 | // AWS SDK v3 is pre-installed in the Lambda Node 22 runtime; mark |
| 229 | // external so we don't double-bundle 3+ MiB of SDK. |
| 230 | "@aws-sdk/client-s3", |
| 231 | ], |
| 232 | plugins: [workspaceAliasPlugin], |
| 233 | minify: false, |
| 234 | // sourcemap=false: the ZIP is tight on Lambda's 250 MiB unzipped cap |
| 235 | // (Chrome ~70 MiB + ffmpeg ~80 MiB + ffprobe ~62 MiB + Node deps). A |
| 236 | // 4-5 MiB sourcemap puts us over. Re-enable for local debugging by passing |
| 237 | // --sourcemap; the bundle's stack traces stay readable enough without |
| 238 | // it because we don't minify. |
| 239 | sourcemap: false, |
| 240 | entryPoints: [entry], |
| 241 | outfile, |
| 242 | // Lambda's Node 22 runtime treats `.mjs` as ESM. Inject a real `require` |