_yarn 12 KB

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