§ Quick Take
lerna add runs a whole chain of actions redundantly validating the packages and calling the internet.
We want the —
npm i but for packages within our monorepo!
That's what this CLI does:
That's it. For example, symlink is created at "monorepo-root/packages/object-all-values-equal-to/node_modules/detergent" pointing to "monorepo-root/packages/detergent".
As you expect,
package.json is updated, CLI's are linked properly to
bin/ and devDeps can be set via a flag:
deplink "detergent" -d
deplink "detergent" --dev
§ Supports CLI's
If your package ("b" from the example above) is a CLI, symlinks will be put one level deeper, instead of within
node_modules, for each entry in
bin from package.json, a symlink will be created in
node_modules/.bin/, pointing not to the root of the package "b" but straight to the file that
bin entry in package.json was pointing to.
lerna-clean-changelogs-cli of ours has the following
bin entry in its
If you git-cloned our monorepo and wanted to link package
lerna-clean-changelogs-cli to another package, two symlinks would be created, one for
lcc and another for
lernacleanchangelog, both pointing to the same file,
PS. If you wonder, what happens if a package is both CLI and normal package (has both "main" and "bin" keys in
package.json)? It will still work — both sets of symlinks will be created.
According to lerna link documentation ,
lerna link "symlinks together all packages that are dependencies of each other". But we want just to symlink one!
Well, now those days are gone, we have a simple dependency linker at last.
§ The finest ingredients
Only the finest ~dependencies~ ingredients are used in this CLI:
fs-extra- for promise-based I/O
execa- to run shell processes, the
meow- to bootstrap the CLI
update-notifier- to remind users if currently installed CLI is outdated
Copyright © 2010–2020 Roy Revelt and other contributors