mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-02 14:33:18 -04:00
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:
committed by
Zoltan Kochan
parent
85416ea581
commit
916b26b63c
5
.changeset/stupid-wasps-turn.md
Normal file
5
.changeset/stupid-wasps-turn.md
Normal 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).
|
||||
@@ -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) })
|
||||
}
|
||||
|
||||
|
||||
46
pnpm/test/recursive/filter.ts
Normal file
46
pnpm/test/recursive/filter.ts
Normal 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()
|
||||
})
|
||||
Reference in New Issue
Block a user