Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(add/install): default to "latest" tag for npm packages in deno add npm:pkg #25858

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cli/tools/registry/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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!(
Expand Down
3 changes: 3 additions & 0 deletions tests/registry/npm/@denotest/unstable/1.0.0-beta.1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sayHello() {
console.log("Hello")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@denotest/unstable",
"type": "module",
"version": "1.0.0-beta.1"
}
9 changes: 9 additions & 0 deletions tests/specs/add/only_unstable_versions/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tempDir": true,
"steps": [
{
"args": "add npm:@denotest/unstable",
"output": "add.out"
}
]
}
3 changes: 3 additions & 0 deletions tests/specs/add/only_unstable_versions/add.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add npm:@denotest/[email protected]
Download http://localhost:4260/@denotest/unstable
Download http://localhost:4260/@denotest/unstable/1.0.0-beta.1.tgz
1 change: 1 addition & 0 deletions tests/specs/add/only_unstable_versions/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}