Skip to content

Commit

Permalink
new: Allow plugins to ignore detecting from paths. (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Nov 14, 2023
1 parent 9813d9c commit fcb53fb
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 43 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
- [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md)
- [TOML schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md)

## Unreleased

#### Updates

- Added support to plugins to ignore certain paths when detecting a version.
- WASM API
- Added `DetectVersionOutput.ignore` field.

## 0.22.2

#### 🐞 Fixes
Expand Down
37 changes: 18 additions & 19 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default-members = ["crates/cli"]

[workspace.dependencies]
cached = "0.46.1"
clap = "4.4.7"
clap = "4.4.8"
clap_complete = "4.4.4"
convert_case = "0.6.0"
extism = { version = "0.5.4" }
Expand Down Expand Up @@ -39,7 +39,7 @@ starbase_utils = { version = "0.3.7", default-features = false, features = [
"toml",
] }
thiserror = "1.0.50"
tokio = { version = "1.33.0", features = ["full", "tracing"] }
tokio = { version = "1.34.0", features = ["full", "tracing"] }
tracing = "0.1.40"

# Config for 'cargo dist'
Expand Down
14 changes: 9 additions & 5 deletions crates/core/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,17 @@ impl Tool {
return Ok(None);
}

// TODO move this into plugins
if current_dir.to_string_lossy().contains("node_modules") {
return Ok(None);
}

let has_parser = self.plugin.has_func("parse_version_file");
let result: DetectVersionOutput = self.plugin.cache_func("detect_version_files")?;

if !result.ignore.is_empty() {
if let Some(dir) = current_dir.to_str() {
if result.ignore.iter().any(|ignore| dir.contains(ignore)) {
return Ok(None);
}
}
}

trace!(
tool = self.id.as_str(),
dir = ?current_dir,
Expand Down Expand Up @@ -593,6 +596,7 @@ impl Tool {
debug!(
tool = self.id.as_str(),
file = ?file_path,
version = version.to_string(),
"Detected a version"
);

Expand Down
20 changes: 20 additions & 0 deletions crates/pdk-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ use warpgate_api::VirtualPath;

pub use semver::{Version, VersionReq};

fn is_empty_map<K, V>(value: &HashMap<K, V>) -> bool {
value.is_empty()
}

fn is_empty_vec<T>(value: &[T]) -> bool {
value.is_empty()
}

fn is_false(value: &bool) -> bool {
!(*value)
}
Expand Down Expand Up @@ -103,6 +111,7 @@ json_struct!(

/// Names of commands that will self-upgrade the tool,
/// and should be blocked from happening.
#[serde(skip_serializing_if = "is_empty_vec")]
pub self_upgrade_commands: Vec<String>,

/// Type of the tool.
Expand All @@ -117,7 +126,12 @@ json_struct!(
/// Output returned by the `detect_version_files` function.
pub struct DetectVersionOutput {
/// List of files that should be checked for version information.
#[serde(skip_serializing_if = "is_empty_vec")]
pub files: Vec<String>,

/// List of path patterns to ignore when traversing directories.
#[serde(skip_serializing_if = "is_empty_vec")]
pub ignore: Vec<String>,
}
);

Expand Down Expand Up @@ -241,10 +255,12 @@ json_struct!(

/// List of instructions to execute to build the tool, after system
/// dependencies have been installed.
#[serde(skip_serializing_if = "is_empty_vec")]
pub instructions: Vec<BuildInstruction>,

/// List of system dependencies that are required for building from source.
/// If a dependency does not exist, it will be installed.
#[serde(skip_serializing_if = "is_empty_vec")]
pub system_dependencies: Vec<SystemDependency>,
}
);
Expand Down Expand Up @@ -401,6 +417,7 @@ json_struct!(
pub struct LocateExecutablesOutput {
/// List of directory paths to find the globals installation directory.
/// Each path supports environment variable expansion.
#[serde(skip_serializing_if = "is_empty_vec")]
pub globals_lookup_dirs: Vec<String>,

/// A string that all global binaries are prefixed with, and will be removed
Expand All @@ -415,6 +432,7 @@ json_struct!(

/// Configures secondary/additional executables to create.
/// The map key is the name of the shim/binary file.
#[serde(skip_serializing_if = "is_empty_map")]
pub secondary: HashMap<String, ExecutableConfig>,
}
);
Expand Down Expand Up @@ -525,9 +543,11 @@ json_struct!(
pub latest: Option<Version>,

/// Mapping of aliases (channels, etc) to a version.
#[serde(skip_serializing_if = "is_empty_map")]
pub aliases: HashMap<String, Version>,

/// List of available production versions to install.
#[serde(skip_serializing_if = "is_empty_vec")]
pub versions: Vec<Version>,
}
);
Expand Down
33 changes: 16 additions & 17 deletions plugins/Cargo.lock

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

1 change: 1 addition & 0 deletions plugins/wasm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn register_tool(_: ()) -> FnResult<Json<ToolMetadataOutput>> {
pub fn detect_version_files(_: ()) -> FnResult<Json<DetectVersionOutput>> {
Ok(Json(DetectVersionOutput {
files: vec![".proto-wasm-version".into(), ".protowasmrc".into()],
ignore: vec!["node_modules".into()],
}))
}

Expand Down

0 comments on commit fcb53fb

Please sign in to comment.