5dbb30342e1b7c4a04c3464bb16ffeb33abde139

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

feat(yarn): update completion from zsh-completions (73505e4)

Fixes #10195

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn
  2index 70e783b864e26d4f78e3c2594c2270a06a9b34d0..70ed559295a17ece2261218273d9e43ecbee0ede 100644
  3--- a/plugins/yarn/_yarn
  4+++ b/plugins/yarn/_yarn
  5@@ -32,15 +32,21 @@
  6 # -------
  7 #
  8 #  * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
  9+#  * Shohei YOSHIDA <syohex@gmail.com>
 10 #
 11 # ------------------------------------------------------------------------------
 12 
 13+declare -g _yarn_run_cwd
 14+
 15 _commands=(
 16   'access'
 17+  'audit:Checks for known security issues with the installed packages'
 18   'autoclean:Clean and remove unnecessary files from package dependencies'
 19   'cache:List or clean every cached package'
 20-  "check:Verify package dependencies agains yarn's lock file"
 21+  "check:Verify package dependencies against yarn's lock file"
 22   'config:Manages the yarn configuration files'
 23+  'create:Creates new projects from any create-* starter kits'
 24+  'exec'
 25   'generate-lock-entry:Generates a lock file entry'
 26   'global:Install packages globally on your operating system'
 27   'help:Show information about a command'
 28@@ -50,25 +56,30 @@ _commands=(
 29   'install:Install all the dependencies listed within package.json'
 30   'licenses:List licenses for installed packages'
 31   'link:Symlink a package folder during development'
 32-  'list:List installed packages'
 33   'login:Store registry username and email'
 34   'logout:Clear registry username and email'
 35+  'node:Runs Node with the same version that the one used by Yarn itself'
 36   'outdated:Check for outdated package dependencies'
 37   'owner:Manage package owners'
 38   'pack:Create a compressed gzip archive of package dependencies'
 39+  'policies:Defines project-wide policies for your project'
 40   'publish:Publish a package to the npm registry'
 41   'run:Run a defined package script'
 42   'tag:Add, remove, or list tags on a package'
 43   'team:Maintain team memberships'
 44   'unlink:Unlink a previously created symlink for a package'
 45+  'unplug:Temporarily copies a package outside of the global cache for debugging purposes'
 46   'version:Update the package version'
 47   'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
 48   'why:Show information about why a package is installed'
 49+  'workspace'
 50+  'workspaces:Show information about your workspaces'
 51 )
 52 
 53 _global_commands=(
 54   'add:Installs a package and any packages that it depends on'
 55   'bin:Displays the location of the yarn bin folder'
 56+  'list:List installed packages'
 57   'remove:Remove installed package from dependencies updating package.json'
 58   'upgrade:Upgrades packages to their latest version based on the specified range'
 59   'upgrade-interactive:Interactively upgrade packages'
 60@@ -76,7 +87,12 @@ _global_commands=(
 61 
 62 _yarn_commands_scripts() {
 63   local -a scripts
 64-  scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
 65+  if [[ -n $opt_args[--cwd] ]]; then
 66+    scripts=($(cd $opt_args[--cwd] && yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
 67+  else
 68+    scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
 69+  fi
 70+
 71   _describe 'command or script' _commands -- _global_commands -- scripts
 72 }
 73 
 74@@ -85,7 +101,11 @@ _yarn_scripts() {
 75   local -a scriptNames scriptCommands
 76   local i runJSON
 77 
 78-  runJSON=$(yarn run --json 2>/dev/null)
 79+  if [[ -n $_yarn_run_cwd ]]; then
 80+    runJSON=$(cd $_yarn_run_cwd && yarn run --json 2>/dev/null)
 81+  else
 82+    runJSON=$(yarn run --json 2>/dev/null)
 83+  fi
 84   # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
 85   # pattern as a newline. See https://superuser.com/q/307165
 86   binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
 87@@ -96,7 +116,7 @@ _yarn_scripts() {
 88     scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
 89   done
 90 
 91-  commands=($scripts $binaries)
 92+  commands=('env' $scripts $binaries)
 93   _describe 'command' commands
 94 }
 95 
 96@@ -110,6 +130,17 @@ _yarn_commands() {
 97   _describe 'command' _commands -- _global_commands
 98 }
 99 
100+_yarn_add_files() {
101+  if compset -P "(file|link):"; then
102+    _files
103+  fi
104+}