perf(cli): skip npm install during update when lockfile is unchanged (#17268)#39397
Open
rodboev wants to merge 1 commit into
Open
perf(cli): skip npm install during update when lockfile is unchanged (#17268)#39397rodboev wants to merge 1 commit into
rodboev wants to merge 1 commit into
Conversation
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
Every
hermes updateunconditionally runsnpm citwice (root-only, then workspace), even when the lockfile hasn't changed since the last successful install. On slow or firewalled networks this adds 30-60+ seconds of dead time for Python-only or docs-only commits.The fix hashes
package-lock.jsonwith SHA-256 after each successful install and stores the digest in a per-checkout cache file under the hermes root (~/.hermes/.npm_lock_hash_<project_key>). On subsequent updates,_update_node_dependencies()compares the current lockfile hash against the stored digest and skips bothnpm cicalls when they match. The codebase already uses this pattern for the desktop build (_compute_desktop_content_hash/_desktop_build_needed) and the TUI install path (_tui_need_npm_installcompares lockfile content).The cache is keyed by
PROJECT_ROOTso parallel worktrees don't collide, and validates thatnode_modules/exists before skipping (a matching hash with missing node_modules forces a reinstall). All cache I/O is wrapped in try/except so a corrupt or inaccessible cache file never breaks the update path.Changes
hermes_cli/main.py: add_npm_lockfile_changed()and_record_npm_lockfile_hash()helpers usinghashlib.sha256; guard_update_node_dependencies()with an early return when the lockfile matches the stored hash; record hash after successful install (~+35 lines)tests/hermes_cli/test_cmd_update.py: add 7 tests for the hash helpers, skip path, missing node_modules, and cache error handling (~+65 lines)Validation
package-lock.jsonmissingnode_modules/deleted after cache writtenTest plan
pytest tests/hermes_cli/test_cmd_update.py -v --timeout=0— 32 passedhermes updatetwice in a row, verify second run skips npm ciFixes #17268