mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-12 00:48:21 -05:00
6
.changeset/gold-foxes-explode.md
Normal file
6
.changeset/gold-foxes-explode.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
`pnpm dlx` supports the `--silent` option.
|
||||
5
.changeset/rude-rice-occur.md
Normal file
5
.changeset/rude-rice-occur.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/common-cli-options-help": patch
|
||||
---
|
||||
|
||||
`OUTPUT_OPTIONS` added.
|
||||
@@ -115,3 +115,27 @@ export const FILTERING = {
|
||||
],
|
||||
title: 'Filtering options (run the command only on packages that satisfy at least one of the selectors)',
|
||||
}
|
||||
|
||||
export const OUTPUT_OPTIONS = {
|
||||
title: 'Output',
|
||||
|
||||
list: [
|
||||
{
|
||||
description: 'No output is logged to the console, except fatal errors',
|
||||
name: '--silent, --reporter silent',
|
||||
shortAlias: '-s',
|
||||
},
|
||||
{
|
||||
description: 'The default reporter when the stdout is TTY',
|
||||
name: '--reporter default',
|
||||
},
|
||||
{
|
||||
description: 'The output is always appended to the end. No cursor manipulations are performed',
|
||||
name: '--reporter append-only',
|
||||
},
|
||||
{
|
||||
description: 'The most verbose reporter. Prints all logs in ndjson format',
|
||||
name: '--reporter ndjson',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { FILTERING, OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { FILTERING, OPTIONS, OUTPUT_OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { Config, types as allTypes } from '@pnpm/config'
|
||||
import { WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import { CreateStoreControllerOptions } from '@pnpm/store-connection-manager'
|
||||
@@ -207,29 +207,7 @@ by any dependencies, so it is an emulation of a flat node_modules',
|
||||
...UNIVERSAL_OPTIONS,
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Output',
|
||||
|
||||
list: [
|
||||
{
|
||||
description: 'No output is logged to the console, except fatal errors',
|
||||
name: '--silent, --reporter silent',
|
||||
shortAlias: '-s',
|
||||
},
|
||||
{
|
||||
description: 'The default reporter when the stdout is TTY',
|
||||
name: '--reporter default',
|
||||
},
|
||||
{
|
||||
description: 'The output is always appended to the end. No cursor manipulations are performed',
|
||||
name: '--reporter append-only',
|
||||
},
|
||||
{
|
||||
description: 'The most verbose reporter. Prints all logs in ndjson format',
|
||||
name: '--reporter ndjson',
|
||||
},
|
||||
],
|
||||
},
|
||||
OUTPUT_OPTIONS,
|
||||
FILTERING,
|
||||
{
|
||||
title: 'Experimental options',
|
||||
|
||||
@@ -2,6 +2,8 @@ import fs from 'fs'
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { OUTPUT_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { Config } from '@pnpm/config'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
import execa from 'execa'
|
||||
import PATH from 'path-name'
|
||||
@@ -31,6 +33,7 @@ export function help () {
|
||||
},
|
||||
],
|
||||
},
|
||||
OUTPUT_OPTIONS,
|
||||
],
|
||||
url: docsUrl('dlx'),
|
||||
usages: ['pnpm dlx <command> [args...]'],
|
||||
@@ -40,7 +43,7 @@ export function help () {
|
||||
export async function handler (
|
||||
opts: {
|
||||
package?: string[]
|
||||
},
|
||||
} & Pick<Config, 'reporter'>,
|
||||
params: string[]
|
||||
) {
|
||||
const prefix = path.join(fs.realpathSync(os.tmpdir()), `dlx-${process.pid.toString()}`)
|
||||
@@ -58,7 +61,11 @@ export async function handler (
|
||||
})
|
||||
await rimraf(bins)
|
||||
const pkgs = opts.package ?? params.slice(0, 1)
|
||||
await execa('pnpm', ['add', ...pkgs, '--global', '--global-dir', prefix, '--dir', prefix], {
|
||||
const pnpmArgs = ['add', ...pkgs, '--global', '--global-dir', prefix, '--dir', prefix]
|
||||
if (opts.reporter) {
|
||||
pnpmArgs.push(`--reporter=${opts.reporter}`)
|
||||
}
|
||||
await execa('pnpm', pnpmArgs, {
|
||||
stdio: 'inherit',
|
||||
})
|
||||
await execa(params[0], params.slice(1), {
|
||||
|
||||
@@ -77,3 +77,11 @@ test('silent run only prints the output of the child process', async () => {
|
||||
|
||||
expect(result.stdout.toString().trim()).toBe('hi')
|
||||
})
|
||||
|
||||
test('silent dlx prints the output of the child process only', async () => {
|
||||
prepare({})
|
||||
|
||||
const result = execPnpmSync(['--silent', 'dlx', 'shx', 'echo', 'hi'])
|
||||
|
||||
expect(result.stdout.toString().trim()).toBe('hi')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user