Skip to content

Commit 10a9b83

Browse files
petercoxphotoMartin Vogel
authored andcommitted
fix(pipeline): resolve build-tool path aliases for cross-file imports (#243)
CALLS edges for cross-file function calls were mis-wired or missing in TypeScript projects that use path aliases (e.g. @/lib/auth → src/lib/auth): 1. resolve_relative_import only handled "./relative" paths, so "@/lib/auth"-style imports never reached IMPORTS edges. The import map stayed empty, Strategy 1 in cbm_registry_resolve failed, and resolution fell through to name-based lookups that pick the wrong target when functions share names across files. 2. resolve_import_map built the candidate QN as the bare module QN when the callee had no dot ("requireAdmin" vs "pkg.Func"), instead of module_qn.requireAdmin. Even with a populated import map, bare calls still mis-resolved. Fix: - New src/pipeline/path_alias.{h,c}: language-agnostic build-tool path-alias subsystem. Currently parses tsconfig.json and jsconfig.json compilerOptions.paths + baseUrl via the existing yyjson dependency (with ALLOW_COMMENTS|ALLOW_TRAILING_COMMAS for JSONC). The data model (cbm_path_alias_t / map / scope / collection) is generic; adding Vite/Webpack/Python loaders means writing a new file-parsing helper and registering it in find_alias_files — the resolver, collection, and pipeline integration do not change. - O(n log n) ordering: scope-by-dir-specificity and entry-by- prefix-specificity are sorted with qsort, replacing the O(n²) bubble sorts that the original draft used. With caps of 256 entries per config and 256 configs per repo, the sort is effectively flat. - Resource ceilings with logging: directory recursion capped at 32 levels; total config files capped at 256; per-config size capped at 64 KB. Cap hits emit cbm_log_warn so silent truncation on pathological monorepos shows up in the index log. - Walk hygiene: skips node_modules, .git, dist, build, .next, coverage, target. - Single integration point: cbm_pipeline_resolve_module gets a Strategy 1b between relative-import resolution and pkgmap so both the sequential and parallel pipelines pick up alias resolution automatically. Non-TS projects pay nothing — the loader returns NULL when no usable configs are found. - Layer 2 fix in registry.c: resolve_import_map now builds the candidate as resolved.prefix when suffix is NULL (one-line fix, matching comment). - Tests: 10 path_alias tests (basic wildcard, specificity, exact, extension stripping, baseUrl, NULL safety, nearest-ancestor scope selection, end-to-end loader against a tmp monorepo, no-configs case) plus a registry test for the bare-call fix. Full suite: 2835 passed, 0 failed. Cherry-picked and generalized from #243 (originally TypeScript-only under tsconfig-named types). Renamed types (cbm_path_alias_scope_t / collection_t in place of cbm_tsconfig_*) and centralised the load into cbm_load_path_aliases so future loaders for other build tools slot in without touching extraction or pipeline code. Closes #243. Co-authored-by: Peter Cox <[email protected]>
1 parent 1468c63 commit 10a9b83

11 files changed

Lines changed: 931 additions & 3 deletions

‎Makefile.cbm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ GRAPH_BUFFER_SRCS = src/graph_buffer/graph_buffer.c
171171
# Pipeline module (new)
172172
PIPELINE_SRCS = \
173173
src/pipeline/fqn.c \
174+
src/pipeline/path_alias.c \
174175
src/pipeline/registry.c \
175176
src/pipeline/pipeline.c \
176177
src/pipeline/pipeline_incremental.c \
@@ -295,7 +296,7 @@ TEST_DISCOVER_SRCS = \
295296

296297
TEST_GRAPH_BUFFER_SRCS = tests/test_graph_buffer.c
297298

298-
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_fqn.c tests/test_configlink.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c
299+
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_fqn.c tests/test_path_alias.c tests/test_configlink.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c
299300

300301
TEST_WATCHER_SRCS = tests/test_watcher.c
301302

‎src/pipeline/pass_pkgmap.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,21 @@ char *cbm_pipeline_resolve_module(const cbm_pipeline_ctx_t *ctx, const char *sou
912912
return qn;
913913
}
914914

915+
/* 1b. Try build-tool path aliases (tsconfig/jsconfig paths today;
916+
* other loaders can register here later). Independent of pkgmap. */
917+
if (ctx->path_aliases && source_rel) {
918+
const cbm_path_alias_map_t *amap =
919+
cbm_path_alias_find_for_file(ctx->path_aliases, source_rel);
920+
if (amap) {
921+
char *aliased = cbm_path_alias_resolve(amap, module_path);
922+
if (aliased) {
923+
char *qn = cbm_pipeline_fqn_module(ctx->project_name, aliased);
924+
free(aliased);
925+
return qn;
926+
}
927+
}
928+
}
929+
915930
/* 2. No pkgmap → fall through immediately */
916931
CBMHashTable *pkgmap = cbm_pipeline_get_pkgmap();
917932
if (!pkgmap) {

0 commit comments

Comments
 (0)