Commit b53eecc
authored
Fix version comparison logic for 'latest' upgrades in PSGalleryModule and Package scripts (#170)
## Root Cause
PSDepend was failing to upgrade modules/packages when requesting
`'latest'` if a newer minor version was available. For example, machines
with version 2.8.0 would not upgrade to 2.10.0, reporting:
```
You have the latest version of [module-name], with installed version [2.8.0] and PSGallery version [2.10.0]
```
The issue was **string-based version comparison** instead of typed
version comparison. When comparing as strings:
- `"2.10.0" -le "2.8.0"` evaluates to `$true` (because "1" < "8"
lexically)
This caused the logic to incorrectly conclude that 2.10.0 was not newer
than 2.8.0.
## Solution
Both PSGalleryModule.ps1 and Package.ps1 now:
1. Attempt to parse versions as
`[System.Management.Automation.SemanticVersion]` objects first
2. Fall back to `[System.Version]` if SemanticVersion parsing fails
3. Compare the **typed objects** instead of strings
4. Return `$false` if neither parsing method succeeds
## Testing
Added regression tests to catch this scenario:
- **PSGalleryModule.Type.Tests.ps1**: Verifies 2.8.0 → 2.10.0 upgrade
with `latest`
- **Package.Type.Tests.ps1**: Same scenario for Package dependencies
Fixes #139
Fixes #1531 parent 864e03d commit b53eecc
4 files changed
Lines changed: 64 additions & 9 deletions
File tree
- PSDepend/PSDependScripts
- Tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
255 | | - | |
256 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
257 | 258 | | |
258 | | - | |
259 | | - | |
| 259 | + | |
| 260 | + | |
260 | 261 | | |
261 | | - | |
262 | | - | |
263 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
187 | 206 | | |
188 | 207 | | |
189 | 208 | | |
190 | | - | |
| 209 | + | |
191 | 210 | | |
192 | 211 | | |
193 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
122 | 137 | | |
123 | 138 | | |
124 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
66 | 81 | | |
0 commit comments