@@ -274,17 +274,6 @@ Module._load = function(request, parent, isMain) {
274
274
debug ( 'Module._load REQUEST %s parent: %s' , request , parent . id ) ;
275
275
}
276
276
277
- // REPL is a special case, because it needs the real require.
278
- if ( request === 'internal/repl' || request === 'repl' ) {
279
- if ( Module . _cache [ request ] ) {
280
- return Module . _cache [ request ] ;
281
- }
282
- var replModule = new Module ( request ) ;
283
- replModule . _compile ( NativeModule . getSource ( request ) , `${ request } .js` ) ;
284
- NativeModule . _cache [ request ] = replModule ;
285
- return replModule . exports ;
286
- }
287
-
288
277
var filename = Module . _resolveFilename ( request , parent ) ;
289
278
290
279
var cachedModule = Module . _cache [ filename ] ;
@@ -376,37 +365,9 @@ var resolvedArgv;
376
365
// the file.
377
366
// Returns exception, if any.
378
367
Module . prototype . _compile = function ( content , filename ) {
379
- var self = this ;
380
368
// remove shebang
381
369
content = content . replace ( shebangRe , '' ) ;
382
370
383
- function require ( path ) {
384
- return self . require ( path ) ;
385
- }
386
-
387
- require . resolve = function ( request ) {
388
- return Module . _resolveFilename ( request , self ) ;
389
- } ;
390
-
391
- Object . defineProperty ( require , 'paths' , { get : function ( ) {
392
- throw new Error ( 'require.paths is removed. Use ' +
393
- 'node_modules folders, or the NODE_PATH ' +
394
- 'environment variable instead.' ) ;
395
- } } ) ;
396
-
397
- require . main = process . mainModule ;
398
-
399
- // Enable support to add extra extension types
400
- require . extensions = Module . _extensions ;
401
- require . registerExtension = function ( ) {
402
- throw new Error ( 'require.registerExtension() removed. Use ' +
403
- 'require.extensions instead.' ) ;
404
- } ;
405
-
406
- require . cache = Module . _cache ;
407
-
408
- var dirname = path . dirname ( filename ) ;
409
-
410
371
// create wrapper function
411
372
var wrapper = Module . wrap ( content ) ;
412
373
@@ -431,8 +392,22 @@ Module.prototype._compile = function(content, filename) {
431
392
global . v8debug . Debug . setBreakPoint ( compiledWrapper , 0 , 0 ) ;
432
393
}
433
394
}
434
- var args = [ self . exports , require , self , filename , dirname ] ;
435
- return compiledWrapper . apply ( self . exports , args ) ;
395
+ const dirname = path . dirname ( filename ) ;
396
+ const require = internalModule . makeRequireFunction . call ( this ) ;
397
+
398
+ Object . defineProperty ( require , 'paths' , { get : function ( ) {
399
+ throw new Error ( 'require.paths is removed. Use ' +
400
+ 'node_modules folders, or the NODE_PATH ' +
401
+ 'environment variable instead.' ) ;
402
+ } } ) ;
403
+
404
+ require . registerExtension = function ( ) {
405
+ throw new Error ( 'require.registerExtension() removed. Use ' +
406
+ 'require.extensions instead.' ) ;
407
+ } ;
408
+
409
+ const args = [ this . exports , require , this , filename , dirname ] ;
410
+ return compiledWrapper . apply ( this . exports , args ) ;
436
411
} ;
437
412
438
413
@@ -498,10 +473,10 @@ Module._initPaths = function() {
498
473
Module . globalPaths = modulePaths . slice ( 0 ) ;
499
474
} ;
500
475
501
- // bootstrap repl
502
- Module . requireRepl = function ( ) {
503
- return Module . _load ( 'internal/repl' , '. ') ;
504
- } ;
476
+ // TODO(bnoordhuis) Unused, remove in the future.
477
+ Module . requireRepl = internalUtil . deprecate ( function ( ) {
478
+ return NativeModule . require ( 'internal/repl' ) ;
479
+ } , 'Module.requireRepl is deprecated.' ) ;
505
480
506
481
Module . _preloadModules = function ( requests ) {
507
482
if ( ! Array . isArray ( requests ) )
0 commit comments