Skip to content

Commit dca7d50

Browse files
committed
added multi pkg match arm
1 parent 06da6f4 commit dca7d50

7 files changed

Lines changed: 43 additions & 23 deletions

File tree

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,16 @@ url = "2.5.0"
5555
warg-client = "0.9.2"
5656
warg-crypto = "0.9.2"
5757
warg-protocol = "0.9.2"
58+
59+
# https://github.com/crate-ci/typos/blob/master/docs/reference.md
60+
[workspace.metadata.typos.default]
61+
extend-ignore-re = [
62+
"\\d\\w{4,}\\d",
63+
]
64+
extend-ignore-words-re = [
65+
'^[a-zA-Z]{1,3}$' # ignore words up to length 3
66+
]
67+
68+
[workspace.metadata.typos.default.extend-words]
69+
# strategy shorthand
70+
strat = "strat"

crates/wasm-pkg-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub use publisher::PackagePublisher;
4545
use tokio::io::AsyncSeekExt;
4646
use tokio::sync::RwLock;
4747
use tokio_util::io::SyncIoBridge;
48-
use wasm_pkg_common::config::RegistryConfig;
4948
use wasm_pkg_common::metadata::{LOCAL_PROTOCOL, OCI_PROTOCOL, WARG_PROTOCOL};
5049
pub use wasm_pkg_common::{
5150
config::{Config, CustomConfig, RegistryMapping},

crates/wasm-pkg-client/src/overlay/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, io::Cursor};
1+
use std::collections::HashMap;
22

33
use async_trait::async_trait;
44
use tempfile::TempDir;

crates/wasm-pkg-client/src/publisher.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
use std::collections::{BTreeSet, HashMap};
21

3-
use petgraph::{
4-
acyclic::Acyclic,
5-
graph::{DiGraph, NodeIndex},
6-
};
7-
use wasm_pkg_common::registry::{DependencyGraph, DependencyOf};
82

93
use crate::{PackageRef, PublishingSource, Version};
104

crates/wasm-pkg-common/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TryFrom<String> for Registry {
5757
}
5858
}
5959

60-
/// Represents a directed edge in a package dependnecy graph.
60+
/// Represents a directed edge in a package dependency graph.
6161
#[derive(Clone, Debug)]
6262
pub struct DependencyOf;
6363

crates/wasm-pkg-core/src/resolver.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use anyhow::{bail, Context, Result};
1313
use futures_util::TryStreamExt;
1414
use indexmap::{IndexMap, IndexSet};
1515
use petgraph::{
16-
acyclic::{Acyclic, AcyclicEdgeError},
16+
acyclic::Acyclic,
1717
graph::{DiGraph, NodeIndex},
18-
Graph,
1918
};
2019
use semver::{Comparator, Op, Version, VersionReq};
2120
use tokio::io::{AsyncRead, AsyncReadExt};
@@ -882,7 +881,7 @@ pub struct PublishPlan {
882881

883882
impl PublishPlan {
884883
/// Generate [`Self`] from a list of WIT package paths (files or directories).
885-
fn from_paths(paths: &[impl AsRef<Path>]) -> Result<Self> {
884+
pub fn from_paths(paths: &[impl AsRef<Path>]) -> Result<Self> {
886885
let (graph, indices) = get_local_dependencies(paths)?;
887886
let mut dependents = graph.into_inner();
888887
dependents.reverse();
@@ -895,22 +894,22 @@ impl PublishPlan {
895894
})
896895
}
897896

898-
fn iter<'a>(&'a self) -> impl Iterator<Item = &'a PackageRef> + 'a {
897+
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a PackageRef> + 'a {
899898
self.indices.iter().map(|(pkg, _)| pkg)
900899
}
901900

902-
fn is_empty(&self) -> bool {
901+
pub fn is_empty(&self) -> bool {
903902
self.indices.is_empty()
904903
}
905904

906-
fn len(&self) -> usize {
905+
pub fn len(&self) -> usize {
907906
self.indices.len()
908907
}
909908

910909
/// Returns the set of packages that are ready for publishing (i.e. have no outstanding dependencies).
911910
///
912911
/// These will not be returned in future calls.
913-
fn take_ready(&mut self) -> BTreeSet<PackageRef> {
912+
pub fn take_ready(&mut self) -> BTreeSet<PackageRef> {
914913
self.dependents
915914
.nodes_iter()
916915
// there are no dependents on `self.dendents[id]`
@@ -925,7 +924,7 @@ impl PublishPlan {
925924

926925
/// Packages confirmed to be available in the registry, potentially allowing additional
927926
/// packages to be "ready".
928-
fn mark_confirmed(&mut self, published: impl IntoIterator<Item = PackageRef>) {
927+
pub fn mark_confirmed(&mut self, published: impl IntoIterator<Item = PackageRef>) {
929928
for pkg in published {
930929
let id = self
931930
.indices
@@ -943,7 +942,7 @@ impl PublishPlan {
943942
/// e.g. "foo:a@0.1.0, bar:b@0.2.0, and baz:c@0.3.0".
944943
///
945944
/// Note: the final separator (e.g. "and" in the previous example) can be chosen.
946-
fn package_list(pkgs: impl IntoIterator<Item = PackageRef>, final_sep: &str) -> String {
945+
pub fn package_list(pkgs: impl IntoIterator<Item = PackageRef>, final_sep: &str) -> String {
947946
let mut names: Vec<_> = pkgs.into_iter().map(|pkg| pkg.to_string()).collect();
948947
names.sort();
949948

crates/wkg/src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use wasm_pkg_common::{
1515
package::PackageSpec,
1616
registry::Registry,
1717
};
18-
use wasm_pkg_core::lock::LockFile;
18+
use wasm_pkg_core::{lock::LockFile, resolver::PublishPlan};
1919
use wit_component::DecodedWasm;
2020

2121
mod oci;
@@ -255,6 +255,9 @@ impl PublishArgs {
255255
let client = self.common.get_client().await?;
256256

257257
let package = match self.package {
258+
Some(_) if self.paths.len() > 2 => {
259+
anyhow::bail!("`--package` is currently unsupported when providing more than one path argument");
260+
}
258261
Some(PackageSpec {
259262
package,
260263
version: Some(v),
@@ -265,14 +268,26 @@ impl PublishArgs {
265268
None => None,
266269
};
267270

271+
let path = match &self.paths[..] {
272+
[path] => path,
273+
paths => {
274+
let plan = PublishPlan::from_paths(paths)?;
275+
276+
for pkg in plan.iter() {
277+
println!("{pkg}");
278+
}
279+
todo!();
280+
}
281+
};
282+
268283
// If the input is a directory, build a WIT package from it into a temp
269284
// file first. _tmp is held until the publish completes so the file
270285
// isn't deleted out from under us.
271-
let (publish_path, _tmp) = if self.path.is_dir() {
286+
let (publish_path, _tmp) = if path.is_dir() {
272287
let mut lock_file = LockFile::load(true).await?;
273288
let prev_lock_ref = (lock_file.version, lock_file.packages.clone());
274289
let (pkg_ref, _, bytes) =
275-
wit::build_wit_dir(&self.path, client.clone(), &mut lock_file).await?;
290+
wit::build_wit_dir(&path.clone(), client.clone(), &mut lock_file).await?;
276291
// There is no way to check if we are in a git repository unlike `cargo publish --allow-dirty` so
277292
// check against previous values.
278293
if lock_file != prev_lock_ref && !self.dry_run {
@@ -282,7 +297,7 @@ impl PublishArgs {
282297
.with_context(|| {
283298
format!(
284299
"Run `wkg wit build {}` before attempting to publish",
285-
self.path.to_string_lossy()
300+
path.to_string_lossy()
286301
)
287302
});
288303
}
@@ -291,7 +306,7 @@ impl PublishArgs {
291306

292307
(tmp.path().to_path_buf(), Some(tmp))
293308
} else {
294-
(self.path.clone(), None)
309+
(path.clone(), None)
295310
};
296311

297312
let (package, version) = client

0 commit comments

Comments
 (0)