mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-19 14:20:36 -04:00
fix: don't print added stats when installing lockfile only (#6868)
Related PR: https://github.com/teambit/bit/pull/7703
This commit is contained in:
6
.changeset/giant-feet-cheat.md
Normal file
6
.changeset/giant-feet-cheat.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/default-reporter": patch
|
||||||
|
"pnpm": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Don't print "added" stats, when installing with `--lockfile-only`.
|
||||||
@@ -24,6 +24,7 @@ export function initDefaultReporter (
|
|||||||
aggregateOutput?: boolean
|
aggregateOutput?: boolean
|
||||||
throttleProgress?: number
|
throttleProgress?: number
|
||||||
outputMaxWidth?: number
|
outputMaxWidth?: number
|
||||||
|
hideAddedPkgsProgress?: boolean
|
||||||
}
|
}
|
||||||
context: {
|
context: {
|
||||||
argv: string[]
|
argv: string[]
|
||||||
@@ -103,6 +104,7 @@ export function toOutput$ (
|
|||||||
streamLifecycleOutput?: boolean
|
streamLifecycleOutput?: boolean
|
||||||
aggregateOutput?: boolean
|
aggregateOutput?: boolean
|
||||||
throttleProgress?: number
|
throttleProgress?: number
|
||||||
|
hideAddedPkgsProgress?: boolean
|
||||||
}
|
}
|
||||||
context: {
|
context: {
|
||||||
argv: string[]
|
argv: string[]
|
||||||
@@ -259,6 +261,7 @@ export function toOutput$ (
|
|||||||
aggregateOutput: opts.reportingOptions?.aggregateOutput,
|
aggregateOutput: opts.reportingOptions?.aggregateOutput,
|
||||||
throttleProgress: opts.reportingOptions?.throttleProgress,
|
throttleProgress: opts.reportingOptions?.throttleProgress,
|
||||||
width: opts.reportingOptions?.outputMaxWidth,
|
width: opts.reportingOptions?.outputMaxWidth,
|
||||||
|
hideAddedPkgsProgress: opts.reportingOptions?.hideAddedPkgsProgress,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export function reporterForClient (
|
|||||||
aggregateOutput?: boolean
|
aggregateOutput?: boolean
|
||||||
throttleProgress?: number
|
throttleProgress?: number
|
||||||
width?: number
|
width?: number
|
||||||
|
hideAddedPkgsProgress?: boolean
|
||||||
}
|
}
|
||||||
): Array<Rx.Observable<Rx.Observable<{ msg: string }>>> {
|
): Array<Rx.Observable<Rx.Observable<{ msg: string }>>> {
|
||||||
const width = opts.width ?? process.stdout.columns ?? 80
|
const width = opts.width ?? process.stdout.columns ?? 80
|
||||||
@@ -122,6 +123,7 @@ export function reporterForClient (
|
|||||||
reportProgress(log$, {
|
reportProgress(log$, {
|
||||||
cwd,
|
cwd,
|
||||||
throttle,
|
throttle,
|
||||||
|
hideAddedPkgsProgress: opts.hideAddedPkgsProgress,
|
||||||
}),
|
}),
|
||||||
...reportStats(log$, {
|
...reportStats(log$, {
|
||||||
cmd: opts.cmd,
|
cmd: opts.cmd,
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ export function reportProgress (
|
|||||||
cwd: string
|
cwd: string
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
throttle?: Rx.OperatorFunction<any, any>
|
throttle?: Rx.OperatorFunction<any, any>
|
||||||
|
hideAddedPkgsProgress?: boolean
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const progressOutput = throttledProgressOutput.bind(null, opts.throttle)
|
const progressOutput = throttledProgressOutput.bind(null, opts)
|
||||||
|
|
||||||
return getModulesInstallProgress$(log$.stage, log$.progress).pipe(
|
return getModulesInstallProgress$(log$.stage, log$.progress).pipe(
|
||||||
map(({ importingDone$, progress$, requirer }) => {
|
map(({ importingDone$, progress$, requirer }) => {
|
||||||
@@ -48,13 +49,16 @@ export function reportProgress (
|
|||||||
}
|
}
|
||||||
|
|
||||||
function throttledProgressOutput (
|
function throttledProgressOutput (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
opts: {
|
||||||
throttle: Rx.OperatorFunction<any, any> | undefined,
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
throttle?: Rx.OperatorFunction<any, any>
|
||||||
|
hideAddedPkgsProgress?: boolean
|
||||||
|
},
|
||||||
importingDone$: Rx.Observable<boolean>,
|
importingDone$: Rx.Observable<boolean>,
|
||||||
progress$: Rx.Observable<ProgressStats>
|
progress$: Rx.Observable<ProgressStats>
|
||||||
) {
|
) {
|
||||||
if (throttle != null) {
|
if (opts.throttle != null) {
|
||||||
progress$ = progress$.pipe(throttle)
|
progress$ = progress$.pipe(opts.throttle)
|
||||||
}
|
}
|
||||||
const combinedProgress = Rx.combineLatest(
|
const combinedProgress = Rx.combineLatest(
|
||||||
progress$,
|
progress$,
|
||||||
@@ -63,7 +67,7 @@ function throttledProgressOutput (
|
|||||||
// Avoid logs after all resolved packages were downloaded.
|
// Avoid logs after all resolved packages were downloaded.
|
||||||
// Fixing issue: https://github.com/pnpm/pnpm/issues/1028#issuecomment-364782901
|
// Fixing issue: https://github.com/pnpm/pnpm/issues/1028#issuecomment-364782901
|
||||||
.pipe(takeWhile(([, importingDone]) => !importingDone, true))
|
.pipe(takeWhile(([, importingDone]) => !importingDone, true))
|
||||||
return combinedProgress.pipe(map(createStatusMessage))
|
return combinedProgress.pipe(map(opts.hideAddedPkgsProgress ? createStatusMessageWithoutAdded : createStatusMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getModulesInstallProgress$ (
|
function getModulesInstallProgress$ (
|
||||||
@@ -151,7 +155,36 @@ function getProgressStatsPushStreamByRequirer (progress$: Rx.Observable<Progress
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createStatusMessage ([progress, importingDone]: [ProgressStats, boolean]) {
|
function createStatusMessage ([progress, importingDone]: [ProgressStats, boolean]) {
|
||||||
const msg = `Progress: resolved ${hlValue(progress.resolved.toString())}, reused ${hlValue(progress.reused.toString())}, downloaded ${hlValue(progress.fetched.toString())}, added ${hlValue(progress.imported.toString())}`
|
const msg = `Progress: resolved ${
|
||||||
|
hlValue(progress.resolved.toString())
|
||||||
|
}, reused ${
|
||||||
|
hlValue(progress.reused.toString())
|
||||||
|
}, downloaded ${
|
||||||
|
hlValue(progress.fetched.toString())
|
||||||
|
}, added ${
|
||||||
|
hlValue(progress.imported.toString())
|
||||||
|
}`
|
||||||
|
if (importingDone) {
|
||||||
|
return {
|
||||||
|
done: true,
|
||||||
|
fixed: false,
|
||||||
|
msg: `${msg}, done`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
fixed: true,
|
||||||
|
msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStatusMessageWithoutAdded ([progress, importingDone]: [ProgressStats, boolean]) {
|
||||||
|
const msg = `Progress: resolved ${
|
||||||
|
hlValue(progress.resolved.toString())
|
||||||
|
}, reused ${
|
||||||
|
hlValue(progress.reused.toString())
|
||||||
|
}, downloaded ${
|
||||||
|
hlValue(progress.fetched.toString())
|
||||||
|
}`
|
||||||
if (importingDone) {
|
if (importingDone) {
|
||||||
return {
|
return {
|
||||||
done: true,
|
done: true,
|
||||||
|
|||||||
@@ -50,6 +50,39 @@ test('prints progress beginning', (done) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('prints progress without added packges stats', (done) => {
|
||||||
|
const output$ = toOutput$({
|
||||||
|
context: {
|
||||||
|
argv: ['install'],
|
||||||
|
config: { dir: '/src/project' } as Config,
|
||||||
|
},
|
||||||
|
reportingOptions: {
|
||||||
|
hideAddedPkgsProgress: true,
|
||||||
|
},
|
||||||
|
streamParser: createStreamParser(),
|
||||||
|
})
|
||||||
|
|
||||||
|
stageLogger.debug({
|
||||||
|
prefix: '/src/project',
|
||||||
|
stage: 'resolution_started',
|
||||||
|
})
|
||||||
|
progressLogger.debug({
|
||||||
|
packageId: 'registry.npmjs.org/foo/1.0.0',
|
||||||
|
requester: '/src/project',
|
||||||
|
status: 'resolved',
|
||||||
|
})
|
||||||
|
|
||||||
|
expect.assertions(1)
|
||||||
|
|
||||||
|
output$.pipe(take(1)).subscribe({
|
||||||
|
complete: () => done(),
|
||||||
|
error: done,
|
||||||
|
next: output => {
|
||||||
|
expect(output).toBe(`Progress: resolved ${hlValue('1')}, reused ${hlValue('0')}, downloaded ${hlValue('0')}`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('prints all progress stats', (done) => {
|
test('prints all progress stats', (done) => {
|
||||||
const output$ = toOutput$({
|
const output$ = toOutput$({
|
||||||
context: {
|
context: {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export function initReporter (
|
|||||||
logLevel: opts.config.loglevel as LogLevel,
|
logLevel: opts.config.loglevel as LogLevel,
|
||||||
streamLifecycleOutput: opts.config.stream,
|
streamLifecycleOutput: opts.config.stream,
|
||||||
throttleProgress: 200,
|
throttleProgress: 200,
|
||||||
|
hideAddedPkgsProgress: opts.config.lockfileOnly,
|
||||||
},
|
},
|
||||||
streamParser,
|
streamParser,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user