Skip to content

Commit

Permalink
fix(exec): commands of workspace project should be in PATH
Browse files Browse the repository at this point in the history
close #4481
  • Loading branch information
zkochan committed Apr 16, 2022
1 parent 6fc4c89 commit d3908f7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .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).
2 changes: 1 addition & 1 deletion packages/plugin-commands-script-runners/src/exec.ts
Expand Up @@ -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,
Expand Down
47 changes: 43 additions & 4 deletions packages/plugin-commands-script-runners/test/exec.e2e.ts
Expand Up @@ -52,7 +52,7 @@ test('pnpm recursive exec', async () => {
])

const { selectedProjectsGraph } = await readProjects(process.cwd(), [])
await execa('pnpm', [
await execa(pnpmBin, [
'install',
'-r',
'--registry',
Expand All @@ -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([
{
Expand Down Expand Up @@ -115,7 +154,7 @@ test('exec inside a workspace package', async () => {
},
])

await execa('pnpm', [
await execa(pnpmBin, [
'install',
'-r',
'--registry',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit d3908f7

Please sign in to comment.