Skip to content

fix(microfrontends): respect packageName field #10383

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

Conversation

chris-olszewski
Copy link
Member

Description

This PR does 2 things:

  • Adds a warning if a package is referenced in microfrontends.json that is not present in the monorepo
  • Uses packageName over the applications key if present

Testing Instructions

Added unit tests.

Verified warnings now are present if you reference a package that isn't found in the monorepo:

[0 olszewski@macbookpro] /Users/olszewski/code/vercel/microfrontends $ turbo_dev --skip-infer dev -F nextjs-app-marketing -F nextjs-app-docs --dry=json > /dev/null
turbo 2.5.1

 WARNING  Unable to find packages referenced in 'microfrontends.json' in workspace.Local proxy will not route to the following applications if they are running locally: nextjs-app-marketing-test

Verified that proxy is now started if every application uses a packageName that differs from the key in applications.

@chris-olszewski chris-olszewski requested a review from a team as a code owner April 24, 2025 18:12
Copy link

vercel bot commented Apr 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-designsystem-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-gatsby-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-kitchensink-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-svelte-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 0:54am

Copy link
Member Author

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer's Guide

@@ -394,6 +394,13 @@ impl Engine<Built> {
self.task_graph.node_weights()
}

pub fn task_ids(&self) -> impl Iterator<Item = &TaskId<'static>> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work is removing the concept of a "root" task node since that only exists due to limitation of Go graphing library.

@@ -20,7 +20,8 @@ pub struct MicrofrontendsConfigs {

#[derive(Debug, Clone, Default, PartialEq)]
struct ConfigInfo {
tasks: HashSet<TaskId<'static>>,
// A map from tasks declared in the configuration to the application that they belong to
tasks: HashMap<TaskId<'static>, String>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to store the application name as that is what the microfrontends local proxy uses to identify locally running applications.

@@ -269,11 +266,31 @@ impl<'a> CommandProvider for MicroFrontendProxyProvider<'a> {
}
}

/// A trait for fetching package information required to execute commands
pub trait PackageInfoProvider {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trait allows us to test the microfrontends command generation without building an entire package graph.

Self {
repo_root,
package_graph,
tasks_in_graph,
tasks_in_graph: tasks_in_graph.cloned().collect(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic over to Engine so we could test this command provider without building an entire task graph.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

.unwrap()
.unwrap();
assert!(
cmd.label().ends_with("--names docs-app"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key here is that we pass the "app name" and not the package name

Self {
repo_root,
package_graph,
tasks_in_graph,
tasks_in_graph: tasks_in_graph.cloned().collect(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants