New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(version): add --allow-peer-dependencies-update
, closes #333
#363
Conversation
--allow-peer-deps-update
, closes #333
Codecov Report
@@ Coverage Diff @@
## main #363 +/- ##
==========================================
+ Coverage 96.35% 97.26% +0.91%
==========================================
Files 145 145
Lines 4271 4296 +25
Branches 978 992 +14
==========================================
+ Hits 4115 4178 +63
+ Misses 156 118 -38
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
9369a33
to
d8b846f
Compare
@StarpTech are you going to have a chance to review the PR within the next couple days? I'd like to release this by next week if possible |
I try my best to review it this weekend 🤞 |
I wonder if I should rename the option name |
--allow-peer-deps-update
, closes #333--allow-peer-dependencies-update
, closes #333
I'm going to review it today. |
@StarpTech that'd be awesome because I was about to merge without review, I want to release by the end of this week. Thanks |
It is pretty clear to me. I like. |
I'm not sure if this is right. A fixed peerDep Hi, after reading other issues, I'm unsure if the current assumptions are correct in independent mode. My issue in #333 was the too-restricted version constraint. Under < v1 the developer can use With that knowledge, I'd expect that Lerna is throwing an error (before release and commit) when a version is being published with an invalid peerDep constraint. The developer is responsible to fix this manually. In global mode, this may be automated by bumping the peerDep to lowest compatible version. Again the developer is responsible to set a proper range. Otherwise, Lerna would update it every time. Does it make sense? |
in this case the peer dep
I'm not entirely sure of everything you said but technically speaking the new option would not bump something like
I don't think it's Lerna's responsibility to do anything with a peer dependency that has version range with operator(s), that is the user responsibility to make it valid. The goal of this new PR is simply to apply the exact same bump, as a regular dependency would, and duplicate it in the peer dependencies if need be (which is exactly what you described in issue #333), and that will fix the main issue that everyone brought up in Lerna. Also the regex that I mentioned is only in place to act as a guard (as a peer dep, are you allowed to be bumped, yes or not), this PR has zero code change for the bump logic, I don't intent to change that. To explain a little more what this PR does, prior to this PR the previous implementation of |
You probably have a better understanding of this than me. I'm no longer convinced when this feature is required. Could you add some simple use cases? It might also be good to mention them in the README. After reading the README, the feature sounds like a super edge case. |
@StarpTech well the perfect example would be the one you provided in #333, I also updated the with the new flag both deps would be bumped, for example a {
"name": "B",
"dependencies": {
"A": "workspace:^1.2.0" // will bump to "workspace:^1.3.0",
"B": "^0.4.0": // will bump to "^0.5.0"
},
"peerDependencies": {
"A": "workspace:^1.2.0" // will bump to "workspace:^1.3.0"
"B": ">=0.2.0": // will not be bumped because range with operator (>=) are skipped
}
} without the flag it will only bump the first one it found, that is {
"name": "B",
"dependencies": {
"A": "workspace:^1.2.0" // will bump to "workspace:^1.3.0"
"B": "^0.4.0": // will bump to "^0.5.0"
},
"peerDependencies": {
"A": "workspace:^1.2.0" // will NEVER be bumped
"B": ">=0.2.0": // will NEVER be bumped
}
} I think the concept from the first implementation (prior to this PR) was that you can never have the same package dep into more than one However, |
I think my implementation is ok, so I'll go ahead and merge the PR, I'll release a new version probably later today |
--allow-peer-deps-update
, closes #333 #362Description
Add a new option
--allow-peer-dependencies-update
option on the version command which will help to update peer dependencies before publishing them. This option is opt-in and disabled by default because of what the original Lerna maintainer wrote in Lerna issue #1018This option is not recommended for most users, for them
peerDependencies
will remain untouched unless the user really wants it enabled and has more knowledge in this regard. However even when this flag is enabled, it will never mutate/update peer dependencies with semver range operator (ie>=2.0.0
).Regex used
For this implementation, we'll use this regex to identify if the peer dependency is allowed to be updated or not (regex101)
Note
While at it, the code in
package
andpackage-graph
related toworkspace:
protocol were refactored a bit to follow similar implementation as to what Lerna as recently done, even though the implementation is different at least the naming is now similar.Motivation and Context
Provide a way to bump peer dependencies but only via a flag, this behavior will be disabled by default, this will close #333
The main code change for this new option is in the
updateLocalDependency()
method found inpackage.ts
, a new argumentallowPeerDepsUpdate
was added and when enabled it will addpeerDependencies
into the loop of dependencies to be inspected for updates. The loop is also new in that same method, since prior to this we would only update/bump the 1st dependency found, however now if the flag is enabled, we also include (loop) the peer dependency as well so instead of updating 1 dependency (by name), we might update up to 2 of with the same namein summary, calling
lerna version --allow-peer-dependencies-update
(or the equivalentlerna.json
config) on this packagewill bump both the
dependencies
andpeerDependencies
to^1.3.0
on aminor
bump (note again that a semver range>=
will never be bumped)How Has This Been Tested?
added a lot more unit tests to cover
package.ts
,package-graph
,publish
andversion
What will be valid and update?
It will update (bump) regular semver like these
1.2.3
^1.2.3
^1.4.0-alpha.0
workspace:^1.2.3
but it won't mutate/update things like
>=1.0.0
>=1.0.0 <2.0.0
^1 | ^2 | ^3
Types of changes
Checklist: