Skip to content

Commit

Permalink
new: Clean the proto tool directory. (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Dec 6, 2023
1 parent 1bd9a97 commit 6fdc9a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ pub async fn clean_plugins(proto: &ProtoResource, days: u64) -> miette::Result<u
Ok(clean_count)
}

pub async fn clean_proto(proto: &ProtoResource, days: u64) -> miette::Result<usize> {
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();
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions crates/core/src/proto_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand All @@ -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()
}
);
}
Expand Down

0 comments on commit 6fdc9a4

Please sign in to comment.