Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mfe): add env var indicating mfe proxy #9395

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/turborepo-lib/src/micro_frontends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ impl MicroFrontendsConfigs {
pub fn get(&self, package_name: &str) -> Option<&HashSet<TaskId<'static>>> {
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))
}
}
12 changes: 12 additions & 0 deletions crates/turborepo-lib/src/task_graph/visitor/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,23 @@ pub struct PackageGraphCommandProvider<'a> {
package_graph: &'a PackageGraph,
package_manager_binary: Result<PathBuf, which::Error>,
task_args: TaskArgs<'a>,
mfe_configs: Option<&'a MicroFrontendsConfigs>,
}

impl<'a> PackageGraphCommandProvider<'a> {
pub fn new(
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 {
repo_root,
package_graph,
package_manager_binary,
task_args,
mfe_configs,
}
}

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/task_graph/visitor/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading