Commit f77cbf2
feat(pipeline): resolve npm workspaces package imports (#271 Phase 1)
A Yarn/Lerna/npm monorepo references a sibling package by its declared
`name` (e.g. `@org/a`), but package.json `main`/`exports` often points at
a build artifact (dist/index.js) that is not indexed. pkgmap maps the name
to that dead entry QN, so the import resolves to no node and no
cross-package IMPORTS edge (and therefore no downstream CALLS edge) is
produced.
Phase 1 (npm `workspaces` only, per the maintainer's scoping in #271):
- Detect workspace roots and member manifests during the existing pkgmap
manifest walk (cbm_workspace_try_detect) — no extra file IO. Roots
declare `workspaces` as an array or {"packages":[...]}; member globs are
compiled with the reused gitignore engine ('*', '**', '!' negation,
charclasses). Brace {a,b} expansion is out of scope (debug-logged).
- Collect-then-finalize (cbm_workspaces_finalize) so a member can be parsed
before its declaring root; maps each member NAME -> source DIR, first-wins
on name collision.
- Resolver Strategy 1c (resolve_workspace_member) probes conventional source
entry files (src/index, index, src/main, ...) and subpath targets
(`@org/a/utils/helper` -> <dir>/src/utils/helper). Runs only after the
existing pkgmap/sibling strategies miss, so healthy repos (entry points at
a real indexed file) are byte-for-byte unchanged. The import-targetable
label filter preserves the #767 Folder-phantom guard; self-imports are
rejected.
Because the CALLS import-map is built from IMPORTS edges, fixing IMPORTS
here also improves cross-package call resolution without touching the
generic module resolver.
Tests: new tests/test_workspaces.c (11 unit cases — array/object detection,
single-star/doublestar/negation glob matching, first-wins, NULL-safety,
scan_repo end-to-end) plus two previously-RED contract tests in
test_lang_contract.c (unbuilt dist `main`, and subpath import) that now pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Hitoshi Okazaki <okazaki.hitoshi@tecnos.co.jp>1 parent 90f59c5 commit f77cbf2
9 files changed
Lines changed: 733 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
| 358 | + | |
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
820 | | - | |
821 | | - | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
822 | 826 | | |
| 827 | + | |
| 828 | + | |
823 | 829 | | |
824 | 830 | | |
825 | 831 | | |
| |||
0 commit comments