@@ -85,7 +85,7 @@ const {
85
85
} = require ( 'internal/readline/utils' ) ;
86
86
const { Console } = require ( 'console' ) ;
87
87
const CJSModule = require ( 'internal/modules/cjs/loader' ) . Module ;
88
- const builtinModules = [ ...CJSModule . builtinModules ]
88
+ let _builtinLibs = [ ...CJSModule . builtinModules ]
89
89
. filter ( ( e ) => ! e . startsWith ( '_' ) ) ;
90
90
const domain = require ( 'domain' ) ;
91
91
const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'repl' ) ;
@@ -158,11 +158,9 @@ module.paths = CJSModule._nodeModulePaths(module.filename);
158
158
// This is the default "writer" value, if none is passed in the REPL options,
159
159
// and it can be overridden by custom print functions, such as `probe` or
160
160
// `eyes.js`.
161
- const writer = exports . writer = ( obj ) => inspect ( obj , writer . options ) ;
161
+ const writer = ( obj ) => inspect ( obj , writer . options ) ;
162
162
writer . options = { ...inspect . defaultOptions , showProxy : true } ;
163
163
164
- exports . _builtinLibs = builtinModules ;
165
-
166
164
function REPLServer ( prompt ,
167
165
stream ,
168
166
eval_ ,
@@ -259,7 +257,7 @@ function REPLServer(prompt,
259
257
this . _domain = options . domain || domain . create ( ) ;
260
258
this . useGlobal = ! ! useGlobal ;
261
259
this . ignoreUndefined = ! ! ignoreUndefined ;
262
- this . replMode = replMode || exports . REPL_MODE_SLOPPY ;
260
+ this . replMode = replMode || module . exports . REPL_MODE_SLOPPY ;
263
261
this . underscoreAssigned = false ;
264
262
this . last = undefined ;
265
263
this . underscoreErrAssigned = false ;
@@ -278,7 +276,7 @@ function REPLServer(prompt,
278
276
if ( options [ kStandaloneREPL ] ) {
279
277
// It is possible to introspect the running REPL accessing this variable
280
278
// from inside the REPL. This is useful for anyone working on the REPL.
281
- exports . repl = this ;
279
+ module . exports . repl = this ;
282
280
} else if ( ! addedNewListener ) {
283
281
// Add this listener only once and use a WeakSet that contains the REPLs
284
282
// domains. Otherwise we'd have to add a single listener to each REPL
@@ -399,7 +397,8 @@ function REPLServer(prompt,
399
397
}
400
398
while ( true ) {
401
399
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 ) ) {
403
402
// "void 0" keeps the repl from returning "use strict" as the result
404
403
// value for statements and declarations that don't return a value.
405
404
code = `'use strict'; void 0;\n${ code } ` ;
@@ -579,7 +578,7 @@ function REPLServer(prompt,
579
578
e . stack = e . stack
580
579
. replace ( / ^ r e p l : \d + \r ? \n / , '' )
581
580
. 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 ) {
583
582
e . stack = e . stack . replace ( / ( \s + a t \s + r e p l : ) ( \d + ) / ,
584
583
( _ , pre , line ) => pre + ( line - 1 ) ) ;
585
584
}
@@ -667,7 +666,7 @@ function REPLServer(prompt,
667
666
defineDefaultCommands ( this ) ;
668
667
669
668
// Figure out which "writer" function to use
670
- self . writer = options . writer || exports . writer ;
669
+ self . writer = options . writer || module . exports . writer ;
671
670
672
671
if ( self . writer === writer ) {
673
672
// Conditionally turn on ANSI coloring.
@@ -923,22 +922,12 @@ function REPLServer(prompt,
923
922
ObjectSetPrototypeOf ( REPLServer . prototype , Interface . prototype ) ;
924
923
ObjectSetPrototypeOf ( REPLServer , Interface ) ;
925
924
926
- exports . REPLServer = REPLServer ;
927
-
928
- exports . REPL_MODE_SLOPPY = REPL_MODE_SLOPPY ;
929
- exports . REPL_MODE_STRICT = REPL_MODE_STRICT ;
930
-
931
925
// Prompt is a string to print on each line for the prompt,
932
926
// 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 ) {
939
928
return new REPLServer (
940
929
prompt , source , eval_ , useGlobal , ignoreUndefined , replMode ) ;
941
- } ;
930
+ }
942
931
943
932
REPLServer . prototype . setupHistory = function setupHistory ( historyFile , cb ) {
944
933
history ( this , historyFile , cb ) ;
@@ -993,18 +982,18 @@ REPLServer.prototype.createContext = function() {
993
982
} ) ;
994
983
}
995
984
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 ) ;
998
987
999
988
ObjectDefineProperty ( context , 'module' , {
1000
989
configurable : true ,
1001
990
writable : true ,
1002
- value : module
991
+ value : replModule
1003
992
} ) ;
1004
993
ObjectDefineProperty ( context , 'require' , {
1005
994
configurable : true ,
1006
995
writable : true ,
1007
- value : makeRequireFunction ( module )
996
+ value : makeRequireFunction ( replModule )
1008
997
} ) ;
1009
998
1010
999
addBuiltinLibsToObject ( context ) ;
@@ -1016,6 +1005,7 @@ REPLServer.prototype.resetContext = function() {
1016
1005
this . context = this . createContext ( ) ;
1017
1006
this . underscoreAssigned = false ;
1018
1007
this . underscoreErrAssigned = false ;
1008
+ // TODO(BridgeAR): Deprecate the lines.
1019
1009
this . lines = [ ] ;
1020
1010
this . lines . level = [ ] ;
1021
1011
@@ -1217,7 +1207,7 @@ function complete(line, callback) {
1217
1207
}
1218
1208
1219
1209
if ( ! subdir ) {
1220
- completionGroups . push ( exports . _builtinLibs ) ;
1210
+ completionGroups . push ( _builtinLibs ) ;
1221
1211
}
1222
1212
1223
1213
completionGroupsLoaded ( ) ;
@@ -1610,4 +1600,27 @@ function Recoverable(err) {
1610
1600
}
1611
1601
ObjectSetPrototypeOf ( Recoverable . prototype , SyntaxError . prototype ) ;
1612
1602
ObjectSetPrototypeOf ( 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