@@ -3,17 +3,16 @@ import ts from "typescript";
3
3
import { parse } from "url" ;
4
4
import { existsSync } from "fs" ;
5
5
6
-
7
6
/* ****************************************************************************************************************** *
8
7
* Helpers
9
8
* ****************************************************************************************************************** */
10
9
11
10
export const normalizePath = ( p : string ) =>
12
11
// Is extended length or has non-ascii chars (respectively)
13
- ( / ^ \\ \\ \? \\ / . test ( p ) || / [ ^ \u0000 - \u0080 ] + / . test ( p ) ) ? p :
14
- // Normalize to forward slash and remove repeating slashes
15
- p . replace ( / [ \\ \/ ] + / g , '/' ) ;
16
-
12
+ / ^ \\ \\ \? \\ / . test ( p ) || / [ ^ \u0000 - \u0080 ] + / . test ( p )
13
+ ? p
14
+ : // Normalize to forward slash and remove repeating slashes
15
+ p . replace ( / [ \\ \/ ] + / g , "/" ) ;
17
16
18
17
/* ****************************************************************************************************************** *
19
18
* Transformer
@@ -48,10 +47,10 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
48
47
paths [ "*" ] = paths [ "*" ] ?. concat ( "*" ) ?? [ "*" ] ;
49
48
50
49
const binds = Object . keys ( paths )
51
- . filter ( key => paths [ key ] . length )
52
- . map ( key => ( {
50
+ . filter ( ( key ) => paths [ key ] . length )
51
+ . map ( ( key ) => ( {
53
52
regexp : new RegExp ( "^" + key . replace ( "*" , "(.*)" ) + "$" ) ,
54
- paths : paths [ key ]
53
+ paths : paths [ key ] ,
55
54
} ) ) ;
56
55
57
56
if ( ! baseUrl || binds . length === 0 ) {
@@ -90,7 +89,8 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
90
89
if ( isUrl ( out ) ) return out ;
91
90
92
91
const filepath = resolve ( baseUrl , out ) ;
93
- if ( ! fileExists ( `${ filepath } /index` ) && ! fileExists ( filepath ) ) continue ;
92
+ if ( ! fileExists ( `${ filepath } /index` ) && ! fileExists ( filepath ) )
93
+ continue ;
94
94
95
95
const resolved = fixupImportPath ( relative ( sourceDir , filepath ) ) ;
96
96
@@ -150,7 +150,7 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
150
150
const fileLiteral = ts . createLiteral ( file ) ;
151
151
152
152
return ts . updateCall ( node , node . expression , node . typeArguments , [
153
- fileLiteral
153
+ fileLiteral ,
154
154
] ) ;
155
155
}
156
156
@@ -247,7 +247,7 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
247
247
visitImportSpecifier as any ,
248
248
ts . isImportSpecifier
249
249
) ;
250
- return elements . some ( e => e )
250
+ return elements . some ( ( e ) => e )
251
251
? ts . updateNamedImports ( node , elements )
252
252
: undefined ;
253
253
}
@@ -313,7 +313,7 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
313
313
visitExportSpecifier as any ,
314
314
ts . isExportSpecifier
315
315
) ;
316
- return elements . some ( e => e )
316
+ return elements . some ( ( e ) => e )
317
317
? ts . updateNamedExports ( node , elements )
318
318
: undefined ;
319
319
}
@@ -323,12 +323,12 @@ const transformer = (_: ts.Program) => (context: ts.TransformationContext) => (
323
323
return resolver . isValueAliasDeclaration ( node ) ? node : undefined ;
324
324
}
325
325
326
- function fixupImportPath ( p :string ) {
326
+ function fixupImportPath ( p : string ) {
327
327
let res = normalizePath ( p ) ;
328
328
329
329
/* Remove implicit extension */
330
330
const ext = extname ( res ) ;
331
- if ( ext && implicitExtensions . includes ( ext . replace ( / ^ \. / , '' ) ) )
331
+ if ( ext && implicitExtensions . includes ( ext . replace ( / ^ \. / , "" ) ) )
332
332
res = res . slice ( 0 , - ext . length ) ;
333
333
334
334
return res ;
0 commit comments