Skip to content

Commit a8a0a3e

Browse files
committed
fix: vercel og patch not moving to right node_modules directory
1 parent 5a3555e commit a8a0a3e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: vercel og patch not moving to right node_modules directory
6+
7+
There are two separate places where the node_modules could be. One is a package-scoped node_modules which does not always exist - if it doesn't exist, the server functions-scoped node_modules is used.

packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { patchVercelOgFallbackFont, patchVercelOgImport } from "./vercel-og.js";
1010

1111
type TraceInfo = { version: number; files: string[] };
1212

13+
const vercelOgNodeModulePath = "node_modules/next/dist/compiled/@vercel/og";
14+
1315
/**
1416
* Patches the usage of @vercel/og to be compatible with Cloudflare Workers.
1517
*
@@ -18,15 +20,16 @@ type TraceInfo = { version: number; files: string[] };
1820
export function patchVercelOgLibrary(buildOpts: BuildOptions) {
1921
const { appBuildOutputPath, outputDir } = buildOpts;
2022

21-
const packagePath = path.join(outputDir, "server-functions/default", getPackagePath(buildOpts));
23+
const functionsPath = path.join(outputDir, "server-functions/default");
24+
const packagePath = path.join(functionsPath, getPackagePath(buildOpts));
2225

2326
for (const traceInfoPath of globSync(path.join(appBuildOutputPath, ".next/server/**/*.nft.json"))) {
2427
const traceInfo: TraceInfo = JSON.parse(readFileSync(traceInfoPath, { encoding: "utf8" }));
2528
const tracedNodePath = traceInfo.files.find((p) => p.endsWith("@vercel/og/index.node.js"));
2629

2730
if (!tracedNodePath) continue;
2831

29-
const outputDir = path.join(packagePath, "node_modules/next/dist/compiled/@vercel/og");
32+
const outputDir = getOutputDir({ functionsPath, packagePath });
3033
const outputEdgePath = path.join(outputDir, "index.edge.js");
3134

3235
// Ensure the edge version is available in the OpenNext node_modules.
@@ -55,3 +58,12 @@ export function patchVercelOgLibrary(buildOpts: BuildOptions) {
5558
writeFileSync(routeFilePath, node.commitEdits(edits));
5659
}
5760
}
61+
62+
function getOutputDir(opts: { functionsPath: string; packagePath: string }) {
63+
const packageOutputPath = path.join(opts.packagePath, vercelOgNodeModulePath);
64+
if (existsSync(packageOutputPath)) {
65+
return packageOutputPath;
66+
}
67+
68+
return path.join(opts.functionsPath, vercelOgNodeModulePath);
69+
}

0 commit comments

Comments
 (0)