You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: how to fix versions between dependencies? #359
I don't know if Lerna has some automation to manage this, and I couldn't find any related issues to this:
Basically, I understand that the "Fixed/Locked mode" uses one version for all modules (this is what I want), but is there a way to fix dependencies between modules?
For example, if A depends on B, and the version in lerna.json is 4.1.0, I want packages/A/package.json to be updated with:
{"dependencies": {"B": "4.1.0"}}
instead of "B": "^4.0.0" (it seems to be what Babel is doing).
Update: It doesn't look like something that can be done by lerna. I'll write a script in the repository to update all package.json files to fix versions according to the "master" version.
#! /usr/bin/env node
constfs=require('fs');constpath=require('path');constlernaConfig=require('../lerna.json');// List all the packagesconstPACKAGES_DIR=path.resolve(__dirname,'../packages');constpackages=fs.readdirSync(PACKAGES_DIR);functionupdateDependencies(dependencies){Object.keys(dependencies).map((key)=>{if(!packages.includes(key)){return;}dependencies[key]=lernaConfig.version;});}packages.forEach((name)=>{// Avoid .DS_Storeif(name[0]==='.'){return;}constpkgPath=path.resolve(PACKAGES_DIR,name,'package.json');constpkg=require(pkgPath);pkg.version=lernaConfig.version;updateDependencies(pkg.dependencies);updateDependencies(pkg.devDependencies);fs.writeFileSync(pkgPath,JSON.stringify(pkg,null,3),'utf-8');});
Hey, when do you run this script? One person in our team accidentally made a change in multiple packages, which looked like it didn't create a breaking change, but because inner package dependencies are not locked, it broke other place which used older version. This thing would help us a lot.
EDIT: Didn't get a response, so I solved it this way:
Run a script during git pre-commit and check if lerna.json file has changed.
#!/bin/bash
UPDATED=$(git diff --cached --name-only)
if grep -q lerna.json <<< $UPDATED; then
echo 'Fixing package versions...'
node ./scripts/fix-versions.js
exit 0;
else
exit 0;
fi
If it has changed I run script which simply removes ^ from before version.
Looking at this again, I think it may actually be different from #259. If I'm reading this right, this issue is about pinning to exact versions within the repo, while #259 is about managing external deps.
@Gongreg pointed out that #426 seems to address this issue.
My expectation was exactly the same — dependent package version should be fixed, not using ^ or ~ My main package is an aggregator of other packages and, so, I want to be sure that all are compatible and tested together, so, versions should be fixed.
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Activity
SamyPesse commentedon Oct 4, 2016
Update: It doesn't look like something that can be done by lerna. I'll write a script in the repository to update all
package.jsonfiles to fix versions according to the "master" version.SamyPesse commentedon Oct 8, 2016
Here is the script I'm using:
Gongreg commentedon Nov 3, 2016
Hey, when do you run this script? One person in our team accidentally made a change in multiple packages, which looked like it didn't create a breaking change, but because inner package dependencies are not locked, it broke other place which used older version. This thing would help us a lot.
EDIT: Didn't get a response, so I solved it this way:
Run a script during git pre-commit and check if lerna.json file has changed.
If it has changed I run script which simply removes ^ from before version.
Code is not nice (mutations everywhere), but it will hold.
And after changing file it adds it to staged files. I am not sure it works correctly, we will still have to try it out.
jamiebuilds commentedon Nov 16, 2016
Merging into #259
gigabo commentedon Dec 13, 2016
Looking at this again, I think it may actually be different from #259. If I'm reading this right, this issue is about pinning to exact versions within the repo, while #259 is about managing external deps.
@Gongreg pointed out that #426 seems to address this issue.
develar commentedon Jan 2, 2017
My expectation was exactly the same — dependent package version should be fixed, not using
^or~My main package is an aggregator of other packages and, so, I want to be sure that all are compatible and tested together, so, versions should be fixed.vitorbal commentedon Jan 5, 2018
I think this can be closed now that #426 was merged, which adds support for the
--exactflag.lock commentedon Dec 27, 2018
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.