@@ -85,7 +85,7 @@ const {
8585} = require ( 'internal/readline/utils' ) ;
8686const { Console } = require ( 'console' ) ;
8787const CJSModule = require ( 'internal/modules/cjs/loader' ) . Module ;
88- const builtinModules = [ ...CJSModule . builtinModules ]
88+ let _builtinLibs = [ ...CJSModule . builtinModules ]
8989 . filter ( ( e ) => ! e . startsWith ( '_' ) ) ;
9090const domain = require ( 'domain' ) ;
9191const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'repl' ) ;
@@ -158,11 +158,9 @@ module.paths = CJSModule._nodeModulePaths(module.filename);
158158// This is the default "writer" value, if none is passed in the REPL options,
159159// and it can be overridden by custom print functions, such as `probe` or
160160// `eyes.js`.
161- const writer = exports . writer = ( obj ) => inspect ( obj , writer . options ) ;
161+ const writer = ( obj ) => inspect ( obj , writer . options ) ;
162162writer . options = { ...inspect . defaultOptions , showProxy : true } ;
163163
164- exports . _builtinLibs = builtinModules ;
165-
166164function REPLServer ( prompt ,
167165 stream ,
168166 eval_ ,
@@ -259,7 +257,7 @@ function REPLServer(prompt,
259257 this . _domain = options . domain || domain . create ( ) ;
260258 this . useGlobal = ! ! useGlobal ;
261259 this . ignoreUndefined = ! ! ignoreUndefined ;
262- this . replMode = replMode || exports . REPL_MODE_SLOPPY ;
260+ this . replMode = replMode || module . exports . REPL_MODE_SLOPPY ;
263261 this . underscoreAssigned = false ;
264262 this . last = undefined ;
265263 this . underscoreErrAssigned = false ;
@@ -278,7 +276,7 @@ function REPLServer(prompt,
278276 if ( options [ kStandaloneREPL ] ) {
279277 // It is possible to introspect the running REPL accessing this variable
280278 // from inside the REPL. This is useful for anyone working on the REPL.
281- exports . repl = this ;
279+ module . exports . repl = this ;
282280 } else if ( ! addedNewListener ) {
283281 // Add this listener only once and use a WeakSet that contains the REPLs
284282 // domains. Otherwise we'd have to add a single listener to each REPL
@@ -399,7 +397,8 @@ function REPLServer(prompt,
399397 }
400398 while ( true ) {
401399 try {
402- if ( self . replMode === exports . REPL_MODE_STRICT && ! / ^ \s * $ / . test ( code ) ) {
400+ if ( self . replMode === module . exports . REPL_MODE_STRICT &&
401+ ! / ^ \s * $ / . test ( code ) ) {
403402 // "void 0" keeps the repl from returning "use strict" as the result
404403 // value for statements and declarations that don't return a value.
405404 code = `'use strict'; void 0;\n${ code } ` ;
@@ -579,7 +578,7 @@ function REPLServer(prompt,
579578 e . stack = e . stack
580579 . replace ( / ^ r e p l : \d + \r ? \n / , '' )
581580 . replace ( / ^ \s + a t \s .* \n ? / gm, '' ) ;
582- } else if ( self . replMode === exports . REPL_MODE_STRICT ) {
581+ } else if ( self . replMode === module . exports . REPL_MODE_STRICT ) {
583582 e . stack = e . stack . replace ( / ( \s + a t \s + r e p l : ) ( \d + ) / ,
584583 ( _ , pre , line ) => pre + ( line - 1 ) ) ;
585584 }
@@ -667,7 +666,7 @@ function REPLServer(prompt,
667666 defineDefaultCommands ( this ) ;
668667
669668 // Figure out which "writer" function to use
670- self . writer = options . writer || exports . writer ;
669+ self . writer = options . writer || module . exports . writer ;
671670
672671 if ( self . writer === writer ) {
673672 // Conditionally turn on ANSI coloring.
@@ -923,22 +922,12 @@ function REPLServer(prompt,
923922ObjectSetPrototypeOf ( REPLServer . prototype , Interface . prototype ) ;
924923ObjectSetPrototypeOf ( REPLServer , Interface ) ;
925924
926- exports . REPLServer = REPLServer ;
927-
928- exports . REPL_MODE_SLOPPY = REPL_MODE_SLOPPY ;
929- exports . REPL_MODE_STRICT = REPL_MODE_STRICT ;
930-
931925// Prompt is a string to print on each line for the prompt,
932926// source is a stream to use for I/O, defaulting to stdin/stdout.
933- exports . start = function ( prompt ,
934- source ,
935- eval_ ,
936- useGlobal ,
937- ignoreUndefined ,
938- replMode ) {
927+ function start ( prompt , source , eval_ , useGlobal , ignoreUndefined , replMode ) {
939928 return new REPLServer (
940929 prompt , source , eval_ , useGlobal , ignoreUndefined , replMode ) ;
941- } ;
930+ }
942931
943932REPLServer . prototype . setupHistory = function setupHistory ( historyFile , cb ) {
944933 history ( this , historyFile , cb ) ;
@@ -993,18 +982,18 @@ REPLServer.prototype.createContext = function() {
993982 } ) ;
994983 }
995984
996- const module = new CJSModule ( '<repl>' ) ;
997- module . paths = CJSModule . _resolveLookupPaths ( '<repl>' , parentModule ) ;
985+ const replModule = new CJSModule ( '<repl>' ) ;
986+ replModule . paths = CJSModule . _resolveLookupPaths ( '<repl>' , parentModule ) ;
998987
999988 ObjectDefineProperty ( context , 'module' , {
1000989 configurable : true ,
1001990 writable : true ,
1002- value : module
991+ value : replModule
1003992 } ) ;
1004993 ObjectDefineProperty ( context , 'require' , {
1005994 configurable : true ,
1006995 writable : true ,
1007- value : makeRequireFunction ( module )
996+ value : makeRequireFunction ( replModule )
1008997 } ) ;
1009998
1010999 addBuiltinLibsToObject ( context ) ;
@@ -1016,6 +1005,7 @@ REPLServer.prototype.resetContext = function() {
10161005 this . context = this . createContext ( ) ;
10171006 this . underscoreAssigned = false ;
10181007 this . underscoreErrAssigned = false ;
1008+ // TODO(BridgeAR): Deprecate the lines.
10191009 this . lines = [ ] ;
10201010 this . lines . level = [ ] ;
10211011
@@ -1217,7 +1207,7 @@ function complete(line, callback) {
12171207 }
12181208
12191209 if ( ! subdir ) {
1220- completionGroups . push ( exports . _builtinLibs ) ;
1210+ completionGroups . push ( _builtinLibs ) ;
12211211 }
12221212
12231213 completionGroupsLoaded ( ) ;
@@ -1610,4 +1600,27 @@ function Recoverable(err) {
16101600}
16111601ObjectSetPrototypeOf ( Recoverable . prototype , SyntaxError . prototype ) ;
16121602ObjectSetPrototypeOf ( Recoverable , SyntaxError ) ;
1613- exports . Recoverable = Recoverable ;
1603+
1604+ module . exports = {
1605+ start,
1606+ writer,
1607+ REPLServer,
1608+ REPL_MODE_SLOPPY ,
1609+ REPL_MODE_STRICT ,
1610+ Recoverable
1611+ } ;
1612+
1613+ ObjectDefineProperty ( module . exports , '_builtinLibs' , {
1614+ get : pendingDeprecation ? deprecate (
1615+ ( ) => _builtinLibs ,
1616+ 'repl._builtinLibs is deprecated. Check module.builtinModules instead' ,
1617+ 'DEP0XX1'
1618+ ) : ( ) => _builtinLibs ,
1619+ set : pendingDeprecation ? deprecate (
1620+ ( val ) => _builtinLibs = val ,
1621+ 'repl._builtinLibs is deprecated. Check module.builtinModules instead' ,
1622+ 'DEP0XX1'
1623+ ) : ( val ) => _builtinLibs = val ,
1624+ enumerable : false ,
1625+ configurable : true
1626+ } ) ;
0 commit comments