Skip to content

Commit b069071

Browse files
committed
normalize windows path
1 parent a5d90ca commit b069071

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

packages/fresh/src/dev/dev_build_cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const WINDOWS_SEPARATOR = pathWin32.SEPARATOR;
2020
/** Normalize a path to use forward slashes so that generated files
2121
* are portable across operating systems (e.g. build on Windows,
2222
* deploy on Linux). */
23-
function toPosix(p: string): string {
23+
export function toPosix(p: string): string {
2424
return p.replaceAll(WINDOWS_SEPARATOR, "/");
2525
}
2626

packages/fresh/src/dev/fs_crawl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type FsAdapter, fsAdapter } from "../fs.ts";
22
import type { WalkEntry } from "@std/fs/walk";
3-
import type { FsRouteFileNoMod } from "./dev_build_cache.ts";
3+
import { type FsRouteFileNoMod, toPosix } from "./dev_build_cache.ts";
44
import * as path from "@std/path";
55
import { pathToPattern } from "../router.ts";
66
import { CommandType } from "../commands.ts";
@@ -86,7 +86,7 @@ export async function crawlRouteDir<State>(
8686

8787
files.push({
8888
id,
89-
filePath: entry.path,
89+
filePath: toPosix(entry.path),
9090
type,
9191
pattern,
9292
routePattern,

packages/fresh/src/dev/fs_crawl_test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "@std/expect/expect";
22
import { createFakeFs } from "../test_utils.ts";
3-
import { walkDir } from "./fs_crawl.ts";
3+
import { crawlRouteDir, walkDir } from "./fs_crawl.ts";
44

55
Deno.test("walkDir - ", async () => {
66
const fs = createFakeFs({
@@ -43,3 +43,35 @@ Deno.test("walkDir - respects skip patterns", async () => {
4343
"routes/api/users.ts",
4444
]);
4545
});
46+
47+
Deno.test("crawlRouteDir.filePath - normalized Windows paths", async () => {
48+
const fs = createFakeFs({
49+
"foo\\bar\\baz.txt": "foo",
50+
"D:\\foo\\bar.tsx": "foo",
51+
});
52+
53+
const rawFiles = await crawlRouteDir(fs, "foo", [], () => {});
54+
55+
expect(rawFiles).toEqual(expect.arrayContaining([
56+
{
57+
id: "/D:/foo/bar",
58+
filePath: "D:/foo/bar.tsx",
59+
type: "route",
60+
pattern: "/D:/foo/bar",
61+
routePattern: "/D:/foo/bar",
62+
lazy: true,
63+
css: [],
64+
overrideConfig: { methods: "ALL" },
65+
},
66+
{
67+
id: "/foo/bar/baz",
68+
filePath: "foo/bar/baz.txt",
69+
type: "route",
70+
pattern: "/foo/bar/baz",
71+
routePattern: "/foo/bar/baz",
72+
lazy: true,
73+
css: [],
74+
overrideConfig: { methods: "ALL" },
75+
},
76+
]));
77+
});

packages/fresh/src/test_utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DEFAULT_CONN_INFO } from "./app.ts";
77
import type { Command } from "./commands.ts";
88
import { fsItemsToCommands, type FsRouteFile } from "./fs_routes.ts";
99
import * as path from "@std/path";
10+
import { toPosix } from "./dev/dev_build_cache.ts";
1011

1112
const STUB = {} as unknown as Deno.ServeHandlerInfo;
1213

@@ -123,7 +124,10 @@ export function createFakeFs(files: Record<string, unknown>): FsAdapter {
123124
},
124125
// deno-lint-ignore require-await
125126
async isDirectory(dir) {
126-
return Object.keys(files).some((file) => file.startsWith(dir + "/"));
127+
return Object.keys(files).some((file) =>
128+
// normalize path to posix before comparing
129+
toPosix(file).startsWith(dir + "/")
130+
);
127131
},
128132
async mkdirp(_dir: string) {
129133
},

0 commit comments

Comments
 (0)