Skip to content

Commit b34f6e2

Browse files
wip(core): remove PathHandlers.dirname(path) since it can be obtained with PathHandlers.resolve(path, '.')
1 parent 913a616 commit b34f6e2

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/index.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@ interface Cache {
7070

7171

7272
interface PathHandlers {
73-
dirname(path : string) : string,
74-
extname(path : string) : string,
73+
extname(filepath : string) : string,
7574
/*
7675
* relative to absolute module path resolution.
7776
*/
78-
resolve(current : string, dep : string) : string,
77+
resolve(absoluteFilepath : string, dependencyPath : string) : string,
7978
}
8079

8180

@@ -494,7 +493,7 @@ async function loadDeps(filename : string, deps : string[], options : Options) {
494493
*/
495494
function createModule(filename : string, source : string, options : Options) {
496495

497-
const { moduleCache, pathHandlers: { resolve, dirname } } = options;
496+
const { moduleCache, pathHandlers: { resolve } } = options;
498497

499498
const require = function(path : string) {
500499

@@ -516,7 +515,7 @@ function createModule(filename : string, source : string, options : Options) {
516515

517516
// see https://github.com/nodejs/node/blob/a46b21f556a83e43965897088778ddc7d46019ae/lib/internal/modules/cjs/loader.js#L195-L198
518517
// 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_);
520519

521520
return module;
522521
}
@@ -765,20 +764,13 @@ const defaultModuleHandlers : Record<string, ModuleHandler> = {
765764
* Default implementation of PathHandlers
766765
*/
767766
const defaultPathHandlers : PathHandlers = {
768-
dirname(path) {
767+
extname(filepath) {
769768

770-
return Path.dirname(path);
769+
return Path.extname(filepath);
771770
},
772-
extname(path) {
771+
resolve(absoluteFilepath, dependencyPath) {
773772

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));
782774
}
783775
}
784776

0 commit comments

Comments
 (0)