summaryrefslogtreecommitdiff
path: root/cli/compat/mod.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/compat/mod.rs
parent3db18bf9e6466c74efd9052df4d372ea0b581154 (diff)
refactor: use `once_cell` instead of `lazy_static` (#13135)
Diffstat (limited to 'cli/compat/mod.rs')
-rw-r--r--cli/compat/mod.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/cli/compat/mod.rs b/cli/compat/mod.rs
index 54f8b5fde..14e168764 100644
--- a/cli/compat/mod.rs
+++ b/cli/compat/mod.rs
@@ -7,6 +7,7 @@ use deno_core::error::AnyError;
use deno_core::located_script_name;
use deno_core::url::Url;
use deno_core::JsRuntime;
+use once_cell::sync::Lazy;
pub use esm_resolver::check_if_should_use_esm_loader;
pub(crate) use esm_resolver::NodeEsmResolver;
@@ -62,15 +63,27 @@ static SUPPORTED_MODULES: &[&str] = &[
"zlib",
];
-lazy_static::lazy_static! {
- static ref NODE_COMPAT_URL: String = std::env::var("DENO_NODE_COMPAT_URL").map(String::into).ok()
- .unwrap_or_else(|| STD_URL_STR.to_string());
- static ref GLOBAL_URL_STR: String = format!("{}node/global.ts", NODE_COMPAT_URL.as_str());
- pub(crate) static ref GLOBAL_URL: Url = Url::parse(&GLOBAL_URL_STR).unwrap();
- static ref MODULE_URL_STR: String = format!("{}node/module.ts", NODE_COMPAT_URL.as_str());
- pub(crate) static ref MODULE_URL: Url = Url::parse(&MODULE_URL_STR).unwrap();
- static ref COMPAT_IMPORT_URL: Url = Url::parse("flags:compat").unwrap();
-}
+static NODE_COMPAT_URL: Lazy<String> = Lazy::new(|| {
+ std::env::var("DENO_NODE_COMPAT_URL")
+ .map(String::into)
+ .ok()
+ .unwrap_or_else(|| STD_URL_STR.to_string())
+});
+
+static GLOBAL_URL_STR: Lazy<String> =
+ Lazy::new(|| format!("{}node/global.ts", NODE_COMPAT_URL.as_str()));
+
+pub(crate) static GLOBAL_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse(&GLOBAL_URL_STR).unwrap());
+
+static MODULE_URL_STR: Lazy<String> =
+ Lazy::new(|| format!("{}node/module.ts", NODE_COMPAT_URL.as_str()));
+
+pub(crate) static MODULE_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse(&MODULE_URL_STR).unwrap());
+
+static COMPAT_IMPORT_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse("flags:compat").unwrap());
/// Provide imports into a module graph when the compat flag is true.
pub(crate) fn get_node_imports() -> Vec<(Url, Vec<String>)> {