[Pkg-javascript-commits] [node-module-deps] 154/444: factor out the package lookuper
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:47:51 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-module-deps.
commit 46c0f25246513b032f63f0868242b1377b92005c
Author: James Halliday <mail at substack.net>
Date: Fri Jan 3 21:30:38 2014 -0800
factor out the package lookuper
---
index.js | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/index.js b/index.js
index f733ba4..3638f81 100644
--- a/index.js
+++ b/index.js
@@ -49,20 +49,10 @@ module.exports = function (mains, opts) {
var id = path.resolve(basedir, main);
if (pkgCache[id]) return done();
- var dirs = parents(path.dirname(main));
- (function next () {
- if (dirs.length === 0) return done();
- var dir = dirs.shift();
- var pkgfile = path.join(dir, 'package.json');
- fs.readFile(pkgfile, function (err, src) {
- if (err) return next();
- try { var pkg = JSON.parse(src) }
- catch (err) { return done() }
- pkg.__dirname = dir;
- pkgCache[id] = pkg;
- done();
- });
- })();
+ lookupPkg(main, function (err, pkg) {
+ if (pkg) pkgCache[id] = pkg;
+ done();
+ });
});
function done () { if (--pkgCount === 0) next() }
})();
@@ -131,6 +121,9 @@ module.exports = function (mains, opts) {
].join('')));
if (pkg && pkgdir) pkg.__dirname = pkgdir;
+ if (!pkg || !pkg.__dirname) {
+
+ }
if (cb) cb(file);
if (visited[file]) {
@@ -282,3 +275,19 @@ module.exports = function (mains, opts) {
});
}
};
+
+function lookupPkg (file, cb) {
+ var dirs = parents(path.dirname(file));
+ (function next () {
+ if (dirs.length === 0) return cb(null, undefined);
+ var dir = dirs.shift();
+ var pkgfile = path.join(dir, 'package.json');
+ fs.readFile(pkgfile, function (err, src) {
+ if (err) return next();
+ try { var pkg = JSON.parse(src) }
+ catch (err) { return cb(err) }
+ pkg.__dirname = dir;
+ cb(null, pkg);
+ });
+ })();
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-module-deps.git
More information about the Pkg-javascript-commits
mailing list