From ff6b25d6b5511d8a92930da41db73b93eb1d6cf8 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sat, 27 Feb 2016 17:39:10 -0500 Subject: [PATCH] Implement require.resolve. --- install.js | 6 ++++++ test/run.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/install.js b/install.js index 85e8dc8..6d57a0b 100644 --- a/install.js +++ b/install.js @@ -95,6 +95,12 @@ makeInstaller = function (options) { throw error; } + require.resolve = function (id) { + var f = fileResolve(file, id); + if (f) return f.m.id; + throw new Error("Cannot find module '" + id + "'"); + }; + // A function that immediately returns true iff all the transitive // dependencies of the module identified by id have been installed. // This function can be used with options.onInstall to implement diff --git a/test/run.js b/test/run.js index c328f77..693a544 100644 --- a/test/run.js +++ b/test/run.js @@ -408,6 +408,10 @@ describe("install", function () { assert.strictEqual(require.ready("./dir/d"), true); assert.strictEqual(require("./dir/d").id, "/dir/node_modules/e.js"); + assert.strictEqual( + require.resolve("./dir/d"), + "/dir/node_modules/e.js" + ); }); it("avoids circular package.json resolution chains", function () {