[CmdletBinding()] param( [string]$Path = ".", [switch]$SkipAudit, [switch]$SkipOutdated ) $ErrorActionPreference = 'Stop' if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { throw "npm not found in PATH" } $root = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path if (-not (Test-Path -LiteralPath (Join-Path $root 'package.json') -PathType Leaf)) { throw "package.json not found in $root" } if (-not $SkipOutdated) { Write-Host "Outdated packages:" $raw = @(& npm --prefix $root outdated --json 2>$null) $code = $LASTEXITCODE $text = ($raw -join "`n").Trim() if ($text) { try { $data = $text | ConvertFrom-Json $rows = @() foreach ($property in $data.PSObject.Properties) { $value = $property.Value $rows += [pscustomobject]@{ Package = $property.Name Current = $value.current Wanted = $value.wanted Latest = $value.latest } } if ($rows.Count -gt 0) { $rows | Format-Table -AutoSize } else { Write-Host "No outdated packages." } } catch { Write-Host "Could not parse npm outdated output." } } elseif ($code -eq 0) { Write-Host "No outdated packages." } else { Write-Host "npm outdated failed with code $code." } Write-Host "" } if (-not $SkipAudit) { Write-Host "Vulnerability summary:" $rawAudit = @(& npm --prefix $root audit --json 2>$null) $textAudit = ($rawAudit -join "`n").Trim() if ($textAudit) { try { $audit = $textAudit | ConvertFrom-Json $vulnerabilities = $audit.metadata.vulnerabilities if ($vulnerabilities) { [pscustomobject]@{ Info = $vulnerabilities.info Low = $vulnerabilities.low Moderate = $vulnerabilities.moderate High = $vulnerabilities.high Critical = $vulnerabilities.critical } | Format-List } else { Write-Host "No vulnerability metadata." } } catch { Write-Host "Could not parse npm audit output. A lock file may be required." } } else { Write-Host "npm audit returned no data." } } Write-Host "No packages were installed or updated."