fix(bench): use dist/ for npm benchmark installs#624
Conversation
…tripping error The prior fix (#612) resolved .js→.ts in srcImport, but Node 22 throws ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING when importing .ts from node_modules. Since v3.4.0+ publishes compiled JS in dist/, use that directory instead of src/ for npm-installed benchmarks. Also replace the embedding benchmark's manual cli.ts invocation with npx codegraph, which uses the package's bin entry point.
|
Claude finished @carlos-alm's task —— View job PR Review CompleteReviewing PR #624: fix(bench): use dist/ for npm benchmark installs Todo List
Root Cause AnalysisProblem Being Solved: Node.js 22+ throws Why This Approach: The solution correctly addresses the root cause by using the published compiled JavaScript files ( Risk Assessment: ✅ Low risk. This is a surgical fix with proper fallback logic. The changes are minimal and well-targeted. Backlog Compliance
Technical AnalysisChanges Reviewbench-config.ts:158-161: // v3.4.0+ publishes compiled JS in dist/ alongside raw TS in src/.
// Node cannot strip types from node_modules, so prefer dist/ when available.
const distDir = path.join(pkgDir, 'dist');
const srcDir = fs.existsSync(distDir) ? distDir : path.join(pkgDir, 'src');✅ Excellent fallback strategy: Prefers ✅ Clear documentation: Comments explain the Node.js type-stripping limitation and version context. ✅ Minimal surface area: Only changes the directory resolution logic without affecting the broader import resolution mechanism. benchmark.yml:237-239: - name: Build graph
if: steps.existing.outputs.skip != 'true'
run: npx codegraph build .✅ Uses published interface: Changes from hardcoded ✅ Cleaner approach: Eliminates the need for Node.js flags and import loaders in this specific step. Code Quality Assessment✅ Error handling preserved: The updated error message correctly reflects both potential directories. ✅ Consistency: Both changes align with the same principle — use the published package interface rather than bypassing it. ✅ No security concerns: Changes don't introduce any command injection or other security vulnerabilities. Configuration Change Risk Analysis✅ Low-risk workflow change: The benchmark.yml modification simplifies the build step by using the standard package entry point. ✅ No rule relaxation: This fix doesn't silence warnings or lower test standards — it addresses a legitimate Node.js compatibility issue. Critical ConcernsNone identified. This is a well-executed fix that addresses the root cause without introducing technical debt. Final Recommendation
Minor improvement suggestion: Consider adding a test case to verify the fallback behavior, though the existing error handling provides adequate safety. |
Greptile SummaryThis PR fixes benchmark job failures on Node 22 caused by Confidence Score: 5/5Safe to merge — targeted fix with correct fallback logic and no risk to existing functionality. The core logic is sound: dist/ is preferred when present, src/ is the fallback, and srcImport transparently handles both layouts since all call sites use .js extensions. The npx codegraph build . replacement is valid because npm install runs prepare → tsc, creating dist/cli.js before the step executes. The only finding is minor documentation staleness (P2). No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[resolveBenchmarkSource] --> B{npm mode?}
B -- No --> C[Return local repo src/]
B -- Yes --> D[npm install @optave/codegraph@version into tmpDir]
D --> E{dist/ exists in pkgDir?}
E -- Yes v3.4.0+ --> F[srcDir = pkgDir/dist/]
E -- No older pkg --> G[srcDir = pkgDir/src/]
F --> H{srcDir exists?}
G --> H
H -- No --> I[Cleanup & throw error]
H -- Yes --> J[Return srcDir + cleanup fn]
J --> K[srcImport srcDir file.js]
K --> L{file ends with .js?}
L -- Yes --> M{.ts variant exists in srcDir?}
M -- Yes src/ layout --> N[Return file URL to .ts file]
M -- No dist/ layout --> O[Return file URL to .js file]
L -- No --> O
|
Summary
dist/(compiled JS) instead ofsrc/(raw TS) as the import root. Node 22 throwsERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPINGwhen importing.tsfiles fromnode_modules, which caused all 4 benchmark jobs to fail on v3.4.0.node src/cli.ts build .withnpx codegraph build .in the embedding benchmark's "Build graph" step — uses the package's bin entry point instead of a hardcoded source path.The prior fix (#612) resolved
.js→.tsinsrcImport(), but that still fails because Node refuses type stripping insidenode_modules. Usingdist/sidesteps this entirely since it contains pre-compiled.jsfiles. Falls back tosrc/for older packages withoutdist/.Test plan
version: 3.4.0viaworkflow_dispatch— all 4 jobs should pass and create PRsdevmode (local) — should still work viasrc/+ ts-resolve-loader