| 373 | } |
| 374 | |
| 375 | function readPackageMetadata(rootDir) { |
| 376 | const packagePath = path.join(rootDir, 'package.json'); |
| 377 | if (!fs.existsSync(packagePath)) { |
| 378 | return { packageScripts: {}, verificationCommands: [] }; |
| 379 | } |
| 380 | |
| 381 | let parsed; |
| 382 | try { |
| 383 | parsed = JSON.parse(fs.readFileSync(packagePath, 'utf8')); |
| 384 | } catch (_) { |
| 385 | return { packageScripts: {}, verificationCommands: [] }; |
| 386 | } |
| 387 | |
| 388 | const scripts = parsed.scripts || {}; |
| 389 | const packageScripts = {}; |
| 390 | const verificationCommands = []; |
| 391 | |
| 392 | for (const [name, command] of Object.entries(scripts)) { |
| 393 | packageScripts[name] = command; |
| 394 | if (VERIFICATION_SCRIPT_PATTERN.test(name) || VERIFICATION_SCRIPT_PATTERN.test(command)) { |
| 395 | verificationCommands.push(`npm run ${name}`); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | return { packageScripts, verificationCommands }; |
| 400 | } |
| 401 | |
| 402 | function generateMapIndex(rootDir) { |
| 403 | const resolvedRoot = path.resolve(rootDir || process.cwd()); |