@@ -42,10 +42,7 @@ import { findAndReadConfig } from './configuration';
42
42
*
43
43
* @internal
44
44
*/
45
- export function main (
46
- argv : string [ ] = process . argv . slice ( 2 ) ,
47
- entrypointArgs : Record < string , any > = { }
48
- ) {
45
+ export function main ( argv : string [ ] = process . argv . slice ( 2 ) , entrypointArgs : Record < string , any > = { } ) {
49
46
const args = parseArgv ( argv , entrypointArgs ) ;
50
47
const state : BootstrapState = {
51
48
shouldUseChildProcess : false ,
@@ -174,8 +171,7 @@ function parseArgv(argv: string[], entrypointArgs: Record<string, any>) {
174
171
'--log-error' : '--logError' ,
175
172
'--scope-dir' : '--scopeDir' ,
176
173
'--no-experimental-repl-await' : '--noExperimentalReplAwait' ,
177
- '--experimental-specifier-resolution' :
178
- '--experimentalSpecifierResolution' ,
174
+ '--experimental-specifier-resolution' : '--experimentalSpecifierResolution' ,
179
175
} ,
180
176
{
181
177
argv,
@@ -379,12 +375,7 @@ function phase3(payload: BootstrapState) {
379
375
compilerHost,
380
376
ignore,
381
377
logError,
382
- projectSearchDir : getProjectSearchDir (
383
- cwd ,
384
- scriptMode ,
385
- cwdMode ,
386
- entryPointPath
387
- ) ,
378
+ projectSearchDir : getProjectSearchDir ( cwd , scriptMode , cwdMode , entryPointPath ) ,
388
379
project,
389
380
skipProject,
390
381
skipIgnore,
@@ -396,8 +387,7 @@ function phase3(payload: BootstrapState) {
396
387
scopeDir,
397
388
preferTsExts,
398
389
esm,
399
- experimentalSpecifierResolution :
400
- experimentalSpecifierResolution as ExperimentalSpecifierResolution ,
390
+ experimentalSpecifierResolution : experimentalSpecifierResolution as ExperimentalSpecifierResolution ,
401
391
} ) ;
402
392
403
393
// If ESM is enabled through the parsed tsconfig, stage4 should be run in a child
@@ -432,20 +422,14 @@ function getEntryPointInfo(state: BootstrapState) {
432
422
// `node -e code -i ./script.js` ignores -e
433
423
const executeEval = code != null && ! ( interactive && restArgs . length ) ;
434
424
const executeEntrypoint = ! executeEval && restArgs . length > 0 ;
435
- const executeRepl =
436
- ! executeEntrypoint &&
437
- ( interactive || ( process . stdin . isTTY && ! executeEval ) ) ;
425
+ const executeRepl = ! executeEntrypoint && ( interactive || ( process . stdin . isTTY && ! executeEval ) ) ;
438
426
const executeStdin = ! executeEval && ! executeRepl && ! executeEntrypoint ;
439
427
440
428
/**
441
429
* Unresolved. May point to a symlink, not realpath. May be missing file extension
442
430
* NOTE: resolution relative to cwd option (not `process.cwd()`) is legacy backwards-compat; should be changed in next major: https://github.com/TypeStrong/ts-node/issues/1834
443
431
*/
444
- const entryPointPath = executeEntrypoint
445
- ? isCli
446
- ? resolve ( cwd , restArgs [ 0 ] )
447
- : resolve ( restArgs [ 0 ] )
448
- : undefined ;
432
+ const entryPointPath = executeEntrypoint ? ( isCli ? resolve ( cwd , restArgs [ 0 ] ) : resolve ( restArgs [ 0 ] ) ) : undefined ;
449
433
450
434
return {
451
435
executeEval,
@@ -458,18 +442,11 @@ function getEntryPointInfo(state: BootstrapState) {
458
442
459
443
function phase4 ( payload : BootstrapState ) {
460
444
const { isInChildProcess, tsNodeScript } = payload ;
461
- const { version, showConfig, restArgs, code, print, argv } =
462
- payload . parseArgvResult ;
445
+ const { version, showConfig, restArgs, code, print, argv } = payload . parseArgvResult ;
463
446
const { cwd } = payload . phase2Result ! ;
464
447
const { preloadedConfig } = payload . phase3Result ! ;
465
448
466
- const {
467
- entryPointPath,
468
- executeEntrypoint,
469
- executeEval,
470
- executeRepl,
471
- executeStdin,
472
- } = getEntryPointInfo ( payload ) ;
449
+ const { entryPointPath, executeEntrypoint, executeEval, executeRepl, executeStdin } = getEntryPointInfo ( payload ) ;
473
450
474
451
/**
475
452
* <repl>, [stdin], and [eval] are all essentially virtual files that do not exist on disc and are backed by a REPL
@@ -543,13 +520,10 @@ function phase4(payload: BootstrapState) {
543
520
} ) ;
544
521
register ( service ) ;
545
522
546
- if ( replStuff )
547
- replStuff . state . path = join ( cwd , REPL_FILENAME ( service . ts . version ) ) ;
523
+ if ( replStuff ) replStuff . state . path = join ( cwd , REPL_FILENAME ( service . ts . version ) ) ;
548
524
549
525
if ( isInChildProcess )
550
- (
551
- require ( './child/child-loader' ) as typeof import ( './child/child-loader' )
552
- ) . lateBindHooks ( createEsmHooks ( service ) ) ;
526
+ ( require ( './child/child-loader' ) as typeof import ( './child/child-loader' ) ) . lateBindHooks ( createEsmHooks ( service ) ) ;
553
527
554
528
// Bind REPL service to ts-node compiler service (chicken-and-egg problem)
555
529
replStuff ?. repl . setService ( service ) ;
@@ -566,18 +540,14 @@ function phase4(payload: BootstrapState) {
566
540
if ( version >= 3 ) {
567
541
console . log ( `ts-node v${ VERSION } ${ dirname ( __dirname ) } ` ) ;
568
542
console . log ( `node ${ process . version } ` ) ;
569
- console . log (
570
- `compiler v${ service . ts . version } ${ service . compilerPath ?? '' } `
571
- ) ;
543
+ console . log ( `compiler v${ service . ts . version } ${ service . compilerPath ?? '' } ` ) ;
572
544
process . exit ( 0 ) ;
573
545
}
574
546
575
547
if ( showConfig ) {
576
548
const ts = service . ts as any as TSInternal ;
577
549
if ( typeof ts . convertToTSConfig !== 'function' ) {
578
- console . error (
579
- 'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig'
580
- ) ;
550
+ console . error ( 'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig' ) ;
581
551
process . exit ( 1 ) ;
582
552
}
583
553
let moduleTypes = undefined ;
@@ -586,20 +556,13 @@ function phase4(payload: BootstrapState) {
586
556
const showRelativeTo = dirname ( service . configFilePath ! ) ;
587
557
moduleTypes = { } as Record < string , string > ;
588
558
for ( const [ key , value ] of Object . entries ( service . options . moduleTypes ) ) {
589
- moduleTypes [
590
- relative (
591
- showRelativeTo ,
592
- resolve ( service . options . optionBasePaths ?. moduleTypes ! , key )
593
- )
594
- ] = value ;
559
+ moduleTypes [ relative ( showRelativeTo , resolve ( service . options . optionBasePaths ?. moduleTypes ! , key ) ) ] = value ;
595
560
}
596
561
}
597
562
const json = {
598
563
[ 'ts-node' ] : {
599
564
...service . options ,
600
- require : service . options . require ?. length
601
- ? service . options . require
602
- : undefined ,
565
+ require : service . options . require ?. length ? service . options . require : undefined ,
603
566
moduleTypes,
604
567
optionBasePaths : undefined ,
605
568
compilerOptions : undefined ,
@@ -621,10 +584,7 @@ function phase4(payload: BootstrapState) {
621
584
}
622
585
623
586
// Prepend `ts-node` arguments to CLI for child processes.
624
- process . execArgv . push (
625
- tsNodeScript ,
626
- ...argv . slice ( 2 , argv . length - restArgs . length )
627
- ) ;
587
+ process . execArgv . push ( tsNodeScript , ...argv . slice ( 2 , argv . length - restArgs . length ) ) ;
628
588
629
589
// TODO this comes from BootstrapState
630
590
process . argv = [ process . argv [ 1 ] ]
@@ -633,10 +593,7 @@ function phase4(payload: BootstrapState) {
633
593
634
594
// Execute the main contents (either eval, script or piped).
635
595
if ( executeEntrypoint ) {
636
- if (
637
- payload . isInChildProcess &&
638
- versionGteLt ( process . versions . node , '18.6.0' , '18.7.0' )
639
- ) {
596
+ if ( payload . isInChildProcess && versionGteLt ( process . versions . node , '18.6.0' , '18.7.0' ) ) {
640
597
// HACK workaround node regression
641
598
require ( '../dist-raw/runmain-hack.js' ) . run ( entryPointPath ) ;
642
599
} else {
@@ -647,13 +604,7 @@ function phase4(payload: BootstrapState) {
647
604
// If stdin runs, eval and repl will not.
648
605
if ( executeEval ) {
649
606
addBuiltinLibsToObject ( global ) ;
650
- evalAndExitOnTsError (
651
- evalStuff ! . repl ,
652
- evalStuff ! . module ! ,
653
- code ! ,
654
- print ,
655
- 'eval'
656
- ) ;
607
+ evalAndExitOnTsError ( evalStuff ! . repl , evalStuff ! . module ! , code ! , print , 'eval' ) ;
657
608
}
658
609
659
610
if ( executeRepl ) {
@@ -680,23 +631,15 @@ function phase4(payload: BootstrapState) {
680
631
/**
681
632
* Get project search path from args.
682
633
*/
683
- function getProjectSearchDir (
684
- cwd ?: string ,
685
- scriptMode ?: boolean ,
686
- cwdMode ?: boolean ,
687
- scriptPath ?: string
688
- ) {
634
+ function getProjectSearchDir ( cwd ?: string , scriptMode ?: boolean , cwdMode ?: boolean , scriptPath ?: string ) {
689
635
// Validate `--script-mode` / `--cwd-mode` / `--cwd` usage is correct.
690
636
if ( scriptMode && cwdMode ) {
691
637
throw new TypeError ( '--cwd-mode cannot be combined with --script-mode' ) ;
692
638
}
693
639
if ( scriptMode && ! scriptPath ) {
694
- throw new TypeError (
695
- '--script-mode must be used with a script name, e.g. `ts-node --script-mode <script.ts>`'
696
- ) ;
640
+ throw new TypeError ( '--script-mode must be used with a script name, e.g. `ts-node --script-mode <script.ts>`' ) ;
697
641
}
698
- const doScriptMode =
699
- scriptMode === true ? true : cwdMode === true ? false : ! ! scriptPath ;
642
+ const doScriptMode = scriptMode === true ? true : cwdMode === true ? false : ! ! scriptPath ;
700
643
if ( doScriptMode ) {
701
644
// Use node's own resolution behavior to ensure we follow symlinks.
702
645
// scriptPath may omit file extension or point to a directory with or without package.json.
@@ -739,9 +682,7 @@ function requireResolveNonCached(absoluteModuleSpecifier: string) {
739
682
const { dir , base } = parsePath ( absoluteModuleSpecifier ) ;
740
683
const relativeModuleSpecifier = `./${ base } ` ;
741
684
742
- const req = Module . createRequire (
743
- join ( dir , 'imaginaryUncacheableRequireResolveScript' )
744
- ) ;
685
+ const req = Module . createRequire ( join ( dir , 'imaginaryUncacheableRequireResolveScript' ) ) ;
745
686
return req . resolve ( relativeModuleSpecifier , {
746
687
paths : [
747
688
`${ guaranteedNonexistentDirectoryPrefix } ${ guaranteedNonexistentDirectorySuffix ++ } ` ,
@@ -775,11 +716,7 @@ function evalAndExitOnTsError(
775
716
}
776
717
777
718
if ( isPrinted ) {
778
- console . log (
779
- typeof result === 'string'
780
- ? result
781
- : inspect ( result , { colors : process . stdout . isTTY } )
782
- ) ;
719
+ console . log ( typeof result === 'string' ? result : inspect ( result , { colors : process . stdout . isTTY } ) ) ;
783
720
}
784
721
}
785
722
0 commit comments