(version: string, directory = releaseBenchmarkDir())
| 98 | |
| 99 | /** Find the latest stable benchmark snapshot lower than the release candidate version. */ |
| 100 | export function findPreviousReleaseBenchmark(version: string, directory = releaseBenchmarkDir()) { |
| 101 | const current = parseReleaseVersion(version); |
| 102 | if (!existsSync(directory)) { |
| 103 | return undefined; |
| 104 | } |
| 105 | |
| 106 | const candidates = readdirSync(directory) |
| 107 | .map((fileName) => { |
| 108 | const match = BENCHMARK_FILE_PATTERN.exec(fileName); |
| 109 | if (!match) { |
| 110 | return undefined; |
| 111 | } |
| 112 | |
| 113 | const candidateVersion = parseReleaseVersion(match[1]!); |
| 114 | if (candidateVersion.prerelease) { |
| 115 | return undefined; |
| 116 | } |
| 117 | |
| 118 | if (compareReleaseVersions(candidateVersion.raw, current.raw) >= 0) { |
| 119 | return undefined; |
| 120 | } |
| 121 | |
| 122 | return { |
| 123 | version: candidateVersion.raw, |
| 124 | path: path.join(directory, fileName), |
| 125 | }; |
| 126 | }) |
| 127 | .filter((candidate): candidate is { version: string; path: string } => Boolean(candidate)) |
| 128 | .sort((left, right) => compareReleaseVersions(right.version, left.version)); |
| 129 | |
| 130 | return candidates[0]; |
| 131 | } |
| 132 | |
| 133 | /** Read and lightly validate one benchmark JSON file. */ |
| 134 | export async function loadBenchmarkRun(filePath: string): Promise<BenchmarkRunResult> { |
no test coverage detected