diff --git a/.changeset/ten-mangos-rush.md b/.changeset/ten-mangos-rush.md new file mode 100644 index 00000000..8a41c2a9 --- /dev/null +++ b/.changeset/ten-mangos-rush.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix: improve windows support diff --git a/packages/cloudflare/src/cli/build/patches/plugins/eval-manifest.ts b/packages/cloudflare/src/cli/build/patches/plugins/eval-manifest.ts index 63fffe45..30c3b8ce 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/eval-manifest.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/eval-manifest.ts @@ -60,6 +60,8 @@ function evalManifest($PATH, $$$ARGS) { }, fix: ` function evalManifest($PATH, $$$ARGS) { + const { platform } = require('process'); + $PATH = platform === 'win32' ? $PATH.replaceAll('\\\\', '/') : $PATH; ${returnManifests} throw new Error(\`Unexpected evalManifest(\${$PATH}) call!\`); }`, diff --git a/packages/cloudflare/src/cli/build/patches/plugins/find-dir.ts b/packages/cloudflare/src/cli/build/patches/plugins/find-dir.ts index fa10a2ae..6e995be4 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/find-dir.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/find-dir.ts @@ -36,6 +36,8 @@ rule: pattern: function findDir($DIR, $NAME) { $$$_ } fix: |- function findDir($DIR, $NAME) { + const { platform } = require('process'); + $DIR = platform === 'win32' ? $DIR.replaceAll('\\\\', '/') : $DIR; if ($DIR.endsWith(".next/server")) { if ($NAME === "app") { return ${appExists}; diff --git a/packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts b/packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts index c31c4b70..7689e0c1 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts @@ -53,6 +53,8 @@ function loadManifest($PATH, $$$ARGS) { }, fix: ` function loadManifest($PATH, $$$ARGS) { + const { platform } = require('process'); + $PATH = platform === 'win32' ? $PATH.replaceAll('\\\\', '/') : $PATH; ${returnManifests} throw new Error(\`Unexpected loadManifest(\${$PATH}) call!\`); }`, diff --git a/packages/cloudflare/src/cli/build/patches/plugins/require-page.ts b/packages/cloudflare/src/cli/build/patches/plugins/require-page.ts index c1a12a68..393a1576 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/require-page.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/require-page.ts @@ -4,6 +4,7 @@ import { join } from "node:path"; import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.js"; import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js"; +import { normalizePath } from "../../utils/normalize-path.js"; import { patchCode, type RuleConfig } from "../ast/util.js"; import type { ContentUpdater } from "./content-updater.js"; @@ -41,7 +42,7 @@ async function getRule(buildOpts: BuildOptions) { appPathsManifests = []; } - const manifests = pagesManifests.concat(appPathsManifests); + const manifests = pagesManifests.concat(appPathsManifests).map((path) => normalizePath(path)); const htmlFiles = manifests.filter((file) => file.endsWith(".html")); const jsFiles = manifests.filter((file) => file.endsWith(".js")); @@ -83,7 +84,8 @@ function requirePage($PAGE, $DIST_DIR, $IS_APP_PATH) { }, fix: ` function requirePage($PAGE, $DIST_DIR, $IS_APP_PATH) { - const pagePath = getPagePath($$$ARGS); + const { platform } = require('process'); + const pagePath = platform === 'win32' ? getPagePath($$$ARGS).replaceAll('\\\\', '/') : getPagePath($$$ARGS); ${fnBody} }`, } satisfies RuleConfig;