Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/wasm-pkg-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wasm-pkg-client"
description = "Wasm package client"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/tree/main/crates/wasm-pkg-client"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/"
edition.workspace = true
version.workspace = true
authors.workspace = true
Expand Down Expand Up @@ -44,5 +44,5 @@ tempfile = { workspace = true }

[dev-dependencies]
rcgen = { workspace = true }
rstest = "0.23"
rstest = { workspace = true }
testcontainers = { workspace = true }
8 changes: 7 additions & 1 deletion crates/wasm-pkg-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl Client {
package: &PackageRef,
version: &Version,
) -> Result<Release, Error> {
// FIXME: the `None` below means we ignore workspace overrides for this call
let source = self.resolve_source(package, None).await?;
source.get_release(package, version).await
}
Expand Down Expand Up @@ -191,7 +192,12 @@ impl Client {
fetch_semver_series(source.as_ref().as_ref(), &package, &version).await?
{
match version.cmp(&version_info.version) {
Ordering::Equal => return Err(Error::VersionAlreadyExists(version.to_owned())),
Ordering::Equal => {
return Err(Error::VersionAlreadyExists(
package.clone(),
version.to_owned(),
));
}
Ordering::Greater => {
// incoming version is greater than neighbor
neighbors[0] = Some(version_info);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-client/src/local.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Local filesystem-based package backend.
//!
//! Each package release is a file: `<root>/<namespace>/<name>/<version>.wasm`
//! Each package release is a file: `<root-dir>/<namespace>/<name>/<version>.wasm`
use std::{
io,
Expand Down
17 changes: 12 additions & 5 deletions crates/wasm-pkg-client/tests/publish_semver_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ fn semver_incompatible(previous: &str, new: &str) -> Error {
}
}

fn version_already_exists(version: &str) -> Error {
Error::VersionAlreadyExists(version.parse().unwrap())
fn version_already_exists(package: &str, version: &str) -> Error {
Error::VersionAlreadyExists(
format!("{NAMESPACE}:{package}").parse().unwrap(),
version.parse().unwrap(),
)
}

fn make_client(root: &Path) -> Client {
Expand Down Expand Up @@ -141,7 +144,7 @@ async fn publish(client: &Client, bytes: Vec<u8>, opts: PublishOpts) -> Result<(
Some(("0.1.0", WorldDiff::AddBase)),
("0.1.0", WorldDiff::AddBase),
false,
Err(version_already_exists("0.1.0"))
Err(version_already_exists("dup-version", "0.1.0"))
)]
#[case::duplicate_version_with_skip_semver_check(
"dup-version-opt-out",
Expand Down Expand Up @@ -209,8 +212,12 @@ async fn publish_semver_check(
assert_eq!(previous, exp_prev, "previous version mismatch");
assert_eq!(new, exp_new, "new version mismatch");
}
(Err(Error::VersionAlreadyExists(exp)), Err(Error::VersionAlreadyExists(actual))) => {
assert_eq!(actual, exp, "duplicate version mismatch");
(
Err(Error::VersionAlreadyExists(exp_pkg, exp_ver)),
Err(Error::VersionAlreadyExists(pkg, ver)),
) => {
assert_eq!(pkg, exp_pkg, "duplicate package mismatch");
assert_eq!(ver, exp_ver, "duplicate version mismatch");
}
_ => panic!("expectation mismatch\n expected: {expected:?}\n actual: {result:?}",),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wasm-pkg-common"
description = "Wasm Package common types and configuration"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/tree/main/crates/wasm-pkg-common"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/"
edition.workspace = true
version.workspace = true
authors.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions crates/wasm-pkg-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use http::uri::InvalidUri;
use label::Label;

use crate::package::PackageRef;

#[cfg(feature = "registry-config")]
pub mod config;
pub mod digest;
Expand Down Expand Up @@ -53,8 +55,8 @@ pub enum Error {
RegistryMetadataError(#[source] anyhow::Error),
#[error("version not found: {0}")]
VersionNotFound(semver::Version),
#[error("version {0} is already published for this package")]
VersionAlreadyExists(semver::Version),
#[error("{0}@{1} already exists in the registry")]
VersionAlreadyExists(PackageRef, semver::Version),
#[error(
"new version {new} is not semver-compatible with existing version {previous}: {source:#}"
)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wasm-pkg-core"
description = "Wasm Package Tools core libraries for wkg"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/tree/main/crates/wasm-pkg-core"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/"
edition.workspace = true
version.workspace = true
authors.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-pkg-core/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use crate::{
},
};

/// Directory holding WIT dependencies for one or more packages
pub const WIT_DEPS_DIR: &str = "deps";

/// The supported output types for WIT deps
#[derive(Debug, Clone, Copy, Default)]
pub enum OutputType {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-core/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn test_bad_dep_failure() {
.expect("Should be able to create a new lock file");
let (_temp_cache, client) = common::get_client().await.unwrap();

let world_file = fixture_path.join("wit").join("proxy.wit");
let world_file = fixture_path.join("wit/proxy.wit");
let str_world = tokio::fs::read_to_string(&world_file)
.await
.expect("Should be able to read the world file");
Expand Down
8 changes: 5 additions & 3 deletions crates/wasm-pkg-core/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::path::{Path, PathBuf};

use tempfile::TempDir;
use wasm_pkg_client::{
Client,
Client, Config,
caching::{CachingClient, FileCache},
};
use wasm_pkg_core::wit::WIT_DEPS_DIR;

pub fn fixture_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand All @@ -13,7 +14,8 @@ pub fn fixture_dir() -> PathBuf {
}

pub async fn get_client() -> anyhow::Result<(TempDir, CachingClient<FileCache>)> {
let client = Client::with_global_defaults().await?;
// NOTE: `Client::with_global_defaults()` may pick up a user's redirect of `wasi` to a private registry
let client = Client::new(Config::default());
let cache_temp_dir = tempfile::tempdir()?;
let cache = FileCache::new(cache_temp_dir.path()).await?;

Expand All @@ -38,7 +40,7 @@ async fn copy_dir(source: impl AsRef<Path>, destination: impl AsRef<Path>) -> an
let filetype = entry.file_type().await?;
if filetype.is_dir() {
// Skip the deps directory in case it is there from debugging
if entry.path().file_name().unwrap_or_default() == "deps" {
if entry.path().file_name().unwrap_or_default() == WIT_DEPS_DIR {
continue;
}
Box::pin(copy_dir(
Expand Down
10 changes: 5 additions & 5 deletions crates/wasm-pkg-core/tests/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn test_nested_local(#[values(OutputType::Wasm, OutputType::Wit)] output:
overrides.insert(
"my:local".to_string(),
Override {
path: Some(fixture_path.join("local-dep").join("wit")),
path: Some(fixture_path.join("local-dep/wit")),
..Default::default()
},
);
Expand Down Expand Up @@ -103,21 +103,21 @@ async fn test_transitive_local(#[values(OutputType::Wasm, OutputType::Wit)] outp
(
"example-b:bar".to_string(),
Override {
path: Some(fixture_path.join("example-b").join("wit")),
path: Some(fixture_path.join("example-b/wit")),
version: None,
},
),
(
"example-c:baz".to_string(),
Override {
path: Some(fixture_path.join("example-c").join("wit")),
path: Some(fixture_path.join("example-c/wit")),
version: None,
},
),
(
"example-c:nested".to_string(),
Override {
path: Some(fixture_path.join("example-c").join("wit/nested")),
path: Some(fixture_path.join("example-c/wit/nested")),
version: None,
},
),
Expand All @@ -138,7 +138,7 @@ async fn test_transitive_local(#[values(OutputType::Wasm, OutputType::Wit)] outp
.unwrap_or_else(|e| panic!("Should be able to fetch the dependencies: {e:#}"));

// Ensure that the deps directory contains the correct dependencies
let mut deps_dir = tokio::fs::read_dir(project_path.join("wit").join("deps"))
let mut deps_dir = tokio::fs::read_dir(project_path.join("wit/deps"))
.await
.expect("Should be able to read the deps directory");
let mut deps = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/wkg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wkg"
description = "Wasm Package Tools CLI"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/tree/main/crates/wkg"
repository = "https://github.com/bytecodealliance/wasm-pkg-tools/"
edition.workspace = true
version.workspace = true
authors.workspace = true
Expand Down
Loading
Loading