| 382 | enum { TS_CONFIG_NAMES_COUNT = 2 }; |
| 383 | |
| 384 | static void find_alias_files(const char *abs_dir, const char *rel_dir, alias_config_hit_t *out, |
| 385 | int *count, int max_count, int depth, char **excluded_dirs, |
| 386 | int excluded_count) { |
| 387 | if (*count >= max_count || depth > CBM_PATH_ALIAS_MAX_DEPTH) { |
| 388 | return; |
| 389 | } |
| 390 | cbm_dir_t *d = cbm_opendir(abs_dir); |
| 391 | if (!d) { |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | /* One config file per directory: prefer tsconfig.json over jsconfig.json. */ |
| 396 | for (int i = 0; i < TS_CONFIG_NAMES_COUNT && *count < max_count; i++) { |
| 397 | char check[CBM_SZ_512]; |
| 398 | snprintf(check, sizeof(check), "%s/%s", abs_dir, TS_CONFIG_NAMES[i]); |
| 399 | FILE *f = cbm_fopen(check, "r"); |
| 400 | if (f) { |
| 401 | fclose(f); |
| 402 | snprintf(out[*count].abs, sizeof(out[*count].abs), "%s", check); |
| 403 | snprintf(out[*count].rel, sizeof(out[*count].rel), "%s", rel_dir); |
| 404 | (*count)++; |
| 405 | break; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | cbm_dirent_t *ent; |
| 410 | while ((ent = cbm_readdir(d)) != NULL && *count < max_count) { |
| 411 | if (!ent->is_dir) { |
| 412 | continue; |
| 413 | } |
| 414 | const char *name = ent->name; |
| 415 | if (name[0] == '.' || strcmp(name, "node_modules") == 0 || strcmp(name, "dist") == 0 || |
| 416 | strcmp(name, "build") == 0 || strcmp(name, ".next") == 0 || |
| 417 | strcmp(name, "coverage") == 0 || strcmp(name, "target") == 0 /* Rust */) { |
| 418 | continue; |
| 419 | } |
| 420 | char child_abs[CBM_SZ_512]; |
| 421 | char child_rel[CBM_SZ_256]; |
| 422 | snprintf(child_abs, sizeof(child_abs), "%s/%s", abs_dir, name); |
| 423 | if (rel_dir[0] == '\0') { |
| 424 | snprintf(child_rel, sizeof(child_rel), "%s", name); |
| 425 | } else { |
| 426 | snprintf(child_rel, sizeof(child_rel), "%s/%s", rel_dir, name); |
| 427 | } |
| 428 | if (cbm_pipeline_relpath_is_excluded(child_rel, excluded_dirs, excluded_count)) { |
| 429 | continue; |
| 430 | } |
| 431 | find_alias_files(child_abs, child_rel, out, count, max_count, depth + 1, excluded_dirs, |
| 432 | excluded_count); |
| 433 | } |
| 434 | cbm_closedir(d); |
| 435 | } |
| 436 | |
| 437 | cbm_path_alias_collection_t *cbm_load_path_aliases_excluded(const char *repo_path, |
| 438 | char **excluded_dirs, |
no test coverage detected