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: shareable runtime #3018

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2d5f114
feat(enhanced): custom plugin hooks
ScriptedAlchemy Sep 7, 2024
d489991
fix: support multi runtime chunk
ScriptedAlchemy Sep 8, 2024
2670170
fix: remove entry patching
ScriptedAlchemy Sep 9, 2024
70beb33
fix: remove entry patching
ScriptedAlchemy Sep 9, 2024
71f5193
fix: remove entry patching
ScriptedAlchemy Sep 9, 2024
6be1290
fix: pass experiments to container plugin
ScriptedAlchemy Sep 9, 2024
6bfe53f
fix: move container entry embedding to next
ScriptedAlchemy Sep 9, 2024
9ebbe76
fix(enhanced): put entry patching behind flag
ScriptedAlchemy Sep 9, 2024
2760ed3
fix(enhanced): put entry patching behind flag
ScriptedAlchemy Sep 9, 2024
f9da09e
fix(enhanced): remove old hoisting code
ScriptedAlchemy Sep 9, 2024
6ebff16
fix(enhanced): remove old hoisting code
ScriptedAlchemy Sep 9, 2024
772e821
fix(enhanced): remove old hoisting code
ScriptedAlchemy Sep 10, 2024
d3c8aea
Update packages/enhanced/src/lib/container/runtime/FederationModulesP…
ScriptedAlchemy Sep 10, 2024
287ddab
fix(enhanced): remove old hoisting code
ScriptedAlchemy Sep 10, 2024
47bd54e
Merge remote-tracking branch 'origin/feat/federation-hooks' into feat…
ScriptedAlchemy Sep 10, 2024
0c35086
fix(enhanced): include container module in all if multiple runtime
ScriptedAlchemy Sep 10, 2024
c084b92
Merge branch 'main' into feat/federation-hooks
ScriptedAlchemy Sep 10, 2024
bed1290
chore: update types
ScriptedAlchemy Sep 10, 2024
a66501a
fix(enhanced): update flag logic to support use host
ScriptedAlchemy Sep 11, 2024
81620e3
chore: update compiler types
ScriptedAlchemy Sep 12, 2024
0cb9794
chore: remove old declarations
ScriptedAlchemy Sep 12, 2024
031322f
chore: remove old declarations
ScriptedAlchemy Sep 12, 2024
d8d1f6e
fix(nextjs-mf): fix types
ScriptedAlchemy Sep 12, 2024
5f0e1c7
fix(enhanced): update wrapper plugin apis
ScriptedAlchemy Sep 12, 2024
490c5e0
fix(enhanced): remove declarations from enhanced
ScriptedAlchemy Sep 12, 2024
d300711
fix(enhanced): shared runtime (#2960)
ScriptedAlchemy Sep 30, 2024
653cb9e
sync with main
ScriptedAlchemy Sep 30, 2024
798a4e7
sync with main
ScriptedAlchemy Sep 30, 2024
6b574e2
sync with main
ScriptedAlchemy Sep 30, 2024
aa6b88d
Merge branch 'main' into shared-runtime
ScriptedAlchemy Sep 30, 2024
9d2c57a
fix: sync with main branch
ScriptedAlchemy Sep 30, 2024
9400a1d
chore: format
ScriptedAlchemy Sep 30, 2024
336c63e
chore: filter federaiton manager off instance
ScriptedAlchemy Sep 30, 2024
043ac9d
Merge branch 'main' into shared-runtime
ScriptedAlchemy Sep 30, 2024
098a6e5
Shared Runtime Staging branch (#3029)
ScriptedAlchemy Oct 1, 2024
5da852c
chore: test fixes
ScriptedAlchemy Oct 1, 2024
5abd1ba
refactor(enhanced): use outgoing connections for graph over mgm
ScriptedAlchemy Oct 1, 2024
3b4708f
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 1, 2024
d85557e
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 2, 2024
f5a7816
chore: lint
ScriptedAlchemy Oct 2, 2024
8c0fb2d
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 3, 2024
0955be8
feat(runtime): add shareable runtime and utility functions
ScriptedAlchemy Oct 8, 2024
42acab2
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 8, 2024
db45027
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 10, 2024
bc24baf
fix(enhanced): remove full federation runtime dep set when minimal ru…
ScriptedAlchemy Oct 11, 2024
c130648
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 11, 2024
5106c5a
Merge remote-tracking branch 'origin/shared-runtime' into shared-runtime
ScriptedAlchemy Oct 11, 2024
b7e8350
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 15, 2024
77c7186
fix: add option to getAllReferncedModules so it does not include init…
ScriptedAlchemy Oct 15, 2024
e4bbbd0
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 15, 2024
37ed459
feat(nextjs-mf): support shareable runtime
ScriptedAlchemy Oct 15, 2024
edfa648
chore: add demo
ScriptedAlchemy Oct 29, 2024
6d8286c
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 29, 2024
7e973d3
chore: add demo
ScriptedAlchemy Oct 29, 2024
8475075
chore: add demo
ScriptedAlchemy Oct 29, 2024
fd3071b
chore: add demo
ScriptedAlchemy Oct 30, 2024
54ac678
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 30, 2024
7ce1aa3
chore: locks
ScriptedAlchemy Oct 30, 2024
4b3901e
chore: ci test
ScriptedAlchemy Oct 30, 2024
621a10c
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 30, 2024
1c8172f
chore: ci test
ScriptedAlchemy Oct 30, 2024
c5a5554
chore: ci test
ScriptedAlchemy Oct 30, 2024
712b42b
chore: ci test
ScriptedAlchemy Oct 30, 2024
6c523f1
chore: use external runtime on shop
ScriptedAlchemy Oct 30, 2024
457da10
test: add test cases for shareable runtime
ScriptedAlchemy Oct 31, 2024
60312e3
test: add test cases for shareable runtime
ScriptedAlchemy Oct 31, 2024
28c24df
fix: use tapPromise instead of async
ScriptedAlchemy Oct 31, 2024
f236bd1
fix: use tapPromise instead of async
ScriptedAlchemy Oct 31, 2024
15c487c
fix: revert refactor
ScriptedAlchemy Oct 31, 2024
b995b29
Merge branch 'main' into shared-runtime
ScriptedAlchemy Oct 31, 2024
11c4aba
chore: remove old tsignores
ScriptedAlchemy Oct 31, 2024
88e139b
chore: remove old tsignores
ScriptedAlchemy Oct 31, 2024
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
14 changes: 14 additions & 0 deletions .changeset/ai-eager-cat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@module-federation/enhanced": minor
---

Introduce minimal runtime and experiment options for FederationRuntimePlugin.

- Added support for minimal federation runtime dependency in `FederationRuntimeDependency` class.
- Introduced `experiments` property to `EmbedFederationRuntimePlugin` class.
- Enhanced `FederationRuntimePlugin` to support both standard and minimal runtime dependencies.
- Added logic to handle `useMinimalRuntime` option.
- Conditionally modified entry file path based on the runtime mode.
- Adjusted constructor to initialize new experimental paths and dependencies.
- Modified `getTemplate` and `getFilePath` methods to accommodate minimal runtime.
- Updated `setRuntimeAlias` and `apply` methods to utilize new experiment options and embedded paths.
11 changes: 11 additions & 0 deletions .changeset/ai-eager-tiger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@module-federation/runtime": patch
---

Refactored the script loading mechanism to use a more generalized loaderHook.

- Replaced `createScriptHook` with `loaderHook` across various functions.
- Updated `loadEntryScript` function to use `loaderHook.lifecycle.createScript`.
- Modified `loadEntryDom` function to accept `loaderHook` instead of `createScriptHook`.
- Adjusted `loadEntryNode` function to handle `loaderHook.lifecycle.createScript`.
- Streamlined the handling of script loading in `getRemoteEntry`.
11 changes: 11 additions & 0 deletions .changeset/ai-gentle-eagle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@module-federation/runtime": patch
---

Added support for defining and setting a shareable runtime globally to enhance modularity and reusability within the Federation system.

- Defined a `ShareableRuntime` type encapsulating the core functionalities of the module federation.
- Introduced `__SHAREABLE_RUNTIME__` to the `Federation` interface to store the `ShareableRuntime`.
- Implemented `setGlobalShareableRuntime` function to set the shareable runtime if not already set.
- Modified `FederationManager` methods (`preloadRemote`, `registerRemotes`, `registerPlugins`) to use the spread operator for cleaner code.
- Initialized the global shareable runtime at the module's root with key components like `FederationManager`, `FederationHost`, etc.
8 changes: 8 additions & 0 deletions .changeset/ai-noisy-fox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@module-federation/runtime": patch
---

- Added optional `bundlerId` parameter to FederationHost constructor.
- Modified default logic to choose `bundlerId` if provided, otherwise fallback to `getBuilderId()`.
- Updated `getGlobalFederationInstance` function to accept and utilize an optional `builderId`.
- Ensured internal checks compare with the provided `bundlerId` for consistency in federation instances lookup.
12 changes: 12 additions & 0 deletions .changeset/ai-sleepy-bear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@module-federation/runtime": minor
---

Refactor initialization and management of Federation instances with the new FederationManager class.

- Introduced FederationManager class to encapsulate federation management logic.
- FederationManager class now handles the initialization and operation methods.
- Methods `init`, `loadRemote`, `loadShare`, `loadShareSync`, `preloadRemote`, `registerRemotes`, and `registerPlugins` are now routed through an instance of FederationManager.
- Updated test to exclude `FederationManager` from index.ts exports.
- Minor code cleanup and added import for `getBuilderId` in `index.ts`.
- Removed direct manipulation of a singleton FederationHost instance and replaced it with the FederationManager pattern.
6 changes: 6 additions & 0 deletions .changeset/ai-sleepy-fox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@module-federation/enhanced": patch
---

Use shareable runtime from federation global over custom global top levels
```
5 changes: 5 additions & 0 deletions .changeset/real-baboons-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/nextjs-mf': minor
---

support shareable runtime with experiments `use-host`. Defaults to `hoisted`
5 changes: 5 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ jobs:
uses: ./.github/workflows/e2e-runtime.yml
secrets: inherit

e2e-shareable-runtime:
needs: checkout-install
uses: ./.github/workflows/e2e-shareruntime.yml
secrets: inherit

e2e-manifest:
needs: checkout-install
uses: ./.github/workflows/e2e-manifest.yml
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/e2e-shareruntime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# .github/workflows/e2e-share-host.yml
name: E2E Test for Shared Runtime

on:
workflow_call:

jobs:
e2e-runtime:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Pnpm
run: corepack enable

- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'pnpm'

- name: Set Nx SHA
uses: nrwl/nx-set-shas@v3

- name: Set SKIP_DEVTOOLS_POSTINSTALL environment variable
run: echo "SKIP_DEVTOOLS_POSTINSTALL=true" >> $GITHUB_ENV

- name: Install Dependencies
run: pnpm install

- name: Install Cypress
run: npx cypress install

- name: Run Build for All
run: npx nx run-many --targets=build --projects=tag:type:pkg

- name: Run condition check script
id: check-ci
run: node tools/scripts/ci-is-affected.mjs --appName=3005-runtime-host

- name: E2E Test for Runtime Demo
if: steps.check-ci.outcome == 'success'
run: npx kill-port --port 3005,3006,3007 && pnpm run app:shareable:dev & echo "done" && sleep 20 && npx nx run-many --target=test:e2e --projects=3005-share-host --parallel=1 && lsof -ti tcp:3005,3006,3007 | xargs kill
2 changes: 1 addition & 1 deletion apps/3000-home/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion apps/3001-shop/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
3 changes: 3 additions & 0 deletions apps/3001-shop/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const nextConfig = {
isServer ? 'ssr' : 'chunks'
}/remoteEntry.js`,
},
experiments: {
federationRuntime: 'use-host',
},
exposes: {
'./useCustomRemoteHook': './components/useCustomRemoteHook',
'./WebpackSvg': './components/WebpackSvg',
Expand Down
2 changes: 1 addition & 1 deletion apps/3002-checkout/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
11 changes: 11 additions & 0 deletions apps/shared-runtime/3005-share-host/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
7 changes: 7 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: nxE2EPreset(__filename, { cypressDir: 'cypress' }),
defaultCommandTimeout: 20000,
});
80 changes: 80 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { getH1, getH3 } from '../support/app.po';

describe('3005-share-host/', () => {
beforeEach(() => cy.visit('/'));

describe('Welcome message', () => {
it('should display welcome message', () => {
getH1().contains('Runtime Demo');
});
});

describe('Image checks', () => {
it('should check that the home-webpack-png and remote1-webpack-png images are not 404', () => {
// Get the src attribute of the home-webpack-png image
cy.get('img.home-webpack-png')
.invoke('attr', 'src')
.then((src) => {
if (!src) {
throw new Error('src must not be empty');
}
cy.log(src);
cy.request(src).its('status').should('eq', 200);
});

// Get the src attribute of the shop-webpack-png image
cy.get('img.remote1-webpack-png')
.invoke('attr', 'src')
.then((src) => {
if (!src) {
throw new Error('src must not be empty');
}
// Send a GET request to the src URL
cy.request(src).its('status').should('eq', 200);
});
});

it('should check that the home-webpack-svg and remote1-webpack-svg images are not 404', () => {
// Get the src attribute of the home-webpack-png image
cy.get('img.home-webpack-svg')
.invoke('attr', 'src')
.then((src) => {
if (!src) {
throw new Error('src must not be empty');
}
cy.log(src);
cy.request(src).its('status').should('eq', 200);
});

// Get the src attribute of the shop-webpack-png image
cy.get('img.remote1-webpack-svg')
.invoke('attr', 'src')
.then((src) => {
if (!src) {
throw new Error('src must not be empty');
}
// Send a GET request to the src URL
cy.request(src).its('status').should('eq', 200);
});
});
});

describe('Shared react hook check', () => {
it('should display text which comes from remote1 hook', () => {
cy.get('.remote1-text')
.invoke('html')
.should('equal', 'Custom hook from localhost:3006 works!');
});
});

describe('dynamic remote check', () => {
describe('dynamic-remote/ButtonOldAnt', () => {
it('should display remote button', () => {
cy.get('button.test-remote2').contains('Button');
});
it('should use host shared(antd)', () => {
cy.get('button.test-remote2').contains('Button from [email protected]');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
3 changes: 3 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getH1 = () => cy.get('h1');
export const getH2 = () => cy.get('h2');
export const getH3 = () => cy.get('h3');
35 changes: 35 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference types="cypress" />

// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}

// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
// console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.ts using ES2015 syntax:
import './commands';
20 changes: 20 additions & 0 deletions apps/shared-runtime/3005-share-host/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["cypress", "node"],
"sourceMap": false
},
"include": [
"**/*.ts",
"**/*.js",
"../cypress.config.ts",
"../**/*.cy.ts",
"../**/*.cy.tsx",
"../**/*.cy.js",
"../**/*.cy.jsx",
"../**/*.d.ts"
]
}
17 changes: 17 additions & 0 deletions apps/shared-runtime/3005-share-host/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "share-host",
"private": true,
"version": "0.0.0",
"devDependencies": {
"@module-federation/core": "workspace:*",
"@module-federation/runtime": "workspace:*",
"@module-federation/typescript": "workspace:*",
"@module-federation/enhanced": "workspace:*",
"@module-federation/dts-plugin": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"react-refresh": "0.14.0"
},
"dependencies": {
"antd": "4.24.15"
}
}
Loading
Loading