aports/testing/zed/dont-download-node.patch
2024-06-05 22:24:55 +00:00

115 lines
3.9 KiB
Diff

From 60921dc55f833d722557badcc9a32fe5826f00e6 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sun, 2 Jun 2024 22:48:47 +0200
Subject: [PATCH] Don't download node and npm
See https://github.com/zed-industries/zed/issues/12589
---
Cargo.lock | 1 +
crates/node_runtime/Cargo.toml | 1 +
crates/node_runtime/src/node_runtime.rs | 45 ++++++-------------------
3 files changed, 12 insertions(+), 35 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 6567bf9f8..700e757c6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6588,6 +6588,7 @@ dependencies = [
"tempfile",
"util",
"walkdir",
+ "which 6.0.0",
"windows 0.56.0",
]
diff --git a/crates/node_runtime/Cargo.toml b/crates/node_runtime/Cargo.toml
--- a/crates/node_runtime/Cargo.toml
+++ b/crates/node_runtime/Cargo.toml
@@ -31,6 +31,7 @@
tempfile = { workspace = true, optional = true }
util.workspace = true
walkdir = "2.5.0"
+which.workspace = true
[target.'cfg(windows)'.dependencies]
async-std = { version = "1.12.0", features = ["unstable"] }
diff --git a/crates/node_runtime/src/node_runtime.rs b/crates/node_runtime/src/node_runtime.rs
index a00ce6cd2..f9269f2ca 100644
--- a/crates/node_runtime/src/node_runtime.rs
+++ b/crates/node_runtime/src/node_runtime.rs
@@ -17,6 +17,7 @@ use std::{
sync::Arc,
};
use util::ResultExt;
+use which::which;
#[cfg(windows)]
use smol::process::windows::CommandExt;
@@ -211,8 +212,8 @@ impl RealNodeRuntime {
#[async_trait::async_trait]
impl NodeRuntime for RealNodeRuntime {
async fn binary_path(&self) -> Result<PathBuf> {
- let installation_path = self.install_if_needed().await?;
- Ok(installation_path.join(NODE_PATH))
+ let path = which("node")?; // XXX-Patched
+ Ok(path)
}
async fn run_npm_subcommand(
@@ -221,45 +222,19 @@ impl NodeRuntime for RealNodeRuntime {
subcommand: &str,
args: &[&str],
) -> Result<Output> {
+ // XXX-Patched
let attempt = || async move {
- let installation_path = self.install_if_needed().await?;
-
- let node_binary = installation_path.join(NODE_PATH);
- let npm_file = installation_path.join(NPM_PATH);
- let mut env_path = vec![node_binary
- .parent()
- .expect("invalid node binary path")
- .to_path_buf()];
-
- if let Some(existing_path) = std::env::var_os("PATH") {
- let mut paths = std::env::split_paths(&existing_path).collect::<Vec<_>>();
- env_path.append(&mut paths);
- }
-
- let env_path =
- std::env::join_paths(env_path).context("failed to create PATH env variable")?;
-
- if smol::fs::metadata(&node_binary).await.is_err() {
- return Err(anyhow!("missing node binary file"));
- }
-
- if smol::fs::metadata(&npm_file).await.is_err() {
- return Err(anyhow!("missing npm file"));
- }
+ let node_binary = std::env::var("NODE").map(PathBuf::from).or_else(|_| which("node"))?;
+ let npm_file = which("npm")?;
let mut command = Command::new(node_binary);
- command.env_clear();
- command.env("PATH", env_path);
command.arg(npm_file).arg(subcommand);
- command.args(["--cache".into(), installation_path.join("cache")]);
- command.args([
- "--userconfig".into(),
- installation_path.join("blank_user_npmrc"),
- ]);
command.args([
- "--globalconfig".into(),
- installation_path.join("blank_global_npmrc"),
+ "--userconfig",
+ "/dev/null",
]);
+ command.arg("--no-audit");
+ command.arg("--no-fund");
command.args(args);
if let Some(directory) = directory {
--
2.43.0