Skip to content

Commit 2d4d9bc

Browse files
james-elicxvicb
authored andcommitted
refactor: utility to normalize file paths
1 parent 5bceecc commit 2d4d9bc

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

packages/cloudflare/src/cli/build/patches/to-investigate/inline-eval-manifest.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Config } from "../../../config";
22
import { globSync } from "glob";
33
import path from "node:path";
4+
import { normalizePath } from "../../utils";
45

56
/**
67
* `evalManifest` relies on readFileSync so we need to patch the function so that it instead returns the content of the manifest files
@@ -12,13 +13,9 @@ import path from "node:path";
1213
export function inlineEvalManifest(code: string, config: Config): string {
1314
console.log("# inlineEvalManifest");
1415
const manifestJss = globSync(
15-
path
16-
.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
17-
.replaceAll(path.sep, path.posix.sep)
16+
normalizePath(path.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js"))
1817
).map((file) =>
19-
file
20-
.replaceAll(path.sep, path.posix.sep)
21-
.replace(config.paths.standaloneApp.replaceAll(path.sep, path.posix.sep) + path.posix.sep, "")
18+
normalizePath(file).replace(normalizePath(config.paths.standaloneApp) + path.posix.sep, "")
2219
);
2320
return code.replace(
2421
/function evalManifest\((.+?), .+?\) {/,

packages/cloudflare/src/cli/build/patches/to-investigate/patch-read-file.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Config } from "../../../config";
22
import { globSync } from "glob";
33
import path from "node:path";
4+
import { normalizePath } from "../../utils";
45
import { readFileSync } from "node:fs";
56

67
export function patchReadFile(code: string, config: Config): string {
@@ -20,11 +21,9 @@ export function patchReadFile(code: string, config: Config): string {
2021
// (source: https://github.com/vercel/next.js/blob/15aeb92e/packages/next/src/server/load-manifest.ts#L34-L56)
2122
// Note: we could/should probably just patch readFileSync here or something!
2223
const manifestJsons = globSync(
23-
path.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json").replaceAll(path.sep, path.posix.sep)
24+
normalizePath(path.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json"))
2425
).map((file) =>
25-
file
26-
.replaceAll(path.sep, path.posix.sep)
27-
.replace(config.paths.standaloneApp.replaceAll(path.sep, path.posix.sep) + path.posix.sep, "")
26+
normalizePath(file).replace(normalizePath(config.paths.standaloneApp) + path.posix.sep, "")
2827
);
2928
code = code.replace(
3029
/function loadManifest\((.+?), .+?\) {/,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./ts-parse-file";
22
export * from "./copy-prerendered-routes";
3+
export * from "./normalize-path";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { posix, sep } from "node:path";
2+
3+
export function normalizePath(path: string) {
4+
return path.replaceAll(sep, posix.sep);
5+
}

0 commit comments

Comments
 (0)