From d00c0fe44d0e73edb892fcffcf431fb0097a9348 Mon Sep 17 00:00:00 2001 From: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Date: Mon, 3 Mar 2025 14:17:45 -0800 Subject: [PATCH] feat: Support categories and keywords in forc manifest (#6974) ## Description Related https://github.com/FuelLabs/forc.pub/issues/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. --- docs/book/src/forc/manifest_reference.md | 6 ++++++ forc-pkg/src/manifest/mod.rs | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/book/src/forc/manifest_reference.md b/docs/book/src/forc/manifest_reference.md index ecedae6c8f5..288f90f3289 100644 --- a/docs/book/src/forc/manifest_reference.md +++ b/docs/book/src/forc/manifest_reference.md @@ -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._ @@ -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: @@ -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" } diff --git a/forc-pkg/src/manifest/mod.rs b/forc-pkg/src/manifest/mod.rs index ef1bdee79c2..8ad18e8acae 100644 --- a/forc-pkg/src/manifest/mod.rs +++ b/forc-pkg/src/manifest/mod.rs @@ -204,6 +204,8 @@ pub struct Project { pub homepage: Option, pub repository: Option, pub documentation: Option, + pub categories: Option>, + pub keywords: Option>, #[serde(default = "default_entry")] pub entry: String, pub implicit_std: Option, @@ -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(), @@ -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(), @@ -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] @@ -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(); @@ -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]