diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-10-14 15:35:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 19:35:52 +0000 |
commit | c5449d71da2d623e866d733b6db180a6f94ff7c6 (patch) | |
tree | 91f27329054b33b7524618cb57a484faa74ba82e /cli/tools | |
parent | f3530c858f873b0f4561a52fa92ddd1d099612b3 (diff) |
fix(install): support installing npm package with alias (#26246)
Just tried this out today and it wasn't properly implemented in
https://github.com/denoland/deno/pull/24156
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/registry/pm.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 5dc042620..3276acfbf 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -363,7 +363,14 @@ fn package_json_dependency_entry( selected: SelectedPackage, ) -> (String, String) { if let Some(npm_package) = selected.package_name.strip_prefix("npm:") { - (npm_package.into(), selected.version_req) + if selected.import_name == npm_package { + (npm_package.into(), selected.version_req) + } else { + ( + selected.import_name, + format!("npm:{}@{}", npm_package, selected.version_req), + ) + } } else if let Some(jsr_package) = selected.package_name.strip_prefix("jsr:") { let jsr_package = jsr_package.strip_prefix('@').unwrap_or(jsr_package); let scope_replaced = jsr_package.replace('/', "__"); @@ -741,6 +748,9 @@ fn generate_imports(mut packages_to_version: Vec<(String, String)>) -> String { let mut contents = vec![]; let len = packages_to_version.len(); for (index, (package, version)) in packages_to_version.iter().enumerate() { + if index == 0 { + contents.push(String::new()); // force a newline at the start + } // TODO(bartlomieju): fix it, once we start support specifying version on the cli contents.push(format!("\"{}\": \"{}\"", package, version)); if index != len - 1 { |