-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Create a registry of all shims. (#330)
- Loading branch information
Showing
26 changed files
with
328 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_bun.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"bun": {}, | ||
"bunx": { | ||
"alt_for": "bun", | ||
"before_args": [ | ||
"x" | ||
] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_deno.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"deno": {} | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_go.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"go": {} | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_node.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"node": {} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_npm.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"node": {}, | ||
"node-gyp": { | ||
"alt_for": "npm" | ||
}, | ||
"npm": {}, | ||
"npx": { | ||
"alt_for": "npm" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_pnpm.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"node": {}, | ||
"pnpm": {}, | ||
"pnpx": { | ||
"alt_for": "pnpm", | ||
"before_args": [ | ||
"dlx" | ||
] | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_python.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"pip": { | ||
"alt_for": "python", | ||
"before_args": [ | ||
"-m", | ||
"pip" | ||
] | ||
}, | ||
"python": {} | ||
} |
11 changes: 11 additions & 0 deletions
11
crates/cli/tests/snapshots/plugins_test__plugins__builtins__supports_yarn.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: crates/cli/tests/plugins_test.rs | ||
expression: "fs::read_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()" | ||
--- | ||
{ | ||
"node": {}, | ||
"yarn": {}, | ||
"yarnpkg": { | ||
"alt_for": "yarn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::helpers::{read_json_file_with_lock, write_json_file_with_lock}; | ||
use crate::proto::ProtoEnvironment; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::{BTreeMap, HashMap}; | ||
|
||
// Keep in sync with crates/cli-shim/src/main.rs | ||
#[derive(Default, Deserialize, PartialEq, Serialize)] | ||
#[serde(default)] | ||
pub struct Shim { | ||
#[serde(skip_serializing_if = "Vec::is_empty")] | ||
pub after_args: Vec<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub alt_for: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Vec::is_empty")] | ||
pub before_args: Vec<String>, | ||
|
||
#[serde(skip_serializing_if = "HashMap::is_empty")] | ||
pub env_vars: HashMap<String, String>, | ||
} | ||
|
||
pub type ShimsMap = BTreeMap<String, Shim>; | ||
|
||
pub struct ShimRegistry; | ||
|
||
impl ShimRegistry { | ||
pub fn update<P: AsRef<ProtoEnvironment>>(proto: P, entries: ShimsMap) -> miette::Result<()> { | ||
if entries.is_empty() { | ||
return Ok(()); | ||
} | ||
|
||
let file = proto.as_ref().shims_dir.join("registry.json"); | ||
|
||
let mut config: ShimsMap = if file.exists() { | ||
read_json_file_with_lock(&file)? | ||
} else { | ||
BTreeMap::default() | ||
}; | ||
|
||
let mut mutated = false; | ||
|
||
for (key, value) in entries { | ||
// Don't write the file if nothing has changed | ||
if config | ||
.get(&key) | ||
.is_some_and(|current_value| current_value == &value) | ||
{ | ||
continue; | ||
} | ||
|
||
config.insert(key, value); | ||
mutated = true; | ||
} | ||
|
||
if mutated { | ||
write_json_file_with_lock(file, &config)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.