From a0adf68ffa258d21826fadd85464753ad1d867cb Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 6 Nov 2024 11:16:37 -0500 Subject: [PATCH] feat(mfe): add env var indicating mfe proxy --- crates/turborepo-lib/src/micro_frontends.rs | 6 ++++++ .../turborepo-lib/src/task_graph/visitor/command.rs | 12 ++++++++++++ crates/turborepo-lib/src/task_graph/visitor/exec.rs | 1 + 3 files changed, 19 insertions(+) diff --git a/crates/turborepo-lib/src/micro_frontends.rs b/crates/turborepo-lib/src/micro_frontends.rs index 341e0b4e30ceb..8d5891e9725e6 100644 --- a/crates/turborepo-lib/src/micro_frontends.rs +++ b/crates/turborepo-lib/src/micro_frontends.rs @@ -49,4 +49,10 @@ impl MicroFrontendsConfigs { pub fn get(&self, package_name: &str) -> Option<&HashSet>> { self.configs.get(package_name) } + + pub fn task_has_mfe_proxy(&self, task_id: &TaskId) -> bool { + self.configs + .values() + .any(|dev_tasks| dev_tasks.contains(task_id)) + } } diff --git a/crates/turborepo-lib/src/task_graph/visitor/command.rs b/crates/turborepo-lib/src/task_graph/visitor/command.rs index b211d57c60e92..17b2b315dff46 100644 --- a/crates/turborepo-lib/src/task_graph/visitor/command.rs +++ b/crates/turborepo-lib/src/task_graph/visitor/command.rs @@ -61,6 +61,7 @@ pub struct PackageGraphCommandProvider<'a> { package_graph: &'a PackageGraph, package_manager_binary: Result, task_args: TaskArgs<'a>, + mfe_configs: Option<&'a MicroFrontendsConfigs>, } impl<'a> PackageGraphCommandProvider<'a> { @@ -68,6 +69,7 @@ impl<'a> PackageGraphCommandProvider<'a> { repo_root: &'a AbsoluteSystemPath, package_graph: &'a PackageGraph, task_args: TaskArgs<'a>, + mfe_configs: Option<&'a MicroFrontendsConfigs>, ) -> Self { let package_manager_binary = which::which(package_graph.package_manager().command()); Self { @@ -75,6 +77,7 @@ impl<'a> PackageGraphCommandProvider<'a> { package_graph, package_manager_binary, task_args, + mfe_configs, } } @@ -126,6 +129,15 @@ impl<'a> CommandProvider for PackageGraphCommandProvider<'a> { cmd.env_clear(); cmd.envs(environment.iter()); + // If the task has an associated proxy, then we indicate this to the underlying + // task via an env var + if self + .mfe_configs + .map_or(false, |mfe_configs| mfe_configs.task_has_mfe_proxy(task_id)) + { + cmd.env("TURBO_TASK_HAS_MFE_PROXY", "true"); + } + // We always open stdin and the visitor will close it depending on task // configuration cmd.open_stdin(); diff --git a/crates/turborepo-lib/src/task_graph/visitor/exec.rs b/crates/turborepo-lib/src/task_graph/visitor/exec.rs index d41a34043dadf..0ba1c2a38d2d0 100644 --- a/crates/turborepo-lib/src/task_graph/visitor/exec.rs +++ b/crates/turborepo-lib/src/task_graph/visitor/exec.rs @@ -50,6 +50,7 @@ impl<'a> ExecContextFactory<'a> { visitor.repo_root, &visitor.package_graph, visitor.run_opts.task_args(), + visitor.micro_frontends_configs, ); let mut command_factory = CommandFactory::new(); if let Some(micro_frontends_configs) = visitor.micro_frontends_configs {