mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-19 06:07:59 -04:00
feat: --use-stderr (#3463)
This commit is contained in:
8
.changeset/sweet-fireants-sniff.md
Normal file
8
.changeset/sweet-fireants-sniff.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/config": minor
|
||||||
|
"@pnpm/default-reporter": minor
|
||||||
|
"@pnpm/common-cli-options-help": minor
|
||||||
|
"pnpm": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
New CLI option added: `use-stderr`. When set, all the output is written to stderr.
|
||||||
@@ -53,6 +53,10 @@ export const UNIVERSAL_OPTIONS = [
|
|||||||
description: 'Stream output from child processes immediately, prefixed with the originating package directory. This allows output from different packages to be interleaved.',
|
description: 'Stream output from child processes immediately, prefixed with the originating package directory. This allows output from different packages to be interleaved.',
|
||||||
name: '--stream',
|
name: '--stream',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'Divert all output to stderr',
|
||||||
|
name: '--use-stderr',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
export const FILTERING = {
|
export const FILTERING = {
|
||||||
list: [
|
list: [
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export interface Config {
|
|||||||
ignoreCurrentPrefs?: boolean
|
ignoreCurrentPrefs?: boolean
|
||||||
recursive?: boolean
|
recursive?: boolean
|
||||||
enablePrePostScripts?: boolean
|
enablePrePostScripts?: boolean
|
||||||
|
useStderr?: boolean
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
httpProxy?: string
|
httpProxy?: string
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export const types = Object.assign({
|
|||||||
'use-beta-cli': Boolean,
|
'use-beta-cli': Boolean,
|
||||||
'use-running-store-server': Boolean,
|
'use-running-store-server': Boolean,
|
||||||
'use-store-server': Boolean,
|
'use-store-server': Boolean,
|
||||||
|
'use-stderr': Boolean,
|
||||||
'verify-store-integrity': Boolean,
|
'verify-store-integrity': Boolean,
|
||||||
'virtual-store-dir': String,
|
'virtual-store-dir': String,
|
||||||
'workspace-concurrency': Number,
|
'workspace-concurrency': Number,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export { formatWarn }
|
|||||||
|
|
||||||
export default function (
|
export default function (
|
||||||
opts: {
|
opts: {
|
||||||
|
useStderr?: boolean
|
||||||
streamParser: object
|
streamParser: object
|
||||||
reportingOptions?: {
|
reportingOptions?: {
|
||||||
appendOnly?: boolean
|
appendOnly?: boolean
|
||||||
@@ -37,11 +38,14 @@ export default function (
|
|||||||
const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (process.stdout.columns && process.stdout.columns - 2) ?? 80
|
const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (process.stdout.columns && process.stdout.columns - 2) ?? 80
|
||||||
const output$ = toOutput$({ ...opts, reportingOptions: { ...opts.reportingOptions, outputMaxWidth } })
|
const output$ = toOutput$({ ...opts, reportingOptions: { ...opts.reportingOptions, outputMaxWidth } })
|
||||||
if (opts.reportingOptions?.appendOnly) {
|
if (opts.reportingOptions?.appendOnly) {
|
||||||
|
const writeNext = opts.useStderr
|
||||||
|
? console.error.bind(console)
|
||||||
|
: console.log.bind(console)
|
||||||
output$
|
output$
|
||||||
.subscribe({
|
.subscribe({
|
||||||
complete () {}, // eslint-disable-line:no-empty
|
complete () {}, // eslint-disable-line:no-empty
|
||||||
error: (err) => console.error(err.message),
|
error: (err) => console.error(err.message),
|
||||||
next: (line) => console.log(line),
|
next: writeNext,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -55,12 +59,15 @@ export default function (
|
|||||||
error: (err) => logUpdate(err.message),
|
error: (err) => logUpdate(err.message),
|
||||||
next: logUpdate,
|
next: logUpdate,
|
||||||
})
|
})
|
||||||
|
const write = opts.useStderr
|
||||||
|
? process.stderr.write.bind(process.stderr)
|
||||||
|
: process.stdout.write.bind(process.stdout)
|
||||||
function logUpdate (view: string) {
|
function logUpdate (view: string) {
|
||||||
// A new line should always be appended in case a prompt needs to appear.
|
// A new line should always be appended in case a prompt needs to appear.
|
||||||
// Without a new line the prompt will be joined with the previous output.
|
// Without a new line the prompt will be joined with the previous output.
|
||||||
// An example of such prompt may be seen by running: pnpm update --interactive
|
// An example of such prompt may be seen by running: pnpm update --interactive
|
||||||
if (!view.endsWith(EOL)) view += EOL
|
if (!view.endsWith(EOL)) view += EOL
|
||||||
process.stdout.write(diff.update(view))
|
write(diff.update(view))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export const GLOBAL_OPTIONS = R.pick([
|
|||||||
'reporter',
|
'reporter',
|
||||||
'stream',
|
'stream',
|
||||||
'test-pattern',
|
'test-pattern',
|
||||||
|
'use-stderr',
|
||||||
'workspace-packages',
|
'workspace-packages',
|
||||||
'workspace-root',
|
'workspace-root',
|
||||||
], allTypes)
|
], allTypes)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default (
|
|||||||
switch (reporterType) {
|
switch (reporterType) {
|
||||||
case 'default':
|
case 'default':
|
||||||
defaultReporter({
|
defaultReporter({
|
||||||
|
useStderr: opts.config.useStderr,
|
||||||
context: {
|
context: {
|
||||||
argv: opts.cmd ? [opts.cmd] : [],
|
argv: opts.cmd ? [opts.cmd] : [],
|
||||||
config: opts.config,
|
config: opts.config,
|
||||||
@@ -30,6 +31,7 @@ export default (
|
|||||||
return
|
return
|
||||||
case 'append-only':
|
case 'append-only':
|
||||||
defaultReporter({
|
defaultReporter({
|
||||||
|
useStderr: opts.config.useStderr,
|
||||||
context: {
|
context: {
|
||||||
argv: opts.cmd ? [opts.cmd] : [],
|
argv: opts.cmd ? [opts.cmd] : [],
|
||||||
config: opts.config,
|
config: opts.config,
|
||||||
|
|||||||
@@ -67,6 +67,16 @@ test('install --no-lockfile', async () => {
|
|||||||
expect(await project.readLockfile()).toBeFalsy()
|
expect(await project.readLockfile()).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('write to stderr when --use-stderr is used', async () => {
|
||||||
|
const project = prepare()
|
||||||
|
|
||||||
|
const result = execPnpmSync(['add', 'is-positive', '--use-stderr'])
|
||||||
|
|
||||||
|
await project.has('is-positive')
|
||||||
|
expect(result.stdout.toString()).toBe('')
|
||||||
|
expect(result.stderr.toString()).not.toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
test('install with package-lock=false in .npmrc', async () => {
|
test('install with package-lock=false in .npmrc', async () => {
|
||||||
const project = prepare()
|
const project = prepare()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user