feat(dlx): handle version specifiers in command names (#4024)

close #4023
This commit is contained in:
Lev Chelyadinov
2021-11-21 20:13:08 +03:00
committed by GitHub
parent 23de26f187
commit 5a11c8bac4
3 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
`pnpm dlx` will now support version specifiers for packages.

View File

@@ -68,7 +68,7 @@ export async function handler (
await execa('pnpm', pnpmArgs, {
stdio: 'inherit',
})
await execa(scopeless(params[0]), params.slice(1), {
await execa(versionless(scopeless(params[0])), params.slice(1), {
env: {
...process.env,
[PATH]: [
@@ -86,3 +86,7 @@ function scopeless (pkgName: string) {
}
return pkgName
}
function versionless (scopelessPkgName: string) {
return scopelessPkgName.split('@')[0]
}

View File

@@ -4,6 +4,8 @@ import { prepareEmpty } from '@pnpm/prepare'
jest.mock('execa')
beforeEach((execa as jest.Mock).mockClear)
test('dlx should work with scoped packages', async () => {
prepareEmpty()
@@ -11,3 +13,16 @@ test('dlx should work with scoped packages', async () => {
expect(execa).toBeCalledWith('bar', [], expect.anything())
})
test('dlx should work with versioned packages', async () => {
prepareEmpty()
await dlx.handler({}, ['@foo/bar@next'])
expect(execa).toBeCalledWith(
'pnpm',
expect.arrayContaining(['add', '@foo/bar@next']),
expect.anything()
)
expect(execa).toBeCalledWith('bar', [], expect.anything())
})