fix(exec): commands of workspace project should be in PATH (#4583)

close #4481
This commit is contained in:
Zoltan Kochan
2022-04-16 20:20:29 +03:00
committed by GitHub
parent 6fc4c89bc3
commit 275c405235
3 changed files with 50 additions and 5 deletions

View File

@@ -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).

View File

@@ -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,

View File

@@ -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',