-
Notifications
You must be signed in to change notification settings - Fork 492
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
fix: ensure SemVer instance passed to inc are not modified #427
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the commit updating parse
? After that I think this is good to go!
inc
can be used three ways:npx semver 1.0.0 -i major
SemVer
class: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
inc
should 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
SemVer
instance created inside theinc
function 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