#compdef yarn # ------------------------------------------------------------------------------ # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the zsh-users nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------ # Description # ----------- # # Completion script for yarn 4.11.0 (https://yarnpkg.com/) # # ------------------------------------------------------------------------------ # Authors # ------- # # * Massimiliano Torromeo # * Shohei YOSHIDA # # ------------------------------------------------------------------------------ _yarn() { typeset -A opt_args local context state line local curcontext="$curcontext" local ret=1 _arguments -C \ '(- *)'{-h,--help}'[show help message and exit]' \ '(- *)'{-v,--version}'[show version number and exit]' \ '1: :_yarn_subcommands' \ '*::arg:->args' \ && ret=0 case "$state" in (args) case $words[1] in (add) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '(-F --fixed)'{-F,--fixed}'[store dependency tags as-is instead of resolving them]' \ '(-E --exact)'{-E,--exact}'[do not use any semver modifier on the resolved range]' \ '(-T --tilde)'{-T,--tilde}'[use the "~" semver modifier on the resolved range]' \ '(-C --caret)'{-C,--caret}'[use the "^" semver modifier on the resolved range]' \ '(-D --dev)'{-D,--dev}'[add a package as a dev dependency]' \ '(-P --peer)'{-P,--peer}'[add a package as a peer dependency]' \ '(-O --optional)'{-O,--optional}'[add/upgrade a package to an optional regular/peer dependency]' \ '--prefer-dev[add/upgrade a package to a dev dependency]' \ '(-i --interactive)'{-i,--interactive}'[reuse the specified package from other workspaces in the project]' \ '--cached[reuse the highest version already used somewhere within the project]' \ '--mode[change what artifacts installs generate]:mode' \ '*::package:_files' \ && ret=0 ;; (bin) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-v --verbose)'{-v,--verbose}'[print both the binary name and the locator of the package]' \ '--json[format the output as an NDJSON stream]' \ '*::package' \ && ret=0 ;; (cache) _yarn_cache && ret=0 ;; (config) _yarn_config && ret=0 ;; (constraints) _yarn_constraints && ret=0 ;; (dedupe) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-s --strategy)'{-s,--strategy}'[strategy to use when dedupe dependencies]:strategy:(highest)' \ '(-c --check)'{-c,--check}'[exit with exit code 1 when duplicates are found]' \ '--json[format the output as an NDJSON stream]' \ '--mode[change what artifacts installs generate]:mode:(skip-build update-lockfile)' \ '*::package:_files' \ && ret=0 ;; (dlx) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ \*{-p,--package}'[package to install before the running the command]:package' \ '(-q --quiet)'{-q,--quiet}'[only report critical errors instead of printing the full install logs]' \ '*: :_normal' \ && ret=0 ;; (exec) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '*: :_normal' \ && ret=0 ;; (explain) _yarn_explain && ret=0 ;; (info) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[print versions of a package from the whole project]' \ '(-R --recursive)'{-R,--recursive}'[print information for all packages, including transitive dependencies]' \ '(-X --extra)'{-X,--extra}'[an array of requests of extra data provided by plugins]:extra_data' \ '--cache[print information about the cache entry of a package]' \ '--dependents[print all dependents for each matching package]' \ '--manifest[print data obtained by looking at the package archive]' \ '--name-only[only print the name for the matching packages]' \ '--virtuals[print each instance of the virtual packages]' \ '--json[format the output as an NDJSON stream]' \ '*::package:_files' \ && ret=0 ;; (init) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-p --private)'{-p,--private}'[initialize a private package]' \ '(-w --workspace)'{-w,--workspace}'[initialize a workspace root with a packages/directory]' \ '(-i --install)'{-i,--install}'[initialize package with a specific bundle]' \ '(-n --name)'{-n,--name}'[initialize a package with the given name]:name' \ '*::initializer' \ && ret=0 ;; (install) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '--immutable[abort if the lockfile was to be modified]' \ '--immutable-cache[abort if the cache folder was to be modified]' \ '--refresh-lockfile[refresh the package metadata stored in the lockfile]' \ '--check-cache[always refetch the packages and ensure that their checksums are consistent]' \ '--check-resolutions[valudata that the package resolutions are coherent]' \ '--inline-builds[verbosely print the output of the build steps of dependencies]' \ '--mode[change what artifacts installs generate]:mode:(skip-build update-lockfile)' \ && ret=0 ;; (link) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[link all workspaces belonging to target projects to current one]' \ '(-p --private)'{-p,--private}'[also link private workspaces belonging to target projects to current one]' \ '(-r --relative)'{-r,--relative}'[link workspaces using relative paths instead of absolute paths]' \ '*:workspace:_files -/' \ && ret=0 ;; (node) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '*:node:_node' \ && ret=0 ;; (npm) _yarn_npm && ret=0 ;; (pack) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--install-if-needed[run a preliminary "yarn install" if the package contains build scripts]' \ '(-n --dry-run)'{-n,--dry-run}'[print the file paths without actually generating package archive]' \ '--json[format the output as an NDJSON stream]' \ '(-o --out)'{-o,--out}'[create the archive at the specified path]:path:_files' \ && ret=0 ;; (patch) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-u --update)'{-u,--update}'[reapply local patches that already apply to this package]' \ '--json[format the output as an NDJSON stream]' \ && ret=0 ;; (patch-commit) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-s --save)'{-s,--save}'[add the patch to your resoltion entries]' \ '*:dir:_files -/' \ && ret=0 ;; (plugin) _yarn_plugin && ret=0 ;; (rebuild) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ && ret=0 ;; (remove) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[apply operation to all workspaces from the current project]' \ '--mode[change what artifacts installs generate]:mode:(skip-build update-lockfile)' \ '*:package' \ && ret=0 ;; (run) _yarn_run && ret=0 ;; (search) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ && ret=0 ;; (set) _yarn_set && ret=0 ;; (stage) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-c --commit)'{-c,--commit}'[commit the staged files]' \ '(-r --reset)'{-r,--reset}'[remove all files from the staging area]' \ '(-n --dry-run)'{-n,--dry-run}'[print the commit message and modified files without staging/committing]' \ && ret=0 ;; (unlink) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[unlink all workspaces belonging to target project from current one]' \ '*:workspace:_files -/' \ && ret=0 ;; (unplug) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[unplug direct dependencies from the entire project]' \ '(-R --recursive)'{-R,--recursive}'[unplug both direct and transitive dependencies]' \ '--json[format the output as an NDJSON stream]' \ '*:package' \ && ret=0 ;; (up) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-i --interactive)'{-i,--interactive}'[offer various choices, depending on the detached upgrade paths]' \ '(-F --fixed)'{-F,--fixed}'[store dependency tags as-is instead of resolving them]' \ '(-E --exact)'{-E,--exact}'[do not use any semver modifier on the resolved range]' \ '(-T --tilde)'{-T,--tilde}'[use the "~" semver modifier on the resolved range]' \ '(-C --caret)'{-C,--caret}'[use the "^" semver modifier on the resolved range]' \ '(-R --recursive)'{-R,--recursive}'[resolve again ALL resolutions for those packages]' \ '--mode[change what artifacts installs generate]:mode:(skip-build update-lockfile)' \ '*:package' \ && ret=0 ;; (upgrade-interactive) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ && ret=0 ;; (version) _yarn_version && ret=0 ;; (why) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-R --recursive)'{-R,--recursive}'[list for each workspace]' \ '--json[format the output as an NDJSON stream]' \ '--peers[also print the peer dependencies that match the specified name]' \ '*:package' \ && ret=0 ;; (workspace) _yarn_workspace && ret=0 ;; (workspaces) _yarn_workspaces && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_subcommands] )) || _yarn_subcommands() { local -a commands=( 'add:add dependencies to the project' 'bin:get the path to a binary script' 'cache:cache related commands' 'config:read or change current configuration' 'dedupe:deduplicate dependencies with overlapping ranges' 'dlx:run a package in a temporary environment' 'exec:execute a shell script' 'explain:explain command' 'info:see information related to packages' 'init:create a new package' 'install:install the project dependencies' 'link:connect the local project to another one' 'node:run node with the hook already setup' 'npm:npm related commands' 'pack:generate a tarball from the active workspace' 'patch:prepare a package for patching' 'patch-commit:generate a patch out of a directory' "rebuild:rebuild the project's native packages" 'remove:remove dependencies from the project' 'run:run a script defined in the package.json' 'set:enforce a package resolution' 'stage:add all yarn files to your vcs' 'unlink:disconnect the local project from another one' 'unplug:force the unpacking of a list of packages' 'up:upgrade dependencies across the project' 'why:display the reason why a package is needed' 'constraints:check that the project constraints are met' 'search:open the search interface' 'upgrade-interactive:open the upgrade interface' 'plugin:plugin related commands' 'version:version relarelated commands' 'workspace:workspace related commands' 'workspaces:command for workspaces' ) _describe -t commands 'command' commands "$@" } (( $+functions[_yarn_cache] )) || _yarn_cache() { local ret=1 _arguments -C \ '(- *)'{-h,--help}'[Print this usage information]' \ '1:subcmd:(clean)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (clean) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--mirror[remove the global cache files instead of the local cache files]' \ '--all[remove both the global cache files and the local cache files of the current project]' ;; esac ;; esac return ret } (( $+functions[_yarn_config] )) || _yarn_config() { local ret=1 _arguments -C \ '(- *)'{-h,--help}'[Print this usage information]' \ '1:subcmd:(get set unset)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (get) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--why[print the explanation for a why a setting has its value]' \ '--json[format the output as an NDJSON stream]' \ '--no-redacted[do not redact secrets(such as tokens) from the output]' \ '1:name' \ && ret=0 ;; (set) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[set complete configuration settins to JSON values]' \ '(-H --home)'{-H,--home}'[update the home configuration instead of the project one]' \ '1:name' \ '2:value' \ && ret=0 ;; (unset) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-H --home)'{-H,--home}'[update the home configuration instead of the project one]' \ '1:name' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_constraints] )) || _yarn_constraints() { local ret=1 _arguments -C \ '(- *)'{-h,--help}'[Print this usage information]' \ '(-f --fix)'{-f,--fix}'[attempt to automatically fix unambiguous issues]' \ '--json[format the output as an NDJSON stream]' \ '1:subcmd:(query source)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (query) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '1:query' \ && ret=0 ;; (source) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-v --verbose)'{-v,--verbose}'[print the fact database automatically compiled from workspace manifests]' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_explain] )) || _yarn_explain() { local ret=1 local -a error_codes=(peer-requirements $(yarn explain 2>/dev/null | awk -F'[ :]' '{ print $2 }' 2>/dev/null)) _arguments -C \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '1:subcmd:(($error_codes))' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (peer-requirements) _arguments \ '1:hash' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_npm] )) || _yarn_npm() { local ret=1 _arguments -C \ '1:subcmd:_yarn_npm_subcommands' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (audit) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[audit dependencies from all workspaces]' \ '(-R --recursive)'{-R,--recursive}'[audit transitive dependencies as well]' \ '--environment[which environment to cover]:environment:(production)' \ '--json[format the output as an NDJSON stream]' \ '--no-deprecations[do not warn about deprecated packages]' \ '--severity[minimal severity requested for packages to be displayed]:severity:(info low moderate high critical)' \ '*--exclude[array of glob patterns of packages to exclude from audit]:pattern' \ '*--ignore[array of glob patterns of advisory ID to ignore in the audit report]:pattern' \ && ret=0 ;; (info) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-f --fields)'{-f,--fields}'[a comma-separated list of manifest fields to be displayed]:fields:_yarn_manifest_fields' \ '--json[format the output as an NDJSON stream]' \ '*:package' \ && ret=0 ;; (login) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-S --scope)'{-S,--scope}'[login to the registry configured for a given scope]:scope' \ '--publish[login to the publish registry]' \ '--always-auth[set the npmAlwaysAuth configuration]' \ && ret=0 ;; (logout) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-S --scope)'{-S,--scope}'[logout of the registry configured for a given scope]:scope' \ '--publish[logout to the publish registry]' \ '(-A --all)'{-A,--all}'[logout of all registries]' \ && ret=0 ;; (publish) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--access[access for the published package]:access:(public restricted)' \ '--tag[tag on the registry that the package should be attached to]' \ '--tolerate-republish[warn and exit when republishing an already existing version of a package]' \ '--otp[OTP token to use with the command]:token' \ '--provenance[generate provenance for the package]' \ '(-n --dry-run)'{-n,--dry-run}'[show what would be published without actually publishing]' \ '--json[output the result in JSON format]' \ && ret=0 ;; (tag) _yarn_npm_tag && ret=0 ;; (whoami) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-S --scope)'{-S,--scope}'[print username for the registry configured for a given scope]:scope' \ '--publish[print username for the publish registry]' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_npm_subcommands] )) || _yarn_npm_subcommands() { local -a commands=( 'audit:perform a vulnerability audit against the installed packages' 'info:show information about a package' 'login:store new login info to access the npm registry' 'logout:logout of the npm registry' 'publish:publish the active workspace to the npm registry' 'tag:tag operations' 'whoami:display the name of the authenticated user' ) _describe -t commands 'command' commands "$@" } (( $+functions[_yarn_npm_tag] )) || _yarn_npm_tag() { local ret=1 _arguments -C \ '1:subcmd:(add list remove)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (add|remove) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '1:package' \ '2:tag' \ && ret=0 ;; (list) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '1:package' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_plugin] )) || _yarn_plugin() { local ret=1 _arguments -C \ '(- *)'{-h,--help}'[show help message and exit]' \ '1:subcmd:_yarn_plugin_subcommands' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (check|runtime|list) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ && ret=0 ;; (import) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--checksum[whether to care if this plugin is modified]' \ '*:package' \ && ret=0; ;; (remove) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '1:name' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_plugin_subcommands] )) || _yarn_plugin_subcommands() { local -a commands=( 'check:find all third-party plugins that differ from their own spec' 'import:download plugin' 'list:list the available official plugins' 'remove:remove a plugin' 'runtime:list the active plugins' ) _describe -t commands 'command' commands "$@" } (( $+functions[_yarn_run] )) || _yarn_run() { local ret=1 _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '--inspect[activate inspector]' \ '--inspect-brk[activate inspector and break at start]' \ '(-T --top-level)'{-T,--top-level}'[check the root workspace for scripts and/or binaries]' \ '(-B --binaries-only)'{-B,--binaries-only}'[ignore any user defined scripts and only check binaries]' \ '*--require[preload given module]:module' \ '1: :_yarn_scripts' \ '*:: :_files' \ && ret=0 return ret } (( $+functions[_yarn_set] )) || _yarn_set() { local ret=1 _arguments -C \ '(- *)'{-h,--help}'[show help message and exit]' \ '1:subcmd:(resolution version)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (resolution) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ && ret=0 ;; (version) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--yarn-path[set the yarnPath setting]:path:_files' \ '--only-if-needed[only lock the Yarn version if it is not already locked]' \ '1:version: _alternative "type\:type\:(latest berry stable canary classic self)" "file\:file\:_files"' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_version] )) || _yarn_version() { local ret=1 _arguments -C -s \ '(- *)'{-h,--help}'[Print this usage information]' \ '(-d --deferred)'{-d,--deferred}'[prepare the version to be bumped during the next release cycle]' \ '(-i --immediate)'{-i,--immediate}'[bump the version immediately]' \ '1:subcmd:(apply check)' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (apply) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--all[apply the deferred version changes on all workspaces]' \ '--dry-run[print versions without actually generating the package archive]' \ '--prerelease[add a prerelease identifier to new versions]' \ '--exact[use the exact version of each package, removes any range]' \ '(-R --recursive)'{-R,--recursive}'[release the transitive workspaces as well]' \ '--json[format the output as an NDJSON stream]' \ && ret=0 ;; (check) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-i --interactive)'{-i,--interactive}'[open an interactive interface used to set version bumps]' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_workspace] )) || _yarn_workspace() { local package_json=$(_yarn_package_json_path) local package_dir=$(dirname $package_json) local -a workspaces=(${(@f)$(yarn workspaces list |sed 's/^.*: //')}) local -a components=() for workspace in $workspaces[@] do if [[ "$workspace" != '.' && -d $workspace ]]; then components+=$(basename "$workspace") fi done _arguments -C -s \ '(- *)'{-h,--help}'[Print this usage information]' \ '1:component:(($components))' \ '*:: :->arg' \ && ret=0 case $state in (arg) local component="$words[1]" local workspace_dir="" for workspace in $workspaces[@] do local d=$(basename $workspace) if [[ "$d" == $component ]]; then workspace_dir=$workspace fi done local -a scripts=() if [[ -d $workspace_dir ]]; then if (( $+commands[jq] )); then scripts=($(builtin cd $workspace_dir; jq -r '.scripts | keys | .[]' package.json 2>/dev/null)) elif (( $+commands[perl] )); then local package_json="$workspace_dir/package.json" scripts=($(cat "$package_json" | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); do{($k=$_)=~s/:/\\:/g;say $k}for sort keys %{$r->{scripts}}' 2>/dev/null)) fi fi _arguments \ '1:scripts:(($scripts))' \ '*:: :_files' \ && ret=0 ;; esac return ret } (( $+functions[_yarn_workspaces] )) || _yarn_workspaces() { local ret=1 _arguments -C -s \ '(- *)'{-h,--help}'[Print this usage information]' \ '1:subcmd:_yarn_workspaces_subcommands' \ '*:: :->arg' \ && ret=0 case $state in (arg) case $words[1] in (list) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--since[only include workspaces that have been changed since the specified ref]' \ '(-R,--recursive)'{-R,--recursive}'[find packages via dependencies/devDependencies]' \ '--no-private[exclude workspaces that have the private field set to true]' \ '(-v --verbose)'{-v,--verbose}'[also return the cross-dependencies between workspaces]' \ '--json[format the output as an NDJSON stream]' \ && ret=0 ;; (focus) _arguments \ '(- *)'{-h,--help}'[show help message and exit]' \ '--json[format the output as an NDJSON stream]' \ '--production[only install regular dependencies by ommiting dev dependencies]' \ '(-A --all)'{-A,--all}'[install the entire project]' \ && ret=0 ;; (foreach) _arguments -s \ '(- *)'{-h,--help}'[show help message and exit]' \ '(-A --all)'{-A,--all}'[run the command on all workspaces of a project]' \ '(-R --recursive)'{-R,--recursive}'[run the command current workspace and all of its recursive dependencies]' \ '(-W --worktree)'{-W,--worktree}'[run the command on all workspaces of the current worktree]' \ '(-v --verbose)'{-v,--verbose}'[increase level of logging verbosity up to 2 times]' \ '(-p --parallel)'{-p,--parallel}'[run the commands in parallel]' \ '(-i --interlaced)'{-i,--interlaced}'[print the output of commands in real-time instead of buffering]' \ '(-j --jobs)'{-j,--jobs}'[maximum number of parallel tasks]:jobs:(unlimited)' \ '(-t --topological)'{-t,--topological}'[run command after all workspaces it depends on(regular) have finished]' \ '--topological-dev[run command after all workspaces it depends on(regular + dev) have finished]' \ '*--include[patterns matching workspaces will be traversed]:pattern:_files' \ '*--exclude[patterns matching workspace will not be traversed]:pattern:_files' \ '--no-private[avoid running the command on private workspaces]' \ '--from["from" glob as the starting point for any recursive search]:from' \ '--since[only include workspaces that have been changed since the specified ref]' \ '*: :_normal' \ && ret=0 ;; esac ;; esac return ret } (( $+functions[_yarn_workspaces_subcommands] )) || _yarn_workspaces_subcommands() { local -a commands=( 'focus:install a single workspace and its dependencies' 'foreach:run a command on all workspaces' 'list:list all available workspaces' ) _describe -t commands 'command' commands "$@" } # # Utilities # (( $+functions[_yarn_manifest_fields] )) || _yarn_manifest_fields() { local -a fields=( name version description keywords homepage bugs license author contributors funding files exports main browser bin man directories repository scripts config dependencies devDependencies peerDependencies peerDependenciesMeta bundleDependencies optionalDependencies overrides engines os cpu libc devEngines private publishConfig workspaces ) _values -s , fields $fields } (( $+functions[_yarn_package_json_path] )) || _yarn_package_json_path() { local dir=$(pwd) while true do if [[ -e "${dir}/package.json" ]]; then echo "${dir}/package.json" return fi if [[ $dir == '/' ]]; then break fi dir=$(dirname $dir) done } _yarn_scripts() { local -a binaries if (( $+commands[jq] )); then binaries=($(yarn bin --json 2>/dev/null | jq -r '.name' 2>/dev/null)) elif (( $+commands[perl] )); then binaries=($(yarn bin 2>/dev/null | perl -wln -e 'm{^[^:]+:\s+([a-z]\S+)} and print $1' 2>/dev/null)) fi local -a scripts local package_json=$(_yarn_package_json_path) if [[ -e "$package_json" ]]; then if (( $+commands[jq] )); then scripts=($(jq -r '.scripts | keys | .[]' "$package_json" 2>/dev/null)) elif (( $+commands[perl] )); then scripts=("${(@f)$(cat ${package_json} | perl -0777 -MJSON::PP -n -E 'binmode(STDOUT, ":encoding(UTF-8)"); %r=%{decode_json($_)->{scripts}}; printf "$_\n" for sort keys %r' 2>/dev/null )}") fi fi local -a candidates=($scripts $binaries) _values 'scripts' $candidates } _yarn "$@" # Local Variables: # mode: Shell-Script # sh-indentation: 2 # indent-tabs-mode: nil # sh-basic-offset: 2 # End: # vim: ft=zsh sw=2 ts=2 et