Skip to content

Commit

Permalink
fix: normalize file urls (file:// vs file:///)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansSchall committed Nov 20, 2024
1 parent 272dc93 commit 947a1ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function resolve(
may_fetch: boolean = true,
): Promise<ModuleSpecifier | null> {
// console.log(`%c[RESOLVE] ${id}`, "color:#ff0");
// console.log(`%c[REFERRER] ${referrer}`, "color: gray");
// console.log(`%c[REFERRER] ${referrer} (${isAbsolute(referrer || "") ? "" : "!"}abs)`, "color: gray");
if (o.extra_import_map.has(id)) {
return await resolve(o, graph, await o.extra_import_map.get(id)!, referrer, may_fetch);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function resolve(
}

if (referrer_mod) {
// console.log(`%c[REFERRER] ${referrer_mod.specifier.href}`, "color: gray");
// console.log(`%c[REFERRER] ${referrer_mod.specifier.href}`, "color: green");
const ref = await referrer_mod.resolve_import(id);
if (ref) {
return ref.specifier;
Expand Down
5 changes: 5 additions & 0 deletions src/specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export function parseModuleSpecifier(inp: string | URL): ModuleSpecifier {
}
if (url.protocol === "https:") {
return url as ModuleSpecifier;
} else if (url.protocol === "file:") {
if (!url.href.startsWith("file:///")) {
return new URL(url.href.replace("file://", "file:///")) as ModuleSpecifier;
}
return url as ModuleSpecifier;
} else if (url.pathname.startsWith("/")) {
return new URL(url.href.replace(url.pathname, url.pathname.substring(1))) as ModuleSpecifier;
} else {
Expand Down

0 comments on commit 947a1ba

Please sign in to comment.