mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
e4e8421c25
PR-URL: https://github.com/nodejs/node/pull/46757 Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com> Reviewed-By: Qingyu Deng <i@ayase-lab.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
Number,
|
|
NumberIsNaN,
|
|
NumberParseInt,
|
|
} = primordials;
|
|
|
|
const REPL = require('repl');
|
|
const { kStandaloneREPL } = require('internal/repl/utils');
|
|
|
|
module.exports = { __proto__: REPL };
|
|
module.exports.createInternalRepl = createRepl;
|
|
|
|
function createRepl(env, opts, cb) {
|
|
if (typeof opts === 'function') {
|
|
cb = opts;
|
|
opts = null;
|
|
}
|
|
opts = {
|
|
[kStandaloneREPL]: true,
|
|
ignoreUndefined: false,
|
|
useGlobal: true,
|
|
breakEvalOnSigint: true,
|
|
...opts,
|
|
};
|
|
|
|
if (NumberParseInt(env.NODE_NO_READLINE)) {
|
|
opts.terminal = false;
|
|
}
|
|
|
|
if (env.NODE_REPL_MODE) {
|
|
opts.replMode = {
|
|
'strict': REPL.REPL_MODE_STRICT,
|
|
'sloppy': REPL.REPL_MODE_SLOPPY,
|
|
}[env.NODE_REPL_MODE.toLowerCase().trim()];
|
|
}
|
|
|
|
if (opts.replMode === undefined) {
|
|
opts.replMode = REPL.REPL_MODE_SLOPPY;
|
|
}
|
|
|
|
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
|
if (!NumberIsNaN(historySize) && historySize > 0) {
|
|
opts.historySize = historySize;
|
|
} else {
|
|
opts.historySize = 1000;
|
|
}
|
|
|
|
const repl = REPL.start(opts);
|
|
const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
|
|
repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
|
|
}
|