accuracy(JavaScript): measure import graph accuracy and close gaps below 90%
Part of #237.
Starting estimate: 80-90% recall. This is an unmeasured guess.
Measure
Run codemap on real JavaScript repositories at pinned commits and compare it to ground truth.
- Suggested ground truth: esbuild metafile or madge.
- Report: recall, precision, and whether the coverage status was honest for each file.
Likely gaps to check
CommonJS require forms, package exports maps, dynamic import, bundler aliases.
Done when
- Repositories, commits, method and numbers are recorded here.
- Each miss has a root cause.
- Recall is at or above 90%, or the remaining gap is one codemap cannot close and its coverage status says so.
JavaScript import graph accuracy (issue #239)
Method: ground truth = TypeScript 5 compiler API (ts.preProcessFile + ts.resolveModuleName, Bundler resolution, allowJs, root tsconfig paths) run from a scratch dir outside the clones, static only, no repo code executed. Intra-project edges only (target must be a git-tracked source file in the repo; workspace-package imports via node_modules symlinks are not in truth). codemap 4.6.3, codemap --json --importers <file> per file (its resolved imports). Auto-written .codemap/config.json was replaced with only=[ts,tsx,js,jsx,mjs,cjs,mts,cts] and no excludes so the filter hid nothing (the auto config for express excluded fixtures, and for ky/others listed only a subset of extensions). Importers calls cost 3s each on large repos, so repos over 200 files use a SAMPLE of 60 source files (python random.Random(238) shuffle of the sorted file list); recall/precision are over edges whose importer is in the sample. Honesty = coverage_status of sampled files that had a missed edge.
| repo (shape) | SHA | src files | files measured | recall | precision | files with a miss / reporting complete |
|---|---|---|---|---|---|---|
| expressjs/express (small lib) | 1c6f1b0 | 142 | 60 (sample) | 40/64 = 62.5% | 40/64 = 62.5% | 24 / 24 complete |
| eslint/eslint (big project, packages/) | 11c66ba | 1546 | 60 (sample) | 49/50 = 98.0% | 49/50 = 98.0% | 1 / 0 complete (partial) |
| NodeBB/NodeBB (app, CJS) | f47b640 | 953 | 60 (sample) | 210/210 = 100% | 210/210 | 0 |
| pooled | 299/324 = 92.3% | 299/324 = 92.3% |
Express sample is dominated by examples/ and test/ files whose only intra-repo import is require('../../') or require('../'), so its rate is pessimistic for the library itself but representative of how its tests/examples reference it.
Root causes, ranked by edges lost
- Directory import of the repo root yields a bogus edge (24 missed + 24 false edges, express).
var express = require('../../');(examples/cookies/index.js) andrequire('../')(test/app.route.js) should resolve to index.js. codemap emits the phantom edge/index.js(leading slash, no such file) instead ofindex.js. Location: resolver extension list scanner/types.go:359 ("/index.js" appended to an empty base gives "/index.js"); the exact join site was not traced (inferred). Fix size: small. Both recall and precision suffer, and coverage_status stayscomplete: worst-case honesty. - Directory import resolved via package.json (1 edge, eslint, probably more repo-wide).
require("../packages/js")(eslint tools/generate-formatter-examples.js) should reach packages/js/types/index.d.ts per TypeScript resolution (package.json types/main); codemap leaves it unresolved. eslint's note lists the similar./packages/jsand../../packages/jsimports as unresolved, so it is flagged partial. Fix size: medium (read package.json main/exports/types for directory targets). - One false edge (eslint): tests/pnpm/test-eslint.config.js -> lib/config-api.js (not in TS truth; not diagnosed).
- Template-string / variable requires (e.g.
messages/${templateName}.js) are reported as unresolved in notes, not as fabricated edges; not closable statically.
Honesty
- express: 24/24 miss files reported
complete(and 24 phantom edges). Worst case. - eslint: all 60 sampled files
partial; the single miss was flagged. NodeBB: allpartialwith 0 misses (conservative). Limits: 60-file samples, small edge counts (express 64, eslint 50); truth uses TS resolution, which can differ from Node CJS in edge cases.
Measured with codemap 4.6.3. Sampled numbers are samples, not a census.
Released in v4.6.4. Recall / precision against the truth set: express 1.000 / 1.000, NodeBB .998 / 1.000, eslint .981 / .986. The eslint dip is from two real edges (require("..") and require("../..") to lib/api.js) that the truth script does not count.
Measured in #264 (v4.6.4, Node 22's resolver as truth):
- held-out: three.js recall 1.000 / precision 1.000, ECC 0.987 / 1.000, axios 0.976 / 1.000
- tuned: express 1.000 / 1.000, eslint 0.950 / 1.000, NodeBB 1.000 / 0.993
Every held-out miss is .cjs (#267) or .mjs excluded by the auto config (#268). eslint's misses include package.json main directory imports (#271). axios was independently rebuilt and matched exactly.