mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
feat(dlx): handle version specifiers in command names (#4024)
close #4023
This commit is contained in:
5
.changeset/rich-horses-know.md
Normal file
5
.changeset/rich-horses-know.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
---
|
||||
|
||||
`pnpm dlx` will now support version specifiers for packages.
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user