Skip to content

Commit 9b27d5e

Browse files
BridgeARBethGriggs
authored andcommitted
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. PR-URL: #26970 Refs: #25362 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent 3263264 commit 9b27d5e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/internal/modules/cjs/loader.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ function updateChildren(parent, child, scan) {
9696
children.push(child);
9797
}
9898

99-
function Module(id, parent) {
99+
function Module(id = '', parent) {
100100
this.id = id;
101+
this.path = path.dirname(id);
101102
this.exports = {};
102103
this.parent = parent;
103104
updateChildren(parent, this, false);

0 commit comments

Comments
 (0)