|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Build script for @hyperframes/aws-lambda (public OSS package). |
| 4 | + * |
| 5 | + * Bundles each subpath barrel via esbuild → dist/, then emits .d.ts via tsc. |
| 6 | + * |
| 7 | + * Subpaths (each gets its own dist entry so adopters that import one path |
| 8 | + * don't load the others' transitive graphs at module-load time): |
| 9 | + * |
| 10 | + * . (the umbrella barrel: handler + sdk + cdk types re-exported) |
| 11 | + * ./handler (the Lambda runtime entry — what `scripts/build-zip.ts` ZIPs) |
| 12 | + * ./sdk (client-side helpers — AWS-SDK only, no chromium/puppeteer) |
| 13 | + * ./cdk (CDK L2 construct — aws-cdk-lib is a peer dep) |
| 14 | + * |
| 15 | + * All production deps and peer deps are kept external so consumers resolve |
| 16 | + * them via their own node_modules. |
| 17 | + */ |
| 18 | + |
| 19 | +import { build } from "esbuild"; |
| 20 | +import { execSync } from "node:child_process"; |
| 21 | +import { mkdirSync, rmSync } from "node:fs"; |
| 22 | + |
| 23 | +rmSync("dist", { recursive: true, force: true }); |
| 24 | +mkdirSync("dist", { recursive: true }); |
| 25 | + |
| 26 | +const sharedOpts = { |
| 27 | + bundle: true, |
| 28 | + platform: "node", |
| 29 | + target: "node22", |
| 30 | + format: "esm", |
| 31 | + minify: false, |
| 32 | + sourcemap: true, |
| 33 | + external: [ |
| 34 | + "@aws-sdk/client-s3", |
| 35 | + "@aws-sdk/client-sfn", |
| 36 | + "@hyperframes/producer", |
| 37 | + "@hyperframes/producer/distributed", |
| 38 | + "@sparticuz/chromium", |
| 39 | + "aws-cdk-lib", |
| 40 | + "constructs", |
| 41 | + "ffmpeg-static", |
| 42 | + "ffprobe-static", |
| 43 | + "puppeteer-core", |
| 44 | + "tar", |
| 45 | + ], |
| 46 | +}; |
| 47 | + |
| 48 | +await Promise.all([ |
| 49 | + build({ ...sharedOpts, entryPoints: ["src/index.ts"], outfile: "dist/index.js" }), |
| 50 | + build({ ...sharedOpts, entryPoints: ["src/handler.ts"], outfile: "dist/handler.js" }), |
| 51 | + build({ ...sharedOpts, entryPoints: ["src/sdk/index.ts"], outfile: "dist/sdk/index.js" }), |
| 52 | + build({ ...sharedOpts, entryPoints: ["src/cdk/index.ts"], outfile: "dist/cdk/index.js" }), |
| 53 | +]); |
| 54 | + |
| 55 | +// esbuild doesn't emit .d.ts. tsc does, with a build-only tsconfig that |
| 56 | +// drops the workspace `paths` overrides so `@hyperframes/producer` resolves |
| 57 | +// through node_modules to the sibling package's already-built `dist/` |
| 58 | +// types instead of pulling its full source tree into emit (which would |
| 59 | +// violate rootDir). |
| 60 | +execSync("tsc -p tsconfig.build.json --emitDeclarationOnly", { stdio: "inherit" }); |
| 61 | + |
| 62 | +console.log("[Build] Complete: dist/{index,handler,sdk/index,cdk/index}.js + .d.ts"); |
0 commit comments