mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-14 09:02:44 -05: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.',
|
||||
name: '--stream',
|
||||
},
|
||||
{
|
||||
description: 'Divert all output to stderr',
|
||||
name: '--use-stderr',
|
||||
},
|
||||
]
|
||||
export const FILTERING = {
|
||||
list: [
|
||||
|
||||
@@ -66,6 +66,7 @@ export interface Config {
|
||||
ignoreCurrentPrefs?: boolean
|
||||
recursive?: boolean
|
||||
enablePrePostScripts?: boolean
|
||||
useStderr?: boolean
|
||||
|
||||
// proxy
|
||||
httpProxy?: string
|
||||
|
||||
@@ -96,6 +96,7 @@ export const types = Object.assign({
|
||||
'use-beta-cli': Boolean,
|
||||
'use-running-store-server': Boolean,
|
||||
'use-store-server': Boolean,
|
||||
'use-stderr': Boolean,
|
||||
'verify-store-integrity': Boolean,
|
||||
'virtual-store-dir': String,
|
||||
'workspace-concurrency': Number,
|
||||
|
||||
@@ -14,6 +14,7 @@ export { formatWarn }
|
||||
|
||||
export default function (
|
||||
opts: {
|
||||
useStderr?: boolean
|
||||
streamParser: object
|
||||
reportingOptions?: {
|
||||
appendOnly?: boolean
|
||||
@@ -37,11 +38,14 @@ export default function (
|
||||
const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (process.stdout.columns && process.stdout.columns - 2) ?? 80
|
||||
const output$ = toOutput$({ ...opts, reportingOptions: { ...opts.reportingOptions, outputMaxWidth } })
|
||||
if (opts.reportingOptions?.appendOnly) {
|
||||
const writeNext = opts.useStderr
|
||||
? console.error.bind(console)
|
||||
: console.log.bind(console)
|
||||
output$
|
||||
.subscribe({
|
||||
complete () {}, // eslint-disable-line:no-empty
|
||||
error: (err) => console.error(err.message),
|
||||
next: (line) => console.log(line),
|
||||
next: writeNext,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -55,12 +59,15 @@ export default function (
|
||||
error: (err) => logUpdate(err.message),
|
||||
next: logUpdate,
|
||||
})
|
||||
const write = opts.useStderr
|
||||
? process.stderr.write.bind(process.stderr)
|
||||
: process.stdout.write.bind(process.stdout)
|
||||
function logUpdate (view: string) {
|
||||
// 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.
|
||||
// An example of such prompt may be seen by running: pnpm update --interactive
|
||||
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',
|
||||
'stream',
|
||||
'test-pattern',
|
||||
'use-stderr',
|
||||
'workspace-packages',
|
||||
'workspace-root',
|
||||
], allTypes)
|
||||
|
||||
@@ -15,6 +15,7 @@ export default (
|
||||
switch (reporterType) {
|
||||
case 'default':
|
||||
defaultReporter({
|
||||
useStderr: opts.config.useStderr,
|
||||
context: {
|
||||
argv: opts.cmd ? [opts.cmd] : [],
|
||||
config: opts.config,
|
||||
@@ -30,6 +31,7 @@ export default (
|
||||
return
|
||||
case 'append-only':
|
||||
defaultReporter({
|
||||
useStderr: opts.config.useStderr,
|
||||
context: {
|
||||
argv: opts.cmd ? [opts.cmd] : [],
|
||||
config: opts.config,
|
||||
|
||||
@@ -67,6 +67,16 @@ test('install --no-lockfile', async () => {
|
||||
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 () => {
|
||||
const project = prepare()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user