feat: allow installing mutiple packages using dlx command (#3710)

Allow use of mutiple --package parameters with pnpm dlx command

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Tautvydas Duda
2021-08-28 23:37:07 +03:00
committed by GitHub
parent 138c53d158
commit 7f097f26f2
3 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": minor
---
Support for multiple `--package` parameters added for `pnpm dlx` command

View File

@@ -13,7 +13,7 @@ export function rcOptionsTypes () {
}
export const cliOptionsTypes = () => ({
package: String,
package: [String, Array],
})
export function help () {
@@ -37,7 +37,7 @@ export function help () {
export async function handler (
opts: {
package?: string
package?: string[]
},
params: string[]
) {
@@ -55,8 +55,8 @@ export async function handler (
} catch (err) { }
})
await rimraf(bins)
const pkg = opts.package ?? params[0]
await execa('pnpm', ['add', pkg, '--global', '--global-dir', prefix, '--dir', prefix], {
const pkgs = opts.package ?? params.slice(0, 1)
await execa('pnpm', ['add', ...pkgs, '--global', '--global-dir', prefix, '--dir', prefix], {
stdio: 'inherit',
})
await execa(params[0], params.slice(1), {

View File

@@ -10,11 +10,14 @@ test('dlx', async () => {
expect(fs.existsSync('foo')).toBeTruthy()
})
test('dlx --package <pkg>', async () => {
test('dlx --package <pkg1> [--package <pkg2>]', async () => {
prepareEmpty()
await dlx.handler({
package: 'zkochan/for-testing-pnpm-dlx',
package: [
'zkochan/for-testing-pnpm-dlx',
'is-positive',
],
}, ['foo'])
expect(fs.existsSync('foo')).toBeTruthy()