mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
5
.changeset/sweet-geese-ring.md
Normal file
5
.changeset/sweet-geese-ring.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
---
|
||||
|
||||
`dlx` should be able to run scoped packages.
|
||||
@@ -68,7 +68,7 @@ export async function handler (
|
||||
await execa('pnpm', pnpmArgs, {
|
||||
stdio: 'inherit',
|
||||
})
|
||||
await execa(params[0], params.slice(1), {
|
||||
await execa(scopeless(params[0]), params.slice(1), {
|
||||
env: {
|
||||
...process.env,
|
||||
[PATH]: [
|
||||
@@ -79,3 +79,10 @@ export async function handler (
|
||||
stdio: 'inherit',
|
||||
})
|
||||
}
|
||||
|
||||
function scopeless (pkgName: string) {
|
||||
if (pkgName.startsWith('@')) {
|
||||
return pkgName.split('/')[1]
|
||||
}
|
||||
return pkgName
|
||||
}
|
||||
|
||||
24
packages/plugin-commands-script-runners/test/dlx.e2e.ts
Normal file
24
packages/plugin-commands-script-runners/test/dlx.e2e.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import fs from 'fs'
|
||||
import { dlx } from '@pnpm/plugin-commands-script-runners'
|
||||
import { prepareEmpty } from '@pnpm/prepare'
|
||||
|
||||
test('dlx', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await dlx.handler({}, ['shx', 'touch', 'foo'])
|
||||
|
||||
expect(fs.existsSync('foo')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('dlx --package <pkg1> [--package <pkg2>]', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await dlx.handler({
|
||||
package: [
|
||||
'zkochan/for-testing-pnpm-dlx',
|
||||
'is-positive',
|
||||
],
|
||||
}, ['foo'])
|
||||
|
||||
expect(fs.existsSync('foo')).toBeTruthy()
|
||||
})
|
||||
@@ -1,24 +1,13 @@
|
||||
import fs from 'fs'
|
||||
import execa from 'execa'
|
||||
import { dlx } from '@pnpm/plugin-commands-script-runners'
|
||||
import { prepareEmpty } from '@pnpm/prepare'
|
||||
|
||||
test('dlx', async () => {
|
||||
jest.mock('execa')
|
||||
|
||||
test('dlx should work with scoped packages', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await dlx.handler({}, ['shx', 'touch', 'foo'])
|
||||
await dlx.handler({}, ['@foo/bar'])
|
||||
|
||||
expect(fs.existsSync('foo')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('dlx --package <pkg1> [--package <pkg2>]', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await dlx.handler({
|
||||
package: [
|
||||
'zkochan/for-testing-pnpm-dlx',
|
||||
'is-positive',
|
||||
],
|
||||
}, ['foo'])
|
||||
|
||||
expect(fs.existsSync('foo')).toBeTruthy()
|
||||
expect(execa).toBeCalledWith('bar', [], expect.anything())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user