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

deps-report

v0.5.0

Published

Generate reports about dependencies and dependents of your JavaScript/TypeScript files through an AST. It supports import and require statements.

Downloads

16

Readme

deps-report

node version npm downloads deps-report version Travis Coverage Status license Greenkeeper badge Donate to this project using Paypal Donate to this project using Patreon

Generate reports about dependencies and dependents of your JavaScript/TypeScript files through an AST. It supports import and require statements.

Parsers used:

Install

npm install -g deps-report

Screenshots

CLI Usage

Usage: deps-report [options] [command]

Options:

  -V, --version                             output the version number
  -j, --json                                Output results in JSON format
  -p, --pretty                              Pretty-print JSON output (implies --json)
  -a, --abs-path                            Print absolute path of dependencies/dependents
  -e, --exclude-node-modules                Don't consider node_modules dependencies
  -w, --webpack-config [webpackConfigFile]  Webpack config file for resolving aliased modules
  -s, --specifiers                          Show specifiers imported by the dependency/dependent
  --no-color                                Display terminal output without colors
  -h, --help                                output usage information

Commands:

  find-dependencies [options] <glob> [otherGlobs...]

      Usage: find-dependencies [options] <glob> [otherGlobs...]
      Options:

        -c, --circular      Show if there are some circular dependencies
        --only-not-found    Show all modules that have no dependencies
        --hide-not-found    Hide all modules that have no dependencies
        --only-circular     Show only circular dependencies
        -h, --help          output usage information


  find-dependents [options] <glob> [otherGlobs...]

      Usage: find-dependents [options] <glob> [otherGlobs...]
      Options:

        -r, --root [root]   Root folder from where to start the search. Default is the dirname of each glob entry
        -c, --circular      Show if there are some circular dependencies
        --only-not-found    Show all modules that no one is depending on
        --hide-not-found    Hide all modules that no one is depending on
        --only-circular     Show only circular dependencies
        -h, --help          output usage information

Examples find-dependencies

$ deps-report find-dependencies tests/project-react-js-test/src/App.js

Processed 1 file in 122.297ms.

tests/project-react-js-test/src/App.js, found 3 dependencies:
 1) react
 2) ./logo.svg
 3) ./App.css


$ deps-report -s find-dependencies tests/project-react-js-test/src/App.js

Processed 1 file in 127.538ms.

tests/project-react-js-test/src/App.js, found 3 dependencies:
 1) react, specifiers imported: default as React, Component
 2) ./logo.svg, specifiers imported: default as logo
 3) ./App.css


$ deps-report -a find-dependencies 'tests/project-react-js-test/src/*.js'

Processed 4 files in 149.446ms.

tests/project-react-js-test/src/App.js, found 3 dependencies:
 1) react
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/logo.svg
 3) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.css

tests/project-react-js-test/src/App.test.js, found 3 dependencies:
 1) react
 2) react-dom
 3) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js

tests/project-react-js-test/src/index.js, found 5 dependencies:
 1) react
 2) react-dom
 3) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/index.css
 4) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js
 5) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/registerServiceWorker.js

tests/project-react-js-test/src/registerServiceWorker.js, found 0 dependencies:
    No dependencies found!


$ deps-report -ae find-dependencies 'tests/project-react-js-test/src/*.js'

Processed 4 files in 139.507ms.

tests/project-react-js-test/src/App.js, found 2 dependencies:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/logo.svg
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.css

tests/project-react-js-test/src/App.test.js, found 1 dependency:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js

tests/project-react-js-test/src/index.js, found 3 dependencies:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/index.css
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js
 3) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/registerServiceWorker.js

tests/project-react-js-test/src/registerServiceWorker.js, found 0 dependencies:
    No dependencies found!


$ deps-report -ae find-dependencies 'tests/project-react-js-test/src/*.js' '!tests/project-react-js-test/src/**/*.test.js'

Processed 3 files in 141.737ms.

tests/project-react-js-test/src/App.js, found 2 dependencies:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/logo.svg
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.css

tests/project-react-js-test/src/index.js, found 3 dependencies:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/index.css
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js
 3) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/registerServiceWorker.js

tests/project-react-js-test/src/registerServiceWorker.js, found 0 dependencies:
    No dependencies found!


$ deps-report -w tests/project-test/webpack.config.js find-dependencies tests/project-test/a.js

Processed 1 file in 109.559ms.

tests/project-test/a.js, found 12 dependencies:
 1) path
 2) fs
 3) ./c/d.js
 4) Utilities/index.js
 5) UtilitiesRelativePath
 6) Utilities/utilityA.js
 7) Templates/main.js
 8) TemplatesMain
 9) MyPath
10) fs
11) ./e/b.js
12) ./c/d.js


$ deps-report -w tests/project-test/webpack.config.js find-dependencies --only-circular tests/project-test/a.js

Processed 1 file in 153.199ms.

tests/project-test/a.js, found 2 dependencies:
 1) ./c/d.js
 2) ./c/d.js


$ deps-report -ae -w tests/project-test/webpack.config.js find-dependencies tests/project-test/a.js

Processed 1 file in 118.478ms.

tests/project-test/a.js, found 8 dependencies:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-test/c/d.js
 2) /Users/lorenzo/Desktop/deps-report/tests/project-test/src/utilities/index.js
 3) /Users/lorenzo/Desktop/deps-report/tests/project-test/src/utilities/relative.js
 4) /Users/lorenzo/Desktop/deps-report/tests/project-test/src/utilities/utilityA.js
 5) /Users/lorenzo/Desktop/deps-report/tests/project-test/src/templates/main.js
 6) /Users/lorenzo/Desktop/deps-report/tests/project-test/src/templates/main.js
 7) /Users/lorenzo/Desktop/deps-report/tests/project-test/e/b.js
 8) /Users/lorenzo/Desktop/deps-report/tests/project-test/c/d.js


$ deps-report -w tests/project-test/webpack.config.js find-dependencies --only-not-found "tests/project-test/*.ts"

Processed 1 file in 42.623ms.

tests/project-test/c.ts

JSON format example:

$ deps-report -jps find-dependencies -c tests/project-react-js-test/src/App.js

{
  "tests/project-react-js-test/src/App.js": {
    "absolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js",
    "files": 3,
    "dependencies": [
      {
        "importPath": "react",
        "importAbsolutePath": "react",
        "isCircularDependency": null,
        "isNodeModule": true,
        "specifiers": [
          {
            "name": "React",
            "alias": "",
            "isDefault": true
          },
          {
            "name": "Component",
            "alias": "",
            "isDefault": false
          }
        ]
      },
      {
        "importPath": "./logo.svg",
        "importAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/logo.svg",
        "isCircularDependency": false,
        "isNodeModule": false,
        "specifiers": [
          {
            "name": "logo",
            "alias": "",
            "isDefault": true
          }
        ]
      },
      {
        "importPath": "./App.css",
        "importAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.css",
        "isCircularDependency": false,
        "isNodeModule": false,
        "specifiers": []
      }
    ]
  }
}

Examples find-dependents

$ deps-report find-dependents tests/project-react-js-test/src/App.js

Processed 1 file in 199.088ms.

tests/project-react-js-test/src/App.js, found 2 dependents:
 1) tests/project-react-js-test/src/App.test.js
 2) tests/project-react-js-test/src/index.js


$ deps-report -s find-dependents tests/project-react-js-test/src/App.js

Processed 1 file in 197.761ms.

tests/project-react-js-test/src/App.js, found 2 dependents:
 1) tests/project-react-js-test/src/App.test.js, specifiers imported: default as App
 2) tests/project-react-js-test/src/index.js, specifiers imported: default as App


$ deps-report -as find-dependents tests/project-react-js-test/src/App.js

Processed 1 file in 199.046ms.

tests/project-react-js-test/src/App.js, found 2 dependents:
 1) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.test.js, specifiers imported: default as App
 2) /Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/index.js, specifiers imported: default as App


$ deps-report find-dependents tests/project-test/a1.ts

Processed 1 file in 191.590ms.

tests/project-test/a1.ts, found 0 dependents:
    No dependents found!


$ deps-report find-dependents -c -r tests/project-test tests/project-test/c/d.js

Processed 1 file in 218.268ms.

tests/project-test/c/d.js, found 4 dependents:
 1) tests/project-test/a.js, Circular Dependency
 2) tests/project-test/e/b.js
 3) tests/project-test/a.ts
 4) tests/project-test/b.ts


$ deps-report -es -w tests/project-test/webpack.config.js find-dependents -r tests/project-test/ tests/project-test/src/utilities/index.js tests/project-test/src/templates/main.js

Processed 2 files in 852.220ms.

tests/project-test/src/utilities/index.js, found 2 dependents:
 1) tests/project-test/a.js, specifiers imported: default as Utilities
 2) tests/project-test/a.ts, specifiers imported: default as Utilities

tests/project-test/src/templates/main.js, found 3 dependents:
 1) tests/project-test/a.js, specifiers imported: default as templates
 2) tests/project-test/src/utilities/index.js, specifiers imported: default as templates
 3) tests/project-test/a.ts, specifiers imported: default as templates

You can search also images and css files imported in your javascript files (such as in a React project):

$ deps-report -s find-dependents tests/project-react-js-test/src/logo.svg

Processed 1 file in 218.263ms.

tests/project-react-js-test/src/logo.svg, found 1 dependent:
 1) tests/project-react-js-test/src/App.js, specifiers imported: default as logo


$ deps-report find-dependents tests/project-react-js-test/src/App.css

Processed 1 file in 213.301ms.

tests/project-react-js-test/src/App.css, found 1 dependent:
 1) tests/project-react-js-test/src/App.js

JSON format example:

$ deps-report -jps find-dependents -c tests/project-react-js-test/src/App.js

{
  "tests/project-react-js-test/src/App.js": {
    "absolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js",
    "files": 2,
    "dependents": [
      {
        "filePath": "tests/project-react-js-test/src/App.test.js",
        "fileAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.test.js",
        "importPath": "./App.js",
        "importAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js",
        "isCircularDependency": false,
        "specifiers": [
          {
            "name": "App",
            "alias": "",
            "isDefault": true
          }
        ]
      },
      {
        "filePath": "tests/project-react-js-test/src/index.js",
        "fileAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/index.js",
        "importPath": "./App.js",
        "importAbsolutePath": "/Users/lorenzo/Desktop/deps-report/tests/project-react-js-test/src/App.js",
        "isCircularDependency": false,
        "specifiers": [
          {
            "name": "App",
            "alias": "",
            "isDefault": true
          }
        ]
      }
    ]
  }
}

API Usage

const depsReport = require('deps-report')

// find-dependencies command options

let optionsFindDependencies = {
  circular: false,              // if true, it will try to see if there are some circular dependencies with input files
  onlyCircular: false,          // if true, it will return only dependecies with circular dependency with input files
  onlyNotFound: false,          // if true, it will return all modules that have no dependencies
  hideNotFound: false,          // used only for CLI output
  parent: {
    excludeNodeModules: false,  // if true, it will exclude all node modules
    json: false,                // used only for CLI output
    pretty: false,              // used only for CLI output
    absPath: false,             // used only for CLI output
    color: false,               // used only for CLI output
    webpackConfig: 'tests/project-test/webpack.config.js', // used to resolve module aliases
    specifiers: false           // if true, it will populate the specifiers imported by the dependency
  } 
}

// see the corresponding JSON format example
depsReport.findDependencies(["tests/project-test/a.js"], optionsFindDependencies)


// find-dependents command options

let optionsFindDependents = {
  root: 'tests/project-test',   // Root folder from where to start the search of dependents
  circular: false,              // if true, it will try to see if there are some circular dependencies with input files
  onlyCircular: false,          // if true, it will return only dependents with circular dependency with input files
  onlyNotFound: false,          // if true, it will return all modules that no one is depending on
  hideNotFound: false,          // used only for CLI output
  parent: {
    excludeNodeModules: false,  // if true, it will exclude all node modules
    json: false,                // used only for CLI output
    pretty: false,              // used only for CLI output
    absPath: false,             // used only for CLI output
    color: false,               // used only for CLI output
    webpackConfig: 'tests/project-test/webpack.config.js', // used to resolve module aliases
    specifiers: false           // if true, it will populate the specifiers imported by the dependent
  } 
}

// see the corresponding JSON format example
depsReport.findDependents(["tests/project-test/src/templates/*.js", "tests/project-test/src/utilities/*.js"], optionsFindDependents)

Support

Feature request/enhancement

For feature requests/enhancement, create an issue!

paypal Become a Patron

License

MIT License