@@ -8,6 +8,7 @@ import { ensureProjectCacheDir } from '../projectCache.ts';
88import { fmtCacheFileName } from './cacheStore.ts' ;
99import { resolveFmtConfig } from './config.ts' ;
1010import { discoverFmtFiles } from './discovery.ts' ;
11+ import { formatDuration } from './duration.ts' ;
1112import { createRelativePathResolver , toPosixPath } from './pathHelpers.ts' ;
1213import { runFmtFiles } from './runner.ts' ;
1314import type { FmtMode , FmtRunResult , ResolvedFmtConfig } from './types.ts' ;
@@ -157,35 +158,6 @@ const createDisplayPathResolver = (
157158 return ( filePath ) => toPosixPath ( resolveRelativePath ( filePath ) ) ;
158159} ;
159160
160- const prettyTime = ( seconds : number ) : string => {
161- const format = ( time : string , unit : 'm' | 's' ) =>
162- color . bold ( `${ time } ${ unit } ` ) ;
163-
164- if ( seconds < 10 ) {
165- const digits = seconds >= 0.01 ? 2 : 3 ;
166- return format ( seconds . toFixed ( digits ) , 's' ) ;
167- }
168-
169- if ( seconds < 60 ) {
170- return format ( seconds . toFixed ( 1 ) , 's' ) ;
171- }
172-
173- const minutes = Math . floor ( seconds / 60 ) ;
174- const minutesLabel = format ( minutes . toFixed ( 0 ) , 'm' ) ;
175- const remainingSeconds = seconds % 60 ;
176-
177- if ( remainingSeconds === 0 ) {
178- return minutesLabel ;
179- }
180-
181- const secondsLabel = format (
182- remainingSeconds . toFixed ( remainingSeconds % 1 === 0 ? 0 : 1 ) ,
183- 's' ,
184- ) ;
185-
186- return `${ minutesLabel } ${ secondsLabel } ` ;
187- } ;
188-
189161const formatCount = ( count : number ) : string => color . bold ( count ) ;
190162const formatFileCount = ( count : number , isError = false ) : string => {
191163 const formattedCount = formatCount ( count ) ;
@@ -207,7 +179,7 @@ const logFmtResult = (
207179 mode : FmtMode ,
208180 cwd : string ,
209181 processedFileCount : number ,
210- durationSeconds : number ,
182+ durationMilliseconds : number ,
211183 fixCommand ?: string ,
212184) : void => {
213185 let writtenCount = 0 ;
@@ -229,13 +201,18 @@ const logFmtResult = (
229201 }
230202 }
231203
204+ if ( mode === 'list-different' ) {
205+ return ;
206+ }
207+
208+ const time = color . bold ( formatDuration ( durationMilliseconds ) ) ;
209+
232210 if ( mode === 'write' ) {
233211 if ( writtenCount === 0 && result . exitCode !== 0 ) {
234212 return ;
235213 }
236214
237215 const processedFiles = formatFileCount ( processedFileCount ) ;
238- const time = prettyTime ( durationSeconds ) ;
239216 const message =
240217 writtenCount > 0
241218 ? `Formatted ${ formatCount ( writtenCount ) } of ${ processedFiles } in ${ time } .`
@@ -244,21 +221,17 @@ const logFmtResult = (
244221 return ;
245222 }
246223
247- if ( mode !== 'check' ) {
248- return ;
249- }
250-
251224 if ( differentCount > 0 ) {
252225 const differentFiles = formatFileCount ( differentCount , true ) ;
253226 const processedFiles = formatFileCount ( processedFileCount ) ;
254227 const fixHint = fixCommand
255228 ? `Run ${ color . cyan ( fixCommand ) } to fix.`
256229 : `Rerun this command without ${ color . cyan ( '--check' ) } to fix.` ;
257230 logger . error ( `Formatting issues found in ${ differentFiles } . ${ fixHint } ` ) ;
258- logger . info ( `Checked ${ processedFiles } in ${ prettyTime ( durationSeconds ) } .` ) ;
231+ logger . info ( `Checked ${ processedFiles } in ${ time } .` ) ;
259232 } else if ( result . exitCode === 0 ) {
260233 logger . success (
261- `Checked ${ formatFileCount ( processedFileCount ) } in ${ prettyTime ( durationSeconds ) } . No issues found.` ,
234+ `Checked ${ formatFileCount ( processedFileCount ) } in ${ time } . No issues found.` ,
262235 ) ;
263236 }
264237} ;
@@ -415,13 +388,13 @@ const runFmtCLI = async (
415388 return ;
416389 }
417390
418- const durationSeconds = ( performance . now ( ) - startTime ) / 1000 ;
391+ const durationMilliseconds = performance . now ( ) - startTime ;
419392 logFmtResult (
420393 result ,
421394 mode ,
422395 cwd ,
423396 result . processedFileCount ,
424- durationSeconds ,
397+ durationMilliseconds ,
425398 fixCommand ,
426399 ) ;
427400 process . exitCode = result . exitCode ;
0 commit comments