From 5fa5ab1514a2d20083d30809c30e50bfcb29e82f Mon Sep 17 00:00:00 2001 From: Guillaume Bouvignies Date: Mon, 25 Dec 2023 09:03:40 +0100 Subject: [PATCH] feat: bun can read private npm package (#2915) * feat: bun can read private package * Add / at the end of url --- backend/windmill-api/openapi-deref.yaml | 2 +- backend/windmill-worker/src/bun_executor.rs | 40 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/backend/windmill-api/openapi-deref.yaml b/backend/windmill-api/openapi-deref.yaml index 34f42f59b1..072e300ab3 100644 --- a/backend/windmill-api/openapi-deref.yaml +++ b/backend/windmill-api/openapi-deref.yaml @@ -1,6 +1,6 @@ openapi: 3.0.3 info: - version: 1.229.0 + version: 1.230.0 title: Windmill API contact: name: Windmill Team diff --git a/backend/windmill-worker/src/bun_executor.rs b/backend/windmill-worker/src/bun_executor.rs index 61e3776731..d7a02b8406 100644 --- a/backend/windmill-worker/src/bun_executor.rs +++ b/backend/windmill-worker/src/bun_executor.rs @@ -16,7 +16,7 @@ use crate::{ start_child_process, write_file, write_file_binary, }, AuthedClientBackgroundTask, BUN_CACHE_DIR, BUN_PATH, DISABLE_NSJAIL, DISABLE_NUSER, HOME_ENV, - NSJAIL_PATH, PATH_ENV, TZ_ENV, + NPM_CONFIG_REGISTRY, NSJAIL_PATH, PATH_ENV, TZ_ENV, }; use tokio::{ @@ -84,6 +84,44 @@ pub async fn gen_lockfile( ) .await?; + // if custom NPM registry is being used, write bunfig.toml at the root of the job dir + if let Some(ref s) = NPM_CONFIG_REGISTRY.read().await.clone() { + let (raw_url, token_opt) = if s.contains(":_authToken=") { + let split_url = s.split(":_authToken=").collect::>(); + let url = split_url + .get(0) + .map(|u| u.to_string()) + .unwrap_or("".to_string()); + let token = split_url + .get(1) + .map(|t| t.to_string()) + .unwrap_or("".to_string()); + (url, Some(token)) + } else { + (s.to_owned(), None) + }; + // somehow bun fails to resolve deps if the url does not end with a slash ... + let url = if !raw_url.ends_with("/") { + format!("{raw_url}/") + } else { + raw_url.to_string() + }; + let registry_toml_string = if let Some(token) = token_opt { + format!("{{ url = \"{url}\", token = \"{token}\" }}") + } else { + format!("\"{url}\"") + }; + let bunfig_toml = format!( + r#" +[install] +registry = {} +"#, + registry_toml_string + ); + tracing::debug!("Writing following bunfig.toml: {bunfig_toml}"); + let _ = write_file(&job_dir, "bunfig.toml", &bunfig_toml).await?; + } + let common_bun_proc_envs: HashMap = get_common_bun_proc_envs(&base_internal_url).await;