Necessitates Proper Modularity

    TypeScript icon, indicating that this package has built-in type declarations

    3.1.7 • Public • Published


    build npm

    This package can create a dependency tree from a given set of files/folders. The nodes of the tree are files and the edges are file -> file dependencies. The most common way to express such a dependency between two files is some sort of import statement (require(), import ... from, @import) or a directive.

    It provides an extensible API for file processors to generate this dependency tree and comes with a few of them out of the box:

    It has support for custom resolvers using enhanced-resolve and dynamic reference transformation. It has built-in file caching and test coverage is ~80%+.


    const dependencyTree = new DependencyTree(['/path/to/my/dir']);
    const {
      missing, // a map from files in any of the given root directories to their (missing) dependencies
      resolved, // a map from files in any of the given root directories to their dependencies
    } = await dependencyTree.gather();
    // we can now get set of (transitive) references to a file
    const directOrTransitiveReferences = DependencyTree.getReferences(resolved, [
    // or we can get the set of (transitive) dependencies of a file
    const directOrTransitiveDependencies = DependencyTree.getDependencies(

    Use cases

    • Visualisation of (epxlicit and implicit) in-code dependencies
    • Identifying build targets that need to be regenerated based on affected code


    • Bump the version of package.json to a meaningful version for the changes since the last release (we follow semver).
    • To do a dry-run of the release and what would go out in the package you can manually execute the npm-publish workflow on the main branch. It will do a dry-run publish (not actually publish the new version).
    • Draft a new release in the github project - please use a tag named vX.X.X (where X.X.X is the new to-be-releases semver of the package - please add as many detail as possible to the release description.
    • Once you're ready, Publish the release. Publishing will trigger the npm-publish workflow on the tag and do the actual publish to npm.


    npm i @canva/dependency-tree

    DownloadsWeekly Downloads






    Unpacked Size

    65 kB

    Total Files


    Last publish


    • canva-opensource
    • canva-dev