@@ -284,11 +284,13 @@ exports.main = function main(argv, options, callback) {
284
284
// Set up transforms
285
285
const transforms = [ ] ;
286
286
if ( args . transform ) {
287
+ let tsNodeRegistered = false ;
287
288
let transformArgs = args . transform ;
288
289
for ( let i = 0 , k = transformArgs . length ; i < k ; ++ i ) {
289
290
let filename = transformArgs [ i ] . trim ( ) ;
290
- if ( / \. t s $ / . test ( filename ) ) {
291
+ if ( ! tsNodeRegistered && filename . endsWith ( '.ts' ) ) {
291
292
require ( "ts-node" ) . register ( { transpileOnly : true , skipProject : true , compilerOptions : { target : "ES2016" } } ) ;
293
+ tsNodeRegistered = true ;
292
294
}
293
295
try {
294
296
const classOrModule = require ( require . resolve ( filename , { paths : [ baseDir , process . cwd ( ) ] } ) ) ;
@@ -370,8 +372,11 @@ exports.main = function main(argv, options, callback) {
370
372
var sourceText = null ; // text reported back to the compiler
371
373
var sourcePath = null ; // path reported back to the compiler
372
374
375
+ const libraryPrefix = exports . libraryPrefix ;
376
+ const libraryFiles = exports . libraryFiles ;
377
+
373
378
// Try file.ts, file/index.ts, file.d.ts
374
- if ( ! internalPath . startsWith ( exports . libraryPrefix ) ) {
379
+ if ( ! internalPath . startsWith ( libraryPrefix ) ) {
375
380
if ( ( sourceText = readFile ( sourcePath = internalPath + ".ts" , baseDir ) ) == null ) {
376
381
if ( ( sourceText = readFile ( sourcePath = internalPath + "/index.ts" , baseDir ) ) == null ) {
377
382
// portable d.ts: uses the .js file next to it in JS or becomes an import in Wasm
@@ -381,22 +386,22 @@ exports.main = function main(argv, options, callback) {
381
386
382
387
// Search library in this order: stdlib, custom lib dirs, paths
383
388
} else {
384
- const plainName = internalPath . substring ( exports . libraryPrefix . length ) ;
389
+ const plainName = internalPath . substring ( libraryPrefix . length ) ;
385
390
const indexName = plainName + "/index" ;
386
- if ( exports . libraryFiles . hasOwnProperty ( plainName ) ) {
387
- sourceText = exports . libraryFiles [ plainName ] ;
388
- sourcePath = exports . libraryPrefix + plainName + ".ts" ;
389
- } else if ( exports . libraryFiles . hasOwnProperty ( indexName ) ) {
390
- sourceText = exports . libraryFiles [ indexName ] ;
391
- sourcePath = exports . libraryPrefix + indexName + ".ts" ;
391
+ if ( libraryFiles . hasOwnProperty ( plainName ) ) {
392
+ sourceText = libraryFiles [ plainName ] ;
393
+ sourcePath = libraryPrefix + plainName + ".ts" ;
394
+ } else if ( libraryFiles . hasOwnProperty ( indexName ) ) {
395
+ sourceText = libraryFiles [ indexName ] ;
396
+ sourcePath = libraryPrefix + indexName + ".ts" ;
392
397
} else { // custom lib dirs
393
398
for ( const libDir of customLibDirs ) {
394
399
if ( ( sourceText = readFile ( plainName + ".ts" , libDir ) ) != null ) {
395
- sourcePath = exports . libraryPrefix + plainName + ".ts" ;
400
+ sourcePath = libraryPrefix + plainName + ".ts" ;
396
401
break ;
397
402
} else {
398
403
if ( ( sourceText = readFile ( indexName + ".ts" , libDir ) ) != null ) {
399
- sourcePath = exports . libraryPrefix + indexName + ".ts" ;
404
+ sourcePath = libraryPrefix + indexName + ".ts" ;
400
405
break ;
401
406
}
402
407
}
@@ -412,7 +417,7 @@ exports.main = function main(argv, options, callback) {
412
417
const absBasePath = path . isAbsolute ( basePath ) ? basePath : path . join ( baseDir , basePath ) ;
413
418
const paths = [ ] ;
414
419
for ( let parts = absBasePath . split ( SEP ) , i = parts . length , k = SEP == "/" ? 0 : 1 ; i >= k ; -- i ) {
415
- if ( parts [ i - 1 ] != "node_modules" ) paths . push ( parts . slice ( 0 , i ) . join ( SEP ) + SEP + "node_modules" ) ;
420
+ if ( parts [ i - 1 ] !== "node_modules" ) paths . push ( parts . slice ( 0 , i ) . join ( SEP ) + SEP + "node_modules" ) ;
416
421
}
417
422
for ( const currentPath of paths . concat ( ...args . path ) . map ( p => path . relative ( baseDir , p ) ) ) {
418
423
if ( args . traceResolution ) stderr . write ( " in " + path . join ( currentPath , packageName ) + EOL ) ;
@@ -435,14 +440,14 @@ exports.main = function main(argv, options, callback) {
435
440
const mainDir = path . join ( currentPath , packageName , mainPath ) ;
436
441
const plainName = filePath ;
437
442
if ( ( sourceText = readFile ( path . join ( mainDir , plainName + ".ts" ) , baseDir ) ) != null ) {
438
- sourcePath = exports . libraryPrefix + packageName + "/" + plainName + ".ts" ;
443
+ sourcePath = libraryPrefix + packageName + "/" + plainName + ".ts" ;
439
444
packageBases . set ( sourcePath . replace ( / \. t s $ / , "" ) , path . join ( currentPath , packageName ) ) ;
440
445
if ( args . traceResolution ) stderr . write ( " -> " + path . join ( mainDir , plainName + ".ts" ) + EOL ) ;
441
446
break ;
442
447
} else if ( ! isPackageRoot ) {
443
448
const indexName = filePath + "/index" ;
444
449
if ( ( sourceText = readFile ( path . join ( mainDir , indexName + ".ts" ) , baseDir ) ) !== null ) {
445
- sourcePath = exports . libraryPrefix + packageName + "/" + indexName + ".ts" ;
450
+ sourcePath = libraryPrefix + packageName + "/" + indexName + ".ts" ;
446
451
packageBases . set ( sourcePath . replace ( / \. t s $ / , "" ) , path . join ( currentPath , packageName ) ) ;
447
452
if ( args . traceResolution ) stderr . write ( " -> " + path . join ( mainDir , indexName + ".ts" ) + EOL ) ;
448
453
break ;
@@ -453,10 +458,8 @@ exports.main = function main(argv, options, callback) {
453
458
}
454
459
}
455
460
}
456
-
457
461
// No such file
458
462
if ( sourceText == null ) return null ;
459
-
460
463
return { sourceText, sourcePath } ;
461
464
}
462
465
0 commit comments