@@ -70,12 +70,11 @@ interface Cache {
70
70
71
71
72
72
interface PathHandlers {
73
- dirname ( path : string ) : string ,
74
- extname ( path : string ) : string ,
73
+ extname ( filepath : string ) : string ,
75
74
/*
76
75
* relative to absolute module path resolution.
77
76
*/
78
- resolve ( current : string , dep : string ) : string ,
77
+ resolve ( absoluteFilepath : string , dependencyPath : string ) : string ,
79
78
}
80
79
81
80
@@ -494,7 +493,7 @@ async function loadDeps(filename : string, deps : string[], options : Options) {
494
493
*/
495
494
function createModule ( filename : string , source : string , options : Options ) {
496
495
497
- const { moduleCache, pathHandlers : { resolve, dirname } } = options ;
496
+ const { moduleCache, pathHandlers : { resolve } } = options ;
498
497
499
498
const require = function ( path : string ) {
500
499
@@ -516,7 +515,7 @@ function createModule(filename : string, source : string, options : Options) {
516
515
517
516
// see https://github.com/nodejs/node/blob/a46b21f556a83e43965897088778ddc7d46019ae/lib/internal/modules/cjs/loader.js#L195-L198
518
517
// see https://github.com/nodejs/node/blob/a46b21f556a83e43965897088778ddc7d46019ae/lib/internal/modules/cjs/loader.js#L1102
519
- Function ( 'exports' , 'require' , 'module' , '__filename' , '__dirname' , 'import_' , source ) . call ( module . exports , module . exports , require , module , filename , dirname ( filename ) , import_ ) ;
518
+ Function ( 'exports' , 'require' , 'module' , '__filename' , '__dirname' , 'import_' , source ) . call ( module . exports , module . exports , require , module , filename , resolve ( filename , '.' ) , import_ ) ;
520
519
521
520
return module ;
522
521
}
@@ -765,20 +764,13 @@ const defaultModuleHandlers : Record<string, ModuleHandler> = {
765
764
* Default implementation of PathHandlers
766
765
*/
767
766
const defaultPathHandlers : PathHandlers = {
768
- dirname ( path ) {
767
+ extname ( filepath ) {
769
768
770
- return Path . dirname ( path ) ;
769
+ return Path . extname ( filepath ) ;
771
770
} ,
772
- extname ( path ) {
771
+ resolve ( absoluteFilepath , dependencyPath ) {
773
772
774
- return Path . extname ( path ) ;
775
- } ,
776
- resolve ( current , dep ) {
777
-
778
- if ( dep [ 0 ] !== '.' )
779
- return dep ;
780
-
781
- return Path . normalize ( Path . join ( Path . dirname ( current ) , dep ) ) ;
773
+ return dependencyPath [ 0 ] !== '.' ? dependencyPath : Path . normalize ( Path . join ( Path . dirname ( absoluteFilepath ) , dependencyPath ) ) ;
782
774
}
783
775
}
784
776
0 commit comments