Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Proper handling when pkg.main points to a directory. #27

Closed
wants to merge 2 commits into from

3 participants

@jaredhanson

This is a fix for #22, in which a package has a dependency, and that dependency has a pkg.main property that points to a directory rather than a file.

This includes the same one-line fix as #24, and also includes a test case (which would fail without the fix).

See also: defunctzombie/node-browser-resolve#27

@kumavis

+1

@substack
Owner

Thanks for the patch! Merged in 0.4.2.

@substack substack closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/async.js
@@ -51,7 +51,7 @@ module.exports = function resolve (x, opts, cb) {
}
(function load (exts) {
- if (exts.length === 0) return cb(null, undefined);
+ if (exts.length === 0) return cb(null, undefined, pkg);
var file = x + exts[0];
isFile(file, function (err, ex) {
View
38 test/resolver.js
@@ -75,7 +75,7 @@ test('baz', function (t) {
});
test('biz', function (t) {
- t.plan(12);
+ t.plan(24);
var dir = __dirname + '/resolver/biz/node_modules';
resolve('./grux', { basedir : dir }, function (err, res, pkg) {
@@ -90,6 +90,18 @@ test('biz', function (t) {
t.equal(pkg.main, 'biz');
});
+ resolve('./garply', { basedir : dir }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/garply/lib/index.js');
+ t.equal(pkg.main, './lib');
+ });
+
+ resolve('./garply', { basedir : dir, package: { main: 'biz' } }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/garply/lib/index.js');
+ t.equal(pkg.main, './lib');
+ });
+
resolve('tiv', { basedir : dir + '/grux' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/tiv/index.js');
@@ -102,6 +114,18 @@ test('biz', function (t) {
t.equal(pkg, undefined);
});
+ resolve('tiv', { basedir : dir + '/garply' }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/tiv/index.js');
+ t.equal(pkg, undefined);
+ });
+
+ resolve('tiv', { basedir : dir + '/garply', package: { main: './lib' } }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/tiv/index.js');
+ t.equal(pkg, undefined);
+ });
+
resolve('grux', { basedir : dir + '/tiv' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/grux/index.js');
@@ -113,6 +137,18 @@ test('biz', function (t) {
t.equal(res, dir + '/grux/index.js');
t.equal(pkg, undefined);
});
+
+ resolve('garply', { basedir : dir + '/tiv' }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/garply/lib/index.js');
+ t.equal(pkg.main, './lib');
+ });
+
+ resolve('garply', { basedir : dir + '/tiv', package: { main: 'tiv' } }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/garply/lib/index.js');
+ t.equal(pkg.main, './lib');
+ });
});
test('quux', function (t) {
View
1  test/resolver/biz/node_modules/garply/lib/index.js
@@ -0,0 +1 @@
+module.exports = 'hello garply';
View
3  test/resolver/biz/node_modules/garply/package.json
@@ -0,0 +1,3 @@
+{
+ "main" : "./lib"
+}
Something went wrong with that request. Please try again.