fix: respect include-workspace-root npmrc option (#4928)

close #4906

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Van NguyenandZoltan Kochan authored and GitHub committed 2022-06-25 00:04:28 +03:00
1 parent 6576a92b12
commit f48d46ef6f
6 files changed
+38 -1

No files matched your search

+6
View File
@@ -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
View File
@@ -28,6 +28,7 @@ export interface Config {
dir: string
bin: string
ignoreScripts?: boolean
includeWorkspaceRoot?: boolean
save?: boolean
saveProd?: boolean
saveDev?: boolean
+1
View File
@@ -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,
+1
View File
@@ -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
+1 -1
View File
@@ -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 })
}
+28
View File
@@ -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([
{