Skip to content

Commit 072feec

Browse files
addaleaxTrott
authored andcommitted
Revert "repl: always check for NODE_REPL_MODE environment variable"
This reverts commit b831b08. This presumably unbreaks the ASAN github action build. Example failure: 2020-06-25T19:59:15.1448178Z === release test-repl-envvars === 2020-06-25T19:59:15.1448872Z Path: parallel/test-repl-envvars 2020-06-25T19:59:15.1449449Z --- stderr --- 2020-06-25T19:59:15.1449835Z assert.js:103 2020-06-25T19:59:15.1450194Z throw new AssertionError(obj); 2020-06-25T19:59:15.1450524Z ^ 2020-06-25T19:59:15.1450817Z 2020-06-25T19:59:15.1451431Z AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: 2020-06-25T19:59:15.1452000Z + actual - expected 2020-06-25T19:59:15.1452298Z 2020-06-25T19:59:15.1452634Z { 2020-06-25T19:59:15.1452978Z terminal: true, 2020-06-25T19:59:15.1453321Z + useColors: false 2020-06-25T19:59:15.1453861Z - useColors: true 2020-06-25T19:59:15.1454225Z } 2020-06-25T19:59:15.1454841Z at /home/runner/work/node/node/test/parallel/test-repl-envvars.js:55:12 2020-06-25T19:59:15.1455246Z at internal/repl.js:33:5 PR-URL: #34058 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 82f13fa commit 072feec

12 files changed

+109
-73
lines changed

doc/api/repl.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,6 @@ A list of the names of all Node.js modules, e.g., `'http'`.
555555
<!-- YAML
556556
added: v0.1.91
557557
changes:
558-
- version: REPLACEME
559-
pr-url: https://github.com/nodejs/node/pull/33461
560-
description: The `NODE_REPL_MODE` environment variable now accounts for
561-
all repl instances.
562558
- version:
563559
- v13.4.0
564560
- v12.17.0

lib/internal/main/repl.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) {
3535
console.log(`Welcome to Node.js ${process.version}.\n` +
3636
'Type ".help" for more information.');
3737

38-
require('internal/repl').createInternalRepl();
38+
const cliRepl = require('internal/repl');
39+
cliRepl.createInternalRepl(process.env, (err, repl) => {
40+
if (err) {
41+
throw err;
42+
}
43+
repl.on('exit', () => {
44+
if (repl._flushing) {
45+
repl.pause();
46+
return repl.once('flushHistory', () => {
47+
process.exit();
48+
});
49+
}
50+
process.exit();
51+
});
52+
});
3953

4054
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
4155
// evaluate the code in the current context.

lib/internal/repl.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,51 @@
33
const {
44
Number,
55
NumberIsNaN,
6+
ObjectCreate,
67
} = primordials;
78

89
const REPL = require('repl');
910
const { kStandaloneREPL } = require('internal/repl/utils');
1011

11-
function createInternalRepl(opts = {}, callback = () => {}) {
12+
module.exports = ObjectCreate(REPL);
13+
module.exports.createInternalRepl = createRepl;
14+
15+
function createRepl(env, opts, cb) {
16+
if (typeof opts === 'function') {
17+
cb = opts;
18+
opts = null;
19+
}
1220
opts = {
1321
[kStandaloneREPL]: true,
22+
ignoreUndefined: false,
1423
useGlobal: true,
1524
breakEvalOnSigint: true,
16-
...opts,
17-
terminal: parseInt(process.env.NODE_NO_READLINE) ? false : opts.terminal,
25+
...opts
1826
};
1927

20-
const historySize = Number(process.env.NODE_REPL_HISTORY_SIZE);
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);
2144
if (!NumberIsNaN(historySize) && historySize > 0) {
2245
opts.historySize = historySize;
2346
} else {
2447
opts.historySize = 1000;
2548
}
2649

2750
const repl = REPL.start(opts);
28-
const historyPath = repl.terminal ? process.env.NODE_REPL_HISTORY : '';
29-
repl.setupHistory(historyPath, (err, repl) => {
30-
if (err) {
31-
throw err;
32-
}
33-
callback(repl);
34-
});
51+
const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
52+
repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
3553
}
36-
37-
module.exports = { createInternalRepl };

lib/repl.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ const {
115115
setupPreview,
116116
setupReverseSearch,
117117
} = require('internal/repl/utils');
118-
const { hasColors } = require('internal/tty');
119118
const {
120119
getOwnNonIndexProperties,
121120
propertyFilter: {
@@ -214,8 +213,8 @@ function REPLServer(prompt,
214213
// If possible, check if stdout supports colors or not.
215214
if (options.output.hasColors) {
216215
options.useColors = options.output.hasColors();
217-
} else {
218-
options.useColors = hasColors();
216+
} else if (process.env.NODE_DISABLE_COLORS === undefined) {
217+
options.useColors = true;
219218
}
220219
}
221220

@@ -260,6 +259,7 @@ function REPLServer(prompt,
260259
this._domain = options.domain || domain.create();
261260
this.useGlobal = !!useGlobal;
262261
this.ignoreUndefined = !!ignoreUndefined;
262+
this.replMode = replMode || module.exports.REPL_MODE_SLOPPY;
263263
this.underscoreAssigned = false;
264264
this.last = undefined;
265265
this.underscoreErrAssigned = false;
@@ -269,11 +269,6 @@ function REPLServer(prompt,
269269
// Context id for use with the inspector protocol.
270270
this[kContextId] = undefined;
271271

272-
this.replMode = replMode ||
273-
(/^\s*strict\s*$/i.test(process.env.NODE_REPL_MODE) ?
274-
module.exports.REPL_MODE_STRICT :
275-
module.exports.REPL_MODE_SLOPPY);
276-
277272
if (this.breakEvalOnSigint && eval_) {
278273
// Allowing this would not reflect user expectations.
279274
// breakEvalOnSigint affects only the behavior of the default eval().

test/parallel/test-repl-colors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ inout._write = function(s, _, cb) {
2020

2121
const repl = new REPLServer({ input: inout, output: inout, useColors: true });
2222
inout.isTTY = true;
23-
inout.hasColors = () => true;
2423
const repl2 = new REPLServer({ input: inout, output: inout });
2524

2625
process.on('exit', function() {

test/parallel/test-repl-envvars.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ require('../common');
66
const stream = require('stream');
77
const REPL = require('internal/repl');
88
const assert = require('assert');
9-
const debug = require('util').debuglog('test');
9+
const inspect = require('util').inspect;
1010

1111
const tests = [
1212
{
13-
env: { TERM: 'xterm-256' },
13+
env: {},
1414
expected: { terminal: true, useColors: true }
1515
},
1616
{
@@ -30,33 +30,35 @@ const tests = [
3030
expected: { terminal: false, useColors: false }
3131
},
3232
{
33-
env: { NODE_NO_READLINE: '0', TERM: 'xterm-256' },
33+
env: { NODE_NO_READLINE: '0' },
3434
expected: { terminal: true, useColors: true }
3535
}
3636
];
3737

38-
const originalEnv = process.env;
39-
4038
function run(test) {
4139
const env = test.env;
4240
const expected = test.expected;
4341

44-
process.env = { ...originalEnv, ...env };
45-
4642
const opts = {
4743
terminal: true,
4844
input: new stream.Readable({ read() {} }),
4945
output: new stream.Writable({ write() {} })
5046
};
5147

52-
REPL.createInternalRepl(opts, (repl) => {
53-
debug(env);
54-
const { terminal, useColors } = repl;
55-
assert.deepStrictEqual({ terminal, useColors }, expected);
48+
Object.assign(process.env, env);
49+
50+
REPL.createInternalRepl(process.env, opts, function(err, repl) {
51+
assert.ifError(err);
52+
53+
assert.strictEqual(repl.terminal, expected.terminal,
54+
`Expected ${inspect(expected)} with ${inspect(env)}`);
55+
assert.strictEqual(repl.useColors, expected.useColors,
56+
`Expected ${inspect(expected)} with ${inspect(env)}`);
57+
for (const key of Object.keys(env)) {
58+
delete process.env[key];
59+
}
5660
repl.close();
57-
if (tests.length)
58-
run(tests.shift());
5961
});
6062
}
6163

62-
run(tests.shift());
64+
tests.forEach(run);

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ function cleanupTmpFile() {
521521
return true;
522522
}
523523

524-
const originalEnv = process.env;
525-
526524
function runTest() {
527525
const opts = tests.shift();
528526
if (!opts) return; // All done
@@ -537,9 +535,7 @@ function runTest() {
537535
const lastChunks = [];
538536
let i = 0;
539537

540-
process.env = { ...originalEnv, ...opts.env };
541-
542-
REPL.createInternalRepl({
538+
REPL.createInternalRepl(opts.env, {
543539
input: new ActionStream(),
544540
output: new stream.Writable({
545541
write(chunk, _, next) {
@@ -574,7 +570,12 @@ function runTest() {
574570
useColors: false,
575571
preview: opts.preview,
576572
terminal: true
577-
}, function(repl) {
573+
}, function(err, repl) {
574+
if (err) {
575+
console.error(`Failed test # ${numtests - tests.length}`);
576+
throw err;
577+
}
578+
578579
repl.once('close', () => {
579580
if (opts.clean)
580581
cleanupTmpFile();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ const tmpdir = require('../common/tmpdir');
3535
tmpdir.refresh();
3636
const replHistoryPath = path.join(tmpdir.path, '.node_repl_history');
3737

38-
const checkResults = common.mustCall((repl) => {
38+
const checkResults = common.mustCall(function(err, r) {
39+
assert.ifError(err);
40+
3941
const stat = fs.statSync(replHistoryPath);
4042
const fileMode = stat.mode & 0o777;
4143
assert.strictEqual(
4244
fileMode, 0o600,
4345
`REPL history file should be mode 0600 but was 0${fileMode.toString(8)}`);
4446

4547
// Close the REPL
46-
repl.input.emit('keypress', '', { ctrl: true, name: 'd' });
47-
repl.input.end();
48+
r.input.emit('keypress', '', { ctrl: true, name: 'd' });
49+
r.input.end();
4850
});
4951

50-
process.env.NODE_REPL_HISTORY = replHistoryPath;
51-
5252
repl.createInternalRepl(
53+
{ NODE_REPL_HISTORY: replHistoryPath },
5354
{
5455
terminal: true,
5556
input: stream,

test/parallel/test-repl-options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ common.expectWarning({
4242

4343
// Create a dummy stream that does nothing
4444
const stream = new ArrayStream();
45-
stream.hasColors = () => true;
4645

4746
// 1, mostly defaults
4847
const r1 = repl.start({

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ fs.createReadStream(historyFixturePath)
191191

192192
const runTestWrap = common.mustCall(runTest, numtests);
193193

194-
const originalEnv = process.env;
195-
196194
function runTest(assertCleaned) {
197195
const opts = tests.shift();
198196
if (!opts) return; // All done
@@ -210,16 +208,15 @@ function runTest(assertCleaned) {
210208
}
211209
}
212210

211+
const env = opts.env;
213212
const test = opts.test;
214213
const expected = opts.expected;
215214
const clean = opts.clean;
216215
const before = opts.before;
217216

218217
if (before) before();
219218

220-
process.env = { ...originalEnv, ...opts.env };
221-
222-
REPL.createInternalRepl({
219+
REPL.createInternalRepl(env, {
223220
input: new ActionStream(),
224221
output: new stream.Writable({
225222
write(chunk, _, next) {
@@ -242,7 +239,12 @@ function runTest(assertCleaned) {
242239
prompt,
243240
useColors: false,
244241
terminal: true
245-
}, function(repl) {
242+
}, function(err, repl) {
243+
if (err) {
244+
console.error(`Failed test # ${numtests - tests.length}`);
245+
throw err;
246+
}
247+
246248
repl.once('close', () => {
247249
if (repl._flushing) {
248250
repl.once('flushHistory', onClose);

0 commit comments

Comments
 (0)