-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy path_ListOutdatedDependencies.ps1
More file actions
143 lines (122 loc) · 5.52 KB
/
Copy path_ListOutdatedDependencies.ps1
File metadata and controls
143 lines (122 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#Requires -Version 7.0
<#
.SYNOPSIS
Lists all outdated NuGet and npm packages for the solution, across every supported target framework.
.DESCRIPTION
Runs `dotnet outdated` for the solution (projects already multi-target
net8.0/net9.0/net10.0 via <TargetFrameworks>) and groups the results by
$(TargetFramework).
Also lists outdated npm packages (via npm-check-updates) for the Core.Assets project,
without changing any package.json or lock file.
.NOTES
Requires the dotnet-outdated-tool and npm-check-updates:
dotnet tool install --global dotnet-outdated-tool --add-source https://api.nuget.org/v3/index.json
npm install --global npm-check-updates --registry https://registry.npmjs.org/
#>
$ErrorActionPreference = 'Stop'
$repoRoot = $PSScriptRoot
$slnPath = Join-Path $repoRoot 'Microsoft.FluentUI.sln'
$npmProjects = @('src/Core.Assets')
# Key = "TargetFramework|Name|OldVersion|NewVersion", used to avoid duplicate rows across projects.
$updates = [ordered]@{}
Write-Host "`n=== Checking outdated NuGet packages ===" -ForegroundColor Cyan
$reportPath = Join-Path $repoRoot 'outdated.json'
if (Test-Path $reportPath) {
Remove-Item $reportPath -Force
}
try {
dotnet outdated $slnPath --version-lock Major --pre-release Never -o $reportPath -of json
if (-not (Test-Path $reportPath)) {
throw "No report generated (dotnet-outdated-tool might not be installed)."
}
$report = Get-Content -Path $reportPath -Raw | ConvertFrom-Json
foreach ($project in $report.Projects) {
foreach ($targetFramework in $project.TargetFrameworks) {
foreach ($dependency in $targetFramework.Dependencies) {
$key = "$($targetFramework.Name)|$($dependency.Name)|$($dependency.ResolvedVersion)|$($dependency.LatestVersion)"
if (-not $updates.Contains($key)) {
$updates[$key] = [pscustomobject]@{
TargetFramework = $targetFramework.Name
Package = $dependency.Name
OldVersion = $dependency.ResolvedVersion
NewVersion = $dependency.LatestVersion
}
}
}
}
}
}
finally {
if (Test-Path $reportPath) {
Remove-Item $reportPath -Force
}
}
$targetFrameworks = $updates.Values | Select-Object -ExpandProperty TargetFramework -Unique | Sort-Object
$summary = $updates.Values | Sort-Object TargetFramework, Package, OldVersion
Write-Host "`n=== Summary of outdated NuGet packages (grouped by target framework) ===" -ForegroundColor Green
foreach ($targetFramework in $targetFrameworks) {
$group = $summary | Where-Object { $_.TargetFramework -eq $targetFramework }
if ($group) {
Write-Host "`n-- $targetFramework --" -ForegroundColor Yellow
$group | Select-Object Package, OldVersion, NewVersion | Format-Table -AutoSize
}
}
# Key = "Project|Name|OldVersion|NewVersion", used to avoid duplicate rows.
$npmUpdates = [ordered]@{}
foreach ($npmProject in $npmProjects) {
Write-Host "`n=== Checking outdated npm packages for $npmProject ===" -ForegroundColor Cyan
$packageFilePath = Join-Path $repoRoot "$npmProject/package.json"
try {
$jsonOutput = ncu --packageFile $packageFilePath --jsonUpgraded 2>&1 | Out-String
$upgraded = $jsonOutput | ConvertFrom-Json
}
catch {
Write-Warning "ncu failed for ${npmProject}: $_"
continue
}
$currentPackageJson = Get-Content -Path $packageFilePath -Raw | ConvertFrom-Json
foreach ($property in $upgraded.PSObject.Properties) {
$packageName = $property.Name
$newVersion = $property.Value -replace '^[\^~]', ''
$oldVersion = $null
foreach ($section in @('dependencies', 'devDependencies')) {
if ($currentPackageJson.$section -and $currentPackageJson.$section.PSObject.Properties[$packageName]) {
$oldVersion = $currentPackageJson.$section.$packageName -replace '^[\^~]', ''
break
}
}
$key = "$npmProject|$packageName|$oldVersion|$newVersion"
if (-not $npmUpdates.Contains($key)) {
$npmUpdates[$key] = [pscustomobject]@{
Project = $npmProject
Package = $packageName
OldVersion = $oldVersion
NewVersion = $newVersion
}
}
}
}
if ($npmUpdates.Count -gt 0) {
Write-Host "`n=== Summary of outdated npm packages (grouped by project) ===" -ForegroundColor Green
foreach ($npmProject in $npmProjects) {
$group = $npmUpdates.Values | Where-Object { $_.Project -eq $npmProject } | Sort-Object Package
if ($group) {
Write-Host "`n-- $npmProject --" -ForegroundColor Yellow
$group | Select-Object Package, OldVersion, NewVersion | Format-Table -AutoSize
}
}
}
Write-Host "`n=== Next steps: apply the updates manually ===" -ForegroundColor Green
Write-Host @'
NuGet packages:
1. Update the versions listed above in Directory.Packages.props.
2. Review shared version properties (RuntimeVersion*, AspNetCoreVersion*, EfCoreVersion*) so packages
that reference them stay aligned for each target framework.
3. Restore and build the solution:
dotnet restore ./Microsoft.FluentUI.sln
dotnet build ./Microsoft.FluentUI.sln --configuration Release
npm packages:
1. Update the versions listed above in src/Core.Assets/package.json.
2. Reinstall to regenerate the lock files:
npm install --prefix ./src/Core.Assets
'@