fix: lazy-install JS parser npm deps on first use#37
Merged
ar7casper merged 5 commits intoMay 12, 2026
Merged
Conversation
openant parse fails with "Cannot find module 'ts-morph'" when the JS parser's node_modules directory hasn't been populated — there's no bootstrap step that runs npm install the way the Go CLI's runtime.go does for the Python venv. _parse_javascript now checks for parsers/javascript/node_modules/ before invoking Node, and shells out to npm install once if it's missing. Matches the venv's "first run installs, later runs are fast" UX, but scoped to actual JS parser use so Python/Go-only users don't need npm. Fails with a clear error if npm is not on PATH or install fails. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use node_modules/.package-lock.json as the install completion sentinel so a killed prior install (Ctrl+C, OOM) is correctly retried. - Serialize concurrent bootstraps with a cross-platform file lock so two parallel parses don't both run npm install in the same directory. - Raise a clearer error when package.json is missing instead of letting npm silently produce an empty install. - Include the reproduction command in npm-install failure messages. - Add tests for partial-install retry, package.json missing, repro-command in error, and lock-serialized re-entry.
- msvcrt.locking() locks at the *current* file position, so opening with "a+" (which seeks to EOF) made each caller lock a different byte and the lock was effectively non-exclusive. Open with "w" and seek to 0 before locking so all callers contend on the same byte. - Add libs/openant-core/parsers/javascript/.openant-npm-install.lock to .gitignore so the lockfile isn't accidentally committed.
Contributor
Author
Manual verification
|
Contributor
Author
Local test resultsTested the lazy bootstrap on Windows by importing Commands run: First-call output: Second-call output (run immediately after): Outcome:
|
Closed
21 tasks
ar7casper
approved these changes
May 12, 2026
This was referenced May 12, 2026
Fixes test_no_bare_open_in_non_test_code lint check which requires all open() calls in non-test code to specify an explicit encoding. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fd4ee23 to
3b8b5a2
Compare
ar7casper
added a commit
that referenced
this pull request
May 13, 2026
Covers the seven PRs in this release: - #35: parse --level default → reachable (CLI consistency with scan + Python CLI) - #36: auto-detect dep changes via ~/.openant/venv/.deps-hash - #37: lazy JS parser npm bootstrap on first use - #39: TypeScript/NestJS DI-aware call resolution (constructor + field + functional inject()) - #40: --language auto opt-in for openant init + non-git path support + shared config/languages.json - #49: Express anonymous route handler extraction (route_handler / route_middleware) - #50: --llm-reachability opt-in stage + cross-parser call_graph.json contract Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openant parseon a JS/TS repo fails out of the box withCannot find module 'ts-morph'because nothing in the install flow populatesparsers/javascript/node_modules/.This adds a lazy bootstrap in
_parse_javascriptthat runsnpm installonce ifnode_modules/is missing, mirroring the Go CLI's existing venv bootstrap pattern. Lazy (on first JS parse) rather than eager (at CLI startup) so users who only scan Python/Go repos don't need Node/npm installed.If
npmis missing or the install fails, the helper raises with a clear message pointing at the parser directory.Addresses item 21 from #16 (does not close the issue).
Test plan
npmmissing on PATH: clear error message names the parser directory.tests/test_js_parser_bootstrap.pypasses (5 unit tests covering the four branches plus the integration surface).