1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

fix(npm): automatically find binary entrypoint when values are all the same (#16735)

This commit is contained in:
David Sherret 2022-11-21 10:53:03 -05:00 committed by GitHub
parent c0482e09c3
commit a300b968b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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!(