From c0305af2c4aba6d6ecd39eb100a59998d87ddc69 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Thu, 26 Sep 2019 15:58:49 -0700 Subject: repl: check for NODE_REPL_EXTERNAL_MODULE PR-URL: https://github.com/nodejs/node/pull/29778 Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang --- lib/internal/main/repl.js | 66 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 93b932f0bd..693b7048a3 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -19,38 +19,44 @@ prepareMainThreadExecution(); markBootstrapComplete(); -// --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(1); -} +if (process.env.NODE_REPL_EXTERNAL_MODULE) { + require('internal/modules/cjs/loader') + .Module + ._load(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(1); + } -console.log(`Welcome to Node.js ${process.version}.\n` + - 'Type ".help" for more information.'); + console.log(`Welcome to Node.js ${process.version}.\n` + + 'Type ".help" for more information.'); -const cliRepl = require('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(); - }); + const cliRepl = require('internal/repl'); + cliRepl.createInternalRepl(process.env, (err, repl) => { + if (err) { + throw err; } - process.exit(); + 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]')) { - evalScript('[eval]', - getOptionValue('--eval'), - getOptionValue('--inspect-brk'), - getOptionValue('--print')); + + // If user passed '-e' or '--eval' along with `-i` or `--interactive`, + // evaluate the code in the current context. + if (getOptionValue('[has_eval_string]')) { + evalScript('[eval]', + getOptionValue('--eval'), + getOptionValue('--inspect-brk'), + getOptionValue('--print')); + } } -- cgit v1.2.3