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

depgraph

v0.5.9

Published

generate a dependency graph or tree of nodes from a given moduleid

Downloads

48

Readme

depgraph

npm License: GPL v3

scrounge

depgraph returns a dependency graph for a javascript module. It resolves ESM, CommonJS and Typescript modules using resolvewithplus.

depgraph is similar to module-deps and uses some of the same dependencies.


A sample graph, tree and dependency-ordered array are seen using example calls below found in the unit tests.

Graph

For each graph node, "inarr" references dependent nodes and "outarr" references depedency nodes.

const graph = await depgraph.graph.getfromseedfile('./test/files/root.js')

console.log(JSON.stringify(graph, null, '\t'))

result

{
  "depgraph-0.0.6:~/test/files/root.js": {
    "content": "...",
    "filepath": "./test/files/root.js",
    "uid": "depgraph-0.0.6:~/test/files/root.js",
    "inarr": [],
    "outarr": [{
      "refname": "./fileb",
      "uid": "depgraph-0.0.6:~/test/files/fileb.js"
    },{
      "refname": "./filea",
      "uid": "depgraph-0.0.6:~/test/files/filea.js"
    },{
      "refname": "./filec",
      "uid": "depgraph-0.0.6:~/test/files/filec/index.js"
    },{
      "refname": "resolveuid",
      "uid": "resolveuid-0.0.2:~/index.js"
    },{
      "refname": "./dir/filed.js",
      "uid": "depgraph-0.0.6:~/test/files/dir/filed.js"
    }]
  },
  "depgraph-0.0.6:~/test/files/fileb.js": {
    "content": "...",
    "filepath": "./test/files/fileb.js",
    "uid": "depgraph-0.0.6:~/test/files/fileb.js",
    "inarr": [{
      "refname": "./fileb",
      "uid": "depgraph-0.0.6:~/test/files/root.js"
    },{
      "refname": "./fileb",
      "uid": "depgraph-0.0.6:~/test/files/filea.js"
    }],
    "outarr": []
  },
  "depgraph-0.0.6:~/test/files/filea.js": {
    "content": "...",
    "filepath": "./test/files/filea.js",
    "uid": "depgraph-0.0.6:~/test/files/filea.js",
    "inarr": [{
      "refname": "./filea",
      "uid": "depgraph-0.0.6:~/test/files/root.js"
    }],
    "outarr": [{
      "refname": "./fileb",
      "uid": "depgraph-0.0.6:~/test/files/fileb.js"
    }]
  },
  "depgraph-0.0.6:~/test/files/filec/index.js": {
    "content": "...",
    "filepath": "./test/files/filec/index.js",
    "uid": "depgraph-0.0.6:~/test/files/filec/index.js",
    "inarr": [{
      "refname": "./filec",
      "uid": "depgraph-0.0.6:~/test/files/root.js"
    },{
      "refname": "./../filec",
      "uid": "depgraph-0.0.6:~/test/files/dir/filed.js"
    }],
    "outarr": []
  },
  "resolveuid-0.0.2:~/index.js": {
    "content": "...",
    "filepath": "./node_modules/resolveuid/index.js",
    "uid": "resolveuid-0.0.2:~/index.js",
    "inarr": [{
      "refname": "resolveuid",
      "uid": "depgraph-0.0.6:~/test/files/root.js"
    }],
    "outarr": [{
      "refname": "./src/resolveuid",
      "uid": "resolveuid-0.0.2:~/src/resolveuid.js"
    }]
  },
  "resolveuid-0.0.2:~/src/resolveuid.js": {
    "content": "...",
    "filepath": "./node_modules/resolveuid/src/resolveuid.js",
    "uid": "resolveuid-0.0.2:~/src/resolveuid.js",
    "inarr": [{
      "refname": "./src/resolveuid",
      "uid": "resolveuid-0.0.2:~/index.js"
    }],
    "outarr": []
  },
  "depgraph-0.0.6:~/test/files/dir/filed.js": {
    "content": "...",
    "filepath": "./test/files/dir/filed.js",
    "uid": "depgraph-0.0.6:~/test/files/dir/filed.js",
    "inarr": [{
      "refname": "./dir/filed.js",
      "uid": "depgraph-0.0.6:~/test/files/root.js"
    }],
    "outarr": [{
      "refname": "./../filec",
      "uid": "depgraph-0.0.6:~/test/files/filec/index.js"
    }]
  }
}

Array

The graph is used to construct a dependency-ordered array.

const graph = await depgraph.graph.getfromseedfile('./test/files/root.js')

console.log(JSON.stringify(depgraph.graph.getdeparr(graph), null, '\t'))

result

[{
  "content": "...",
  "filepath": "./test/files/fileb.js",
  "uid": "depgraph-0.0.6:~/test/files/fileb.js",
  "inarr": [{
    "refname": "./fileb",
    "uid": "depgraph-0.0.6:~/test/files/root.js"
  },{
    "refname": "./fileb",
    "uid": "depgraph-0.0.6:~/test/files/filea.js"
  }],
  "outarr": []
},{
  "content": "...",
  "filepath": "./test/files/filea.js",
  "uid": "depgraph-0.0.6:~/test/files/filea.js",
  "inarr": [{
    "refname": "./filea",
    "uid": "depgraph-0.0.6:~/test/files/root.js"
  }],
  "outarr": [{
    "refname": "./fileb",
    "uid": "depgraph-0.0.6:~/test/files/fileb.js"
  }]
},{
  "content": "...",
  "filepath": "./test/files/filec/index.js",
  "uid": "depgraph-0.0.6:~/test/files/filec/index.js",
  "inarr": [{
    "refname": "./filec",
    "uid": "depgraph-0.0.6:~/test/files/root.js"
  },{
    "refname": "./../filec",
    "uid": "depgraph-0.0.6:~/test/files/dir/filed.js"
  }],
  "outarr": []
},{
  "content": "...",
  "filepath": "./node_modules/resolveuid/src/resolveuid.js",
  "uid": "resolveuid-0.0.2:~/src/resolveuid.js",
  "inarr": [{
    "refname": "./src/resolveuid",
    "uid": "resolveuid-0.0.2:~/index.js"
  }],
  "outarr": []
},{
  "content": "...",
  "filepath": "./node_modules/resolveuid/index.js",
  "uid": "resolveuid-0.0.2:~/index.js",
  "inarr": [{
    "refname": "resolveuid",
    "uid": "depgraph-0.0.6:~/test/files/root.js"
  }],
  "outarr": [{
    "refname": "./src/resolveuid",
    "uid": "resolveuid-0.0.2:~/src/resolveuid.js"
  }]
},{
  "content": "...",
  "filepath": "./test/files/dir/filed.js",
  "uid": "depgraph-0.0.6:~/test/files/dir/filed.js",
  "inarr": [{
    "refname": "./dir/filed.js",
	"uid": "depgraph-0.0.6:~/test/files/root.js"
  }],
  "outarr": [{
    "refname": "./../filec",
    "uid": "depgraph-0.0.6:~/test/files/filec/index.js"
  }]
},{
  "content": "...",
  "filepath": "./test/files/root.js",
  "uid": "depgraph-0.0.6:~/test/files/root.js",
  "inarr": [],
  "outarr": [{
    "refname": "./fileb",
    "uid": "depgraph-0.0.6:~/test/files/fileb.js"
  },{
    "refname": "./filea",
    "uid": "depgraph-0.0.6:~/test/files/filea.js"
  },{
    "refname": "./filec",
    "uid": "depgraph-0.0.6:~/test/files/filec/index.js"
  },{
    "refname": "resolveuid",
    "uid": "resolveuid-0.0.2:~/index.js"
  },{
    "refname": "./dir/filed.js",
    "uid": "depgraph-0.0.6:~/test/files/dir/filed.js"
  }]
}]

Tree

Trees are generated from the graph usi the archy format. Full tree construction may be prohibited by circular cjs dependencies.

The default tree may render a leaf multiple times, but will render the children once only.

const tree = await depgraph.tree.getfromseedfile('./test/files/root.js')

console.log(archy(tree));

result

depgraph-0.0.6:~/test/files/root.js
├── depgraph-0.0.6:~/test/files/fileb.js
├─┬ depgraph-0.0.6:~/test/files/filea.js
│ └── depgraph-0.0.6:~/test/files/fileb.js
├── depgraph-0.0.6:~/test/files/filec/index.js
├─┬ resolveuid-0.0.2:~/index.js
│ └── resolveuid-0.0.2:~/src/resolveuid.js
└─┬ depgraph-0.0.6:~/test/files/dir/filed.js
  └── depgraph-0.0.6:~/test/files/filec/index.js

The 'small' tree renders each leaf once only.

const tree = await depgraph.tree.getfromseedfilesmall('./test/files/root.js')

console.log(archy(tree))

result

depgraph-0.0.6:~/test/files/root.js
├── depgraph-0.0.6:~/test/files/fileb.js
├── depgraph-0.0.6:~/test/files/filea.js
├── depgraph-0.0.6:~/test/files/filec/index.js
├─┬ resolveuid-0.0.2:~/index.js
│ └── resolveuid-0.0.2:~/src/resolveuid.js
└── depgraph-0.0.6:~/test/files/dir/filed.js

Modifiers

When { iscircular: false } is passed to getdeparr an error will be thrown when circular dependencies are found. All options are passed directly to the resolver, resolvewithplus, and so it is possible to specify preferred resolutions using options like { isbrowser: true } and { priority: ['browser', 'import', ':spectype', 'default'] }

scrounge