Skip to content

Commit

Permalink
breaking: Standardize configuration. (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 6, 2023
1 parent 9568b84 commit 0a6efff
Show file tree
Hide file tree
Showing 79 changed files with 2,748 additions and 1,813 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@
- [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md)
- [TOML schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md)

## Unreleased

#### 💥 Breaking

> To ease the migration process, we've added a new migrate command. Simply run `proto migrate v0.24` after upgrading proto!
- Standardized configuration files.
- Merged `~/.proto/config.toml` functionality into `.prototools` under a new `[settings]` table. This means settings like `auto-clean` can be defined anywhere now.
- Removed `~/.proto/config.toml`. Use `~/.proto/.prototools` instead, which is now the new global config (via `--global` arg).
- Moved `node-intercept-globals` setting to `tools.node.intercept-globals`.
- Reworked user configured aliases and default/global version.
- Moved values to `.prototools` (user managed) from `~/.proto/tools/<name>/manifest.json` (internally managed).
- Aliases are now stored in the `[tools.<name>]`, while the default version is at the root.
```toml
node = "20.10.0"
[tools.node.aliases]
work = "^18"
```
- Updated `proto alias` and `proto unalias` to longer write to the global config by default. Now requires a `--global` flag.
- This change was made to align with `proto pin`, `proto tool add`, and `proto tool remove`.

#### 🚀 Updates

- Added a `proto migrate v0.24` command for migrating configs. We'll also log a warning if we detect the old configuration.
- For some scenarios, we'll attempt to auto-migrate under the hood when applicable.
- Updated non-latest plugins to be cached for 30 days, instead of forever.

#### 🐞 Fixes

- Fixed an issue where resolving canary versions wouldn't work correctly.

## 0.23.8

#### 🚀 Updates
Expand Down
94 changes: 86 additions & 8 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ once_cell = "1.18.0"
once_map = "0.4.13"
regex = { version = "1.10.2", default-features = false, features = ["std"] }
reqwest = { version = "0.11.22", default-features = false }
schematic = { version = "0.12.8", default-features = false, features = [
"schema",
] }
schematic = { version = "0.12.10", default-features = false }
semver = "1.0.20"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub enum Commands {
alias = "ap",
name = "add-plugin",
about = "Add a plugin.",
long_about = "Add a plugin to the local .prototools config, or global ~/.proto/config.toml config.",
long_about = "Add a plugin to the local .prototools config, or global ~/.proto/.prototools config.",
hide = true
)]
AddPlugin(AddToolArgs),
Expand Down Expand Up @@ -188,7 +188,7 @@ pub enum Commands {
alias = "rp",
name = "remove-plugin",
about = "Remove a plugin.",
long_about = "Remove a plugin from the local .prototools config, or global ~/.proto/config.toml config.",
long_about = "Remove a plugin from the local .prototools config, or global ~/.proto/.prototools config.",
hide = true
)]
RemovePlugin(RemoveToolArgs),
Expand Down Expand Up @@ -255,7 +255,7 @@ pub enum ToolCommands {
#[command(
name = "add",
about = "Add a tool plugin.",
long_about = "Add a plugin to the local .prototools config, or global ~/.proto/config.toml config."
long_about = "Add a plugin to the local .prototools config, or global ~/.proto/.prototools config."
)]
Add(AddToolArgs),

Expand All @@ -278,7 +278,7 @@ pub enum ToolCommands {
#[command(
name = "remove",
about = "Remove a tool plugin.",
long_about = "Remove a plugin from the local .prototools config, or global ~/.proto/config.toml config."
long_about = "Remove a plugin from the local .prototools config, or global ~/.proto/.prototools config."
)]
Remove(RemoveToolArgs),
}
26 changes: 19 additions & 7 deletions crates/cli/src/commands/alias.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::ProtoCliError;
use crate::helpers::ProtoResource;
use clap::Args;
use proto_core::{is_alias_name, load_tool, Id, UnresolvedVersionSpec};
use proto_core::{is_alias_name, Id, ProtoConfig, UnresolvedVersionSpec};
use starbase::system;
use starbase_styles::color;
use tracing::info;
Expand All @@ -15,10 +16,16 @@ pub struct AliasArgs {

#[arg(required = true, help = "Version or alias to associate with")]
spec: UnresolvedVersionSpec,

#[arg(
long,
help = "Add to the global .prototools instead of local .prototools"
)]
global: bool,
}

#[system]
pub async fn alias(args: ArgsRef<AliasArgs>) {
pub async fn alias(args: ArgsRef<AliasArgs>, proto: ResourceRef<ProtoResource>) {
if let UnresolvedVersionSpec::Alias(inner_alias) = &args.spec {
if &args.alias == inner_alias {
return Err(ProtoCliError::NoMatchingAliasToVersion.into());
Expand All @@ -32,12 +39,17 @@ pub async fn alias(args: ArgsRef<AliasArgs>) {
.into());
}

let mut tool = load_tool(&args.id).await?;
let tool = proto.load_tool(&args.id).await?;

ProtoConfig::update(tool.proto.get_config_dir(args.global), |config| {
let tool_configs = config.tools.get_or_insert(Default::default());
let tool_config = tool_configs.entry(tool.id.clone()).or_default();

tool.manifest
.aliases
.insert(args.alias.clone(), args.spec.clone());
tool.manifest.save()?;
tool_config
.aliases
.get_or_insert(Default::default())
.insert(args.alias.clone(), args.spec.clone());
})?;

info!(
"Added alias {} ({}) for {}",
Expand Down
7 changes: 4 additions & 3 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::helpers::ProtoResource;
use clap::Args;
use proto_core::{detect_version, load_tool, Id, UnresolvedVersionSpec};
use proto_core::{detect_version, Id, UnresolvedVersionSpec};
use starbase::system;

#[derive(Args, Clone, Debug)]
Expand All @@ -18,8 +19,8 @@ pub struct BinArgs {
}

#[system]
pub async fn bin(args: ArgsRef<BinArgs>) {
let mut tool = load_tool(&args.id).await?;
pub async fn bin(args: ArgsRef<BinArgs>, proto: ResourceRef<ProtoResource>) {
let mut tool = proto.load_tool(&args.id).await?;
let version = detect_version(&tool, args.spec.clone()).await?;

tool.resolve_version(&version, true).await?;
Expand Down
Loading

0 comments on commit 0a6efff

Please sign in to comment.