summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/upgrade.rs8
-rw-r--r--cli/tools/vendor/specifiers.rs57
2 files changed, 13 insertions, 52 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index db1383eb0..702a578c9 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -9,7 +9,6 @@ use deno_core::futures::StreamExt;
use deno_runtime::deno_fetch::reqwest;
use deno_runtime::deno_fetch::reqwest::Client;
use once_cell::sync::Lazy;
-use semver_parser::version::parse as semver_parse;
use std::env;
use std::fs;
use std::io::Write;
@@ -48,7 +47,8 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
&& !regex::Regex::new("^[0-9a-f]{40}$")?.is_match(&passed_version)
{
bail!("Invalid commit hash passed");
- } else if !upgrade_flags.canary && semver_parse(&passed_version).is_err()
+ } else if !upgrade_flags.canary
+ && semver::Version::parse(&passed_version).is_err()
{
bail!("Invalid semver passed");
}
@@ -83,8 +83,8 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
latest_hash.truncate(7);
crate::version::GIT_COMMIT_HASH == latest_hash
} else if !crate::version::is_canary() {
- let current = semver_parse(&crate::version::deno()).unwrap();
- let latest = semver_parse(&latest_version).unwrap();
+ let current = semver::Version::parse(&crate::version::deno()).unwrap();
+ let latest = semver::Version::parse(&latest_version).unwrap();
current >= latest
} else {
false
diff --git a/cli/tools/vendor/specifiers.rs b/cli/tools/vendor/specifiers.rs
index b869e989c..5d4f98278 100644
--- a/cli/tools/vendor/specifiers.rs
+++ b/cli/tools/vendor/specifiers.rs
@@ -8,6 +8,7 @@ use deno_ast::ModuleSpecifier;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
+use crate::fs_util;
use crate::fs_util::path_with_stem_suffix;
/// Partitions the provided specifiers by the non-path and non-query parts of a specifier.
@@ -29,24 +30,7 @@ pub fn partition_by_root_specifiers<'a>(
/// Gets the directory name to use for the provided root.
pub fn dir_name_for_root(root: &ModuleSpecifier) -> PathBuf {
- let mut result = String::new();
- if let Some(domain) = root.domain() {
- result.push_str(&sanitize_segment(domain));
- }
- if let Some(port) = root.port() {
- if !result.is_empty() {
- result.push('_');
- }
- result.push_str(&port.to_string());
- }
- let mut result = PathBuf::from(result);
- if let Some(segments) = root.path_segments() {
- for segment in segments.filter(|s| !s.is_empty()) {
- result = result.join(sanitize_segment(segment));
- }
- }
-
- result
+ fs_util::root_url_to_safe_local_dirname(root)
}
/// Gets a unique file path given the provided file path
@@ -90,25 +74,16 @@ pub fn is_remote_specifier_text(text: &str) -> bool {
pub fn sanitize_filepath(text: &str) -> String {
text
.chars()
- .map(|c| if is_banned_path_char(c) { '_' } else { c })
- .collect()
-}
-
-fn is_banned_path_char(c: char) -> bool {
- matches!(c, '<' | '>' | ':' | '"' | '|' | '?' | '*')
-}
-
-fn sanitize_segment(text: &str) -> String {
- text
- .chars()
- .map(|c| if is_banned_segment_char(c) { '_' } else { c })
+ .map(|c| {
+ if fs_util::is_banned_path_char(c) {
+ '_'
+ } else {
+ c
+ }
+ })
.collect()
}
-fn is_banned_segment_char(c: char) -> bool {
- matches!(c, '/' | '\\') || is_banned_path_char(c)
-}
-
#[cfg(test)]
mod test {
use super::*;
@@ -203,20 +178,6 @@ mod test {
}
#[test]
- fn should_get_dir_name_root() {
- run_test("http://deno.land/x/test", "deno.land/x/test");
- run_test("http://localhost", "localhost");
- run_test("http://localhost/test%20:test", "localhost/test%20_test");
-
- fn run_test(specifier: &str, expected: &str) {
- assert_eq!(
- dir_name_for_root(&ModuleSpecifier::parse(specifier).unwrap()),
- PathBuf::from(expected)
- );
- }
- }
-
- #[test]
fn test_unique_path() {
let mut paths = HashSet::new();
assert_eq!(