summaryrefslogtreecommitdiff
path: root/cli/npm/resolution/snapshot.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-01-31 21:27:40 -0500
committerGitHub <noreply@github.com>2023-01-31 21:27:40 -0500
commit600fff79cdf5d52154344a0e3a8a523e1e21c3c1 (patch)
tree89e10e4a5fe1c6a67e8955c6710ff16aa25ef853 /cli/npm/resolution/snapshot.rs
parente85ca8be0dafdab28e6283aed64c8ee0eb3a338d (diff)
refactor(semver): generalize semver related structs (#17605)
- Generalizes the npm version code (ex. `NpmVersion` -> `Version`, `NpmVersionReq` -> `VersionReq`). This is a slow refactor towards extracting out this code for deno specifiers and better usage in deno_graph. - Removes `SpecifierVersionReq`. Consolidates `NpmVersionReq` and `SpecifierVersionReq` to just `VersionReq` - Removes `NpmVersionMatcher`. This now just looks at `VersionReq`. - Paves the way to allow us to create `NpmPackageReference`'s from a package.json's dependencies/dev dependencies (`VersionReq::parse_from_npm`).
Diffstat (limited to 'cli/npm/resolution/snapshot.rs')
-rw-r--r--cli/npm/resolution/snapshot.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs
index be64ea611..934320a1d 100644
--- a/cli/npm/resolution/snapshot.rs
+++ b/cli/npm/resolution/snapshot.rs
@@ -19,11 +19,11 @@ use crate::npm::cache::NpmPackageCacheFolderId;
use crate::npm::registry::NpmPackageVersionDistInfo;
use crate::npm::registry::NpmRegistryApi;
use crate::npm::registry::RealNpmRegistryApi;
+use crate::semver::VersionReq;
use super::NpmPackageId;
use super::NpmPackageReq;
use super::NpmResolutionPackage;
-use super::NpmVersionMatcher;
/// Packages partitioned by if they are "copy" packages or not.
pub struct NpmPackagesPartitioned {
@@ -159,12 +159,8 @@ impl NpmResolutionSnapshot {
// TODO(bartlomieju): this should use a reverse lookup table in the
// snapshot instead of resolving best version again.
- let req = NpmPackageReq {
- name: name.to_string(),
- version_req: None,
- };
-
- if let Some(id) = self.resolve_best_package_id(name, &req) {
+ let any_version_req = VersionReq::parse_from_npm("*").unwrap();
+ if let Some(id) = self.resolve_best_package_id(name, &any_version_req) {
if let Some(pkg) = self.packages.get(&id) {
return Ok(pkg);
}
@@ -201,14 +197,14 @@ impl NpmResolutionSnapshot {
pub fn resolve_best_package_id(
&self,
name: &str,
- version_matcher: &impl NpmVersionMatcher,
+ version_req: &VersionReq,
) -> Option<NpmPackageId> {
// todo(dsherret): this is not exactly correct because some ids
// will be better than others due to peer dependencies
let mut maybe_best_id: Option<&NpmPackageId> = None;
if let Some(ids) = self.packages_by_name.get(name) {
for id in ids {
- if version_matcher.matches(&id.version) {
+ if version_req.matches(&id.version) {
let is_best_version = maybe_best_id
.as_ref()
.map(|best_id| best_id.version.cmp(&id.version).is_lt())