Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter-prod flag including all workspace pkgs #5437

Merged
merged 1 commit into from Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/large-suns-relax.md
@@ -0,0 +1,9 @@
---
"pnpm": patch
---

fix: Stop --filter-prod option to run command on all the projects when used on workspace. --filter-prod option now only filter from `dependencies` and omit `devDependencies` instead of including all the packages when used on workspace. So what was happening is that if you use `--filter-prod` on workspace root like this:
```bash
pnpm --filter-prod ...build-modules exec node -e 'console.log(require(`./package.json`).name)'
```
it was printing all the package of workspace, where it should only print the package name of itself and packages where it has been added as `dependency` (not as `devDependencies`)
4 changes: 2 additions & 2 deletions packages/pnpm/src/main.ts
Expand Up @@ -196,9 +196,9 @@ export default async function run (inputArgv: string[]) {
]
const relativeWSDirPath = () => path.relative(process.cwd(), wsDir) || '.'
if (config.workspaceRoot) {
filters.push({ filter: `{${relativeWSDirPath()}}`, followProdDepsOnly: false })
filters.push({ filter: `{${relativeWSDirPath()}}`, followProdDepsOnly: Boolean(config.filterProd.length) })
} else if (!config.includeWorkspaceRoot && (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test')) {
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: false })
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: Boolean(config.filterProd.length) })
}

const filterResults = await filterPackages(allProjects, filters, {
Expand Down
57 changes: 57 additions & 0 deletions packages/pnpm/test/filterProd.test.ts
@@ -0,0 +1,57 @@
import path from 'path'
import writeYamlFile from 'write-yaml-file'
import { execPnpm } from './utils'
import {
preparePackages,
} from '@pnpm/prepare'

test.each([
{ message: '--filter should include devDependencies', filter: '--filter', expected: ['project-1', 'project-3', 'project-4'] },
{ message: '--filter-prod should not include devDependencies', filter: '--filter-prod', expected: ['project-1', 'project-3'] },
])('$message', async ({ filter, expected }) => {
preparePackages([
{
name: 'project-1',
version: '1.0.0',
dependencies: { 'project-2': '1.0.0', 'project-3': '1.0.0' },
devDependencies: { 'json-append': '1' },
scripts: {
test: 'node -e "process.stdout.write(\'project-1\')" | json-append ../output.json',
},
},
{
name: 'project-2',
version: '1.0.0',
dependencies: {},
devDependencies: { 'json-append': '1' },
scripts: {
test: 'node -e "process.stdout.write(\'project-2\')" | json-append ../output.json',
},
},
{
name: 'project-3',
version: '1.0.0',
dependencies: { 'project-2': '1.0.0' },
devDependencies: { 'json-append': '1' },
scripts: {
test: 'node -e "process.stdout.write(\'project-3\')" | json-append ../output.json',
},
},
{
name: 'project-4',
version: '1.0.0',
dependencies: {},
devDependencies: { 'json-append': '1', 'project-3': '1.0.0' },
scripts: {
test: 'node -e "process.stdout.write(\'project-4\')" | json-append ../output.json',
},
},
])

await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
await execPnpm(['install'])

await execPnpm(['recursive', 'test', filter, '...project-3'])
const { default: output } = await import(path.resolve('output.json'))
expect(output.sort()).toStrictEqual(expected)
})