fix: npm lockfile causing cache instability #2424
Merged
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.
Bug
In order to find the correct lockfile entry for
foo: ^1.0.0
inpackage-lock.json
without performing a full scan one must know where the dependency is coming from. This is different from other lockfiles where the descriptor is enough to find the correct entry. In order to avoid performing a full scan the lockfile implementation (#1830) resolved the return values ofAllDependencies
to their lockfile keys instead of package names. This caused the first value of the resolved dependencies to be just the package name and version and all of the following ones to be the lockfile entry key and version. The selection of first value was dependent on map iteration causing the instability.Fix
The most straightforward fix is to always use the lockfile key and version when adding to the list of resolved files.
Considerations
This change now means when we have lockfile information, package manager implementation details will bleed out into populating
ExternalDeps
. At the moment this field is only used for calculating a hash, but if we eventually want to surface this data we'd probably want to normalize it back to a simple package name and version.Fixes #2307