Skip to content

Commit

Permalink
Dump ESBuild metadata to handler.mjs.meta.json (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Jan 29, 2025
1 parent f13d813 commit 1b3a972
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .changeset/four-crabs-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@opennextjs/cloudflare": patch
---

Dump ESBuild metadata to `handler.mjs.meta.json`

The ESBuild metadata are written to a file alongside `handler.mjs`
in `.open-next/server-functions/default/...`
2 changes: 1 addition & 1 deletion packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"dependencies": {
"@ast-grep/napi": "^0.34.1",
"@dotenvx/dotenvx": "catalog:",
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@712",
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@715",
"enquirer": "^2.4.1",
"glob": "catalog:",
"ts-morph": "catalog:",
Expand Down
10 changes: 9 additions & 1 deletion packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
const openNextServer = path.join(outputPath, packagePath, `index.mjs`);
const openNextServerBundle = path.join(outputPath, packagePath, `handler.mjs`);

await build({
const result = await build({
entryPoints: [openNextServer],
bundle: true,
outfile: openNextServerBundle,
format: "esm",
target: "esnext",
minify: false,
metafile: true,
plugins: [
createFixRequiresESBuildPlugin(buildOpts),
inlineRequirePagePlugin(buildOpts),
Expand Down Expand Up @@ -135,6 +136,13 @@ globalThis.__BUILD_TIMESTAMP_MS__ = ${Date.now()};
},
});

if (result.errors.length > 0) {
result.errors.forEach((error) => console.error(error));
throw new Error(`There was a problem bundling the server.`);
}

fs.writeFileSync(openNextServerBundle + ".meta.json", JSON.stringify(result.metafile, null, 2));

await updateWorkerBundledCode(openNextServerBundle, buildOpts);

const isMonorepo = monorepoRoot !== appPath;
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b3a972

Please sign in to comment.