( entries: GlobPath[], nowTimestamp: number, recencyThresholdMs: number, )
| 31 | * Older files are listed after recent ones, sorted alphabetically by path. |
| 32 | */ |
| 33 | export function sortFileEntries( |
| 34 | entries: GlobPath[], |
| 35 | nowTimestamp: number, |
| 36 | recencyThresholdMs: number, |
| 37 | ): GlobPath[] { |
| 38 | const sortedEntries = [...entries]; |
| 39 | sortedEntries.sort((a, b) => { |
| 40 | const mtimeA = a.mtimeMs ?? 0; |
| 41 | const mtimeB = b.mtimeMs ?? 0; |
| 42 | const aIsRecent = nowTimestamp - mtimeA < recencyThresholdMs; |
| 43 | const bIsRecent = nowTimestamp - mtimeB < recencyThresholdMs; |
| 44 | |
| 45 | if (aIsRecent && bIsRecent) { |
| 46 | return mtimeB - mtimeA; |
| 47 | } else if (aIsRecent) { |
| 48 | return -1; |
| 49 | } else if (bIsRecent) { |
| 50 | return 1; |
| 51 | } else { |
| 52 | return a.fullpath().localeCompare(b.fullpath()); |
| 53 | } |
| 54 | }); |
| 55 | return sortedEntries; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Parameters for the GlobTool |
no test coverage detected