Permalink
Browse files

List dependents of a package.

  • Loading branch information...
1 parent 0551a0c commit 68fd7570e572465dae9d1b234f8f098b8d8bfb8d @timoxley timoxley committed Nov 11, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 fetch.js
View
@@ -30,6 +30,7 @@ function fetch() {
if (!pkg.description) console.log('"description" missing for %s', pkg.name);
words = words.concat(parse(pkg.description));
words = words.concat(pkg.keywords || []);
+ pkg.dependents = dependents(pkg, pkgs)
pkg.stars = 0;
++pending;
@@ -69,6 +70,27 @@ function fetch() {
});
}
+/**
+ * List packages that depend on the supplied package, `pkg`.
+ *
+ * @param pkg
+ * @param pkgs {Array} All packages to analyse.
+ * @return {Array} Repos of packages that depend on `pkg`.
+ */
+function dependents(pkg, pkgs) {
+ var repo = pkg.repo
+ return pkgs.filter(blank).filter(function(pkg) {
+ pkg.dependencies = pkg.dependencies || []
+ return Object.keys(pkg.dependencies).indexOf(repo) !== -1
+ }).map(function(pkg) {
+ return pkg.repo
+ })
+}
+
+function blank(pkg) {
+ return !!pkg
+}
+
function parse(str) {
str = String(str).trim();
if (!str) return [];

0 comments on commit 68fd757

Please sign in to comment.