Skip to content

Commit

Permalink
feat: Support categories and keywords in forc manifest (#6974)
Browse files Browse the repository at this point in the history
## Description

Related FuelLabs/forc.pub#30

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
  • Loading branch information
sdankel authored Mar 3, 2025
1 parent d7f9b62 commit d00c0fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/book/src/forc/manifest_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The `Forc.toml` (the _manifest_ file) is a compulsory file for each package and
* `homepage` — URL of the project homepage.
* `repository` — URL of the project source repository.
* `documentation` — URL of the project documentation.
* `categories` — Categories of the project.
* `keywords` — Keywords the project.
* `entry` — The entry point for the compiler to start parsing from.
* For the recommended way of selecting an entry point of large libraries please take a look at: [Libraries](./../sway-program-types/libraries.md)
* `implicit-std` - Controls whether provided `std` version (with the current `forc` version) will get added as a dependency _implicitly_. _Unless you know what you are doing, leave this as default._
Expand Down Expand Up @@ -39,6 +41,8 @@ An example `Forc.toml` is shown below. Under `[project]` the following fields ar
* `homepage`
* `repository`
* `documentation`
* `categories`
* `keywords`

Also for the following fields, a default value is provided so omitting them is allowed:

Expand All @@ -57,6 +61,8 @@ documentation = "https://example.com/"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"
categories = ["example"]
keywords = ["example"]

[project.metadata]
indexing = { namespace = "counter-contract", schema_path = "out/release/counter-contract-abi.json" }
Expand Down
16 changes: 10 additions & 6 deletions forc-pkg/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ pub struct Project {
pub homepage: Option<Url>,
pub repository: Option<Url>,
pub documentation: Option<Url>,
pub categories: Option<Vec<String>>,
pub keywords: Option<Vec<String>>,
#[serde(default = "default_entry")]
pub entry: String,
pub implicit_std: Option<bool>,
Expand Down Expand Up @@ -1399,6 +1401,8 @@ mod tests {
description: Some("test description".to_string()),
homepage: None,
documentation: None,
categories: None,
keywords: None,
repository: None,
organization: None,
license: "Apache-2.0".to_string(),
Expand All @@ -1425,6 +1429,8 @@ mod tests {
description: Some("test description".to_string()),
homepage: Some(Url::parse("https://example.com").unwrap()),
documentation: Some(Url::parse("https://docs.example.com").unwrap()),
categories: Some(vec!["test-category".to_string()]),
keywords: Some(vec!["test-keyword".to_string()]),
repository: Some(Url::parse("https://example.com").unwrap()),
organization: None,
license: "Apache-2.0".to_string(),
Expand All @@ -1446,6 +1452,8 @@ mod tests {
assert_eq!(project.repository, deserialized.repository);
assert_eq!(project.metadata, deserialized.metadata);
assert_eq!(project.metadata, None);
assert_eq!(project.categories, deserialized.categories);
assert_eq!(project.keywords, deserialized.keywords);
}

#[test]
Expand All @@ -1457,11 +1465,11 @@ mod tests {
authors = ["Test Author"]
description = "A test project"
version = "1.0.0"
keywords = ["test", "project"]
categories = ["test"]
[metadata]
mykey = "https://example.com"
keywords = ["test", "project"]
categories = ["test"]
"#;

let project: Project = toml::from_str(toml_str).unwrap();
Expand All @@ -1474,10 +1482,6 @@ mod tests {
table.get("mykey").unwrap().as_str().unwrap(),
"https://example.com"
);

let keywords = table.get("keywords").unwrap().as_array().unwrap();
assert_eq!(keywords[0].as_str().unwrap(), "test");
assert_eq!(keywords[1].as_str().unwrap(), "project");
}

#[test]
Expand Down

0 comments on commit d00c0fe

Please sign in to comment.