Skip to content

Commit 60c9ad7

Browse files
committed
repl: remove deprecated NODE_REPL_HISTORY_FILE
PR-URL: #13876 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1a5f670 commit 60c9ad7

File tree

5 files changed

+14
-151
lines changed

5 files changed

+14
-151
lines changed

doc/api/deprecations.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,10 @@ instead.
378378
<a id="DEP0041"></a>
379379
### DEP0041: NODE\_REPL\_HISTORY\_FILE environment variable
380380

381-
Type: Documentation-only
381+
Type: End-of-life
382382

383-
The `NODE_REPL_HISTORY_FILE` environment variable has been deprecated.
383+
The `NODE_REPL_HISTORY_FILE` environment variable was removed. Please use
384+
`NODE_REPL_HISTORY` instead.
384385

385386
<a id="DEP0042"></a>
386387
### DEP0042: tls.CryptoStream

doc/api/repl.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,6 @@ by saving inputs to a `.node_repl_history` file located in the user's home
506506
directory. This can be disabled by setting the environment variable
507507
`NODE_REPL_HISTORY=""`.
508508

509-
#### NODE_REPL_HISTORY_FILE
510-
<!-- YAML
511-
added: v2.0.0
512-
deprecated: v3.0.0
513-
-->
514-
515-
> Stability: 0 - Deprecated: Use `NODE_REPL_HISTORY` instead.
516-
517-
Previously in Node.js/io.js v2.x, REPL history was controlled by using a
518-
`NODE_REPL_HISTORY_FILE` environment variable, and the history was saved in JSON
519-
format. This variable has now been deprecated, and the old JSON REPL history
520-
file will be automatically converted to a simplified plain text format. This new
521-
file will be saved to either the user's home directory, or a directory defined
522-
by the `NODE_REPL_HISTORY` variable, as documented in the
523-
[Environment Variable Options](#repl_environment_variable_options).
524-
525509
### Using the Node.js REPL with advanced line-editors
526510

527511
For advanced line-editors, start Node.js with the environment variable

lib/internal/repl.js

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function createInternalRepl(env, opts, cb) {
3434
if (parseInt(env.NODE_NO_READLINE)) {
3535
opts.terminal = false;
3636
}
37-
// the "dumb" special terminal, as defined by terminfo, doesn't support
37+
// The "dumb" special terminal, as defined by terminfo, doesn't support
3838
// ANSI color control codes.
3939
// see http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
4040
if (parseInt(env.NODE_DISABLE_COLORS) || env.TERM === 'dumb') {
@@ -61,17 +61,15 @@ function createInternalRepl(env, opts, cb) {
6161

6262
const repl = REPL.start(opts);
6363
if (opts.terminal) {
64-
return setupHistory(repl, env.NODE_REPL_HISTORY,
65-
env.NODE_REPL_HISTORY_FILE, cb);
64+
return setupHistory(repl, env.NODE_REPL_HISTORY, cb);
6665
}
6766

6867
repl._historyPrev = _replHistoryMessage;
6968
cb(null, repl);
7069
}
7170

72-
function setupHistory(repl, historyPath, oldHistoryPath, ready) {
73-
// Empty string disables persistent history.
74-
71+
function setupHistory(repl, historyPath, ready) {
72+
// Empty string disables persistent history
7573
if (typeof historyPath === 'string')
7674
historyPath = historyPath.trim();
7775

@@ -131,50 +129,8 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
131129

132130
if (data) {
133131
repl.history = data.split(/[\n\r]+/, repl.historySize);
134-
} else if (oldHistoryPath === historyPath) {
135-
// If pre-v3.0, the user had set NODE_REPL_HISTORY_FILE to
136-
// ~/.node_repl_history, warn the user about it and proceed.
137-
_writeToOutput(
138-
repl,
139-
'\nThe old repl history file has the same name and location as ' +
140-
`the new one i.e., ${historyPath} and is empty.\nUsing it as is.\n`);
141-
142-
} else if (oldHistoryPath) {
143-
let threw = false;
144-
try {
145-
// Pre-v3.0, repl history was stored as JSON.
146-
// Try and convert it to line separated history.
147-
const oldReplJSONHistory = fs.readFileSync(oldHistoryPath, 'utf8');
148-
149-
// Only attempt to use the history if there was any.
150-
if (oldReplJSONHistory) repl.history = JSON.parse(oldReplJSONHistory);
151-
152-
if (Array.isArray(repl.history)) {
153-
repl.history = repl.history.slice(0, repl.historySize);
154-
} else {
155-
threw = true;
156-
_writeToOutput(
157-
repl,
158-
'\nError: The old history file data has to be an Array.\n' +
159-
'REPL session history will not be persisted.\n');
160-
}
161-
} catch (err) {
162-
// Cannot open or parse history file.
163-
// Don't crash, just don't persist history.
164-
threw = true;
165-
const type = err instanceof SyntaxError ? 'parse' : 'open';
166-
_writeToOutput(repl, `\nError: Could not ${type} old history file.\n` +
167-
'REPL session history will not be persisted.\n');
168-
}
169-
if (!threw) {
170-
// Grab data from the older pre-v3.0 JSON NODE_REPL_HISTORY_FILE format.
171-
_writeToOutput(
172-
repl,
173-
'\nConverted old JSON repl history to line-separated history.\n' +
174-
`The new repl history file can be found at ${historyPath}.\n`);
175-
} else {
176-
repl.history = [];
177-
}
132+
} else {
133+
repl.history = [];
178134
}
179135

180136
fs.open(historyPath, 'r+', onhandle);
@@ -188,7 +144,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
188144
repl._historyHandle = hnd;
189145
repl.on('line', online);
190146

191-
// reading the file data out erases it
147+
// Reading the file data out erases it
192148
repl.once('flushHistory', function() {
193149
repl.resume();
194150
ready(null, repl);

test/fixtures/old-repl-history-file.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ const CLEAR = { ctrl: true, name: 'u' };
5858
const historyFixturePath = fixtures.path('.node_repl_history');
5959
const historyPath = path.join(tmpdir.path, '.fixture_copy_repl_history');
6060
const historyPathFail = fixtures.path('nonexistent_folder', 'filename');
61-
const oldHistoryPathObj = fixtures.path('old-repl-history-file-obj.json');
62-
const oldHistoryPathFaulty = fixtures.path('old-repl-history-file-faulty.json');
63-
const oldHistoryPath = fixtures.path('old-repl-history-file.json');
64-
const enoentHistoryPath = fixtures.path('enoent-repl-history-file.json');
65-
const emptyHistoryPath = fixtures.path('.empty-repl-history-file');
6661
const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history');
6762
const emptyHiddenHistoryPath = fixtures.path('.empty-hidden-repl-history-file');
6863
const devNullHistoryPath = path.join(tmpdir.path,
@@ -72,23 +67,10 @@ const prompt = '> ';
7267
const replDisabled = '\nPersistent history support disabled. Set the ' +
7368
'NODE_REPL_HISTORY environment\nvariable to a valid, ' +
7469
'user-writable path to enable.\n';
75-
const convertMsg = '\nConverted old JSON repl history to line-separated ' +
76-
'history.\nThe new repl history file can be found at ' +
77-
`${defaultHistoryPath}.\n`;
7870
const homedirErr = '\nError: Could not get the home directory.\n' +
7971
'REPL session history will not be persisted.\n';
8072
const replFailedRead = '\nError: Could not open history file.\n' +
8173
'REPL session history will not be persisted.\n';
82-
const oldHistoryFailedOpen = '\nError: Could not open old history file.\n' +
83-
'REPL session history will not be persisted.\n';
84-
const oldHistoryFailedParse = '\nError: Could not parse old history file.\n' +
85-
'REPL session history will not be persisted.\n';
86-
const oldHistoryObj = '\nError: The old history file data has to be an Array' +
87-
'.\nREPL session history will not be persisted.\n';
88-
const sameHistoryFilePaths = '\nThe old repl history file has the same name ' +
89-
'and location as the new one i.e., ' +
90-
`${defaultHistoryPath}` +
91-
' and is empty.\nUsing it as is.\n';
9274

9375
const tests = [
9476
{
@@ -101,84 +83,28 @@ const tests = [
10183
test: [UP],
10284
expected: [prompt, replDisabled, prompt]
10385
},
104-
{
105-
env: { NODE_REPL_HISTORY_FILE: enoentHistoryPath },
106-
test: [UP],
107-
expected: [prompt, oldHistoryFailedOpen, prompt]
108-
},
109-
{
110-
env: { NODE_REPL_HISTORY_FILE: oldHistoryPathObj },
111-
test: [UP],
112-
expected: [prompt, oldHistoryObj, prompt]
113-
},
114-
{
115-
env: { NODE_REPL_HISTORY_FILE: oldHistoryPathFaulty },
116-
test: [UP],
117-
expected: [prompt, oldHistoryFailedParse, prompt]
118-
},
119-
{
120-
env: { NODE_REPL_HISTORY: '',
121-
NODE_REPL_HISTORY_FILE: oldHistoryPath },
122-
test: [UP],
123-
expected: [prompt, replDisabled, prompt]
124-
},
125-
{
126-
env: { NODE_REPL_HISTORY_FILE: emptyHistoryPath },
127-
test: [UP],
128-
expected: [prompt, convertMsg, prompt]
129-
},
130-
{
131-
env: { NODE_REPL_HISTORY_FILE: defaultHistoryPath },
132-
test: [UP],
133-
expected: [prompt, sameHistoryFilePaths, prompt]
134-
},
13586
{
13687
env: { NODE_REPL_HISTORY: historyPath },
13788
test: [UP, CLEAR],
13889
expected: [prompt, `${prompt}'you look fabulous today'`, prompt]
13990
},
140-
{
141-
env: { NODE_REPL_HISTORY: historyPath,
142-
NODE_REPL_HISTORY_FILE: oldHistoryPath },
143-
test: [UP, CLEAR],
144-
expected: [prompt, `${prompt}'you look fabulous today'`, prompt]
145-
},
146-
{
147-
env: { NODE_REPL_HISTORY: historyPath,
148-
NODE_REPL_HISTORY_FILE: '' },
149-
test: [UP, CLEAR],
150-
expected: [prompt, `${prompt}'you look fabulous today'`, prompt]
151-
},
15291
{
15392
env: {},
154-
test: [UP],
155-
expected: [prompt]
156-
},
157-
{
158-
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath },
159-
test: [UP, CLEAR, '\'42\'', ENTER],
160-
expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt, '\'',
161-
'4', '2', '\'', '\'42\'\n', prompt, prompt],
93+
test: [UP, '\'42\'', ENTER],
94+
expected: [prompt, '\'', '4', '2', '\'', '\'42\'\n', prompt, prompt],
16295
clean: false
16396
},
164-
{ // Requires the above testcase
97+
{ // Requires the above test case
16598
env: {},
16699
test: [UP, UP, ENTER],
167-
expected: [prompt, `${prompt}'42'`, `${prompt}'=^.^='`, '\'=^.^=\'\n',
168-
prompt]
100+
expected: [prompt, `${prompt}'42'`, '\'42\'\n', prompt]
169101
},
170102
{
171103
env: { NODE_REPL_HISTORY: historyPath,
172104
NODE_REPL_HISTORY_SIZE: 1 },
173105
test: [UP, UP, CLEAR],
174106
expected: [prompt, `${prompt}'you look fabulous today'`, prompt]
175107
},
176-
{
177-
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath,
178-
NODE_REPL_HISTORY_SIZE: 1 },
179-
test: [UP, UP, UP, CLEAR],
180-
expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt]
181-
},
182108
{
183109
env: { NODE_REPL_HISTORY: historyPathFail,
184110
NODE_REPL_HISTORY_SIZE: 1 },

0 commit comments

Comments
 (0)