Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ import { Config } from "../../../config";
*/
export function patchFindDir(code: string, config: Config): string {
console.log("# patchFindDir");
return code.replace(
"function findDir(dir, name) {",
`function findDir(dir, name) {
if (dir.endsWith(".next/server")) {
if (name === "app") {
const patchedCode = code.replace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment here with the pre-15.1 code and 15.1 code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? it feels a bit overkill to me here 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might help if we later need to convert the patch to AST but your call :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and to be clear I meant fn signature, not the whole function)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it as is if it's ok by you 🙂

but if you do prefer a comment, could you please add a code suggestion here and I'd be happy to just go with whatever you'd fine useful here 🙂

/function findDir\((?<dir>dir\d*), (?<name>name\d*)\) {/,
`function findDir($dir, $name) {
if ($dir.endsWith(".next/server")) {
if ($name === "app") {
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "app")}`)};
}
if (name === "pages") {
if ($name === "pages") {
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "pages")}`)};
}
}
throw new Error("Unknown findDir call: " + dir + " " + name);
throw new Error("Unknown findDir call: " + $dir + " " + $name);
`
);

if (patchedCode === code) {
throw new Error("Patch `patchFindDir` not applied");
}

return patchedCode;
}
Loading