diff --git a/Cargo.lock b/Cargo.lock index 191703f6c5..055b7c539a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1687,9 +1687,9 @@ dependencies = [ [[package]] name = "deno_cache_dir" -version = "0.19.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502c5f3120fe5b32908e9a4b3af95b7e1a35e8fa758d87155b03a3810655c9f0" +checksum = "869a62459ded73382e018c7c58a07df170ba5f5befb67e18ee10494e769efe2a" dependencies = [ "async-trait", "base32", diff --git a/Cargo.toml b/Cargo.toml index 41da00608f..f2021c53e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ repository = "https://github.com/denoland/deno" deno_ast = { version = "=0.46.6", features = ["transpiling"] } deno_core = { version = "0.345.0" } -deno_cache_dir = "=0.19.2" +deno_cache_dir = "=0.20.0" deno_config = { version = "=0.54.2", features = ["workspace"] } deno_doc = "=0.172.0" deno_error = "=0.5.6" diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 78c156575a..fb0ccc822b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -47,6 +47,7 @@ use deno_lib::args::NPM_PROCESS_STATE; use deno_lib::version::DENO_VERSION_INFO; use deno_lib::worker::StorageKeyResolver; use deno_npm::NpmSystemInfo; +use deno_resolver::factory::resolve_jsr_url; use deno_runtime::deno_permissions::PermissionsOptions; use deno_runtime::inspector_server::InspectorServer; use deno_semver::npm::NpmPackageReqReference; @@ -67,27 +68,7 @@ use thiserror::Error; use crate::sys::CliSys; pub fn jsr_url() -> &'static Url { - static JSR_URL: Lazy = Lazy::new(|| { - let env_var_name = "JSR_URL"; - if let Ok(registry_url) = std::env::var(env_var_name) { - // ensure there is a trailing slash for the directory - let registry_url = format!("{}/", registry_url.trim_end_matches('/')); - match Url::parse(®istry_url) { - Ok(url) => { - return url; - } - Err(err) => { - log::debug!( - "Invalid {} environment variable: {:#}", - env_var_name, - err, - ); - } - } - } - - Url::parse("https://jsr.io/").unwrap() - }); + static JSR_URL: Lazy = Lazy::new(|| resolve_jsr_url(&CliSys::default())); &JSR_URL } diff --git a/resolvers/deno/factory.rs b/resolvers/deno/factory.rs index 7b683582f5..904bee9b3e 100644 --- a/resolvers/deno/factory.rs +++ b/resolvers/deno/factory.rs @@ -45,6 +45,7 @@ use sys_traits::SystemRandom; use sys_traits::SystemTimeNow; use sys_traits::ThreadSleep; use thiserror::Error; +use url::Url; use crate::npm::managed::ManagedInNpmPkgCheckerCreateOptions; use crate::npm::managed::ManagedNpmResolverCreateOptions; @@ -127,6 +128,25 @@ pub enum ConfigDiscoveryOption { Disabled, } +/// Resolves the JSR regsitry URL to use for the given system. +pub fn resolve_jsr_url(sys: &impl sys_traits::EnvVar) -> Url { + let env_var_name = "JSR_URL"; + if let Ok(registry_url) = sys.env_var(env_var_name) { + // ensure there is a trailing slash for the directory + let registry_url = format!("{}/", registry_url.trim_end_matches('/')); + match Url::parse(®istry_url) { + Ok(url) => { + return url; + } + Err(err) => { + log::debug!("Invalid {} environment variable: {:#}", env_var_name, err,); + } + } + } + + Url::parse("https://jsr.io/").unwrap() +} + #[async_trait::async_trait(?Send)] pub trait SpecifiedImportMapProvider: std::fmt::Debug + MaybeSend + MaybeSync @@ -259,6 +279,7 @@ pub struct WorkspaceFactory deno_dir_path: DenoDirPathProviderRc, global_http_cache: Deferred>, http_cache: Deferred>, + jsr_url: Deferred, node_modules_dir_path: Deferred>, npm_cache_dir: Deferred, npmrc: Deferred, @@ -288,6 +309,7 @@ impl WorkspaceFactory { sys, global_http_cache: Default::default(), http_cache: Default::default(), + jsr_url: Default::default(), node_modules_dir_path: Default::default(), npm_cache_dir: Default::default(), npmrc: Default::default(), @@ -305,6 +327,10 @@ impl WorkspaceFactory { self.workspace_directory = Deferred::from(workspace_directory); } + pub fn jsr_url(&self) -> &Url { + self.jsr_url.get_or_init(|| resolve_jsr_url(&self.sys)) + } + pub fn initial_cwd(&self) -> &PathBuf { &self.initial_cwd } @@ -453,6 +479,7 @@ impl WorkspaceFactory { local_path.clone(), global_cache, deno_cache_dir::GlobalToLocalCopy::Allow, + self.jsr_url().clone(), ); Ok(new_rc(local_cache).into()) }