2015-04-23 09:35:53 +02:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-09 09:55:53 +02:00
|
|
|
const { Object } = primordials;
|
|
|
|
|
2015-04-23 09:35:53 +02:00
|
|
|
const REPL = require('repl');
|
2019-01-19 15:34:00 +01:00
|
|
|
const { kStandaloneREPL } = require('internal/repl/utils');
|
2019-02-01 18:49:16 +01:00
|
|
|
|
2015-05-04 10:40:40 +02:00
|
|
|
module.exports = Object.create(REPL);
|
2018-02-11 19:17:03 +01:00
|
|
|
module.exports.createInternalRepl = createRepl;
|
2015-05-04 10:40:40 +02:00
|
|
|
|
2018-02-11 19:17:03 +01:00
|
|
|
function createRepl(env, opts, cb) {
|
2015-08-02 07:38:28 +02:00
|
|
|
if (typeof opts === 'function') {
|
|
|
|
cb = opts;
|
|
|
|
opts = null;
|
|
|
|
}
|
2018-12-18 03:15:57 +01:00
|
|
|
opts = {
|
2019-01-19 15:34:00 +01:00
|
|
|
[kStandaloneREPL]: true,
|
2015-05-02 23:47:17 +02:00
|
|
|
ignoreUndefined: false,
|
2016-07-19 20:41:47 +02:00
|
|
|
useGlobal: true,
|
2018-12-18 03:15:57 +01:00
|
|
|
breakEvalOnSigint: true,
|
|
|
|
...opts
|
|
|
|
};
|
2015-04-23 09:35:53 +02:00
|
|
|
|
|
|
|
if (parseInt(env.NODE_NO_READLINE)) {
|
|
|
|
opts.terminal = false;
|
|
|
|
}
|
|
|
|
|
2019-03-08 12:21:35 +01:00
|
|
|
if (env.NODE_REPL_MODE) {
|
|
|
|
opts.replMode = {
|
|
|
|
'strict': REPL.REPL_MODE_STRICT,
|
|
|
|
'sloppy': REPL.REPL_MODE_SLOPPY
|
|
|
|
}[env.NODE_REPL_MODE.toLowerCase().trim()];
|
|
|
|
}
|
2015-04-23 09:35:53 +02:00
|
|
|
|
|
|
|
if (opts.replMode === undefined) {
|
2017-02-28 03:45:53 +01:00
|
|
|
opts.replMode = REPL.REPL_MODE_SLOPPY;
|
2015-04-23 09:35:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
2018-02-13 00:56:35 +01:00
|
|
|
if (!Number.isNaN(historySize) && historySize > 0) {
|
2015-04-23 09:35:53 +02:00
|
|
|
opts.historySize = historySize;
|
|
|
|
} else {
|
|
|
|
opts.historySize = 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
const repl = REPL.start(opts);
|
2019-03-08 12:21:35 +01:00
|
|
|
const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
|
|
|
|
repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
|
2015-04-23 09:35:53 +02:00
|
|
|
}
|