Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strange-llamas-tie.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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