Skip to content

Commit ea2fbfa

Browse files
Update patchFindDir to work with Next.js 15.1 (#184)
Also add patching validation check
1 parent 361c28a commit ea2fbfa

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/cloudflare/src/cli/build/patches/to-investigate/patch-find-dir.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ import { Config } from "../../../config";
1111
*/
1212
export function patchFindDir(code: string, config: Config): string {
1313
console.log("# patchFindDir");
14-
return code.replace(
15-
"function findDir(dir, name) {",
16-
`function findDir(dir, name) {
17-
if (dir.endsWith(".next/server")) {
18-
if (name === "app") {
14+
const patchedCode = code.replace(
15+
/function findDir\((?<dir>dir\d*), (?<name>name\d*)\) {/,
16+
`function findDir($dir, $name) {
17+
if ($dir.endsWith(".next/server")) {
18+
if ($name === "app") {
1919
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "app")}`)};
2020
}
21-
if (name === "pages") {
21+
if ($name === "pages") {
2222
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "pages")}`)};
2323
}
2424
}
25-
throw new Error("Unknown findDir call: " + dir + " " + name);
25+
throw new Error("Unknown findDir call: " + $dir + " " + $name);
2626
`
2727
);
28+
29+
if (patchedCode === code) {
30+
throw new Error("Patch `patchFindDir` not applied");
31+
}
32+
33+
return patchedCode;
2834
}

0 commit comments

Comments
 (0)