mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
In addition, use process.stderr instead of console.error when there is no need to swallow the error. PR-URL: https://github.com/nodejs/node/pull/27112 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 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');
|
|
|
|
prepareMainThreadExecution();
|
|
|
|
// --entry-type flag not supported in REPL
|
|
if (require('internal/options').getOptionValue('--entry-type')) {
|
|
// If we can't write to stderr, we'd like to make this a noop,
|
|
// so use console.error.
|
|
const { error } = require('internal/console/global');
|
|
error('Cannot specify --entry-type for REPL');
|
|
process.exit(1);
|
|
}
|
|
|
|
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 (process._eval != null) {
|
|
evalScript('[eval]', process._eval, process._breakFirstLine);
|
|
}
|
|
|
|
markBootstrapComplete();
|