diff --git a/Cargo.lock b/Cargo.lock index 6dc7dd1ce7c94c..a705bad9cacbff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9043,6 +9043,7 @@ dependencies = [ "async-trait", "async-watch", "async_zip", + "collections", "futures 0.3.31", "http_client", "log", diff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rs index 7a87103f4405cc..47e33d72f82d4e 100644 --- a/crates/eval/src/eval.rs +++ b/crates/eval/src/eval.rs @@ -413,6 +413,7 @@ pub fn init(cx: &mut App) -> Arc { }), ) }), + version_overrides: settings.version_overrides.clone(), }; tx.send(Some(options)).log_err(); }) diff --git a/crates/node_runtime/Cargo.toml b/crates/node_runtime/Cargo.toml index 1c03214d5c55a3..9a51bcb17113ab 100644 --- a/crates/node_runtime/Cargo.toml +++ b/crates/node_runtime/Cargo.toml @@ -22,6 +22,7 @@ async-watch.workspace = true async-tar.workspace = true async-trait.workspace = true async_zip.workspace = true +collections.workspace = true futures.workspace = true http_client.workspace = true log.workspace = true diff --git a/crates/node_runtime/src/node_runtime.rs b/crates/node_runtime/src/node_runtime.rs index c2ccba34c48ae5..9d7fa6ac107bab 100644 --- a/crates/node_runtime/src/node_runtime.rs +++ b/crates/node_runtime/src/node_runtime.rs @@ -4,6 +4,7 @@ use anyhow::{Context, Result, anyhow, bail}; pub use archive::extract_zip; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; +use collections::HashMap; use futures::AsyncReadExt; use http_client::{HttpClient, Url}; use semver::Version; @@ -28,6 +29,7 @@ pub struct NodeBinaryOptions { pub allow_path_lookup: bool, pub allow_binary_download: bool, pub use_paths: Option<(PathBuf, PathBuf)>, + pub version_overrides: Option>, } #[derive(Clone)] @@ -128,7 +130,21 @@ impl NodeRuntime { } pub async fn npm_package_latest_version(&self, name: &str) -> Result { - let http = self.0.lock().await.http.clone(); + let state = self.0.lock().await; + + let version_override = state + .options + .borrow() + .as_ref() + .and_then(|options| options.version_overrides.as_ref()?.get(name)) + .cloned(); + if let Some(version) = version_override { + return Ok(version); + } + + let http = state.http.clone(); + drop(state); + let output = self .instance() .await? diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index 387bccbcd10883..2dc841ec64e2db 100644 --- a/crates/project/src/project_settings.rs +++ b/crates/project/src/project_settings.rs @@ -105,6 +105,8 @@ pub struct NodeBinarySettings { /// If enabled, Zed will download its own copy of Node. #[serde(default)] pub ignore_system_version: Option, + /// Map of package names to version overrides. + pub version_overrides: Option>, } #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] diff --git a/crates/remote_server/src/unix.rs b/crates/remote_server/src/unix.rs index d81ae3012954e8..57a89b535e4598 100644 --- a/crates/remote_server/src/unix.rs +++ b/crates/remote_server/src/unix.rs @@ -813,6 +813,7 @@ fn initialize_settings( }), ) }), + version_overrides: settings.version_overrides.clone(), }; tx.send(Some(options)).log_err(); }) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 29a5f04dd8c3bb..5a1eb6ad6ea270 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -403,6 +403,7 @@ fn main() { }), ) }), + version_overrides: settings.version_overrides.clone(), }; tx.send(Some(options)).log_err(); })