Skip to content

Commit

Permalink
refactor: use the new regex utility for cross-platform paths (#271)
Browse files Browse the repository at this point in the history
* refactor: use the new regex utility for cross-platform paths

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

* formatting
  • Loading branch information
james-elicx authored Jan 21, 2025
1 parent 6dd5ca4 commit 27ab1ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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

0 comments on commit 27ab1ab

Please sign in to comment.