Press "Enter" to skip to content

JavaScript: Yarn 3.1 revises the workspace syntax

The new minor version of the Yarn JavaScript package manager is version 3.1. The alternative to npm follows the semantic versioning and therefore has no breaking changes to show. However, the new version adapts the SDK to take into account a breaking change in Visual Studio Code 1.61 and higher.

Yarn 3.1 revises the workspace syntax and adds workspace:^ as workspace:~ added. So far was already workspace:* available whose ranks were replaced with the corresponding ranks of the target workspace at the time of publication. However, if there was an insertion mark (caret, ^) instead of an exact range, it was only in the form workspace:^x.y.z possible what Yarn updated throughout the repository after a release. The resulting merge conflicts should be reduced by the new syntax. This is primarily intended to simplify cross-references in monorepos, in which most of the packages are intended for publication.

As a special case, the syntax is also in the peerDependencies-Field allowed:

{
  "peerDependencies": {
    "@my/other-package": "workspace:^"
  }
} 

In addition, the new flag is --since added that on yarn workspaces list and yarn workspaces foreach can apply. As a result, the commands are only applied to packages that have changed compared to the main or master branch – depending on the branches available. However describes the Yarn team the new option as “still a little experimental” – especially when used in conjunction with -R,--recursive is used.

The new yarn version has Node.js – recently released in version 17 – thanks of the experimental Tools Corepack on board. This should serve to build a bridge between Node.js and package managers and supports Yarn and pnp, but not npm.

The use of ECMAScript Modules (ESM) with the aid of the Loader Hook API, which is not yet considered stable, is also experimental in Yarn 3.1. ESM support should be activated automatically if one of the packages in the Dependence Tree is "type": "module"Field contains. It can also be activated or deactivated manually in the settings (pnpEnableEsmLoader: true).

All new features in Yarn 3.1 are a dev.to contribution as the changelog on GitHub refer to.


(May)

Article Source

Disclaimer: This article is generated from the feed and not edited by our team.