Yarn Documentation

website·Indexed 18 days ago

https://yarnpkg.com/

Documentation for the Yarn package manager, covering Yarn Modern and migration from Yarn Classic (1.x). Includes guides on Plug'n'Play (PnP), workspace management, configuration via .yarnrc.yml, and various dependency protocols such as npm:, git:, patch:, and portal:. It also provides details on CLI usage, plugin development, and Corepack installation.

Tokens
203.9K
Snippets
1.7K
Records
2.2K
Agent score
96%

What's inside Yarn

  1. Overview of GithubFetcher

    The GithubFetcher class is responsible for taking a package locator and fetching its file data from GitHub. It implements the Fetcher interface from yarnpkg-core. Fetchers generally translate a locator into a set of files on disk, which may be actual filesystem paths or virtual paths (e.g., files inside a zip archive).
  2. Overview of Yarn Plug'n'Play (PnP) Installation Plugin

    The PnP installation plugin adds support for installing packages according to the Plug'n'Play specification. This plugin is included by default in Yarn.
  3. Overview of PnpLinker

    PnpLinker acts as the glue between the logical dependency tree and its representation on the filesystem. Its primary purpose is to take package data and place it on the filesystem in a format compatible with the target environment (such as generating a .pnp.cjs file for Node.js). Multiple linkers can coexist within the same dependency tree, allowing a single tree to contain packages managed by different linkers.
  4. Overview of PnpmLinker

    The PnpmLinker class implements the Linker interface. Linkers act as the glue between the logical dependency tree and its representation on the filesystem. Their primary purpose is to take package data and place it on the filesystem in a format compatible with the target environment (e.g., generating a .pnp.cjs file for Node). Multiple linkers can coexist within the same dependency tree, allowing a single tree to contain packages from different linkers.
  5. Overview of TarballFileFetcher

    The TarballFileFetcher is a component responsible for taking a locator and fetching its associated file data. Fetchers abstract the source of the package data; for example, an npm fetcher downloads from a registry, while a workspace fetcher provides a link to the local filesystem.
  6. Overview of the NoFS class

    The NoFS class is part of the yarnpkg-fslib library and inherits from FakeFS and PortablePath. It provides a standardized file system interface where many operations are intentionally disabled (returning never or Promise<never>), making it suitable for environments where file system access should be restricted or mocked as non-functional.
  7. Overview of Yarn Resolver data structures

    Resolvers transform a package range (e.g., webpack@^4.0.0) into a specific resolution (e.g., webpack@4.28.0) using three primary data structures:

    • Descriptors: Contain a package name and a range. A descriptor alone is insufficient to fetch package data as it may point to multiple resolutions.
    • Locators: Contain a package name and a unique reference used to identify and fetch a package from its remote location. Locators also function as valid descriptors.
    • Packages: Expanded locators that contain full package definitions, including the dependency list.
  8. Overview of Yarn JavaScript constraints

    Constraints allow the enforcement of rules across workspace packages. Currently, the engine supports enforcing rules on workspace dependencies and arbitrary package.json fields. It does not currently support transitive dependencies or project structure. Constraints are defined using a declarative model: you specify the expected state, and Yarn either reports a mismatch or automatically fixes it when running yarn constraints --fix.
  9. Overview of LockfileResolver and Package Resolution

    The LockfileResolver is responsible for transforming package descriptors (e.g., webpack@^4.0.0) into specific package resolutions (e.g., webpack@4.28.0) to produce a lockfile. It utilizes three primary data structures:

    • Descriptors: Contain a package name and a range (e.g., ^4.0.0). A descriptor identifies what is needed but not necessarily a unique remote location.
    • Locators: Contain a package name and a unique reference (e.g., 4.28.0) used to identify and fetch a package from its remote location. Locators also function as valid descriptors.
    • Packages: Full package definitions derived from locators, containing detailed information such as the package's dependency list.
  10. Overview of Yarn package manager

    Yarn is an open-source package manager for JavaScript projects used to install, update, configure, and remove package dependencies. It is designed for speed, correctness, and security, offering features such as workspaces, offline caching, parallel installs, and hardened mode. Unlike many other package managers, Yarn reimplements all commands rather than deferring to npm, ensuring full control over stability and the developer experience.
  11. Overview of Yarn Resolver concepts

    Resolvers are responsible for transforming a package range (e.g., webpack@^4.0.0) into a specific resolved package (e.g., webpack@4.28.0) with its dependencies. They utilize three primary data structures:

    • Descriptors: Contain a package name and a range (e.g., ^4.0.0). A descriptor is not sufficient to fetch package data as it may point to multiple versions.
    • Locators: Contain a package name and a unique reference (e.g., 4.28.0) used to identify and fetch the package. Locators are also valid descriptors.
    • Packages: Full package definitions derived from locators, containing detailed information such as the dependency list.