Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-commands-script-runners): add --shell-mode option for pnpm dlx #5840

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/olive-readers-drop.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
})