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(angular): add dynamic federation support to mfe generator #9551

Merged
merged 1 commit into from Mar 29, 2022

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Mar 28, 2022

Current Behavior

Our generators currently have no method of generating a Module Federation setup that uses Dynamic Federation.

Expected Behavior

Our setup-mfe generator should support creating a Dynamic Federation setup.

Only host apps really need to understand the concept of Dynamic Federation as it is within the host app that the wiring of the remote apps takes place.

We want to promote a Dynamic Federation pattern that consists of:

  • Build once, deploy anywhere strategy
  • A host application that resolves its remotes' locations at runtime
  • A JSON file with a structure of: Record<string, string> matching: remoteName: remoteUrl
  • A method of fetching the JSON file at runtime to initialise the remote containers.
  • A method for routing to the module exposed by the remote apps

Therefore we should aim to achieve 3 things:

  • setup-mfe should be able to create a host app with a pattern for dynamic federation
  • host generator should have a --dynamic flag that will specify that the host should be created following the dynamic federation pattern
  • remote generator should NOT have a --dynamic flag, as it makes no sense for a remote itself. HOWEVER, the logic of adding the remote to a specified --host SHOULD still take into account if the host app has been configured with dynamic federation in mind.

@nx-cloud
Copy link

nx-cloud bot commented Mar 28, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5c37b61. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 8 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Mar 28, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/9ttFPzVhihDWFaSq4qxN6o37pChM
✅ Preview: https://nx-dev-git-fork-coly010-angular-dynamic-federation-nrwl.vercel.app

Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

);

if (!hostMfeConfigPath || !tree.exists(hostMfeConfigPath)) {
throw new Error(
Copy link
Member

@jaysoo jaysoo Mar 29, 2022

Choose a reason for hiding this comment

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

Maybe mention mfe.manfest.json as well in case the user meant to use dynamic host -- maybe they renamed the file without realizing the problem.

Can we do some validation on mfe.config.js to guard on this edge case? i.e. that the host should be using dynamic remotes, but the dynamic manifest isn't found.

Copy link
Member

@jaysoo jaysoo left a comment

Choose a reason for hiding this comment

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

Looks good overall.

There is an edge case where the user may rename the config files (mfe.config.js and mfe.manifest.json), and it's not obvious that this will cause minor issues later when generating new remotes.

@Coly010 Coly010 merged commit 5378128 into nrwl:master Mar 29, 2022
@Coly010 Coly010 deleted the angular/dynamic-federation branch March 29, 2022 15:57
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants