mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
feat: start caching npm package version's "bin" entry from npm registry (#17881)
This commit is contained in:
parent
b56b8c8a75
commit
9b8992d4b4
1 changed files with 65 additions and 2 deletions
|
@ -89,17 +89,25 @@ impl Ord for NpmDependencyEntry {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct NpmPeerDependencyMeta {
|
||||
#[serde(default)]
|
||||
optional: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum NpmPackageVersionBinEntry {
|
||||
String(String),
|
||||
Map(HashMap<String, String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NpmPackageVersionInfo {
|
||||
pub version: String,
|
||||
pub dist: NpmPackageVersionDistInfo,
|
||||
pub bin: Option<NpmPackageVersionBinEntry>,
|
||||
// Bare specifier to version (ex. `"typescript": "^3.0.1") or possibly
|
||||
// package and version (ex. `"typescript-3.0.1": "npm:typescript@3.0.1"`).
|
||||
#[serde(default)]
|
||||
|
@ -639,3 +647,58 @@ impl NpmRegistryApiInner for TestNpmRegistryApiInner {
|
|||
NpmRegistryApi::default_url()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use deno_core::serde_json;
|
||||
|
||||
use crate::npm::registry::NpmPackageVersionBinEntry;
|
||||
use crate::npm::NpmPackageVersionDistInfo;
|
||||
|
||||
use super::NpmPackageVersionInfo;
|
||||
|
||||
#[test]
|
||||
fn deserializes_minimal_pkg_info() {
|
||||
let text = r#"{ "version": "1.0.0", "dist": { "tarball": "value", "shasum": "test" } }"#;
|
||||
let info: NpmPackageVersionInfo = serde_json::from_str(text).unwrap();
|
||||
assert_eq!(
|
||||
info,
|
||||
NpmPackageVersionInfo {
|
||||
version: "1.0.0".to_string(),
|
||||
dist: NpmPackageVersionDistInfo {
|
||||
tarball: "value".to_string(),
|
||||
shasum: "test".to_string(),
|
||||
integrity: None,
|
||||
},
|
||||
bin: None,
|
||||
dependencies: Default::default(),
|
||||
peer_dependencies: Default::default(),
|
||||
peer_dependencies_meta: Default::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserializes_bin_entry() {
|
||||
// string
|
||||
let text = r#"{ "version": "1.0.0", "bin": "bin-value", "dist": { "tarball": "value", "shasum": "test" } }"#;
|
||||
let info: NpmPackageVersionInfo = serde_json::from_str(text).unwrap();
|
||||
assert_eq!(
|
||||
info.bin,
|
||||
Some(NpmPackageVersionBinEntry::String("bin-value".to_string()))
|
||||
);
|
||||
|
||||
// map
|
||||
let text = r#"{ "version": "1.0.0", "bin": { "a": "a-value", "b": "b-value" }, "dist": { "tarball": "value", "shasum": "test" } }"#;
|
||||
let info: NpmPackageVersionInfo = serde_json::from_str(text).unwrap();
|
||||
assert_eq!(
|
||||
info.bin,
|
||||
Some(NpmPackageVersionBinEntry::Map(HashMap::from([
|
||||
("a".to_string(), "a-value".to_string()),
|
||||
("b".to_string(), "b-value".to_string()),
|
||||
])))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue