|
1 | 1 | # Controlled Vendor Sharing
|
2 | 2 |
|
3 |
| -Dynamic Vendor Sharing is an application that implements a control panel in the runtime plugin for module federation 1.5 in rspack or `@module-federation/enhanced`. The control panel allows you to deterministically manage and modify the rules for shared modules, as well as upgrade or downgrade applications based on the inputs from the React form. |
| 3 | +This example demonstrates a runtime plugin implementation for Module Federation that provides dynamic control over shared module versions. It allows you to deterministically manage and modify shared module versions across federated applications using a control panel interface and localStorage persistence. |
4 | 4 |
|
5 | 5 | ## Features
|
6 | 6 |
|
7 |
| -- Runtime plugin that implements rules for module sharing. |
8 |
| -- React form for modifying the rules. |
9 |
| -- Ability to upgrade or downgrade applications. |
10 |
| -- `app1` and `app2` exposing different button components. |
| 7 | +- Runtime plugin for dynamic version control of shared modules |
| 8 | +- Control panel UI for managing shared module versions |
| 9 | +- Persistent version settings using localStorage (`formDataVMSC` key) |
| 10 | +- Support for upgrading/downgrading shared module versions |
| 11 | +- E2E tests to verify version control functionality |
11 | 12 |
|
12 | 13 | ## Main Components
|
13 | 14 |
|
14 |
| -### `./app1/control-share.ts` |
| 15 | +### `control-share.ts` |
15 | 16 |
|
16 |
| -This is the runtime plugin that implements the rules for module federation. |
| 17 | +A runtime plugin that implements version control for Module Federation. Key features: |
| 18 | +- Implements the `FederationRuntimePlugin` interface |
| 19 | +- Uses localStorage to persist version preferences |
| 20 | +- Handles version resolution and module sharing between applications |
| 21 | +- Manages share scope mapping and instance tracking |
17 | 22 |
|
18 |
| -### `./app1/src/ControlPanel.js` |
| 23 | +### E2E Tests (`checkAutomaticVendorApps.cy.ts`) |
19 | 24 |
|
20 |
| -This is a React form that allows for the modification of rules implemented in `control-share.ts`. |
| 25 | +Comprehensive E2E tests that verify: |
| 26 | +- Initial shared module versions |
| 27 | +- Version override functionality through localStorage |
| 28 | +- UI updates reflecting version changes |
| 29 | +- Button component rendering with correct version information |
21 | 30 |
|
22 |
| -# Running Demo |
| 31 | +## Running Demo |
23 | 32 |
|
24 | 33 | Run `pnpm run start`. This will build and serve both `app1` and `app2` on ports 3001 and 3002 respectively.
|
25 | 34 |
|
26 |
| -- [localhost:3001](http://localhost:3001/) |
27 |
| -- [localhost:3002](http://localhost:3002/) |
| 35 | +- [localhost:3001](http://localhost:3001/) - Host application with control panel |
| 36 | +- [localhost:3002](http://localhost:3002/) - Remote application |
28 | 37 |
|
29 |
| -# Running Cypress E2E Tests |
| 38 | +## Running Cypress E2E Tests |
30 | 39 |
|
31 |
| -To run tests in interactive mode, run `npm run cypress:debug` from the root directory of the project. It will open Cypress Test Runner and allow to run tests in interactive mode. [More info about "How to run tests"](../../cypress/README.md#how-to-run-tests) |
| 40 | +To run tests in interactive mode: |
| 41 | +```bash |
| 42 | +npm run cypress:debug |
| 43 | +``` |
32 | 44 |
|
33 |
| -To build app and run test in headless mode, run `yarn e2e:ci`. It will build app and run tests for this workspace in headless mode. If tets failed cypress will create `cypress` directory in sample root folder with screenshots and videos. |
| 45 | +To run tests in headless mode: |
| 46 | +```bash |
| 47 | +yarn e2e:ci |
| 48 | +``` |
34 | 49 |
|
35 |
| -["Best Practices, Rules amd more interesting information here](../../cypress/README.md) |
| 50 | +For failed tests, screenshots and videos will be saved in the `cypress` directory. |
| 51 | + |
| 52 | +## Implementation Details |
| 53 | + |
| 54 | +The control panel allows you to: |
| 55 | +- View current versions of shared modules (react, react-dom, lodash) |
| 56 | +- Override versions for specific applications |
| 57 | +- Save settings to localStorage |
| 58 | +- Clear settings and reload to default versions |
| 59 | + |
| 60 | +The runtime plugin (`control-share.ts`) handles: |
| 61 | +- Version resolution based on localStorage settings |
| 62 | +- Share scope management |
| 63 | +- Instance tracking and updates |
| 64 | +- Cross-application module sharing rules |
0 commit comments