Skip to content

Releasing a monorepo workspace ​

@neosjs/release-plugin-workspaces is an official plugin for @neosjs/release. In a monorepo workspace it writes the same version into every package in one release, then publishes all non-private packages to npm. It supports pnpm, npm, and yarn workspaces.

The built-in npm plugin only publishes the package.json in the root directory, and the root of a monorepo is usually private, so publishing multiple packages has to be done by a plugin. Recommending and choosing the version, committing, tagging, and creating the Release are still handled by the built-in plugins; only the version in the root package.json is updated by them.

Installation ​

Run this in the root of the repository (-w installs into the root of the workspace):

sh
pnpm add @neosjs/release-plugin-workspaces -Dw

Requires @neosjs/release 1.4.0 or later.

Usage ​

The plugin is enabled automatically when the current directory is a pnpm, npm, or yarn workspace. No configuration is needed:

sh
npx release

The release explains each step as it goes. The plugin prints its messages in Chinese; the example below shows what they mean:

text
包管理器: pnpm (依据 pnpm-lock.yaml)
工作区: 3 个子包, 2 个会发布 (@demo/ui, @demo/utils), 1 个是私有包 (@demo/docs)
packages/ui/package.json: 1.2.0 → 1.3.0
packages/ui/package.json: @demo/utils 1.2.0 → 1.3.0
packages/utils/package.json: 1.2.0 → 1.3.0
使用 pnpm 发布 2 个包: @demo/ui, @demo/utils
  • Line 1: the package manager that was detected (pnpm, based on pnpm-lock.yaml).
  • Line 2: 3 packages found, 2 will be published, 1 is private.
  • Lines 3 to 5: each version that is written, including dependencies between workspace packages.
  • Line 6: publishing 2 packages with pnpm.

Detecting the package manager ​

The plugin tells which package manager a project uses only from the project's own markers, never from what happens to be installed on the machine: a project may have npm installed and still use pnpm. It checks, in order:

OrderMarkerExample
1packageManager in the plugin options"packageManager": "yarn"
2The packageManager field of the root package.json"packageManager": "pnpm@10.33.0"
3The lockfile in the root directorypnpm-lock.yaml, yarn.lock, package-lock.json
4A pnpm-workspace.yaml in the root directoryTreated as pnpm
5None of the aboveTreated as npm, with a hint that it can be set manually

The result is printed when the release starts. If it is wrong, set packageManager in the plugin options.

When more than one lockfile exists in the root directory (for example, an old lockfile that was not deleted after switching package managers), the first match in the table above is used and a warning is printed:

text
根目录同时存在 pnpm-lock.yaml、package-lock.json, 按 pnpm 处理。请删除不再使用的锁文件, 或在插件配置里设置 packageManager

It reads: both pnpm-lock.yaml and package-lock.json were found, pnpm is used. Delete the lockfile that is no longer needed, or set packageManager in the plugin options.

Package versions ​

  • Every package shares one version, the same as the root. When the root package.json has no version, the current version is the highest one found among the packages.
  • Packages without a version field are left untouched.
  • Dependencies between workspace packages that pin an exact version (such as "@demo/utils": "1.2.0") are updated to the new version as well. Ranges such as workspace:*, ^, and ~ are not modified.

Publishing ​

Package managerListing packagesPublishing
pnpmpnpm -r listpnpm -r publish --no-git-checks
npmnpm query .workspacenpm publish --workspaces
yarnyarn workspaces info on yarn 1, yarn workspaces list on yarn 2+One package at a time, in each non-private package directory: npm publish on yarn 1, yarn npm publish on yarn 2+
  • --no-git-checks for pnpm: pnpm only allows publishing from the main or master branch by default, while the release branch may be a different one.
  • One package at a time for yarn: yarn 1 has no built-in command for publishing every package, so the plugin publishes each package itself on both yarn versions.
  • Private packages are not published, but their version is still updated.
  • dist-tag: stable versions are published to latest. Pre-release versions are published to the pre-release identifier (1.3.0-beta.0 maps to beta), or to next when the identifier is purely numeric.
  • Interactive mode (outside CI): the terminal is handed over to the package manager, so you can log in or complete two-factor authentication when prompted if no token is configured.

Login check ​

Before the release starts, the plugin checks that you are logged in to npm. Without a login the release fails before any file is modified. The built-in plugins skip this check when the root is private, so this plugin adds it.

Package managerCheckLog in with
pnpm, npmnpm whoaminpm login
yarn 1Not checked (it publishes with the npm login as well)npm login
yarn 2+yarn npm whoamiyarn npm login

yarn 2+ does not read login credentials from .npmrc; they are stored in its own configuration, so log in with yarn npm login.

Options ​

json
{
  "plugins": {
    "@neosjs/release-plugin-workspaces": {
      "packageManager": "pnpm",
      "publishArgs": "--access public"
    }
  }
}
OptionDescription
packageManagerThe package manager the project uses: pnpm, npm, or yarn. When not set, it is detected from the project's own markers
publishWhether to publish to npm, true by default. Set to false to only update the package versions
tagThe dist-tag to publish to. When not set, it is determined by the rules above
otpThe npm one-time password (for accounts with two-factor authentication enabled)
publishArgsExtra arguments passed to the publish command, as a string or an array

To disable the plugin, set it to false in the config:

json
{
  "plugins": {
    "@neosjs/release-plugin-workspaces": false
  }
}

Not supported yet ​

  • --canary: it would require temporarily rewriting and then restoring the version of every package. The release fails with a clear error instead.
  • Staged publishing (npm.stage): fails with a clear error.
  • One tag per package: a single tag in the root (such as v1.3.0) is used.
  • bun workspaces: when only bun.lock is found, the release fails with an error. Use packageManager to choose how the project is handled.

When publishing fails ​

The plugin publishes only after the commit and tag have been pushed. If the push succeeds but publishing fails, you will see this warning (in Chinese):

text
提交和标签已经推送, 但包没有发布成功。解决报错的问题后, 在项目根目录执行 pnpm -r publish 重新发布, 不需要重新发版

It means the commit and tag have been pushed, but the packages were not published. Fix the reported problem and run the command shown in the warning, which matches your package manager (such as npm publish --workspaces); there is no need to run the release again. Packages that were already published in the previous attempt may be rejected for being published twice; skip them and continue with the rest.