[Windows] Use Get-LatestChocoPackageVersion to get nodejs version to install (#4469)

* Use Get-LatestChocoPackageVersion to get nodejs
* Fix typo in Send-RequestToChocolateyPackages
This commit is contained in:
Mikhail Timofeev
2021-11-11 13:13:07 +03:00
committed by GitHub
parent 08024941c3
commit 0ddb8a2302
2 changed files with 4 additions and 13 deletions

View File

@@ -11,16 +11,7 @@ New-Item -Path $PrefixPath -Force -ItemType Directory
New-Item -Path $CachePath -Force -ItemType Directory
$defaultVersion = (Get-ToolsetContent).node.default
$queryFilter = "`$filter=(Id eq 'nodejs') and (IsPrerelease eq false) and (Version ge '$defaultVersion')"
$url = "https://community.chocolatey.org/api/v2/Packages()?$queryFilter"
$chocoVersionsOutput = (Invoke-RestMethod -Uri $url).properties.Version
# Take the latest version available for given default version from the toolset which is used as wildcard
# Toolset file can contain a version in any form: Major, Major.Minor or even the exact version
$versionToInstall = $chocoVersionsOutput |
# Take the exact default version and its subversions
Where-Object { $_ -Like "$defaultVersion.*" -or $_ -eq $defaultVersion } |
Sort-Object { [Version]$_ } |
Select-Object -Last 1
$versionToInstall = Get-LatestChocoPackageVersion -TargetVersion $defaultVersion -PackageName "nodejs"
Choco-Install -PackageName nodejs -ArgumentList "--version=$versionToInstall"