forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl.js
More file actions
37 lines (31 loc) · 872 Bytes
/
repl.js
File metadata and controls
37 lines (31 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const {
Number,
NumberIsNaN,
} = primordials;
const REPL = require('repl');
const { kStandaloneREPL } = require('internal/repl/utils');
function createInternalRepl(opts = {}, callback = () => {}) {
opts = {
[kStandaloneREPL]: true,
useGlobal: true,
breakEvalOnSigint: true,
...opts,
terminal: parseInt(process.env.NODE_NO_READLINE) ? false : opts.terminal,
};
const historySize = Number(process.env.NODE_REPL_HISTORY_SIZE);
if (!NumberIsNaN(historySize) && historySize > 0) {
opts.historySize = historySize;
} else {
opts.historySize = 1000;
}
const repl = REPL.start(opts);
const historyPath = repl.terminal ? process.env.NODE_REPL_HISTORY : '';
repl.setupHistory(historyPath, (err, repl) => {
if (err) {
throw err;
}
callback(repl);
});
}
module.exports = { createInternalRepl };