Skip to content

WIP: feat: add createInstance api #3874

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/cuddly-spoons-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

chore(runtime): add RUNTIME-009 error code
5 changes: 5 additions & 0 deletions .changeset/few-games-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

refactor(runtime): rename FederationRuntimePlugin to ModuleFederationRuntimePlugin
5 changes: 5 additions & 0 deletions .changeset/good-apricots-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': minor
---

feat(runtime): add createInstance api and deprecate init
11 changes: 11 additions & 0 deletions .changeset/poor-pillows-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@module-federation/webpack-bundler-runtime': patch
'@module-federation/bridge-react': patch
'@module-federation/data-prefetch': patch
'@module-federation/runtime-core': patch
'@module-federation/modern-js': patch
'@module-federation/runtime': patch
'@module-federation/node': patch
---

chore: rename FederationHost to ModuleFederation
4 changes: 2 additions & 2 deletions apps/manifest-demo/webpack-host/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';

export default function (): FederationRuntimePlugin {
export default function (): ModuleFederationRuntimePlugin {
return {
name: 'custom-plugin-build',
beforeInit(args) {
Expand Down
4 changes: 2 additions & 2 deletions apps/manifest-demo/webpack-host/src/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
export default function (): FederationRuntimePlugin {
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';
export default function (): ModuleFederationRuntimePlugin {
return {
name: 'custom-plugin',
beforeInit(args) {
Expand Down
2 changes: 1 addition & 1 deletion apps/node-host/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';

export default function () {
return {
Expand Down
4 changes: 2 additions & 2 deletions apps/router-demo/router-host-2000/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import './App.css';
import BridgeReactPlugin from '@module-federation/bridge-react/plugin';
import { ErrorBoundary } from 'react-error-boundary';
import Remote1AppNew from 'remote1/app';
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import { Spin } from 'antd';

const fallbackPlugin: () => FederationRuntimePlugin = function () {
const fallbackPlugin: () => ModuleFederationRuntimePlugin = function () {
return {
name: 'fallback-plugin',
errorLoadRemote(args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 2. Entry File Loading (afterResolve): Attempts to load from a backup service
*/

import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';

interface LifecycleBasedConfig {
backupEntryUrl?: string;
Expand All @@ -18,7 +18,7 @@ interface LifecycleBasedConfig {

export const createLifecycleBasedPlugin = (
config: LifecycleBasedConfig = {},
): FederationRuntimePlugin => {
): ModuleFederationRuntimePlugin => {
const {
backupEntryUrl = 'http://localhost:2002/mf-manifest.json',
errorMessage = 'Module loading failed, please try again later',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* Use this when you don't need different handling strategies for different error types.
*/

import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';

interface SimpleConfig {
errorMessage?: string;
}

export const createSimplePlugin = (
config: SimpleConfig = {},
): FederationRuntimePlugin => {
): ModuleFederationRuntimePlugin => {
const { errorMessage = 'Module loading failed, please try again later' } =
config;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import {
createLifecycleBasedPlugin,
createSimplePlugin,
Expand All @@ -15,7 +15,7 @@ interface FallbackConfig {

const fallbackPlugin = (
config: FallbackConfig = {},
): FederationRuntimePlugin => {
): ModuleFederationRuntimePlugin => {
const {
backupEntryUrl = 'http://localhost:2002/mf-manifest.json',
errorMessage = 'Module loading failed, please try again later',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';

// The default external policy is version-first: the version with a higher version is used preferentially, even if the version is not loaded. Internally, it must be compatible with the previous logic, mainly loading
const sharedStrategy: () => FederationRuntimePlugin = () => ({
const sharedStrategy: () => ModuleFederationRuntimePlugin = () => ({
name: 'shared-strategy',
beforeInit(args) {
const { userOptions, shareInfo } = args;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';

// The default external policy is version-first: the version with a higher version is used preferentially, even if the version is not loaded. Internally, it must be compatible with the previous logic, mainly loading
const sharedStrategy: () => FederationRuntimePlugin = () => ({
const sharedStrategy: () => ModuleFederationRuntimePlugin = () => ({
name: 'shared-strategy',
beforeInit(args) {
const { userOptions, shareInfo } = args;
Expand Down
4 changes: 2 additions & 2 deletions apps/runtime-demo/3005-runtime-host/src/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
export default function (): FederationRuntimePlugin {
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';
export default function (): ModuleFederationRuntimePlugin {
return {
name: 'custom-plugin',
beforeInit(args) {
Expand Down
10 changes: 5 additions & 5 deletions apps/website-new/docs/en/blog/error-load-remote.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ import React from 'react';
import { init, loadRemote } from '@module-federation/enhanced/runtime';
import { RetryPlugin } from '@module-federation/retry-plugin';

+ const fallbackPlugin: () => FederationRuntimePlugin = function () {
+ const fallbackPlugin: () => ModuleFederationRuntimePlugin = function () {
+ return {
+ name: 'fallback-plugin',
+ errorLoadRemote(args) {
Expand Down Expand Up @@ -263,7 +263,7 @@ export default defineConfig({

```tsx
// src/runtime-plugin/fallback.ts
import type { FederationRuntimePlugin } from '@module-federation/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/runtime';

interface FallbackConfig {
// Backup service address
Expand All @@ -272,7 +272,7 @@ interface FallbackConfig {
errorMessage?: string;
}

const fallbackPlugin = (config: FallbackConfig = {}): FederationRuntimePlugin => {
const fallbackPlugin = (config: FallbackConfig = {}): ModuleFederationRuntimePlugin => {
const {
backupEntryUrl = 'http://localhost:2002/mf-manifest.json',
errorMessage = 'Module loading failed, please try again later'
Expand Down Expand Up @@ -435,9 +435,9 @@ return () => ({
If you don't need to distinguish between error types, you can use a generic error handling solution:

```ts
import type { FederationRuntimePlugin } from '@module-federation/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/runtime';

const fallbackPlugin = (errorMessage = 'Module loading failed, please try again later'): FederationRuntimePlugin => {
const fallbackPlugin = (errorMessage = 'Module loading failed, please try again later'): ModuleFederationRuntimePlugin => {
return {
name: 'fallback-plugin',
async errorLoadRemote() {
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/docs/en/configure/experiments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This object contains flags related to build-time optimizations that can affect t
- **Required:** No
- **Default:** `false`

When set to `true`, this option defines the `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN` global constant as `true` during the build. In the `@module-federation/runtime-core`, this prevents the `snapshotPlugin()` and `generatePreloadAssetsPlugin()` from being included and initialized within the FederationHost.
When set to `true`, this option defines the `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN` global constant as `true` during the build. In the `@module-federation/runtime-core`, this prevents the `snapshotPlugin()` and `generatePreloadAssetsPlugin()` from being included and initialized within the Module Federation instance.

**Impact:**
* **Benefit:** Can reduce the overall bundle size of the Module Federation runtime by excluding the code for these two plugins.
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/docs/en/configure/exposes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Example:
```jsx
module.exports = {
plugins: [
new ModuleFederation({
new ModuleFederationPlugin({
name: 'provider',
exposes: {
// Note: "./" is not supported. Exporting as `.` indicates a default export
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/docs/en/configure/getpublicpath.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you're using module federation webpack plugin and want to set a dynamic publi
```ts title="rspack.config.ts"
module.exports = {
plugins: [
new ModuleFederation({
new ModuleFederationPlugin({
name: 'provider',
exposes: {
'./Button': './src/components/Button.tsx',
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/docs/en/configure/implementation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For example, if you want to use a specific version of `@module-federation/runtim
module.exports = {
// ...other configurations
plugins: [
new ModuleFederation({
new ModuleFederationPlugin({
// ...other Module Federation options
implementation: require.resolve('@module-federation/runtime-tools'),
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/docs/en/configure/remotes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface PluginRemoteOptions {
```js
module.exports = {
plugins: [
new ModuleFederation({
new ModuleFederationPlugin({
name: 'host',
// The `remotes` below defines two remotes, named `manifest-provider` for the project started on port 3011 and `js-entry-provider` for the project started on port 3012
remotes: {
Expand Down
6 changes: 3 additions & 3 deletions apps/website-new/docs/en/configure/runtimeplugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Once set, runtime plugins will be automatically injected and used during the bui
To create a runtime plugin file, you can name it `custom-runtime-plugin.ts`:

```ts title="custom-runtime-plugin.ts"
import { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
import { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';

export default function (): FederationRuntimePlugin {
export default function (): ModuleFederationRuntimePlugin {
return {
name: 'custom-plugin-build',
beforeInit(args) {
Expand All @@ -36,7 +36,7 @@ Then, apply this plugin in your build configuration:
const path = require('path');
module.exports = {
plugins: [
new ModuleFederation({
new ModuleFederationPlugin({
name: 'host',
remotes: {
'manifest-provider':
Expand Down
Loading