How to view the dependency tree of a js, ts file module

Keywords: Javascript React less npm github

Recently, I took over a page of others. The code was messy and jumbled. When I was adding functions, I found that the module I added conflicts with the original module, but I didn't know where the original module was, so I found it.

But I found that this way is too clumsy, and I didn't find the corresponding tool on the Internet, so I wrote a tool myself.

Project address: sdep.

install

npm install sdep -g

Use

sdep [options] <file>

Common command line parameters

  • -Q, -- Query < query >: find the dependency chain of a module (for example: - q react)
  • -r, --regular: match query as a regular (for example: - Q 'react|react DOM' - R)
  • -i, --ignore: do not display files in node \

Third party libraries used

Example

View the dependency structure of a file

sdep example/index.js
example/index.js
├ example/css/css.css
├ example/css/scss.scss
├ example/css/less.less
├ example/jsx.jsx
| ├ node_modules/react/index.js
| | ├ node_modules/react/cjs/react.production.min.js
| | | └ node_modules/object-assign/index.js
| | └ node_modules/react/cjs/react.development.js
| |   ├ node_modules/object-assign/index.js
| |   └ node_modules/prop-types/checkPropTypes.js
| |     └ node_modules/prop-types/lib/ReactPropTypesSecret.js
| ├ node_modules/react-dom/index.js
| | ├ node_modules/react-dom/cjs/react-dom.production.min.js
| | | ├ node_modules/react/index.js
| | | | ├ node_modules/react/cjs/react.production.min.js
| | | | | └ node_modules/object-assign/index.js
| | | | └ node_modules/react/cjs/react.development.js
| | | |   ├ node_modules/object-assign/index.js
| | | |   └ node_modules/prop-types/checkPropTypes.js
| | | |     └ node_modules/prop-types/lib/ReactPropTypesSecret.js
| | | ├ node_modules/object-assign/index.js
| | | └ node_modules/scheduler/index.js
| | |   ├ node_modules/scheduler/cjs/scheduler.production.min.js
| | |   └ node_modules/scheduler/cjs/scheduler.development.js
| | └ node_modules/react-dom/cjs/react-dom.development.js
| |   ├ node_modules/react/index.js
| |   | ├ node_modules/react/cjs/react.production.min.js
| |   | | └ node_modules/object-assign/index.js
| |   | └ node_modules/react/cjs/react.development.js
| |   |   ├ node_modules/object-assign/index.js
| |   |   └ node_modules/prop-types/checkPropTypes.js
| |   |     └ node_modules/prop-types/lib/ReactPropTypesSecret.js
| |   ├ node_modules/object-assign/index.js
| |   ├ node_modules/prop-types/checkPropTypes.js
| |   | └ node_modules/prop-types/lib/ReactPropTypesSecret.js
| |   ├ node_modules/scheduler/index.js
| |   | ├ node_modules/scheduler/cjs/scheduler.production.min.js
| |   | └ node_modules/scheduler/cjs/scheduler.development.js
| |   └ node_modules/scheduler/tracing.js
| |     ├ node_modules/scheduler/cjs/scheduler-tracing.production.min.js
| |     └ node_modules/scheduler/cjs/scheduler-tracing.development.js
| └ example/wel.jsx
|   └ node_modules/react/index.js
|     ├ node_modules/react/cjs/react.production.min.js
|     | └ node_modules/object-assign/index.js
|     └ node_modules/react/cjs/react.development.js
|       ├ node_modules/object-assign/index.js
|       └ node_modules/prop-types/checkPropTypes.js
|         └ node_modules/prop-types/lib/ReactPropTypesSecret.js
└ example/async/index.js
  └ example/async/index.css

View the dependency chain of a file containing react

sdep example/index.js -q react
example/index.js
└ example/jsx.jsx
  └ node_modules/react/index.js
example/index.js
└ example/jsx.jsx
  └ node_modules/react-dom/index.js
example/index.js
└ example/jsx.jsx
  └ example/wel.jsx
    └ node_modules/react/index.js

View the dependency chain of a file containing less or scss

sdep example/index.js -q 'less|scss' -r
example/index.js
└ example/css/scss.scss
example/index.js
└ example/css/less.less

Follow-up

More blogs, see https://github.com/senntyou/blogs

Author: Deep to you (@ senntyou)

Copyright notice: Free Reprint - non commercial - non derivative - keep signature( Creative sharing 3.0 License)

Posted by Anarking on Sat, 30 Nov 2019 12:43:20 -0800