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