Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
new: Support gofmt and loosen version range. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored May 9, 2024
1 parent b3454fb commit df434d1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.11.1

#### 🚀 Updates

- Added `gofmt` as a secondary shim/binary.
- Updated `go.mod` version parsing to use better ranges.

## 0.11.0

#### 🚀 Updates
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "go_plugin"
version = "0.11.0"
version = "0.11.1"
edition = "2021"
license = "MIT"
publish = false
Expand Down
8 changes: 7 additions & 1 deletion src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub fn parse_version_file(
if input.file == "go.mod" || input.file == "go.work" {
for line in input.content.split('\n') {
if let Some(v) = line.strip_prefix("go ") {
version = Some(UnresolvedVersionSpec::parse(v)?);
let range = format!("^{}", from_go_version(v));

version = Some(UnresolvedVersionSpec::parse(range)?);
break;
}
}
Expand Down Expand Up @@ -144,6 +146,10 @@ pub fn locate_executables(
primary: Some(ExecutableConfig::new(
env.os.get_exe_name(format!("bin/{}", BIN)),
)),
secondary: HashMap::from_iter([(
"gofmt".into(),
ExecutableConfig::new(env.os.get_exe_name("bin/gofmt")),
)]),
..LocateExecutablesOutput::default()
}))
}
Expand Down
6 changes: 5 additions & 1 deletion tests/snapshots/shims_test__creates_shims.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ source: tests/shims_test.rs
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()"
---
{
"go-test": {}
"go-test": {},
"gofmt": {
"alt_bin": true,
"parent": "go-test"
}
}
6 changes: 3 additions & 3 deletions tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ generate_resolve_versions_tests!("go-test", {
"1.11" => "1.11.13",
"1.9.0-rc2" => "1.9.0-rc2",
"1.21.0" => "1.21.0",
"1.21" => "1.21.9",
"1.21" => "1.21.10",
});

#[test]
Expand Down Expand Up @@ -50,7 +50,7 @@ require (

assert_eq!(
output.version.unwrap(),
UnresolvedVersionSpec::parse("1.20").unwrap()
UnresolvedVersionSpec::parse("^1.20.0").unwrap()
);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ use (

assert_eq!(
output.version.unwrap(),
UnresolvedVersionSpec::parse("1.18").unwrap()
UnresolvedVersionSpec::parse("^1.18.0").unwrap()
);
}

Expand Down

0 comments on commit df434d1

Please sign in to comment.