_yarn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. #compdef yarn
  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.
  13. #
  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. # ------------------------------------------------------------------------------
  25. # Description
  26. # -----------
  27. #
  28. # Completion script for yarn (https://yarnpkg.com/)
  29. #
  30. # ------------------------------------------------------------------------------
  31. # Authors
  32. # -------
  33. #
  34. # * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
  35. #
  36. # ------------------------------------------------------------------------------
  37. _commands=(
  38. 'access'
  39. 'autoclean:Clean and remove unnecessary files from package dependencies'
  40. 'cache:List or clean every cached package'
  41. "check:Verify package dependencies agains yarn's lock file"
  42. 'config:Manages the yarn configuration files'
  43. 'generate-lock-entry:Generates a lock file entry'
  44. 'global:Install packages globally on your operating system'
  45. 'help:Show information about a command'
  46. 'import:Generate yarn.lock from an existing npm-installed node_modules folder'
  47. 'info:Show information about a package'
  48. 'init:Interactively creates or updates a package.json file'
  49. 'install:Install all the dependencies listed within package.json'
  50. 'licenses:List licenses for installed packages'
  51. 'link:Symlink a package folder during development'
  52. 'list:List installed packages'
  53. 'login:Store registry username and email'
  54. 'logout:Clear registry username and email'
  55. 'outdated:Check for outdated package dependencies'
  56. 'owner:Manage package owners'
  57. 'pack:Create a compressed gzip archive of package dependencies'
  58. 'publish:Publish a package to the npm registry'
  59. 'run:Run a defined package script'
  60. 'tag:Add, remove, or list tags on a package'
  61. 'team:Maintain team memberships'
  62. 'unlink:Unlink a previously created symlink for a package'
  63. 'version:Update the package version'
  64. 'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
  65. 'why:Show information about why a package is installed'
  66. )
  67. _global_commands=(
  68. 'add:Installs a package and any packages that it depends on'
  69. 'bin:Displays the location of the yarn bin folder'
  70. 'remove:Remove installed package from dependencies updating package.json'
  71. 'upgrade:Upgrades packages to their latest version based on the specified range'
  72. 'upgrade-interactive'
  73. )
  74. _yarn_commands_scripts() {
  75. local -a scripts
  76. 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'))
  77. _describe 'command or script' _commands -- _global_commands -- scripts
  78. }
  79. _yarn_scripts() {
  80. local -a scripts
  81. 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'))
  82. _describe 'script' scripts
  83. }
  84. _yarn_global_commands() {
  85. local -a cmds
  86. cmds=('ls:List installed packages')
  87. _describe 'command' _global_commands
  88. }
  89. _yarn_commands() {
  90. _describe 'command' _commands -- _global_commands
  91. }
  92. _yarn() {
  93. local context state state_descr line
  94. typeset -A opt_args
  95. _arguments \
  96. '(-h --help)'{-h,--help}'[output usage information]' \
  97. '(-V --version)'{-V,--version}'[output the version number]' \
  98. '--verbose[output verbose messages on internal operations]' \
  99. '--offline[trigger an error if any required dependencies are not available in local cache]' \
  100. '--prefer-offline[use network only if dependencies are not available in local cache]' \
  101. '--strict-semver' \
  102. '--json' \
  103. "--ignore-scripts[don't run lifecycle scripts]" \
  104. '--har[save HAR output of network traffic]' \
  105. '--ignore-platform[ignore platform checks]' \
  106. '--ignore-engines[ignore engines check]' \
  107. '--ignore-optional[ignore optional dependencies]' \
  108. '--force[install and build packages even if they were built before, overwrite lockfile]' \
  109. '--skip-integrity-check[run install without checking if node_modules is installed]' \
  110. '--check-files[install will verify file tree of packages for consistency]' \
  111. "--no-bin-links[don't generate bin links when setting up packages]" \
  112. '--flat[only allow one version of a package]' \
  113. '(--prod --production)'{--prod,--production} \
  114. "--no-lockfile[don't read or generate a lockfile]" \
  115. "--pure-lockfile[don't generate a lockfile]" \
  116. "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
  117. '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
  118. '--global-folder=[modules folder]:folder:_files -/' \
  119. '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
  120. '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \
  121. '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \
  122. '--no-emoji[disable emoji in output]' \
  123. '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
  124. '--proxy=:host:_hosts' \
  125. '--https-proxy=:host:_hosts' \
  126. '--no-progress[disable progress bar]' \
  127. '--network-concurrency=[maximum number of concurrent network requests]:number' \
  128. '--network-timeout=[TCP timeout for network requests]:milliseconds' \
  129. '--non-interactive[do not show interactive prompts]' \
  130. '1: :_yarn_commands_scripts' \
  131. '*:: :->command_args'
  132. case $state in
  133. command_args)
  134. case $words[1] in
  135. help)
  136. _arguments \
  137. '1: :_yarn_commands' \
  138. ;;
  139. access)
  140. _arguments \
  141. '1: :(public restricted grant revoke ls-packages ls-collaborators edit)'
  142. ;;
  143. add)
  144. _arguments \
  145. '(-D --dev)'{-D,--dev}'[install packages in devDependencies]' \
  146. '(-P --peer)'{-P,--peer}'[install packages in peerDependencies]' \
  147. '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \
  148. '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \
  149. '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \
  150. '*:package-name:'
  151. ;;
  152. cache)
  153. _arguments \
  154. '1: :(ls dir clean)'
  155. ;;
  156. check)
  157. _arguments \
  158. '--integrity' \
  159. '--verify-tree'
  160. ;;
  161. config)
  162. _arguments \
  163. '1: :(set get delete list)' \
  164. '*:: :->config_args'
  165. ;;
  166. global)
  167. _arguments \
  168. '--prefix=[bin prefix to use to install binaries]' \
  169. '1: :_yarn_global_commands' \
  170. '*:: :->command_args'
  171. ;;
  172. info)
  173. _arguments \
  174. '1:package:' \
  175. '2:field'
  176. ;;
  177. init)
  178. _arguments \
  179. '(-y --yes)'{-y,--yes}'[install packages in devDependencies]'
  180. ;;
  181. licenses)
  182. _arguments \
  183. '1: :(ls generate-disclaimer)' \
  184. ;;
  185. link|unlink|outdated)
  186. _arguments \
  187. '1:package' \
  188. ;;
  189. list)
  190. _arguments \
  191. '--depth[Limit the depth of the shown dependencies]:depth'
  192. ;;
  193. owner)
  194. _arguments \
  195. '1: :(ls add rm)' \
  196. '*:: :->owner_args'
  197. ;;
  198. pack)
  199. _arguments \
  200. '(-f --filename)'{-f,--filename}':filename:_files'
  201. ;;
  202. publish)
  203. _arguments \
  204. '--new-version:version:' \
  205. '--message:message:' \
  206. '--no-git-tag-version' \
  207. '--access:access:' \
  208. '--tag:tag:' \
  209. '1: :_files'
  210. ;;
  211. remove|upgrade)
  212. _arguments \
  213. '*:package:'
  214. ;;
  215. run)
  216. _arguments \
  217. '1: :_yarn_scripts'
  218. ;;
  219. tag)
  220. _arguments \
  221. '1: :(ls add rm)' \
  222. '*:: :->tag_args'
  223. ;;
  224. team)
  225. _arguments \
  226. '1: :(create destroy add rm ls)' \
  227. '*:: :->team_args'
  228. ;;
  229. version)
  230. _arguments \
  231. '--new-version:version:' \
  232. '--message:message:' \
  233. '--no-git-tag-version'
  234. ;;
  235. why)
  236. _arguments \
  237. '1:query:_files'
  238. ;;
  239. esac
  240. ;;
  241. esac
  242. case $state in
  243. config_args)
  244. case $words[1] in
  245. get|delete)
  246. _arguments \
  247. '1:key:'
  248. ;;
  249. set)
  250. _arguments \
  251. '(-g --global)'{-g,--global} \
  252. '1:key:' \
  253. '2:value:'
  254. ;;
  255. esac
  256. ;;
  257. owner_args)
  258. case $words[1] in
  259. ls)
  260. _arguments \
  261. '1:package:'
  262. ;;
  263. add|rm)
  264. _arguments \
  265. '1:user:' \
  266. '2:package:'
  267. ;;
  268. esac
  269. ;;
  270. tag_args)
  271. case $words[1] in
  272. ls)
  273. _arguments \
  274. '1:package'
  275. ;;
  276. add|rm)
  277. _arguments \
  278. '1:package:' \
  279. '2:tag:'
  280. ;;
  281. esac
  282. ;;
  283. team_args)
  284. case $words[1] in
  285. create|destroy|ls)
  286. _arguments \
  287. '1:scope\:team:'
  288. ;;
  289. add|rm)
  290. _arguments \
  291. '1:scope\:team:' \
  292. '2:user:'
  293. ;;
  294. esac
  295. ;;
  296. esac
  297. }
  298. _yarn "$@"
  299. # Local Variables:
  300. # mode: Shell-Script
  301. # sh-indentation: 2
  302. # indent-tabs-mode: nil
  303. # sh-basic-offset: 2
  304. # End:
  305. # vim: ft=zsh sw=2 ts=2 et