Skip to content

Commit 27ab1ab

Browse files
authored
refactor: use the new regex utility for cross-platform paths (#271)
* refactor: use the new regex utility for cross-platform paths * Update packages/cloudflare/src/cli/build/bundle-server.ts * formatting
1 parent 6dd5ca4 commit 27ab1ab

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
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: 7 additions & 3 deletions
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,9 +184,12 @@ 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-
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
188-
}));
187+
build.onResolve(
188+
{ filter: getCrossPlatformPathRegex(String.raw`^\./require-hook$`, { escape: false }) },
189+
() => ({
190+
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
191+
})
192+
);
189193
},
190194
};
191195
}

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)