Skip to content

Commit c8a2052

Browse files
Kelly Seldenljharb
authored andcommitted
[Fix] support opts.package in non-relative lookups
1 parent 4b10996 commit c8a2052

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/async.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ module.exports = function resolve(x, options, callback) {
185185
var dir = dirs[0];
186186

187187
var file = path.join(dir, x);
188-
loadAsFile(file, undefined, onfile);
188+
loadAsFile(file, opts.package, onfile);
189189

190190
function onfile(err, m, pkg) {
191191
if (err) return cb(err);
192192
if (m) return cb(null, m, pkg);
193-
loadAsDirectory(path.join(dir, x), undefined, ondir);
193+
loadAsDirectory(path.join(dir, x), opts.package, ondir);
194194
}
195195

196196
function ondir(err, n, pkg) {

test/resolver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('bar', function (t) {
5555
resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) {
5656
if (err) t.fail(err);
5757
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
58-
t.equal(pkg, undefined);
58+
t.equal(pkg.main, 'bar');
5959
});
6060
});
6161

@@ -113,7 +113,7 @@ test('biz', function (t) {
113113
resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) {
114114
if (err) t.fail(err);
115115
t.equal(res, path.join(dir, 'tiv/index.js'));
116-
t.equal(pkg, undefined);
116+
t.equal(pkg.main, 'grux');
117117
});
118118

119119
resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) {
@@ -125,7 +125,7 @@ test('biz', function (t) {
125125
resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) {
126126
if (err) t.fail(err);
127127
t.equal(res, path.join(dir, 'tiv/index.js'));
128-
t.equal(pkg, undefined);
128+
t.equal(pkg.main, './lib');
129129
});
130130

131131
resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) {
@@ -137,7 +137,7 @@ test('biz', function (t) {
137137
resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
138138
if (err) t.fail(err);
139139
t.equal(res, path.join(dir, 'grux/index.js'));
140-
t.equal(pkg, undefined);
140+
t.equal(pkg.main, 'tiv');
141141
});
142142

143143
resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) {

0 commit comments

Comments
 (0)