fix(install): store tags associated with package in node_modules dir #26000
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.
Fixes #25998. Fixes #25928.
Originally I was just going to make this an error message instead of a panic, but once I got to a minimal repro I felt that this really should work.
The panic occurs when you have
nodeModulesDir: manual
(or a package.json present), and you have an npm package with a tag in your deno.json (see the spec test that illustrates this).This code path only actually executes when trying to choose an appropriate package version from
node_modules/.deno
, so we should be able to fix it by storing some extra data at install time.The fix proposed here is to repurpose the
.initialized
file that we store innode_modules
to store the tags associated with a package. Basically, if you have a version requirement with a tag (e.g.npm:chalk@latest
), when we set up the node_modules folder for that package, we store the tag (latest
) in.initialized
. Then, when doing BYONM resolution, if we have a version requirement with a tag, we read that file and check if the tag is present.The downside is that we do more work when setting up
node_modules
. We could do this only when BYONM is enabled, but that would have the downside of needing to re-rundeno install
when you switch from auto -> manual, though maybe that's not a big deal.