| 397 | } |
| 398 | |
| 399 | function findNewestHar(rootDir) { |
| 400 | if (!fs.existsSync(rootDir)) { |
| 401 | return null; |
| 402 | } |
| 403 | |
| 404 | let latestFile = null; |
| 405 | let latestMtime = 0; |
| 406 | const queue = [rootDir]; |
| 407 | |
| 408 | while (queue.length > 0) { |
| 409 | const currentDir = queue.pop(); |
| 410 | const entries = fs.readdirSync(currentDir, { withFileTypes: true }); |
| 411 | |
| 412 | for (const entry of entries) { |
| 413 | const fullPath = path.join(currentDir, entry.name); |
| 414 | if (entry.isDirectory()) { |
| 415 | queue.push(fullPath); |
| 416 | continue; |
| 417 | } |
| 418 | |
| 419 | if (!entry.isFile() || !entry.name.endsWith('.har')) { |
| 420 | continue; |
| 421 | } |
| 422 | |
| 423 | const stat = fs.statSync(fullPath); |
| 424 | if (!latestFile || stat.mtimeMs > latestMtime) { |
| 425 | latestFile = fullPath; |
| 426 | latestMtime = stat.mtimeMs; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | return latestFile; |
| 432 | } |
| 433 | |
| 434 | function ensureFileExists(filePath, message) { |
| 435 | if (!fs.existsSync(filePath)) { |