diff --git a/src/package_json.rs b/src/package_json.rs index de5a396..774c458 100644 --- a/src/package_json.rs +++ b/src/package_json.rs @@ -66,8 +66,8 @@ pub struct PackageJson { #[builder(default, setter(into, strip_option))] pub version: Option, - /// Version must be parseable by node-semver, which is bundled with npm as a - /// dependency. + /// Put a description in it. It's a string. + /// This helps people discover your package, as it's listed in npm search. #[serde(default, skip_serializing_if = "Option::is_none")] #[builder(default, setter(into, strip_option))] pub description: Option, @@ -165,7 +165,7 @@ pub struct PackageJson { skip_serializing_if = "Option::is_none" )] #[builder(default, setter(into, strip_option))] - pub types_versions: Option>, + pub types_versions: Option>, /// Specify either a single file or an array of filenames to put in place for /// the man program to find. @@ -395,6 +395,20 @@ pub enum Repository { }, } +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum TypesVersion { + Path(String), + PathMapping(IndexMap), +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum TypesVersionPaths { + Path(String), + PathList(Vec), +} + #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] pub enum Workspaces { diff --git a/tests/fixtures/5/package.json b/tests/fixtures/5/package.json new file mode 100644 index 0000000..787364f --- /dev/null +++ b/tests/fixtures/5/package.json @@ -0,0 +1,13 @@ +{ + "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "one": [ + "dist/one/index.d.ts" + ], + "two": [ + "dist/two/index.d.ts" + ] + } + } +} diff --git a/tests/package_json.rs b/tests/package_json.rs index 7166622..e3ca377 100644 --- a/tests/package_json.rs +++ b/tests/package_json.rs @@ -46,6 +46,28 @@ fn parse_package_json_file_with_dependencies() { "###); } +#[test] +fn parse_packages_json_file_with_typescript_fields() { + let contents = read_to_string("./tests/fixtures/5/package.json").unwrap(); + let package_json = PackageJson::try_from(contents).unwrap(); + + insta::assert_json_snapshot!(package_json, @r###" + { + "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "one": [ + "dist/one/index.d.ts" + ], + "two": [ + "dist/two/index.d.ts" + ] + } + } + } + "###); +} + #[test] fn create_package_json_file_with_builder_pattern() { let mut additional_fields: AdditionalFields = IndexMap::new();