summaryrefslogtreecommitdiff
path: root/plugins/yarn/_yarn
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/yarn/_yarn')
-rw-r--r--plugins/yarn/_yarn34
1 files changed, 29 insertions, 5 deletions
diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn
index 382f58a0a..70e783b86 100644
--- a/plugins/yarn/_yarn
+++ b/plugins/yarn/_yarn
@@ -71,7 +71,7 @@ _global_commands=(
'bin:Displays the location of the yarn bin folder'
'remove:Remove installed package from dependencies updating package.json'
'upgrade:Upgrades packages to their latest version based on the specified range'
- 'upgrade-interactive'
+ 'upgrade-interactive:Interactively upgrade packages'
)
_yarn_commands_scripts() {
@@ -81,9 +81,23 @@ _yarn_commands_scripts() {
}
_yarn_scripts() {
- local -a scripts
- 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'))
- _describe 'script' scripts
+ local -a commands binaries scripts
+ local -a scriptNames scriptCommands
+ local i runJSON
+
+ runJSON=$(yarn run --json 2>/dev/null)
+ # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
+ # pattern as a newline. See https://superuser.com/q/307165
+ binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
+ scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
+ scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{(.+")\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\'$'\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
+
+ for (( i=1; i <= $#scriptNames; i++ )); do
+ scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
+ done
+
+ commands=($scripts $binaries)
+ _describe 'command' commands
}
_yarn_global_commands() {
@@ -240,7 +254,8 @@ _yarn() {
run)
_arguments \
- '1: :_yarn_scripts'
+ '1: :_yarn_scripts' \
+ '*:: :_default'
;;
tag)
@@ -255,6 +270,11 @@ _yarn() {
'*:: :->team_args'
;;
+ upgrade-interactive)
+ _arguments \
+ '--latest:use the version tagged latest in the registry:'
+ ;;
+
version)
_arguments \
'--new-version:version:' \
@@ -266,6 +286,10 @@ _yarn() {
_arguments \
'1:query:_files'
;;
+
+ *)
+ _default
+ ;;
esac
;;
esac