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: https://github.com/nodejs/node/pull/26970
Refs: https://github.com/nodejs/node/pull/25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-03-28 23:34:24 +01:00
parent be577615c8
commit d0043136e5
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -98,8 +98,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);