Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit bf84e5c

Browse files
committed
fix importmap using local files
1 parent e117ad5 commit bf84e5c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// modified from https://github.com/Microsoft/typescript-tslint-plugin
22
import path from "path";
33
import fs from "fs";
4-
import { URL } from "url";
4+
import { URL, fileURLToPath } from "url";
55

66
import merge from "merge-deep";
77
import ts_module, {
@@ -474,12 +474,19 @@ function parseModuleName(
474474
const moduleUrl = resolve(
475475
moduleName,
476476
parsedImportMap,
477-
new URL(path.dirname(containingFile) + "/", "file:///"),
477+
new URL("file:///" + path.dirname(containingFile) + "/"),
478478
);
479479

480-
return moduleUrl.protocol === "file:"
481-
? moduleUrl.pathname
482-
: moduleUrl.href;
480+
if (moduleUrl.protocol === "file:") {
481+
return fileURLToPath(moduleUrl.href)
482+
}
483+
484+
if (moduleUrl.protocol === "http:" || moduleUrl.protocol === "https:") {
485+
return moduleUrl.href
486+
}
487+
488+
// just support protocol: file, http, https
489+
return undefined;
483490
} catch (e) {
484491
if (logger) logger.info("moduleName: " + moduleName);
485492
if (logger) logger.info("e: " + (e as Error).stack);

0 commit comments

Comments
 (0)