Don't use yarn run --json for newer yarn
This commit is contained in:
parent
2f54f2b212
commit
839df66922
29
src/_yarn
29
src/_yarn
|
@ -86,31 +86,32 @@ _global_commands=(
|
|||
)
|
||||
|
||||
_yarn_commands_scripts() {
|
||||
local -a scripts
|
||||
local -a scripts binaries
|
||||
|
||||
if [[ -n $opt_args[--cwd] ]]; then
|
||||
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'))
|
||||
scripts=($(cd $opt_args[--cwd] && cat package.json | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); say for sort keys %{$r->{scripts}}'))
|
||||
binaries=($(cd $opt_args[--cwd] && echo node_modules/.bin/*(x:t)))
|
||||
else
|
||||
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'))
|
||||
scripts=($(cat package.json | perl -0777 -MJSON::PP -n -E '%r=decode_json($_); say for sort keys %{$r->{scripts}}'))
|
||||
binaries=($(echo node_modules/.bin/*(x:t)))
|
||||
fi
|
||||
|
||||
_describe 'command or script' _commands -- _global_commands -- scripts
|
||||
_describe 'command or script' _commands -- _global_commands -- scripts -- binaries
|
||||
}
|
||||
|
||||
_yarn_scripts() {
|
||||
local -a commands binaries scripts
|
||||
local -a scriptNames scriptCommands
|
||||
local i runJSON
|
||||
local -a binaries scriptNames scriptCommands scripts
|
||||
local -a commands
|
||||
|
||||
if [[ -n $_yarn_run_cwd ]]; then
|
||||
runJSON=$(cd $_yarn_run_cwd && yarn run --json 2>/dev/null)
|
||||
scriptNames=($(cd $opt_args[--cwd] && cat package.json | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf qq($_:$r{$_}\n) for sort keys %r'))
|
||||
scriptCommands=("${(@f)$(cd $opt_args[--cwd] && cat package.json | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$r{$_}\n" for sort keys %r')}")
|
||||
binaries=($(cd $opt_args[--cwd] && echo node_modules/.bin/*(x:t)))
|
||||
else
|
||||
runJSON=$(yarn run --json 2>/dev/null)
|
||||
scriptNames=($(cat package.json | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$_\n" for sort keys %r'))
|
||||
scriptCommands=("${(@f)$(cat package.json | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$r{$_}\n" for sort keys %r')}")
|
||||
binaries=($(echo node_modules/.bin/*(x:t)))
|
||||
fi
|
||||
# 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]}")
|
||||
|
|
Loading…
Reference in New Issue