Created
November 5, 2020 20:22
-
-
Save andria-dev/c5fbdb7dc616d468245c7ed035c4527b to your computer and use it in GitHub Desktop.
A Powershell function to get all of the node dependencies defined in a JSON file that match a pattern.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: yarn remove $(Get-NodePackages -Pattern 'gatsby') | |
function Get-NodePackages { | |
param ( | |
$Pattern = '.*', | |
$PackagePath = '.\package.json' | |
) | |
$package = ConvertFrom-Json $(gc $PackagePath | Out-String) | |
$dependencies = $package.dependencies ?? @() | |
$devDependencies = $package.devDependencies ?? @() | |
$dependencyMembers = $(Get-Member -InputObject $dependencies) + $(Get-Member -InputObject $devDependencies) | |
return $( | |
$dependencyMembers | Where-Object { | |
$_.MemberType -eq 'NoteProperty' -and $_.Name -match $Pattern | |
} | |
).Name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment