Skip to content

Commit

Permalink
feat: align the time log format with Rsbuild (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Aug 13, 2024
1 parent 00d190c commit 172b1f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-dts/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export async function emitDts(
throw new Error('DTS generation failed');
}

logger.info(
`DTS generation succeeded in ${getTimeCost(start)} ${color.gray(`(${name})`)}`,
logger.ready(
`DTS generated in ${getTimeCost(start)} ${color.gray(`(${name})`)}`,
);
} else {
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
Expand Down
19 changes: 18 additions & 1 deletion packages/plugin-dts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,25 @@ export function getFileLoc(diagnostic: ts.Diagnostic): string {
return '';
}

export const prettyTime = (seconds: number): string => {
const format = (time: string) => color.bold(time);

if (seconds < 10) {
const digits = seconds >= 0.01 ? 2 : 3;
return `${format(seconds.toFixed(digits))} s`;
}

if (seconds < 60) {
return `${format(seconds.toFixed(1))} s`;
}

const minutes = seconds / 60;
return `${format(minutes.toFixed(2))} m`;
};

export function getTimeCost(start: number): string {
return `${Math.floor(Date.now() - start)}ms`;
const second = (Date.now() - start) / 1000;
return prettyTime(second);
}

export async function processDtsFiles(
Expand Down

0 comments on commit 172b1f3

Please sign in to comment.