Herd NPM packages in your monorepo. 🐶
This devtool ensures that common dependencies in a monorepo "resolve" to the same version to allow for hoisting with tools like Lerna. This makes for more predictable development and a smaller bundle footprint.
First, Sheepdog looks at package.json
files and forms a dependency tree. This
dependency tree represents all the dependencies an entire monorepo needs.
Next, Sheepdog examines the tree and tries to see if dependency ranges across the monorepo "resolve" to the same version. At a high-level, that routine looks like this:
- Dependency version ranges can be thought of as mathematical intervals.
- If all version ranges end on the same version with the same exclusivity,
the dependencies will resolve. For example, these version ranges will resolve
because they both end in
3.0.0
exclusive:^2.0.0 => [2.0.0, 3.0.0) ^2.1.5 => [2.1.5, 3.0.0)
Finally, using this information, Sheepdog reports which dependencies are inconsistent in which packages in the monorepo.
$ yarn add global sheepdog
Jump to command line argument documentation:
Executing Sheepdog with no arguments will find all
package.json
files in the current directory that are
simultaneously not in a node_modules
directory. It will
then warn you of dependencies that conflict with each other
in your monorepo packages (they do not resolve to the same
version).
Exits with code 0.
-b | --bark
Makes Sheepdog exit with code 1 if it finds conflicts. Useful for continuous integration.
-m | --marshal
Allows you to marshal conflicting dependencies to the correct version interactively. Useful for correcting dependency inconsistencies.
-d | --dir <directory>
Changes the working directory in which Sheepdog will try
to find package.json
files.
-q | --quiet
Suppresses extraneous information to the terminal.
-i | --ignore <modules>
Ignores conflicting versions of modules in <modules>
.
For example:
# Ignores conflicting versions of react and redux.
$ sheepdog -i react,redux
-o | --only <type>
Only work on a specific dependency type. For example:
# Only works on devDependencies and dependencies
$ sheepdog -o dependencies,devDependencies