Skip to content

Commit 538f745

Browse files
committed
module: add path to the module object
This adds the `path` property to the module object. It contains the current directory as path. That is necessary to add an extra caching layer. It also makes sure the `id` uses a default in case it's not set. Otherwise the `path.dirname(id)` command could fail.
1 parent 50e2414 commit 538f745

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ function updateChildren(parent, child, scan) {
103103
children.push(child);
104104
}
105105

106-
function Module(id, parent) {
106+
function Module(id = '', parent) {
107107
this.id = id;
108+
this.path = path.dirname(id);
108109
this.exports = {};
109110
this.parent = parent;
110111
updateChildren(parent, this, false);

0 commit comments

Comments
 (0)