From 55d67d1f75a2e9eeaaac48a10ba595d4a332c7ca Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:42:29 -0400 Subject: [PATCH] build: add 'override_env' dict option to dev_pnpm_task_binary --- core/api/BUCK | 3 +++ toolchains/workspace-pnpm/macros.bzl | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/api/BUCK b/core/api/BUCK index 9c10f9ba18d..7ab3833ad64 100644 --- a/core/api/BUCK +++ b/core/api/BUCK @@ -276,6 +276,9 @@ dev_pnpm_task_binary( srcs = [":src"], visibility = ["PUBLIC"], env = dummy_env_dict, + override_env = { + "MONGODB_CON": "mongodb://localhost:27017/galoy", + }, ) dev_pnpm_task_binary( diff --git a/toolchains/workspace-pnpm/macros.bzl b/toolchains/workspace-pnpm/macros.bzl index de1e8de49bb..14699ef90e3 100644 --- a/toolchains/workspace-pnpm/macros.bzl +++ b/toolchains/workspace-pnpm/macros.bzl @@ -1042,7 +1042,9 @@ def dict_to_env_string(input_dict): return '\n'.join(env_strings) def pnpm_task_binary_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]: - env_file = ctx.actions.write(".env", dict_to_env_string(ctx.attrs.env), is_executable = True) + combined_env = dict(ctx.attrs.env) + combined_env.update(ctx.attrs.override_env) + env_file = ctx.actions.write(".env", dict_to_env_string(combined_env), is_executable = True) script = ctx.actions.write("pnpm-run.sh", """\ #!/usr/bin/env bash @@ -1092,6 +1094,13 @@ dev_pnpm_task_binary = rule(impl = pnpm_task_binary_impl, attrs = { default = {}, doc = """Env values to inject for pnpm command run""" ), + "override_env": attrs.dict( + key = attrs.string(), + value = attrs.arg(), + sorted = False, + default = {}, + doc = """Env values to override originally injected values with""" + ), }) def pnpm_task_test_impl(ctx: AnalysisContext) -> list[[DefaultInfo, ExternalRunnerTestInfo]]: