mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
feat(plugin-commands-script-runners): add --shell-mode option for pnpm dlx (#5840)
close #5679
This commit is contained in:
6
.changeset/olive-readers-drop.md
Normal file
6
.changeset/olive-readers-drop.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
The `pnpm dlx` command supports the `--shell-mode` (or `-c`) option. When used, the script is executed by a shell [#5679](https://github.com/pnpm/pnpm/issues/5679).
|
||||
@@ -16,11 +16,16 @@ import { makeEnv } from './makeEnv'
|
||||
|
||||
export const commandNames = ['dlx']
|
||||
|
||||
export const shorthands = {
|
||||
c: '--shell-mode',
|
||||
}
|
||||
|
||||
export function rcOptionsTypes () {
|
||||
return {
|
||||
...pick([
|
||||
'use-node-version',
|
||||
], types),
|
||||
'shell-mode': Boolean,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +40,16 @@ export function help () {
|
||||
descriptionLists: [
|
||||
{
|
||||
title: 'Options',
|
||||
|
||||
list: [
|
||||
{
|
||||
description: 'The package to install before running the command',
|
||||
name: '--package',
|
||||
},
|
||||
{
|
||||
description: 'Runs the script inside of a shell. Uses /bin/sh on UNIX and \\cmd.exe on Windows.',
|
||||
name: '--shell-mode',
|
||||
shortAlias: '-c',
|
||||
},
|
||||
],
|
||||
},
|
||||
OUTPUT_OPTIONS,
|
||||
@@ -52,6 +61,7 @@ export function help () {
|
||||
|
||||
export type DlxCommandOptions = {
|
||||
package?: string[]
|
||||
shellMode?: boolean
|
||||
} & Pick<Config, 'reporter' | 'userAgent'> & add.AddCommandOptions
|
||||
|
||||
export async function handler (
|
||||
@@ -87,8 +97,10 @@ export async function handler (
|
||||
? command
|
||||
: await getBinName(modulesDir, await getPkgName(prefix))
|
||||
await execa(binName, args, {
|
||||
cwd: process.cwd(),
|
||||
env,
|
||||
stdio: 'inherit',
|
||||
shell: opts.shellMode ?? false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -90,3 +90,19 @@ test('dlx should fail when the package has no bins', async () => {
|
||||
}, ['is-positive'])
|
||||
).rejects.toThrow(/No binaries found in is-positive/)
|
||||
})
|
||||
|
||||
test('dlx should work in shell mode', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await dlx.handler({
|
||||
...DEFAULT_OPTS,
|
||||
dir: path.resolve('project'),
|
||||
storeDir: path.resolve('store'),
|
||||
package: [
|
||||
'is-positive',
|
||||
],
|
||||
shellMode: true,
|
||||
}, ['echo "some text" > foo'])
|
||||
|
||||
expect(fs.existsSync('foo')).toBeTruthy()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user