Skip to content

Commit a7805ce

Browse files
fix: windows paths
1 parent b055812 commit a7805ce

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/dev/dev_build_cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { encodeHex } from "@std/encoding/hex";
1010
import { crypto } from "@std/crypto";
1111
import { fsAdapter } from "../fs.ts";
1212
import type { FileTransformer } from "./file_transformer.ts";
13-
import { assertInDir } from "../utils.ts";
13+
import { assertInDir, pathToSpec } from "../utils.ts";
1414
import type { ResolvedBuildConfig } from "./builder.ts";
1515
import { fsItemsToCommands, type FsRouteFile } from "../fs_routes.ts";
1616
import type { Command } from "../commands.ts";
@@ -358,7 +358,7 @@ import staticFileData from "./static-files.json" with { type: "json" };
358358
${
359359
islands
360360
.map((item) => {
361-
const spec = path.relative(outDir, item.server);
361+
const spec = pathToSpec(path.relative(outDir, item.server));
362362
return `import * as ${item.name} from "${spec}";`;
363363
})
364364
.join("\n")
@@ -368,7 +368,7 @@ ${
368368
${
369369
this.#fsRoutes.files
370370
.map((item, i) => {
371-
const spec = path.relative(outDir, item.filePath);
371+
const spec = pathToSpec(path.relative(outDir, item.filePath));
372372
return `import * as fsRoute_${i} from "${spec}"`;
373373
})
374374
.join("\n")

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ export class UniqueNamer {
6363
return name;
6464
}
6565
}
66+
67+
const PATH_TO_SPEC = /[\\/]+/g;
68+
export function pathToSpec(str: string): string {
69+
return str.replaceAll(PATH_TO_SPEC, "/");
70+
}

src/utils_test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "@std/expect";
2-
import { escapeScript, pathToExportName } from "./utils.ts";
2+
import { escapeScript, pathToExportName, pathToSpec } from "./utils.ts";
33

44
Deno.test("filenameToExportName", () => {
55
expect(pathToExportName("/islands/foo.tsx")).toBe("foo");
@@ -52,3 +52,9 @@ Deno.test("escapeScript - json", () => {
5252
"\\u003C!--<\\/ScRIpt>",
5353
);
5454
});
55+
56+
Deno.test("pathToSpec", () => {
57+
expect(pathToSpec("/foo/bar")).toEqual("/foo/bar");
58+
expect(pathToSpec("\\foo\\bar")).toEqual("/foo/bar");
59+
expect(pathToSpec("\\\\foo//bar")).toEqual("/foo/bar");
60+
});

0 commit comments

Comments
 (0)