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

resolve-tree

v0.1.14

Published

Recursively resolve node.js modules and its dependencies looking in node_modules trees

Downloads

105

Readme

resolve-tree Build Status Code Climate NPM js-standard-style

Recursively resolve node.js modules and its dependencies looking in node_modules trees.

The module resolution algorithm behavies like require.resolve in node.js. It also mimics the recursive module resolution behavior used by npm.

Features

  • Recursively resolves a node_modules dependency tree
  • Proper error reporting if some package cannot be resolved or is missing
  • Detects repeated and circular dependencies across nested dependency trees.
  • Module lookup algorithm behavies like require.resolve
  • Produces a detailed abstract dependency tree representation
  • Provides convenient helpers that you will love
  • Almost dependency free (only uses some stable tiny modules)
  • Fast: all the I/O operations are executed asynchronously in parallel

Not supported yet

  • Semantic version operator based resolution

Installation

npm install resolve-tree

Usage

const resolve = require('resolve-tree')

// Names of the packages to resolve
const names = ['foo', 'bar']

// Custom optional params for the resolution
const opts = {
  basedir: process.cwd(),
  lookups: ['dependencies', 'devDependencies']
}

resolve.packages(names, opts, function (err, tree) {
  if (err) return console.error(err)

  const json = JSON.stringify(tree, null, 2)
  console.log(json)
})

The resolved dependency tree serialized to JSON looks like this:

[{
  "name": "foo",
  "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/package.json",
  "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple",
  "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/index.js",
  "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo",
  "version": "0.1.0",
  "meta": {
    "name": "foo",
    "dependencies": {
      "baz": "~0.1.0",
      "bar": "~0.1.0",
      "quz": "~0.1.0"
    }
  },
  "dependencies": [{
    "name": "baz",
    "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz/package.json",
    "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo",
    "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz/index.js",
    "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz",
    "version": "0.1.0",
    "meta": {
      "name": "baz"
    }
  }, {
    "name": "bar",
    "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/bar/package.json",
    "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo",
    "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/bar/index.js",
    "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/bar",
    "version": "0.1.0",
    "meta": {
      "name": "bar",
      "dependencies": {
        "baz": "~0.1.0"
      }
    },
    "dependencies": [{
      "name": "baz",
      "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz/package.json",
      "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/bar",
      "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz/index.js",
      "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/baz",
      "version": "0.1.0",
      "meta": {
        "name": "baz"
      }
    }]
  }, {
    "name": "quz",
    "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz/package.json",
    "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo",
    "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz/index.js",
    "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz",
    "version": "0.1.0",
    "meta": {
      "name": "quz",
      "dependencies": {
        "baz": "~0.0.1"
      }
    },
    "dependencies": [{
      "name": "baz",
      "manifest": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz/node_modules/baz/package.json",
      "basedir": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz",
      "main": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz/node_modules/baz/index.js",
      "root": "/Users/h2non/Projects/resolve-tree/fixtures/simple/node_modules/foo/node_modules/quz/node_modules/baz",
      "version": "0.1.0",
      "meta": {
        "name": "baz",
        "version": "0.0.1"
      }
    }]
  }]
}]

API

Supported options

  • basedir string - Base directory path to start lookups. Default to process.cwd().
  • lookups array<string> - Dependency types to lookup. Allowed values are: dependencies, devDependencies, peerDependencies. Defaults to: dependencies

resolve.packages(names, [ opts, ] cb)

Alias: byName()

Find and resolve modules and its dependencies recursively looking by package name.

resolve.manifest(pkgManifest, [ opts, ] cb)

Resolve dependencies recursively reading the package.json metadata.

resolve.flatten(tree) => array<pkg>

Flatten dependency tree to one level structure tree.

resolve.flattenMap(tree, [ field ]) => array<mixed>

Flatten the given dependency tree mapping by dependency value field or custom mapper function.

resolve.resolutions = object

Map of packages resolution mappings.

{
  'mz': 'mz/fs'
}

resolve.packagesSync(names, [ opts ])

Alias: byNameSync

Synchronous version of packages. Find and resolve modules and its dependencies recursively looking by package name.

resolve.manifestSync(pkgManifest, [ opts ])

Synchronous version of manifest. Resolve dependencies recursively reading the package.json metadata.

License

MIT - Tomas Aparicio