From 03e6727a0461bf83865f6f0412f4fb8990cf27e6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 2 Sep 2022 11:21:40 -0400 Subject: [PATCH] fix(npm): correct exact matching of pre-release versions (#15745) --- cli/npm/resolution.rs | 2 +- cli/npm/semver/mod.rs | 6 +++--- cli/npm/semver/specifier.rs | 9 +++++---- cli/tests/testdata/npm/deno_run_non_existent.out | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/npm/resolution.rs b/cli/npm/resolution.rs index b6d643bb11..4f46bbed46 100644 --- a/cli/npm/resolution.rs +++ b/cli/npm/resolution.rs @@ -514,7 +514,7 @@ fn get_resolved_package_version_and_info( None => bail!( concat!( "Could not find npm package '{}' matching {}{}. ", - "Try retreiving the latest npm package information by running with --reload", + "Try retrieving the latest npm package information by running with --reload", ), pkg_name, version_matcher.version_text(), diff --git a/cli/npm/semver/mod.rs b/cli/npm/semver/mod.rs index 2b5cc5a035..10a87a13ff 100644 --- a/cli/npm/semver/mod.rs +++ b/cli/npm/semver/mod.rs @@ -313,9 +313,7 @@ fn simple(input: &str) -> ParseResult { } } }), - map(partial, |partial| { - partial.as_greater_range(VersionBoundKind::Inclusive) - }), + map(partial, |partial| partial.as_equal_range()), )(input) } @@ -842,6 +840,8 @@ mod tests { ("1.0.0 - x", "1.9.7"), ("1.x - x", "1.9.7"), ("<=7.x", "7.9.9"), + // additional tests + ("1.0.0-alpha.13", "1.0.0-alpha.13"), ]; for (req_text, version_text) in fixtures { let req = NpmVersionReq::parse(req_text).unwrap(); diff --git a/cli/npm/semver/specifier.rs b/cli/npm/semver/specifier.rs index 019360422a..64e3c4f9be 100644 --- a/cli/npm/semver/specifier.rs +++ b/cli/npm/semver/specifier.rs @@ -6,7 +6,6 @@ use monch::*; use super::errors::with_failure_handling; use super::range::Partial; -use super::range::VersionBoundKind; use super::range::VersionRange; use super::range::XRange; use super::NpmVersion; @@ -57,9 +56,7 @@ fn version_range(input: &str) -> ParseResult { map(preceded(ch('^'), partial), |partial| { partial.as_caret_version_range() }), - map(partial, |partial| { - partial.as_greater_range(VersionBoundKind::Inclusive) - }), + map(partial, |partial| partial.as_equal_range()), )(input) } @@ -186,6 +183,10 @@ mod tests { assert!(tester.matches("1.0.1")); assert!(!tester.matches("1.0.2")); assert!(!tester.matches("1.1.1")); + + // pre-release + let tester = VersionReqTester::new("1.0.0-alpha.13"); + assert!(tester.matches("1.0.0-alpha.13")); } #[test] diff --git a/cli/tests/testdata/npm/deno_run_non_existent.out b/cli/tests/testdata/npm/deno_run_non_existent.out index 4f5d7b4c13..f0e8a0791a 100644 --- a/cli/tests/testdata/npm/deno_run_non_existent.out +++ b/cli/tests/testdata/npm/deno_run_non_existent.out @@ -1,2 +1,2 @@ Download http://localhost:4545/npm/registry/mkdirp -error: Could not find npm package 'mkdirp' matching 0.5.125. Try retreiving the latest npm package information by running with --reload +error: Could not find npm package 'mkdirp' matching 0.5.125. Try retrieving the latest npm package information by running with --reload