fix: allow pnpm runtime set in workspace root (#11584)

* fix: allow `pnpm runtime set` in workspace root

`pnpm runtime set <name> <version>` previously failed in the root of a
multi-package workspace with the `ADDING_TO_ROOT` error. Since installing
a runtime is workspace-wide configuration, pass `--workspace-root` to the
underlying `pnpm add` call when not running globally.

* fix: use --ignore-workspace-root-check instead of --workspace-root

The previous fix forced every non-global runtime install to land in
the workspace root, which broke running the command from a workspace
subproject. Switch to --ignore-workspace-root-check, which only
suppresses the safety warning and leaves the install target as the
current directory.
This commit is contained in:
Zoltan Kochan
2026-05-11 19:53:44 +02:00
committed by GitHub
parent 4b25a3dfa8
commit a575dd2461
3 changed files with 9 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/engine.runtime.commands": patch
"pnpm": patch
---
`pnpm runtime set <name> <version>` no longer fails in the root of a multi-package workspace with the `ADDING_TO_ROOT` error. Installing the workspace root is a valid target for a runtime, so the command now bypasses that safety check.

View File

@@ -94,6 +94,8 @@ function runtimeSet (opts: RuntimeCommandOptions, params: string[]): void {
if (opts.global) {
args.push('--global')
if (opts.bin) args.push('--global-bin-dir', opts.bin)
} else {
args.push('--ignore-workspace-root-check')
}
if (opts.storeDir) args.push('--store-dir', opts.storeDir)
if (opts.cacheDir) args.push('--cache-dir', opts.cacheDir)

View File

@@ -37,7 +37,7 @@ test('runtime set uses project dir when not global', async () => {
}, ['set', 'node', '22'])
expect(mockRunPnpmCli).toHaveBeenCalledWith(
['add', 'node@runtime:22'],
['add', 'node@runtime:22', '--ignore-workspace-root-check'],
{ cwd: '/tmp/project' }
)
})