diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-11-21 10:53:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 10:53:03 -0500 |
commit | a300b968b0720434e84ec9d11752e9323513c7c2 (patch) | |
tree | d6eb72adb8474a349e6769ff9c29402502346243 | |
parent | c0482e09c3362fa7ff00a5af04938595bbae4706 (diff) |
fix(npm): automatically find binary entrypoint when values are all the same (#16735)
-rw-r--r-- | cli/node/mod.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 1f3c493d2..68eb7b02b 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -591,7 +591,7 @@ fn resolve_bin_entry_value<'a>( Value::Object(o) => { if let Some(bin_name) = bin_name { o.get(bin_name) - } else if o.len() == 1 { + } else if o.len() == 1 || o.len() > 1 && o.values().all(|v| v == o.values().next().unwrap()) { o.values().next() } else { o.get(&pkg_req.name) @@ -1295,6 +1295,21 @@ mod tests { ) ); + // should resolve since all the values are the same + let value = json!({ + "bin1": "./value", + "bin2": "./value", + }); + assert_eq!( + resolve_bin_entry_value( + &NpmPackageReq::from_str("test").unwrap(), + None, + &value + ) + .unwrap(), + "./value" + ); + // should not resolve when specified and is a string let value = json!("./value"); assert_eq!( |