Skip to content

Commit 4abc696

Browse files
committed
Ignore non-object package.json files, fixes #134
Previously this would hang. Node also ignores package.json files that don't contain objects.
1 parent 54fa993 commit 4abc696

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ Deps.prototype.lookupPackage = function (file, cb) {
540540
fns.forEach(function (f) { f(err, pkg) });
541541
}
542542
if (err) cb(err)
543-
else if (pkg) cb(null, pkg)
543+
else if (pkg && typeof pkg === 'object') cb(null, pkg)
544544
else {
545545
self.pkgCache[pkgfile] = false;
546546
next();

test/invalid_pkg.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var mdeps = require('../');
2+
var test = require('tap').test;
3+
var path = require('path');
4+
var fs = require('fs');
5+
6+
test('invalid pkg', function (t) {
7+
var d = mdeps();
8+
d.on('package', function (pkg_) {
9+
// console.error({pkg_});
10+
});
11+
d.end(path.join(__dirname, '/invalid_pkg/file.js'));
12+
d.on('data', function () {});
13+
d.on('end', function () {
14+
t.end();
15+
});
16+
});

test/invalid_pkg/file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./')

test/invalid_pkg/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
T.pass()

test/invalid_pkg/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"just a string"

0 commit comments

Comments
 (0)