bun install with no cache option if env: BUN_NO_CACHE (#6338)

* bun install with no cache option if env: BUN_NO_CACHE

* lazy static
This commit is contained in:
Alexander Petric
2025-08-07 11:54:57 -04:00
committed by GitHub
parent dfd8356284
commit f19cc2aa4c
2 changed files with 20 additions and 5 deletions
+16 -5
View File
@@ -20,7 +20,7 @@ use crate::{
read_file_content, read_result, start_child_process, write_file_binary, OccupancyMetrics,
},
handle_child::handle_child,
BUNFIG_INSTALL_SCOPES, BUN_BUNDLE_CACHE_DIR, BUN_CACHE_DIR, BUN_PATH, DISABLE_NSJAIL,
BUNFIG_INSTALL_SCOPES, BUN_BUNDLE_CACHE_DIR, BUN_CACHE_DIR, BUN_NO_CACHE, BUN_PATH, DISABLE_NSJAIL,
DISABLE_NUSER, HOME_ENV, NODE_BIN_PATH, NODE_PATH, NPM_CONFIG_REGISTRY, NPM_PATH, NSJAIL_PATH,
PATH_ENV, PROXY_ENVS, TZ_ENV,
};
@@ -293,12 +293,21 @@ pub async fn install_bun_lockfile(
occupancy_metrics: &mut Option<&mut OccupancyMetrics>,
) -> Result<()> {
let mut child_cmd = Command::new(if npm_mode { &*NPM_PATH } else { &*BUN_PATH });
let mut args = vec!["install", "--save-text-lockfile"];
let no_cache = !npm_mode && *BUN_NO_CACHE;
if no_cache {
args.push("--no-cache");
}
child_cmd
.current_dir(job_dir)
.env_clear()
.envs(PROXY_ENVS.clone())
.envs(common_bun_proc_envs)
.args(vec!["install", "--save-text-lockfile"])
.args(args)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
@@ -307,6 +316,8 @@ pub async fn install_bun_lockfile(
let mut npm_logs = if npm_mode {
"NPM mode\n".to_string()
} else if no_cache {
"Bun install with --no-cache flag (BUN_NO_CACHE=true)\n".to_string()
} else {
"".to_string()
};
@@ -339,7 +350,7 @@ pub async fn install_bun_lockfile(
false
};
if npm_mode {
if npm_mode || no_cache {
if let Some(db) = db {
append_logs(&job_id.clone(), w_id, npm_logs, db).await;
}
@@ -1687,7 +1698,7 @@ BigInt.prototype.toJSON = function () {{
return this.toString();
}};
console.log('start');
console.log('start');
for await (const line of Readline.createInterface({{ input: process.stdin }})) {{
{print_lines}
@@ -1696,7 +1707,7 @@ for await (const line of Readline.createInterface({{ input: process.stdin }})) {
process.exit(0);
}}
try {{
let {{ {spread} }} = JSON.parse(line)
let {{ {spread} }} = JSON.parse(line)
{dates}
let res = await Main.main(...[ {spread} ]);
console.log("wm_res[success]:" + JSON.stringify(res ?? null, (key, value) => typeof value === 'undefined' ? null : value));
+4
View File
@@ -328,6 +328,10 @@ lazy_static::lazy_static! {
pub static ref NPM_CONFIG_REGISTRY: Arc<RwLock<Option<String>>> = Arc::new(RwLock::new(None));
pub static ref BUNFIG_INSTALL_SCOPES: Arc<RwLock<Option<String>>> = Arc::new(RwLock::new(None));
pub static ref BUN_NO_CACHE: bool = std::env::var("BUN_NO_CACHE")
.ok()
.and_then(|x| x.parse::<bool>().ok())
.unwrap_or(false);
pub static ref NUGET_CONFIG: Arc<RwLock<Option<String>>> = Arc::new(RwLock::new(None));
pub static ref MAVEN_REPOS: Arc<RwLock<Option<String>>> = Arc::new(RwLock::new(None));
pub static ref NO_DEFAULT_MAVEN: AtomicBool = AtomicBool::new(std::env::var("NO_DEFAULT_MAVEN")