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

feat(add): strip package subpath when adding a package (#25419)

These now works:
```
$ deno add @std/dotenv/load
$ deno add npm:preact/hooks
```
Previously we were erroring out, because this is a "package reference"
including
a subpath.

Closes https://github.com/denoland/deno/issues/25385

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
Bartek Iwańczuk 2024-09-04 13:55:30 +01:00 committed by GitHub
parent 74fc66da11
commit c58a628e2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 2 deletions

View file

@ -3,6 +3,8 @@
mod cache_deps; mod cache_deps;
pub use cache_deps::cache_top_level_deps; pub use cache_deps::cache_top_level_deps;
use deno_semver::jsr::JsrPackageReqReference;
use deno_semver::npm::NpmPackageReqReference;
use std::borrow::Cow; use std::borrow::Cow;
use std::path::Path; use std::path::Path;
@ -501,14 +503,18 @@ impl AddPackageReq {
match prefix { match prefix {
Prefix::Jsr => { Prefix::Jsr => {
let package_req = PackageReq::from_str(entry_text)?; let req_ref =
JsrPackageReqReference::from_str(&format!("jsr:{}", entry_text))?;
let package_req = req_ref.into_inner().req;
Ok(AddPackageReq { Ok(AddPackageReq {
alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()), alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()),
value: AddPackageReqValue::Jsr(package_req), value: AddPackageReqValue::Jsr(package_req),
}) })
} }
Prefix::Npm => { Prefix::Npm => {
let package_req = PackageReq::from_str(entry_text)?; let req_ref =
NpmPackageReqReference::from_str(&format!("npm:{}", entry_text))?;
let package_req = req_ref.into_inner().req;
Ok(AddPackageReq { Ok(AddPackageReq {
alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()), alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()),
value: AddPackageReqValue::Npm(package_req), value: AddPackageReqValue::Npm(package_req),

View file

@ -0,0 +1,19 @@
{
"tempDir": true,
"steps": [
{
"args": "add @std/testing/bdd npm:preact/hooks",
"output": "add.out"
},
{
"args": "add @std/testing/bdd@1 npm:preact/hooks@10",
"output": "wrong_constraint_jsr.out",
"exitCode": 1
},
{
"args": "add npm:preact/hooks@10",
"output": "wrong_constraint_npm.out",
"exitCode": 1
}
]
}

View file

@ -0,0 +1,8 @@
[UNORDERED_START]
Add jsr:@std/testing@1.0.0
Add npm:preact@10.19.6
Download http://127.0.0.1:4250/@std/testing/1.0.0/bdd.ts
Download http://127.0.0.1:4250/@std/testing/1.0.0/types.ts
Download http://localhost:4260/preact
Download http://localhost:4260/preact/preact-10.19.6.tgz
[UNORDERED_END]

View file

@ -0,0 +1,4 @@
error: Failed to parse package required: @std/testing/bdd@1
Caused by:
Invalid package specifier 'jsr:@std/testing/bdd@1'. Did you mean to write 'jsr:@std/testing@1/bdd'?

View file

@ -0,0 +1,4 @@
error: Failed to parse package required: npm:preact/hooks@10
Caused by:
Invalid package specifier 'npm:preact/hooks@10'. Did you mean to write 'npm:preact@10/hooks'?