From 6fdc9a4b11cb57365071d6fdc58bf1022f74b8c5 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 6 Dec 2023 10:49:17 -0800 Subject: [PATCH] new: Clean the proto tool directory. (#321) --- CHANGELOG.md | 11 +++++++++++ crates/cli/src/commands/clean.rs | 27 +++++++++++++++++++++++++++ crates/core/src/proto_config.rs | 16 ++++++++-------- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be1b3af0..4616f089e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ intercept-globals = false ``` - Updated non-latest plugins to be cached for 30 days, instead of forever. +- Updated cleaning to also remove old proto versions from `~/.proto/tools/proto`. - WASM API - Added a `get_tool_config` function. Can be typed with a serde compatible struct. - Deprecated the `get_proto_user_config` function. @@ -52,6 +53,16 @@ - Fixed an issue where resolving canary versions wouldn't work correctly. +#### 🧩 Plugins + +- Updated `bun_plugin` to v0.6. +- Updated `deno_plugin` to v0.6. +- Updated `go_plugin` to v0.6. +- Updated `node_plugin` and `node_depman_plugin` to v0.6. +- Updated `python_plugin` to v0.4. +- Updated `rust_plugin` to v0.5. +- Updated `schema_plugin` (TOML) to v0.6. + ## 0.23.8 #### 🚀 Updates diff --git a/crates/cli/src/commands/clean.rs b/crates/cli/src/commands/clean.rs index 00484ecf1..6a06b373b 100644 --- a/crates/cli/src/commands/clean.rs +++ b/crates/cli/src/commands/clean.rs @@ -187,6 +187,31 @@ pub async fn clean_plugins(proto: &ProtoResource, days: u64) -> miette::Result miette::Result { + let duration = Duration::from_secs(86400 * days); + let mut clean_count = 0; + + for file in fs::read_dir_all(proto.env.tools_dir.join("proto"))? { + let path = file.path(); + + if path.is_file() { + let bytes = fs::remove_file_if_older_than(&path, duration)?; + + if bytes > 0 { + debug!( + "proto version {} hasn't been used in over {} days, removing", + color::path(&path), + days + ); + + clean_count += 1; + } + } + } + + Ok(clean_count) +} + pub async fn purge_tool(proto: &ProtoResource, id: &Id, yes: bool) -> SystemResult { let tool = proto.load_tool(id).await?; let inventory_dir = tool.get_inventory_dir(); @@ -255,6 +280,8 @@ pub async fn internal_clean(proto: &ProtoResource, args: &CleanArgs) -> SystemRe clean_count += clean_tool(tool, now, days, args.yes).await?; } + clean_count += clean_proto(proto, days as u64).await?; + if clean_count > 0 { info!("Successfully cleaned up {} versions", clean_count); } diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index ec48b0aed..2402570af 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -107,7 +107,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("bun"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/bun-plugin/releases/download/v0.5.0/bun_plugin.wasm".into() + url: "https://github.com/moonrepo/bun-plugin/releases/download/v0.6.0/bun_plugin.wasm".into() } ); } @@ -116,7 +116,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("deno"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/deno-plugin/releases/download/v0.5.0/deno_plugin.wasm".into() + url: "https://github.com/moonrepo/deno-plugin/releases/download/v0.6.0/deno_plugin.wasm".into() } ); } @@ -125,7 +125,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("go"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/go-plugin/releases/download/v0.5.0/go_plugin.wasm".into() + url: "https://github.com/moonrepo/go-plugin/releases/download/v0.6.0/go_plugin.wasm".into() } ); } @@ -134,7 +134,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("node"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/node-plugin/releases/download/v0.5.3/node_plugin.wasm".into() + url: "https://github.com/moonrepo/node-plugin/releases/download/v0.6.0/node_plugin.wasm".into() } ); } @@ -144,7 +144,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw(depman), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/node-plugin/releases/download/v0.5.3/node_depman_plugin.wasm".into() + url: "https://github.com/moonrepo/node-plugin/releases/download/v0.6.0/node_depman_plugin.wasm".into() } ); } @@ -154,7 +154,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("python"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/python-plugin/releases/download/v0.3.0/python_plugin.wasm".into() + url: "https://github.com/moonrepo/python-plugin/releases/download/v0.4.0/python_plugin.wasm".into() } ); } @@ -163,7 +163,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw("rust"), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/rust-plugin/releases/download/v0.4.0/rust_plugin.wasm".into() + url: "https://github.com/moonrepo/rust-plugin/releases/download/v0.5.0/rust_plugin.wasm".into() } ); } @@ -172,7 +172,7 @@ impl ProtoConfig { self.plugins.insert( Id::raw(SCHEMA_PLUGIN_KEY), PluginLocator::SourceUrl { - url: "https://github.com/moonrepo/schema-plugin/releases/download/v0.5.0/schema_plugin.wasm".into() + url: "https://github.com/moonrepo/schema-plugin/releases/download/v0.6.0/schema_plugin.wasm".into() } ); }