fix: prevent implicit root exclusion when user filters are provided (#10465)

* fix: prevent implicit root exclusion when user filters are provided

* docs: add changeset

* test: remove redundant init

---------

Co-authored-by: tensorworker <tensorworker@proton.me>
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Tensorworker
2026-01-16 10:12:33 -05:00
committed by Zoltan Kochan
parent 85416ea581
commit 916b26b63c
3 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"pnpm": major
---
Do not exclude the root workspace project, when it is explicitly selected via a filter [#10465](https://github.com/pnpm/pnpm/pull/10465).

View File

@@ -213,7 +213,7 @@ export async function main (inputArgv: string[]): Promise<void> {
const relativeWSDirPath = () => path.relative(process.cwd(), wsDir) || '.'
if (config.workspaceRoot) {
filters.push({ filter: `{${relativeWSDirPath()}}`, followProdDepsOnly: Boolean(config.filterProd.length) })
} else if (workspaceDir && !config.includeWorkspaceRoot && (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test')) {
} else if (filters.length === 0 && workspaceDir && !config.includeWorkspaceRoot && (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test')) {
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: Boolean(config.filterProd.length) })
}

View File

@@ -0,0 +1,46 @@
import fs from 'fs'
import { prepare } from '@pnpm/prepare'
import { execPnpmSync } from '../utils/index.js'
test('pnpm --filter <root> add <pkg> should work', async () => {
prepare({
name: 'root',
version: '1.0.0',
pnpm: {
overrides: {
'is-positive': '1.0.0',
},
},
})
fs.writeFileSync('pnpm-workspace.yaml', 'packages:\n - "."\n')
const result = execPnpmSync(['--filter', 'root', 'add', 'is-positive'])
if (result.status !== 0) {
console.log(result.stdout.toString())
console.log(result.stderr.toString())
}
expect(result.status).toBe(0)
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
expect(pkg.dependencies['is-positive']).toBeTruthy()
})
test('pnpm --filter . add <pkg> should work', async () => {
prepare({
name: 'root',
version: '1.0.0',
})
fs.writeFileSync('pnpm-workspace.yaml', 'packages:\n - "."\n')
const result = execPnpmSync(['--filter', '.', 'add', 'is-positive'])
if (result.status !== 0) {
console.log(result.stdout.toString())
console.log(result.stderr.toString())
}
expect(result.status).toBe(0)
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
expect(pkg.dependencies['is-positive']).toBeTruthy()
})