Skip to content

Commit

Permalink
fix: Windows support (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty authored Oct 9, 2024
1 parent 83abcfe commit 8d18ca4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ import path from "node:path";
export function inlineEvalManifest(code: string, config: Config): string {
console.log("# inlineEvalManifest");
const manifestJss = globSync(
path.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
path
.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
.replaceAll(path.sep, path.posix.sep)
).map((file) =>
file
.replaceAll(path.sep, path.posix.sep)
.replace(config.paths.standaloneApp.replaceAll(path.sep, path.posix.sep) + path.posix.sep, "")
);
return code.replace(
/function evalManifest\((.+?), .+?\) {/,
`$&
${manifestJss
.map(
(manifestJs) => `
if ($1.endsWith("${manifestJs}")) {
require("${path.join(config.paths.standaloneApp, manifestJs)}");
require(${JSON.stringify(path.join(config.paths.standaloneApp, manifestJs))});
return {
__RSC_MANIFEST: {
"${manifestJs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function inlineNextRequire(code: string, config: Config) {
.map(
(module) => `
if (pagePath.endsWith("${module}")) {
return require("${path.join(config.paths.standaloneApp, module)}");
return require(${JSON.stringify(path.join(config.paths.standaloneApp, module))});
}
`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export function patchReadFile(code: string, config: Config): string {
`
);

// Same as above, the next-server code loads the manifests with `readyFileSync` and we want to avoid that
// Same as above, the next-server code loads the manifests with `readFileSync` and we want to avoid that
// (source: https://github.com/vercel/next.js/blob/15aeb92e/packages/next/src/server/load-manifest.ts#L34-L56)
// Note: we could/should probably just patch readFileSync here or something!
const manifestJsons = globSync(path.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
(file) => file.replace(config.paths.standaloneApp + "/", "")
const manifestJsons = globSync(
path.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json").replaceAll(path.sep, path.posix.sep)
).map((file) =>
file
.replaceAll(path.sep, path.posix.sep)
.replace(config.paths.standaloneApp.replaceAll(path.sep, path.posix.sep) + path.posix.sep, "")
);
code = code.replace(
/function loadManifest\((.+?), .+?\) {/,
Expand Down

0 comments on commit 8d18ca4

Please sign in to comment.