Skip to content

Commit 4f9fbfa

Browse files
committed
fix: urls not working
1 parent f36216e commit 4f9fbfa

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { dirname, relative, resolve } from "path";
22
import ts from "typescript";
33
import slash from "slash";
4+
import { parse } from "url";
45

56
const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
67
sourceFile: ts.SourceFile
@@ -28,11 +29,18 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
2829
return sourceFile;
2930
}
3031

32+
function isUrl(s: string) {
33+
return parse(s).protocol !== null;
34+
}
35+
3136
function bindModuleToFile(moduleName: string) {
3237
for (const { regexp, path } of binds) {
3338
const match = regexp.exec(moduleName);
3439
if (match) {
3540
const out = path.replace(/\*/g, match[1]);
41+
if (isUrl(out)) {
42+
return out;
43+
}
3644
const file = slash(relative(sourceDir, resolve(baseUrl, out)));
3745
return file[0] === "." ? file : `./${file}`;
3846
}

tests/__fixtures/core/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export { NoRuntimecodeHere } from "@utils/types-only";
44
import { subs, NoRuntimecodeHere } from "@utils";
55
import "@circular/b";
66
import { A } from "@circular/a";
7+
import * as path from "path";
8+
9+
path.sep;
710

811
sum.sum(2, 3);
912

tests/__fixtures/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"declaration": true,
99
"baseUrl": "./",
1010
"paths": {
11+
"path": ["https://external.url/path.js"],
1112
"@*": ["*"]
1213
},
1314

tests/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ files.forEach(file => {
1717
});
1818

1919
function update(content: string, sourceDir: string) {
20-
return content.replace(/"(@.*)"/g, (_, moduleName) => {
21-
return `"${bindModuleToFile(moduleName, sourceDir)}"`;
22-
});
20+
return content
21+
.replace(/"(@.*)"/g, (_, moduleName) => {
22+
return `"${bindModuleToFile(moduleName, sourceDir)}"`;
23+
})
24+
.replace('"path"', '"https://external.url/path.js"');
2325
}
2426

2527
function bindModuleToFile(moduleName: string, sourceDir: string) {

0 commit comments

Comments
 (0)