File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { encodeHex } from "@std/encoding/hex";
1010import { crypto } from "@std/crypto" ;
1111import { fsAdapter } from "../fs.ts" ;
1212import type { FileTransformer } from "./file_transformer.ts" ;
13- import { assertInDir } from "../utils.ts" ;
13+ import { assertInDir , pathToSpec } from "../utils.ts" ;
1414import type { ResolvedBuildConfig } from "./builder.ts" ;
1515import { fsItemsToCommands , type FsRouteFile } from "../fs_routes.ts" ;
1616import 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" )
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" )
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 11import { expect } from "@std/expect" ;
2- import { escapeScript , pathToExportName } from "./utils.ts" ;
2+ import { escapeScript , pathToExportName , pathToSpec } from "./utils.ts" ;
33
44Deno . 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+ } ) ;
You can’t perform that action at this time.
0 commit comments