Skip to content

Commit

Permalink
fix: respect include-workspace-root npmrc option (#4928)
Browse files Browse the repository at this point in the history
close #4906

Co-authored-by: Zoltan Kochan <z@kochan.io>
  • Loading branch information
shirotech and zkochan committed Jun 24, 2022
1 parent 6576a92 commit f48d46e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/cyan-eels-own.md
@@ -0,0 +1,6 @@
---
"@pnpm/config": minor
"pnpm": minor
---

New setting added: `include-workspace-root`. When it is set to `true`, the `run`, `exec`, `add`, and `test` commands will include the root package, when executed recursively [#4906](https://github.com/pnpm/pnpm/issues/4906)
1 change: 1 addition & 0 deletions packages/config/src/Config.ts
Expand Up @@ -28,6 +28,7 @@ export interface Config {
dir: string
bin: string
ignoreScripts?: boolean
includeWorkspaceRoot?: boolean
save?: boolean
saveProd?: boolean
saveDev?: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Expand Up @@ -63,6 +63,7 @@ export const types = Object.assign({
'ignore-pnpmfile': Boolean,
'ignore-workspace': Boolean,
'ignore-workspace-root-check': Boolean,
'include-workspace-root': Boolean,
'legacy-dir-filtering': Boolean,
'link-workspace-packages': [Boolean, 'deep'],
lockfile: Boolean,
Expand Down
1 change: 1 addition & 0 deletions packages/pnpm/src/cmd/index.ts
Expand Up @@ -47,6 +47,7 @@ export const GLOBAL_OPTIONS = pick([
'ignore-workspace',
'workspace-packages',
'workspace-root',
'include-workspace-root',
], allTypes)

export type CommandResponse = string | { output: string, exitCode: number } | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/pnpm/src/main.ts
Expand Up @@ -197,7 +197,7 @@ export default async function run (inputArgv: string[]) {
const relativeWSDirPath = () => path.relative(process.cwd(), wsDir) || '.'
if (config.workspaceRoot) {
filters.push({ filter: `{${relativeWSDirPath()}}`, followProdDepsOnly: false })
} else if (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test') {
} else if (!config.includeWorkspaceRoot && (cmd === 'run' || cmd === 'exec' || cmd === 'add' || cmd === 'test')) {
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: false })
}

Expand Down
28 changes: 28 additions & 0 deletions packages/pnpm/test/monorepo/index.ts
Expand Up @@ -1499,6 +1499,34 @@ test('pnpm run should include the workspace root when --workspace-root option is
expect(await exists('project/test')).toBeTruthy()
})

test('pnpm run should include the workspace root when include-workspace-root is set to true', 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 fs.writeFile('.npmrc', 'include-workspace-root', 'utf8')
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })

await execPnpm(['-r', 'test'])

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

test('legacy directory filtering', async () => {
preparePackages([
{
Expand Down

0 comments on commit f48d46e

Please sign in to comment.