Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Latest commit

 

History

History
52 lines (39 loc) · 3.07 KB

README.md

File metadata and controls

52 lines (39 loc) · 3.07 KB

@canva/dependency-tree

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%+.

Usage

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, [
  '/path/to/my/dir/file.ts',
]);

// or we can get the set of (transitive) dependencies of a file
const directOrTransitiveDependencies = DependencyTree.getDependencies(
  resolved,
  ['/path/to/my/dir/file.ts'],
);

Use cases

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

Releasing

  • 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.