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

dependency-info

v0.3.2

Published

Get your project dependency tree from npm as well as from bower

Downloads

1

Readme

dependency-info

Build Status Coverage Status Dependency Status devDependency Status

Read useful info from your dependency tree. It supports both npm and bower.

Install

npm install dependency-info

Usage

First af all, you have to retrieve your dependency tree.

The async way

var dependencyInfo = require('dependency-info');
dependencyInfo.readTree({
    manager: 'npm'
})
.then(function (tree) {
    ...
})
.catch(function (err) {
    ...
});

Of course, you can also get it synchronously

var dependencyInfo = require('dependency-info')
    list, 
    tree;
tree = dependencyInfo.readTreeSync({
	manager: 'npm'
});

Parameters

readTreeand readTreeSync accept the same options param:

{
path:       {String}    path to module whose dependencies will be fetched. 
                        Default: process.cwd() 
manager:    {String}    Package manager: 'npm' or 'bower'
type:       {String}    All dependencies: 'all' (default)
            or
            {Array}     Accepted values: 'dependencies' and 'devDependencies'
deep:       {Boolean}   If true it search for all dependencies, not only the direct ones. 
                        Default value: false
filterBy:   
    {
        keyword: {Array} List of keywords the dependency must have
    }
}

How to use this info

Tree object provides you a method to get a sorted Array of the information you need.

tree.list(fields, order)

This method looks over the tree and returns an ordered array of key value objects filled with the specified fields, which will be taken from each dependency json file.

fields {Array}
Property names form json files. You can also use 'path', which will contain the full path to dependency directory.
order {String}
Sort dependencies in ascending ('asc') or descending order ('desc')

Examples

Case 1: Getting path to main JS of your gulp plugins

var dependencyInfo = require('dependency-info');
dependencyInfo.readTree({
	manager: 'npm',
	filterBy: {
	    keyword: 'gulpplugin'
	}
})
.then(function (tree) {
	var list = tree.list(['name', 'path', 'main', 'files'], 'asc');
})

As a result, list and the following structure will be alike.

[ { name: 'gulp-autoprefixer',
    path: '/var/my-project/node_modules/gulp-autoprefixer',
    main: undefined,
    files: [ 'index.js' ] },
  { name: 'gulp-copy',
    path: '/var/my-project/node_modules/gulp-copy',
    main: 'index.js',
    files: undefined },
  { name: 'gulp-minify-css',
    path: '/var/my-project/node_modules/gulp-minify-css',
    main: undefined,
    files: [ 'index.js' ] },
  { name: 'gulp-prettify',
    path: '/var/my-project/node_modules/gulp-prettify',
    main: 'index.js',
    files: undefined },
  { name: 'gulp-rename',
    path: '/var/my-project/node_modules/gulp-rename',
    main: './index.js',
    files: [ 'index.js' ] },
  { name: 'gulp-sass',
    path: '/var/my-project/node_modules/gulp-sass',
    main: 'index.js',
    files: undefined },
  { name: 'gulp-strip-css-comments',
    path: '/var/my-project/node_modules/gulp-strip-css-comments',
    main: undefined,
    files: [ 'index.js' ] } ]

Case 2: Logging version info synchronously

var dependencyInfo = require('dependency-info')
    list, 
    tree;
tree = dependencyInfo.readTreeSync({
	manager: 'npm'
});
list = tree.list(['name', 'version'], 'asc');
console.log(list);

This code will output a message like this:

[ { name: 'connect-livereload', version: '0.5.3' },
  { name: 'express', version: '4.12.3' },
  { name: 'gulp', version: '3.8.11' },
  { name: 'gulp-autoprefixer', version: '2.2.0' },
  { name: 'gulp-copy', version: '0.0.2' },
  { name: 'gulp-kit', version: '0.1.1' },
  { name: 'gulp-minify-css', version: '1.1.0' },
  { name: 'gulp-prettify', version: '0.3.0' },
  { name: 'gulp-rename', version: '1.2.2' },
  { name: 'gulp-sass', version: '1.3.3' },
  { name: 'gulp-strip-css-comments', version: '1.1.0' },
  { name: 'tiny-lr', version: '0.1.5' } ]

License

MIT. See LICENSE for details.