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

Code before:
              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" => {
          if workspace_npm_package_names.contains(
            specifier.as_str()[4..]
              .trim_start_matches('/')
              .trim_end_matches('/'),
          ) {
            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 {

Review comment (suggestion):
I think this won't work if someone specifies a subpath? Probably we should parse to `NpmPackageReqReference` here then check the set for the `.req()`

Code after:
      match specifier.scheme() {
        "jsr" => {
          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())
        }
        _ => {