fix: dlx should work without a configured global directory (#4612)

* fix: dlx should work without a configured global directory

close #4597

* docs: add changesets
This commit is contained in:
Zoltan Kochan
2022-04-24 13:02:32 +03:00
committed by GitHub
parent 17fa76e2bb
commit c5caf83346
4 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
`pnpm dlx` should work without a configure global directory.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": patch
---
Allow to pass `global-bin-dir` through CLI options to the `add` command.

View File

@@ -18,6 +18,7 @@ export function rcOptionsTypes () {
'fetch-retry-mintimeout',
'fetch-timeout',
'force',
'global-bin-dir',
'global-dir',
'global-pnpmfile',
'global',

View File

@@ -61,15 +61,24 @@ export async function handler (
})
await rimraf(bins)
const pkgs = opts.package ?? params.slice(0, 1)
const pnpmArgs = ['add', ...pkgs, '--global', '--global-dir', prefix, '--dir', prefix]
const pnpmArgs = [
'add',
...pkgs,
'--global',
`--global-dir=${prefix}`,
`--dir=${prefix}`,
`--config.global-bin-dir=${bins}`,
]
if (opts.reporter) {
pnpmArgs.push(`--reporter=${opts.reporter}`)
}
const env = makeEnv({ userAgent: opts.userAgent, prependPaths: [bins] })
await execa('pnpm', pnpmArgs, {
env,
stdio: 'inherit',
})
await execa(versionless(scopeless(params[0])), params.slice(1), {
env: makeEnv({ userAgent: opts.userAgent, prependPaths: [bins] }),
env,
stdio: 'inherit',
})
}