From ab7a1e2f77aaf15e3ed2d07e5a2bf1f0331e4e7a Mon Sep 17 00:00:00 2001 From: Subham Singh Date: Tue, 24 Sep 2019 15:09:39 +0530 Subject: [PATCH] Fix require node module, #246 --- src/req-manager.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/req-manager.js b/src/req-manager.js index eb4ff6d3..f17f25f4 100644 --- a/src/req-manager.js +++ b/src/req-manager.js @@ -1,5 +1,6 @@ var mod = require("module"), path = require("path"), + fs = require("fs"), logger = require("./logger"); var Req = function (filepath, root) { @@ -7,7 +8,7 @@ var Req = function (filepath, root) { this.root = root; this.filepath = filepath || null; this.nativeModules = [ - "assert", "buffer", "child_process", "constants", "crypto", "tls", "dgram", "dns", "http", "https", + "assert", "buffer", "child_process", "constants", "crypto", "tls", "dgram", "dns", "http", "https", "net", "querystring", "url", "domain", "events", "fs", "path", "os", "punycode", "stream", "string_decoder", "timers", "tty", "util", "sys", "vm", "zlib" ]; @@ -31,7 +32,14 @@ Req.prototype.load = function (modname) { path.join(self.root, "node_modules") ].concat(module.paths.filter(function (p) { return p.indexOf(".gauge") < 0; })); try { - return modname === path.basename(modname) ? m.require(modname) : m.require(path.join(path.dirname(self.filepath), modname)); + if (modname === path.basename(modname)) { + return m.require(modname); + } + let relativePath = path.join(path.dirname(self.filepath), modname); + if (fs.existsSync(relativePath)) { + return m.require(relativePath); + } + return m.require(modname); } catch (e) { logger.error("Unable to require module '" + modname + "' in " + self.filepath + "\n" + e.stack); return null;