@@ -63,16 +63,9 @@ let ModuleJob;
6363let createDynamicModule ;
6464
6565const {
66- CHAR_UPPERCASE_A ,
67- CHAR_LOWERCASE_A ,
68- CHAR_UPPERCASE_Z ,
69- CHAR_LOWERCASE_Z ,
7066 CHAR_FORWARD_SLASH ,
7167 CHAR_BACKWARD_SLASH ,
72- CHAR_COLON ,
73- CHAR_UNDERSCORE ,
74- CHAR_0 ,
75- CHAR_9 ,
68+ CHAR_COLON
7669} = require ( 'internal/constants' ) ;
7770
7871const isWindows = process . platform === 'win32' ;
@@ -466,14 +459,10 @@ if (isWindows) {
466459 } ;
467460}
468461
469-
470- // 'index.' character codes
471- const indexChars = [ 105 , 110 , 100 , 101 , 120 , 46 ] ;
472- const indexLen = indexChars . length ;
473- Module . _resolveLookupPaths = function ( request , parent , newReturn ) {
462+ Module . _resolveLookupPaths = function ( request , parent ) {
474463 if ( NativeModule . canBeRequiredByUsers ( request ) ) {
475464 debug ( 'looking for %j in []' , request ) ;
476- return ( newReturn ? null : [ request , [ ] ] ) ;
465+ return null ;
477466 }
478467
479468 // Check for node modules paths.
@@ -489,71 +478,24 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
489478 }
490479
491480 debug ( 'looking for %j in %j' , request , paths ) ;
492- return ( newReturn ? ( paths . length > 0 ? paths : null ) : [ request , paths ] ) ;
481+ return paths . length > 0 ? paths : null ;
493482 }
494483
495484 // With --eval, parent.id is not set and parent.filename is null.
496485 if ( ! parent || ! parent . id || ! parent . filename ) {
497486 // Make require('./path/to/foo') work - normally the path is taken
498487 // from realpath(__filename) but with eval there is no filename
499- var mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
488+ const mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
500489
501490 debug ( 'looking for %j in %j' , request , mainPaths ) ;
502- return ( newReturn ? mainPaths : [ request , mainPaths ] ) ;
503- }
504-
505- // Is the parent an index module?
506- // We can assume the parent has a valid extension,
507- // as it already has been accepted as a module.
508- const base = path . basename ( parent . filename ) ;
509- var parentIdPath ;
510- if ( base . length > indexLen ) {
511- var i = 0 ;
512- for ( ; i < indexLen ; ++ i ) {
513- if ( indexChars [ i ] !== base . charCodeAt ( i ) )
514- break ;
515- }
516- if ( i === indexLen ) {
517- // We matched 'index.', let's validate the rest
518- for ( ; i < base . length ; ++ i ) {
519- const code = base . charCodeAt ( i ) ;
520- if ( code !== CHAR_UNDERSCORE &&
521- ( code < CHAR_0 || code > CHAR_9 ) &&
522- ( code < CHAR_UPPERCASE_A || code > CHAR_UPPERCASE_Z ) &&
523- ( code < CHAR_LOWERCASE_A || code > CHAR_LOWERCASE_Z ) )
524- break ;
525- }
526- if ( i === base . length ) {
527- // Is an index module
528- parentIdPath = parent . id ;
529- } else {
530- // Not an index module
531- parentIdPath = path . dirname ( parent . id ) ;
532- }
533- } else {
534- // Not an index module
535- parentIdPath = path . dirname ( parent . id ) ;
536- }
537- } else {
538- // Not an index module
539- parentIdPath = path . dirname ( parent . id ) ;
540- }
541- var id = path . resolve ( parentIdPath , request ) ;
542-
543- // Make sure require('./path') and require('path') get distinct ids, even
544- // when called from the toplevel js file
545- if ( parentIdPath === '.' &&
546- id . indexOf ( '/' ) === - 1 &&
547- ( ! isWindows || id . indexOf ( '\\' ) === - 1 ) ) {
548- id = './' + id ;
491+ return mainPaths ;
549492 }
550493
551- debug ( 'RELATIVE: requested: %s set ID to: %s from %s' , request , id ,
552- parent . id ) ;
494+ debug ( 'RELATIVE: requested: %s from parent.id %s' , request , parent . id ) ;
553495
554496 const parentDir = [ path . dirname ( parent . filename ) ] ;
555- debug ( 'looking for %j in %j' , id , parentDir ) ;
556- return ( newReturn ? parentDir : [ id , parentDir ] ) ;
497+ debug ( 'looking for %j' , parentDir ) ;
498+ return parentDir ;
557499} ;
558500
559501// Check the cache for the requested file.
@@ -625,15 +567,15 @@ Module._resolveFilename = function(request, parent, isMain, options) {
625567 for ( var i = 0 ; i < options . paths . length ; i ++ ) {
626568 const path = options . paths [ i ] ;
627569 fakeParent . paths = Module . _nodeModulePaths ( path ) ;
628- const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent , true ) ;
570+ const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
629571
630572 for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
631573 if ( ! paths . includes ( lookupPaths [ j ] ) )
632574 paths . push ( lookupPaths [ j ] ) ;
633575 }
634576 }
635577 } else {
636- paths = Module . _resolveLookupPaths ( request , parent , true ) ;
578+ paths = Module . _resolveLookupPaths ( request , parent ) ;
637579 }
638580
639581 // Look up the filename first, since that's the cache key.
0 commit comments