From 6d24c4e428cd2a421b0979ae002dd3962da7483e Mon Sep 17 00:00:00 2001 From: Daniel Macovei Date: Mon, 20 Nov 2023 14:15:13 -0600 Subject: [PATCH] fixes after packagename changes --- src/commands/bundle.rs | 10 +++++----- src/commands/dependencies.rs | 32 ++++++++++++++++++-------------- src/commands/lock.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/commands/bundle.rs b/src/commands/bundle.rs index dc94bef1..4ac888ab 100644 --- a/src/commands/bundle.rs +++ b/src/commands/bundle.rs @@ -8,7 +8,7 @@ use warg_client::{ }, Client, }; -use warg_protocol::{package::ReleaseState, registry::PackageId}; +use warg_protocol::{package::ReleaseState, registry::PackageName}; use wasm_encoder::{ Component, ComponentImportSection, ComponentSectionId, ComponentTypeRef, RawSection, }; @@ -23,7 +23,7 @@ pub struct BundleCommand { /// Only show information for the specified package. #[clap(value_name = "PACKAGE")] - pub package: Option, + pub package: Option, } impl BundleCommand { @@ -70,14 +70,14 @@ impl<'a> Bundler<'a> { let (_, imp) = import?; let mut full_name = imp.name.0.split('/'); let name = full_name.next(); - if (!imp.name.0.contains('/')) { - if let Some(name) = name { + if !imp.name.0.contains('/') { + if let Some(_) = name { let kindless_name = imp.name.0.splitn(2, '=').last(); if let Some(name) = kindless_name { let mut version_and_name = name.split('@'); let identifier = version_and_name.next(); if let Some(name) = identifier { - let pkg_id = PackageId::new(name.replace('<', ""))?; + let pkg_id = PackageName::new(name.replace('<', ""))?; if let Some(info) = self.client.registry().load_package(&pkg_id).await? { let release_state = &info.state.releases().last().unwrap().state; diff --git a/src/commands/dependencies.rs b/src/commands/dependencies.rs index e7bfc14e..8a79b65c 100644 --- a/src/commands/dependencies.rs +++ b/src/commands/dependencies.rs @@ -8,10 +8,8 @@ use warg_client::{ storage::{ContentStorage, PackageInfo, RegistryStorage}, FileSystemClient, }; -use warg_protocol::{package::ReleaseState, registry::PackageId, VersionReq}; -use wasmparser::{ - Chunk, ComponentImport, ComponentImportName, ComponentImportSectionReader, Parser, Payload, -}; +use warg_protocol::{package::ReleaseState, registry::PackageName, VersionReq}; +use wasmparser::{Chunk, ComponentImport, ComponentImportSectionReader, Parser, Payload}; /// Print Dependency Tree #[derive(Args)] @@ -22,7 +20,7 @@ pub struct DependenciesCommand { /// Only show information for the specified package. #[clap(value_name = "PACKAGE")] - pub package: Option, + pub package: Option, } impl DependenciesCommand { @@ -42,15 +40,16 @@ impl DependenciesCommand { #[async_recursion] async fn parse_deps<'a>( - id: &'a PackageId, + id: &'a PackageName, version: Option<&'a str>, client: &FileSystemClient, node: &mut TreeBuilder, parser: &mut DepsParser, ) -> Result<()> { let vreq = if let Some(v) = version { - let v = v.replace(['{', '}'], "").replace([' '], ", "); - VersionReq::parse(&v) + let v = &v.replace(['{', '}'], "").replace([' '], ", "); + let v = &v[0..v.len() - 1]; + VersionReq::parse(v) } else { Ok(VersionReq::STAR) }?; @@ -66,7 +65,7 @@ impl DependenciesCommand { let bytes = fs::read(p)?; let deps = parser.parse(&bytes)?; for dep in deps { - let name = dep.name.0; + let name = dep.name.0.replace('<', ""); let kindless_name = name.splitn(2, '=').last(); if let Some(name) = kindless_name { let mut name_and_version = name.split('@'); @@ -74,7 +73,7 @@ impl DependenciesCommand { let version = name_and_version.next(); if let Some(identifier) = versionless_name { let grand_child = node.begin_child(name.to_string()); - let id = PackageId::new(identifier)?; + let id = PackageName::new(identifier)?; Self::parse_deps(&id, version, client, grand_child, parser) .await?; grand_child.end_child(); @@ -90,12 +89,17 @@ impl DependenciesCommand { async fn print_package_info(client: &FileSystemClient, info: &PackageInfo) -> Result<()> { let mut parser = DepsParser::new(); - let root_package = client.registry().load_package(&info.id).await?; + let root_package = client.registry().load_package(&info.name).await?; if let Some(rp) = root_package { let latest = rp.state.releases().last(); if let Some(l) = latest { - client.download(&info.id, &VersionReq::STAR).await?; - let mut tree = TreeBuilder::new(format!("{0}@{1}", info.id, l.version)); + client.download(&info.name, &VersionReq::STAR).await?; + let mut tree = TreeBuilder::new(format!( + "{0}:{1}@{2}", + info.name.namespace(), + info.name.name(), + l.version + )); if let ReleaseState::Released { content } = &l.state { let path = client.content().content_location(content); if let Some(p) = path { @@ -110,7 +114,7 @@ impl DependenciesCommand { let versionless_name = name_and_version.next(); let version = name_and_version.next(); if let Some(identifier) = versionless_name { - let id = PackageId::new(identifier)?; + let id = PackageName::new(identifier.replace('<', ""))?; Self::parse_deps(&id, version, client, child, &mut parser) .await?; } diff --git a/src/commands/lock.rs b/src/commands/lock.rs index 7f535082..fa53b65d 100644 --- a/src/commands/lock.rs +++ b/src/commands/lock.rs @@ -105,6 +105,22 @@ impl LockListBuilder { } } self.lock_list.insert(name.replace('<', "").to_string()); + } else { + client.download(&id, &VersionReq::STAR).await?; + if let Some(info) = client.registry().load_package(&id).await? { + let release = info.state.releases().last(); + if let Some(r) = release { + let state = &r.state; + if let ReleaseState::Released { content } = state { + let path = client.content().content_location(content); + if let Some(p) = path { + let bytes = fs::read(p)?; + self.parse_package(client, &bytes).await?; + } + } + } + self.lock_list.insert(name.replace('<', "").to_string()); + } } } } @@ -155,6 +171,11 @@ impl LockCommand { if let Some(package) = self.package { if let Some(info) = client.registry().load_package(&package).await? { Self::lock(client, &info, self.executable).await?; + } else { + client.download(&package, &VersionReq::STAR).await?; + if let Some(info) = client.registry().load_package(&package).await? { + Self::lock(client, &info, self.executable).await?; + } } } Ok(()) @@ -164,7 +185,9 @@ impl LockCommand { let maybe_find = |s: &str, c: char| s.find(c); let mut builder = LockListBuilder::new(); builder.build_list(&client, info).await?; - builder.lock_list.insert(info.name.name().to_string()); + builder + .lock_list + .insert(format!("{}:{}", info.name.namespace(), info.name.name())); let mut composer = CompositionGraph::new(); let mut handled = HashMap::::new(); for package in builder.lock_list { @@ -296,7 +319,7 @@ impl LockCommand { } } } - let final_name = &info.name.name().to_string(); + let final_name = &format!("{}:{}", info.name.namespace(), &info.name.name()); let id = handled.get(final_name); let options = if let Some(id) = id {