meta_package_manager.managers.yarn module¶

class meta_package_manager.managers.yarn.Yarn[source]¶

Bases: PackageManager

Virtual base shared by Yarn Classic and Yarn Berry.

The two Yarn lines grew incompatible CLIs, so mpm models them as separate managers, YarnClassic and YarnBerry, both invoking the same yarn binary. The reported version decides which one is active: Classic claims the 1.x range, Berry 2.x and later. Only the shared cache-cleanup operation lives on this base.

Command equivalences with the sibling JS managers are listed in antfu-collective/ni.

Initialize cli_errors list.

homepage_url: str | None = 'https://yarnpkg.com'¶

Home page of the project, only used in documentation for reference.

Slug of the brand mark standing for this manager in the documentation.

Names an SVG vendored under docs/assets/managers/, whose provenance and license are recorded in docs/assets/managers/logos.yaml. Inlined at the top of the manager’s page by meta_package_manager._docs; a manager leaving it unset keeps the page’s default package glyph.

Several managers legitimately share one slug, either because they wrap the same upstream (brew and cask) or because the tool has no mark of its own and its ecosystem’s stands in (apt under Debian’s swirl, cargo under Rust’s gear). Documentation-only, like homepage_url: no CLI output reads it.

platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='aix', name='IBM AIX'), Platform(id='almalinux', name='AlmaLinux'), Platform(id='alpine', name='Alpine Linux'), Platform(id='altlinux', name='ALT Linux'), Platform(id='amzn', name='Amazon Linux'), Platform(id='android', name='Android'), Platform(id='arch', name='Arch Linux'), Platform(id='buildroot', name='Buildroot'), Platform(id='cachyos', name='CachyOS'), Platform(id='centos', name='CentOS'), Platform(id='chromeos', name='ChromeOS'), Platform(id='clearlinux', name='Clear Linux OS'), Platform(id='cloudlinux', name='CloudLinux OS'), Platform(id='cygwin', name='Cygwin'), Platform(id='debian', name='Debian'), Platform(id='dragonfly_bsd', name='DragonFly BSD'), Platform(id='endeavouros', name='EndeavourOS'), Platform(id='exherbo', name='Exherbo Linux'), Platform(id='fedora', name='Fedora'), Platform(id='freebsd', name='FreeBSD'), Platform(id='generic_linux', name='Generic Linux'), Platform(id='gentoo', name='Gentoo Linux'), Platform(id='guix', name='Guix System'), Platform(id='haiku', name='Haiku'), Platform(id='hurd', name='GNU/Hurd'), Platform(id='ibm_powerkvm', name='IBM PowerKVM'), Platform(id='illumos', name='illumos'), Platform(id='kali', name='Kali Linux'), Platform(id='kvmibm', name='KVM for IBM z Systems'), Platform(id='linuxmint', name='Linux Mint'), Platform(id='macos', name='macOS'), Platform(id='mageia', name='Mageia'), Platform(id='mandriva', name='Mandriva Linux'), Platform(id='manjaro', name='Manjaro Linux'), Platform(id='midnightbsd', name='MidnightBSD'), Platform(id='netbsd', name='NetBSD'), Platform(id='nixos', name='NixOS'), Platform(id='nobara', name='Nobara'), Platform(id='openbsd', name='OpenBSD'), Platform(id='opensuse', name='openSUSE'), Platform(id='openwrt', name='OpenWrt'), Platform(id='oracle', name='Oracle Linux'), Platform(id='os400', name='IBM i'), Platform(id='parallels', name='Parallels'), Platform(id='pidora', name='Pidora'), Platform(id='pikaos', name='PikaOS'), Platform(id='raspbian', name='Raspbian'), Platform(id='rhel', name='RedHat Enterprise Linux'), Platform(id='rocky', name='Rocky Linux'), Platform(id='scientific', name='Scientific Linux'), Platform(id='slackware', name='Slackware'), Platform(id='sles', name='SUSE Linux Enterprise Server'), Platform(id='slitaz', name='SliTaz GNU/Linux'), Platform(id='solaris', name='Solaris'), Platform(id='sourcemage', name='Source Mage GNU/Linux'), Platform(id='sunos', name='SunOS'), Platform(id='tuxedo', name='Tuxedo OS'), Platform(id='ubuntu', name='Ubuntu'), Platform(id='ultramarine', name='Ultramarine'), Platform(id='void', name='Void Linux'), Platform(id='windows', name='Windows'), Platform(id='wsl1', name='Windows Subsystem for Linux v1'), Platform(id='wsl2', name='Windows Subsystem for Linux v2'), Platform(id='xenserver', name='XenServer')})¶

List of platforms supported by the manager.

Allows for a mishmash of platforms and groups of platforms. Will be normalized into a frozenset of Platform instances at instantiation.

virtual: bool = True¶

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

cleanup_cache()[source]¶

Removes things we don’t need anymore.

See yarn cache clean.

$ yarn cache clean --all
yarn cache v1.22.19
success Cleared cache.
✨  Done in 0.35s.
Return type:

None

cli_names: tuple[str, ...] = ('yarn',)¶

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

id: str = 'yarn'¶

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'Yarn'¶

Return package manager’s common name.

Default value is based on class name.

class meta_package_manager.managers.yarn.YarnClassic[source]¶

Bases: Yarn

Yarn Classic, the 1.x line.

mpm claims this class for any yarn binary reporting a 1.x version and drives it through the yarn global command family, so installs, upgrades and removals target the global prefix. Its --json output is a stream of one JSON object per line, not a single document, so every query is parsed line by line.

Note

Yarn has no dedicated search command by maintainer decision, so search is simulated with yarn info and only resolves exact package names.

Initialize cli_errors list.

maintenance_note: str | None = 'Yarn Classic (`1.x`) is [frozen](https://github.com/yarnpkg/yarn), taking only security fixes; the actively developed [Yarn Berry](https://github.com/yarnpkg/berry) line has a different CLI and is wrapped separately as the `yarn-berry` manager.'¶

A watch note about a still-maintained upstream whose activity is slowing or whose status is ambiguous, as a MyST markdown block.

Unlike unmaintained, this is purely informational: the manager stays in the default selection and in the test matrices. It renders as a {note} admonition atop the manager’s documentation page, flagging upstreams worth keeping an eye on (a slow release cadence, superseded-but-still-shipped tools, a discontinued platform still under vendor support). May embed markdown links. Mutually exclusive with unmaintained: a confirmed-dead manager carries an unmaintained_message instead. Enforced by test_maintenance_note.

id: str = 'yarn'¶

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'Yarn Classic'¶

Return package manager’s common name.

Default value is based on class name.

requirement: str | None = '>=1.20.0,<2.0.0'¶

Version requirement specifier.

Supports a comma-separated range of constraints (e.g. ">=1.20.0,<2.0.0"). A bare version string like "1.20.0" is treated as >=1.20.0.

Parsed by meta_package_manager.version.VersionRange.

Defaults to None, which deactivates version check entirely.

cli_names: tuple[str, ...] = ('yarn',)¶

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

pre_args: tuple[str, ...] = ('--silent',)¶
property installed: Iterator[Package]¶

Fetch installed packages.

$ yarn global --json list --depth 0
{"type":"activityStart","data":{"id":0}}
{"type":"activityTick","data":{"id":0,"name":"awesome-lint@^0.18.0"}}
{"type":"activityTick","data":{"id":0,"name":"arrify@^2.0.1"}}
{"type":"activityTick","data":{"id":0,"name":"case@^1.6.3"}}
{"type":"activityTick","data":{"id":0,"name":"emoji-regex@^9.2.0"}}
{"type":"activityEnd","data":{"id":0}}
{"type":"progressStart","data":{"id":0,"total":327}}
{"type":"progressTick","data":{"id":0,"current":1}}
{"type":"progressTick","data":{"id":0,"current":2}}
{"type":"progressTick","data":{"id":0,"current":3}}
{"type":"progressTick","data":{"id":0,"current":4}}
{"type":"progressTick","data":{"id":0,"current":5}}
{"type":"progressFinish","data":{"id":0}}
{"type":"info","data":""[email protected]" has binaries:"}
{"type":"list","data":{"type":"bins-awesome-lint","items":["awesome-lint"]}}
$ yarn global list --depth 0
yarn global v1.22.19
info "[email protected]" has binaries:
   - awesome-lint
✨  Done in 0.13s.
property global_dir: str[source]¶

Locate the global directory.

$ yarn global dir
~/.config/yarn/global
property outdated: Iterator[Package]¶

Fetch outdated packages.

Yarn emits its --json output as a stream of one JSON object per line (the sample below elides the info color-legend object; the human-readable transcript further down shows it):

$ yarn --json outdated --cwd ~/.config/yarn/global
{"type":"warning","data":"package.json: No license field"}
{"type":"table","data":{"head":["Package","Current","Wanted","Latest","Package Type","URL"],"body":[["markdown","0.4.0","0.4.0","0.5.0","dependencies","git://github.com/evilstreak/markdown-js.git"]]}}
$ yarn outdated --cwd ~/.config/yarn/global
yarn outdated v1.22.19
warning package.json: No license field
info Color legend :
"<red>"    : Major Update backward-incompatible updates
"<yellow>" : Minor Update backward-compatible features
"<green>"  : Patch Update backward-compatible bug fixes
Package  Current Wanted Latest Package Type URL
markdown 0.4.0   0.4.0  0.5.0  dependencies git://github.com/.../md-js.git
✨  Done in 0.95s.
search(query, extended, exact)[source]¶

Fetch matching packages.

Warning

Yarn maintainers have decided to not implement a dedicated search command.

Search is simulated by a direct call to yarn info, and as a result only works for exact match.

$ yarn --json info python | jq
{
  "type": "inspect",
  "data": {
    "name": "python",
    "description": "Interact with python child process",
    "dist-tags": {
      "latest": "0.0.4"
    },
    "versions": [
      "0.0.0",
      "0.0.1",
      "0.0.2",
      "0.0.3",
      "0.0.4"
    ],
    "maintainers": [
      {
        "name": "drderidder",
        "email": "[email protected]"
      }
    ],
    "time": {
      "modified": "2017-09-16T05:26:13.151Z",
      "created": "2011-07-11T01:59:04.362Z",
      "0.0.0": "2011-07-11T01:59:05.137Z",
      "0.0.1": "2011-07-17T05:23:33.166Z",
      "0.0.2": "2011-07-20T03:42:50.379Z",
      "0.0.3": "2014-06-08T00:39:08.562Z",
      "0.0.4": "2015-01-25T02:48:07.820Z"
    },
    "author": {
      "name": "Darren DeRidder"
    },
    "repository": {
      "type": "git",
      "url": "git://github.com/73rhodes/node-python.git"
    },
    "homepage": "https://github.com/73rhodes/node-python",
    "bugs": {
      "url": "https://github.com/73rhodes/node-python/issues"
    },
    "readmeFilename": "README.md",
    "users": {
      "dewang-mistry": true,
      "goliatone": true,
      "sapanbhuta": true,
      "aditcmarix": true,
      "imlucas": true,
      "heyderpd": true,
      "ukuli": true,
      "chbardel": true,
      "asaupup": true,
      "nuwaio": true
    },
    "version": "0.0.4",
    "main": "./lib/python.js",
    "engines": {
      "node": ">= 0.4.1"
    },
    "gitHead": "69754aaa57658193916a1bf5fc391198098f74f6",
    "scripts": {},
    "dist": {
      "shasum": "3094e898ef17a33aa9c3e973b3848a38e47d1818",
      "tarball": "https://registry.npmjs.org/python/-/python-1.tgz"
    },
    "directories": {}
  }
}
Return type:

Iterator[Package]

install(package_id, version=None)[source]¶

Install one package.

$ yarn --silent global add awesome-lint
yarn global v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] đźšš  Fetching packages...
[3/4] đź”—  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Installed "[email protected]" with binaries:
    - awesome-lint
✨  Done in 16.15s.
Return type:

str

upgrade_all_cli()[source]¶

Generates the CLI to upgrade all outdated packages.

$ yarn --silent global upgrade --latest
yarn global v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] đźšš  Fetching packages...
[3/4] đź”—  Linking dependencies...
[4/4] 🔨  Rebuilding all packages...
success Saved lockfile.
success Saved 271 new dependencies.
info Direct dependencies
├─ [email protected]
└─ [email protected]
info All dependencies
├─ @babel/[email protected]
├─ @babel/[email protected]
├─ @nodelib/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
(...)
└─ [email protected]
✨  Done in 19.89s.
Return type:

tuple[str, ...]

upgrade_one_cli(package_id, version=None)[source]¶

Generates the CLI to upgrade the provided package.

$ yarn --silent global upgrade markdown --latest
yarn global v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] đźšš  Fetching packages...
[3/4] đź”—  Linking dependencies...
[4/4] 🔨  Rebuilding all packages...
success Saved lockfile.
success Saved 2 new dependencies.
info Direct dependencies
└─ [email protected]
info All dependencies
├─ [email protected]
└─ [email protected]
✨  Done in 1.77s.
Return type:

tuple[str, ...]

remove(package_id)[source]¶

Remove one package.

$ yarn --silent global remove awesome-lint
yarn global v1.22.19
[1/2] đź—‘  Removing module awesome-lint...
[2/2] 🔨  Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
✨  Done in 0.21s.
Return type:

str

virtual: bool = False¶

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

class meta_package_manager.managers.yarn.YarnBerry[source]¶

Bases: Yarn

Yarn Berry, the 2.x and later line.

mpm claims this class for any yarn binary reporting a 2.x or newer version.

Warning

Yarn Berry removed the yarn global command family entirely: it has no notion of globally installed packages. Only search is available, while installed, outdated, install, upgrade and remove are all unsupported.

Note

search is simulated with yarn npm info and only resolves exact package names.

Initialize cli_errors list.

id: str = 'yarn-berry'¶

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'Yarn Berry'¶

Return package manager’s common name.

Default value is based on class name.

requirement: str | None = '>=2.0.0'¶

Version requirement specifier.

Supports a comma-separated range of constraints (e.g. ">=1.20.0,<2.0.0"). A bare version string like "1.20.0" is treated as >=1.20.0.

Parsed by meta_package_manager.version.VersionRange.

Defaults to None, which deactivates version check entirely.

cli_names: tuple[str, ...] = ('yarn',)¶

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

search(query, extended, exact)[source]¶

Fetch matching packages.

Warning

Search is simulated by a direct call to yarn npm info, and as a result only works for exact match.

$ yarn npm info python --json | jq
{
  "name": "python",
  "description": "Interact with python child process",
  "dist-tags": {
    "latest": "0.0.4"
  },
  "versions": [
    "0.0.0",
    "0.0.1",
    "0.0.2",
    "0.0.3",
    "0.0.4"
  ],
  "version": "0.0.4",
  (...)
}
Return type:

Iterator[Package]

virtual: bool = False¶

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.