PluginsEdit this page on GitHub
Ever since Yarn was created, our very essence has been about experimenting, evolving, pushing the status quo - rinse and repeat, each time one step further, each time paving the way for our next move.
As you can guess, this philosophy (coupled with the high number of external contributions we receive) requires us to iterate fast in order to accommodate the various experiments that we brew. In a major step forward, Yarn got redesigned in the v2 in order to leverage a new modular API that can be extended through plugins. Nowadays, most of our features are implemented through those plugins - even
yarn add and
yarn install are preinstalled plugins!
Plugins can add new resolvers. Resolvers are the components tasked from converting dependency ranges (for example
^1.2.0) into fully-qualified package references (for example
npm:1.2.0). By implementing a resolver, you can tell Yarn which versions are valid candidates to a specific range.
Plugins can add new fetchers. Fetchers are the components that take the fully-qualified package references we mentioned in the previous step (for example
npm:1.2.0) and know how to obtain the data of the package they belong to. Fetchers can work with remote packages (for example the npm registry), but can also find the packages directly from their location on the disk (or any other data source).
Plugins can add new linkers. Once all the packages have been located and are ready for installation, Yarn will call the linkers to generate the files needed for the install targets to work properly. As an example, the PnP linker would generate the
.pnp.cjsmanifest, and a Python linker would instead generate the virtualenv files needed.
Plugins can add new commands. Each plugin can ship as many commands as they see fit, which will be injected into our CLI (also making them available through
yarn --help). Because the Yarn plugins are dynamically linked with the running Yarn process, they can be very small and guaranteed to share the exact same behavior as your package manager (which wouldn't be the case if you were to reimplement the workspace detection, for example).
Plugins can register to some events. Yarn has a concept known as "hooks", where events are periodically triggered during the lifecycle of the package manager. Plugins can register to those hooks in order to add their own logic depending on what the core allows. For example, the
afterAllInstalledhook will be called each time the
Project#installmethod ends - typically after each
Plugins can be integrated with each other. Each plugin has the ability to trigger special actions called hooks, and to register themselves to any defined hook. So for example, you could make a plugin that would execute an action each time a package is added as dependency of one of your workspaces!
We have a tutorial for this! Head over to Plugin Tutorial.
yarn plugin import <name>
stage - Adds a new command to Yarn (
yarn stage) to automatically stage & commit all changes to Yarn-related files in a single line.
yarn plugin import <bundle url>
This is just a centralized list of third-party plugins to make discovery easier. No guarantees are made as to plugin quality, compatibility, or lack of malicious code. As with all third-party dependencies, you should review them yourself before including them in your project.
yarn.build by Owen Kelly - monorepo tooling that leverages Yarn's dependency graph to run
teston whats changed in parallel as fast as possible. It also includes a command to
bundlethem up into deployable apps for Docker, AWS Lambda, or any other server. Each command is also available as an individual plugin.
yarn-plugin-envinfo by TheKnarf - yarn plugin so that you can run envinfo in your project. It'll read a project local configuration file so that different projects can ask for different info. Useful for helping new developers when onboarding them into your project.
http-proxy by Aron Tsang - yarn plugin that loads a default http Proxy Agent based on the HTTP_PROXY or HTTPS_PROXY environmental variable when running lifecycle script such as
postinstall. This is useful for allowing postinstall scripts to run in corporate environments where internet access requires an explicit HTTP Connect Proxy.
yarn-plugin-pin-deps by Splitgraph - Pin dependencies to their currently resolved exact version. This plugin will find any dependencies referenced with a semver identifier, and will update
package.jsonto replace that identifier with the exact version of the package currently resolved in the lockfile for that reference.
yarn-plugin-scripts by jgttech - Add capability to define customized scripts within the
.yarnrc.ymlfile, similar to
package.json, but more robost and similar to something like GitHub Actions. Each script can be invoked by its name, such as
yarn scripts <name_of_script>. Each script is an array of one or more commands to execute.
yarn-scripts-cache by Roman Gischkowski - A Yarn Berry plugin to cache script execution results. Previous build results can be restored, even from a remote cache server. This allows for build result sharing with a team of developers, significantly decreasing build times and eliminating downtime.
If you wrote a plugin yourself, feel free to open a PR to add it at the end of this list!