Skip to content

Commit ac9d7fc

Browse files
authored
fix(build): bundle the Lambda handler as CommonJS (#281)
1 parent b97ffa5 commit ac9d7fc

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎.github/workflows/publish.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: curl https://curl.se/ca/cacert.pem -o build/public-certs.pem
2929

3030
- name: Zip Lambda
31-
run: zip -r -qq proxy-lambda.zip build node_modules
31+
run: bun run package
3232

3333
- name: Upload Release Assets
3434
uses: softprops/action-gh-release@v3

‎.github/workflows/test.yaml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ jobs:
2929
- name: Build
3030
run: bun run build
3131

32+
- name: Setup Node
33+
uses: actions/setup-node@v7
34+
with:
35+
# Keep in sync with the Lambda runtime in lambda.tf
36+
node-version: 20
37+
38+
- name: Smoke Test Lambda Bundle
39+
# Load the handler from the packaged zip the way Lambda does: as CommonJS, with
40+
# require(esm) and module syntax detection off, so an ESM bundle fails here too.
41+
run: |
42+
bun run package
43+
unzip -q proxy-lambda.zip -d "$RUNNER_TEMP/lambda"
44+
cd "$RUNNER_TEMP/lambda"
45+
node --no-experimental-require-module --no-experimental-detect-module -e "
46+
if (typeof require('./build/proxy.js').handler !== 'function') throw new Error('build/proxy.js does not export handler');
47+
"
48+
3249
- name: Test
3350
run: bun run test
3451

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"main": "lambdas/proxy/index.js",
55
"type": "module",
66
"scripts": {
7-
"build": "bun build lambda/proxy.ts --outdir build/ --target node",
7+
"build": "bun build lambda/proxy.ts --outdir build/ --target node --format cjs",
8+
"package": "zip -r -qq proxy-lambda.zip build node_modules",
89
"format": "prettier --write .",
910
"format-check": "prettier --check .",
1011
"test": "bun test"

0 commit comments

Comments
 (0)