1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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
This commit is contained in:
David Sherret 2024-10-14 15:35:52 -04:00 committed by GitHub
parent f3530c858f
commit c5449d71da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 48 additions and 6 deletions

View file

@ -363,7 +363,14 @@ fn package_json_dependency_entry(
selected: SelectedPackage, selected: SelectedPackage,
) -> (String, String) { ) -> (String, String) {
if let Some(npm_package) = selected.package_name.strip_prefix("npm:") { 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:") { } else if let Some(jsr_package) = selected.package_name.strip_prefix("jsr:") {
let jsr_package = jsr_package.strip_prefix('@').unwrap_or(jsr_package); let jsr_package = jsr_package.strip_prefix('@').unwrap_or(jsr_package);
let scope_replaced = jsr_package.replace('/', "__"); 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 mut contents = vec![];
let len = packages_to_version.len(); let len = packages_to_version.len();
for (index, (package, version)) in packages_to_version.iter().enumerate() { 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 // TODO(bartlomieju): fix it, once we start support specifying version on the cli
contents.push(format!("\"{}\": \"{}\"", package, version)); contents.push(format!("\"{}\": \"{}\"", package, version));
if index != len - 1 { if index != len - 1 {

View file

@ -0,0 +1,13 @@
{
"tempDir": true,
"steps": [{
"args": "install my-alias@npm:@denotest/add",
"output": "[WILDCARD]"
}, {
"args": [
"eval",
"console.log(Deno.readTextFileSync('package.json').trim())"
],
"output": "package.json.out"
}]
}

View file

@ -0,0 +1,4 @@
{
"dependencies": {
}
}

View file

@ -0,0 +1,5 @@
{
"dependencies": {
"my-alias": "npm:@denotest/add@^1.0.0"
}
}

View file

@ -1,3 +1,5 @@
{ {
"devDependencies": { "@denotest/esm-basic": "^1.0.0" } "devDependencies": {
"@denotest/esm-basic": "^1.0.0"
}
} }

View file

@ -1,3 +1,5 @@
{ {
"dependencies": { "@denotest/esm-basic": "^1.0.0" } "dependencies": {
"@denotest/esm-basic": "^1.0.0"
}
} }

View file

@ -1,3 +1,5 @@
{ {
"devDependencies": { "@denotest/esm-basic": "^1.0.0" } "devDependencies": {
"@denotest/esm-basic": "^1.0.0"
}
} }

View file

@ -1,3 +1,5 @@
{ {
"dependencies": { "@denotest/deprecated-package": "^1.0.0" } "dependencies": {
"@denotest/deprecated-package": "^1.0.0"
}
} }

View file

@ -1,3 +1,5 @@
{ {
"devDependencies": { "@denotest/esm-basic": "^1.0.0" } "devDependencies": {
"@denotest/esm-basic": "^1.0.0"
}
} }