2015-04-23 00:35:53 -07:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
2019-11-28 10:30:51 +01:00
|
|
|
Number,
|
2019-11-27 19:59:29 +01:00
|
|
|
NumberIsNaN,
|
2019-11-22 18:04:46 +01:00
|
|
|
} = primordials;
|
2019-04-09 09:55:53 +02:00
|
|
|
|
2015-04-23 00:35:53 -07:00
|
|
|
const REPL = require('repl');
|
2019-01-19 15:34:00 +01:00
|
|
|
const { kStandaloneREPL } = require('internal/repl/utils');
|
2019-02-01 12:49:16 -05:00
|
|
|
|
2020-05-19 02:33:55 +02:00
|
|
|
function createInternalRepl(opts = {}, callback = () => {}) {
|
2018-12-18 03:15:57 +01:00
|
|
|
opts = {
|
2019-01-19 15:34:00 +01:00
|
|
|
[kStandaloneREPL]: true,
|
2016-07-19 14:41:47 -04:00
|
|
|
useGlobal: true,
|
2018-12-18 03:15:57 +01:00
|
|
|
breakEvalOnSigint: true,
|
2020-05-19 02:33:55 +02:00
|
|
|
...opts,
|
|
|
|
terminal: parseInt(process.env.NODE_NO_READLINE) ? false : opts.terminal,
|
2018-12-18 03:15:57 +01:00
|
|
|
};
|
2015-04-23 00:35:53 -07:00
|
|
|
|
2020-05-19 02:33:55 +02:00
|
|
|
const historySize = Number(process.env.NODE_REPL_HISTORY_SIZE);
|
2019-11-27 19:59:29 +01:00
|
|
|
if (!NumberIsNaN(historySize) && historySize > 0) {
|
2015-04-23 00:35:53 -07:00
|
|
|
opts.historySize = historySize;
|
|
|
|
} else {
|
|
|
|
opts.historySize = 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
const repl = REPL.start(opts);
|
2020-05-19 02:33:55 +02:00
|
|
|
const historyPath = repl.terminal ? process.env.NODE_REPL_HISTORY : '';
|
|
|
|
repl.setupHistory(historyPath, (err, repl) => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
callback(repl);
|
|
|
|
});
|
2015-04-23 00:35:53 -07:00
|
|
|
}
|
2020-05-19 02:33:55 +02:00
|
|
|
|
|
|
|
module.exports = { createInternalRepl };
|