feat: support NuGet version ranges for gallery dependency types#199
feat: support NuGet version ranges for gallery dependency types#199HeyItsGilbert wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds NuGet-style version range support to PSDepend’s gallery-backed dependency types by allowing ranges to be expressed in the existing Version string field (while keeping bare versions as exact matches for backward compatibility). It centralizes version ordering and range evaluation in shared private helpers, and updates the PSGallery dependency scripts to resolve ranges to a concrete version where native installers can’t express exclusive bounds.
Changes:
- Added shared private helpers:
Compare-Version,ConvertFrom-VersionRange,Test-VersionInRange; reimplementedTest-VersionEqualityon top ofCompare-Version. - Updated
PSGalleryModuleandPSGalleryNugetto resolve a range to the highest satisfying available version before installing (since their installers require exact versions); updatedPSResourceGetto treat ranges as a pass-through for install and for “already satisfied” checks. - Added unit tests for the helpers and expanded type tests for the three affected dependency scripts; updated docs/ADR/changelog.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| PSDepend/PSDependScripts/PSGalleryModule.ps1 | Accepts ranges; resolves range to exact version before Install-Module; uses Test-VersionInRange for installed satisfaction checks |
| PSDepend/PSDependScripts/PSGalleryNuget.ps1 | Accepts ranges; resolves range to exact version before invoking nuget.exe; uses Test-VersionInRange for installed satisfaction checks |
| PSDepend/PSDependScripts/PSResourceGet.ps1 | Uses Test-VersionInRange for installed satisfaction checks; uses Compare-Version for “latest” up-to-date logic |
| PSDepend/Private/Compare-Version.ps1 | New shared ordering primitive for version strings (SemVer → System.Version → string fallback) |
| PSDepend/Private/ConvertFrom-VersionRange.ps1 | New NuGet range parser with exact-vs-range detection based on delimiters |
| PSDepend/Private/Test-VersionInRange.ps1 | New shared predicate for “does installed version satisfy exact or range?” |
| PSDepend/Private/Test-VersionEquality.ps1 | Reimplemented equality via Compare-Version |
| Tests/Compare-Version.Tests.ps1 | New unit tests for Compare-Version |
| Tests/ConvertFrom-VersionRange.Tests.ps1 | New unit tests for range parsing |
| Tests/Test-VersionInRange.Tests.ps1 | New unit tests for range satisfaction semantics |
| Tests/PSGalleryModule.Type.Tests.ps1 | Added range-resolution and satisfaction/skip behavior tests |
| Tests/PSGalleryNuget.Type.Tests.ps1 | Added range-resolution and “no satisfying version” behavior tests |
| Tests/PSResourceGet.Type.Tests.ps1 | Added range pass-through and satisfaction/skip behavior tests |
| CONTEXT.md | Documented the “VersionRange in Version field” concept |
| CHANGELOG.md | Added entry documenting version range support for the three types |
| adr/0001-nuget-version-ranges.md | Added ADR capturing rationale and constraints of NuGet range syntax + exact resolution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test Results 3 files 78 suites 1m 30s ⏱️ Results for commit 70a4dc6. ♻️ This comment has been updated with latest results. |
…91) Carry version ranges in the existing Version field using NuGet range syntax (e.g. '[2.2.3,3.0)', '[2.0,)', '(,3.0)') for PSGalleryModule, PSResourceGet, and PSGalleryNuget. A bare version still means an exact version; a range installs the highest available version that satisfies it. Add three private helpers: Compare-Version (IComparable ordering primitive that replaces the duplicated TryParse blocks), ConvertFrom-VersionRange (parser), and Test-VersionInRange (the shared satisfaction predicate). Test-VersionEquality is reimplemented on Compare-Version. PSResourceGet passes the range straight to Install-PSResource; the other two resolve the range to an exact version (find -> filter -> install) since their installers cannot express exclusive bounds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A malformed NuGet range (e.g. [1.0.0,2.0.0) caused ConvertFrom-VersionRange to return $null, leaving RequiredVersion unset so the script silently fell back to installing the latest version instead of the constrained range. Error out and skip install when the range cannot be parsed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c7145a8 to
d89a752
Compare
- Fail fast on malformed version ranges in PSGalleryNuget and PSResourceGet,
matching the PSGalleryModule contract (+ regression tests for both).
- Extract the duplicated range-resolution loop into a shared
Resolve-VersionInRange helper used by PSGalleryModule and PSGalleryNuget
(+ unit tests).
- Route PSResourceGet's import-version range detection through
ConvertFrom-VersionRange instead of a divergent inline regex that dropped
the ')' delimiter.
- Fix $params.Add casing nit and the "repository []" empty-repository error
message in PSGalleryModule.
- Trace Compare-Version's ordinal string fallback via Write-Verbose.
- Correct the stale Test-VersionEquality description; document PSResourceGet's
range pass-through (help, CONTEXT.md) and add a range example.
- Tighten the PSGalleryModule resolve test (-ParameterFilter { $AllVersions }),
add a null-Version case for Test-VersionInRange, and assert PSResourceGet
pass-through does not pre-resolve via Find-PSResource.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Adds version-range support to the gallery dependency types, carried in the existing
Versionfield using NuGet range syntax (e.g.'[2.2.3,3.0)','[2.0,)','(,3.0)').'3.2.1') still means that exact version — existing requirements files are unaffected.@{ Pester = '[5.0,6.0)' }) and hash syntax.Supported for
PSGalleryModule,PSResourceGet, andPSGalleryNuget.Design
A string is treated as a range only when it contains a delimiter (
[ ] ( ) ,); otherwise it stays exact. Seeadr/0001-nuget-version-ranges.mdfor the rationale (NuGet syntax over named keys/operator strings; resolving to an exact version instead ofInstall-Module's inclusive-only native params).Implementation
Compare-Version(IComparable ordering primitive, replaces the duplicatedTryParseblocks),ConvertFrom-VersionRange(parser),Test-VersionInRange(shared satisfaction predicate).Test-VersionEqualityreimplemented onCompare-Version.Install-PSResource -Version.Tests
Closes #65
Closes #91
🤖 Generated with Claude Code