Repository: denoland/deno
File: cli/tools/pm/cache_deps.rs (Rust)

Code before:
            }
            if !seen_reqs.insert(req.req().clone()) {
              continue;
            }
            let resolved_req = graph.packages.mappings().get(req.req());
            let jsr_resolver = jsr_resolver.clone();
            info_futures.push(async move {
              let nv = if let Some(req) = resolved_req {
                Cow::Borrowed(req)
              } else {
                Cow::Owned(jsr_resolver.req_to_nv(req.req()).await?)
              };
              if let Some(info) = jsr_resolver.package_version_info(&nv).await {
                return Some((specifier.clone(), info));
              }
              None
            });
          }
        }
        "npm" => {
          let Ok(req_ref) =
            NpmPackageReqReference::from_str(specifier.as_str())
          else {
            continue;
          };
          if workspace_npm_package_names.contains(&*req_ref.req().name) {
            continue;
          }
          roots.push(specifier.clone())
        }
        _ => {
          if entry.key.ends_with('/') && specifier.as_str().ends_with('/') {
            continue;
          }
          if specifier.scheme() == "file" {
            if let Ok(path) = specifier.to_file_path() {
              if !path.is_file() {
                continue;
              }
            }
          }
          roots.push(specifier.clone());
        }
      }
    }

    while let Some(info_future) = info_futures.next().await {
      if let Some((specifier, info)) = info_future {
        let exports = info.exports();
        for (k, _) in exports {
          if let Ok(spec) = specifier.join(k) {

Review comment (suggestion):
I kind of wonder if we should still install when the req doesn't match the version in the package.json, but this is probably fine.

Code after:
          let specifier_str = specifier.as_str();
          if let Ok(req) = JsrPackageReqReference::from_str(specifier_str) {
            if let Some(sub_path) = req.sub_path() {
              if sub_path.ends_with('/') {
                continue;
              }
              roots.push(specifier.clone());
              continue;
            }
            if !seen_reqs.insert(req.req().clone()) {
              continue;
            }
            let resolved_req = graph.packages.mappings().get(req.req());
            let jsr_resolver = jsr_resolver.clone();
            info_futures.push(async move {
              let nv = if let Some(req) = resolved_req {
                Cow::Borrowed(req)
              } else {
                Cow::Owned(jsr_resolver.req_to_nv(req.req()).await?)
              };
              if let Some(info) = jsr_resolver.package_version_info(&nv).await {
                return Some((specifier.clone(), info));
              }
              None
            });
          }
        }
        "npm" => {
          let Ok(req_ref) =
            NpmPackageReqReference::from_str(specifier.as_str())
          else {
            continue;
          };
          let version = workspace_npm_packages.get(&*req_ref.req().name);
          if let Some(version) = version {
            let Ok(version) = Version::parse_from_npm(version) else {
              continue;
            };
            let version_req = &req_ref.req().version_req;
            if version_req.tag().is_none() && version_req.matches(&version) {
              // if version req matches the workspace package's version, use that
              // (so it doesn't need to be installed)
              continue;
            }
          }

          roots.push(specifier.clone())
        }
        _ => {
          if entry.key.ends_with('/') && specifier.as_str().ends_with('/') {
            continue;