From 74157190961dda2b455b0f7fade7f88eddbe57de Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 15:39:03 -0700 Subject: [PATCH 1/6] Add failing test --- .../npm/@denotest/unstable/1.0.0-beta.1/index.js | 3 +++ .../npm/@denotest/unstable/1.0.0-beta.1/package.json | 5 +++++ tests/specs/add/only_unstable_versions/__test__.jsonc | 9 +++++++++ tests/specs/add/only_unstable_versions/add.out | 3 +++ tests/specs/add/only_unstable_versions/deno.json | 1 + 5 files changed, 21 insertions(+) create mode 100644 tests/registry/npm/@denotest/unstable/1.0.0-beta.1/index.js create mode 100644 tests/registry/npm/@denotest/unstable/1.0.0-beta.1/package.json create mode 100644 tests/specs/add/only_unstable_versions/__test__.jsonc create mode 100644 tests/specs/add/only_unstable_versions/add.out create mode 100644 tests/specs/add/only_unstable_versions/deno.json diff --git a/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/index.js b/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/index.js new file mode 100644 index 00000000000000..ba330abd564dbc --- /dev/null +++ b/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/index.js @@ -0,0 +1,3 @@ +export function sayHello() { + console.log("Hello") +} \ No newline at end of file diff --git a/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/package.json b/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/package.json new file mode 100644 index 00000000000000..69f2a57cd84314 --- /dev/null +++ b/tests/registry/npm/@denotest/unstable/1.0.0-beta.1/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/unstable", + "type": "module", + "version": "1.0.0-beta.1" +} \ No newline at end of file diff --git a/tests/specs/add/only_unstable_versions/__test__.jsonc b/tests/specs/add/only_unstable_versions/__test__.jsonc new file mode 100644 index 00000000000000..d05628b6f5f61a --- /dev/null +++ b/tests/specs/add/only_unstable_versions/__test__.jsonc @@ -0,0 +1,9 @@ +{ + "tempDir": true, + "steps": [ + { + "args": "add npm:@denotest/unstable", + "output": "add.out" + } + ] +} diff --git a/tests/specs/add/only_unstable_versions/add.out b/tests/specs/add/only_unstable_versions/add.out new file mode 100644 index 00000000000000..48462b8beaddcd --- /dev/null +++ b/tests/specs/add/only_unstable_versions/add.out @@ -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 diff --git a/tests/specs/add/only_unstable_versions/deno.json b/tests/specs/add/only_unstable_versions/deno.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/tests/specs/add/only_unstable_versions/deno.json @@ -0,0 +1 @@ +{} From d8ddd28fc098070fb10369e8627c31e45bdeb605 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 15:58:07 -0700 Subject: [PATCH 2/6] Default to "latest" tag for npm reqs in deno install --- cli/tools/registry/pm.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 05785ec7434ffe..4fd5fb05ffe3c5 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -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; @@ -654,6 +655,14 @@ struct AddPackageReq { value: AddPackageReqValue, } +static LATEST_REQ: std::sync::LazyLock = + std::sync::LazyLock::new(|| { + VersionReq::from_raw_text_and_inner( + "latest".into(), + deno_semver::RangeSetOrTag::Tag("latest".into()), + ) + }); + impl AddPackageReq { pub fn parse(entry_text: &str) -> Result, AnyError> { enum Prefix { @@ -717,7 +726,14 @@ 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 + && !entry_text.contains("@*") + { + package_req.version_req = LATEST_REQ.clone(); + } Ok(Ok(AddPackageReq { alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()), value: AddPackageReqValue::Npm(package_req), From 4f0f1f1faf33a92587c0cbc94b4b0cc5e6fe1525 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 16:31:36 -0700 Subject: [PATCH 3/6] Only on fallback --- cli/tools/registry/pm.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 4fd5fb05ffe3c5..c03587c1b06fd0 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -730,6 +730,7 @@ impl AddPackageReq { // 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 = LATEST_REQ.clone(); From 864ece448368a5ea2782ff74602da4a65ce9d853 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 16:40:58 -0700 Subject: [PATCH 4/6] Appease clippy --- cli/tools/registry/pm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index c03587c1b06fd0..f456cd1bf57dcc 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -729,7 +729,7 @@ impl AddPackageReq { 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 + if package_req.version_req == *deno_semver::WILDCARD_VERSION_REQ && package_req.version_req.version_text() == "*" && !entry_text.contains("@*") { From fc8bf9850e853a131b04b69d83876d031a42b943 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 17:31:00 -0700 Subject: [PATCH 5/6] Update test --- cli/tools/registry/pm.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index f456cd1bf57dcc..9cb290f1f281b7 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -905,7 +905,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!( From 1f425e2b6f1b32602140397d6c133a764d6380a8 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 24 Sep 2024 17:32:52 -0700 Subject: [PATCH 6/6] Remove static --- cli/tools/registry/pm.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 9cb290f1f281b7..c92710f4602b80 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -655,14 +655,6 @@ struct AddPackageReq { value: AddPackageReqValue, } -static LATEST_REQ: std::sync::LazyLock = - std::sync::LazyLock::new(|| { - VersionReq::from_raw_text_and_inner( - "latest".into(), - deno_semver::RangeSetOrTag::Tag("latest".into()), - ) - }); - impl AddPackageReq { pub fn parse(entry_text: &str) -> Result, AnyError> { enum Prefix { @@ -733,7 +725,10 @@ impl AddPackageReq { && package_req.version_req.version_text() == "*" && !entry_text.contains("@*") { - package_req.version_req = LATEST_REQ.clone(); + 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()),