@@ -8,7 +8,7 @@ const os = require('os');
88const util = require ( 'util' ) ;
99const debug = util . debuglog ( 'repl' ) ;
1010module . exports = Object . create ( REPL ) ;
11- module . exports . createInternalRepl = createInternalRepl ;
11+ module . exports . createInternalRepl = createRepl ;
1212
1313// XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary.
1414// The debounce is to guard against code pasted into the REPL.
@@ -19,7 +19,7 @@ function _writeToOutput(repl, message) {
1919 repl . _refreshLine ( ) ;
2020}
2121
22- function createInternalRepl ( env , opts , cb ) {
22+ function createRepl ( env , opts , cb ) {
2323 if ( typeof opts === 'function' ) {
2424 cb = opts ;
2525 opts = null ;
@@ -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 ) ;
0 commit comments