@@ -63,16 +63,9 @@ let ModuleJob;
63
63
let createDynamicModule ;
64
64
65
65
const {
66
- CHAR_UPPERCASE_A ,
67
- CHAR_LOWERCASE_A ,
68
- CHAR_UPPERCASE_Z ,
69
- CHAR_LOWERCASE_Z ,
70
66
CHAR_FORWARD_SLASH ,
71
67
CHAR_BACKWARD_SLASH ,
72
- CHAR_COLON ,
73
- CHAR_UNDERSCORE ,
74
- CHAR_0 ,
75
- CHAR_9 ,
68
+ CHAR_COLON
76
69
} = require ( 'internal/constants' ) ;
77
70
78
71
const isWindows = process . platform === 'win32' ;
@@ -466,14 +459,10 @@ if (isWindows) {
466
459
} ;
467
460
}
468
461
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 ) {
474
463
if ( NativeModule . canBeRequiredByUsers ( request ) ) {
475
464
debug ( 'looking for %j in []' , request ) ;
476
- return ( newReturn ? null : [ request , [ ] ] ) ;
465
+ return null ;
477
466
}
478
467
479
468
// Check for node modules paths.
@@ -489,71 +478,24 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
489
478
}
490
479
491
480
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 ;
493
482
}
494
483
495
484
// With --eval, parent.id is not set and parent.filename is null.
496
485
if ( ! parent || ! parent . id || ! parent . filename ) {
497
486
// Make require('./path/to/foo') work - normally the path is taken
498
487
// from realpath(__filename) but with eval there is no filename
499
- var mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
488
+ const mainPaths = [ '.' ] . concat ( Module . _nodeModulePaths ( '.' ) , modulePaths ) ;
500
489
501
490
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 ;
549
492
}
550
493
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 ) ;
553
495
554
496
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 ;
557
499
} ;
558
500
559
501
// Check the cache for the requested file.
@@ -625,15 +567,15 @@ Module._resolveFilename = function(request, parent, isMain, options) {
625
567
for ( var i = 0 ; i < options . paths . length ; i ++ ) {
626
568
const path = options . paths [ i ] ;
627
569
fakeParent . paths = Module . _nodeModulePaths ( path ) ;
628
- const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent , true ) ;
570
+ const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
629
571
630
572
for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
631
573
if ( ! paths . includes ( lookupPaths [ j ] ) )
632
574
paths . push ( lookupPaths [ j ] ) ;
633
575
}
634
576
}
635
577
} else {
636
- paths = Module . _resolveLookupPaths ( request , parent , true ) ;
578
+ paths = Module . _resolveLookupPaths ( request , parent ) ;
637
579
}
638
580
639
581
// Look up the filename first, since that's the cache key.
0 commit comments