@@ -13,6 +13,17 @@ const transformer = <T extends ts.Node>(_: ts.Program) => {
1313 resolve : paths [ key ] [ 0 ] // TODO should check if is not empty
1414 } ) ) ;
1515 let fileDir = "" ;
16+ function findFileInPaths ( text : string ) {
17+ for ( const path of regPaths ) {
18+ const match = text . match ( path . regexp ) ;
19+ if ( match ) {
20+ const out = path . resolve . replace ( / \* / g, match [ 1 ] ) ;
21+ const file = slash ( relative ( fileDir , resolve ( baseUrl , out ) ) ) ;
22+ return file ;
23+ }
24+ }
25+ return null ;
26+ }
1627 function visit ( node : ts . Node ) : ts . Node {
1728 if ( ts . isSourceFile ( node ) ) {
1829 fileDir = dirname ( node . fileName ) ;
@@ -22,11 +33,8 @@ const transformer = <T extends ts.Node>(_: ts.Program) => {
2233 ts . isImportDeclaration ( node ) &&
2334 ts . isStringLiteral ( node . moduleSpecifier )
2435 ) {
25- for ( const path of regPaths ) {
26- const match = node . moduleSpecifier . text . match ( path . regexp ) ;
27- if ( match === null ) continue ;
28- const out = path . resolve . replace ( / \* / g, match [ 1 ] ) ;
29- const file = slash ( relative ( fileDir , resolve ( baseUrl , out ) ) ) ;
36+ const file = findFileInPaths ( node . moduleSpecifier . text ) ;
37+ if ( file ) {
3038 return ts . updateImportDeclaration (
3139 node ,
3240 node . decorators ,
@@ -37,6 +45,23 @@ const transformer = <T extends ts.Node>(_: ts.Program) => {
3745 ) ;
3846 }
3947 }
48+ if (
49+ ts . isExportDeclaration ( node ) &&
50+ node . moduleSpecifier &&
51+ ts . isStringLiteral ( node . moduleSpecifier )
52+ ) {
53+ const file = findFileInPaths ( node . moduleSpecifier . text ) ;
54+ if ( file ) {
55+ return ts . updateExportDeclaration (
56+ node ,
57+ node . decorators ,
58+ node . modifiers ,
59+ node . exportClause ,
60+ // If it's in the same level or below add the ./
61+ ts . createLiteral ( file [ 0 ] === "." ? file : `./${ file } ` )
62+ ) ;
63+ }
64+ }
4065 return ts . visitEachChild ( node , visit , context ) ;
4166 }
4267 return ts . visitNode ( rootNode , visit ) ;
0 commit comments