From 9b27d5eebb6aaefc868a44431eb26084c74bd92d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 28 Mar 2019 23:34:24 +0100 Subject: [PATCH] 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 Reviewed-By: Matteo Collina Signed-off-by: Beth Griggs --- lib/internal/modules/cjs/loader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 5ea3f55c52fffc..b8eed4b808a965 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -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);