From 5b097fd7e5224db6de65847a604f5c60a93667a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 3 Oct 2022 19:10:53 +0200 Subject: fix(npm): better error is version is specified after subpath (#16131) --- cli/npm/resolution.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cli/npm') diff --git a/cli/npm/resolution.rs b/cli/npm/resolution.rs index d56cc87bc..497f40906 100644 --- a/cli/npm/resolution.rs +++ b/cli/npm/resolution.rs @@ -77,6 +77,18 @@ impl NpmPackageReference { } else { Some(parts[name_part_len..].join("/")) }; + + if let Some(sub_path) = &sub_path { + if let Some(at_index) = sub_path.rfind('@') { + let (new_sub_path, version) = sub_path.split_at(at_index); + let msg = format!( + "Invalid package specifier 'npm:{}/{}'. Did you mean to write 'npm:{}{}/{}'?", + name, sub_path, name, version, new_sub_path + ); + return Err(generic_error(msg)); + } + } + Ok(NpmPackageReference { req: NpmPackageReq { name, version_req }, sub_path, -- cgit v1.2.3