mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -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:
parent
f3530c858f
commit
c5449d71da
9 changed files with 48 additions and 6 deletions
|
@ -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 {
|
||||
|
|
13
tests/specs/add/alias/__test__.jsonc
Normal file
13
tests/specs/add/alias/__test__.jsonc
Normal 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"
|
||||
}]
|
||||
}
|
4
tests/specs/add/alias/package.json
Normal file
4
tests/specs/add/alias/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
5
tests/specs/add/alias/package.json.out
Normal file
5
tests/specs/add/alias/package.json.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"my-alias": "npm:@denotest/add@^1.0.0"
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"devDependencies": { "@denotest/esm-basic": "^1.0.0" }
|
||||
"devDependencies": {
|
||||
"@denotest/esm-basic": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"dependencies": { "@denotest/esm-basic": "^1.0.0" }
|
||||
"dependencies": {
|
||||
"@denotest/esm-basic": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"devDependencies": { "@denotest/esm-basic": "^1.0.0" }
|
||||
"devDependencies": {
|
||||
"@denotest/esm-basic": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"dependencies": { "@denotest/deprecated-package": "^1.0.0" }
|
||||
"dependencies": {
|
||||
"@denotest/deprecated-package": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"devDependencies": { "@denotest/esm-basic": "^1.0.0" }
|
||||
"devDependencies": {
|
||||
"@denotest/esm-basic": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue