From df607c2a1015f7bc7e8d70e50e9c26203f0c6973 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 24 Jan 2024 16:49:05 +0100 Subject: [PATCH] fix: bun default registry and performance improvements --- backend/parsers/windmill-parser-ts/src/lib.rs | 3 ++- backend/windmill-worker/loader_builder.bun.ts | 17 ++++++++++++----- backend/windmill-worker/src/bun_executor.rs | 4 ++-- frontend/src/lib/components/instanceSettings.ts | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backend/parsers/windmill-parser-ts/src/lib.rs b/backend/parsers/windmill-parser-ts/src/lib.rs index fb4a3323c8..b820a7771b 100644 --- a/backend/parsers/windmill-parser-ts/src/lib.rs +++ b/backend/parsers/windmill-parser-ts/src/lib.rs @@ -291,7 +291,8 @@ lazy_static::lazy_static! { } pub fn remove_pinned_imports(code: &str) -> anyhow::Result { - let imports = parse_expr_for_imports(code)?; + let mut imports = parse_expr_for_imports(code)?; + imports.sort_by_key(|f| 0 - (f.len() as i32)); let mut content = code.to_string(); for import in imports { let to_c = IMPORTS_VERSION.captures(&import); diff --git a/backend/windmill-worker/loader_builder.bun.ts b/backend/windmill-worker/loader_builder.bun.ts index f869090262..048ce82eb6 100644 --- a/backend/windmill-worker/loader_builder.bun.ts +++ b/backend/windmill-worker/loader_builder.bun.ts @@ -19,7 +19,6 @@ if (!bo.success) { content.replaceAll("__require", "require") ); - const { intersect } = require("semver-intersect"); const dependencies: Record = {}; for (const i of imports) { let [_, name, version] = i.path.match(captureVersion) ?? []; @@ -47,15 +46,23 @@ if (!bo.success) { } const resolvedDeps: Record = {}; for (const i in dependencies) { + const versions = dependencies[i]; resolvedDeps[i] = - dependencies[i].length == 0 + versions.length == 0 ? "latest" - : dependencies[i].reduce((a, b) => { - return intersect(a, b); - }); + : versions.length == 1 + ? versions[0] + : reduceIntersect(versions); } await Bun.write( "./package.json", JSON.stringify({ dependencies: resolvedDeps }, null, 2) ); + + function reduceIntersect(versions: string[]): string { + const { intersect } = require("semver-intersect"); + return versions.reduce((a, b) => { + return intersect(a, b); + }); + } } diff --git a/backend/windmill-worker/src/bun_executor.rs b/backend/windmill-worker/src/bun_executor.rs index 3d4a767c26..2a37708c1a 100644 --- a/backend/windmill-worker/src/bun_executor.rs +++ b/backend/windmill-worker/src/bun_executor.rs @@ -190,12 +190,12 @@ async fn gen_bunfig(job_dir: &str) -> Result<()> { let (url, token_opt) = if let Some(ref s) = registry { let url = s.trim(); if url.is_empty() { - ("https://registry.npmjs.org".to_string(), None) + ("https://registry.npmjs.org/".to_string(), None) } else { parse_npm_config(s) } } else { - ("https://registry.npmjs.org".to_string(), None) + ("https://registry.npmjs.org/".to_string(), None) }; let registry_toml_string = if let Some(token) = token_opt { format!("{{ url = \"{url}\", token = \"{token}\" }}") diff --git a/frontend/src/lib/components/instanceSettings.ts b/frontend/src/lib/components/instanceSettings.ts index 6cdfb796b9..68a7267e65 100644 --- a/frontend/src/lib/components/instanceSettings.ts +++ b/frontend/src/lib/components/instanceSettings.ts @@ -127,7 +127,7 @@ export const settings: Record = { description: 'Add private NPM registry', key: 'npm_config_registry', fieldType: 'text', - placeholder: 'https://yourregistry', + placeholder: 'https://registry.npmjs.org/:_authToken=npm_FOOBAR', storage: 'setting', ee_only: '' },