summaryrefslogtreecommitdiff
path: root/resolvers/deno/npm/byonm.rs
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-10-02 17:16:46 -0700
committerGitHub <noreply@github.com>2024-10-02 17:16:46 -0700
commit275418473e7bda2b0bd33c86ae54cf3ac8ac5341 (patch)
tree970102cfb05c67819678f4d29a08a0aaf354bed3 /resolvers/deno/npm/byonm.rs
parent1e0c9b8c5b85c6c18ecdef0374a945b361d6e79d (diff)
fix(install): store tags associated with package in node_modules dir (#26000)
Fixes #25998. Fixes https://github.com/denoland/deno/issues/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.
Diffstat (limited to 'resolvers/deno/npm/byonm.rs')
-rw-r--r--resolvers/deno/npm/byonm.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/resolvers/deno/npm/byonm.rs b/resolvers/deno/npm/byonm.rs
index 5bc4e62b2..3394b3e50 100644
--- a/resolvers/deno/npm/byonm.rs
+++ b/resolvers/deno/npm/byonm.rs
@@ -253,7 +253,24 @@ impl<Fs: DenoResolverFs> ByonmNpmResolver<Fs> {
let Ok(version) = Version::parse_from_npm(version) else {
continue;
};
- if req.version_req.matches(&version) {
+ if let Some(tag) = req.version_req.tag() {
+ let initialized_file =
+ node_modules_deno_dir.join(&entry.name).join(".initialized");
+ let Ok(contents) = self.fs.read_to_string_lossy(&initialized_file)
+ else {
+ continue;
+ };
+ let mut tags = contents.split(',').map(str::trim);
+ if tags.any(|t| t == tag) {
+ if let Some((best_version_version, _)) = &best_version {
+ if version > *best_version_version {
+ best_version = Some((version, entry.name));
+ }
+ } else {
+ best_version = Some((version, entry.name));
+ }
+ }
+ } else if req.version_req.matches(&version) {
if let Some((best_version_version, _)) = &best_version {
if version > *best_version_version {
best_version = Some((version, entry.name));