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.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Signed-off-by: Beth Griggs <[email protected]>
  • Loading branch information
BridgeAR authored and BethGriggs committed Apr 9, 2019
1 parent 3263264 commit 9b27d5e
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 @@ -96,8 +96,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 9b27d5e

Please sign in to comment.