Skip to content

Commit 6c84a10

Browse files
committed
normalize id variable and escape file path
1 parent 4c7b8f4 commit 6c84a10

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/cloudflare/src/cli/build/patches/plugins/node-module-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
77
import { normalizePath } from "../../utils/normalize-path.js";
88
import { patchCode, type RuleConfig } from "../ast/util.js";
99
import type { ContentUpdater } from "./content-updater.js";
10+
import { posix, sep } from "node:path";
1011

1112
export function inlineNodeModuleLoader(updater: ContentUpdater, buildOpts: BuildOptions) {
1213
return updater.updateContent(
@@ -41,7 +42,7 @@ async function getRule(buildOpts: BuildOptions) {
4142
const fnBody = `
4243
${files
4344
.map(
44-
(file) => `if ($ID.endsWith("${file}")) {
45+
(file) => `if ($ID.replaceAll(${JSON.stringify(sep)}, ${JSON.stringify(posix.sep)}).endsWith(${JSON.stringify(file)})) {
4546
return require(${JSON.stringify(join(serverDir, file))});
4647
}`
4748
)

0 commit comments

Comments
 (0)