Skip to content

Commit

Permalink
Merge pull request #33 from mario-eth/release/v0.2.6
Browse files Browse the repository at this point in the history
Release/v0.2.6
  • Loading branch information
mario-eth authored Mar 22, 2024
2 parents 4f6cd6b + 96fb423 commit cbecec7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 520 deletions.
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
Expand Up @@ -10,7 +10,7 @@ license = "MIT"
name = "soldeer"
readme = "./README.md"
repository = "https://github.com/mario-eth/soldeer"
version = "0.2.4"
version = "0.2.6"

[dependencies]
chrono = {version = "0.4.34", features = ["serde"]}
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ This project was started to solve the following issues:
- npmjs was built for the js ecosystem not for solidity
- github versioning of the releases is a pain and not all the projects are using it correctly

## Version 0.2.4
## Version 0.2.6

#### Breaking Changes introduced in 0.2.6

In 0.2.6 the `sdependencies` has been renamed to `dependencies`. Furthermore a dependency now stored in the toml respects Cargo toml format with `version` and `url` included.

### WARNING

Expand Down Expand Up @@ -50,13 +54,13 @@ Then you have to create a `soldeer.toml` file in the root of your project. The f
[remappings]
enabled = true

[sdependencies]
[dependencies]
```

The `remappings` option let's you enable or disable the remappings autocompletion. If you set it to `true` then the remappings will be automatically updated when you install a new dependency.
The `sdependencies` option is used to store the dependencies that you install via the `soldeer install <dependency>~<version>` command.
The `dependencies` option is used to store the dependencies that you install via the `soldeer install <dependency>~<version>` command.

If you want to use it with the foundry you can skip the creation of the `soldeer.toml` file and use the `foundry.toml` file instead. You just have to add the `sdependencies` option in the `foundry.toml` file and the remappings will be updated automatically.
If you want to use it with the foundry you can skip the creation of the `soldeer.toml` file and use the `foundry.toml` file instead. You just have to add the `dependencies` option in the `foundry.toml` file and the remappings will be updated automatically.

Example of foundry configuration:

Expand All @@ -67,14 +71,14 @@ bytecode_hash = "none"
cbor_metadata = false

.... other foundry config
[sdependencies]
[dependencies]
```

Even if the `[sdependencies]` is empty, this will tell to soldeer to use the `foundry.toml` file for the dependencies management.
Even if the `[dependencies]` is empty, this will tell to soldeer to use the `foundry.toml` file for the dependencies management.

#### WARNING

If you do not define a `soldeer.toml` with the `enabled` field or a `foundry.toml` with the `sdependencies` field, the remappings will not be updated and you will receive a warning.
If you do not define a `soldeer.toml` with the `enabled` field or a `foundry.toml` with the `dependencies` field, the remappings will not be updated and you will receive a warning.

### HOW TO INSTALL IT

Expand Down
462 changes: 0 additions & 462 deletions all_dependencies.toml

This file was deleted.

10 changes: 8 additions & 2 deletions soldeer.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Example of soldeer.toml
[remappings]
enabled = false
enabled = true

[sdependencies]
[dependencies]
"@openzeppelin-contracts~5.0.2" = { version = "5.0.2", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/5_0_2_14-03-2024_06:11:59_contracts.zip" }
"@openzeppelin-contracts~4.9.6" = { version = "4.9.6", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_6_14-03-2024_06:11:55_contracts.zip" }
"@openzeppelin-contracts~5.0.0-rc.1" = { version = "5.0.0-rc.1", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/5_0_0-rc_1_22-01-2024_13:13:58_contracts.zip" }
"@openzeppelin-contracts~5.0.0-rc.0" = { version = "5.0.0-rc.0", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/5_0_0-rc_0_22-01-2024_13:13:57_contracts.zip" }
"@openzeppelin-contracts~4.9.0-rc.1" = { version = "4.9.0-rc.1", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_0-rc_1_22-01-2024_13:13:49_contracts.zip" }
"@openzeppelin-contracts~4.8.0-rc.2" = { version = "4.8.0-rc.2", url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_8_0-rc_2_22-01-2024_13:13:39_contracts.zip" }
71 changes: 40 additions & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ use toml::{
use yansi::Paint;
extern crate toml_edit;
use std::io;
use toml_edit::Document;
use toml_edit::{
value,
Document,
Item,
};

// Top level struct to hold the TOML data.
#[derive(Deserialize, Debug)]
struct Data {
sdependencies: Table,
dependencies: Table,
}

// Dependency object used to store a dependency data
Expand All @@ -58,7 +62,6 @@ pub fn read_config(filename: String) -> Result<Vec<Dependency>, ConfigError> {
}
}
let contents = read_file_to_string(&filename.clone());

// Use a `match` block to return the
// file `contents` as a `Data struct: Ok(d)`
// or handle any `errors: Err(_)`.
Expand All @@ -67,20 +70,21 @@ pub fn read_config(filename: String) -> Result<Vec<Dependency>, ConfigError> {
// `d` is a local variable.
Ok(d) => d,
// Handle the `error` case.
Err(_) => {
Err(err) => {
println!("{:?}", err);
return Err(ConfigError {
cause: format!("Could not read the config file {}", filename),
});
}
};

let mut dependencies: Vec<Dependency> = Vec::new();
data.sdependencies.iter().for_each(|(k, v)| {
data.dependencies.iter().for_each(|(k, v)| {
let parts: Vec<&str> = k.split('~').collect::<Vec<&str>>();
dependencies.push(Dependency {
name: parts.first().unwrap().to_string(),
version: parts.get(1).unwrap().to_string(),
url: v.to_string().replace('\"', ""),
name: parts[0].to_string(),
version: v["version"].to_string().replace('"', ""),
url: v["url"].to_string().replace('\"', ""),
});
});

Expand Down Expand Up @@ -142,20 +146,20 @@ pub fn define_config_file() -> Result<String, ConfigError> {
.to_owned()
+ "/foundry.toml";

// check if the foundry.toml has the sdependencies defined, if so then we setup the foundry.toml as the config file
// check if the foundry.toml has the dependencies defined, if so then we setup the foundry.toml as the config file
if fs::metadata(&foundry_file).is_ok() {
let contents = read_file_to_string(&foundry_file.clone());
let doc: Document = contents.parse::<Document>().expect("invalid doc");

if doc.get("sdependencies").is_some() {
if doc.get("dependencies").is_some() {
filename = foundry_file;
}
}

let exists: bool = Path::new(&filename).exists();
if !exists {
eprintln!(
"The config file does not exist. Soldeer has exited. If you wish to proceed, below is the minimum requirement for the soldeer.toml file that needs to be created:\n \n [foundry]\n enabled = true\n foundry-config = false\n\n [sdependencies]\n"
"The config file does not exist. Soldeer has exited. If you wish to proceed, below is the minimum requirement for the soldeer.toml file that needs to be created:\n \n [foundry]\n enabled = true\n foundry-config = false\n\n [dependencies]\n"
);
exit(404);
}
Expand Down Expand Up @@ -205,11 +209,10 @@ pub fn add_to_config(
};
let contents = read_file_to_string(&filename.clone());
let mut doc: Document = contents.parse::<Document>().expect("invalid doc");

if doc.get("sdependencies").is_some()
&& doc["sdependencies"]
.get(format!("{}~{}", dependency_name, dependency_version))
.is_some()
let item = doc["dependencies"].get(dependency_name);
if doc.get("dependencies").is_some()
&& item.is_some()
&& item.unwrap()["version"].to_string().replace('"', "") == dependency_version
{
println!(
"{}",
Expand All @@ -221,10 +224,10 @@ pub fn add_to_config(
return Ok(());
}

// in case we don't have sdependencies defined in the config file, we add it and re-read the doc
if doc.get("sdependencies").is_none() {
// in case we don't have dependencies defined in the config file, we add it and re-read the doc
if doc.get("dependencies").is_none() {
let mut file: std::fs::File = fs::OpenOptions::new().append(true).open(&filename).unwrap();
if let Err(e) = write!(file, "{}", String::from("\n[sdependencies]\n")) {
if let Err(e) = write!(file, "{}", String::from("\n[dependencies]\n")) {
eprintln!("Couldn't write to file: {}", e);
}

Expand All @@ -234,10 +237,10 @@ pub fn add_to_config(
}
let mut new_dependencies: String = String::new(); //todo delete this

// in case we don't have sdependencies defined in the config file, we add it and re-read the doc
if doc.get("sdependencies").is_none() {
// in case we don't have dependencies defined in the config file, we add it and re-read the doc
if doc.get("dependencies").is_none() {
let mut file: std::fs::File = fs::OpenOptions::new().append(true).open(&filename).unwrap();
if let Err(e) = write!(file, "{}", String::from("\n[sdependencies]\n")) {
if let Err(e) = write!(file, "{}", String::from("\n[dependencies]\n")) {
eprintln!("Couldn't write to file: {}", e);
}

Expand All @@ -251,12 +254,18 @@ pub fn add_to_config(
dependency_name, dependency_version, dependency_url
));

doc["sdependencies"].as_table_mut().unwrap().insert(
format!("{}~{}", dependency_name, dependency_version)
.to_string()
.as_str(),
toml_edit::value(dependency_url),
let mut new_item: Item = Item::None;
new_item["version"] = value(dependency_version);
new_item["url"] = value(dependency_url);
let dependency_name = format!(
"{}~{}",
dependency_name.to_string().as_str(),
dependency_version.to_string().as_str()
);
doc["dependencies"]
.as_table_mut()
.unwrap()
.insert(dependency_name.as_str(), new_item);
let mut file: std::fs::File = fs::OpenOptions::new()
.write(true)
.append(false)
Expand Down Expand Up @@ -401,15 +410,15 @@ pub fn get_foundry_setup() -> Result<Vec<bool>, ConfigError> {
Err(_) => {
println!(
"{}",
Paint::yellow("The remappings field not found in the soldeer.toml and no foundry config file found or the foundry.toml does not contain the `[sdependencies]` field. \nThe foundry.toml file should contain the `[sdependencies]` field if you want to use it as a config file. If you want to use the soldeer.toml file, please add the `[remappings]` field to it with the `enabled` key set to `true` or `false`. \nMore info on https://github.com/mario-eth/soldeer\nThe installation was successful but the remappings feature was skipped.".to_string())
Paint::yellow("The remappings field not found in the soldeer.toml and no foundry config file found or the foundry.toml does not contain the `[dependencies]` field. \nThe foundry.toml file should contain the `[dependencies]` field if you want to use it as a config file. If you want to use the soldeer.toml file, please add the `[remappings]` field to it with the `enabled` key set to `true` or `false`. \nMore info on https://github.com/mario-eth/soldeer\nThe installation was successful but the remappings feature was skipped.".to_string())
);
return Ok(vec![false]);
}
};
if data.remappings.get("enabled").is_none() {
println!(
"{}",
Paint::yellow("The remappings field not found in the soldeer.toml and no foundry config file found or the foundry.toml does not contain the `[sdependencies]` field. \nThe foundry.toml file should contain the `[sdependencies]` field if you want to use it as a config file. If you want to use the soldeer.toml file, please add the `[remappings]` field to it with the `enabled` key set to `true` or `false`. \nMore info on https://github.com/mario-eth/soldeer\nThe installation was successful but the remappings feature was skipped.".to_string())
Paint::yellow("The remappings field not found in the soldeer.toml and no foundry config file found or the foundry.toml does not contain the `[dependencies]` field. \nThe foundry.toml file should contain the `[dependencies]` field if you want to use it as a config file. If you want to use the soldeer.toml file, please add the `[remappings]` field to it with the `enabled` key set to `true` or `false`. \nMore info on https://github.com/mario-eth/soldeer\nThe installation was successful but the remappings feature was skipped.".to_string())
);
return Ok(vec![false]);
}
Expand Down Expand Up @@ -446,7 +455,7 @@ src = "src"
test = "test"
libs = ["dependencies"]
[sdependencies]
[dependencies]
"#;
} else if option.trim() == "2" {
path = path.join("soldeer.toml");
Expand All @@ -455,7 +464,7 @@ libs = ["dependencies"]
[remappings]
enabled = true
[sdependencies]
[dependencies]
"#;
} else {
return Err(ConfigError {
Expand Down
2 changes: 1 addition & 1 deletion src/dependency_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn unzip_dependency(
return Err(UnzippingError {
name: dependency_name.to_string(),
version: dependency_version.to_string(),
})
});
}
}
println!(
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub async fn run(args: Args) -> Result<(), SoldeerError> {
});
}
}
// check the foundry setup, in case we have a foundry.toml, then the foundry.toml will be used for `sdependencies`
// check the foundry setup, in case we have a foundry.toml, then the foundry.toml will be used for `dependencies`
let f_setup_vec: Vec<bool> = match get_foundry_setup() {
Ok(setup) => setup,
Err(err) => return Err(SoldeerError { message: err.cause }),
Expand Down Expand Up @@ -245,7 +245,7 @@ pub async fn run(args: Args) -> Result<(), SoldeerError> {
Err(err) => {
return Err(SoldeerError {
message: format!("Error unzipping dependency {}~{}", err.name, err.version),
})
});
}
}

Expand Down Expand Up @@ -279,7 +279,7 @@ pub async fn run(args: Args) -> Result<(), SoldeerError> {
}
}

// check the foundry setup, in case we have a foundry.toml, then the foundry.toml will be used for `sdependencies`
// check the foundry setup, in case we have a foundry.toml, then the foundry.toml will be used for `dependencies`
let f_setup_vec: Vec<bool> = match get_foundry_setup() {
Ok(f_setup) => f_setup,
Err(err) => {
Expand Down Expand Up @@ -322,10 +322,10 @@ pub async fn run(args: Args) -> Result<(), SoldeerError> {
.unwrap()
.to_string(),
);
let regex = Regex::new(r"^[@|a-z][a-z0-9-]*[a-z]$").unwrap();
let regex = Regex::new(r"^[@|a-z0-9][a-z0-9-]*[a-z0-9]$").unwrap();

if !regex.is_match(&dependency_name) {
return Err(SoldeerError{message:"Dependency name {} is not valid, you can use only alphanumeric characters `-` and `@`".to_string()});
return Err(SoldeerError{message:format!("Dependency name {} is not valid, you can use only alphanumeric characters `-` and `@`", &dependency_name)});
}
match push_version(&dependency_name, &dependency_version, PathBuf::from(path)).await {
Ok(_) => {}
Expand Down
20 changes: 10 additions & 10 deletions src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Clone for LockEntry {
// Top level struct to hold the TOML data.
#[derive(Deserialize, Debug)]
struct LockType {
sdependencies: Vec<LockEntry>,
dependencies: Vec<LockEntry>,
}
fn read_lock() -> Result<Vec<LockEntry>, LockError> {
let lock_file: PathBuf = if cfg!(test) {
Expand Down Expand Up @@ -71,7 +71,7 @@ fn read_lock() -> Result<Vec<LockEntry>, LockError> {
return Ok(vec![]);
}
};
Ok(data.sdependencies)
Ok(data.dependencies)
}

pub fn lock_check(dependencies: &[Dependency]) -> Result<Vec<Dependency>, LockError> {
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn write_lock(dependencies: &[Dependency], clean: bool) -> Result<(), LockEr
let hash = sha256_digest(&dependency.name, &dependency.version);
new_lock_entries.push_str(&format!(
r#"
[[sdependencies]]
[[dependencies]]
name = "{}"
version = "{}"
source = "{}"
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn remove_lock(dependency_name: &str, dependency_version: &str) -> Result<()
if entry.name != dependency_name || entry.version != dependency_version {
new_lock_entries.push_str(&format!(
r#"
[[sdependencies]]
[[dependencies]]
name = "{}"
version = "{}"
source = "{}"
Expand Down Expand Up @@ -247,13 +247,13 @@ mod tests {
pub fn initialize() {
let lock_file = check_lock_file();
let lock_contents = r#"
[[sdependencies]]
[[dependencies]]
name = "@openzeppelin-contracts"
version = "2.3.0"
source = "registry+https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@openzeppelin-contracts~2.3.0.zip"
checksum = "a2d469062adeb62f7a4aada78237acae4ad3c168ba65c3ac9c76e290332c11ec"
[[sdependencies]]
[[dependencies]]
name = "@prb-test"
version = "0.6.5"
source = "registry+https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@prb-test~0.6.5.zip"
Expand Down Expand Up @@ -339,7 +339,7 @@ checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016"
assert_eq!(
contents,
r#"
[[sdependencies]]
[[dependencies]]
name = "@openzeppelin-contracts"
version = "2.5.0"
source = "https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@openzeppelin-contracts~2.5.0.zip"
Expand Down Expand Up @@ -367,19 +367,19 @@ checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016"
assert_eq!(
contents,
r#"
[[sdependencies]]
[[dependencies]]
name = "@openzeppelin-contracts"
version = "2.3.0"
source = "registry+https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@openzeppelin-contracts~2.3.0.zip"
checksum = "a2d469062adeb62f7a4aada78237acae4ad3c168ba65c3ac9c76e290332c11ec"
[[sdependencies]]
[[dependencies]]
name = "@prb-test"
version = "0.6.5"
source = "registry+https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@prb-test~0.6.5.zip"
checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016"
[[sdependencies]]
[[dependencies]]
name = "@openzeppelin-contracts-2"
version = "2.6.0"
source = "https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@openzeppelin-contracts~2.6.0.zip"
Expand Down

0 comments on commit cbecec7

Please sign in to comment.