Skip to content
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: add identifier validation to inc() #754

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

mbtools
Copy link
Contributor

@mbtools mbtools commented Jan 21, 2025

  • Adds a check of the identifier parameter for inc() when trying to increase pre-releases. This prevents the creation of an invalid semver.
  • Removes side-effects of inc() when it is throwing (it was changing the version)

Closes #349

@mbtools mbtools requested a review from a team as a code owner January 21, 2025 19:38
classes/semver.js Outdated Show resolved Hide resolved
@wraithgar
Copy link
Member

The .inc docs already state or null if it's not valid. This is how folks currently will have been building their code. We can't start throwing here w/o a semver major change.

We'll have to return null in cases where we're throwing in this PR. I do think refusing to generate invalid results is a good bugfix. Semver.inc('1.1.1', 'prerelease', 'dev/bar') should return null

@mbtools
Copy link
Contributor Author

mbtools commented Jan 28, 2025

The inc() function does exactly that:

https://github.com/npm/node-semver/blob/main/functions/inc.js#L16

The classes usually throw if something is off. Should this be different here?

@wraithgar
Copy link
Member

The inc() function does exactly that:

Ah yep you're right.

@wraithgar wraithgar merged commit 8a34bde into npm:main Jan 28, 2025
29 checks passed
@github-actions github-actions bot mentioned this pull request Jan 28, 2025
@mbtools mbtools deleted the inc_validate_preid branch January 28, 2025 17:53
wraithgar pushed a commit that referenced this pull request Jan 29, 2025
🤖 I have created a release *beep* *boop*
---


## [7.7.0](v7.6.3...v7.7.0)
(2025-01-29)
### Features
*
[`0864b3c`](0864b3c)
[#753](#753) add "release" inc
type (#753) (@mbtools)
### Bug Fixes
*
[`d588e37`](d588e37)
[#755](#755) diff: fix prerelease
to stable version diff logic (#755) (@eminberkayd, berkay.daglar)
*
[`8a34bde`](8a34bde)
[#754](#754) add identifier
validation to `inc()` (#754) (@mbtools)
### Documentation
*
[`67e5478`](67e5478)
[#756](#756) readme: added
missing period for consistency (#756) (@shaymolcho)
*
[`868d4bb`](868d4bb)
[#749](#749) clarify comment
about obsolete prefixes (#749) (@mbtools, @ljharb)
### Chores
*
[`145c554`](145c554)
[#741](#741) bump
@npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
*
[`753e02b`](753e02b)
[#747](#747) bump
@npmcli/template-oss from 4.23.3 to 4.23.4 (#747) (@dependabot[bot],
@npm-cli-bot)
*
[`0b812d5`](0b812d5)
[#744](#744) postinstall for
dependabot template-oss PR (@hashtagchris)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] inc() may produce invalid semver with ReleaseType: prerelease
2 participants