Skip to content

Commit 172b1f3

Browse files
authored
feat: align the time log format with Rsbuild (#85)
1 parent 00d190c commit 172b1f3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/plugin-dts/src/tsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export async function emitDts(
7474
throw new Error('DTS generation failed');
7575
}
7676

77-
logger.info(
78-
`DTS generation succeeded in ${getTimeCost(start)} ${color.gray(`(${name})`)}`,
77+
logger.ready(
78+
`DTS generated in ${getTimeCost(start)} ${color.gray(`(${name})`)}`,
7979
);
8080
} else {
8181
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;

packages/plugin-dts/src/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,25 @@ export function getFileLoc(diagnostic: ts.Diagnostic): string {
4848
return '';
4949
}
5050

51+
export const prettyTime = (seconds: number): string => {
52+
const format = (time: string) => color.bold(time);
53+
54+
if (seconds < 10) {
55+
const digits = seconds >= 0.01 ? 2 : 3;
56+
return `${format(seconds.toFixed(digits))} s`;
57+
}
58+
59+
if (seconds < 60) {
60+
return `${format(seconds.toFixed(1))} s`;
61+
}
62+
63+
const minutes = seconds / 60;
64+
return `${format(minutes.toFixed(2))} m`;
65+
};
66+
5167
export function getTimeCost(start: number): string {
52-
return `${Math.floor(Date.now() - start)}ms`;
68+
const second = (Date.now() - start) / 1000;
69+
return prettyTime(second);
5370
}
5471

5572
export async function processDtsFiles(

0 commit comments

Comments
 (0)