R
RSS new | Ribbon Flower — Hoop Size Experiments
Guest
- Thread Author
- #1
Welcome to the release notes for Yarn 3.1! We're quite excited by this release, as it brings various improvements that we've all been looking forward to. Let's dig into that!
As always, keep in mind those are only the highlights, the full changelog is much more comprehensive.
The Yarn org needs your help to make our work more sustainable! Please take a look at our OpenCollective and GitHub Sponsors pages for more details
Did you know that Yarn now ships with Node? This is done via the Node.js Corepack project, which includes both the Yarn and pnpm binaries as shims. By adding the
Note that Corepack is available starting from Node.js 16.9, but is currently opt-in. Don't forget to run
We also improved in 3.1 the
ESM has always been supported when using the
While the Loader Hook API isn't entirely stable yet, a large amount of work has been made lately and our team has been able to produce an initial experimental support for ESM modules. It should be enabled automatically if we detect that one of the packages in your dependency tree contains a
Being experimental, it's possible that some bugs may arise or that new Node releases bring some breaking changes around the API. Be sure to report issues on our bug tracker!
New Install Mode:
The pnpm package manager was one of the first tools to advocate for using symlinks when installing packages within the
Starting from Yarn 3.1, you can try out symlink-based installs by adding the following setting to your
Esbuild and swc are two native packages that gained a lot of attention lately thanks to their impressive performances over their competitors. They recently revamped how their packages are built to avoid complex postinstall scripts, but did so in a way that was less efficient than before for Yarn projects.
Yarn 3.1 features a new optimization that kicks in when a package is listed as
In case you need to manually configure a strict set of package architectures to support (for example like in a zero-install case, where you want to read from an immutable set of packages), you can use the
The
This can come in handy if you wish to only run builds in some specific workspaces, or just get a list of the workspaces which changed for scripting purposes:
The
New Workspace Syntax:
Workspaces supported a special syntax via
Yarn now supports
Additionally, as a special case, this syntax is now allowed in the
As always, keep in mind those are only the highlights, the full changelog is much more comprehensive.
Sponsoringhttps://yarnpkg.com/blog/release/3.1#sponsoring
The Yarn org needs your help to make our work more sustainable! Please take a look at our OpenCollective and GitHub Sponsors pages for more details
Table of contenthttps://yarnpkg.com/blog/release/3.1#table-of-content
- Node.js Corepack Integration
- ESM Support
- New Install Mode:
pnpm - Conditional Packages
- Smart Changeset Filters
- New Workspace Syntax:
workspace:^
Improvementshttps://yarnpkg.com/blog/release/3.1#improvements
Node.js Corepack Integrationhttps://yarnpkg.com/blog/release/3.1#nodejs-corepack-integration
Did you know that Yarn now ships with Node? This is done via the Node.js Corepack project, which includes both the Yarn and pnpm binaries as shims. By adding the
[URL='https://yarnpkg.com/configuration/manifest#packageManager']packageManager[/URL] field to your package.json, you can enforce the use of a specific package manager & package manager version in a completely transparent way:
Code:
[COLOR=#393A34][COLOR=#393A34]{[/COLOR]
[COLOR=#36acaa]"packageManager"[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#e3116c]"[email protected]"[/COLOR][/COLOR]
[COLOR=#393A34][COLOR=#393A34]}[/COLOR][/COLOR]
Note that Corepack is available starting from Node.js 16.9, but is currently opt-in. Don't forget to run
corepack enable a single time to make sure the shims are globally installed!We also improved in 3.1 the
init command to properly support Corepack: running yarn [URL='https://yarnpkg.com/cli/init']init[/URL] -2 will now automatically setup a Yarn Modern project, setting its [URL='https://yarnpkg.com/configuration/manifest#packageManager']packageManager[/URL] field as required ESM Supporthttps://yarnpkg.com/blog/release/3.1#esm-support
ESM has always been supported when using the
node_modules linker, since it's the same old install strategy that Node has always supported. However, with PnP taking ownership of the resolution pipeline, compatibility with ESM wasn't a given and had to be implemented using the Loader Hook API.While the Loader Hook API isn't entirely stable yet, a large amount of work has been made lately and our team has been able to produce an initial experimental support for ESM modules. It should be enabled automatically if we detect that one of the packages in your dependency tree contains a
"type": "module" field, but you can enable or disable it manually through your settings:[COLOR=#393A34][COLOR=#00a4db]pnpEnableEsmLoader[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#36acaa]true[/COLOR][/COLOR]Being experimental, it's possible that some bugs may arise or that new Node releases bring some breaking changes around the API. Be sure to report issues on our bug tracker!
New Install Mode: pnpmhttps://yarnpkg.com/blog/release/3.1#new-install-mode-pnpm
The pnpm package manager was one of the first tools to advocate for using symlinks when installing packages within the
node_modules folder. While we went another way with PnP, we decided that the implementation cost was low enough that it would be worth adding support for this symlink-based install strategy as well.Starting from Yarn 3.1, you can try out symlink-based installs by adding the following setting to your
.yarnrc.yml file:[COLOR=#393A34][COLOR=#00a4db]nodeLinker[/COLOR][COLOR=#393A34]:[/COLOR] pnpm[/COLOR]Conditional Packageshttps://yarnpkg.com/blog/release/3.1#conditional-packages
Esbuild and swc are two native packages that gained a lot of attention lately thanks to their impressive performances over their competitors. They recently revamped how their packages are built to avoid complex postinstall scripts, but did so in a way that was less efficient than before for Yarn projects.
Yarn 3.1 features a new optimization that kicks in when a package is listed as
[URL='https://yarnpkg.com/configuration/manifest#optionalDependencies']optionalDependencies[/URL] and lists [URL='https://yarnpkg.com/configuration/manifest#os']os[/URL] and/or [URL='https://yarnpkg.com/configuration/manifest#cpu']cpu[/URL] fields. When that happens, Yarn will skip fetching and installing those packages unless they match the current system parameters.In case you need to manually configure a strict set of package architectures to support (for example like in a zero-install case, where you want to read from an immutable set of packages), you can use the
[URL='https://yarnpkg.com/configuration/yarnrc#supportedArchitectures']supportedArchitectures[/URL] setting:
Code:
[COLOR=#393A34][COLOR=#00a4db]supportedArchitectures[/COLOR][COLOR=#393A34]:[/COLOR]
[COLOR=#00a4db]os[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#393A34][[/COLOR]linux[COLOR=#393A34],[/COLOR] darwin[COLOR=#393A34]][/COLOR]
[COLOR=#00a4db]cpu[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#393A34][[/COLOR]x64[COLOR=#393A34],[/COLOR] arm64[COLOR=#393A34]][/COLOR][/COLOR]
Smart Changeset Filtershttps://yarnpkg.com/blog/release/3.1#smart-changeset-filters
The
yarn [URL='https://yarnpkg.com/cli/workspaces/foreach']workspaces foreach[/URL] and yarn [URL='https://yarnpkg.com/cli/workspaces/list']workspaces list[/URL] commands now ships with brand new --since flags. When set, those commands will only execute against the packages that changed when compared to the main branch (either [URL='https://yarnpkg.com/configuration/manifest#main']main[/URL] or master, depending on the branches in your repository).This can come in handy if you wish to only run builds in some specific workspaces, or just get a list of the workspaces which changed for scripting purposes:
Code:
yarn [URL='https://yarnpkg.com/cli/workspaces/foreach']workspaces foreach[/URL] --since run eslint .
yarn [URL='https://yarnpkg.com/cli/workspaces/list']workspaces list[/URL] --since
The
--since flag also accepts an optional argument (--since=${commit-ish}) to manually define a source from which the changes should be derived.New Workspace Syntax: workspace:^https://yarnpkg.com/blog/release/3.1#new-workspace-syntax-workspace
Workspaces supported a special syntax via
workspace:*, with those ranges being replaced at publish-time by exact ranges corresponding to the real version of the target workspace. However, if you wanted to use a caret instead of an exact range, you had to use the verbose workspace:^x.y.z form, which Yarn updated repo-wide after each publish.Yarn now supports
workspace:^ and workspace:~ as well, making it much easier to cross-reference workspaces within a monorepo where most packages are intended to be published, by preventing a good amount of the merge conflicts that used to happen after Yarn updated the verbose ranges.Additionally, as a special case, this syntax is now allowed in the
[URL='https://yarnpkg.com/configuration/manifest#peerDependencies']peerDependencies[/URL] field as well:
Code:
[COLOR=#393A34][COLOR=#393A34]{[/COLOR]
[COLOR=#36acaa]"peerDependencies"[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#393A34]{[/COLOR]
[COLOR=#36acaa]"@my/other-package"[/COLOR][COLOR=#393A34]:[/COLOR] [COLOR=#e3116c]"workspace:^"[/COLOR][/COLOR]
[COLOR=#393A34] [COLOR=#393A34]}
}[/COLOR][/COLOR]