• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const {
4  Number,
5  NumberIsNaN,
6  ObjectCreate,
7} = primordials;
8
9const REPL = require('repl');
10const { kStandaloneREPL } = require('internal/repl/utils');
11
12module.exports = ObjectCreate(REPL);
13module.exports.createInternalRepl = createRepl;
14
15function createRepl(env, opts, cb) {
16  if (typeof opts === 'function') {
17    cb = opts;
18    opts = null;
19  }
20  opts = {
21    [kStandaloneREPL]: true,
22    ignoreUndefined: false,
23    useGlobal: true,
24    breakEvalOnSigint: true,
25    ...opts
26  };
27
28  if (parseInt(env.NODE_NO_READLINE)) {
29    opts.terminal = false;
30  }
31
32  if (env.NODE_REPL_MODE) {
33    opts.replMode = {
34      'strict': REPL.REPL_MODE_STRICT,
35      'sloppy': REPL.REPL_MODE_SLOPPY
36    }[env.NODE_REPL_MODE.toLowerCase().trim()];
37  }
38
39  if (opts.replMode === undefined) {
40    opts.replMode = REPL.REPL_MODE_SLOPPY;
41  }
42
43  const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
44  if (!NumberIsNaN(historySize) && historySize > 0) {
45    opts.historySize = historySize;
46  } else {
47    opts.historySize = 1000;
48  }
49
50  const repl = REPL.start(opts);
51  const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
52  repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
53}
54