Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #1021
- Loading branch information
Showing
10 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@pnpm/core-loggers": minor | ||
"@pnpm/default-reporter": minor | ||
"pnpm": patch | ||
--- | ||
|
||
Show execution time on `install`, `update`, `add`, and `remove` [#1021](https://github.com/pnpm/pnpm/issues/1021). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import baseLogger, { | ||
LogBase, | ||
} from '@pnpm/logger' | ||
|
||
export const executionTimeLogger = baseLogger('execution-time') | ||
|
||
export interface ExecutionTimeMessage { | ||
startedAt: number | ||
endedAt: number | ||
} | ||
|
||
export type ExecutionTimeLog = { name: 'pnpm:execution-time' } & LogBase & ExecutionTimeMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/default-reporter/src/reporterForClient/reportExecutionTime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import prettyMs from 'pretty-ms' | ||
import { ExecutionTimeLog } from '@pnpm/core-loggers' | ||
import * as Rx from 'rxjs' | ||
import { map, take } from 'rxjs/operators' | ||
|
||
export function reportExecutionTime ( | ||
executionTime$: Rx.Observable<ExecutionTimeLog> | ||
) { | ||
return executionTime$.pipe( | ||
take(1), | ||
map((log) => { | ||
return Rx.of({ | ||
fixed: true, // Without this, for some reason sometimes the progress bar is printed after the execution time | ||
msg: `Done in ${prettyMs(log.endedAt - log.startedAt)}`, | ||
}) | ||
}) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { executionTimeLogger } from '@pnpm/core-loggers' | ||
import { toOutput$ } from '@pnpm/default-reporter' | ||
import { createStreamParser } from '@pnpm/logger' | ||
import { take } from 'rxjs/operators' | ||
|
||
test('does not print execution time for help command', (done) => { | ||
const output$ = toOutput$({ | ||
context: { | ||
argv: ['help'], | ||
}, | ||
streamParser: createStreamParser(), | ||
}) | ||
|
||
executionTimeLogger.debug({ | ||
startedAt: 1665279402859, | ||
endedAt: 1665279413671, | ||
}) | ||
|
||
const subscription = output$.subscribe({ | ||
complete: () => done(), | ||
error: done, | ||
next: () => { | ||
done('should not log anything') | ||
}, | ||
}) | ||
|
||
setTimeout(() => { | ||
done() | ||
subscription.unsubscribe() | ||
}, 10) | ||
}) | ||
|
||
test('prints execution time for install command', (done) => { | ||
const output$ = toOutput$({ | ||
context: { | ||
argv: ['install'], | ||
}, | ||
streamParser: createStreamParser(), | ||
}) | ||
|
||
executionTimeLogger.debug({ | ||
startedAt: 1665279402859, | ||
endedAt: 1665279413671, | ||
}) | ||
|
||
expect.assertions(1) | ||
|
||
output$.pipe(take(1)).subscribe({ | ||
complete: () => done(), | ||
error: done, | ||
next: output => { | ||
expect(output).toBe('Done in 10.8s') | ||
}, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters