Assume that the package foo depends on the package bar, both packages are in the same monorepo and being developed in parallel.
Since npm allows installing the local dependencies by relative paths, the bar in the package.json of foo can be specified as:
{
"name": "foo",
"version": "0.0.0"
"devDependencies": {
"bar": "../bar"
}
}
Assume also that bar is the peer dependency of foo:
{
"name": "foo",
"version": "0.0.0"
"peerDependencies": {
"bar": "0.0.0"
}
"devDependencies": {
"bar": "../bar"
}
}
Now, suppose that the version 0.0.0 of foo package has been published.
How to replace the "../bar" reference in package.json of foo with 0.0.0 and install the dependency from npm instead of symlink?
- If just execute
npm install [email protected] -E, the symlink will not be replaced with the distribution from npm. - If we execute
npm uninstall bar && npm install bar -D -E, thebarwill be deleted from thepeerDependenciestoo, thus we need manually edit thepackage.jsonto restore it after installation. Not impossible to automate it, but not very simple.
Assume that only npm may be used, no third-party utils like Lerna, Yarn workspaces, etc.
npm uninstall bar && npm install bar -D -E, the "bar" will be deleted from the peerDependencies too, thus we need manually edit the package.json to restore it after installation. Not impossible to automate it, but not very simple.