@asidatascience/link-local-monorepo
v1.0.4
Published
A utility for linking all monorepo packages in another project
Keywords
Readme
Link Local Monorepo
A convenience utility for linking pnpm monorepo packages in another project. Uses the file: protocol.
- Works with
pnpmworkspaces - Requires the monorepo packages to be in the
packagesdirectory - Currently only supports linking a single monorepo
- Consuming project must use git and have
pnpm-lock.yamlat the git root
Installing
pnpm install @asidatascience/link-local-monorepo- Add a
.pnpmfile.cjs. Example usage:
const ENV_FILE = '.env';
const ENV_PROPERTY = 'MY_MONOREPO_PATH';
const setupLocalLink = require('@asidatascience/link-local-monorepo').init(ENV_FILE, ENV_PROPERTY);
function readPackage(pkg, context) {
setupLocalLink(pkg);
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};Usage
- Add an env file matching defined
ENV_FILE - Set an environment variable equal to the defined
ENV_PROPERTYwith a path to the mono repo pnpm install- Unset the value and repeat the install before committing changes
Injected vs uninjected dependencies
Typically, you will be using this to link your monorepo into another location for local development, so you will want changes to synchronise across as you develop.
However, on some build systems, such as Vercel, this can create type conflicts as the source monorepo packages will clash with the target repo packages. If this happens, you can set { injected: true } as an option on .init() to make the packages injected. This will instead force-install the source monorepo packages rather than link them.
This will mean that changes will not synchronise, but it will stop package conflicts.
(Recommended) Block lock file commits of local packages
Add a git precommit hook with the following
pnpm fail-if-linking-local
