Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rare-hornets-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

refactor: use the new regex utility for constructing cross-platform paths
10 changes: 7 additions & 3 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";

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

import { Config } from "../config.js";
Expand Down Expand Up @@ -183,9 +184,12 @@ function createFixRequiresESBuildPlugin(config: Config): Plugin {
name: "replaceRelative",
setup(build) {
// Note: we (empty) shim require-hook modules as they generate problematic code that uses requires
build.onResolve({ filter: /^\.(\/|\\)require-hook$/ }, () => ({
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
}));
build.onResolve(
{ filter: getCrossPlatformPathRegex(String.raw`^\./require-hook$`, { escape: false }) },
() => ({
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
})
);
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { openNextEdgePlugins } from "@opennextjs/aws/plugins/edge.js";
import { openNextReplacementPlugin } from "@opennextjs/aws/plugins/replacement.js";
import { openNextResolvePlugin } from "@opennextjs/aws/plugins/resolve.js";
import type { FunctionOptions, SplittedFunctionOptions } from "@opennextjs/aws/types/open-next.js";
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";

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

Expand Down Expand Up @@ -173,15 +174,15 @@ async function generateBundle(
const plugins = [
openNextReplacementPlugin({
name: `requestHandlerOverride ${name}`,
target: /core(\/|\\)requestHandler\.js/g,
target: getCrossPlatformPathRegex("core/requestHandler.js"),
deletes: [
...(disableNextPrebundledReact ? ["applyNextjsPrebundledReact"] : []),
...(disableRouting ? ["withRouting"] : []),
],
}),
openNextReplacementPlugin({
name: `utilOverride ${name}`,
target: /core(\/|\\)util\.js/g,
target: getCrossPlatformPathRegex("core/util.js"),
deletes: [
...(disableNextPrebundledReact ? ["requireHooks"] : []),
...(isBefore13413 ? ["trustHostHeader"] : ["requestHandlerHost"]),
Expand Down
Loading