_yarn 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. # * Shohei YOSHIDA <syohex@gmail.com>
  36. #
  37. # ------------------------------------------------------------------------------
  38. declare -g _yarn_run_cwd
  39. _commands=(
  40. 'access'
  41. 'audit:Checks for known security issues with the installed packages'
  42. 'autoclean:Clean and remove unnecessary files from package dependencies'
  43. 'cache:List or clean every cached package'
  44. "check:Verify package dependencies against yarn's lock file"
  45. 'config:Manages the yarn configuration files'
  46. 'create:Creates new projects from any create-* starter kits'
  47. 'exec'
  48. 'generate-lock-entry:Generates a lock file entry'
  49. 'global:Install packages globally on your operating system'
  50. 'help:Show information about a command'
  51. 'import:Generate yarn.lock from an existing npm-installed node_modules folder'
  52. 'info:Show information about a package'
  53. 'init:Interactively creates or updates a package.json file'
  54. 'install:Install all the dependencies listed within package.json'
  55. 'licenses:List licenses for installed packages'
  56. 'link:Symlink a package folder during development'
  57. 'login:Store registry username and email'
  58. 'logout:Clear registry username and email'
  59. 'node:Runs Node with the same version that the one used by Yarn itself'
  60. 'outdated:Check for outdated package dependencies'
  61. 'owner:Manage package owners'
  62. 'pack:Create a compressed gzip archive of package dependencies'
  63. 'policies:Defines project-wide policies for your project'
  64. 'publish:Publish a package to the npm registry'
  65. 'run:Run a defined package script'
  66. 'tag:Add, remove, or list tags on a package'
  67. 'team:Maintain team memberships'
  68. 'unlink:Unlink a previously created symlink for a package'
  69. 'unplug:Temporarily copies a package outside of the global cache for debugging purposes'
  70. 'version:Update the package version'
  71. 'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
  72. 'why:Show information about why a package is installed'
  73. 'workspace'
  74. 'workspaces:Show information about your workspaces'
  75. )
  76. _global_commands=(
  77. 'add:Installs a package and any packages that it depends on'
  78. 'bin:Displays the location of the yarn bin folder'
  79. 'list:List installed packages'
  80. 'remove:Remove installed package from dependencies updating package.json'
  81. 'upgrade:Upgrades packages to their latest version based on the specified range'
  82. 'upgrade-interactive:Interactively upgrade packages'
  83. )
  84. _yarn_commands_scripts() {
  85. local -a scripts
  86. if [[ -n $opt_args[--cwd] ]]; then
  87. scripts=($(cd $opt_args[--cwd] && 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'))
  88. else
  89. 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'))
  90. fi
  91. _describe 'command or script' _commands -- _global_commands -- scripts
  92. }
  93. _yarn_scripts() {
  94. local -a commands binaries scripts
  95. local -a scriptNames scriptCommands
  96. local i runJSON
  97. if [[ -n $_yarn_run_cwd ]]; then
  98. runJSON=$(cd $_yarn_run_cwd && yarn run --json 2>/dev/null)
  99. else
  100. runJSON=$(yarn run --json 2>/dev/null)
  101. fi
  102. # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
  103. # pattern as a newline. See https://superuser.com/q/307165
  104. binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
  105. scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
  106. scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{(.+")\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\'$'\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
  107. for (( i=1; i <= $#scriptNames; i++ )); do
  108. scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
  109. done
  110. commands=('env' $scripts $binaries)
  111. _describe 'command' commands
  112. }
  113. _yarn_global_commands() {
  114. local -a cmds
  115. cmds=('ls:List installed packages')
  116. _describe 'command' _global_commands
  117. }
  118. _yarn_commands() {
  119. _describe 'command' _commands -- _global_commands
  120. }
  121. _yarn_add_files() {
  122. if compset -P "(file|link):"; then
  123. _files
  124. fi
  125. }
  126. _yarn_workspaces() {
  127. local -a workspaces=(${(@f)$(yarn workspaces info |sed -n -e 's/^ "\([^"]*\)": {/\1/p')})
  128. _describe 'workspace' workspaces
  129. }
  130. _yarn() {
  131. local context state state_descr line
  132. typeset -A opt_args
  133. _arguments \
  134. '(-h --help)'{-h,--help}'[output usage information]' \
  135. '(-V --version)'{-V,--version}'[output the version number]' \
  136. '--verbose[output verbose messages on internal operations]' \
  137. '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \
  138. '--check-files[install will verify file tree of packages for consistency]' \
  139. '--cwd=[working directory to use]:path:_files -/' \
  140. "(--enable-pnp --pnp)--disable-pnp[disable the Plug'n'Play installation]" \
  141. '(--no-emoji)--emoji=[enable emoji in output(default: false)]:enabled:(true false)' \
  142. '(--emoji)--no-emoji[disable emoji in output]' \
  143. '(--disable-pnp)'{--enable-pnp,--pnp}"[enable the Plug'n'Play installation]" \
  144. '--flat[only allow one version of a package]' \
  145. '--focus[Focus on a single workspace by installing remote copies of its sibling workspaces]' \
  146. '--force[install and build packages even if they were built before, overwrite lockfile]' \
  147. "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
  148. '--global-folder=[modules folder]:folder:_files -/' \
  149. '--har[save HAR output of network traffic]' \
  150. '--https-proxy=[HTTPS proxy]:host:_hosts' \
  151. '--ignore-engines[ignore engines check]' \
  152. "--ignore-scripts[don't run lifecycle scripts]" \
  153. '--ignore-optional[ignore optional dependencies]' \
  154. '--ignore-platform[ignore platform checks]' \
  155. '--json[format Yarn log messages as lines of JSON]' \
  156. '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
  157. '--link-folder=[specify a custom folder to store global links]' \
  158. '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
  159. '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \
  160. '--network-concurrency=[maximum number of concurrent network requests]:number' \
  161. '--network-timeout=[TCP timeout for network requests]:milliseconds' \
  162. "--no-bin-links[don't generate bin links when setting up packages]" \
  163. '--no-default-rc[prevent Yarn from automatically detecting yarnrc and npmrc files]' \
  164. "--no-lockfile[don't read or generate a lockfile]" \
  165. '--non-interactive[do not show interactive prompts]' \
  166. '--no-node-version-check[do not warn when using a potentially unsupported Node version]' \
  167. '--no-progress[disable progress bar]' \
  168. '--offline[trigger an error if any required dependencies are not available in local cache]' \
  169. '--otp=[one-time password for two factor authentication]:otpcode' \
  170. '--prefer-offline[use network only if dependencies are not available in local cache]' \
  171. '--preferred-cache-folder=[specify a custom folder to store the yarn cache if possible]:folder:_files -/' \
  172. '(--prod --production)'{--prod,--production}'[install only production dependencies]' \
  173. '--proxy=[HTTP proxy]:host:_hosts' \
  174. "--pure-lockfile[don't generate a lockfile]" \
  175. '--registry=[override configuration registry]:url:_urls' \
  176. '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
  177. '--scripts-prepend-node-path=[prepend the node executable dir to the PATH in scripts]:bool:(true false)' \
  178. '--skip-integrity-check[run install without checking if node_modules is installed]' \
  179. "--strict-semver[don't compare semver loosely]" \
  180. '--update-checksum[update package checksums from current repository]' \
  181. '--use-yarnrc=[specifies a yarnrc that Yarn should use]:yarnrc:_files' \
  182. '1: :_yarn_commands_scripts' \
  183. '*:: :->command_args'
  184. case $state in
  185. command_args)
  186. case $words[1] in
  187. help)
  188. _arguments \
  189. '1: :_yarn_commands' \
  190. ;;
  191. access)
  192. _arguments \
  193. '1: :(public restricted grant revoke ls-packages ls-collaborators edit)'
  194. ;;
  195. add)
  196. _arguments \
  197. '(-D --dev)'{-D,--dev}'[install packages in devDependencies]' \
  198. '(-P --peer)'{-P,--peer}'[install packages in peerDependencies]' \
  199. '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \
  200. '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \
  201. '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \
  202. '(--ignore-workspace-root-check -W)'{--ignore-workspace-root-check,-W}'[allows a package to be installed at the workspaces root]' \
  203. '--audit[checks for known security issues with the installed packages]' \
  204. '*:package-name:_yarn_add_files'
  205. ;;
  206. audit)
  207. _arguments \
  208. '--verbose[output verbose message]' \
  209. '--json[format Yarn log messages as lines of JSON]' \
  210. '--level=[only print advisories with severity greater than or equal to]:level:(info low moderate high critical)' \
  211. '--groups=[only audit dependencies from listed groups]:groups:->groups_args'
  212. ;;
  213. cache)
  214. _arguments \
  215. '1: :(list dir clean)' \
  216. '*:: :->cache_args'
  217. ;;
  218. check)
  219. _arguments \
  220. '--integrity[Verifies that versions and hashed values of the package contents in package.json]' \
  221. '--verify-tree[Recursively verifies that the dependencies in package.json are present in node_modules]'
  222. ;;
  223. config)
  224. _arguments \
  225. '1: :(set get delete list)' \
  226. '*:: :->config_args'
  227. ;;
  228. global)
  229. _arguments \
  230. '--prefix=[bin prefix to use to install binaries]' \
  231. '1: :_yarn_global_commands' \
  232. '*:: :->command_args'
  233. ;;
  234. info)
  235. _arguments \
  236. '1:package:' \
  237. '2:field'
  238. ;;
  239. init)
  240. _arguments \
  241. '(-y --yes)'{-y,--yes}'[install packages in devDependencies]'
  242. ;;
  243. licenses)
  244. _arguments \
  245. '1: :(ls generate-disclaimer)' \
  246. ;;
  247. link|unlink|outdated)
  248. _arguments \
  249. '1:package' \
  250. ;;
  251. list)
  252. _arguments \
  253. '--depth=[Limit the depth of the shown dependencies]:depth' \
  254. '--pattern=[filter the list of dependencies by the pattern]'
  255. ;;
  256. owner)
  257. _arguments \
  258. '1: :(list add rm)' \
  259. '*:: :->owner_args'
  260. ;;
  261. pack)
  262. _arguments \
  263. '(-f --filename)'{-f,--filename}':filename:_files'
  264. ;;
  265. publish)
  266. _arguments \
  267. '--new-version:version:' \
  268. '--message:message:' \
  269. '--no-git-tag-version' \
  270. '--access:access:' \
  271. '--tag:tag:' \
  272. '1: :_files'
  273. ;;
  274. policies)
  275. _arguments \
  276. '1: :(set-version)'
  277. ;;
  278. remove|upgrade)
  279. _arguments \
  280. '*:package:'
  281. ;;
  282. run)
  283. if [[ -n $opt_args[--cwd] ]]; then
  284. _yarn_run_cwd=$opt_args[--cwd]
  285. else
  286. _yarn_run_cwd=''
  287. fi
  288. _arguments \
  289. '1: :_yarn_scripts' \
  290. '*:: :_default'
  291. ;;
  292. tag)
  293. _arguments \
  294. '1: :(lists add rm)' \
  295. '*:: :->tag_args'
  296. ;;
  297. team)
  298. _arguments \
  299. '1: :(create destroy add rm list)' \
  300. '*:: :->team_args'
  301. ;;
  302. upgrade-interactive)
  303. _arguments \
  304. '--latest[use the version tagged latest in the registry]'
  305. ;;
  306. version)
  307. _arguments \
  308. '--new-version[create a new version using an interactive session to prompt you]:version:' \
  309. '--major[creates a new version by incrementing the major version]' \
  310. '--minor[creates a new version by incrementing the minor version]' \
  311. '--patch[creates a new version by incrementing the patch version]' \
  312. '--premajor[creates a new prerelease version by incrementing the major version]' \
  313. '--preminor[creates a new prerelease version by incrementing the minor version]' \
  314. '--prepatch[creates a new prerelease version by incrementing the patch version]' \
  315. '--prerelease[increments the prerelease version number keeping the main version]' \
  316. '--no-git-tag-version[creates a new version without creating a git tag]' \
  317. '--no-commit-hooks[bypasses running commit hooks when committing the new version]'
  318. ;;
  319. why)
  320. _arguments \
  321. '1:query:_files'
  322. ;;
  323. workspace)
  324. _arguments \
  325. '1:workspace:_yarn_workspaces' \
  326. '*:: :_yarn_global_commands'
  327. ;;
  328. workspaces)
  329. _arguments \
  330. '--json[format Yarn log messages as lines of JSON]' \
  331. '1:commands:(info run)'
  332. ;;
  333. *)
  334. _default
  335. ;;
  336. esac
  337. ;;
  338. esac
  339. case $state in
  340. cache_args)
  341. if [[ $words[1] == "list" ]]; then
  342. _arguments \
  343. '--pattern=[print out every cached package that matches the pattern]:pattern:'
  344. fi
  345. ;;
  346. config_args)
  347. case $words[1] in
  348. get|delete)
  349. _arguments \
  350. '1:key:'
  351. ;;
  352. set)
  353. _arguments \
  354. '(-g --global)'{-g,--global} \
  355. '1:key:' \
  356. '2:value:'
  357. ;;
  358. esac
  359. ;;
  360. groups_args)
  361. local dependency_groups=(devDependencies dependencies optionalDependencies peerDependencies bundledDependencies)
  362. _values -s ',' 'groups' $dependency_groups
  363. ;;
  364. owner_args)
  365. case $words[1] in
  366. ls)
  367. _arguments \
  368. '1:package:'
  369. ;;
  370. add|rm)
  371. _arguments \
  372. '1:user:' \
  373. '2:package:'
  374. ;;
  375. esac
  376. ;;
  377. tag_args)
  378. case $words[1] in
  379. ls)
  380. _arguments \
  381. '1:package'
  382. ;;
  383. add|rm)
  384. _arguments \
  385. '1:package:' \
  386. '2:tag:'
  387. ;;
  388. esac
  389. ;;
  390. team_args)
  391. case $words[1] in
  392. create|destroy|ls)
  393. _arguments \
  394. '1:scope\:team:'
  395. ;;
  396. add|rm)
  397. _arguments \
  398. '1:scope\:team:' \
  399. '2:user:'
  400. ;;
  401. esac
  402. ;;
  403. esac
  404. }
  405. _yarn "$@"
  406. # Local Variables:
  407. # mode: Shell-Script
  408. # sh-indentation: 2
  409. # indent-tabs-mode: nil
  410. # sh-basic-offset: 2
  411. # End:
  412. # vim: ft=zsh sw=2 ts=2 et