Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure patchFindDir works with Next.js 15 and add patching validation check #184

Merged
merged 2 commits into from
Dec 17, 2024
Merged
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
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\d*), (name\d*)\) {/,
dario-piotrowicz marked this conversation as resolved.
Show resolved Hide resolved
`function findDir($1, $2) {
if ($1.endsWith(".next/server")) {
if ($2 === "app") {
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "app")}`)};
}
if (name === "pages") {
if ($2 === "pages") {
return ${existsSync(`${join(config.paths.output.standaloneAppServer, "pages")}`)};
}
}
throw new Error("Unknown findDir call: " + dir + " " + name);
throw new Error("Unknown findDir call: " + $1 + " " + $2);
`
);

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

return patchedCode;
}
Loading