Skip to content

Commit 2cc01da

Browse files
committed
repl: default useGlobal to true
This is a partial revert of 15157c3. This change lead to a regression that broke require() in the CLI REPL, as imported files were evaluated in a different context. Refs: #5703 Fixes: #7788 PR-URL: #7795 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 68b966b commit 2cc01da

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/internal/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function createRepl(env, opts, cb) {
2222
opts = opts || {
2323
ignoreUndefined: false,
2424
terminal: process.stdout.isTTY,
25-
useGlobal: false,
25+
useGlobal: true,
2626
breakEvalOnSigint: true
2727
};
2828

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
const path = require('path');
6+
const child = cp.spawn(process.execPath, ['--interactive']);
7+
const fixture = path.join(common.fixturesDir, 'is-object.js').replace(/\\/g,
8+
'/');
9+
let output = '';
10+
11+
child.stdout.setEncoding('utf8');
12+
child.stdout.on('data', (data) => {
13+
output += data;
14+
});
15+
16+
child.on('exit', common.mustCall(() => {
17+
const results = output.split('\n').map((line) => {
18+
return line.replace(/\w*>\w*/, '').trim();
19+
});
20+
21+
assert.deepStrictEqual(results, ['undefined', 'true', 'true', '']);
22+
}));
23+
24+
child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n');
25+
child.stdin.write('isObject({});\n');
26+
child.stdin.write(`require('${fixture}').isObject({});\n`);
27+
child.stdin.write('.exit');
28+
child.stdin.end();

0 commit comments

Comments
 (0)