skott is a minimalist developer tool that can be used to efficiently generate directed graphs from your JavaScript/Node.js project. It can automatically collect metadata, detect circular dependencies and can be used to implement affected/incremental patterns as it exposes a way to know precisely dependencies for each graph node.
Graph Construction skott is powered by digraph-js, a 0 dependency Node.js library to make Directed Graph construction and traversal effortless.
Note
skott goal is to represent all the file tree structure but was designed to only include dependencies currently being used in the project based on the entrypoint. Consequently unused files (files that are not imported/exported by any other file) won't be included in the graph structure.
Work in progress includes:
Why you should care about circular dependencies and dead code
- Circular (also known as cyclic) dependencies
Let's start with an example of a simple circular dependency between three graph nodes:
In the context of skott, nodes represent JavaScript files.
graph LR
src/fileA.js --> src/fileB.js
src/fileB.js --> src/fileC.js
src/fileC.js --> src/fileA.js
What is the problem with cycles?
Circular dependencies can make your program crash or introduce inconsistencies while modules are being loaded. Node.js module systems try to resolve circular dependencies using different approaches which are more or less successful. For example, CommonJS can (due to its dynamic nature of resolving imports) introduce inconsistencies when building the project graph.
If you're using ECMAScript modules, you can consider yourself safe about module resolution inconsistencies mentioned above, mostly thanks to its static nature.
Nevertheless, cyclic dependencies at the file-level are sometimes choices but more often code smells revealing design misconceptions, so be sure to double check that.
- Dead code
Dead code can be defined as a code literally having no impact on the application, meaning that removing dead code should not alter in any way the behavior of the system. Some module bundlers such as Rollup and Webpack allow to delete some of the dead code leveraging tree shaking.
However, tree shaking is not an easy task and can mostly work with module systems using static-based imports/exports such as ECMAScript modules. To avoid removing code that appears to be used at runtime, module bundlers are being very precise about determining automatically chunks of code that can be safely removed. Module bundlers can also be helped by providing them manually clues about what can be safely removed e.g. /*#__PURE__*/
for Webpack.
If you're not using tools implementing tree shaking, you will be able soon to use skott, which will bring up soon unused imports/exports warnings
Documentation
Please refer to the documentation at the skott package level