* Validate a list of plugin component relative paths by checking existence in parallel. * * This helper parallelizes the pathExists checks (the expensive async part) while * preserving deterministic error/log ordering by iterating results sequentially. * * Introduced to fix a perf regression fr
( relPaths: string[], pluginPath: string, pluginName: string, source: string, component: PluginComponent, componentLabel: string, contextLabel: string, errors: PluginError[], )
| 1263 | * @returns Array of full paths that exist on disk, in original order |
| 1264 | */ |
| 1265 | async function validatePluginPaths( |
| 1266 | relPaths: string[], |
| 1267 | pluginPath: string, |
| 1268 | pluginName: string, |
| 1269 | source: string, |
| 1270 | component: PluginComponent, |
| 1271 | componentLabel: string, |
| 1272 | contextLabel: string, |
| 1273 | errors: PluginError[], |
| 1274 | ): Promise<string[]> { |
| 1275 | // Parallelize the async pathExists checks |
| 1276 | const checks = await Promise.all( |
| 1277 | relPaths.map(async relPath => { |
| 1278 | const fullPath = join(pluginPath, relPath) |
| 1279 | return { relPath, fullPath, exists: await pathExists(fullPath) } |
| 1280 | }), |
| 1281 | ) |
| 1282 | // Process results in original order to keep error/log ordering deterministic |
| 1283 | const validPaths: string[] = [] |
| 1284 | for (const { relPath, fullPath, exists } of checks) { |
| 1285 | if (exists) { |
| 1286 | validPaths.push(fullPath) |
| 1287 | } else { |
| 1288 | logForDebugging( |
| 1289 | `${componentLabel} path ${relPath} ${contextLabel} not found at ${fullPath} for ${pluginName}`, |
| 1290 | { level: 'warn' }, |
| 1291 | ) |
| 1292 | logError( |
| 1293 | new Error( |
| 1294 | `Plugin component file not found: ${fullPath} for ${pluginName}`, |
| 1295 | ), |
| 1296 | ) |
| 1297 | errors.push({ |
| 1298 | type: 'path-not-found', |
| 1299 | source, |
| 1300 | plugin: pluginName, |
| 1301 | path: fullPath, |
| 1302 | component, |
| 1303 | }) |
| 1304 | } |
| 1305 | } |
| 1306 | return validPaths |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * Creates a LoadedPlugin object from a plugin directory path. |
no test coverage detected