Skip to content

Commit

Permalink
module: add path to the module object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BridgeAR committed Mar 31, 2019
1 parent 50e2414 commit 538f745
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ function updateChildren(parent, child, scan) {
children.push(child);
}

function Module(id, parent) {
function Module(id = '', parent) {
this.id = id;
this.path = path.dirname(id);
this.exports = {};
this.parent = parent;
updateChildren(parent, this, false);
Expand Down

0 comments on commit 538f745

Please sign in to comment.