Skip to content

Commit 213025c

Browse files
committed
refactor: use the new regex utility for cross-platform paths
1 parent 0f8448b commit 213025c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/rare-hornets-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
refactor: use the new regex utility for constructing cross-platform paths

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "node:path";
44
import { fileURLToPath } from "node:url";
55

66
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
7+
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
78
import { build, Plugin } from "esbuild";
89

910
import { Config } from "../config.js";
@@ -183,7 +184,7 @@ function createFixRequiresESBuildPlugin(config: Config): Plugin {
183184
name: "replaceRelative",
184185
setup(build) {
185186
// Note: we (empty) shim require-hook modules as they generate problematic code that uses requires
186-
build.onResolve({ filter: /^\.(\/|\\)require-hook$/ }, () => ({
187+
build.onResolve({ filter: getCrossPlatformPathRegex("^\\./require-hook$", { escape: false }) }, () => ({
187188
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
188189
}));
189190
},

packages/cloudflare/src/cli/build/open-next/createServerBundle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { openNextEdgePlugins } from "@opennextjs/aws/plugins/edge.js";
1616
import { openNextReplacementPlugin } from "@opennextjs/aws/plugins/replacement.js";
1717
import { openNextResolvePlugin } from "@opennextjs/aws/plugins/resolve.js";
1818
import type { FunctionOptions, SplittedFunctionOptions } from "@opennextjs/aws/types/open-next.js";
19+
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
1920

2021
import { normalizePath } from "../utils/index.js";
2122

@@ -173,15 +174,15 @@ async function generateBundle(
173174
const plugins = [
174175
openNextReplacementPlugin({
175176
name: `requestHandlerOverride ${name}`,
176-
target: /core(\/|\\)requestHandler\.js/g,
177+
target: getCrossPlatformPathRegex("core/requestHandler.js"),
177178
deletes: [
178179
...(disableNextPrebundledReact ? ["applyNextjsPrebundledReact"] : []),
179180
...(disableRouting ? ["withRouting"] : []),
180181
],
181182
}),
182183
openNextReplacementPlugin({
183184
name: `utilOverride ${name}`,
184-
target: /core(\/|\\)util\.js/g,
185+
target: getCrossPlatformPathRegex("core/util.js"),
185186
deletes: [
186187
...(disableNextPrebundledReact ? ["requireHooks"] : []),
187188
...(isBefore13413 ? ["trustHostHeader"] : ["requestHandlerHost"]),

0 commit comments

Comments
 (0)