Skip to content

Commit

Permalink
internal: Add version helpers. Remove old plugin code. (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Oct 28, 2023
1 parent 66da6c7 commit 4cbade4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 262 deletions.
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ path = "src/main.rs"
[dependencies]
proto_core = { version = "0.21.0", path = "../core" }
proto_pdk_api = { version = "0.9.0", path = "../pdk-api" }
proto_wasm_plugin = { version = "0.7.3", path = "../wasm-plugin" }
system_env = { version = "0.1.2", path = "../system-env" }
chrono = "0.4.31"
clap = { workspace = true, features = ["derive", "env"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/version_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ fn extract_installed_versions(installed: &HashSet<VersionSpec>) -> HashSet<&Vers
installed
.iter()
.filter_map(|item| match item {
VersionSpec::Alias(_) => None,
VersionSpec::Version(v) => Some(v),
_ => None,
})
.collect()
}
Expand Down
1 change: 0 additions & 1 deletion crates/pdk-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repository = "https://github.com/moonrepo/proto"
[dependencies]
proto_core = { version = "0.21.0", path = "../core" }
proto_pdk_api = { version = "0.9.0", path = "../pdk-api" }
proto_wasm_plugin = { version = "0.7.3", path = "../wasm-plugin" }
extism = { workspace = true }
serde_json = { workspace = true }
toml = { version = "0.8.2", optional = true }
Expand Down
3 changes: 1 addition & 2 deletions crates/pdk-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ pub use macros::*;
pub use proto_core as core;
pub use proto_core::{
Id, ProtoEnvironment, Tool, ToolManifest, ToolsConfig, UnresolvedVersionSpec, UserConfig,
Version, VersionReq, VersionSpec,
Version, VersionReq, VersionSpec, Wasm,
};
pub use proto_pdk_api::*;
pub use wrapper::WasmTestWrapper;

use proto_core::inject_default_manifest_config;
use proto_wasm_plugin::Wasm;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::{env, fs};
Expand Down
20 changes: 19 additions & 1 deletion crates/version-spec/src/resolved_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::str::FromStr;
#[derive(Clone, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(untagged, into = "String", try_from = "String")]
pub enum VersionSpec {
Canary,
Alias(String),
Version(Version),
}
Expand All @@ -18,22 +19,31 @@ impl VersionSpec {
Self::from_str(value.as_ref())
}

pub fn is_alias<A: AsRef<str>>(&self, name: A) -> bool {
match self {
Self::Alias(alias) => alias == name.as_ref(),
_ => false,
}
}

pub fn is_canary(&self) -> bool {
match self {
Self::Canary => true,
Self::Alias(alias) => alias == "canary",
_ => false,
}
}

pub fn is_latest(&self) -> bool {
match self {
Self::Alias(alias) => alias == "latest",
Self::Alias(alias) => alias == "latest" || alias == "stable",
_ => false,
}
}

pub fn to_unresolved_spec(&self) -> UnresolvedVersionSpec {
match self {
Self::Canary => UnresolvedVersionSpec::Canary,
Self::Alias(alias) => UnresolvedVersionSpec::Alias(alias.to_owned()),
Self::Version(version) => UnresolvedVersionSpec::Version(version.to_owned()),
}
Expand Down Expand Up @@ -84,6 +94,7 @@ impl Debug for VersionSpec {
impl Display for VersionSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Canary => write!(f, "canary"),
Self::Alias(alias) => write!(f, "{}", alias),
Self::Version(version) => write!(f, "{}", version),
}
Expand All @@ -93,6 +104,7 @@ impl Display for VersionSpec {
impl PartialEq<&str> for VersionSpec {
fn eq(&self, other: &&str) -> bool {
match self {
Self::Canary => "canary" == *other,
Self::Alias(alias) => alias == other,
Self::Version(version) => version.to_string() == *other,
}
Expand All @@ -107,3 +119,9 @@ impl PartialEq<Version> for VersionSpec {
}
}
}

impl AsRef<VersionSpec> for VersionSpec {
fn as_ref(&self) -> &VersionSpec {
self
}
}
23 changes: 20 additions & 3 deletions crates/version-spec/src/unresolved_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ impl UnresolvedVersionSpec {
Self::from_str(value.as_ref())
}

pub fn is_alias<A: AsRef<str>>(&self, name: A) -> bool {
match self {
Self::Alias(alias) => alias == name.as_ref(),
_ => false,
}
}

pub fn is_canary(&self) -> bool {
matches!(self, UnresolvedVersionSpec::Canary)
match self {
Self::Canary => true,
Self::Alias(alias) => alias == "canary",
_ => false,
}
}

pub fn is_latest(&self) -> bool {
match self {
Self::Alias(alias) => alias == "latest",
Self::Alias(alias) => alias == "latest" || alias == "stable",
_ => false,
}
}

pub fn to_resolved_spec(&self) -> VersionSpec {
match self {
Self::Canary => VersionSpec::Alias("canary".to_owned()),
Self::Canary => VersionSpec::Canary,
Self::Alias(alias) => VersionSpec::Alias(alias.to_owned()),
Self::Version(version) => VersionSpec::Version(version.to_owned()),
_ => unreachable!(),
Expand Down Expand Up @@ -148,3 +159,9 @@ impl PartialEq<VersionSpec> for UnresolvedVersionSpec {
}
}
}

impl AsRef<UnresolvedVersionSpec> for UnresolvedVersionSpec {
fn as_ref(&self) -> &UnresolvedVersionSpec {
self
}
}
15 changes: 0 additions & 15 deletions crates/wasm-plugin/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions crates/wasm-plugin/README.md

This file was deleted.

Loading

0 comments on commit 4cbade4

Please sign in to comment.