mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Add an ExitCode enum class and use it throughout the code base instead of hard-coding the exit codes everywhere. At the moment, the exit codes used in many places do not actually conform to what the documentation describes. With the new enums (which are also available to the JS land as constants in an internal binding) we could migrate to a more consistent usage of the codes, and eventually expose the constants to the user land when they are stable enough. PR-URL: https://github.com/nodejs/node/pull/44746 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
70 lines
1.9 KiB
JavaScript
70 lines
1.9 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,
|
|
markBootstrapComplete
|
|
} = require('internal/process/pre_execution');
|
|
|
|
const esmLoader = require('internal/process/esm_loader');
|
|
const {
|
|
evalScript
|
|
} = require('internal/process/execution');
|
|
|
|
const console = require('internal/console/global');
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
|
|
|
|
prepareMainThreadExecution();
|
|
|
|
markBootstrapComplete();
|
|
|
|
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');
|
|
// TODO(joyeecheung): should be kInvalidCommandLineArgument.
|
|
process.exit(kGenericUserError);
|
|
}
|
|
|
|
esmLoader.loadESM(() => {
|
|
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'));
|
|
}
|
|
});
|
|
}
|