diff --git a/src/package_json.rs b/src/package_json.rs index 73901faa..7e05d202 100644 --- a/src/package_json.rs +++ b/src/package_json.rs @@ -24,6 +24,16 @@ pub struct PackageJson { /// pub name: Option, + /// The "type" field. + /// + /// + pub r#type: Option, + + /// The "sideEffects" field. + /// + /// + pub side_effects: Option, + raw_json: std::sync::Arc, } @@ -51,9 +61,11 @@ impl PackageJson { json_object.remove("optionalDependencies"); } - // Add name. + // Add name, type and sideEffects. package_json.name = json_object.get("name").and_then(|field| field.as_str()).map(ToString::to_string); + package_json.r#type = json_object.get("type").cloned(); + package_json.side_effects = json_object.get("sideEffects").cloned(); } package_json.path = path; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index d369413f..0fc52887 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -35,9 +35,10 @@ fn eq() { #[test] fn package_json() { let resolution = resolve("./tests/package.json"); - assert!(resolution - .package_json() - .is_some_and(|json| json.name.as_ref().is_some_and(|name| name == "name"))); + let package_json = resolution.package_json().unwrap(); + assert_eq!(package_json.name.as_ref().unwrap(), "name"); + assert_eq!(package_json.r#type.as_ref().unwrap().as_str(), "module".into()); + assert!(package_json.side_effects.as_ref().unwrap().is_object()); } #[cfg(feature = "package_json_raw_json_api")] diff --git a/tests/package.json b/tests/package.json index f099adcf..54f58b8c 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,3 +1,5 @@ { - "name": "name" + "name": "name", + "type": "module", + "sideEffects": {} }