_yarn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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:Interactively upgrade packages'
  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 commands binaries scripts
  81. local -a scriptNames scriptCommands
  82. local i runJSON
  83. runJSON=$(yarn run --json 2>/dev/null)
  84. binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
  85. scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
  86. scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{([^}]+)\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
  87. for (( i=1; i <= $#scriptNames; i++ )); do
  88. scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
  89. done
  90. commands=($scripts $binaries)
  91. _describe 'command' commands
  92. }
  93. _yarn_global_commands() {
  94. local -a cmds
  95. cmds=('ls:List installed packages')
  96. _describe 'command' _global_commands
  97. }
  98. _yarn_commands() {
  99. _describe 'command' _commands -- _global_commands
  100. }
  101. _yarn() {
  102. local context state state_descr line
  103. typeset -A opt_args
  104. _arguments \
  105. '(-h --help)'{-h,--help}'[output usage information]' \
  106. '(-V --version)'{-V,--version}'[output the version number]' \
  107. '--verbose[output verbose messages on internal operations]' \
  108. '--offline[trigger an error if any required dependencies are not available in local cache]' \
  109. '--prefer-offline[use network only if dependencies are not available in local cache]' \
  110. '--strict-semver' \
  111. '--json' \
  112. "--ignore-scripts[don't run lifecycle scripts]" \
  113. '--har[save HAR output of network traffic]' \
  114. '--ignore-platform[ignore platform checks]' \
  115. '--ignore-engines[ignore engines check]' \
  116. '--ignore-optional[ignore optional dependencies]' \
  117. '--force[install and build packages even if they were built before, overwrite lockfile]' \
  118. '--skip-integrity-check[run install without checking if node_modules is installed]' \
  119. '--check-files[install will verify file tree of packages for consistency]' \
  120. "--no-bin-links[don't generate bin links when setting up packages]" \
  121. '--flat[only allow one version of a package]' \
  122. '(--prod --production)'{--prod,--production} \
  123. "--no-lockfile[don't read or generate a lockfile]" \
  124. "--pure-lockfile[don't generate a lockfile]" \
  125. "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
  126. '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
  127. '--global-folder=[modules folder]:folder:_files -/' \
  128. '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
  129. '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \
  130. '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \
  131. '--no-emoji[disable emoji in output]' \
  132. '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
  133. '--proxy=:host:_hosts' \
  134. '--https-proxy=:host:_hosts' \
  135. '--no-progress[disable progress bar]' \
  136. '--network-concurrency=[maximum number of concurrent network requests]:number' \
  137. '--network-timeout=[TCP timeout for network requests]:milliseconds' \
  138. '--non-interactive[do not show interactive prompts]' \
  139. '1: :_yarn_commands_scripts' \
  140. '*:: :->command_args'
  141. case $state in
  142. command_args)
  143. case $words[1] in
  144. help)
  145. _arguments \
  146. '1: :_yarn_commands' \
  147. ;;
  148. access)
  149. _arguments \
  150. '1: :(public restricted grant revoke ls-packages ls-collaborators edit)'
  151. ;;
  152. add)
  153. _arguments \
  154. '(-D --dev)'{-D,--dev}'[install packages in devDependencies]' \
  155. '(-P --peer)'{-P,--peer}'[install packages in peerDependencies]' \
  156. '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \
  157. '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \
  158. '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \
  159. '*:package-name:'
  160. ;;
  161. cache)
  162. _arguments \
  163. '1: :(ls dir clean)'
  164. ;;
  165. check)
  166. _arguments \
  167. '--integrity' \
  168. '--verify-tree'
  169. ;;
  170. config)
  171. _arguments \
  172. '1: :(set get delete list)' \
  173. '*:: :->config_args'
  174. ;;
  175. global)
  176. _arguments \
  177. '--prefix=[bin prefix to use to install binaries]' \
  178. '1: :_yarn_global_commands' \
  179. '*:: :->command_args'
  180. ;;
  181. info)
  182. _arguments \
  183. '1:package:' \
  184. '2:field'
  185. ;;
  186. init)
  187. _arguments \
  188. '(-y --yes)'{-y,--yes}'[install packages in devDependencies]'
  189. ;;
  190. licenses)
  191. _arguments \
  192. '1: :(ls generate-disclaimer)' \
  193. ;;
  194. link|unlink|outdated)
  195. _arguments \
  196. '1:package' \
  197. ;;
  198. list)
  199. _arguments \
  200. '--depth[Limit the depth of the shown dependencies]:depth'
  201. ;;
  202. owner)
  203. _arguments \
  204. '1: :(ls add rm)' \
  205. '*:: :->owner_args'
  206. ;;
  207. pack)
  208. _arguments \
  209. '(-f --filename)'{-f,--filename}':filename:_files'
  210. ;;
  211. publish)
  212. _arguments \
  213. '--new-version:version:' \
  214. '--message:message:' \
  215. '--no-git-tag-version' \
  216. '--access:access:' \
  217. '--tag:tag:' \
  218. '1: :_files'
  219. ;;
  220. remove|upgrade)
  221. _arguments \
  222. '*:package:'
  223. ;;
  224. run)
  225. _arguments \
  226. '1: :_yarn_scripts' \
  227. '*:: :_default'
  228. ;;
  229. tag)
  230. _arguments \
  231. '1: :(ls add rm)' \
  232. '*:: :->tag_args'
  233. ;;
  234. team)
  235. _arguments \
  236. '1: :(create destroy add rm ls)' \
  237. '*:: :->team_args'
  238. ;;
  239. upgrade-interactive)
  240. _arguments \
  241. '--latest:use the version tagged latest in the registry:'
  242. ;;
  243. version)
  244. _arguments \
  245. '--new-version:version:' \
  246. '--message:message:' \
  247. '--no-git-tag-version'
  248. ;;
  249. why)
  250. _arguments \
  251. '1:query:_files'
  252. ;;
  253. *)
  254. _default
  255. ;;
  256. esac
  257. ;;
  258. esac
  259. case $state in
  260. config_args)
  261. case $words[1] in
  262. get|delete)
  263. _arguments \
  264. '1:key:'
  265. ;;
  266. set)
  267. _arguments \
  268. '(-g --global)'{-g,--global} \
  269. '1:key:' \
  270. '2:value:'
  271. ;;
  272. esac
  273. ;;
  274. owner_args)
  275. case $words[1] in
  276. ls)
  277. _arguments \
  278. '1:package:'
  279. ;;
  280. add|rm)
  281. _arguments \
  282. '1:user:' \
  283. '2:package:'
  284. ;;
  285. esac
  286. ;;
  287. tag_args)
  288. case $words[1] in
  289. ls)
  290. _arguments \
  291. '1:package'
  292. ;;
  293. add|rm)
  294. _arguments \
  295. '1:package:' \
  296. '2:tag:'
  297. ;;
  298. esac
  299. ;;
  300. team_args)
  301. case $words[1] in
  302. create|destroy|ls)
  303. _arguments \
  304. '1:scope\:team:'
  305. ;;
  306. add|rm)
  307. _arguments \
  308. '1:scope\:team:' \
  309. '2:user:'
  310. ;;
  311. esac
  312. ;;
  313. esac
  314. }
  315. _yarn "$@"
  316. # Local Variables:
  317. # mode: Shell-Script
  318. # sh-indentation: 2
  319. # indent-tabs-mode: nil
  320. # sh-basic-offset: 2
  321. # End:
  322. # vim: ft=zsh sw=2 ts=2 et