mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(add/install): default to "latest" tag for npm packages in deno add npm:pkg
(#25858)
Fixes #25813. I initially tried doing this in `deno_semver`, where it's a cleaner change, but that caused breakage in deno in places where we don't expect a tag (see https://github.com/denoland/deno/issues/25857). This does not fix wildcard requirements failing to choose pre-release versions. That's a little more involved and I'll do a separate PR.
This commit is contained in:
parent
6c26c1ed96
commit
5c40b47629
6 changed files with 37 additions and 2 deletions
|
@ -5,6 +5,7 @@ mod cache_deps;
|
|||
pub use cache_deps::cache_top_level_deps;
|
||||
use deno_semver::jsr::JsrPackageReqReference;
|
||||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use deno_semver::VersionReq;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::path::PathBuf;
|
||||
|
@ -717,7 +718,18 @@ impl AddPackageReq {
|
|||
Prefix::Npm => {
|
||||
let req_ref =
|
||||
NpmPackageReqReference::from_str(&format!("npm:{}", entry_text))?;
|
||||
let package_req = req_ref.into_inner().req;
|
||||
let mut package_req = req_ref.into_inner().req;
|
||||
// deno_semver defaults to a version req of `*` if none is specified
|
||||
// we want to default to `latest` instead
|
||||
if package_req.version_req == *deno_semver::WILDCARD_VERSION_REQ
|
||||
&& package_req.version_req.version_text() == "*"
|
||||
&& !entry_text.contains("@*")
|
||||
{
|
||||
package_req.version_req = VersionReq::from_raw_text_and_inner(
|
||||
"latest".into(),
|
||||
deno_semver::RangeSetOrTag::Tag("latest".into()),
|
||||
);
|
||||
}
|
||||
Ok(Ok(AddPackageReq {
|
||||
alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()),
|
||||
value: AddPackageReqValue::Npm(package_req),
|
||||
|
@ -888,7 +900,9 @@ mod test {
|
|||
AddPackageReq::parse("@alias/pkg@npm:foo").unwrap().unwrap(),
|
||||
AddPackageReq {
|
||||
alias: "@alias/pkg".to_string(),
|
||||
value: AddPackageReqValue::Npm(PackageReq::from_str("foo").unwrap())
|
||||
value: AddPackageReqValue::Npm(
|
||||
PackageReq::from_str("foo@latest").unwrap()
|
||||
)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export function sayHello() {
|
||||
console.log("Hello")
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@denotest/unstable",
|
||||
"type": "module",
|
||||
"version": "1.0.0-beta.1"
|
||||
}
|
9
tests/specs/add/only_unstable_versions/__test__.jsonc
Normal file
9
tests/specs/add/only_unstable_versions/__test__.jsonc
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"steps": [
|
||||
{
|
||||
"args": "add npm:@denotest/unstable",
|
||||
"output": "add.out"
|
||||
}
|
||||
]
|
||||
}
|
3
tests/specs/add/only_unstable_versions/add.out
Normal file
3
tests/specs/add/only_unstable_versions/add.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
Add npm:@denotest/unstable@1.0.0-beta.1
|
||||
Download http://localhost:4260/@denotest/unstable
|
||||
Download http://localhost:4260/@denotest/unstable/1.0.0-beta.1.tgz
|
1
tests/specs/add/only_unstable_versions/deno.json
Normal file
1
tests/specs/add/only_unstable_versions/deno.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
Loading…
Reference in a new issue