diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-01-31 21:27:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 21:27:40 -0500 |
commit | 600fff79cdf5d52154344a0e3a8a523e1e21c3c1 (patch) | |
tree | 89e10e4a5fe1c6a67e8955c6710ff16aa25ef853 /cli/npm/registry.rs | |
parent | e85ca8be0dafdab28e6283aed64c8ee0eb3a338d (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/registry.rs')
-rw-r--r-- | cli/npm/registry.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 9598feba1..fea6996ab 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -25,13 +25,12 @@ use serde::Serialize; use crate::args::CacheSetting; use crate::cache::CACHE_PERM; use crate::http_util::HttpClient; +use crate::semver::Version; +use crate::semver::VersionReq; use crate::util::fs::atomic_write_file; use crate::util::progress_bar::ProgressBar; use super::cache::NpmCache; -use super::resolution::NpmVersionMatcher; -use super::semver::NpmVersion; -use super::semver::NpmVersionReq; // npm registry docs: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md @@ -61,11 +60,11 @@ pub struct NpmDependencyEntry { pub kind: NpmDependencyEntryKind, pub bare_specifier: String, pub name: String, - pub version_req: NpmVersionReq, + pub version_req: VersionReq, /// When the dependency is also marked as a peer dependency, /// use this entry to resolve the dependency when it can't /// be resolved as a peer dependency. - pub peer_dep_version_req: Option<NpmVersionReq>, + pub peer_dep_version_req: Option<VersionReq>, } impl PartialOrd for NpmDependencyEntry { @@ -82,7 +81,7 @@ impl Ord for NpmDependencyEntry { Ordering::Equal => other .version_req .version_text() - .cmp(&self.version_req.version_text()), + .cmp(self.version_req.version_text()), ordering => ordering, } } @@ -129,7 +128,7 @@ impl NpmPackageVersionInfo { (entry.0.clone(), entry.1.clone()) }; let version_req = - NpmVersionReq::parse(&version_req).with_context(|| { + VersionReq::parse_from_npm(&version_req).with_context(|| { format!( "error parsing version requirement for dependency: {bare_specifier}@{version_req}" ) @@ -217,7 +216,7 @@ pub trait NpmRegistryApi: Clone + Sync + Send + 'static { fn package_version_info( &self, name: &str, - version: &NpmVersion, + version: &Version, ) -> BoxFuture<'static, Result<Option<NpmPackageVersionInfo>, AnyError>> { let api = self.clone(); let name = name.to_string(); |