Skip to content

Add npm package version override capability #30302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/eval/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ pub fn init(cx: &mut App) -> Arc<AgentAppState> {
}),
)
}),
version_overrides: settings.version_overrides.clone(),
};
tx.send(Some(options)).log_err();
})
Expand Down
1 change: 1 addition & 0 deletions crates/node_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion crates/node_runtime/src/node_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<HashMap<String, String>>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -128,7 +130,21 @@ impl NodeRuntime {
}

pub async fn npm_package_latest_version(&self, name: &str) -> Result<String> {
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?
Expand Down
2 changes: 2 additions & 0 deletions crates/project/src/project_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ pub struct NodeBinarySettings {
/// If enabled, Zed will download its own copy of Node.
#[serde(default)]
pub ignore_system_version: Option<bool>,
/// Map of package names to version overrides.
pub version_overrides: Option<HashMap<String, String>>,
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
Expand Down
1 change: 1 addition & 0 deletions crates/remote_server/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ fn initialize_settings(
}),
)
}),
version_overrides: settings.version_overrides.clone(),
};
tx.send(Some(options)).log_err();
})
Expand Down
1 change: 1 addition & 0 deletions crates/zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ fn main() {
}),
)
}),
version_overrides: settings.version_overrides.clone(),
};
tx.send(Some(options)).log_err();
})
Expand Down
Loading