( paths: string[], abortSignal: AbortSignal, )
| 103 | } |
| 104 | |
| 105 | async function sortFileMatchesByModifiedTime( |
| 106 | paths: string[], |
| 107 | abortSignal: AbortSignal, |
| 108 | ): Promise<string[]> { |
| 109 | const fs = getFsImplementation() |
| 110 | const matches: Array<{ path: string; mtimeMs: number }> = [] |
| 111 | const batchSize = 256 |
| 112 | |
| 113 | for (let i = 0; i < paths.length; i += batchSize) { |
| 114 | if (abortSignal.aborted) { |
| 115 | throw abortSignal.reason ?? new Error('Glob aborted') |
| 116 | } |
| 117 | |
| 118 | const batch = paths.slice(i, i + batchSize) |
| 119 | const stats = await Promise.allSettled(batch.map(path => fs.stat(path))) |
| 120 | for (let j = 0; j < batch.length; j++) { |
| 121 | const result = stats[j]! |
| 122 | matches.push({ |
| 123 | path: batch[j]!, |
| 124 | mtimeMs: |
| 125 | result.status === 'fulfilled' ? (result.value.mtimeMs ?? 0) : 0, |
| 126 | }) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | matches.sort( |
| 131 | (a, b) => a.mtimeMs - b.mtimeMs || a.path.localeCompare(b.path), |
| 132 | ) |
| 133 | return matches.map(match => match.path) |
| 134 | } |
| 135 | |
| 136 | function getDirectoryGlobMaxDepth(pattern: string): number { |
| 137 | const normalized = normalizeGlobPattern(pattern).replace(/\/+$/, '') |
no test coverage detected