From 275c4052359189c37a348804374c8dc7f6ab3016 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 16 Apr 2022 20:20:29 +0300 Subject: [PATCH] fix(exec): commands of workspace project should be in PATH (#4583) close #4481 --- .changeset/strange-llamas-tie.md | 6 +++ .../src/exec.ts | 2 +- .../test/exec.e2e.ts | 47 +++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .changeset/strange-llamas-tie.md diff --git a/.changeset/strange-llamas-tie.md b/.changeset/strange-llamas-tie.md new file mode 100644 index 00000000000..239e4684fe4 --- /dev/null +++ b/.changeset/strange-llamas-tie.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +When `pnpm exec` is running a command in a workspace project, the commands that are in the dependencies of that workspace project should be in the PATH [#4481](https://github.com/pnpm/pnpm/issues/4481). diff --git a/packages/plugin-commands-script-runners/src/exec.ts b/packages/plugin-commands-script-runners/src/exec.ts index e32d29d8f30..b97939e8c5b 100644 --- a/packages/plugin-commands-script-runners/src/exec.ts +++ b/packages/plugin-commands-script-runners/src/exec.ts @@ -137,7 +137,7 @@ export async function handler ( PNPM_PACKAGE_NAME: opts.selectedProjectsGraph?.[prefix]?.package.manifest.name, }, prependPaths: [ - path.join(opts.dir, 'node_modules/.bin'), + path.join(prefix, 'node_modules/.bin'), ...opts.extraBinPaths, ], userAgent: opts.userAgent, diff --git a/packages/plugin-commands-script-runners/test/exec.e2e.ts b/packages/plugin-commands-script-runners/test/exec.e2e.ts index 6fbb3e114a2..f7c1da765af 100644 --- a/packages/plugin-commands-script-runners/test/exec.e2e.ts +++ b/packages/plugin-commands-script-runners/test/exec.e2e.ts @@ -52,7 +52,7 @@ test('pnpm recursive exec', async () => { ]) const { selectedProjectsGraph } = await readProjects(process.cwd(), []) - await execa('pnpm', [ + await execa(pnpmBin, [ 'install', '-r', '--registry', @@ -74,6 +74,45 @@ test('pnpm recursive exec', async () => { expect(outputs2).toStrictEqual(['project-1', 'project-3']) }) +test('pnpm recursive exec finds bin files of workspace projects', async () => { + preparePackages([ + { + name: 'project-1', + version: '1.0.0', + + dependencies: { + cowsay: '1.5.0', + }, + }, + { + name: 'project-2', + version: '1.0.0', + + dependencies: { + cowsay: '1.5.0', + }, + }, + ]) + + const { selectedProjectsGraph } = await readProjects(process.cwd(), []) + await execa(pnpmBin, [ + 'install', + '-r', + '--registry', + REGISTRY, + '--store-dir', + path.resolve(DEFAULT_OPTS.storeDir), + ]) + await exec.handler({ + ...DEFAULT_OPTS, + dir: process.cwd(), + recursive: true, + selectedProjectsGraph, + }, ['cowsay', 'hi']) + + // If there was no exception, the test passed +}) + test('exec inside a workspace package', async () => { preparePackages([ { @@ -115,7 +154,7 @@ test('exec inside a workspace package', async () => { }, ]) - await execa('pnpm', [ + await execa(pnpmBin, [ 'install', '-r', '--registry', @@ -196,7 +235,7 @@ test('testing the bail config with "pnpm recursive exec"', async () => { ]) const { selectedProjectsGraph } = await readProjects(process.cwd(), []) - await execa('pnpm', [ + await execa(pnpmBin, [ 'install', '-r', '--registry', @@ -272,7 +311,7 @@ test('pnpm recursive exec --no-sort', async () => { ]) const { selectedProjectsGraph } = await readProjects(process.cwd(), []) - await execa('pnpm', [ + await execa(pnpmBin, [ 'install', '-r', '--registry',