fix: lazy-install JS parser npm deps on first use#37
Draft
joshbouncesecurity wants to merge 3 commits intoknostic:masterfrom
Draft
fix: lazy-install JS parser npm deps on first use#37joshbouncesecurity wants to merge 3 commits intoknostic:masterfrom
joshbouncesecurity wants to merge 3 commits intoknostic:masterfrom
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:
|
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).