File tree Expand file tree Collapse file tree 4 files changed +17
-3
lines changed
Expand file tree Collapse file tree 4 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 11import { dirname , relative , resolve } from "path" ;
22import ts from "typescript" ;
33import slash from "slash" ;
4+ import { parse } from "url" ;
45
56const 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 }
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ export { NoRuntimecodeHere } from "@utils/types-only";
44import { subs , NoRuntimecodeHere } from "@utils" ;
55import "@circular/b" ;
66import { A } from "@circular/a" ;
7+ import * as path from "path" ;
8+
9+ path . sep ;
710
811sum . sum ( 2 , 3 ) ;
912
Original file line number Diff line number Diff line change 88 "declaration" : true ,
99 "baseUrl" : " ./" ,
1010 "paths" : {
11+ "path" : [" https://external.url/path.js" ],
1112 "@*" : [" *" ]
1213 },
1314
Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ files.forEach(file => {
1717} ) ;
1818
1919function 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
2527function bindModuleToFile ( moduleName : string , sourceDir : string ) {
You can’t perform that action at this time.
0 commit comments