Repository navigation
feat(engines): support .node-version and .python-version - #490
Conversation
Both fields make Yarn add the matching builtin package (@yarnpkg/node, @yarnpkg/python) to the dependencies of the root workspace, and expose their binaries in the PATH of every package of the project (workspaces and dependency build scripts alike) without adding them to their dependencies. @yarnpkg/python is a new builtin package providing the python-build-standalone CPython builds. The release a build comes from is stored as prerelease of its locator (3.13.1-20241206), so that the lockfile always describes the same artifacts. yarn init now sets devEngines.node to the latest Node.js release.
✅ Deploy Preview for yarn-v6 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…ands Islands without their own pythonVersion now resolve their PyPI packages for the Python version devEngines.python resolves to (from the lockfile when it pins a build, otherwise by resolving the range upfront, since islands resolve in parallel with the rest of the project), instead of the global pythonVersion setting. Their venvs are also created from the installed @yarnpkg/python build rather than from an interpreter looked up on the system or downloaded separately. An island with its own pythonVersion keeps the previous behavior.
--node-version writes the given range to devEngines.node instead of looking up the latest Node.js release, and --no-node-version leaves the field out.
Relies on arcanis/clipanion-rs#12, which applies the default of Option<T> options: not passing --node-version now means the latest release, and the generated --no-node-version leaves the field out, without a separate flag.
arcanis/clipanion-rs#12 got merged, so clipanion no longer needs to point at its branch.
The workspace resolution moved into workspace_resolution (#488), which now injects the devEngines of the root workspace.
The lockfile no longer stores the workspaces (#488).
⏱️ Benchmark Resultsgatsby install-full-cold
📊 Raw benchmark data (gatsby install-full-cold)Base times: 4.360s, 4.408s, 4.273s, 4.396s, 4.348s, 4.331s, 4.251s, 4.387s, 4.320s, 4.278s, 4.472s, 4.597s, 4.261s, 4.153s, 4.314s, 4.441s, 4.243s, 4.267s, 4.310s, 4.259s, 4.197s, 4.327s, 4.240s, 4.324s, 4.244s, 4.354s, 4.316s, 4.332s, 4.363s, 4.252s Head times: 4.361s, 4.236s, 4.268s, 4.390s, 4.405s, 4.440s, 4.298s, 4.256s, 4.344s, 4.310s, 4.353s, 4.368s, 4.374s, 4.291s, 4.403s, 4.348s, 4.400s, 4.289s, 4.274s, 4.306s, 4.443s, 4.677s, 4.363s, 4.478s, 4.344s, 4.437s, 4.408s, 4.618s, 4.369s, 4.374s gatsby install-cache-only
📊 Raw benchmark data (gatsby install-cache-only)Base times: 1.691s, 1.430s, 1.492s, 1.468s, 1.450s, 1.432s, 1.441s, 1.436s, 1.450s, 1.513s, 1.443s, 1.434s, 1.419s, 1.482s, 1.428s, 1.691s, 1.533s, 1.464s, 1.476s, 1.436s, 1.436s, 1.457s, 1.446s, 1.440s, 1.468s, 1.511s, 1.421s, 1.447s, 1.486s, 1.466s Head times: 1.464s, 1.438s, 1.439s, 1.442s, 1.469s, 1.429s, 1.464s, 1.456s, 1.517s, 1.415s, 1.474s, 1.470s, 1.445s, 1.922s, 1.569s, 1.735s, 1.410s, 1.458s, 1.558s, 1.483s, 1.405s, 1.421s, 1.452s, 1.459s, 1.449s, 1.479s, 1.462s, 1.444s, 1.462s, 1.448s gatsby install-cache-and-lock (warm, with lockfile)
📊 Raw benchmark data (gatsby install-cache-and-lock (warm, with lockfile))Base times: 0.350s, 0.349s, 0.355s, 0.351s, 0.352s, 0.359s, 0.356s, 0.488s, 0.360s, 0.357s, 0.362s, 0.357s, 0.364s, 0.353s, 0.356s, 0.361s, 0.361s, 0.362s, 0.360s, 0.356s, 0.360s, 0.416s, 0.364s, 0.366s, 0.370s, 0.366s, 0.370s, 0.362s, 0.360s, 0.364s Head times: 0.350s, 0.359s, 0.360s, 0.349s, 0.348s, 0.348s, 0.343s, 0.348s, 0.348s, 0.343s, 1.062s, 0.667s, 0.808s, 0.352s, 0.351s, 0.351s, 0.354s, 0.351s, 0.354s, 0.353s, 0.353s, 0.358s, 0.358s, 0.370s, 0.352s, 0.360s, 0.362s, 0.357s, 0.372s, 0.360s |
Cargo.lock is main's, with clipanion moved to the commit of arcanis/clipanion-rs#12.
Adds lazy dependencies: packages that are only downloaded once one of
their binaries is called. The typical case is `@yarnpkg/node` (100+ MB):
with it lazy, fresh clones whose scripts never run JavaScript don't
download it.
## Declaring them
```json
{
"dependenciesMeta": {
"@yarnpkg/node": {"lazy": true}
}
}
```
- `dependenciesMeta.<name>.lazy` in the root manifest, next to `built`
and `unplugged`. It accepts the same keys (globs, `name@range`).
- Variants of a lazy package (the per-platform builds of
`@yarnpkg/node`) are lazy too.
## What installs do
- Lazy packages are resolved and locked like any other package.
- They're downloaded when they're added to the project, so the lockfile
records their checksum. A later download therefore never changes
`yarn.lock`.
- They're also installed normally when they're already in the cache.
- Otherwise the install skips them. It reuses the existing path for
packages built for other platforms (`MissingZip`), which the linkers
already skip.
- `yarn install --fetch-lazy` downloads all of them, for example when
preparing a CI image or before working offline.
## Binaries in the lockfile
`Resolution` gets a `bin` field (name → path in the package), filled at
resolution time:
- npm packages: the registry metadata (`bin` was already kept in the
metadata cache);
- `@yarnpkg/node`: its known binary (`node`);
- folders, tarballs, git, etc.: their manifest.
To support this, `bin` moved from `Manifest` to `RemoteManifest`, which
`Manifest` flattens, so manifests serialize the same.
This changes lockfiles: entries of packages with binaries gain a `bin`
field when they're next resolved. Entries reused from an existing
lockfile are left alone. A lazy package whose resolution doesn't list
binaries (an old lockfile entry, or a PyPI package, whose entry points
are only known from the wheel) is downloaded normally.
## Downloading on first use
- Until the package is downloaded, its binaries are exposed as
`Binary::Lazy`. Their PATH wrapper calls a new internal command, `yarn
debug run-lazy-binary <project> <locator> <name> …args`.
- That command downloads the package, checks it against the lockfile
checksum when there is one, and extracts it to a fixed location. It then
`exec`s the binary in the caller's folder and environment, through
`node` for JS binaries.
- The location is the one the linker reserved for the package during the
last install, recorded in the install state like any other package
location: its unplugged folder with PnP (the PnP linker forces lazy
packages to be unplugged), its hoisted folder in `node_modules` with
`node-modules`, and its store folder with `pnpm`. Each linker keeps
whatever gets extracted there instead of deleting it, so there's no
second copy anywhere, and the package can be `require`d as soon as it's
downloaded.
- No install runs during this, so a build script can call a lazy binary
while an install is running it. That's tested with a `postinstall` that
runs `node`.
- The folder may already hold the packages nested inside it. The
extraction goes through a temporary folder, moves the entries that
aren't there yet, and writes a marker last.
- Concurrent calls download the package once. The download holds an
exclusive lock on `.yarn/ignore/lazy-locks/<package>.lock`
(`File::lock`). The other processes wait for it, then find the package
ready.
- A progress bar is drawn on stderr while this happens, only when stderr
is a terminal and `enableProgressBars` is on, since the binary's stdout
may be read by another program. It shows the bytes received (the HTTP
client adds them to a task-local counter that the download sets up),
then the conversion and the extraction. A spinner replaces it when the
package comes from a mirror, and a waiting message shows when another
process is downloading the package.
- Once extracted, the binaries point straight at the package, so the
wrapper is no longer involved.
- The up-to-date check notices lazy packages that have been downloaded
since the last install, so the next install links them normally
(binaries in `node_modules/.bin`, build scripts, ...).
- `yarn bin <name>` downloads the package before printing the path.
`yarn bin --json` prints where the binary will be without downloading
it.
## Tests
`features/lazyDependencies.test.ts` (11 tests):
- a lazy package is downloaded when added, and not on a fresh clone
until called;
- the lockfile is unchanged after the download;
- packages found in the cache are installed normally;
- `--fetch-lazy` downloads them;
- a build script triggers the download during an install;
- `yarn bin` triggers the download;
- lazy npm packages with PnP, `node-modules` and `pnpm`, including a
binary that `require`s a dependency of its package, and requiring the
package right after its download;
- downloaded lazy packages are kept by the following installs;
- three parallel calls download the package once. The test registry now
counts Node.js downloads; without the lock, the count is 3 every time.
Unit tests cover the progress lines. The bar itself was checked by hand
in a pseudo-terminal, with a real Node.js download and two parallel
calls.
## Not covered yet
- Lazy packages can only be used through their binaries until they're
downloaded. `require()` before that fails.
- Build scripts of a lazy package don't run when it's downloaded on
first use, only at the next install that links it.
- Making the `devEngines` packages of #490 lazy by default comes once
both PRs are merged.
---
_Generated by [Claude Code](https://claude.ai/code)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
The binaries of the engines handle the lazy packages of #491.
The packages providing the engines (@yarnpkg/node, @yarnpkg/python) are now lazy unless dependenciesMeta says otherwise: they're downloaded when added to the project, but a fresh clone only downloads them once one of their binaries is called. The Python engine stays eager when venv islands use it as interpreter, since the install needs it. The Python builds now list their binaries in the lockfile, which lazy packages need.
The playground used to only copy the packageManager field from the manifest yarn init generated in its scratch folder, so the projects missed devEngines (and whatever init adds next). The page now puts the fields of the tutorial's manifest on top of the generated one instead.
Lazy packages are downloaded when they're added to the project so that the lockfile records their checksum, but the lockfile doesn't record the checksums of the packages that only apply to some systems (such as the per-platform builds of @yarnpkg/node). Those are now only downloaded once their binaries are called, which spares the playground (and any yarn init) a Node.js download it had no use for.
Projects get Node.js through the devEngines field yarn init sets, so the tutorial no longer starts from a missing Node.js: it shows the lazy download on first use, who depends on the engine, and how a workspace pins another release. The remarks of the other tutorials about the sandbox not having Node.js are updated as well.
devEngines only allows a single runtime per the spec, which doesn't fit projects with both Node.js and Python. The engines now come from the .node-version and .python-version files at the root of the project (the ones nvm, fnm, pyenv and uv read too), and devEngines is no longer read. The engines are stored in the lockfile's project section, since they change the dependencies of the root workspace without its manifest saying so; --since compares them like the other project rules. Versions Yarn can't install (lts/*, system, ...) are ignored with a warning. yarn init now writes the latest Node.js major to .node-version.
Reading a missing file builds an error (and captures its backtrace) before ok_missing turns it into None; most projects have no version files, so checking first avoids that cost on every command.
A .node-version or .python-version file in the folder of one of the workspaces of an island overrides the one at the root of the project for that island. Its engines are development dependencies of the island's workspaces, resolved by the island solver; the Python one also sets the Python version the island's PyPI packages are resolved for and its venvs are created from. Venv islands install builtin packages next to the venvs rather than in site-packages.
Adds support for declaring the project's Node.js and Python through
.node-versionand.python-versionfiles at its root. These are the same files nvm, fnm, pyenv and uv read.This started as
devEngines.node/devEngines.pythonsupport. Per the spec,devEnginesonly has a singleruntimefield, which doesn't fit projects with both Node.js and Python, so the engines now come from the version files anddevEnginesis no longer read.What the engines do
@yarnpkg/node@builtin:<version>,@yarnpkg/python@builtin:<version>) to the dependencies of the root workspace. It's treated like a dev dependency, so production installs skip it. A root workspace that declares the package itself (or gets it from a profile) keeps its own declaration.node;pythonandpython3) are visible from every package: root scripts, scripts of other workspaces, and dependency build scripts. Those packages don't get them as dependencies. A package whose own dependencies include@yarnpkg/nodeuses its own version.dependenciesMeta["@yarnpkg/node"].lazy: falseturns this off. The Python engine stays eager when venv islands use it as their interpreter.yarn init(and the playground) a Node.js download.pythonVersion. Their PyPI packages are resolved for it and their venvs are created from it. Islands can also have version files of their own (see below).The version files
24means the latest 24.x,24.11.1that exact release. Thev24andcpython-3.13prefixes are accepted.lts/*,system,pypy3.10, …) is ignored with a warning, since other tools may understand it.projectsection ("engines": {"node": "24"}), because they change the root workspace's dependencies without its manifest saying so. feat(lockfile): read the workspaces from their manifests instead of storing them #488's consistency check requires that, and--sincecompares them between revisions like the other project rules.Island version files
An island can have its own
.node-version/.python-version, in the folder of one of its workspaces. For that island they override the files at the project root; the other workspaces keep the project's engines.islands. Their binaries take precedence over the project engines in the island's scripts. They're downloaded with the rest of the island, not lazily.pythonVersionsetting, then its own.python-version, then the project's.python-version, then the globalpythonVersion. The island's own.python-versionis resolved before the island so its PyPI packages are solved for that version. Its locked build comes from the island's part of the lockfile.site-packages. They're extracted once to.yarn/ignore/island-builtins/<slug>and shared by the island's venvs. An island with its own.python-versioncreates its venvs from that build.@yarnpkg/pythonThis is a new builtin package providing the python-build-standalone CPython builds, with one variant per platform. Builds are downloaded from
pythonDownloadMirrorand checked against the release'sSHA256SUMS.@yarnpkg/python@builtin:3.13.18-20261124), while the package version stays3.13.18.3.12.1-20240101.yarn inityarn initwrites.node-versionwith the latest Node.js major, unless the file exists.--node-version=<version>writes something else;latestis the default.--no-node-versionwrites no file. This relies on fix(derive): apply the default of Option<T> options arcanis/clipanion-rs#12 (merged).Playground
yarn initgenerates, with the tutorial's fields on top, and get the.node-versionit writes.Tests
features/engines.test.ts(29 tests, 7 of them for island version files),commands/init.test.ts, and updatedlazyDependenciestests.Generated by Claude Code