Skip to content

Commit

Permalink
fixes after packagename changes
Browse files Browse the repository at this point in the history
  • Loading branch information
macovedj committed Nov 20, 2023
1 parent 77ea75b commit 6d24c4e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/commands/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -23,7 +23,7 @@ pub struct BundleCommand {

/// Only show information for the specified package.
#[clap(value_name = "PACKAGE")]
pub package: Option<PackageId>,
pub package: Option<PackageName>,
}

impl BundleCommand {
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 18 additions & 14 deletions src/commands/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -22,7 +20,7 @@ pub struct DependenciesCommand {

/// Only show information for the specified package.
#[clap(value_name = "PACKAGE")]
pub package: Option<PackageId>,
pub package: Option<PackageName>,
}

impl DependenciesCommand {
Expand All @@ -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)
}?;
Expand All @@ -66,15 +65,15 @@ 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('@');
let versionless_name = name_and_version.next();
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();
Expand All @@ -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 {
Expand All @@ -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?;
}
Expand Down
27 changes: 25 additions & 2 deletions src/commands/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
Expand Down Expand Up @@ -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(())
Expand All @@ -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::<String, InstanceId>::new();
for package in builder.lock_list {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6d24c4e

Please sign in to comment.