diff --git a/crates/pdk-api/src/api.rs b/crates/pdk-api/src/api.rs index 115fd8bd2..02b93a6a9 100644 --- a/crates/pdk-api/src/api.rs +++ b/crates/pdk-api/src/api.rs @@ -1,7 +1,6 @@ use crate::host_funcs::ExecCommandOutput; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::ffi::OsStr; use std::path::PathBuf; use system_env::SystemDependency; use version_spec::{UnresolvedVersionSpec, VersionSpec}; @@ -403,38 +402,6 @@ json_struct!( } ); -json_struct!( - /// Input passed to the `locate_bins` function. - pub struct LocateBinsInput { - /// Current tool context. - pub context: ToolContext, - } -); - -json_struct!( - /// Output returned by the `locate_bins` function. - #[deprecated(since = "0.22.0", note = "Use `locate_executables` function instead.")] - pub struct LocateBinsOutput { - /// Relative path from the tool directory to the binary to execute. - #[serde(skip_serializing_if = "Option::is_none")] - pub bin_path: Option, - - /// When true, the last item in `globals_lookup_dirs` will be used, - /// regardless if it exists on the file system or not. - #[serde(skip_serializing_if = "is_false")] - pub fallback_last_globals_dir: bool, - - /// List of directory paths to find the globals installation directory. - /// Each path supports environment variable expansion. - pub globals_lookup_dirs: Vec, - - /// A string that all global binaries are prefixed with, and will be removed - /// when listing and filtering available globals. - #[serde(skip_serializing_if = "Option::is_none")] - pub globals_prefix: Option, - } -); - json_struct!( /// Input passed to the `install_global` function. pub struct InstallGlobalInput { @@ -549,11 +516,6 @@ json_struct!( ); impl LoadVersionsOutput { - #[deprecated = "Use from() instead."] - pub fn from_tags(tags: &[String]) -> anyhow::Result { - Self::from(tags.to_vec()) - } - /// Create the output from a list of strings that'll be parsed as versions. /// The latest version will be the highest version number. pub fn from(values: Vec) -> anyhow::Result { @@ -609,113 +571,6 @@ json_struct!( } ); -// Shimmer - -json_struct!( - /// Configuration for individual shim files. - pub struct ShimConfig { - /// The binary to execute. Can be a relative path from the tool directory, - /// or an absolute path - #[serde(skip_serializing_if = "Option::is_none")] - pub bin_path: Option, - - /// Name of a parent binary that's required for this shim to work. - /// For example, `npm` requires `node`. - #[serde(skip_serializing_if = "Option::is_none")] - pub parent_bin: Option, - - /// Custom args to prepend to user-provided args. - #[serde(skip_serializing_if = "Option::is_none")] - pub before_args: Option, - - /// Custom args to append to user-provided args. - #[serde(skip_serializing_if = "Option::is_none")] - pub after_args: Option, - } -); - -impl ShimConfig { - /// Create a global shim that executes the parent tool, - /// but uses the provided binary as the entry point. - pub fn global_with_alt_bin(bin_path: B) -> ShimConfig - where - B: AsRef, - { - ShimConfig { - bin_path: Some(bin_path.as_ref().into()), - ..ShimConfig::default() - } - } - - /// Create a global shim that executes the parent tool, - /// but prefixes the user-provided arguments with the - /// provided arguments (typically a sub-command). - pub fn global_with_sub_command(args: A) -> ShimConfig - where - A: AsRef, - { - ShimConfig { - before_args: Some(args.as_ref().to_owned()), - ..ShimConfig::default() - } - } - - /// Create a local shim that executes the provided binary. - pub fn local(bin_path: B) -> ShimConfig - where - B: AsRef, - { - ShimConfig { - bin_path: Some(bin_path.as_ref().into()), - ..ShimConfig::default() - } - } - - /// Create a local shim that executes the provided binary - /// through the context of the configured parent. - pub fn local_with_parent(bin_path: B, parent: P) -> ShimConfig - where - B: AsRef, - P: AsRef, - { - ShimConfig { - bin_path: Some(bin_path.as_ref().into()), - parent_bin: Some(parent.as_ref().to_owned()), - ..ShimConfig::default() - } - } -} - -json_struct!( - /// Input passed to the `create_shims` function. - pub struct CreateShimsInput { - /// Current tool context. - pub context: ToolContext, - } -); - -json_struct!( - /// Output returned by the `create_shims` function. - #[deprecated(since = "0.22.0", note = "Use `locate_executables` function instead.")] - pub struct CreateShimsOutput { - /// Avoid creating the global shim. - #[serde(skip_serializing_if = "is_false")] - pub no_primary_global: bool, - - /// Configures the default/primary global shim. - #[serde(skip_serializing_if = "Option::is_none")] - pub primary: Option, - - /// Additional global shims to create in the `~/.proto/shims` directory. - /// Maps a shim name to a relative binary path. - pub global_shims: HashMap, - - /// Local shims to create in the `~/.proto/tools///shims` directory. - /// Maps a shim name to its configuration. - pub local_shims: HashMap, - } -); - // MISCELLANEOUS json_struct!( diff --git a/crates/pdk-api/src/api_deprecated.rs b/crates/pdk-api/src/api_deprecated.rs new file mode 100644 index 000000000..8de105397 --- /dev/null +++ b/crates/pdk-api/src/api_deprecated.rs @@ -0,0 +1,145 @@ +#![allow(deprecated)] + +use crate::api::ToolContext; +use crate::json_struct; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::ffi::OsStr; +use std::path::PathBuf; + +json_struct!( + /// Input passed to the `locate_bins` function. + pub struct LocateBinsInput { + /// Current tool context. + pub context: ToolContext, + } +); + +json_struct!( + /// Output returned by the `locate_bins` function. + #[deprecated(since = "0.22.0", note = "Use `locate_executables` function instead.")] + pub struct LocateBinsOutput { + /// Relative path from the tool directory to the binary to execute. + #[serde(skip_serializing_if = "Option::is_none")] + pub bin_path: Option, + + /// When true, the last item in `globals_lookup_dirs` will be used, + /// regardless if it exists on the file system or not. + pub fallback_last_globals_dir: bool, + + /// List of directory paths to find the globals installation directory. + /// Each path supports environment variable expansion. + pub globals_lookup_dirs: Vec, + + /// A string that all global binaries are prefixed with, and will be removed + /// when listing and filtering available globals. + #[serde(skip_serializing_if = "Option::is_none")] + pub globals_prefix: Option, + } +); + +// Shimmer + +json_struct!( + /// Configuration for individual shim files. + pub struct ShimConfig { + /// The binary to execute. Can be a relative path from the tool directory, + /// or an absolute path + #[serde(skip_serializing_if = "Option::is_none")] + pub bin_path: Option, + + /// Name of a parent binary that's required for this shim to work. + /// For example, `npm` requires `node`. + #[serde(skip_serializing_if = "Option::is_none")] + pub parent_bin: Option, + + /// Custom args to prepend to user-provided args. + #[serde(skip_serializing_if = "Option::is_none")] + pub before_args: Option, + + /// Custom args to append to user-provided args. + #[serde(skip_serializing_if = "Option::is_none")] + pub after_args: Option, + } +); + +impl ShimConfig { + /// Create a global shim that executes the parent tool, + /// but uses the provided binary as the entry point. + pub fn global_with_alt_bin(bin_path: B) -> ShimConfig + where + B: AsRef, + { + ShimConfig { + bin_path: Some(bin_path.as_ref().into()), + ..ShimConfig::default() + } + } + + /// Create a global shim that executes the parent tool, + /// but prefixes the user-provided arguments with the + /// provided arguments (typically a sub-command). + pub fn global_with_sub_command(args: A) -> ShimConfig + where + A: AsRef, + { + ShimConfig { + before_args: Some(args.as_ref().to_owned()), + ..ShimConfig::default() + } + } + + /// Create a local shim that executes the provided binary. + pub fn local(bin_path: B) -> ShimConfig + where + B: AsRef, + { + ShimConfig { + bin_path: Some(bin_path.as_ref().into()), + ..ShimConfig::default() + } + } + + /// Create a local shim that executes the provided binary + /// through the context of the configured parent. + pub fn local_with_parent(bin_path: B, parent: P) -> ShimConfig + where + B: AsRef, + P: AsRef, + { + ShimConfig { + bin_path: Some(bin_path.as_ref().into()), + parent_bin: Some(parent.as_ref().to_owned()), + ..ShimConfig::default() + } + } +} + +json_struct!( + /// Input passed to the `create_shims` function. + pub struct CreateShimsInput { + /// Current tool context. + pub context: ToolContext, + } +); + +json_struct!( + /// Output returned by the `create_shims` function. + #[deprecated(since = "0.22.0", note = "Use `locate_executables` function instead.")] + pub struct CreateShimsOutput { + /// Avoid creating the global shim. + pub no_primary_global: bool, + + /// Configures the default/primary global shim. + #[serde(skip_serializing_if = "Option::is_none")] + pub primary: Option, + + /// Additional global shims to create in the `~/.proto/shims` directory. + /// Maps a shim name to a relative binary path. + pub global_shims: HashMap, + + /// Local shims to create in the `~/.proto/tools///shims` directory. + /// Maps a shim name to its configuration. + pub local_shims: HashMap, + } +); diff --git a/crates/pdk-api/src/lib.rs b/crates/pdk-api/src/lib.rs index a5fa9b16c..ccb23f786 100644 --- a/crates/pdk-api/src/lib.rs +++ b/crates/pdk-api/src/lib.rs @@ -1,10 +1,12 @@ mod api; +mod api_deprecated; mod error; mod hooks; mod host; mod host_funcs; pub use api::*; +pub use api_deprecated::*; pub use error::*; pub use hooks::*; pub use host::*;