Skip to content

Commit 698bf2e

Browse files
cjihrigMylesBorins
authored andcommitted
repl: don't override all internal repl defaults
The createInternalRepl() module accepts an options object as an argument. However, if one is provided, it overrides all of the default options. This commit applies the options object to the defaults, only changing the values that are explicitly set. PR-URL: #7826 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 02e8187 commit 698bf2e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/internal/repl.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const REPL = require('repl');
55
const path = require('path');
66
const fs = require('fs');
77
const os = require('os');
8-
const debug = require('util').debuglog('repl');
8+
const util = require('util');
9+
const debug = util.debuglog('repl');
910

1011
module.exports = Object.create(REPL);
1112
module.exports.createInternalRepl = createRepl;
@@ -19,11 +20,11 @@ function createRepl(env, opts, cb) {
1920
cb = opts;
2021
opts = null;
2122
}
22-
opts = opts || {
23+
opts = util._extend({
2324
ignoreUndefined: false,
2425
terminal: process.stdout.isTTY,
2526
useGlobal: true
26-
};
27+
}, opts);
2728

2829
if (parseInt(env.NODE_NO_READLINE)) {
2930
opts.terminal = false;

test/parallel/test-repl-envvars.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Flags: --expose-internals
44

5-
require('../common');
5+
const common = require('../common');
66
const stream = require('stream');
77
const REPL = require('internal/repl');
88
const assert = require('assert');
@@ -46,6 +46,10 @@ function run(test) {
4646

4747
REPL.createInternalRepl(env, opts, function(err, repl) {
4848
if (err) throw err;
49+
50+
// The REPL registers 'module' and 'require' globals
51+
common.allowGlobals(repl.context.module, repl.context.require);
52+
4953
assert.equal(expected.terminal, repl.terminal,
5054
'Expected ' + inspect(expected) + ' with ' + inspect(env));
5155
assert.equal(expected.useColors, repl.useColors,

test/parallel/test-repl-history-perm.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const replHistoryPath = path.join(common.tmpDir, '.node_repl_history');
3535
const checkResults = common.mustCall(function(err, r) {
3636
if (err)
3737
throw err;
38+
39+
// The REPL registers 'module' and 'require' globals
40+
common.allowGlobals(r.context.module, r.context.require);
41+
3842
r.input.end();
3943
const stat = fs.statSync(replHistoryPath);
4044
assert.strictEqual(

test/parallel/test-repl-persistent-history.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ function runTest(assertCleaned) {
262262
throw err;
263263
}
264264

265+
// The REPL registers 'module' and 'require' globals.
266+
// This test also registers '_'.
267+
common.allowGlobals(repl.context.module,
268+
repl.context.require,
269+
repl.context._);
270+
265271
repl.once('close', () => {
266272
if (repl._flushing) {
267273
repl.once('flushHistory', onClose);

0 commit comments

Comments
 (0)