@@ -9,14 +9,14 @@ use anyhow::{Context, Result};
99use semver:: VersionReq ;
1010use serde:: { Deserialize , Serialize } ;
1111use tokio:: io:: AsyncWriteExt ;
12- use wasm_metadata:: { Link , LinkType , RegistryMetadata } ;
1312
1413/// The default name of the configuration file.
1514pub const CONFIG_FILE_NAME : & str = "wkg.toml" ;
1615
1716/// The structure for a wkg.toml configuration file. This file is entirely optional and is used for
1817/// overriding and annotating wasm packages.
1918#[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq , Eq ) ]
19+ #[ serde( deny_unknown_fields) ]
2020pub struct Config {
2121 /// Overrides for various packages
2222 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
@@ -60,6 +60,7 @@ impl Config {
6060}
6161
6262#[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq , Eq ) ]
63+ #[ serde( deny_unknown_fields) ]
6364pub struct Override {
6465 /// A path to the package on disk. If this is set, the package will be loaded from the given
6566 /// path. If this is not set, the package will be loaded from the registry.
@@ -72,59 +73,26 @@ pub struct Override {
7273}
7374
7475#[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq , Eq ) ]
76+ #[ serde( deny_unknown_fields) ]
7577pub struct Metadata {
76- /// The authors of the package.
78+ /// The author(s) of the package.
7779 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
78- pub authors : Option < Vec < String > > ,
79- /// The categories of the package.
80- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
81- pub categories : Option < Vec < String > > ,
80+ pub author : Option < String > ,
8281 /// The package description.
8382 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
8483 pub description : Option < String > ,
8584 /// The package license.
86- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
87- pub license : Option < String > ,
88- /// The package documentation URL.
89- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
90- pub documentation : Option < String > ,
85+ #[ serde( default , skip_serializing_if = "Option::is_none" , alias = "license" ) ]
86+ pub licenses : Option < String > ,
87+ /// The package source code URL.
88+ #[ serde( default , skip_serializing_if = "Option::is_none" , alias = "repository" ) ]
89+ pub source : Option < String > ,
9190 /// The package homepage URL.
9291 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
9392 pub homepage : Option < String > ,
94- /// The package repository URL .
93+ /// The package source control revision .
9594 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
96- pub repository : Option < String > ,
97- }
98-
99- impl From < Metadata > for wasm_metadata:: RegistryMetadata {
100- fn from ( value : Metadata ) -> Self {
101- let mut meta = RegistryMetadata :: default ( ) ;
102- meta. set_authors ( value. authors ) ;
103- meta. set_categories ( value. categories ) ;
104- meta. set_description ( value. description ) ;
105- meta. set_license ( value. license ) ;
106- let mut links = Vec :: new ( ) ;
107- if let Some ( documentation) = value. documentation {
108- links. push ( Link {
109- ty : LinkType :: Documentation ,
110- value : documentation,
111- } ) ;
112- }
113- if let Some ( homepage) = value. homepage {
114- links. push ( Link {
115- ty : LinkType :: Homepage ,
116- value : homepage,
117- } ) ;
118- }
119- if let Some ( repository) = value. repository {
120- links. push ( Link {
121- ty : LinkType :: Repository ,
122- value : repository,
123- } ) ;
124- }
125- meta. set_links ( ( !links. is_empty ( ) ) . then_some ( links) ) ;
126- meta
127- }
95+ pub revision : Option < String > ,
12896}
12997
13098#[ cfg( test) ]
@@ -144,13 +112,12 @@ mod tests {
144112 } ,
145113 ) ] ) ) ,
146114 metadata : Some ( Metadata {
147- authors : Some ( vec ! [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
148- categories : Some ( vec ! [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
149- description : Some ( "foo" . to_string ( ) ) ,
150- license : Some ( "foo" . to_string ( ) ) ,
151- documentation : Some ( "foo" . to_string ( ) ) ,
152- homepage : Some ( "foo" . to_string ( ) ) ,
153- repository : Some ( "foo" . to_string ( ) ) ,
115+ author : Some ( "Foo Bar" . to_string ( ) ) ,
116+ description : Some ( "Foobar baz" . to_string ( ) ) ,
117+ licenses : Some ( "FBB" . to_string ( ) ) ,
118+ source : Some ( "https://gitfoo/bar" . to_string ( ) ) ,
119+ homepage : Some ( "https://foo.bar" . to_string ( ) ) ,
120+ revision : Some ( "f00ba4" . to_string ( ) ) ,
154121 } ) ,
155122 } ;
156123
0 commit comments