Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

List dependents of a package. #11

Merged
merged 1 commit into from over 1 year ago

2 participants

Tim Oxley TJ Holowaychuk
Tim Oxley
Owner

It's useful to see what depends on a particular package:

  • Aids in component discovery.
  • Gives clues at to which components are considered canonical.
  • …which in turn should help prevent components with duplicate functionality popping up.
  • Shows practical 'usage examples'.
  • Shows where work needs to be done (e.g. number of dependents on jquery).

Whether/how you want to add this to the human readable component-search output is up to you, this will at least make it available in the --json output, but perhaps a flag like --show-dependents and/or some kind of limit on the number of dependents in default output, e.g.

  component/jquery
  url: https://github.com/component/jquery
  desc: jQuery component
  dependents: btknorr/davis.js, component/progress-notification, component/calendar + 25 others
  ★ 1

Examples

(Manually omitted package details other than name and dependents)

[{
  "name": "notification",
  "dependents": [ // 2
    "component/progress-notification",
    "component/confirmation-notification"
  ]
},
{
  "name": "stream",
  "dependents": [ // 6
    "juliangruber/shoe",
    "juliangruber/sorta",
    "juliangruber/fwd",
    "juliangruber/through",
    "juliangruber/duplexer",
    "juliangruber/min-wait"
  ]
},
{
  "name": "jquery",
  "dependents": [ // 28
    "btknorr/davis.js",
    "component/progress-notification",
    "component/calendar",
    "component/color-picker",
    "component/confirmation-popover",
    "component/confirmation-notification",
    "component/dialog",
    "component/tip",
    "component/pager",
    "component/popover",
    "component/notification",
    "component/dropdown",
    "component/menu",
    "colinf/listbox-menu",
    "colinf/datepicker",
    "component/overlay",
    "component/confirmation",
    "RetroFOX/buttonset",
    "matthewmueller/list",
    "cbou/jquery-mobile",
    "retrofox/datatable",
    "btknorr/bootbox",
    "pazguille/editable",
    "matthewmueller/events",
    "btknorr/bootstrap",
    "timoxley/backbone-view",
    "ember-components/ember",
    "ember-components/data"
  ]
},
{
  "name": "classes",
  "dependents": [ // 14
    "component/dropdown",
    "component/more",
    "component/dropload",
    "RetroFOX/buttonset",
    "ForbesLindesay/booting-sub-nav",
    "tomerdmnt/carousel",
    "tomerdmnt/carousel-slide",
    "tomerdmnt/offcanvas",
    "matthewmueller/autocomplete",
    "component/dom",
    "component/sketch",
    "component/reactive",
    "component/clipboard-dom",
    "timoxley/element-selector"
  ]
}]
// ETC
TJ Holowaychuk visionmedia commented on the diff
((7 lines not shown))
  76 + * @param pkg
  77 + * @param pkgs {Array} All packages to analyse.
  78 + * @return {Array} Repos of packages that depend on `pkg`.
  79 + */
  80 +function dependents(pkg, pkgs) {
  81 + var repo = pkg.repo
  82 + return pkgs.filter(blank).filter(function(pkg) {
  83 + pkg.dependencies = pkg.dependencies || []
  84 + return Object.keys(pkg.dependencies).indexOf(repo) !== -1
  85 + }).map(function(pkg) {
  86 + return pkg.repo
  87 + })
  88 +}
  89 +
  90 +function blank(pkg) {
  91 + return !!pkg
1
TJ Holowaychuk Owner

hehe :D I still need to find the source of these damn blanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
TJ Holowaychuk
Owner

great idea ! thanks man, this will aid in building a dependency graph as well, I definitely want that on the site

TJ Holowaychuk visionmedia merged commit 5c05716 into from
Tim Oxley
Owner

Bump… keen to see this one go live.

TJ Holowaychuk
Owner

I do think we should map these but I think I'll make it optional in the search response since it causes a lot of JSON bloat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 11, 2012
Tim Oxley timoxley List dependents of a package. 68fd757
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. +22 0 fetch.js
22 fetch.js
@@ -30,6 +30,7 @@ function fetch() {
30 30 if (!pkg.description) console.log('"description" missing for %s', pkg.name);
31 31 words = words.concat(parse(pkg.description));
32 32 words = words.concat(pkg.keywords || []);
  33 + pkg.dependents = dependents(pkg, pkgs)
33 34 pkg.stars = 0;
34 35
35 36 ++pending;
@@ -69,6 +70,27 @@ function fetch() {
69 70 });
70 71 }
71 72
  73 +/**
  74 + * List packages that depend on the supplied package, `pkg`.
  75 + *
  76 + * @param pkg
  77 + * @param pkgs {Array} All packages to analyse.
  78 + * @return {Array} Repos of packages that depend on `pkg`.
  79 + */
  80 +function dependents(pkg, pkgs) {
  81 + var repo = pkg.repo
  82 + return pkgs.filter(blank).filter(function(pkg) {
  83 + pkg.dependencies = pkg.dependencies || []
  84 + return Object.keys(pkg.dependencies).indexOf(repo) !== -1
  85 + }).map(function(pkg) {
  86 + return pkg.repo
  87 + })
  88 +}
  89 +
  90 +function blank(pkg) {
  91 + return !!pkg
  92 +}
  93 +
72 94 function parse(str) {
73 95 str = String(str).trim();
74 96 if (!str) return [];

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.