From 5393aa43fe09d4e26be52d95d40f4d83d93e2ead Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 5 Aug 2023 19:17:52 +0200 Subject: [PATCH] feat: add support for custom import map on deno --- README.md | 3 +-- backend/windmill-worker/src/worker.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66c6862da8..038f07be06 100644 --- a/README.md +++ b/README.md @@ -367,12 +367,11 @@ it being synced automatically everyday. | QUEUE_LIMIT_WAIT_RESULT | None | The number of max jobs in the queue before rejecting immediately the request in 'run_wait_result' endpoint. Takes precedence on the query arg. If none is specified, there are no limit. | Worker | | DENO_AUTH_TOKENS | None | Custom DENO_AUTH_TOKENS to pass to worker to allow the use of private modules | Worker | | DENO_FLAGS | None | Override the flags passed to deno (default --allow-all) to tighten permissions. Minimum permissions needed are "--allow-read=args.json --allow-write=result.json" | Worker | +| DENO_EXTRA_IMPORT_MAP | None | extra import map to use to run deno scripts (format: `key:value,key:value`) | Worker | | NPM_CONFIG_REGISTRY | None | Registry to use for NPM dependencies, set if you have a private repository you need to use instead of the default public NPM registry | Worker | | PIP_LOCAL_DEPENDENCIES | None | Specify dependencies that are installed locally and do not need to be solved nor installed again | | | ADDITIONAL_PYTHON_PATHS | None | Specify python paths (separated by a :) to be appended to the PYTHONPATH of the python jobs. To be used with PIP_LOCAL_DEPENDENCIES to use python codebases within Windmill | Worker | | INCLUDE_HEADERS | None | Whitelist of headers that are passed to jobs as args (separated by a comma) | Server | -| WHITELIST_WORKSPACES | None | Whitelist of workspaces this worker takes job from | Worker | -| BLACKLIST_WORKSPACES | None | Blacklist of workspaces this worker takes job from | Worker | | INSTANCE_EVENTS_WEBHOOK | None | Webhook to notify of events such as new user added, signup/invite. Can hook back to windmill to send emails | | GLOBAL_CACHE_INTERVAL | 10\*60 | (Enterprise Edition only) Interval in seconds in between bucket sync of the cache. This interval \* 2 is the time at which you're guaranteed all the worker's caches are synced together. | Worker | | WORKER_TAGS | 'deno,go,python3,bash,flow,hub,dependency' | The worker groups assigned to that workers | Worker | diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index bacdaf4a5c..a2435c29f6 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -205,6 +205,14 @@ lazy_static::lazy_static! { .ok() .map(|x| x.split(' ').map(|x| x.to_string()).collect()); + static ref DENO_EXTRA_IMPORT_MAP: String = std::env::var("DENO_EXTRA_IMPORT_MAP") + .ok() + .map(|x| x.split(',').map(|x| { + let mut splitted = x.split("="); + let key = splitted.next().unwrap(); + let value = splitted.next().unwrap(); + format!(",\n \"{key}\": \"{value}\"") + }).join("\n")).unwrap_or_else(|| String::new()); pub static ref WHITELIST_ENVS: Option> = std::env::var("WHITELIST_ENVS") @@ -1713,6 +1721,7 @@ run().catch(async (e) => {{ if c == script_path_parts_len - 1 { "" } else { "/" }, ); } + let extra_import_map = DENO_EXTRA_IMPORT_MAP.as_str(); let import_map = format!( r#"{{ "imports": {{ @@ -1721,6 +1730,7 @@ run().catch(async (e) => {{ "/": "{base_internal_url}/api/w/{w_id}/scripts/raw/p/", "./wrapper.ts": "./wrapper.ts", "./main.ts": "./main.ts"{relative_mounts} + {extra_import_map} }} }}"#, );