0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/lib/internal/main/repl.js
Richard Lau 1a96abe849
Revert "lib: print to stdout/stderr directly instead of using console"
This reverts commit 2b24ffae22.

Fixes: https://github.com/nodejs/node/issues/27819

PR-URL: https://github.com/nodejs/node/pull/27823
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-05-26 16:44:16 +02:00

57 lines
1.4 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 console = require('internal/console/global');
const { getOptionValue } = require('internal/options');
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);
}
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();
});
}
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'));
}