mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 16:23:36 +00:00

`getOptionValue('--eval')` always returns a string, so it is never loose-equal to `null`. Running eval makes some modifications to the global object, including setting `module` to a different value, which we want to avoid if possible. Refs: https://github.com/nodejs/node/pull/27278 PR-URL: https://github.com/nodejs/node/pull/27587 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// Create the REPL if `-i` or `--interactive` is passed, or if
|
|
// the main module is not specified and stdin is a TTY.
|
|
|
|
const {
|
|
prepareMainThreadExecution
|
|
} = require('internal/bootstrap/pre_execution');
|
|
|
|
const {
|
|
evalScript
|
|
} = require('internal/process/execution');
|
|
|
|
const { print, kStderr, kStdout } = require('internal/util/print');
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
prepareMainThreadExecution();
|
|
|
|
markBootstrapComplete();
|
|
|
|
// --input-type flag not supported in REPL
|
|
if (getOptionValue('--input-type')) {
|
|
print(kStderr, 'Cannot specify --input-type for REPL');
|
|
process.exit(1);
|
|
}
|
|
|
|
print(kStdout, `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();
|
|
});
|
|
}
|
|
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'));
|
|
}
|