From 11dd5052ce21a2bb5b711f8833810ce6d246b2ab Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 22 Jun 2017 18:47:44 +0200 Subject: [PATCH] repl: remove deprecated NODE_REPL_HISTORY_FILE --- doc/api/deprecations.md | 8 ++ doc/api/repl.md | 16 ---- lib/internal/repl.js | 60 ++------------ test/fixtures/old-repl-history-file.json | 4 - test/parallel/test-repl-persistent-history.js | 82 +------------------ 5 files changed, 20 insertions(+), 150 deletions(-) delete mode 100644 test/fixtures/old-repl-history-file.json diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index c18c9d58e0b521..e4cad9e1ab8491 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -892,6 +892,14 @@ Use [`asyncResource.runInAsyncScope()`][] API instead which provides a much safer, and more convenient, alternative. See https://github.com/nodejs/node/pull/18513 for more details. + +### DEP0XXX: NODE_REPL_HISTORY_FILE environment variable + +Type: End-of-life + +`NODE_REPL_HISTORY_FILE` environment variable was removed. Please use +`NODE_REPL_HISTORY` instead. + [`--pending-deprecation`]: cli.html#cli_pending_deprecation [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array diff --git a/doc/api/repl.md b/doc/api/repl.md index 506f54a4b8a2a8..182c0434c0340a 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -506,22 +506,6 @@ by saving inputs to a `.node_repl_history` file located in the user's home directory. This can be disabled by setting the environment variable `NODE_REPL_HISTORY=""`. -#### NODE_REPL_HISTORY_FILE - - -> Stability: 0 - Deprecated: Use `NODE_REPL_HISTORY` instead. - -Previously in Node.js/io.js v2.x, REPL history was controlled by using a -`NODE_REPL_HISTORY_FILE` environment variable, and the history was saved in JSON -format. This variable has now been deprecated, and the old JSON REPL history -file will be automatically converted to a simplified plain text format. This new -file will be saved to either the user's home directory, or a directory defined -by the `NODE_REPL_HISTORY` variable, as documented in the -[Environment Variable Options](#repl_environment_variable_options). - ### Using the Node.js REPL with advanced line-editors For advanced line-editors, start Node.js with the environment variable diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 76412c3b118a8c..25874ed52b5666 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -34,8 +34,8 @@ function createInternalRepl(env, opts, cb) { if (parseInt(env.NODE_NO_READLINE)) { opts.terminal = false; } - // the "dumb" special terminal, as defined by terminfo, doesn't support - // ANSI color control codes. + // The "dumb" special terminal, as defined by terminfo, doesn't support + // ANSI colour control codes. // see http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials if (parseInt(env.NODE_DISABLE_COLORS) || env.TERM === 'dumb') { opts.useColors = false; @@ -61,17 +61,15 @@ function createInternalRepl(env, opts, cb) { const repl = REPL.start(opts); if (opts.terminal) { - return setupHistory(repl, env.NODE_REPL_HISTORY, - env.NODE_REPL_HISTORY_FILE, cb); + return setupHistory(repl, env.NODE_REPL_HISTORY, cb); } repl._historyPrev = _replHistoryMessage; cb(null, repl); } -function setupHistory(repl, historyPath, oldHistoryPath, ready) { - // Empty string disables persistent history. - +function setupHistory(repl, historyPath, ready) { + // Empty string disables persistent history if (typeof historyPath === 'string') historyPath = historyPath.trim(); @@ -131,50 +129,8 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { if (data) { repl.history = data.split(/[\n\r]+/, repl.historySize); - } else if (oldHistoryPath === historyPath) { - // If pre-v3.0, the user had set NODE_REPL_HISTORY_FILE to - // ~/.node_repl_history, warn the user about it and proceed. - _writeToOutput( - repl, - '\nThe old repl history file has the same name and location as ' + - `the new one i.e., ${historyPath} and is empty.\nUsing it as is.\n`); - - } else if (oldHistoryPath) { - let threw = false; - try { - // Pre-v3.0, repl history was stored as JSON. - // Try and convert it to line separated history. - const oldReplJSONHistory = fs.readFileSync(oldHistoryPath, 'utf8'); - - // Only attempt to use the history if there was any. - if (oldReplJSONHistory) repl.history = JSON.parse(oldReplJSONHistory); - - if (Array.isArray(repl.history)) { - repl.history = repl.history.slice(0, repl.historySize); - } else { - threw = true; - _writeToOutput( - repl, - '\nError: The old history file data has to be an Array.\n' + - 'REPL session history will not be persisted.\n'); - } - } catch (err) { - // Cannot open or parse history file. - // Don't crash, just don't persist history. - threw = true; - const type = err instanceof SyntaxError ? 'parse' : 'open'; - _writeToOutput(repl, `\nError: Could not ${type} old history file.\n` + - 'REPL session history will not be persisted.\n'); - } - if (!threw) { - // Grab data from the older pre-v3.0 JSON NODE_REPL_HISTORY_FILE format. - _writeToOutput( - repl, - '\nConverted old JSON repl history to line-separated history.\n' + - `The new repl history file can be found at ${historyPath}.\n`); - } else { - repl.history = []; - } + } else { + repl.history = []; } fs.open(historyPath, 'r+', onhandle); @@ -188,7 +144,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { repl._historyHandle = hnd; repl.on('line', online); - // reading the file data out erases it + // Reading the file data out erases it repl.once('flushHistory', function() { repl.resume(); ready(null, repl); diff --git a/test/fixtures/old-repl-history-file.json b/test/fixtures/old-repl-history-file.json deleted file mode 100644 index 963d93ddf379c0..00000000000000 --- a/test/fixtures/old-repl-history-file.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "'=^.^='", - "'hello world'" -] diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 43c868f8326f3f..4d0330272ab3c6 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -58,11 +58,6 @@ const CLEAR = { ctrl: true, name: 'u' }; const historyFixturePath = fixtures.path('.node_repl_history'); const historyPath = path.join(tmpdir.path, '.fixture_copy_repl_history'); const historyPathFail = fixtures.path('nonexistent_folder', 'filename'); -const oldHistoryPathObj = fixtures.path('old-repl-history-file-obj.json'); -const oldHistoryPathFaulty = fixtures.path('old-repl-history-file-faulty.json'); -const oldHistoryPath = fixtures.path('old-repl-history-file.json'); -const enoentHistoryPath = fixtures.path('enoent-repl-history-file.json'); -const emptyHistoryPath = fixtures.path('.empty-repl-history-file'); const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history'); const emptyHiddenHistoryPath = fixtures.path('.empty-hidden-repl-history-file'); const devNullHistoryPath = path.join(tmpdir.path, @@ -72,23 +67,10 @@ const prompt = '> '; const replDisabled = '\nPersistent history support disabled. Set the ' + 'NODE_REPL_HISTORY environment\nvariable to a valid, ' + 'user-writable path to enable.\n'; -const convertMsg = '\nConverted old JSON repl history to line-separated ' + - 'history.\nThe new repl history file can be found at ' + - `${defaultHistoryPath}.\n`; const homedirErr = '\nError: Could not get the home directory.\n' + 'REPL session history will not be persisted.\n'; const replFailedRead = '\nError: Could not open history file.\n' + 'REPL session history will not be persisted.\n'; -const oldHistoryFailedOpen = '\nError: Could not open old history file.\n' + - 'REPL session history will not be persisted.\n'; -const oldHistoryFailedParse = '\nError: Could not parse old history file.\n' + - 'REPL session history will not be persisted.\n'; -const oldHistoryObj = '\nError: The old history file data has to be an Array' + - '.\nREPL session history will not be persisted.\n'; -const sameHistoryFilePaths = '\nThe old repl history file has the same name ' + - 'and location as the new one i.e., ' + - `${defaultHistoryPath}` + - ' and is empty.\nUsing it as is.\n'; const tests = [ { @@ -101,71 +83,21 @@ const tests = [ test: [UP], expected: [prompt, replDisabled, prompt] }, - { - env: { NODE_REPL_HISTORY_FILE: enoentHistoryPath }, - test: [UP], - expected: [prompt, oldHistoryFailedOpen, prompt] - }, - { - env: { NODE_REPL_HISTORY_FILE: oldHistoryPathObj }, - test: [UP], - expected: [prompt, oldHistoryObj, prompt] - }, - { - env: { NODE_REPL_HISTORY_FILE: oldHistoryPathFaulty }, - test: [UP], - expected: [prompt, oldHistoryFailedParse, prompt] - }, - { - env: { NODE_REPL_HISTORY: '', - NODE_REPL_HISTORY_FILE: oldHistoryPath }, - test: [UP], - expected: [prompt, replDisabled, prompt] - }, - { - env: { NODE_REPL_HISTORY_FILE: emptyHistoryPath }, - test: [UP], - expected: [prompt, convertMsg, prompt] - }, - { - env: { NODE_REPL_HISTORY_FILE: defaultHistoryPath }, - test: [UP], - expected: [prompt, sameHistoryFilePaths, prompt] - }, { env: { NODE_REPL_HISTORY: historyPath }, test: [UP, CLEAR], expected: [prompt, `${prompt}'you look fabulous today'`, prompt] }, - { - env: { NODE_REPL_HISTORY: historyPath, - NODE_REPL_HISTORY_FILE: oldHistoryPath }, - test: [UP, CLEAR], - expected: [prompt, `${prompt}'you look fabulous today'`, prompt] - }, - { - env: { NODE_REPL_HISTORY: historyPath, - NODE_REPL_HISTORY_FILE: '' }, - test: [UP, CLEAR], - expected: [prompt, `${prompt}'you look fabulous today'`, prompt] - }, { env: {}, - test: [UP], - expected: [prompt] - }, - { - env: { NODE_REPL_HISTORY_FILE: oldHistoryPath }, - test: [UP, CLEAR, '\'42\'', ENTER], - expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt, '\'', - '4', '2', '\'', '\'42\'\n', prompt, prompt], + test: [UP, '\'42\'', ENTER], + expected: [prompt, '\'', '4', '2', '\'', '\'42\'\n', prompt, prompt], clean: false }, - { // Requires the above testcase + { // Requires the above test case env: {}, test: [UP, UP, ENTER], - expected: [prompt, `${prompt}'42'`, `${prompt}'=^.^='`, '\'=^.^=\'\n', - prompt] + expected: [prompt, `${prompt}'42'`, '\'42\'\n', prompt] }, { env: { NODE_REPL_HISTORY: historyPath, @@ -173,12 +105,6 @@ const tests = [ test: [UP, UP, CLEAR], expected: [prompt, `${prompt}'you look fabulous today'`, prompt] }, - { - env: { NODE_REPL_HISTORY_FILE: oldHistoryPath, - NODE_REPL_HISTORY_SIZE: 1 }, - test: [UP, UP, UP, CLEAR], - expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt] - }, { env: { NODE_REPL_HISTORY: historyPathFail, NODE_REPL_HISTORY_SIZE: 1 },