fix: ensure SemVer instance passed to inc are not modified#427
fix: ensure SemVer instance passed to inc are not modified#427lukekarrys merged 2 commits intonpm:mainfrom
Conversation
|
Thanks for this PR @louis-bompart! I think this is the right direction for And I apologize for letting this sit so long, it now has some conficts and shouldn't need any dep updates as those have all been updated. |
That's my two cents, so take it as it is, but I think that a 'clone' function would be a bit out of place: I think adding a factory function to the SemVer class would maybe be more in place. So instead of doing: import {clone, SemVer} from 'semver';
const verA = new SemVer('1.0.0');
const verB = clone(verA);One would do this: import {SemVer} from 'semver';
const verA = new SemVer('1.0.0');
const verB = SemVer.clone(verA);Another solution would be to do nothing and use structuredClone internally. This would require to enforce Node >=17.x tho. |
✔️. As far as I could tell, only |
|
Thanks @louis-bompart! This looks great!
Thanks for looking into this, not sure why I thought there would be more. And sorry for the back and forth but I now think that this should only apply to I can see people using > s = new semver.SemVer('1.0.0')
SemVer {
options: {},
loose: false,
includePrerelease: false,
raw: '1.0.0',
major: 1,
minor: 0,
patch: 0,
prerelease: [],
build: [],
version: '1.0.0'
}
> s === semver.parse(s)
true
> s === semver.parse('1.0.0')
false |
lukekarrys
left a comment
There was a problem hiding this comment.
Can you remove the commit updating parse? After that I think this is good to go!
inccan be used three ways:npx semver 1.0.0 -i majorSemVerclass:semverInstance.inc('major')inc('1.0.0', 'major')This PR does not impact the behaviour of the first two and focuses only on the last one.
The underlying issue is described in #425, but tl;dr
incshould be a pure function (I think, from its documentation on NPM), and here it has a side-effect.I remove this side-effect by ensuring that the
SemVerinstance created inside theincfunction is created from a string, which removes the mutation vector.References
Depends on #426 - just to fix the tests, that's why 563d75e is polluting the changeset
Fixes #425