From a300b968b0720434e84ec9d11752e9323513c7c2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 21 Nov 2022 10:53:03 -0500 Subject: fix(npm): automatically find binary entrypoint when values are all the same (#16735) --- cli/node/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'cli/node/mod.rs') 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!( -- cgit v1.2.3