feat(package): ignore private JS packages (#975)
`private: true` in `package.json` files means that the package is not supposed to be published to npm, which makes the `version` field meaningless, so we should probably ignore it to not clutter the prompt too much.
This commit is contained in:
parent
0674007bfe
commit
d0e1904758
|
@ -41,6 +41,11 @@ fn extract_cargo_version(file_contents: &str) -> Option<String> {
|
|||
|
||||
fn extract_package_version(file_contents: &str) -> Option<String> {
|
||||
let package_json: json::Value = json::from_str(file_contents).ok()?;
|
||||
|
||||
if package_json.get("private").and_then(json::Value::as_bool) == Some(true) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let raw_version = package_json.get("version")?.as_str()?;
|
||||
if raw_version == "null" {
|
||||
return None;
|
||||
|
@ -163,7 +168,10 @@ mod tests {
|
|||
extract_package_version(&package_with_version),
|
||||
expected_version
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_package_version_without_version() {
|
||||
let package_without_version = json::json!({
|
||||
"name": "spacefish"
|
||||
})
|
||||
|
@ -176,6 +184,49 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_package_version_with_null_version() {
|
||||
let package_with_null_version = json::json!({
|
||||
"name": "spacefish",
|
||||
"version": null
|
||||
})
|
||||
.to_string();
|
||||
|
||||
let expected_version = None;
|
||||
assert_eq!(
|
||||
extract_package_version(&package_with_null_version),
|
||||
expected_version
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_package_version_with_null_string_version() {
|
||||
let package_with_null_string_version = json::json!({
|
||||
"name": "spacefish",
|
||||
"version": "null"
|
||||
})
|
||||
.to_string();
|
||||
|
||||
let expected_version = None;
|
||||
assert_eq!(
|
||||
extract_package_version(&package_with_null_string_version),
|
||||
expected_version
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_private_package_version() {
|
||||
let private_package = json::json!({
|
||||
"name": "spacefish",
|
||||
"version": "0.1.0",
|
||||
"private": true
|
||||
})
|
||||
.to_string();
|
||||
|
||||
let expected_version = None;
|
||||
assert_eq!(extract_package_version(&private_package), expected_version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_poetry_version() {
|
||||
let poetry_with_version = toml::toml! {
|
||||
|
|
Loading…
Reference in New Issue