@@ -65,16 +65,9 @@ let ModuleJob;
6565let createDynamicModule ;
6666
6767const {
68- CHAR_UPPERCASE_A ,
69- CHAR_LOWERCASE_A ,
70- CHAR_UPPERCASE_Z ,
71- CHAR_LOWERCASE_Z ,
7268 CHAR_FORWARD_SLASH ,
7369 CHAR_BACKWARD_SLASH ,
74- CHAR_COLON ,
75- CHAR_UNDERSCORE ,
76- CHAR_0 ,
77- CHAR_9 ,
70+ CHAR_COLON
7871} = require ( 'internal/constants' ) ;
7972
8073const isWindows = process . platform === 'win32' ;
@@ -472,14 +465,10 @@ if (isWindows) {
472465 } ;
473466}
474467
475-
476- // 'index.' character codes
477- const indexChars = [ 105 , 110 , 100 , 101 , 120 , 46 ] ;
478- const indexLen = indexChars . length ;
479- Module . _resolveLookupPaths = function ( request , parent , newReturn ) {
468+ Module . _resolveLookupPaths = function ( request , parent ) {
480469 if ( NativeModule . canBeRequiredByUsers ( request ) ) {
481470 debug ( 'looking for %j in []' , request ) ;
482- return ( newReturn ? null : [ request , [ ] ] ) ;
471+ return null ;
483472 }
484473
485474 // Check for node modules paths.
@@ -495,71 +484,24 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
495484 }
496485
497486 debug ( 'looking for %j in %j' , request , paths ) ;
498- return ( newReturn ? ( paths . length > 0 ? paths : null ) : [ request , paths ] ) ;
487+ return paths . length > 0 ? paths : null ;
499488 }
500489
501490 // With --eval, parent.id is not set and parent.filename is null.
502491 if ( ! parent || ! parent . id || ! parent . filename ) {
503492 // Make require('./path/to/foo') work - normally the path is taken
504493 // from realpath(__filename) but with eval there is no filename
505- var mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
494+ const mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
506495
507496 debug ( 'looking for %j in %j' , request , mainPaths ) ;
508- return ( newReturn ? mainPaths : [ request , mainPaths ] ) ;
509- }
510-
511- // Is the parent an index module?
512- // We can assume the parent has a valid extension,
513- // as it already has been accepted as a module.
514- const base = path . basename ( parent . filename ) ;
515- var parentIdPath ;
516- if ( base . length > indexLen ) {
517- var i = 0 ;
518- for ( ; i < indexLen ; ++ i ) {
519- if ( indexChars [ i ] !== base . charCodeAt ( i ) )
520- break ;
521- }
522- if ( i === indexLen ) {
523- // We matched 'index.', let's validate the rest
524- for ( ; i < base . length ; ++ i ) {
525- const code = base . charCodeAt ( i ) ;
526- if ( code !== CHAR_UNDERSCORE &&
527- ( code < CHAR_0 || code > CHAR_9 ) &&
528- ( code < CHAR_UPPERCASE_A || code > CHAR_UPPERCASE_Z ) &&
529- ( code < CHAR_LOWERCASE_A || code > CHAR_LOWERCASE_Z ) )
530- break ;
531- }
532- if ( i === base . length ) {
533- // Is an index module
534- parentIdPath = parent . id ;
535- } else {
536- // Not an index module
537- parentIdPath = path . dirname ( parent . id ) ;
538- }
539- } else {
540- // Not an index module
541- parentIdPath = path . dirname ( parent . id ) ;
542- }
543- } else {
544- // Not an index module
545- parentIdPath = path . dirname ( parent . id ) ;
546- }
547- var id = path . resolve ( parentIdPath , request ) ;
548-
549- // Make sure require('./path') and require('path') get distinct ids, even
550- // when called from the toplevel js file
551- if ( parentIdPath === '.' &&
552- id . indexOf ( '/' ) === - 1 &&
553- ( ! isWindows || id . indexOf ( '\\' ) === - 1 ) ) {
554- id = './' + id ;
497+ return mainPaths ;
555498 }
556499
557- debug ( 'RELATIVE: requested: %s set ID to: %s from %s' , request , id ,
558- parent . id ) ;
500+ debug ( 'RELATIVE: requested: %s from parent.id %s' , request , parent . id ) ;
559501
560502 const parentDir = [ path . dirname ( parent . filename ) ] ;
561- debug ( 'looking for %j in %j' , id , parentDir ) ;
562- return ( newReturn ? parentDir : [ id , parentDir ] ) ;
503+ debug ( 'looking for %j' , parentDir ) ;
504+ return parentDir ;
563505} ;
564506
565507// Check the cache for the requested file.
@@ -647,15 +589,15 @@ Module._resolveFilename = function(request, parent, isMain, options) {
647589 for ( var i = 0 ; i < options . paths . length ; i ++ ) {
648590 const path = options . paths [ i ] ;
649591 fakeParent . paths = Module . _nodeModulePaths ( path ) ;
650- const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent , true ) ;
592+ const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
651593
652594 for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
653595 if ( ! paths . includes ( lookupPaths [ j ] ) )
654596 paths . push ( lookupPaths [ j ] ) ;
655597 }
656598 }
657599 } else {
658- paths = Module . _resolveLookupPaths ( request , parent , true ) ;
600+ paths = Module . _resolveLookupPaths ( request , parent ) ;
659601 }
660602
661603 // Look up the filename first, since that's the cache key.
0 commit comments