mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(node/package_json): Avoid panic when "exports" field is null (#20588)
Fixes #20558 Implementation: when package.json `exports` field is `null`, treat it as if it was not set
This commit is contained in:
parent
65a94a6176
commit
15cfb67551
1 changed files with 20 additions and 4 deletions
|
@ -114,14 +114,14 @@ impl PackageJson {
|
||||||
let version_val = package_json.get("version");
|
let version_val = package_json.get("version");
|
||||||
let type_val = package_json.get("type");
|
let type_val = package_json.get("type");
|
||||||
let bin = package_json.get("bin").map(ToOwned::to_owned);
|
let bin = package_json.get("bin").map(ToOwned::to_owned);
|
||||||
let exports = package_json.get("exports").map(|exports| {
|
let exports = package_json.get("exports").and_then(|exports| {
|
||||||
if is_conditional_exports_main_sugar(exports) {
|
Some(if is_conditional_exports_main_sugar(exports) {
|
||||||
let mut map = Map::new();
|
let mut map = Map::new();
|
||||||
map.insert(".".to_string(), exports.to_owned());
|
map.insert(".".to_string(), exports.to_owned());
|
||||||
map
|
map
|
||||||
} else {
|
} else {
|
||||||
exports.as_object().unwrap().to_owned()
|
exports.as_object()?.to_owned()
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let imports = imports_val
|
let imports = imports_val
|
||||||
|
@ -240,3 +240,19 @@ fn is_conditional_exports_main_sugar(exports: &Value) -> bool {
|
||||||
|
|
||||||
is_conditional_sugar
|
is_conditional_sugar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn null_exports_should_not_crash() {
|
||||||
|
let package_json = PackageJson::load_from_string(
|
||||||
|
PathBuf::from("/package.json"),
|
||||||
|
r#"{ "exports": null }"#.to_string(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(package_json.exports.is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue