diff --git a/.changeset/angry-eagles-breathe.md b/.changeset/angry-eagles-breathe.md new file mode 100644 index 0000000000..3870bbc655 --- /dev/null +++ b/.changeset/angry-eagles-breathe.md @@ -0,0 +1,5 @@ +--- +"@pnpm/default-reporter": minor +--- + +Add an option to hide the directory prefix in the progress output. diff --git a/cli/default-reporter/src/index.ts b/cli/default-reporter/src/index.ts index 40f62f694b..170fa5f370 100644 --- a/cli/default-reporter/src/index.ts +++ b/cli/default-reporter/src/index.ts @@ -25,6 +25,7 @@ export function initDefaultReporter ( throttleProgress?: number outputMaxWidth?: number hideAddedPkgsProgress?: boolean + hideProgressPrefix?: boolean } context: { argv: string[] @@ -105,6 +106,7 @@ export function toOutput$ ( aggregateOutput?: boolean throttleProgress?: number hideAddedPkgsProgress?: boolean + hideProgressPrefix?: boolean } context: { argv: string[] @@ -262,6 +264,7 @@ export function toOutput$ ( throttleProgress: opts.reportingOptions?.throttleProgress, width: opts.reportingOptions?.outputMaxWidth, hideAddedPkgsProgress: opts.reportingOptions?.hideAddedPkgsProgress, + hideProgressPrefix: opts.reportingOptions?.hideProgressPrefix, } ) diff --git a/cli/default-reporter/src/reporterForClient/index.ts b/cli/default-reporter/src/reporterForClient/index.ts index 89100aadc1..c5c7c68466 100644 --- a/cli/default-reporter/src/reporterForClient/index.ts +++ b/cli/default-reporter/src/reporterForClient/index.ts @@ -67,6 +67,7 @@ export function reporterForClient ( throttleProgress?: number width?: number hideAddedPkgsProgress?: boolean + hideProgressPrefix?: boolean } ): Array>> { const width = opts.width ?? process.stdout.columns ?? 80 @@ -124,6 +125,7 @@ export function reporterForClient ( cwd, throttle, hideAddedPkgsProgress: opts.hideAddedPkgsProgress, + hideProgressPrefix: opts.hideProgressPrefix, }), ...reportStats(log$, { cmd: opts.cmd, diff --git a/cli/default-reporter/src/reporterForClient/reportProgress.ts b/cli/default-reporter/src/reporterForClient/reportProgress.ts index 31e809ec31..11450a334c 100644 --- a/cli/default-reporter/src/reporterForClient/reportProgress.ts +++ b/cli/default-reporter/src/reporterForClient/reportProgress.ts @@ -27,24 +27,27 @@ export function reportProgress ( // eslint-disable-next-line @typescript-eslint/no-explicit-any throttle?: Rx.OperatorFunction hideAddedPkgsProgress?: boolean + hideProgressPrefix?: boolean } ) { const progressOutput = throttledProgressOutput.bind(null, opts) return getModulesInstallProgress$(log$.stage, log$.progress).pipe( - map(({ importingDone$, progress$, requirer }) => { - const output$ = progressOutput(importingDone$, progress$) + map(opts.hideProgressPrefix + ? ({ importingDone$, progress$ }) => progressOutput(importingDone$, progress$) + : ({ importingDone$, progress$, requirer }) => { + const output$ = progressOutput(importingDone$, progress$) - if (requirer === opts.cwd) { - return output$ - } - return output$.pipe( - map((msg: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any - msg['msg'] = zoomOut(opts.cwd, requirer, msg['msg']) - return msg - }) - ) - }) + if (requirer === opts.cwd) { + return output$ + } + return output$.pipe( + map((msg: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any + msg['msg'] = zoomOut(opts.cwd, requirer, msg['msg']) + return msg + }) + ) + }) ) } diff --git a/cli/default-reporter/test/reportingProgress.ts b/cli/default-reporter/test/reportingProgress.ts index 2f42123cd5..32dd6d1837 100644 --- a/cli/default-reporter/test/reportingProgress.ts +++ b/cli/default-reporter/test/reportingProgress.ts @@ -159,6 +159,39 @@ test('prints progress beginning of node_modules from not cwd', (done) => { }) }) +test('prints progress beginning of node_modules from not cwd, when progress prefix is hidden', (done) => { + const output$ = toOutput$({ + context: { + argv: ['install'], + config: { dir: '/src/projects' } as Config, + }, + streamParser: createStreamParser(), + reportingOptions: { + hideProgressPrefix: true, + }, + }) + + stageLogger.debug({ + prefix: '/src/projects/foo', + stage: 'resolution_started', + }) + progressLogger.debug({ + packageId: 'registry.npmjs.org/foo/1.0.0', + requester: '/src/projects/foo', + 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')}, added ${hlValue('0')}`) + }, + }) +}) + test('prints progress beginning when appendOnly is true', (done) => { const output$ = toOutput$({ context: {