Skip to content

Commit

Permalink
feat(plugin-commands-script-runners): add --shell-mode option for pnp…
Browse files Browse the repository at this point in the history
…m dlx (#5840)

close #5679
  • Loading branch information
await-ovo committed Dec 26, 2022
1 parent 964d5ff commit b3dfa3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/olive-readers-drop.md
@@ -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).
14 changes: 13 additions & 1 deletion exec/plugin-commands-script-runners/src/dlx.ts
Expand Up @@ -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,
}
}

Expand All @@ -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,
Expand All @@ -52,6 +61,7 @@ export function help () {

export type DlxCommandOptions = {
package?: string[]
shellMode?: boolean
} & Pick<Config, 'reporter' | 'userAgent'> & add.AddCommandOptions

export async function handler (
Expand Down Expand Up @@ -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,
})
}

Expand Down
16 changes: 16 additions & 0 deletions exec/plugin-commands-script-runners/test/dlx.e2e.ts
Expand Up @@ -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()
})

0 comments on commit b3dfa3b

Please sign in to comment.