Skip to content

Commit 1b3a972

Browse files
authored
Dump ESBuild metadata to handler.mjs.meta.json (#295)
1 parent f13d813 commit 1b3a972

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.changeset/four-crabs-carry.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
Dump ESBuild metadata to `handler.mjs.meta.json`
6+
7+
The ESBuild metadata are written to a file alongside `handler.mjs`
8+
in `.open-next/server-functions/default/...`

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"dependencies": {
7474
"@ast-grep/napi": "^0.34.1",
7575
"@dotenvx/dotenvx": "catalog:",
76-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@712",
76+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@715",
7777
"enquirer": "^2.4.1",
7878
"glob": "catalog:",
7979
"ts-morph": "catalog:",

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
4343
const openNextServer = path.join(outputPath, packagePath, `index.mjs`);
4444
const openNextServerBundle = path.join(outputPath, packagePath, `handler.mjs`);
4545

46-
await build({
46+
const result = await build({
4747
entryPoints: [openNextServer],
4848
bundle: true,
4949
outfile: openNextServerBundle,
5050
format: "esm",
5151
target: "esnext",
5252
minify: false,
53+
metafile: true,
5354
plugins: [
5455
createFixRequiresESBuildPlugin(buildOpts),
5556
inlineRequirePagePlugin(buildOpts),
@@ -135,6 +136,13 @@ globalThis.__BUILD_TIMESTAMP_MS__ = ${Date.now()};
135136
},
136137
});
137138

139+
if (result.errors.length > 0) {
140+
result.errors.forEach((error) => console.error(error));
141+
throw new Error(`There was a problem bundling the server.`);
142+
}
143+
144+
fs.writeFileSync(openNextServerBundle + ".meta.json", JSON.stringify(result.metafile, null, 2));
145+
138146
await updateWorkerBundledCode(openNextServerBundle, buildOpts);
139147

140148
const isMonorepo = monorepoRoot !== appPath;

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)