Fix npm8 subdependency updates when version is in-range #13754
+398
−6
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.
What are you trying to accomplish?
npm8's
npm update <dependency>command won't update a subdependency if the current version already satisfies the parent's semver range, even when a newer in-range version exists. For example, updatingfollow-redirectsfrom 1.15.2 to 1.15.6 whenaxiosspecifies^1.15.0fails despite both versions being valid.This blocks security updates for subdependencies when the vulnerability is patched within the existing semver range.
Anything you want to highlight for special attention from reviewers?
Approach: Implemented npm8 subdependency updater following the existing npm6 pattern:
package-lock.jsonpackagesobjectnpm install --package-lock-onlyto regenerate with latest compatible versionKey implementation details:
removeDependenciesFromLockfile()removes package entries but preserves dependency references in parent packages (npm resolves these during regeneration)detect-indentfor formatting consistency with npm6 helperChanges:
npm_and_yarn/helpers/lib/npm8/subdependency-updater.js- Core lockfile manipulation and regeneration logicSubdependencyVersionResolver#run_npm_updater- Calls new helper viaSharedHelpers.run_helper_subprocessNpmLockfileUpdater#run_npm8_subdependency_updater- Calls new helper instead of command-linenpm updateHow will you know you've accomplished your goal?
Unit tests verify lockfile manipulation correctly removes subdependencies while preserving parent references. Integration tests with axios/follow-redirects fixture demonstrate the fix resolves the reported scenario.
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.