yarn
Manage and install JavaScript package dependencies
TLDR
Install a module globally
Install all dependencies referenced in the package.json file (the install is optional)
Install a module and save it as a dependency to the package.json file (add --dev to save as a dev dependency)
Uninstall a module and remove it from the package.json file
Interactively create a package.json file
Identify whether a module is a dependency and list other modules that depend upon it
SYNOPSIS
yarn [command] [arguments]
PARAMETERS
add [package names]
Adds one or more packages as dependencies to your project.
install
Installs all dependencies listed in your project's package.json and yarn.lock files.
remove [package names]
Removes one or more packages from your project's dependencies.
upgrade [package names]
Upgrades one or more packages to their latest available version, based on your specified version ranges.
cache
Used to manage the global package cache. Subcommands include 'clean', 'dir', and 'list'.
config
Used to set and retrieve Yarn configuration settings. Subcommands include 'get', 'set', and 'delete'.
init
Initializes a new yarn project, creating a package.json file.
run [script]
Runs a script defined in the package.json file.
DESCRIPTION
Yarn is a package manager for your code. It allows you to automate the process of installing, updating, configuring, and removing NPM packages used in a project. Yarn caches every downloaded package so you never need to download it again. It also does everything in parallel to maximize resource utilization, so install times are faster than ever. Yarn uses lockfiles to guarantee that an install on one system will install the same way on another system.
It can be thought of as a client-side package manager. Yarn is often used in conjunction with Node.js for JavaScript project dependency management, but it can be used with other ecosystems as well. Yarn prioritizes speed, consistency, and security, improving upon the functionality of other package managers like npm.
CAVEATS
Yarn relies on a `package.json` file in the project directory to manage dependencies. Ensure you have a properly formatted `package.json` file.
Conflicting dependencies can sometimes cause issues; resolving these conflicts might require manual intervention or the use of resolutions.
LOCKFILES
Yarn uses lockfiles (yarn.lock) to ensure deterministic installations. This means that the exact same versions of dependencies will be installed across different environments (e.g., development, staging, production). Lockfiles prevent unexpected behavior due to dependency updates.
WORKSPACES
Yarn supports workspaces, which allow you to manage multiple packages within a single repository. This is useful for monorepo setups where you have several related packages that are developed and released together.
HISTORY
Yarn was originally developed by Facebook, Google, Exponent, and Tilde to address performance and consistency issues found in npm (Node Package Manager). It was first released in October 2016.
The initial motivation was to provide faster and more reliable dependency installations. Yarn introduced features like lockfiles (`yarn.lock`) to ensure deterministic installations across different environments.
Yarn quickly gained popularity in the JavaScript community and became a widely adopted package manager, eventually influencing improvements in npm itself. The development of Yarn continues with a focus on modernizing and streamlining the package management workflow.
SEE ALSO
npm(1), package.json(5)