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