Skip to content

Commit

Permalink
Implement require.resolve.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Feb 27, 2016
1 parent 7da0fb3 commit ff6b25d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit ff6b25d

Please sign in to comment.