Skip to content

Commit f0df3d7

Browse files
committed
weird hack around build process
1 parent 2a1381a commit f0df3d7

File tree

6 files changed

+517
-38
lines changed

6 files changed

+517
-38
lines changed

cloudformation/main.yml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,33 +123,9 @@ Resources:
123123
Type: AWS::Serverless::Function
124124
DependsOn:
125125
- AppLogGroups
126-
Metadata:
127-
BuildMethod: esbuild
128-
BuildProperties:
129-
Format: esm
130-
Minify: !Equals [!Ref RunEnvironment, 'prod']
131-
OutExtension:
132-
- .js=.mjs
133-
Loader:
134-
- .png=file
135-
- .pkpass=file
136-
- .json=file
137-
Target: "es2022"
138-
Sourcemap: !Not [!Equals [!Ref RunEnvironment, 'prod']]
139-
EntryPoints:
140-
- api/lambda.js
141-
External:
142-
- aws-sdk
143-
Banner:
144-
- js=import path from 'path';
145-
import { fileURLToPath } from 'url';
146-
import { createRequire as topLevelCreateRequire } from 'module';
147-
const require = topLevelCreateRequire(import.meta.url);
148-
const __filename = fileURLToPath(import.meta.url);
149-
const __dirname = path.dirname(__filename);
150126
Properties:
151127
Architectures: [arm64]
152-
CodeUri: ../dist
128+
CodeUri: ../dist/lambda
153129
AutoPublishAlias: live
154130
Runtime: nodejs22.x
155131
Description: !Sub "${ApplicationFriendlyName} API Lambda"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"build": "yarn workspaces run build && yarn lockfile-manage",
1313
"dev": "concurrently --names 'api,ui' 'yarn workspace infra-core-api run dev' 'yarn workspace infra-core-ui run dev'",
14-
"lockfile-manage": "synp --with-workspace --source-file yarn.lock && cp package-lock.json dist/ && cp src/api/package.json dist/ && rm package-lock.json",
14+
"lockfile-manage": "synp --with-workspace --source-file yarn.lock && cp package-lock.json dist/lambda/ && cp src/api/package.lambda.json dist/lambda/package.json && rm package-lock.json",
1515
"prettier": "yarn workspaces run prettier && prettier --check tests/**/*.ts",
1616
"prettier:write": "yarn workspaces run prettier:write && prettier --write tests/**/*.ts",
1717
"lint": "yarn workspaces run lint",

src/api/build.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import esbuild from "esbuild";
2+
3+
esbuild
4+
.build({
5+
entryPoints: ["api/lambda.js"], // Entry file
6+
bundle: true,
7+
format: "esm",
8+
minify: true,
9+
outdir: "../../dist/lambda/",
10+
outExtension: { ".js": ".mjs" },
11+
loader: {
12+
".png": "file",
13+
".pkpass": "file",
14+
".json": "file",
15+
}, // File loaders
16+
target: "es2022", // Target ES2022
17+
sourcemap: false,
18+
platform: "node",
19+
external: ["aws-sdk", "moment-timezone","passkit-generator", "fastify"],
20+
banner: {
21+
js: `
22+
import path from 'path';
23+
import { fileURLToPath } from 'url';
24+
import { createRequire as topLevelCreateRequire } from 'module';
25+
const require = topLevelCreateRequire(import.meta.url);
26+
const __filename = fileURLToPath(import.meta.url);
27+
const __dirname = path.dirname(__filename);
28+
`.trim(),
29+
}, // Banner for compatibility with CommonJS
30+
})
31+
.then(() => console.log("Build completed successfully!"))
32+
.catch((error) => {
33+
console.error("Build failed:", error);
34+
process.exit(1);
35+
});

src/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "BSD-3-Clause",
88
"type": "module",
99
"scripts": {
10-
"build": "tsc",
10+
"build": "tsc && node build.js",
1111
"dev": "cross-env LOG_LEVEL=debug concurrently --names 'esbuild,server' 'node esbuild.config.js --watch' 'cd ../../dist_devel && nodemon index.js'",
1212
"typecheck": "tsc --noEmit",
1313
"lint": "eslint . --ext .ts --cache",

src/api/package.lambda.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "infra-core-api",
3+
"version": "1.0.0",
4+
"description": "ACM@UIUC Infra - Sample AWS Lambda in Node",
5+
"main": "index.js",
6+
"author": "ACM@UIUC",
7+
"license": "BSD-3-Clause",
8+
"type": "module",
9+
"dependencies": {
10+
"moment-timezone": "^0.5.45",
11+
"passkit-generator": "^3.3.1",
12+
"fastify": "^5.1.0"
13+
},
14+
"devDependencies": {}
15+
}

0 commit comments

Comments
 (0)