783ce457af3c28bf9f683ee560e1ba1fdecec969

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge branch 'update/yarn-plugin'

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/yarn/README.md b/plugins/yarn/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..c4e6d6da542cbd7db3472ded527689fec06f042c
  4--- /dev/null
  5+++ b/plugins/yarn/README.md
  6@@ -0,0 +1,33 @@
  7+# Yarn plugin
  8+
  9+This plugin adds completion for the [Yarn package manager](https://yarnpkg.com/en/),
 10+as well as some aliases for common Yarn commands.
 11+
 12+To use it, add `yarn` to the plugins array in your zshrc file:
 13+
 14+```zsh
 15+plugins=(... yarn)
 16+```
 17+
 18+## Aliases
 19+
 20+| Alias | Command                                   | Description                                                 |
 21+|-------|-------------------------------------------|-------------------------------------------------------------|
 22+| y     | `yarn`                                    | The Yarn command                                            |
 23+| ya    | `yarn add`                                | Install a package in dependencies (`package.json`)          |
 24+| yad   | `yarn add --dev`                          | Install a package in devDependencies (`package.json`)       |
 25+| yap   | `yarn add --peer`                         | Install a package in peerDependencies (`package.json`)      |
 26+| yb    | `yarn build`                              | Run the build script defined in `package.json`              |
 27+| ycc   | `yarn cache clean`                        | Clean yarn's global cache of packages                       |
 28+| ygu   | `yarn global upgrade`                     | Upgrade packages installed globally to their latest version |
 29+| yh    | `yarn help`                               | Show help for a yarn command                                |
 30+| yin   | `yarn install`                            | Install dependencies defined in `package.json`              |
 31+| yls   | `yarn list`                               | List installed packages                                     |
 32+| yout  | `yarn outdated`                           | Check for outdated package dependencies                     |
 33+| yrm   | `yarn remove`                             | Remove installed packages                                   |
 34+| yrun  | `yarn run`                                | Run a defined package script                                |
 35+| yst   | `yarn start`                              | Run the start script defined in `package.json`              |
 36+| yt    | `yarn test`                               | Run the test script defined in `package.json`               |
 37+| yuc   | `yarn global upgrade && yarn cache clean` | Upgrade global packages and clean yarn's global cache       |
 38+| yui   | `yarn upgrade-interactive`                | Prompt for which outdated packages to upgrade               |
 39+| yup   | `yarn upgrade`                            | Upgrade packages to their latest version                    |
 40diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn
 41new file mode 100644
 42index 0000000000000000000000000000000000000000..382f58a0abacde5beb4836459a37a71d4d26440c
 43--- /dev/null
 44+++ b/plugins/yarn/_yarn
 45@@ -0,0 +1,345 @@
 46+#compdef yarn
 47+# ------------------------------------------------------------------------------
 48+# Redistribution and use in source and binary forms, with or without
 49+# modification, are permitted provided that the following conditions are met:
 50+#     * Redistributions of source code must retain the above copyright
 51+#       notice, this list of conditions and the following disclaimer.
 52+#     * Redistributions in binary form must reproduce the above copyright
 53+#       notice, this list of conditions and the following disclaimer in the
 54+#       documentation and/or other materials provided with the distribution.
 55+#     * Neither the name of the zsh-users nor the
 56+#       names of its contributors may be used to endorse or promote products
 57+#       derived from this software without specific prior written permission.
 58+#
 59+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 60+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 61+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 62+# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
 63+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 64+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 65+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 66+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 67+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 68+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 69+# ------------------------------------------------------------------------------
 70+# Description
 71+# -----------
 72+#
 73+#  Completion script for yarn (https://yarnpkg.com/)
 74+#
 75+# ------------------------------------------------------------------------------
 76+# Authors
 77+# -------
 78+#
 79+#  * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
 80+#
 81+# ------------------------------------------------------------------------------
 82+
 83+_commands=(
 84+  'access'
 85+  'autoclean:Clean and remove unnecessary files from package dependencies'
 86+  'cache:List or clean every cached package'
 87+  "check:Verify package dependencies agains yarn's lock file"
 88+  'config:Manages the yarn configuration files'
 89+  'generate-lock-entry:Generates a lock file entry'
 90+  'global:Install packages globally on your operating system'
 91+  'help:Show information about a command'
 92+  'import:Generate yarn.lock from an existing npm-installed node_modules folder'
 93+  'info:Show information about a package'
 94+  'init:Interactively creates or updates a package.json file'
 95+  'install:Install all the dependencies listed within package.json'
 96+  'licenses:List licenses for installed packages'
 97+  'link:Symlink a package folder during development'
 98+  'list:List installed packages'
 99+  'login:Store registry username and email'
100+  'logout:Clear registry username and email'
101+  'outdated:Check for outdated package dependencies'
102+  'owner:Manage package owners'
103+  'pack:Create a compressed gzip archive of package dependencies'
104+  'publish:Publish a package to the npm registry'
105+  'run:Run a defined package script'
106+  'tag:Add, remove, or list tags on a package'
107+  'team:Maintain team memberships'
108+  'unlink:Unlink a previously created symlink for a package'
109+  'version:Update the package version'
110+  'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
111+  'why:Show information about why a package is installed'
112+)
113+
114+_global_commands=(
115+  'add:Installs a package and any packages that it depends on'
116+  'bin:Displays the location of the yarn bin folder'
117+  'remove:Remove installed package from dependencies updating package.json'
118+  'upgrade:Upgrades packages to their latest version based on the specified range'
119+  'upgrade-interactive'
120+)
121+
122+_yarn_commands_scripts() {
123+  local -a scripts
124+  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'))
125+  _describe 'command or script' _commands -- _global_commands -- scripts
126+}
127+
128+_yarn_scripts() {
129+  local -a scripts
130+  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'))
131+  _describe 'script' scripts
132+}
133+
134+_yarn_global_commands() {
135+  local -a cmds
136+  cmds=('ls:List installed packages')
137+  _describe 'command' _global_commands
138+}
139+
140+_yarn_commands() {
141+  _describe 'command' _commands -- _global_commands
142+}
143+
144+_yarn() {
145diff --git a/plugins/yarn/yarn.plugin.zsh b/plugins/yarn/yarn.plugin.zsh
146index eee811b16100a86e9800fabc7d1f3ad8d9dd73f8..fe752357f991ebbcd3df42143aadaa9c4b0cabb9 100644
147--- a/plugins/yarn/yarn.plugin.zsh
148+++ b/plugins/yarn/yarn.plugin.zsh
149@@ -1,98 +1,18 @@
150-# Alias sorted alphabetically
151-
152-alias y="yarn "
153+alias y="yarn"
154 alias ya="yarn add"
155+alias yad="yarn add --dev"
156+alias yap="yarn add --peer"
157+alias yb="yarn build"
158 alias ycc="yarn cache clean"
159+alias ygu="yarn global upgrade"
160 alias yh="yarn help"
161+alias yin="yarn install"
162+alias yls="yarn list"
163 alias yout="yarn outdated"
164+alias yrm="yarn remove"
165+alias yrun="yarn run"
166+alias yst="yarn start"
167+alias yt="yarn test"
168+alias yuc="yarn global upgrade && yarn cache clean"
169 alias yui="yarn upgrade-interactive"
170-
171-_yarn ()
172-{
173-    local -a _1st_arguments _dopts _dev _production
174-    local expl
175-    typeset -A opt_args
176-
177-    _dopts=(
178-        '(--force)--force[This refetches all packages, even ones that were previously installed.]'
179-    )
180-
181-    _installopts=(
182-        '(--flat)--flat[Only allow one version of a package. On the first run this will prompt you to choose a single version for each package that is depended on at multiple version ranges.]'
183-        '(--har)--har[Outputs an HTTP archive from all the network requests performed during the installation.]'
184-        '(--no-lockfile)--no-lockfile[Don’t read or generate a yarn.lock lockfile.]'
185-        '(--pure-lockfile)--pure-lockfile[Don’t generate a yarn.lock lockfile.]'
186-    )
187-
188-    _dev=('(--dev)--dev[Save installed packages into the project"s package.json devDependencies]')
189-
190-    _production=('(--production)--production[Do not install project devDependencies]')
191-
192-    _upgrade=(
193-        '(--exact)--exact[Install exact version]'
194-        '(--tilde)--tilde[Install most recent release with the same minor version]'
195-     )
196-
197-    _1st_arguments=(
198-      'help:Display help information about yarn' \
199-      'init:Initialize for the development of a package' \
200-      'add:Add a package to use in your current package' \
201-      'install:Install all the dependencies listed within package.json in the local node_modules folder' \
202-      'publish:Publish a package to a package manager' \
203-      'remove:Remove a package that will no longer be used in your current package' \
204-      'cache:Clear the local cache. It will be populated again the next time yarn or yarn install is run' \
205-      'clean:Frees up space by removing unnecessary files and folders from dependencies' \
206-      'check:Verifies that versions of the package dependencies in the current project’s package.json matches that of yarn’s lock file' \
207-      'ls:List all installed packages' \
208-      'global:Makes binaries available to use on your operating system' \
209-      'info:<package> [<field>] - fetch information about a package and return it in a tree format' \
210-      'outdated:Checks for outdated package dependencies' \
211-      'run:Runs a defined package script' \
212-      'self-update:Updates Yarn to the latest version' \
213-      'upgrade:Upgrades packages to their latest version based on the specified range' \
214-      'upgrade-interactive:Selectively upgrades specific packages in a simple way' \
215-      'why:<query> - Show information about why a package is installed'
216-    )
217-    _arguments \
218-    '*:: :->subcmds' && return 0
219-
220-    if (( CURRENT == 1 )); then
221-        _describe -t commands "yarn subcommand" _1st_arguments
222-        return
223-    fi
224-
225-    case "$words[1]" in
226-        add)
227-        _arguments \
228-        $_dopts \
229-        $_dev \
230-        $_production
231-        ;;
232-        install)
233-        _arguments \
234-        $_installopts \
235-        $_dopts \
236-        $_dev \
237-        $_no_color \
238-        $_production
239-        ;;
240-        update)
241-        _arguments \
242-        $_dopts
243-        ;;
244-        remove)
245-        _arguments \
246-        $_dopts
247-        ;;
248-        upgrade-interactive)