ÿØÿà JFIF    ÿÛ „  ( %"1!%)+...383,7(-.+  -+++--++++---+-+-----+---------------+---+-++7-----ÿÀ  ß â" ÿÄ     ÿÄ H    !1AQaq"‘¡2B±ÁÑð#R“Ò Tbr‚²á3csƒ’ÂñDS¢³$CÿÄ   ÿÄ %  !1AQa"23‘ÿÚ   ? ôÿ ¨pŸªáÿ —åYõõ\?àÒü©ŠÄï¨pŸªáÿ —åYõõ\?àÓü©ŠÄá 0Ÿªáÿ Ÿå[úƒ ú®ði~TÁbqÐ8OÕpÿ ƒOò¤Oè`–RÂáœá™êi€ßÉ< FtŸI“öÌ8úDf´°å}“¾œ6  öFá°y¥jñÇh†ˆ¢ã/ÃÐ:ªcÈ "Y¡ðÑl>ÿ ”ÏËte:qž\oäŠe÷󲍷˜HT4&ÿ ÓÐü6ö®¿øþßèô Ÿ•7Ñi’•j|“ñì>b…þS?*Óôÿ ÓÐü*h¥£ír¶ü UãS炟[AÐaè[ûª•õ&õj?†Éö+EzP—WeÒírJFt ‘BŒ†Ï‡%#tE Øz ¥OÛ«!1›üä±Í™%ºÍãö]°î(–:@<‹ŒÊö×òÆt¦ãº+‡¦%ÌÁ²h´OƒJŒtMÜ>ÀÜÊw3Y´•牋4ǍýʏTì>œú=Íwhyë,¾Ôò×õ¿ßÊa»«þˆѪQ|%6ž™A õ%:øj<>É—ÿ Å_ˆCbõ¥š±ý¯Ýƒï…¶|RëócÍf溪“t.СøTÿ *Ä¿-{†çàczůŽ_–^XþŒ±miB[X±d 1,é”zEù»& î9gœf™9Ð'.;—™i}!ôšåîqêÛ٤ёý£½ÆA–àôe"A$˝Úsäÿ ÷Û #°xŸëí(l »ý3—¥5m! rt`†0~'j2(]S¦¦kv,ÚÇ l¦øJA£Šƒ J3E8ÙiŽ:cÉžúeZ°€¯\®kÖ(79«Ž:¯X”¾³Š&¡* ….‰Ž(ÜíŸ2¥ª‡×Hi²TF¤ò[¨íÈRëÉ䢍mgÑ.Ÿ<öäS0í„ǹÁU´f#Vß;Õ–…P@3ío<ä-±»Ž.L|kªÀê›fÂ6@»eu‚|ÓaÞÆŸ…¨ááå>åŠ?cKü6ùTÍÆ”†sĤÚ;H2RÚ†õ\Ö·Ÿn'¾ ñ#ºI¤Å´%çÁ­‚â7›‹qT3Iï¨ÖÚ5I7Ë!ÅOóŸ¶øÝñØôת¦$Tcö‘[«Ö³šÒ';Aþ ¸èíg A2Z"i¸vdÄ÷.iõ®§)¿]¤À†–‡É&ä{V¶iŽ”.Ó×Õÿ û?h¬Mt–íª[ÿ Ñÿ ÌV(í}=ibÔ¡›¥¢±b Lô¥‡piη_Z<‡z§èŒ)iÖwiÇ 2hÙ3·=’d÷8éŽ1¦¸c¤µ€7›7Ø ð\á)} ¹fËí›pAÃL%âc2 í§æQz¿;T8sæ°qø)QFMð‰XŒÂ±N¢aF¨…8¯!U  Z©RÊ ÖPVÄÀÍin™Ì-GˆªÅËŠ›•zË}º±ŽÍFò¹}Uw×#ä5B¤{î}Ð<ÙD é©¤&‡ïDbàÁôMÁ." ¤‡ú*õ'VŽ|¼´Úgllº¼klz[Æüï÷Aób‡Eÿ dÑ»Xx9ÃÜ£ÁT/`¼¸vI±Ýµ·Ë‚“G³þ*Ÿû´r|*}<¨îºœ @¦mÄ’M¹”.œ«Y–|6ÏU¤jç¥ÕÞqO ˜kDÆÁ¨5ÿ š;ÐЦ¦€GÙk \ –Þ=â¼=SͧµªS°ÚÍpÜãQűÀõ¬?ÃÁ1Ñ•õZà?hóœ€ L¦l{Y*K˜Ù›zc˜–ˆâ ø+¾ ­-Ök¥%ùEÜA'}ˆ><ÊIè“bpÍ/qÞâvoX€w,\úªò6Z[XdÒæ­@Ö—€$òJí#é>'°Ú ôª˜<)4ryÙ£|óAÅn5žêŸyÒäMÝ2{"}‰–¤l÷ûWX\l¾Á¸góÉOÔ /óñB¤f¸çñ[.P˜ZsÊË*ßT܈§QN¢’¡¨§V¼(Üù*eÕ“”5T¨‹Âê¥FŒã½Dü[8'Ò¥a…Ú¶k7a *•›¼'Ò·\8¨ª\@\õ¢¦íq+DÙrmÎ…_ªæ»ŠÓœ¡¯’Ré9MÅ×D™lælffc+ŒÑ,ý™ÿ ¯þǤ=Å’Á7µ÷ÚÛ/“Ü€ñýã¼àí¾ÕÑ+ƒ,uµMâÀÄbm:ÒÎPæ{˜Gz[ƒ¯«® KHà`ߨŠéí¯P8Aq.C‰ à€kòpj´kN¶qô€…Õ,ÜNŠª-­{Zö’æû44‰sŽè‰îVíRœÕm" 6?³D9¡ÇTíÅꋇ`4«¸ÝÁô ï’ýorqКÇZ«x4Žâéþuïf¹µö[P ,Q£éaX±`PÉÍZ ¸äYúg üAx ’6Lê‚xÝÓ*äQ  Ï’¨hÍ =²,6ï#rÃ<¯–£»ƒ‹,–ê•€ aÛsñ'%Æ"®ÛüìBᝠHÚ3ß°©$“XnœÖ’î2ËTeûìxîß ¦å¿çÉ ðK§þ{‘t‚Ϋ¬jéîZ[ ”š7L¥4VÚCE×]m¤Øy”ä4-dz£œ§¸x.*ãÊÊ b÷•h:©‡¦s`BTÁRû¾g⻩‹jø sF¢àJøFl‘È•Xᓁà~*j¯ +(ÚÕ6-£¯÷GŠØy‚<Ç’.F‹Hœw(+)ÜÜâÈzÄäT§FߘãÏ;DmVœ3Àu@mÚüXÝü•3B¨òÌÁÛ<·ÃÜ z,Ì@õÅ·d2]ü8s÷IôÞ¯^Ç9¢u„~ëAŸï4«M? K]­ÅàPl@s_ p:°¬ZR”´›JC[CS.h‹ƒïËœ«Æ]–÷ó‚wR×k7X‰k›‘´ù¦=¡«‰¨¨Â')—71ó’c‡Ðúµ `é.{§p¹ój\Ž{1h{o±Ý=áUÊïGÖŒõ–-BÄm+AZX¶¡ ïHðæ¥JmÙ;…䡟ˆ¦ ° äšiÉg«$üMk5¤L“’çÊvïâï ,=f“"íἊ5ô¬x6{ɏžID0e¸vçmi'︧ºð9$ò¹÷*£’9ÿ ²TÔ…×>JV¥}Œ}$p[bÔ®*[jzS*8 ”·T›Í–ñUîƒwo$áè=LT™ç—~ô·¤ÈÚ$榍q‰„+´kFm)ž‹©i–ËqÞŠ‰à¶ü( ‚•§ •°ò·‡#5ª•µÊ﯅¡X¨šÁ*F#TXJÊ ušJVÍ&=iÄs1‚3•'fý§5Ñ<=[íÞ­ PÚ;ѱÌ_~Ä££8rÞ ²w;’hDT°>ÈG¬8Á²ÚzŽ®ò®qZcqJêäÞ-ö[ܘbň±çb“ж31²n×iƒðÕ;1¶þÉ ªX‰,ßqÏ$>•î íZ¥Z 1{ç൵+ƒÕµ¥°T$§K]á»Ûï*·¤tMI’ÂZbŽÕiÒ˜}bÓ0£ª5›¨ [5Ž^ÝœWøÂÝh° ¢OWun£¤5 a2Z.G2³YL]jåtì”ä ÁÓ‘%"©<Ôúʰsº UZvä‡ÄiÆÒM .÷V·™ø#kèýiíÌ–ª)µT[)BˆõÑ xB¾B€ÖT¨.¥~ð@VĶr#¸ü*åZNDŽH;âi ],©£öØpù(šºãö¼T.uCê•4@ÿ GÕÛ)Cx›®0ø#:ÏðFÒbR\(€€Ä®fã4Þ‰Fä¯HXƒÅ,†öEÑÔÜ]Öv²?tLÃvBY£ú6Êu5ÅAQ³1‘’¬x–HŒÐ‡ ^ ¸KwJôÖŽ5×CÚ¨vÜ«/B0$×k°=ðbÇ(Ï)w±A†Á† 11Í=èQšµ626ŒÜ/`G«µ<}—-Ö7KEHÈÉðóȤmݱû±·ø«Snmá=“䫚mݱŸ¡¶~ó·“äUóJæúòB|E LêŽy´jDÔ$G¢þÐñ7óR8ýÒ…Ç› WVe#·Ÿ p·Fx~•ݤF÷0Èÿ K¯æS<6’¡WШ; ´ÿ ¥Êø\Òuî†åÝ–VNœkÒ7oòX¨Á­Ø÷FÎÑä±g÷ÿ M~Çî=p,X´ ÝÌÚÅ‹’ÃjÖ.ØöÏñ qïQ¤ÓZE†° =6·]܈ s¸>v•Ž^Ý\wq9r‰Î\¸¡kURÒ$­*‹Nq?Þª*!sŠÆ:TU_u±T+øX¡ ®¹¡,ÄâÃBTsÜ$Ø›4m椴zÜK]’’›Pƒ @€#â˜`é¹=I‡fiV•Ôî“nRm+µFPOhÍ0B£ €+¬5c v•:P'ÒyÎ ‰V~‚Ó†ÖuókDoh$å\*ö%Ю=£«…aȼ½÷Û.-½VŒŠ¼'lyî±1¬3ó#ÞE¿ÔS¤gV£m›=§\û"—WU¤ÚǼÿ ÂnÁGŒÃ ‚õN D³õNÚíŒÕ;HôyÄÈ©P¹Ä{:?R‘Ô¨âF÷ø£bÅó® JS|‚R÷ivýáâ€Æé¡è³´IئÑT!§˜•ت‚¬â@q€wnïCWÄ@JU€ê¯m6]Ï:£âx'+ÒðXvÓ¦Úm=–´7œ $ì“B£~p%ÕŸUþ« N@¼üï~w˜ñø5®—'Ôe»¤5ã//€ž~‰Tþ›Å7•#¤× Íö pÄ$ùeåì*«ÓŠEØWEÈsßg ¦ûvžSsLpºÊW–âµEWöˬH; ™!CYõZ ÃÄf æ#1W. \uWâ\,\Çf j’<qTbên›Î[vxx£ë 'ö¨1›˜ÀM¼Pÿ H)ƒêêŒA7s,|F“ 꺸k³9Ìö*ç®;Ö!Ö$Eiž•¹ÒÚ†ýóéÝû¾ÕS®ó$’NÝäŸz¤5r¦ãÄÃD÷Üø!°ø‡Ô&@m™Ì^Ãä­d q5Lnÿ N;.6½·N|#ä"1Nƒx“ã<3('&ñßt  ~ªu”1Tb㫨9ê–›–bìd$ߣ=#ÕãÒmU¯eí$EFù5ýYô櫨æì™Ç—±ssM]·á¿0ÕåJRÓªîiƒ+O58ÖñªŠÒx" \µâá¨i’¤i —Ö ” M+M¤ë9‚‰A¦°Qõ¾ßøK~¼Ã‘g…Ö´~÷Ï[3GUœÒ½#…kàÔ®Ò”‰³·dWV‰IP‰Ú8u¹”E ÖqLj¾êÕCBš{A^Âß;–¨`¯¬ìö ˼ ×tìø.tƐm*n¨y4o&Àx¥n¦×î‡aupáÛj8¿m›è¶ã!o½;ß0y^ý×^EÑ¿ÒjzŒ­)vÚÑnÄL …^ªô× ‡—‚3k Îý­hï]içå–îÏ*÷ñþ»Ô CÒjøjÍznˆ´ ¹#b'Fô‹ ‰v¥'’à'T´ƒHýÍ%M‰ ƒ&ÆÇŒï1 ‘ –Þ ‰i¬s žR-Ÿ kЬá¬7:þ 0ŒÅÒÕ/aÙ¬ÃÝ#Úøœ ©aiVc‰. ¹¦ãµ” ›Yg¦›ÆÎýº°f³7ƒhá·¸­}&D9¡ÂsÉÙÞèŠõØàC™¨ñbFC|´Ü(ŸƒÚÒ-%»'a Ì¿)ËÇn¿úÿ ÞŽX…4ÊÅH^ôΑí@ù¹Eh¶“L8Çjù ¼ÎåVªóR©Ï5uà V4lZß®=€xÖŸ–ÑÈ ÷”¨°¾__yM1tÉ?uÆþIkÄgæ@þ[¢†°XÃJ£j·:nkÅ¢u ‘}âGzö­/IµèЬ¼48q¦F°ŽR¼=ûì{´¯RýicS ÕÛ íNtÍÙï£,w4rêì®»~x(©Uñ§#Ñ&œÕ¤>ÎåÍÓ9’Ö{9eV­[Öjâ²ãu]˜å2›qÑšÕJç0€sÄ|Êëè0튔bÁ>“{×_F`Ø©ºê:µä,v¤ðfc1±"«ÔÍän1#=· Âøv~H½ÐßA¾¿Ü€Óš]Õ; I¾÷ç‚Qi†î¹9ywÔKG˜áñ zQY—§ÃÕZ07§X‚ Áh;ÁM)iÌCH-¯T‘ë|A0{Ò½LÚ–TâÖkÜ’dÀ“rmm»”جPF³ÖcbE§T€ÒxKºû’Ó®7±²(\4ŽÃ¸Uu@j™yĵ;³µ!Á¢b.W¤=mõ´êµK k ¸K^ÜÛ#p*Ü14qkZç5ïë †°5Ï%ÍÛ<Õ¤×Ô¥ê†C Õ´¼ú$ƒÖ“”]Ù¬qÞÚ[4©ý!ûÏ—Áb쳐XµA¬â~`›Çr¸8ìùÝ䫦<>ä÷«?xs´ÇÑ /á;¹øüÊÈÙà{"@Žïzâ¬[âß‚ U_<ÇŸ½4èN˜ú61®qŠu ¦þF£»äJ_ˆÙÎ~ ÞAã–݄ϗrŠD;xTž‘ô`É«…suãO`?³à™ô Lý#Íc5öoæØ‚y´´÷«ZR§<&JÇ+éâô´€i!Àˆ0æAoàðLèÖ-2ŸõW.’t^–(KÁmHµV@xÜÇy®Ñø­â^:Ú3w· 7½¹°ñ¸â¹®:',«Mœ—n­Á+Ãbš LÈ‘ÄnRÓÅœ%¦²‰¨ùQ:¤f‚ "PÕtô¸…cæl…&˜Ú˜Ôkv‹ž+vŠ,=¢v­6—Xy*¥t£«<™:“aîϲ=¦6rO]XI¿Œ÷¤zÚ­›¶ 6÷”w\d ü~v®ˆÌk«^m<ÿ ¢‰Õ\)ùºŽ;… lîÙÅEŠ®cѾ@vnMÏ,¼“ñ•ŽBxðÃzãÇç%3ˆ"}Ù•Åî> BÉú;Ò]V+P˜F_´ßé> Øše|ï‡ÄOmFæÇ ãqÞ$/xÐx­z`ï9"œÜij‚!7.\Td…9M‡•iŽ‹¾‘50ÞŽn¥ß4ÉôO ¹*í^QêËÜÇÌ8=ާs‰'ÂëÙ«á%Pú[O †ÅP¯Vsް.‰,kc¶ ¬A9n˜XÎ-ÞšN["¹QÕ‰ƒMýÁߺXJæÍaLj¾×Ãmã¾ãÚ uñÒþåQô¦¥ /ÄUx:‚ÍÜ’ Đ©ØÝ3V¨‰ÕnÐ6ó*óúK­«…c ¯U òhsý­jóÔj#,ímŒRµ«lbïUTŒÑ8†Ä0œÏr`ð¡¬É Ї ë"À² ™ 6¥ f¶ ¢ÚoܱԷ-<Àî)†a¶ž'Ú»¨TXqØæ¶÷YÄHy˜9ÈIW­YÀuMFë ºÏ’AqÌ4·/Ú †ô'i$øä­=Ä Ý|öK×40è|È6p‘0§)o¥ctî§H+CA-“ xØ|ÐXАç l8íºð3Ø:³¤¬KX¯UÿÙ #!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bootstrap = exports.main = void 0; const path_1 = require("path"); const util_1 = require("util"); const Module = require("module"); let arg; const util_2 = require("./util"); const repl_1 = require("./repl"); const index_1 = require("./index"); const node_internal_modules_cjs_helpers_1 = require("../dist-raw/node-internal-modules-cjs-helpers"); const spawn_child_1 = require("./child/spawn-child"); const configuration_1 = require("./configuration"); /** * Main `bin` functionality. * * This file is split into a chain of functions (phases), each one adding to a shared state object. * This is done so that the next function can either be invoked in-process or, if necessary, invoked in a child process. * * The functions are intentionally given uncreative names and left in the same order as the original code, to make a * smaller git diff. */ function main(argv = process.argv.slice(2), entrypointArgs = {}) { const args = parseArgv(argv, entrypointArgs); const state = { shouldUseChildProcess: false, isInChildProcess: false, isCli: true, tsNodeScript: __filename, parseArgvResult: args, }; return bootstrap(state); } exports.main = main; /** @internal */ function bootstrap(state) { if (!state.phase2Result) { state.phase2Result = phase2(state); if (state.shouldUseChildProcess && !state.isInChildProcess) { // Note: When transitioning into the child-process after `phase2`, // the updated working directory needs to be preserved. return (0, spawn_child_1.callInChild)(state); } } if (!state.phase3Result) { state.phase3Result = phase3(state); if (state.shouldUseChildProcess && !state.isInChildProcess) { // Note: When transitioning into the child-process after `phase2`, // the updated working directory needs to be preserved. return (0, spawn_child_1.callInChild)(state); } } return phase4(state); } exports.bootstrap = bootstrap; function parseArgv(argv, entrypointArgs) { arg !== null && arg !== void 0 ? arg : (arg = require('arg')); // HACK: technically, this function is not marked @internal so it's possible // that libraries in the wild are doing `require('ts-node/dist/bin').main({'--transpile-only': true})` // We can mark this function @internal in next major release. // For now, rewrite args to avoid a breaking change. entrypointArgs = { ...entrypointArgs }; for (const key of Object.keys(entrypointArgs)) { entrypointArgs[key.replace(/([a-z])-([a-z])/g, (_$0, $1, $2) => `${$1}${$2.toUpperCase()}`)] = entrypointArgs[key]; } const args = { ...entrypointArgs, ...arg({ // Node.js-like options. '--eval': String, '--interactive': Boolean, '--print': Boolean, '--require': [String], // CLI options. '--help': Boolean, '--cwdMode': Boolean, '--scriptMode': Boolean, '--version': arg.COUNT, '--showConfig': Boolean, '--esm': Boolean, // Project options. '--cwd': String, '--files': Boolean, '--compiler': String, '--compilerOptions': util_2.parse, '--project': String, '--ignoreDiagnostics': [String], '--ignore': [String], '--transpileOnly': Boolean, '--transpiler': String, '--swc': Boolean, '--typeCheck': Boolean, '--compilerHost': Boolean, '--pretty': Boolean, '--skipProject': Boolean, '--skipIgnore': Boolean, '--preferTsExts': Boolean, '--logError': Boolean, '--emit': Boolean, '--scope': Boolean, '--scopeDir': String, '--noExperimentalReplAwait': Boolean, '--experimentalSpecifierResolution': String, // Aliases. '-e': '--eval', '-i': '--interactive', '-p': '--print', '-r': '--require', '-h': '--help', '-s': '--script-mode', '-v': '--version', '-T': '--transpileOnly', '-H': '--compilerHost', '-I': '--ignore', '-P': '--project', '-C': '--compiler', '-D': '--ignoreDiagnostics', '-O': '--compilerOptions', '--dir': '--cwd', // Support both tsc-style camelCase and node-style hypen-case for *all* flags '--cwd-mode': '--cwdMode', '--script-mode': '--scriptMode', '--show-config': '--showConfig', '--compiler-options': '--compilerOptions', '--ignore-diagnostics': '--ignoreDiagnostics', '--transpile-only': '--transpileOnly', '--type-check': '--typeCheck', '--compiler-host': '--compilerHost', '--skip-project': '--skipProject', '--skip-ignore': '--skipIgnore', '--prefer-ts-exts': '--preferTsExts', '--log-error': '--logError', '--scope-dir': '--scopeDir', '--no-experimental-repl-await': '--noExperimentalReplAwait', '--experimental-specifier-resolution': '--experimentalSpecifierResolution', }, { argv, stopAtPositional: true, }), }; // Only setting defaults for CLI-specific flags // Anything passed to `register()` can be `undefined`; `create()` will apply // defaults. const { '--cwd': cwdArg, '--help': help = false, '--scriptMode': scriptMode, '--cwdMode': cwdMode, '--version': version = 0, '--showConfig': showConfig, '--require': argsRequire = [], '--eval': code = undefined, '--print': print = false, '--interactive': interactive = false, '--files': files, '--compiler': compiler, '--compilerOptions': compilerOptions, '--project': project, '--ignoreDiagnostics': ignoreDiagnostics, '--ignore': ignore, '--transpileOnly': transpileOnly, '--typeCheck': typeCheck, '--transpiler': transpiler, '--swc': swc, '--compilerHost': compilerHost, '--pretty': pretty, '--skipProject': skipProject, '--skipIgnore': skipIgnore, '--preferTsExts': preferTsExts, '--logError': logError, '--emit': emit, '--scope': scope = undefined, '--scopeDir': scopeDir = undefined, '--noExperimentalReplAwait': noExperimentalReplAwait, '--experimentalSpecifierResolution': experimentalSpecifierResolution, '--esm': esm, _: restArgs, } = args; return { // Note: argv and restArgs may be overwritten by child process argv: process.argv, restArgs, cwdArg, help, scriptMode, cwdMode, version, showConfig, argsRequire, code, print, interactive, files, compiler, compilerOptions, project, ignoreDiagnostics, ignore, transpileOnly, typeCheck, transpiler, swc, compilerHost, pretty, skipProject, skipIgnore, preferTsExts, logError, emit, scope, scopeDir, noExperimentalReplAwait, experimentalSpecifierResolution, esm, }; } function phase2(payload) { const { help, version, cwdArg, esm } = payload.parseArgvResult; if (help) { console.log(` Usage: ts-node [options] [ -e script | script.ts ] [arguments] Options: -e, --eval [code] Evaluate code -p, --print Print result of \`--eval\` -r, --require [path] Require a node module before execution -i, --interactive Opens the REPL even if stdin does not appear to be a terminal --esm Bootstrap with the ESM loader, enabling full ESM support --swc Use the faster swc transpiler -h, --help Print CLI usage -v, --version Print module version information. -vvv to print additional information --showConfig Print resolved configuration and exit -T, --transpileOnly Use TypeScript's faster \`transpileModule\` or a third-party transpiler -H, --compilerHost Use TypeScript's compiler host API -I, --ignore [pattern] Override the path patterns to skip compilation -P, --project [path] Path to TypeScript JSON project file -C, --compiler [name] Specify a custom TypeScript compiler --transpiler [name] Specify a third-party, non-typechecking transpiler -D, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code -O, --compilerOptions [opts] JSON object to merge with compiler options --cwd Behave as if invoked within this working directory. --files Load \`files\`, \`include\` and \`exclude\` from \`tsconfig.json\` on startup --pretty Use pretty diagnostic formatter (usually enabled by default) --cwdMode Use current directory instead of for config resolution --skipProject Skip reading \`tsconfig.json\` --skipIgnore Skip \`--ignore\` checks --emit Emit output files into \`.ts-node\` directory --scope Scope compiler to files within \`scopeDir\`. Anything outside this directory is ignored. --scopeDir Directory for \`--scope\` --preferTsExts Prefer importing TypeScript files over JavaScript files --logError Logs TypeScript errors to stderr instead of throwing exceptions --noExperimentalReplAwait Disable top-level await in REPL. Equivalent to node's --no-experimental-repl-await --experimentalSpecifierResolution [node|explicit] Equivalent to node's --experimental-specifier-resolution `); process.exit(0); } // Output project information. if (version === 1) { console.log(`v${index_1.VERSION}`); process.exit(0); } const cwd = cwdArg ? (0, path_1.resolve)(cwdArg) : process.cwd(); // If ESM is explicitly enabled through the flag, stage3 should be run in a child process // with the ESM loaders configured. if (esm) payload.shouldUseChildProcess = true; return { cwd, }; } function phase3(payload) { const { emit, files, pretty, transpileOnly, transpiler, noExperimentalReplAwait, typeCheck, swc, compilerHost, ignore, preferTsExts, logError, scriptMode, cwdMode, project, skipProject, skipIgnore, compiler, ignoreDiagnostics, compilerOptions, argsRequire, scope, scopeDir, esm, experimentalSpecifierResolution, } = payload.parseArgvResult; const { cwd } = payload.phase2Result; // NOTE: When we transition to a child process for ESM, the entry-point script determined // here might not be the one used later in `phase4`. This can happen when we execute the // original entry-point but then the process forks itself using e.g. `child_process.fork`. // We will always use the original TS project in forked processes anyway, so it is // expected and acceptable to retrieve the entry-point information here in `phase2`. // See: https://github.com/TypeStrong/ts-node/issues/1812. const { entryPointPath } = getEntryPointInfo(payload); const preloadedConfig = (0, configuration_1.findAndReadConfig)({ cwd, emit, files, pretty, transpileOnly: (transpileOnly !== null && transpileOnly !== void 0 ? transpileOnly : transpiler != null) ? true : undefined, experimentalReplAwait: noExperimentalReplAwait ? false : undefined, typeCheck, transpiler, swc, compilerHost, ignore, logError, projectSearchDir: getProjectSearchDir(cwd, scriptMode, cwdMode, entryPointPath), project, skipProject, skipIgnore, compiler, ignoreDiagnostics, compilerOptions, require: argsRequire, scope, scopeDir, preferTsExts, esm, experimentalSpecifierResolution: experimentalSpecifierResolution, }); // If ESM is enabled through the parsed tsconfig, stage4 should be run in a child // process with the ESM loaders configured. if (preloadedConfig.options.esm) payload.shouldUseChildProcess = true; return { preloadedConfig }; } /** * Determines the entry-point information from the argv and phase2 result. This * method will be invoked in two places: * * 1. In phase 3 to be able to find a project from the potential entry-point script. * 2. In phase 4 to determine the actual entry-point script. * * Note that we need to explicitly re-resolve the entry-point information in the final * stage because the previous stage information could be modified when the bootstrap * invocation transitioned into a child process for ESM. * * Stages before (phase 4) can and will be cached by the child process through the Brotli * configuration and entry-point information is only reliable in the final phase. More * details can be found in here: https://github.com/TypeStrong/ts-node/issues/1812. */ function getEntryPointInfo(state) { const { code, interactive, restArgs } = state.parseArgvResult; const { cwd } = state.phase2Result; const { isCli } = state; // Figure out which we are executing: piped stdin, --eval, REPL, and/or entrypoint // This is complicated because node's behavior is complicated // `node -e code -i ./script.js` ignores -e const executeEval = code != null && !(interactive && restArgs.length); const executeEntrypoint = !executeEval && restArgs.length > 0; const executeRepl = !executeEntrypoint && (interactive || (process.stdin.isTTY && !executeEval)); const executeStdin = !executeEval && !executeRepl && !executeEntrypoint; /** * Unresolved. May point to a symlink, not realpath. May be missing file extension * 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 */ const entryPointPath = executeEntrypoint ? isCli ? (0, path_1.resolve)(cwd, restArgs[0]) : (0, path_1.resolve)(restArgs[0]) : undefined; return { executeEval, executeEntrypoint, executeRepl, executeStdin, entryPointPath, }; } function phase4(payload) { var _a, _b, _c, _d, _e, _f, _g; const { isInChildProcess, tsNodeScript } = payload; const { version, showConfig, restArgs, code, print, argv } = payload.parseArgvResult; const { cwd } = payload.phase2Result; const { preloadedConfig } = payload.phase3Result; const { entryPointPath, executeEntrypoint, executeEval, executeRepl, executeStdin, } = getEntryPointInfo(payload); let evalStuff; let replStuff; let stdinStuff; let evalAwarePartialHost = undefined; if (executeEval) { const state = new repl_1.EvalState((0, path_1.join)(cwd, repl_1.EVAL_FILENAME)); evalStuff = { state, repl: (0, repl_1.createRepl)({ state, composeWithEvalAwarePartialHost: evalAwarePartialHost, ignoreDiagnosticsThatAreAnnoyingInInteractiveRepl: false, }), }; ({ evalAwarePartialHost } = evalStuff.repl); // Create a local module instance based on `cwd`. const module = (evalStuff.module = new Module(repl_1.EVAL_NAME)); module.filename = evalStuff.state.path; module.paths = Module._nodeModulePaths(cwd); } if (executeStdin) { const state = new repl_1.EvalState((0, path_1.join)(cwd, repl_1.STDIN_FILENAME)); stdinStuff = { state, repl: (0, repl_1.createRepl)({ state, composeWithEvalAwarePartialHost: evalAwarePartialHost, ignoreDiagnosticsThatAreAnnoyingInInteractiveRepl: false, }), }; ({ evalAwarePartialHost } = stdinStuff.repl); // Create a local module instance based on `cwd`. const module = (stdinStuff.module = new Module(repl_1.STDIN_NAME)); module.filename = stdinStuff.state.path; module.paths = Module._nodeModulePaths(cwd); } if (executeRepl) { const state = new repl_1.EvalState((0, path_1.join)(cwd, repl_1.REPL_FILENAME)); replStuff = { state, repl: (0, repl_1.createRepl)({ state, composeWithEvalAwarePartialHost: evalAwarePartialHost, }), }; ({ evalAwarePartialHost } = replStuff.repl); } // Register the TypeScript compiler instance. const service = (0, index_1.createFromPreloadedConfig)({ // Since this struct may have been marshalled across thread or process boundaries, we must restore // un-marshall-able values. ...preloadedConfig, options: { ...preloadedConfig.options, readFile: (_a = evalAwarePartialHost === null || evalAwarePartialHost === void 0 ? void 0 : evalAwarePartialHost.readFile) !== null && _a !== void 0 ? _a : undefined, fileExists: (_b = evalAwarePartialHost === null || evalAwarePartialHost === void 0 ? void 0 : evalAwarePartialHost.fileExists) !== null && _b !== void 0 ? _b : undefined, tsTrace: index_1.DEFAULTS.tsTrace, }, }); (0, index_1.register)(service); if (isInChildProcess) require('./child/child-loader').lateBindHooks((0, index_1.createEsmHooks)(service)); // Bind REPL service to ts-node compiler service (chicken-and-egg problem) replStuff === null || replStuff === void 0 ? void 0 : replStuff.repl.setService(service); evalStuff === null || evalStuff === void 0 ? void 0 : evalStuff.repl.setService(service); stdinStuff === null || stdinStuff === void 0 ? void 0 : stdinStuff.repl.setService(service); // Output project information. if (version === 2) { console.log(`ts-node v${index_1.VERSION}`); console.log(`node ${process.version}`); console.log(`compiler v${service.ts.version}`); process.exit(0); } if (version >= 3) { console.log(`ts-node v${index_1.VERSION} ${(0, path_1.dirname)(__dirname)}`); console.log(`node ${process.version}`); console.log(`compiler v${service.ts.version} ${(_c = service.compilerPath) !== null && _c !== void 0 ? _c : ''}`); process.exit(0); } if (showConfig) { const ts = service.ts; if (typeof ts.convertToTSConfig !== 'function') { console.error('Error: --showConfig requires a typescript versions >=3.2 that support --showConfig'); process.exit(1); } let moduleTypes = undefined; if (service.options.moduleTypes) { // Assumption: this codepath requires CLI invocation, so moduleTypes must have come from a tsconfig, not API. const showRelativeTo = (0, path_1.dirname)(service.configFilePath); moduleTypes = {}; for (const [key, value] of Object.entries(service.options.moduleTypes)) { moduleTypes[(0, path_1.relative)(showRelativeTo, (0, path_1.resolve)((_d = service.options.optionBasePaths) === null || _d === void 0 ? void 0 : _d.moduleTypes, key))] = value; } } const json = { ['ts-node']: { ...service.options, require: ((_e = service.options.require) === null || _e === void 0 ? void 0 : _e.length) ? service.options.require : undefined, moduleTypes, optionBasePaths: undefined, compilerOptions: undefined, project: (_f = service.configFilePath) !== null && _f !== void 0 ? _f : service.options.project, }, ...ts.convertToTSConfig(service.config, (_g = service.configFilePath) !== null && _g !== void 0 ? _g : (0, path_1.join)(cwd, 'ts-node-implicit-tsconfig.json'), service.ts.sys), }; console.log( // Assumes that all configuration options which can possibly be specified via the CLI are JSON-compatible. // If, in the future, we must log functions, for example readFile and fileExists, then we can implement a JSON // replacer function. JSON.stringify(json, null, 2)); process.exit(0); } // Prepend `ts-node` arguments to CLI for child processes. process.execArgv.push(tsNodeScript, ...argv.slice(2, argv.length - restArgs.length)); // TODO this comes from BootstrapState process.argv = [process.argv[1]] .concat(executeEntrypoint ? [entryPointPath] : []) .concat(restArgs.slice(executeEntrypoint ? 1 : 0)); // Execute the main contents (either eval, script or piped). if (executeEntrypoint) { if (payload.isInChildProcess && (0, util_2.versionGteLt)(process.versions.node, '18.6.0')) { // HACK workaround node regression require('../dist-raw/runmain-hack.js').run(entryPointPath); } else { Module.runMain(); } } else { // Note: eval and repl may both run, but never with stdin. // If stdin runs, eval and repl will not. if (executeEval) { (0, node_internal_modules_cjs_helpers_1.addBuiltinLibsToObject)(global); evalAndExitOnTsError(evalStuff.repl, evalStuff.module, code, print, 'eval'); } if (executeRepl) { replStuff.repl.start(); } if (executeStdin) { let buffer = code || ''; process.stdin.on('data', (chunk) => (buffer += chunk)); process.stdin.on('end', () => { evalAndExitOnTsError(stdinStuff.repl, stdinStuff.module, buffer, // `echo 123 | node -p` still prints 123 print, 'stdin'); }); } } } /** * Get project search path from args. */ function getProjectSearchDir(cwd, scriptMode, cwdMode, scriptPath) { // Validate `--script-mode` / `--cwd-mode` / `--cwd` usage is correct. if (scriptMode && cwdMode) { throw new TypeError('--cwd-mode cannot be combined with --script-mode'); } if (scriptMode && !scriptPath) { throw new TypeError('--script-mode must be used with a script name, e.g. `ts-node --script-mode `'); } const doScriptMode = scriptMode === true ? true : cwdMode === true ? false : !!scriptPath; if (doScriptMode) { // Use node's own resolution behavior to ensure we follow symlinks. // scriptPath may omit file extension or point to a directory with or without package.json. // This happens before we are registered, so we tell node's resolver to consider ts, tsx, and jsx files. // In extremely rare cases, is is technically possible to resolve the wrong directory, // because we do not yet know preferTsExts, jsx, nor allowJs. // See also, justification why this will not happen in real-world situations: // https://github.com/TypeStrong/ts-node/pull/1009#issuecomment-613017081 const exts = ['.js', '.jsx', '.ts', '.tsx']; const extsTemporarilyInstalled = []; for (const ext of exts) { if (!(0, util_2.hasOwnProperty)(require.extensions, ext)) { extsTemporarilyInstalled.push(ext); require.extensions[ext] = function () { }; } } try { return (0, path_1.dirname)(requireResolveNonCached(scriptPath)); } finally { for (const ext of extsTemporarilyInstalled) { delete require.extensions[ext]; } } } return cwd; } const guaranteedNonexistentDirectoryPrefix = (0, path_1.resolve)(__dirname, 'doesnotexist'); let guaranteedNonexistentDirectorySuffix = 0; /** * require.resolve an absolute path, tricking node into *not* caching the results. * Necessary so that we do not pollute require.resolve cache prior to installing require.extensions * * Is a terrible hack, because node does not expose the necessary cache invalidation APIs * https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results */ function requireResolveNonCached(absoluteModuleSpecifier) { // node <= 12.1.x fallback: The trick below triggers a node bug on old versions. // On these old versions, pollute the require cache instead. This is a deliberate // ts-node limitation that will *rarely* manifest, and will not matter once node 12 // is end-of-life'd on 2022-04-30 const isSupportedNodeVersion = (0, util_2.versionGteLt)(process.versions.node, '12.2.0'); if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier); const { dir, base } = (0, path_1.parse)(absoluteModuleSpecifier); const relativeModuleSpecifier = `./${base}`; const req = (0, util_2.createRequire)((0, path_1.join)(dir, 'imaginaryUncacheableRequireResolveScript')); return req.resolve(relativeModuleSpecifier, { paths: [ `${guaranteedNonexistentDirectoryPrefix}${guaranteedNonexistentDirectorySuffix++}`, ...(req.resolve.paths(relativeModuleSpecifier) || []), ], }); } /** * Evaluate an [eval] or [stdin] script */ function evalAndExitOnTsError(replService, module, code, isPrinted, filenameAndDirname) { let result; (0, repl_1.setupContext)(global, module, filenameAndDirname); try { result = replService.evalCode(code); } catch (error) { if (error instanceof index_1.TSError) { console.error(error); process.exit(1); } throw error; } if (isPrinted) { console.log(typeof result === 'string' ? result : (0, util_1.inspect)(result, { colors: process.stdout.isTTY })); } } if (require.main === module) { main(); } //# sourceMappingURL=bin.js.map