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

feat: exclude the root from recursive exec|run|add #3647

Merged
merged 3 commits into from Aug 6, 2021
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
5 changes: 5 additions & 0 deletions .changeset/chilly-ligers-thank.md
@@ -0,0 +1,5 @@
---
"pnpm": minor
---

Exclude the root package, when running `pnpm exec|run|add`. This change is only active when `use-beta-cli` is set to `true`.
5 changes: 5 additions & 0 deletions .changeset/twenty-trains-pay.md
@@ -0,0 +1,5 @@
---
"pnpm": minor
---

When `--workspace-root` is used, the workspace root package is selected even if the command is executed with filters.
6 changes: 6 additions & 0 deletions packages/pnpm/src/main.ts
Expand Up @@ -178,6 +178,12 @@ export default async function run (inputArgv: string[]) {
...config.filter.map((filter) => ({ filter, followProdDepsOnly: false })),
...config.filterProd.map((filter) => ({ filter, followProdDepsOnly: true })),
]
const relativeWSDirPath = () => path.relative(process.cwd(), wsDir) || '.'
if (config.workspaceRoot) {
filters.push({ filter: `{${relativeWSDirPath()}}`, followProdDepsOnly: false })
} else if (config.useBetaCli && (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test')) {
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: false })
}

const filterResults = await filterPackages(allProjects, filters, {
linkWorkspacePackages: !!config.linkWorkspacePackages,
Expand Down
53 changes: 53 additions & 0 deletions packages/pnpm/test/monorepo/index.ts
Expand Up @@ -1340,3 +1340,56 @@ test('custom virtual store directory in a workspace with shared lockfile', async
expect(modulesManifest?.virtualStoreDir).toBe(path.resolve('virtual-store'))
}
})

test('pnpm run should ignore the root project', async () => {
preparePackages([
{
location: '.',
package: {
scripts: {
test: 'exit 1',
},
},
},
{
name: 'project',
version: '1.0.0',
scripts: {
test: "node -e \"require('fs').writeFileSync('test','','utf8')\"",
},
},
])

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

await execPnpm(['-r', '--config.use-beta-cli=true', 'test'])

expect(await exists('project/test')).toBeTruthy()
})

test('pnpm run should include the workspace root when --workspace-root option is used', async () => {
preparePackages([
{
location: '.',
package: {
scripts: {
test: "node -e \"require('fs').writeFileSync('test','','utf8')\"",
},
},
},
{
name: 'project',
version: '1.0.0',
scripts: {
test: "node -e \"require('fs').writeFileSync('test','','utf8')\"",
},
},
])

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

await execPnpm(['--filter=project', '--workspace-root', 'test'])

expect(await exists('test')).toBeTruthy()
expect(await exists('project/test')).toBeTruthy()
})