Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { build } from "esbuild";
import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js";
import { patchWebpackRuntime } from "./patches/ast/webpack-runtime.js";
import * as patches from "./patches/index.js";
import { inlineBuildId } from "./patches/plugins/build-id.js";
import { ContentUpdater } from "./patches/plugins/content-updater.js";
import { inlineEvalManifest } from "./patches/plugins/eval-manifest.js";
import { patchFetchCacheSetMissingWaitUntil } from "./patches/plugins/fetch-cache-wait-until.js";
Expand Down Expand Up @@ -95,6 +96,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
inlineEvalManifest(updater, buildOpts),
inlineFindDir(updater, buildOpts),
inlineLoadManifest(updater, buildOpts),
inlineBuildId(updater),
// Apply updater updaters, must be the last plugin
updater.plugin,
],
Expand Down Expand Up @@ -197,7 +199,6 @@ export async function updateWorkerBundledCode(

const patchedCode = await patchCodeWithValidations(code, [
["require", patches.patchRequire],
["`buildId` function", (code) => patches.patchBuildId(code, buildOpts)],
["cacheHandler", (code) => patches.patchCache(code, buildOpts)],
[
"'require(this.middlewareManifestPath)'",
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/cli/build/patches/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./investigated/index.js";
export * from "./to-investigate/index.js";
export * from "./to-investigate/inline-middleware-manifest.js";
31 changes: 31 additions & 0 deletions packages/cloudflare/src/cli/build/patches/plugins/build-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Inline `getBuildId` as it relies on `readFileSync`that is not supported by workerd.
*/

import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";

import { patchCode } from "../ast/util.js";
import type { ContentUpdater } from "./content-updater.js";

export function inlineBuildId(updater: ContentUpdater) {
return updater.updateContent(
"inline-build-id",
{
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/next-server\.js$`, { escape: false }),
contentFilter: /getBuildId\(/,
},
async ({ contents }) => patchCode(contents, rule)
);
}

const rule = `
rule:
kind: method_definition
has:
field: name
regex: ^getBuildId$
fix: |-
getBuildId() {
return process.env.NEXT_BUILD_ID;
}
`;

This file was deleted.

This file was deleted.