Repository navigation
feat(install): add lazy dependencies - #491
Conversation
Packages marked with dependenciesMeta.<name>.lazy are resolved and locked like any other, and downloaded when they're added to the project so the lockfile records their checksum. Installs that don't find them in the cache skip them; their binaries, now listed in the lockfile resolutions, download them on their first call and extract them to the location the linker reserved for them, without running an install (so build scripts can call them while an install runs). yarn install --fetch-lazy downloads them all.
9fe276b to
bb9d227
Compare
The node-modules and pnpm linkers now record and keep the location of the lazy packages they skip, like the PnP linker does with their unplugged folder, and downloading a lazy package extracts it there (merging with the packages nested inside it). This removes the separate .yarn/ignore/lazy copy, which nothing cleaned up, and makes the package requirable as soon as it's downloaded.
✅ Deploy Preview for yarn-v6 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…kages Downloading a lazy package now takes an exclusive lock on a file of .yarn/ignore/lazy-locks, so that concurrent calls to its binaries only download it once (the others wait, then find it ready). While it runs, a progress bar is drawn on the standard error when it's a terminal: the bytes received (reported by the HTTP client to the task that asked for them), then the conversion and the extraction, or a note that another process is downloading the package.
⏱️ Benchmark Resultsgatsby install-full-cold
📊 Raw benchmark data (gatsby install-full-cold)Base times: 5.070s, 5.111s, 5.104s, 4.973s, 4.898s, 5.113s, 5.165s, 5.076s, 4.994s, 4.895s, 5.083s, 4.921s, 5.069s, 4.969s, 5.024s, 5.037s, 4.891s, 5.314s, 5.079s, 5.061s, 5.045s, 5.020s, 4.952s, 5.080s, 5.047s, 5.088s, 5.056s, 5.127s, 5.045s, 5.239s Head times: 5.039s, 4.942s, 5.041s, 5.023s, 5.073s, 5.356s, 5.093s, 4.945s, 5.065s, 5.036s, 4.936s, 5.003s, 4.993s, 4.924s, 5.110s, 5.103s, 5.034s, 5.050s, 4.957s, 5.017s, 5.030s, 4.869s, 4.941s, 4.955s, 5.107s, 5.032s, 4.977s, 4.926s, 5.307s, 5.045s gatsby install-cache-only
📊 Raw benchmark data (gatsby install-cache-only)Base times: 1.787s, 1.789s, 1.775s, 1.803s, 1.810s, 1.808s, 1.808s, 1.800s, 1.809s, 1.803s, 1.802s, 1.840s, 1.811s, 1.805s, 1.815s, 1.776s, 1.808s, 1.812s, 1.766s, 1.795s, 1.927s, 1.803s, 1.781s, 1.804s, 1.777s, 1.757s, 1.789s, 1.810s, 1.811s, 1.813s Head times: 1.796s, 1.791s, 1.793s, 1.773s, 1.768s, 1.780s, 1.793s, 1.804s, 1.790s, 1.763s, 1.782s, 1.775s, 1.982s, 1.817s, 1.784s, 1.826s, 1.795s, 1.781s, 1.785s, 1.806s, 1.794s, 1.775s, 1.768s, 1.761s, 1.758s, 1.779s, 1.769s, 1.798s, 1.783s, 1.812s gatsby install-cache-and-lock (warm, with lockfile)
📊 Raw benchmark data (gatsby install-cache-and-lock (warm, with lockfile))Base times: 0.447s, 0.463s, 0.445s, 0.446s, 0.447s, 0.457s, 0.449s, 0.447s, 0.443s, 0.447s, 0.446s, 0.454s, 0.445s, 0.456s, 0.454s, 0.450s, 0.455s, 0.452s, 0.460s, 0.476s, 0.465s, 0.460s, 0.454s, 0.462s, 0.468s, 0.461s, 0.477s, 0.456s, 0.457s, 0.449s Head times: 0.522s, 0.511s, 0.467s, 0.467s, 0.455s, 0.468s, 0.543s, 0.566s, 0.463s, 0.467s, 0.511s, 0.497s, 0.468s, 0.510s, 0.465s, 0.460s, 0.440s, 0.509s, 0.463s, 0.453s, 0.448s, 0.444s, 0.448s, 0.452s, 0.473s, 0.450s, 0.450s, 0.449s, 0.449s, 0.443s |
The lockfile now lists the binaries of the packages, so a build without that change rewrites it, and CI (which installs the repository with the build of the pull request, immutably and in hardened mode) refuses the lockfile written by the previous one. packageManager now points to the build of this branch, and the lockfile is regenerated with it. AGENTS.md documents how to handle such changes.
yarn.lock is main's, regenerated with this branch's build (--refresh-lockfile) as described in AGENTS.md.
The binaries of the engines handle the lazy packages of #491.
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. ```bash 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 (#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. #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` - At the project root, `yarn init` writes `.node-version` with the latest Node.js major, unless the file exists. - `--node-version=<version>` writes something else; `latest` is the default. `--no-node-version` writes no file. This relies on arcanis/clipanion-rs#12 (merged). ## 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](https://claude.ai/code)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
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
{ "dependenciesMeta": { "@yarnpkg/node": {"lazy": true} } }dependenciesMeta.<name>.lazyin the root manifest, next tobuiltandunplugged. It accepts the same keys (globs,name@range).@yarnpkg/node) are lazy too.What installs do
yarn.lock.MissingZip), which the linkers already skip.yarn install --fetch-lazydownloads all of them, for example when preparing a CI image or before working offline.Binaries in the lockfile
Resolutiongets abinfield (name → path in the package), filled at resolution time:binwas already kept in the metadata cache);@yarnpkg/node: its known binary (node);To support this,
binmoved fromManifesttoRemoteManifest, whichManifestflattens, so manifests serialize the same.This changes lockfiles: entries of packages with binaries gain a
binfield 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
Binary::Lazy. Their PATH wrapper calls a new internal command,yarn debug run-lazy-binary <project> <locator> <name> …args.execs the binary in the caller's folder and environment, throughnodefor JS binaries.node_moduleswithnode-modules, and its store folder withpnpm. Each linker keeps whatever gets extracted there instead of deleting it, so there's no second copy anywhere, and the package can berequired as soon as it's downloaded.postinstallthat runsnode..yarn/ignore/lazy-locks/<package>.lock(File::lock). The other processes wait for it, then find the package ready.enableProgressBarsis 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.node_modules/.bin, build scripts, ...).yarn bin <name>downloads the package before printing the path.yarn bin --jsonprints where the binary will be without downloading it.Tests
features/lazyDependencies.test.ts(11 tests):--fetch-lazydownloads them;yarn bintriggers the download;node-modulesandpnpm, including a binary thatrequires a dependency of its package, and requiring the package right after its download;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
require()before that fails.devEnginespackages of feat(engines): support .node-version and .python-version #490 lazy by default comes once both PRs are merged.Generated by Claude Code