UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

75 lines (65 loc) 2.53 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/main/repl.js import * as __hoisted_internal_modules_run_main__ from "nstdlib/lib/internal/modules/run_main"; import * as __hoisted_internal_repl__ from "nstdlib/lib/internal/repl"; import { prepareMainThreadExecution, markBootstrapComplete, } from "nstdlib/lib/internal/process/pre_execution"; import { evalScript } from "nstdlib/lib/internal/process/execution"; import * as console from "nstdlib/lib/internal/console/global"; import { getOptionValue } from "nstdlib/lib/internal/options"; import { exitCodes as __exitCodes__ } from "nstdlib/stub/binding/errors"; import * as __hoisted_internal_modules_cjs_loader__ from "nstdlib/lib/internal/modules/cjs/loader"; // Create the REPL if `-i` or `--interactive` is passed, or if // the main module is not specified and stdin is a TTY. const { kInvalidCommandLineArgument } = __exitCodes__; prepareMainThreadExecution(); markBootstrapComplete(); if (process.env.NODE_REPL_EXTERNAL_MODULE) { __hoisted_internal_modules_cjs_loader__.wrapModuleLoad( process.env.NODE_REPL_EXTERNAL_MODULE, undefined, true, ); } else { // --input-type flag not supported in REPL if (getOptionValue("--input-type")) { // If we can't write to stderr, we'd like to make this a noop, // so use console.error. console.error("Cannot specify --input-type for REPL"); process.exit(kInvalidCommandLineArgument); } __hoisted_internal_modules_run_main__.runEntryPointWithESMLoader(() => { console.log( `Welcome to Node.js ${process.version}.\n` + 'Type ".help" for more information.', ); const cliRepl = __hoisted_internal_repl__; cliRepl.createInternalRepl(process.env, (err, repl) => { if (err) { throw err; } repl.on("exit", () => { if (repl._flushing) { repl.pause(); return repl.once("flushHistory", () => { process.exit(); }); } process.exit(); }); }); // If user passed '-e' or '--eval' along with `-i` or `--interactive`, // evaluate the code in the current context. if (getOptionValue("[has_eval_string]")) { ((...args) => globalThis.evalScript(...args))( "[eval]", getOptionValue("--eval"), getOptionValue("--inspect-brk"), getOptionValue("--print"), ); } // The TLAs in the REPL are still run as scripts, just transformed as async // IIFEs for the REPL code itself to await on. }); }