⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@mldangelo
Copy link
Contributor

Summary

The --loose flag was not being applied when validating input versions.

Problem

$ semver 1.2.3beta -l
# Expected: 1.2.3-beta (exit 0)
# Actual: exit 1

The options object (containing loose: true) was already being passed to coerce() and satisfies(), but the filter() validation step was calling semver.valid(v) without it.

Fix

-  return semver.valid(v)
+  return semver.valid(v, options)

Test plan

  • Added regression test for 1.2.3beta -l
  • All existing tests pass
  • 100% code coverage maintained

@mldangelo mldangelo requested a review from a team as a code owner December 20, 2025 08:08
@mldangelo mldangelo force-pushed the fix/cli-loose-validation branch from b4fa6e7 to 643da59 Compare December 20, 2025 08:11
Copy link
Contributor

@mbtools mbtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for fixing the bug. Please just add the missing test.

}
`

exports[`test/bin/semver.js TAP inc tests > -i release 1.0.0-pre`] = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be deleted. There was a test missing in #753 (see below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Added the missing test ['-i', 'release', '1.0.0-pre'] which restores this snapshot.

['-i', 'premajor', '1.0.0', '--preid=beta', '-n', '1'],
['-i', 'premajor', '1.0.0', '--preid=beta', '-n', 'false'],
['-i', '1.2.3'],
].map(args => t.resolveMatchSnapshot(run(args), args.join(' ')))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the missing test after -i 1.2.3:

['-i', 'release', '1.0.0-pre'],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - added.

mbtools added a commit to abapPM/ABAP-SemVer that referenced this pull request Jan 14, 2026
Update from 7.7.1 to 7.7.3 
(already contains npm/node-semver#835)
@mbtools mbtools mentioned this pull request Jan 14, 2026
The `--loose` flag was not being applied when validating input versions.
The `options` object was already computed and passed to `coerce()` and
`satisfies()`, but the `filter()` call using `semver.valid(v)` was missing
the options parameter.

This meant that loose versions like `1.2.3beta` would fail validation
even when `-l` was specified, despite the documentation stating that
`-l --loose` will "Interpret versions and ranges loosely".
@mldangelo mldangelo force-pushed the fix/cli-loose-validation branch from 643da59 to 8a90577 Compare January 15, 2026 18:21
Copy link
Contributor

@mbtools mbtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm

@wraithgar
Copy link
Member

Thanks @mldangelo for writing this and thanks @mbtools for walking it through the review process to completion.

@wraithgar wraithgar merged commit a29faa5 into npm:main Jan 15, 2026
46 of 54 checks passed
@github-actions github-actions bot mentioned this pull request Jan 15, 2026
@wraithgar
Copy link
Member

7.7.4 will be released once we update our templates to use a newer version of the macos runners (we need to use intel to test node 14, and the macos-13 image was removed).

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.

3 participants