@@ -70,7 +70,6 @@ const {
7070 CHAR_FORWARD_SLASH ,
7171 CHAR_BACKWARD_SLASH ,
7272 CHAR_COLON ,
73- CHAR_DOT ,
7473 CHAR_UNDERSCORE ,
7574 CHAR_0 ,
7675 CHAR_9 ,
@@ -306,7 +305,6 @@ function findLongestRegisteredExtension(filename) {
306305 return '.js' ;
307306}
308307
309- var warned = false ;
310308Module . _findPath = function ( request , paths , isMain ) {
311309 if ( path . isAbsolute ( request ) ) {
312310 paths = [ '' ] ;
@@ -375,18 +373,6 @@ Module._findPath = function(request, paths, isMain) {
375373 }
376374
377375 if ( filename ) {
378- // Warn once if '.' resolved outside the module dir
379- if ( request === '.' && i > 0 ) {
380- if ( ! warned ) {
381- warned = true ;
382- process . emitWarning (
383- 'warning: require(\'.\') resolved outside the package ' +
384- 'directory. This functionality is deprecated and will be removed ' +
385- 'soon.' ,
386- 'DeprecationWarning' , 'DEP0019' ) ;
387- }
388- }
389-
390376 Module . _pathCache [ cacheKey ] = filename ;
391377 return filename ;
392378 }
@@ -490,35 +476,23 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
490476 return ( newReturn ? null : [ request , [ ] ] ) ;
491477 }
492478
493- // Check for non-relative path
494- if ( request . length < 2 ||
495- request . charCodeAt ( 0 ) !== CHAR_DOT ||
496- ( request . charCodeAt ( 1 ) !== CHAR_DOT &&
497- request . charCodeAt ( 1 ) !== CHAR_FORWARD_SLASH &&
498- ( ! isWindows || request . charCodeAt ( 1 ) !== CHAR_BACKWARD_SLASH ) ) ) {
499- var paths = modulePaths ;
500- if ( parent ) {
501- if ( ! parent . paths )
502- paths = parent . paths = [ ] ;
503- else
504- paths = parent . paths . concat ( paths ) ;
505- }
479+ // Check for node modules paths.
480+ if ( request . charAt ( 0 ) !== '.' ||
481+ ( request . length > 1 &&
482+ request . charAt ( 1 ) !== '.' &&
483+ request . charAt ( 1 ) !== '/' &&
484+ ( ! isWindows || request . charAt ( 1 ) !== '\\' ) ) ) {
506485
507- // Maintain backwards compat with certain broken uses of require('.')
508- // by putting the module's directory in front of the lookup paths.
509- if ( request === '.' ) {
510- if ( parent && parent . filename ) {
511- paths . unshift ( path . dirname ( parent . filename ) ) ;
512- } else {
513- paths . unshift ( path . resolve ( request ) ) ;
514- }
486+ let paths = modulePaths ;
487+ if ( parent != null && parent . paths && parent . paths . length ) {
488+ paths = parent . paths . concat ( paths ) ;
515489 }
516490
517491 debug ( 'looking for %j in %j' , request , paths ) ;
518492 return ( newReturn ? ( paths . length > 0 ? paths : null ) : [ request , paths ] ) ;
519493 }
520494
521- // with --eval, parent.id is not set and parent.filename is null
495+ // With --eval, parent.id is not set and parent.filename is null.
522496 if ( ! parent || ! parent . id || ! parent . filename ) {
523497 // Make require('./path/to/foo') work - normally the path is taken
524498 // from realpath(__filename) but with eval there is no filename
0 commit comments