From 8d18ca4a4b665d7e40ffce07a0bf5921291537ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E8=8E=9E=7E=28=3D=5E=E2=96=BD=5E=3D=29?= Date: Thu, 10 Oct 2024 04:28:11 +0800 Subject: [PATCH] fix: Windows support (#81) --- .../patches/to-investigate/inline-eval-manifest.ts | 12 +++++++++--- .../patches/to-investigate/inline-next-require.ts | 2 +- .../build/patches/to-investigate/patch-read-file.ts | 10 +++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/cloudflare/src/cli/build/patches/to-investigate/inline-eval-manifest.ts b/packages/cloudflare/src/cli/build/patches/to-investigate/inline-eval-manifest.ts index 84ca809..d8a9957 100644 --- a/packages/cloudflare/src/cli/build/patches/to-investigate/inline-eval-manifest.ts +++ b/packages/cloudflare/src/cli/build/patches/to-investigate/inline-eval-manifest.ts @@ -12,8 +12,14 @@ 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\((.+?), .+?\) {/, `$& @@ -21,7 +27,7 @@ export function inlineEvalManifest(code: string, config: Config): string { .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 diff --git a/packages/cloudflare/src/cli/build/patches/to-investigate/inline-next-require.ts b/packages/cloudflare/src/cli/build/patches/to-investigate/inline-next-require.ts index 6be36ac..1f0c86b 100644 --- a/packages/cloudflare/src/cli/build/patches/to-investigate/inline-next-require.ts +++ b/packages/cloudflare/src/cli/build/patches/to-investigate/inline-next-require.ts @@ -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))}); } ` ) diff --git a/packages/cloudflare/src/cli/build/patches/to-investigate/patch-read-file.ts b/packages/cloudflare/src/cli/build/patches/to-investigate/patch-read-file.ts index 89560fc..d74da51 100644 --- a/packages/cloudflare/src/cli/build/patches/to-investigate/patch-read-file.ts +++ b/packages/cloudflare/src/cli/build/patches/to-investigate/patch-read-file.ts @@ -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\((.+?), .+?\) {/,