yarn.crescendo.psm1
# Module created by Microsoft.PowerShell.Crescendo class PowerShellCustomFunctionAttribute : System.Attribute { [bool]$RequiresElevation [string]$Source PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } PowerShellCustomFunctionAttribute([bool]$rElevation) { $this.RequiresElevation = $rElevation $this.Source = "Microsoft.PowerShell.Crescendo" } } function Add-YarnPackages { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(Mandatory=$true)] [String[]]$Packages, [Parameter()] [Switch]$Dev, [Parameter()] [Switch]$Peer, [Parameter()] [Switch]$Optional, [Parameter()] [Switch]$Exact, [Parameter()] [Switch]$Tilde, [Parameter()] [Switch]$IgnoreWorkspaceRootCheck, [Parameter()] [Switch]$Audit ) BEGIN { $__PARAMETERMAP = @{ Packages = @{ OriginalName = 'add' OriginalPosition = '0' Position = '2147483647' ParameterType = 'String[]' ApplyToExecutable = $False NoGap = $False } Dev = @{ OriginalName = '--dev' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Peer = @{ OriginalName = '--peer' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Optional = @{ OriginalName = '--optional' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Exact = @{ OriginalName = '--exact' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Tilde = @{ OriginalName = '--tilde' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } IgnoreWorkspaceRootCheck = @{ OriginalName = '--ignore-workspace-root-check' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Audit = @{ OriginalName = '--audit' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message yarn $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("yarn $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "yarn")) { throw "Cannot find executable 'yarn'" } if ( $__handlerInfo.StreamOutput ) { & "yarn" $__commandArgs | & $__handler } else { $result = & "yarn" $__commandArgs & $__handler $result } } } # end PROCESS <# .DESCRIPTION In general, a package is simply a folder with code and a package.json file that describes the contents. When you want to use another package, you first need to add it to your dependencies. This means running yarn add [package-name] to install it into your project. This will also update your package.json and your yarn.lock so that other developers working on the project will get the same dependencies as you when they run yarn or yarn install. Most packages will be installed from the npm registry and referred to by simply their package name. For example, yarn add react will install the react package from the npm registry. You can specify versions using one of these: Add-YarnPackages package-name installs the “latest” version of the package. Add-YarnPackages package-name@1.2.3 installs a specific version of a package from the registry. Add-YarnPackages package-name@tag installs a specific “tag” (e.g. beta, next, or latest). You can also specify packages from different locations: Add-YarnPackages package-name installs the package from the npm registry unless you have specified another one in your package.json. Add-YarnPackages file:/path/to/local/folder installs a package that is on your local file system. This is useful to test out other packages of yours that haven’t been published to the registry. Add-YarnPackages file:/path/to/local/tarball.tgz installs a package from a gzipped tarball which could be used to share a package before publishing it. Add-YarnPackages link:/path/to/local/folder installs a symlink to a package that is on your local file system. This is useful to develop related packages in monorepo environments. Add-YarnPackages <git remote url> installs a package from a remote git repository. Add-YarnPackages <git remote url>#<branch/commit/tag> installs a package from a remote git repository at specific git branch, git commit or git tag. Add-YarnPackages https://my-project.org/package.tgz installs a package from a remote gzipped tarball. .PARAMETER Packages This will install one or more packages in your dependencies. .PARAMETER Dev Using -Dev will install one or more packages in your devDependencies. .PARAMETER Peer Using -Peer will install one or more packages in your peerDependencies. .PARAMETER Optional Using -Optional will install one or more packages in your optionalDependencies. .PARAMETER Exact Using -Exact installs the packages as exact versions. The default is to use the most recent release with the same major version. For example, yarn add foo@1.2.3 would accept version 1.9.1, but yarn add foo@1.2.3 -Exact would only accept version 1.2.3. .PARAMETER Tilde Using -Tilde installs the most recent release of the packages that have the same minor version. The default is to use the most recent release with the same major version. For example, yarn add foo@1.2.3 -Tidle would accept 1.2.9 but not 1.3.0. .PARAMETER IgnoreWorkspaceRootCheck Using -IgnoreWorkspaceRootCheck allows a package to be installed at the workspaces root. This tends not to be desired behaviour, as dependencies are generally expected to be part of a workspace. For example yarn add lerna -IgnoreWorkspaceRootCheck -Dev at the workspaces root would allow lerna to be used within the scripts of the root package.json. .PARAMETER Audit Checks for known security issues with the installed packages. A count of found issues will be added to the output. Use the yarn audit command for additional details. #> } function Install-YarnPackages { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter()] [Switch]$CheckFiles, [Parameter()] [Switch]$Flat, [Parameter()] [Switch]$Force, [Parameter()] [Switch]$IgnoreScripts, [Parameter()] [String]$ModulesFolder, [Parameter()] [Switch]$NoLockfile, [Parameter()] [Switch]$Production, [Parameter()] [Switch]$PureLockfile, [Parameter()] [Switch]$Focus, [Parameter()] [Switch]$FrozenLockfile, [Parameter()] [Switch]$Silent, [Parameter()] [Switch]$IgnoreEngines, [Parameter()] [Switch]$IgnoreOptional, [Parameter()] [Switch]$Offline, [Parameter()] [Switch]$NonInteractive, [Parameter()] [Switch]$UpdateChecksums, [Parameter()] [Switch]$Audit, [Parameter()] [Switch]$NoBinLinks, [Parameter()] [Switch]$LinkDuplicates ) BEGIN { $__PARAMETERMAP = @{ CheckFiles = @{ OriginalName = '--check-files' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Flat = @{ OriginalName = '--flat' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Force = @{ OriginalName = '--force' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } IgnoreScripts = @{ OriginalName = '--ignore-scripts' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } ModulesFolder = @{ OriginalName = '--modules-folder' OriginalPosition = '0' Position = '2147483647' ParameterType = 'String' ApplyToExecutable = $False NoGap = $False } NoLockfile = @{ OriginalName = '--no-lockfile' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Production = @{ OriginalName = '--production' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } PureLockfile = @{ OriginalName = '--pure-lockfile' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Focus = @{ OriginalName = '--focus' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } FrozenLockfile = @{ OriginalName = '--frozen-lockfile' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Silent = @{ OriginalName = '--silent' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } IgnoreEngines = @{ OriginalName = '--ignore-engines' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } IgnoreOptional = @{ OriginalName = '--ignore-optional' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Offline = @{ OriginalName = '--offline' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } NonInteractive = @{ OriginalName = '--non-interactive' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } UpdateChecksums = @{ OriginalName = '--update-checksums' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } Audit = @{ OriginalName = '--audit' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } NoBinLinks = @{ OriginalName = '--no-bin-links' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } LinkDuplicates = @{ OriginalName = '--link-duplicates' OriginalPosition = '0' Position = '2147483647' ParameterType = 'Switch' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'install' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message yarn $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("yarn $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "yarn")) { throw "Cannot find executable 'yarn'" } if ( $__handlerInfo.StreamOutput ) { & "yarn" $__commandArgs | & $__handler } else { $result = & "yarn" $__commandArgs & $__handler $result } } } # end PROCESS <# .DESCRIPTION Install all the dependencies listed within package.json in the local node_modules folder. The yarn.lock file is utilized as follows: If yarn.lock is present and is enough to satisfy all the dependencies listed in package.json, the exact versions recorded in yarn.lock are installed, and yarn.lock will be unchanged. Yarn will not check for newer versions. If yarn.lock is absent, or is not enough to satisfy all the dependencies listed in package.json (for example, if you manually add a dependency to package.json), Yarn looks for the newest versions available that satisfy the constraints in package.json. The results are written to yarn.lock. If you want to ensure yarn.lock is not updated, use -FrozenLockfile. .PARAMETER CheckFiles Verifies that already installed files in node_modules did not get removed. .PARAMETER Flat Install all the dependencies, but only allow one version for each package. On the first run this will prompt you to choose a single version for each package that is depended on at multiple version ranges. These will be added to your package.json under a resolutions field. .PARAMETER Force This refetches all packages, even ones that were previously installed. .PARAMETER IgnoreScripts Do not execute any scripts defined in the project package.json and its dependencies. .PARAMETER ModulesFolder Specifies an alternate location for the node_modules directory, instead of the default ./node_modules. .PARAMETER NoLockfile Don't read or generate a yarn.lock lockfile. .PARAMETER Production Yarn will not install any package listed in devDependencies if the NODE_ENV environment variable is set to production. Use this flag to instruct Yarn to ignore NODE_ENV and take its production-or-not status from this flag instead. .PARAMETER PureLockfile Don't generate a yarn.lock lockfile. .PARAMETER Focus Shallowly installs a package's sibling workspace dependencies underneath its node_modules folder. This allows you to run that workspace without building the other workspaces it depends on. Must be run inside an individual workspace in a workspaces project. Can not be run in a non-workspaces project or at the root of a workspaces project. .PARAMETER FrozenLockfile Don't generate a yarn.lock lockfile and fail if an update is needed. .PARAMETER Silent Run yarn install without printing installation log. .PARAMETER IgnoreEngines Ignore engines check. .PARAMETER IgnoreOptional Don't install optional dependencies. .PARAMETER Offline Run yarn install in offline mode. .PARAMETER NonInteractive Disable interactive prompts, like when there's an invalid version of a dependency. .PARAMETER UpdateChecksums Update checksums in the yarn.lock lockfile if there's a mismatch between them and their package's checksum. .PARAMETER Audit Checks for known security issues with the installed packages. A count of found issues will be added to the output. Use the yarn audit command for additional details. Unlike npm, which automatically runs an audit on every install, yarn will only do so when requested. (This may change in a later update as the feature is proven to be stable.) .PARAMETER NoBinLinks Prevent yarn from creating symlinks for any binaries the package might contain. .PARAMETER LinkDuplicates Create hardlinks to the repeated modules in node_modules. #> } function Invoke-YarnRun { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [ArgumentCompleter( { param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters ) # Write your code here return & $(Join-Path $PSScriptRoot 'Helpers/Get-Commands.ps1') })] [Parameter(Mandatory=$true)] [String]$Command ) BEGIN { $__PARAMETERMAP = @{ Command = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'String' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'run' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message yarn $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("yarn $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "yarn")) { throw "Cannot find executable 'yarn'" } if ( $__handlerInfo.StreamOutput ) { & "yarn" $__commandArgs | & $__handler } else { $result = & "yarn" $__commandArgs & $__handler $result } } } # end PROCESS <# .SYNOPSIS yarn install v1.22.19 info No lockfile found. [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Saved lockfile. Done in 0.18s. .DESCRIPTION See help for yarn .PARAMETER Command #> } function Invoke-YarnWhy { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [ArgumentCompleter( { param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters ) # Write your code here return & $(Join-Path $PSScriptRoot 'Helpers/Get-Packages.ps1') -WordToComplete $WordToComplete })] [Parameter(Mandatory=$true)] [string]$Query ) BEGIN { $__PARAMETERMAP = @{ Query = @{ OriginalName = 'why' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message yarn $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("yarn $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "yarn")) { throw "Cannot find executable 'yarn'" } if ( $__handlerInfo.StreamOutput ) { & "yarn" $__commandArgs | & $__handler } else { $result = & "yarn" $__commandArgs & $__handler $result } } } # end PROCESS <# .DESCRIPTION This command will identify why a package has been installed, detailing which other packages depend upon it, for example, or whether it was explicitly marked as a dependency in the package.json manifest. .PARAMETER Query The mandatory query argument for yarn why can be any of: a package name (as in the above example) a package folder; eg: yarn why node_modules/once a file within a package folder; eg: yarn why node_modules/once/once.js The file locations can also be absolute. #> } function Remove-YarnPackages { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [ArgumentCompleter( { param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters ) # Write your code here return & $(Join-Path $PSScriptRoot 'Helpers/Get-Packages.ps1') -WordToComplete $WordToComplete })] [Parameter(Mandatory=$true)] [String[]]$Packages ) BEGIN { $__PARAMETERMAP = @{ Packages = @{ OriginalName = 'remove' OriginalPosition = '0' Position = '2147483647' ParameterType = 'String[]' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message yarn $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("yarn $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "yarn")) { throw "Cannot find executable 'yarn'" } if ( $__handlerInfo.StreamOutput ) { & "yarn" $__commandArgs | & $__handler } else { $result = & "yarn" $__commandArgs & $__handler $result } } } # end PROCESS <# .DESCRIPTION Running yarn remove foo will remove the package named foo from your direct dependencies updating your package.json and yarn.lock files in the process. Other developers working on the project can run yarn install to sync their own node_modules directories with the updated set of dependencies. When you remove a package, it is removed from all types of dependencies: dependencies, devDependencies, etc. .PARAMETER Packages The packages to remove. #> } |