Skip to content

Commit

Permalink
Merge pull request #159 from aiotter/master
Browse files Browse the repository at this point in the history
fix: import maps does not work on local files
  • Loading branch information
oscarotero authored Jan 9, 2022
2 parents 2ec8d4e + 16704db commit 5f0d950
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ci.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { encode } from "./deps/base64.ts";
import { posix } from "./deps/path.ts";
import { posix, toFileUrl } from "./deps/path.ts";
import { parse } from "./deps/flags.ts";
import { brightGreen, red } from "./deps/colors.ts";
import { Exception } from "./core/errors.ts";
Expand Down Expand Up @@ -30,6 +30,14 @@ export function checkDenoVersion(): void {
}
}

async function ensureUrl(maybeUrl: string) {
try {
return new URL(maybeUrl);
} catch {
return toFileUrl(await Deno.realPath(maybeUrl));
}
}

/**
* Return a data url with the import map of Lume
* Optionally merge it with a custom import map from the user
Expand All @@ -45,7 +53,8 @@ export async function getImportMap(mapFile?: string) {

if (mapFile) {
try {
const file = await (await fetch(mapFile)).text();
const url = await ensureUrl(mapFile);
const file = await (await fetch(url)).text();
const parsedMap = JSON.parse(file) as ImportMap;
map.imports = { ...map.imports, ...parsedMap.imports };
map.scopes = parsedMap.scopes;
Expand Down

0 comments on commit 5f0d950

Please sign in to comment.