summaryrefslogtreecommitdiff
path: root/cli/tools/installer.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-12-19 02:44:42 +0530
committerGitHub <noreply@github.com>2021-12-18 16:14:42 -0500
commit6de53b631fcdb96d72639b6d2db3592d5fa8498d (patch)
tree9a93d868f5f434a4898f212cb6bd53e65ca49ce0 /cli/tools/installer.rs
parent3db18bf9e6466c74efd9052df4d372ea0b581154 (diff)
refactor: use `once_cell` instead of `lazy_static` (#13135)
Diffstat (limited to 'cli/tools/installer.rs')
-rw-r--r--cli/tools/installer.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index 252939f85..c32423f71 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -8,6 +8,7 @@ use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::url::Url;
use log::Level;
+use once_cell::sync::Lazy;
use regex::Regex;
use regex::RegexBuilder;
use std::env;
@@ -21,15 +22,12 @@ use std::path::PathBuf;
#[cfg(not(windows))]
use std::os::unix::fs::PermissionsExt;
-lazy_static::lazy_static! {
- static ref EXEC_NAME_RE: Regex = RegexBuilder::new(
- r"^[a-z][\w-]*$"
- ).case_insensitive(true).build().unwrap();
- // Regular expression to test disk driver letter. eg "C:\\User\username\path\to"
- static ref DRIVE_LETTER_REG: Regex = RegexBuilder::new(
- r"^[c-z]:"
- ).case_insensitive(true).build().unwrap();
-}
+static EXEC_NAME_RE: Lazy<Regex> = Lazy::new(|| {
+ RegexBuilder::new(r"^[a-z][\w-]*$")
+ .case_insensitive(true)
+ .build()
+ .unwrap()
+});
fn validate_name(exec_name: &str) -> Result<(), AnyError> {
if EXEC_NAME_RE.is_match(exec_name) {
@@ -375,13 +373,12 @@ fn is_in_path(dir: &Path) -> bool {
mod tests {
use super::*;
use deno_core::parking_lot::Mutex;
+ use once_cell::sync::Lazy;
use std::process::Command;
use tempfile::TempDir;
use test_util::testdata_path;
- lazy_static::lazy_static! {
- pub static ref ENV_LOCK: Mutex<()> = Mutex::new(());
- }
+ pub static ENV_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
#[test]
fn install_infer_name_from_url() {