Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): store tags associated with package in node_modules dir #26000

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

nathanwhit
Copy link
Member

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 in node_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-run deno install when you switch from auto -> manual, though maybe that's not a big deal.

@bartlomieju
Copy link
Member

The fix proposed here is to repurpose the .initialized file that we store in node_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.

Will this not cause problem when switching to older Deno version? Ie. is this backwards compatible?

@nathanwhit
Copy link
Member Author

The fix proposed here is to repurpose the .initialized file that we store in node_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.

Will this not cause problem when switching to older Deno version? Ie. is this backwards compatible?

Yeah it's backwards compatible, currently .intialized is just an empty file, so the contents don't matter to older versions.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nathanwhit nathanwhit merged commit 2754184 into main Oct 3, 2024
17 checks passed
@nathanwhit nathanwhit deleted the byonm-with-tag-in-deno-json branch October 3, 2024 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when running shadcn@latest init on OSX (M1): "cannot use matches with a tag: latest" latest version not allowed in deno.json and [email protected] is missing __dirname
2 participants