2 # ------------------------------------------------------------------------------
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
5 # * Redistributions of source code must retain the above copyright
6 # notice, this list of conditions and the following disclaimer.
7 # * Redistributions in binary form must reproduce the above copyright
8 # notice, this list of conditions and the following disclaimer in the
9 # documentation and/or other materials provided with the distribution.
10 # * Neither the name of the zsh-users nor the
11 # names of its contributors may be used to endorse or promote products
12 # derived from this software without specific prior written permission.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 # ------------------------------------------------------------------------------
28 # Completion script for yarn (https://yarnpkg.com/)
30 # ------------------------------------------------------------------------------
34 # * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
35 # * Shohei YOSHIDA <syohex@gmail.com>
37 # ------------------------------------------------------------------------------
39 declare -g _yarn_run_cwd
43 'audit:Checks for known security issues with the installed packages'
44 'autoclean:Clean and remove unnecessary files from package dependencies'
45 'cache:List or clean every cached package'
46 "check:Verify package dependencies against yarn's lock file"
47 'config:Manages the yarn configuration files'
48 'create:Creates new projects from any create-* starter kits'
50 'generate-lock-entry:Generates a lock file entry'
51 'global:Install packages globally on your operating system'
52 'help:Show information about a command'
53 'import:Generate yarn.lock from an existing npm-installed node_modules folder'
54 'info:Show information about a package'
55 'init:Interactively creates or updates a package.json file'
56 'install:Install all the dependencies listed within package.json'
57 'licenses:List licenses for installed packages'
58 'link:Symlink a package folder during development'
59 'login:Store registry username and email'
60 'logout:Clear registry username and email'
61 'node:Runs Node with the same version that the one used by Yarn itself'
62 'outdated:Check for outdated package dependencies'
63 'owner:Manage package owners'
64 'pack:Create a compressed gzip archive of package dependencies'
65 'policies:Defines project-wide policies for your project'
66 'publish:Publish a package to the npm registry'
67 'run:Run a defined package script'
68 'tag:Add, remove, or list tags on a package'
69 'team:Maintain team memberships'
70 'unlink:Unlink a previously created symlink for a package'
71 'unplug:Temporarily copies a package outside of the global cache for debugging purposes'
72 'version:Update the package version'
73 'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
74 'why:Show information about why a package is installed'
76 'workspaces:Show information about your workspaces'
80 'add:Installs a package and any packages that it depends on'
81 'bin:Displays the location of the yarn bin folder'
82 'list:List installed packages'
83 'remove:Remove installed package from dependencies updating package.json'
84 'upgrade:Upgrades packages to their latest version based on the specified range'
85 'upgrade-interactive:Interactively upgrade packages'
88 _yarn_find_package_json() {
89 local dir=$(cd "$1" && pwd)
93 if [[ -e "${dir}/package.json" ]]; then
94 echo "${dir}/package.json"
98 if [[ $dir == '/' ]]; then
106 _yarn_commands_scripts() {
107 local -a scripts binaries
110 if [[ -n $opt_args[--cwd] ]]; then
111 packageJson=$(_yarn_find_package_json $opt_args[--cwd])
112 binaries=($(cd $opt_args[--cwd] && echo node_modules/.bin/*(x:t)))
114 packageJson=$(_yarn_find_package_json $pwd)
115 binaries=($(echo node_modules/.bin/*(x:t)))
118 if [[ -n $packageJson ]]; then
119 scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); do{($k=$_)=~s/:/\\:/g;say $k}for sort keys %{$r->{scripts}}'))
122 _describe 'command or script' _commands -- _global_commands -- scripts -- binaries
126 local -a binaries scripts
130 if [[ -n $_yarn_run_cwd ]]; then
131 packageJson=$(_yarn_find_package_json $_yarn_run_cwd)
132 if [[ -d "${_yarn_run_cwd}/node_modules" ]]; then
133 binaries=($(cd $_yarn_run_cwd && echo node_modules/.bin/*(x:t)))
135 binaries=($(cd $_yarn_run_cwd && yarn bin | perl -wln -e 'm{^[^:]+: (\S+)$} and print $1'))
138 packageJson=$(_yarn_find_package_json $pwd)
139 if [[ -d node_modules ]]; then
140 binaries=($(echo node_modules/.bin/*(x:t)))
142 binaries=($(yarn bin | perl -wln -e 'm{^[^:]+: (\S+)$} and print $1'))
146 if [[ -n $packageJson ]]; then
147 scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}")
150 commands=('env' $scripts $binaries)
151 _describe 'command' commands
154 _yarn_global_commands() {
156 cmds=('ls:List installed packages')
157 _describe 'command' _global_commands
161 _describe 'command' _commands -- _global_commands
165 if compset -P "(file|link):"; then
171 local version=$(yarn --version |sed -n 's|\([0-9]*\).*|\1|p')
173 if [[ $version == "1" ]]; then
174 workspaces=(${(@f)$(yarn workspaces info |sed -n -e 's/^ "\([^"]*\)": {/\1/p')})
176 workspaces=(${(@f)$(yarn workspaces list --json | sed -n 's|.*"name":"\([^"]*\)"}|\1|p')})
178 _describe 'workspace' workspaces
182 local context state state_descr line
186 '(-h --help)'{-h,--help}'[output usage information]' \
187 '(-V --version)'{-V,--version}'[output the version number]' \
188 '--verbose[output verbose messages on internal operations]' \
189 '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \
190 '--check-files[install will verify file tree of packages for consistency]' \
191 '--cwd=[working directory to use]:path:_files -/' \
192 "(--enable-pnp --pnp)--disable-pnp[disable the Plug'n'Play installation]" \
193 '(--no-emoji)--emoji=[enable emoji in output(default: false)]:enabled:(true false)' \
194 '(--emoji)--no-emoji[disable emoji in output]' \
195 '(--disable-pnp)'{--enable-pnp,--pnp}"[enable the Plug'n'Play installation]" \
196 '--flat[only allow one version of a package]' \
197 '--focus[Focus on a single workspace by installing remote copies of its sibling workspaces]' \
198 '--force[install and build packages even if they were built before, overwrite lockfile]' \
199 "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
200 '--global-folder=[modules folder]:folder:_files -/' \
201 '--har[save HAR output of network traffic]' \
202 '--https-proxy=[HTTPS proxy]:host:_hosts' \
203 '--ignore-engines[ignore engines check]' \
204 "--ignore-scripts[don't run lifecycle scripts]" \
205 '--ignore-optional[ignore optional dependencies]' \
206 '--ignore-platform[ignore platform checks]' \
207 '--json[format Yarn log messages as lines of JSON]' \
208 '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
209 '--link-folder=[specify a custom folder to store global links]' \
210 '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
211 '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \
212 '--network-concurrency=[maximum number of concurrent network requests]:number' \
213 '--network-timeout=[TCP timeout for network requests]:milliseconds' \
214 "--no-bin-links[don't generate bin links when setting up packages]" \
215 '--no-default-rc[prevent Yarn from automatically detecting yarnrc and npmrc files]' \
216 "--no-lockfile[don't read or generate a lockfile]" \
217 '--non-interactive[do not show interactive prompts]' \
218 '--no-node-version-check[do not warn when using a potentially unsupported Node version]' \
219 '--no-progress[disable progress bar]' \
220 '--offline[trigger an error if any required dependencies are not available in local cache]' \
221 '--otp=[one-time password for two factor authentication]:otpcode' \
222 '--prefer-offline[use network only if dependencies are not available in local cache]' \
223 '--preferred-cache-folder=[specify a custom folder to store the yarn cache if possible]:folder:_files -/' \
224 '(--prod --production)'{--prod,--production}'[install only production dependencies]' \
225 '--proxy=[HTTP proxy]:host:_hosts' \
226 "--pure-lockfile[don't generate a lockfile]" \
227 '--registry=[override configuration registry]:url:_urls' \
228 '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
229 '--scripts-prepend-node-path=[prepend the node executable dir to the PATH in scripts]:bool:(true false)' \
230 '--skip-integrity-check[run install without checking if node_modules is installed]' \
231 "--strict-semver[don't compare semver loosely]" \
232 '--update-checksum[update package checksums from current repository]' \
233 '--use-yarnrc=[specifies a yarnrc that Yarn should use]:yarnrc:_files' \
234 '1: :_yarn_commands_scripts' \
235 '*:: :->command_args'
243 '1: :_yarn_commands' \
248 '1: :(public restricted grant revoke ls-packages ls-collaborators edit)'
253 '(-D --dev)'{-D,--dev}'[install packages in devDependencies]' \
254 '(-P --peer)'{-P,--peer}'[install packages in peerDependencies]' \
255 '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \
256 '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \
257 '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \
258 '(--ignore-workspace-root-check -W)'{--ignore-workspace-root-check,-W}'[allows a package to be installed at the workspaces root]' \
259 '--audit[checks for known security issues with the installed packages]' \
260 '*:package-name:_yarn_add_files'
265 '--verbose[output verbose message]' \
266 '--json[format Yarn log messages as lines of JSON]' \
267 '--level=[only print advisories with severity greater than or equal to]:level:(info low moderate high critical)' \
268 '--groups=[only audit dependencies from listed groups]:groups:->groups_args'
273 '1: :(list dir clean)' \
279 '--integrity[Verifies that versions and hashed values of the package contents in package.json]' \
280 '--verify-tree[Recursively verifies that the dependencies in package.json are present in node_modules]'
285 '1: :(set get delete list)' \
291 '--prefix=[bin prefix to use to install binaries]' \
292 '1: :_yarn_global_commands' \
293 '*:: :->command_args'
304 '(-y --yes)'{-y,--yes}'[install packages in devDependencies]'
309 '1: :(ls generate-disclaimer)' \
312 link|unlink|outdated)
319 '--depth=[Limit the depth of the shown dependencies]:depth' \
320 '--pattern=[filter the list of dependencies by the pattern]'
325 '1: :(list add rm)' \
331 '(-f --filename)'{-f,--filename}':filename:_files'
336 '--new-version:version:' \
337 '--message:message:' \
338 '--no-git-tag-version' \
355 if [[ -n $opt_args[--cwd] ]]; then
356 _yarn_run_cwd=$opt_args[--cwd]
361 '1: :_yarn_scripts' \
367 '1: :(lists add rm)' \
373 '1: :(create destroy add rm list)' \
379 '--latest[use the version tagged latest in the registry]'
384 '--new-version[create a new version using an interactive session to prompt you]:version:' \
385 '--major[creates a new version by incrementing the major version]' \
386 '--minor[creates a new version by incrementing the minor version]' \
387 '--patch[creates a new version by incrementing the patch version]' \
388 '--premajor[creates a new prerelease version by incrementing the major version]' \
389 '--preminor[creates a new prerelease version by incrementing the minor version]' \
390 '--prepatch[creates a new prerelease version by incrementing the patch version]' \
391 '--prerelease[increments the prerelease version number keeping the main version]' \
392 '--no-git-tag-version[creates a new version without creating a git tag]' \
393 '--no-commit-hooks[bypasses running commit hooks when committing the new version]'
403 '1:workspace:_yarn_workspaces' \
404 '*:: :_yarn_global_commands'
409 '--json[format Yarn log messages as lines of JSON]' \
410 '1:commands:(info run)'
422 if [[ $words[1] == "list" ]]; then
424 '--pattern=[print out every cached package that matches the pattern]:pattern:'
436 '(-g --global)'{-g,--global} \
443 local dependency_groups=(devDependencies dependencies optionalDependencies peerDependencies bundledDependencies)
444 _values -s ',' 'groups' $dependency_groups
499 # indent-tabs-mode: nil
502 # vim: ft=zsh sw=2 ts=2 et