You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
REPL, -e, and piped stdin globals are wrong: ,missing exports, module, etc. #1282
changed the title [-]`ts-node --interactive -e` evaluates `-e` expression without `exports`, `module`, etc.[/-][+]REPL, `-e`, and piped stdin globals are wrong: ,missing `exports`, `module`, etc.[/+]on May 27, 2021
Activity
cspotcode commentedon Mar 22, 2021
Seems this bit of code, which only runs when you call
start(), should actually be run earlier in some of our-ecodepaths.https://github.com/TypeStrong/ts-node/blob/main/src/repl.ts#L263-L268
cspotcode commentedon May 23, 2021
Did some more research here.
node --interactiveREPL uses the global object as the REPL's scope. We opt-in to the same via the API.node -e '< expression >' gets access to a bunch of variables added to the global object.
So does REPL code.
I did a test logging the set of fields on
globalwhich are added by callingnew REPLServer()The modules like
fsare getters, presumably for performance.global.__filenameandglobal.__dirnameare set for-eor-p, but only stick around on the global object if you donode -p "" -i__filenameis[eval]for-e,[stdin]for piped input.stdin and
-eglobal.module,.exports,.require,.__filename,.__dirnameset.new REPLServer()only sets.module,.require, but includes_and_error.consoleis not overwritten. I thought it might have been to redirectconsole.log()to the stdin and stdout passed to the REPL, but no.Looks like we need to do these things:
new REPLServer()before any sort of-e,-p,-i, or piped stdin__filenameand__dirnameonly in certain codepaths[eval]and[stdin]for__filenameexportsbecause TS emitted code requires it.contextcspotcode commentedon May 23, 2021
Also must be sure
module.pathsmatches in all cases. Appears to differ between-pand repl.cspotcode commentedon May 24, 2021
Discrepancy between:
node treats the positional as an argv string, does NOT attempt to execute it.
ts-nodebreaks:EvalStatecspotcode commentedon May 24, 2021
Our repl does
process.exit(). We should make the REPL API raise an error somehow, and callprocess.exit()in response to that error in ourbin.ts.[-]`ts-node --interactive -e` evaluates `-e` expression without `exports`, `module`, etc.[/-][+]REPL, `-e`, and piped stdin globals are wrong: ,missing `exports`, `module`, etc.[/+]cspotcode commentedon May 27, 2021
Renamed to capture scope of this ticket.
Fix #1282: correct globals in [stdin], [eval], and <repl> contexts (#…