From f48d46ef6fc0b9922403b9c1d85854d7062a52c3 Mon Sep 17 00:00:00 2001 From: Van Nguyen Date: Sat, 25 Jun 2022 07:04:28 +1000 Subject: [PATCH] fix: respect include-workspace-root npmrc option (#4928) close #4906 Co-authored-by: Zoltan Kochan --- .changeset/cyan-eels-own.md | 6 ++++++ packages/config/src/Config.ts | 1 + packages/config/src/index.ts | 1 + packages/pnpm/src/cmd/index.ts | 1 + packages/pnpm/src/main.ts | 2 +- packages/pnpm/test/monorepo/index.ts | 28 ++++++++++++++++++++++++++++ 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/cyan-eels-own.md diff --git a/.changeset/cyan-eels-own.md b/.changeset/cyan-eels-own.md new file mode 100644 index 00000000000..e349e737e89 --- /dev/null +++ b/.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) diff --git a/packages/config/src/Config.ts b/packages/config/src/Config.ts index d7daeaaf7bd..c7f74aacea4 100644 --- a/packages/config/src/Config.ts +++ b/packages/config/src/Config.ts @@ -28,6 +28,7 @@ export interface Config { dir: string bin: string ignoreScripts?: boolean + includeWorkspaceRoot?: boolean save?: boolean saveProd?: boolean saveDev?: boolean diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 1c256e4a154..493995fefbc 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -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, diff --git a/packages/pnpm/src/cmd/index.ts b/packages/pnpm/src/cmd/index.ts index 28f1b7084c8..17fc14ee8ff 100644 --- a/packages/pnpm/src/cmd/index.ts +++ b/packages/pnpm/src/cmd/index.ts @@ -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 diff --git a/packages/pnpm/src/main.ts b/packages/pnpm/src/main.ts index aaaff22bca5..0295a3d8689 100644 --- a/packages/pnpm/src/main.ts +++ b/packages/pnpm/src/main.ts @@ -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 }) } diff --git a/packages/pnpm/test/monorepo/index.ts b/packages/pnpm/test/monorepo/index.ts index 2dcebdf73e8..e2ff2c5d417 100644 --- a/packages/pnpm/test/monorepo/index.ts +++ b/packages/pnpm/test/monorepo/index.ts @@ -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([ {