Skip to content

feat(engines): support .node-version and .python-version - #490

Merged
arcanis merged 16 commits into
mainfrom
claude/happy-hawking-hzclty
Dec 1, 2026
Merged

arcanis merged 16 commits into
mainfrom
claude/happy-hawking-hzclty

Conversation

@arcanis

@arcanis arcanis commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Adds support for declaring the project's Node.js and Python through .node-version and .python-version files at its root. These are the same files nvm, fnm, pyenv and uv read.

echo 24 > .node-version
echo 3.13 > .python-version

This started as devEngines.node / devEngines.python support. Per the spec, devEngines only has a single runtime field, which doesn't fit projects with both Node.js and Python, so the engines now come from the version files and devEngines is no longer read.

What the engines do

  • Root dependency: each version file adds the matching builtin package (@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.
  • PATH injection: the engine binaries (node; python and python3) 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/node uses its own version.
  • Lazy by default: a fresh clone only downloads an engine the first time one of its binaries is called (feat(install): add lazy dependencies #491). dependenciesMeta["@yarnpkg/node"].lazy: false turns this off. The Python engine stays eager when venv islands use it as their interpreter.
  • Platform-specific lazy packages (like the Node.js builds) are no longer downloaded when added to the project. The lockfile doesn't record their checksums, so there was nothing to download them for. This also spares yarn init (and the playground) a Node.js download.
  • Islands: the Python engine is the Python version of islands that don't set their own 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

  • Yarn reads the first non-comment line as a semver range: 24 means the latest 24.x, 24.11.1 that exact release. The v24 and cpython-3.13 prefixes are accepted.
  • Content Yarn can't install (lts/*, system, pypy3.10, …) is ignored with a warning, since other tools may understand it.
  • The engines are stored in the lockfile's project section ("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 --since compares them between revisions like the other project rules.
  • They're also part of the install configuration hash, so editing a version file triggers a reinstall on the next command.

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.

  • The island's engines become dev dependencies of its workspaces, so the island solver resolves them and the lockfile records them under 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.
  • An island has a single version of each engine. If two of its workspaces have different files, the install fails with an error.
  • Python version precedence for an island is: its pythonVersion setting, then its own .python-version, then the project's .python-version, then the global pythonVersion. The island's own .python-version is 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.
  • Venv islands no longer put builtin packages into 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-version creates its venvs from that build.

@yarnpkg/python

This is a new builtin package providing the python-build-standalone CPython builds, with one variant per platform. Builds are downloaded from pythonDownloadMirror and checked against the release's SHA256SUMS.

  • The same Python version is rebuilt in several python-build-standalone releases. To keep the lockfile deterministic, the release tag is stored as the prerelease part of the locator (@yarnpkg/python@builtin:3.13.18-20261124), while the package version stays 3.13.18.
  • Ranges resolve against the latest release. To pin a build from an older release, use a version like 3.12.1-20240101.

yarn init

Playground

  • Projects now start from the full manifest yarn init generates, with the tutorial's fields on top, and get the .node-version it writes.
  • Tutorial 15 now teaches the version file: Node.js downloaded on first use, who depends on it, and pinning another release for one workspace. The remarks in tutorials 3 and 6 about the sandbox having no Node.js were updated.

Tests

  • features/engines.test.ts (29 tests, 7 of them for island version files), commands/init.test.ts, and updated lazyDependencies tests.
  • Unit tests cover the version-file parsing.
  • The website's tutorial loader accepts all 20 tutorials.

Generated by Claude Code

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.
@netlify

netlify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for yarn-v6 ready!

Name Link
🔨 Latest commit 62af741
🔍 Latest deploy log https://app.netlify.com/projects/yarn-v6/deploys/6b0e859dbbe4ccec2678618c
😎 Deploy Preview https://deploy-preview-490--yarn-v6.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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).
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

⏱️ Benchmark Results

gatsby install-full-cold

Metric Base Head Difference
Mean 4.321s 4.374s +1.24% ⚠️
Median 4.318s 4.365s +1.10% ⚠️
Min 4.153s 4.236s
Max 4.597s 4.677s
Std Dev 0.088s 0.096s
📊 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

Metric Base Head Difference
Mean 1.473s 1.485s +0.79% ⚠️
Median 1.450s 1.459s +0.58% ⚠️
Min 1.419s 1.405s
Max 1.691s 1.922s
Std Dev 0.066s 0.103s
📊 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)

Metric Base Head Difference
Mean 0.366s 0.403s +10.32% ⚠️
Median 0.360s 0.353s -1.82% ✅
Min 0.349s 0.343s
Max 0.488s 1.062s
Std Dev 0.026s 0.159s
📊 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.
arcanis added a commit that referenced this pull request Nov 30, 2026
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.
@arcanis arcanis changed the title feat(engines): support devEngines.node and devEngines.python feat(engines): support .node-version and .python-version Nov 30, 2026
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.
@arcanis
arcanis merged commit 5c33053 into main Dec 1, 2026
25 checks passed
@arcanis
arcanis deleted the claude/happy-hawking-hzclty branch December 1, 2026 09:36

This branch was successfully deployed

1 active deployment
test-reports — 62af741b Deployed Dec 1, 2026 by arcanis via Reporting test results #1820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants