npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dep-tree

v0.2.1

Published

Create and solve a dependency tree.

Downloads

20

Readme

dep-tree

Create and solve a dependency tree. Build Status

NPM

Allows you to create a tree and resolve the parents of any child. Each child can have multiple parents.

Note: no checking is done to stop adding cyclic dependencies. That is up to you.

Example Usage

In the past I've named my database patches in a sequential manner. e.g. '001', '002', '003', but we all know that can cause problems when two or more developers try and grab the next number in the patch series.

Instead, now I call them 'yyyymmdd-name' and each depends on something before it, usually a release number.

Let's say that 'create-user-table' depends on 'create-database'.

And that 'release-1' depends on 'create-user-table'.

Let's now add a few more patches which depend on 'release-1' : 'create-item-table' and 'update-user-table'.

Finally, 'release-2' depends on both 'create-item-table' and 'update-user-table'.

var DepTree = require('dep-tree').
var tree = new DepTree();

// patches for release-1
tree.add('create-database', 'create-user-table');
tree.add('create-user-table', 'release-1');

// -> [ 'create-database', 'create-user-table', 'release-1' ]
tree.solve('release-1');

// patches for release-2
tree.add('release-1', 'create-item-table');
tree.add('release-1', 'update-user-table');
tree.add('create-item-table', 'release-2');
tree.add('update-user-table', 'release-2');

// [
//     'create-database', 'create-user-table', 'release-1',
//     'create-item-table', 'update-user-table', 'release-2'
// ]
tree.solve('release-2');

This example shows a tree which widens between releases and comes together for each release. You don't have to do it this way but it probably makes it more manageable.

Examples

Simple

tree.add('grandparent', 'parent');
tree.solve('grandparent'); // [ 'grandparent' ]
tree.solve('parent'); // [ 'grandparent', 'parent' ]

Multi

tree.add('grandparent', 'parent1');
tree.add('grandparent', 'parent2');
tree.add('parent1', 'child');
tree.add('parent2', 'child');
tree.solve('grandparent'); // [ 'grandparent' ]
tree.solve('parent1');     // [ 'grandparent', 'parent1' ]
tree.solve('parent2');     // [ 'grandparent', 'parent2' ]
tree.solve('child');       // [ 'grandparent', 'parent1', 'parent2', 'child' ]

Author

Written by Andrew Chilton - Blog - Twitter.

License

(Ends)