summaryrefslogtreecommitdiff
path: root/cli/npm/cache.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-10-21 11:20:18 -0400
committerGitHub <noreply@github.com>2022-10-21 15:20:18 +0000
commitbcfe279fba865763c87f9cd8d5a2d0b2cbf451be (patch)
tree68e4d1bc52e261df50279f9ecea14795d1c46f6c /cli/npm/cache.rs
parent0e1a71fec6fff5fe62d7e6b2bfffb7ab877d7b71 (diff)
feat(unstable/npm): initial type checking of npm specifiers (#16332)
Diffstat (limited to 'cli/npm/cache.rs')
-rw-r--r--cli/npm/cache.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs
index 77ecf1228..6a0d72b3a 100644
--- a/cli/npm/cache.rs
+++ b/cli/npm/cache.rs
@@ -160,13 +160,14 @@ impl ReadonlyNpmCache {
.take(if is_scoped_package { 3 } else { 2 })
.map(|(_, part)| part)
.collect::<Vec<_>>();
+ if parts.len() < 2 {
+ return None;
+ }
let version = parts.pop().unwrap();
let name = parts.join("/");
-
- Some(NpmPackageId {
- name,
- version: NpmVersion::parse(version).unwrap(),
- })
+ NpmVersion::parse(version)
+ .ok()
+ .map(|version| NpmPackageId { name, version })
}
pub fn get_cache_location(&self) -> PathBuf {