@ice/mf-runtime 0.0.7 → 0.0.8-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,40 +7,45 @@ import { useMemo } from 'react';
7
7
  import { ErrorBoundary } from 'react-error-boundary';
8
8
  import { FallBack } from './FallBack';
9
9
  import { setFederatedModulePublicPath } from './set-public-path';
10
+ import { getMicroMod } from './mf-global-store';
10
11
  export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, componentProps = {}, children = null })=>{
12
+ var _microMod, _runtime, _runtime1;
13
+ const microMod = getMicroMod(scope);
14
+ if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
15
+ setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
16
+ }
11
17
  if (publicPath) {
12
18
  setFederatedModulePublicPath(scope, publicPath);
13
19
  }
14
20
  const Component = useMemo(()=>{
15
21
  if (!module || !scope) return null;
16
- const RemoteComponent = /*#__PURE__*/ React.lazy(async ()=>{
17
- try {
18
- const remoteModule = await loadRemote(`${scope}/${module}`);
19
- if (runtime) {
20
- const { react, reactDOM } = runtime;
21
- const wrappedComponent = FallBack({
22
+ return /*#__PURE__*/ React.lazy(async ()=>{
23
+ var _remoteModule;
24
+ const remoteModule = await loadRemote(`${scope}/${module}`);
25
+ if (!((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default)) {
26
+ return {
27
+ default: remoteModule
28
+ };
29
+ }
30
+ if (runtime) {
31
+ const { react, reactDOM } = runtime;
32
+ return {
33
+ default: FallBack({
22
34
  Original: remoteModule.default,
23
35
  remoteReact: ()=>react,
24
36
  remoteReactDOM: ()=>reactDOM
25
- });
26
- return {
27
- default: wrappedComponent
28
- };
29
- }
30
- return {
31
- default: remoteModule.default
37
+ })
32
38
  };
33
- } catch (error) {
34
- console.error(`Error loading remote module ${scope}/${module}:`, error);
35
- throw error;
36
39
  }
40
+ return {
41
+ default: remoteModule.default
42
+ };
37
43
  });
38
- return RemoteComponent;
39
44
  }, [
40
45
  module,
41
46
  scope,
42
- runtime.react,
43
- runtime.reactDOM
47
+ (_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
48
+ (_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
44
49
  ]);
45
50
  const Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
46
51
  children: "Loading..."
@@ -51,17 +56,15 @@ export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingCompon
51
56
  error.message
52
57
  ]
53
58
  });
54
- if (Component) {
55
- return /*#__PURE__*/ _jsx(ErrorBoundary, {
56
- FallbackComponent: ErrorFallback,
57
- onError: onError,
58
- children: /*#__PURE__*/ _jsx(React.Suspense, {
59
- fallback: null,
60
- children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
61
- children: children
62
- }))
63
- })
64
- });
65
- }
66
- return Loading;
59
+ if (!Component) return Loading;
60
+ return /*#__PURE__*/ _jsx(ErrorBoundary, {
61
+ FallbackComponent: ErrorFallback,
62
+ onError: onError,
63
+ children: /*#__PURE__*/ _jsx(React.Suspense, {
64
+ fallback: Loading,
65
+ children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
66
+ children: children
67
+ }))
68
+ })
69
+ });
67
70
  };
package/es2017/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ExtendedUserOptions } from './types';
1
+ import type { ExtendedUserOptions, MicroMod } from './types';
2
2
  export { loadRemote, registerPlugins } from '@module-federation/runtime';
3
3
  export * from './FallBack';
4
4
  export * from './RemoteModule';
5
- export declare function init(options: ExtendedUserOptions): void;
5
+ export declare function init(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
package/es2017/index.js CHANGED
@@ -4,8 +4,8 @@ import { initGlobalStore } from './mf-global-store';
4
4
  export { loadRemote, registerPlugins } from '@module-federation/runtime';
5
5
  export * from './FallBack';
6
6
  export * from './RemoteModule';
7
- export function init(options) {
8
- initGlobalStore(options);
7
+ export function init(options, microMods) {
8
+ initGlobalStore(options, microMods);
9
9
  mfInit(options);
10
10
  registerPlugins([
11
11
  runtimePlugin()
@@ -1,4 +1,4 @@
1
- import type { ExtraInfo, ExtendedUserOptions } from './types';
1
+ import type { ExtraInfo, ExtendedUserOptions, MicroMod } from './types';
2
2
  export interface RemoteModuleInfo {
3
3
  key: string;
4
4
  name: string;
@@ -17,10 +17,14 @@ declare global {
17
17
  __MF_GLOBAL_STORE__: {
18
18
  remotes: Map<string, RemoteModuleInfo>;
19
19
  hostRemotes: Map<string, HostRemoteInfo>;
20
+ microMods: Map<string, MicroMod[]>;
21
+ currentModuleName?: string;
20
22
  };
21
23
  }
22
24
  }
23
- export declare function initGlobalStore(options: ExtendedUserOptions): void;
25
+ export declare function getCurrentModuleName(): string;
26
+ export declare function getMicroMod(scope: string): MicroMod;
27
+ export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
24
28
  export declare function generateRemoteKey(name: string, entry: string): string;
25
29
  export declare function getRemoteInfoFromStore(hostName: string, remoteName: string): RemoteModuleInfo | undefined;
26
30
  export declare function hasConflict(hostName: string, remoteName: string): boolean;
@@ -1,10 +1,29 @@
1
- export function initGlobalStore(options) {
1
+ export function getCurrentModuleName() {
2
+ var _window___MF_GLOBAL_STORE__;
3
+ return (_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleName;
4
+ }
5
+ export function getMicroMod(scope) {
6
+ var _microMods;
7
+ const store = window.__MF_GLOBAL_STORE__;
8
+ const currentModuleName = getCurrentModuleName();
9
+ if (!currentModuleName) {
10
+ return undefined;
11
+ }
12
+ const microMods = store.microMods.get(currentModuleName);
13
+ return (_microMods = microMods) === null || _microMods === void 0 ? void 0 : _microMods.find((microMod)=>microMod.appName === scope);
14
+ }
15
+ export function initGlobalStore(options, microMods) {
2
16
  if (!window.__MF_GLOBAL_STORE__) {
3
17
  window.__MF_GLOBAL_STORE__ = {
4
18
  remotes: new Map(),
5
- hostRemotes: new Map()
19
+ hostRemotes: new Map(),
20
+ microMods: new Map(),
21
+ currentModuleName: options.name
6
22
  };
7
23
  }
24
+ if (microMods) {
25
+ window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
26
+ }
8
27
  const store = window.__MF_GLOBAL_STORE__;
9
28
  // 获取或创建 hostInfo
10
29
  const existingHostInfo = store.hostRemotes.get(options.name);
package/es2017/types.d.ts CHANGED
@@ -10,3 +10,11 @@ export type ExtendedRemote = Remote & {
10
10
  export interface ExtendedUserOptions extends Omit<UserOptions, 'remotes'> {
11
11
  remotes: ExtendedRemote[];
12
12
  }
13
+ export interface MicroMod {
14
+ appName: string;
15
+ version: string;
16
+ publicPath: string;
17
+ remoteEntry: string;
18
+ moduleFederatedName: string;
19
+ extraInfo?: ExtraInfo;
20
+ }
@@ -9,45 +9,52 @@ import { useMemo } from "react";
9
9
  import { ErrorBoundary } from "react-error-boundary";
10
10
  import { FallBack } from "./FallBack";
11
11
  import { setFederatedModulePublicPath } from "./set-public-path";
12
+ import { getMicroMod } from "./mf-global-store";
12
13
  export var RemoteModule = function(param) {
13
14
  var module = param.module, scope = param.scope, runtime = param.runtime, publicPath = param.publicPath, LoadingComponent = param.LoadingComponent, ErrorComponent = param.ErrorComponent, onError = param.onError, _param_componentProps = param.componentProps, componentProps = _param_componentProps === void 0 ? {} : _param_componentProps, _param_children = param.children, children = _param_children === void 0 ? null : _param_children;
15
+ var _microMod, _runtime, _runtime1;
16
+ var microMod = getMicroMod(scope);
17
+ if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
18
+ setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
19
+ }
14
20
  if (publicPath) {
15
21
  setFederatedModulePublicPath(scope, publicPath);
16
22
  }
17
23
  var Component = useMemo(function() {
18
24
  if (!module || !scope) return null;
19
- var RemoteComponent = /*#__PURE__*/ React.lazy(/*#__PURE__*/ _async_to_generator(function() {
20
- var remoteModule, react, reactDOM, wrappedComponent, error;
25
+ return /*#__PURE__*/ React.lazy(/*#__PURE__*/ _async_to_generator(function() {
26
+ var _remoteModule, remoteModule, react, reactDOM;
21
27
  return _ts_generator(this, function(_state) {
22
28
  switch(_state.label){
23
29
  case 0:
24
- _state.trys.push([
25
- 0,
26
- 2,
27
- ,
28
- 3
29
- ]);
30
30
  return [
31
31
  4,
32
32
  loadRemote("".concat(scope, "/").concat(module))
33
33
  ];
34
34
  case 1:
35
35
  remoteModule = _state.sent();
36
+ if (!((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default)) {
37
+ return [
38
+ 2,
39
+ {
40
+ default: remoteModule
41
+ }
42
+ ];
43
+ }
36
44
  if (runtime) {
37
45
  react = runtime.react, reactDOM = runtime.reactDOM;
38
- wrappedComponent = FallBack({
39
- Original: remoteModule.default,
40
- remoteReact: function() {
41
- return react;
42
- },
43
- remoteReactDOM: function() {
44
- return reactDOM;
45
- }
46
- });
47
46
  return [
48
47
  2,
49
48
  {
50
- default: wrappedComponent
49
+ default: FallBack({
50
+ Original: remoteModule.default,
51
+ remoteReact: function() {
52
+ return react;
53
+ },
54
+ remoteReactDOM: function() {
55
+ return reactDOM;
56
+ }
57
+ })
51
58
  }
52
59
  ];
53
60
  }
@@ -57,23 +64,14 @@ export var RemoteModule = function(param) {
57
64
  default: remoteModule.default
58
65
  }
59
66
  ];
60
- case 2:
61
- error = _state.sent();
62
- console.error("Error loading remote module ".concat(scope, "/").concat(module, ":"), error);
63
- throw error;
64
- case 3:
65
- return [
66
- 2
67
- ];
68
67
  }
69
68
  });
70
69
  }));
71
- return RemoteComponent;
72
70
  }, [
73
71
  module,
74
72
  scope,
75
- runtime.react,
76
- runtime.reactDOM
73
+ (_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
74
+ (_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
77
75
  ]);
78
76
  var Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
79
77
  children: "Loading..."
@@ -87,17 +85,15 @@ export var RemoteModule = function(param) {
87
85
  ]
88
86
  });
89
87
  };
90
- if (Component) {
91
- return /*#__PURE__*/ _jsx(ErrorBoundary, {
92
- FallbackComponent: ErrorFallback,
93
- onError: onError,
94
- children: /*#__PURE__*/ _jsx(React.Suspense, {
95
- fallback: null,
96
- children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
97
- children: children
98
- }))
99
- })
100
- });
101
- }
102
- return Loading;
88
+ if (!Component) return Loading;
89
+ return /*#__PURE__*/ _jsx(ErrorBoundary, {
90
+ FallbackComponent: ErrorFallback,
91
+ onError: onError,
92
+ children: /*#__PURE__*/ _jsx(React.Suspense, {
93
+ fallback: Loading,
94
+ children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
95
+ children: children
96
+ }))
97
+ })
98
+ });
103
99
  };
package/esm/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ExtendedUserOptions } from './types';
1
+ import type { ExtendedUserOptions, MicroMod } from './types';
2
2
  export { loadRemote, registerPlugins } from '@module-federation/runtime';
3
3
  export * from './FallBack';
4
4
  export * from './RemoteModule';
5
- export declare function init(options: ExtendedUserOptions): void;
5
+ export declare function init(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
package/esm/index.js CHANGED
@@ -4,8 +4,8 @@ import { initGlobalStore } from "./mf-global-store";
4
4
  export { loadRemote, registerPlugins } from "@module-federation/runtime";
5
5
  export * from "./FallBack";
6
6
  export * from "./RemoteModule";
7
- export function init(options) {
8
- initGlobalStore(options);
7
+ export function init(options, microMods) {
8
+ initGlobalStore(options, microMods);
9
9
  mfInit(options);
10
10
  registerPlugins([
11
11
  runtimePlugin()
@@ -1,4 +1,4 @@
1
- import type { ExtraInfo, ExtendedUserOptions } from './types';
1
+ import type { ExtraInfo, ExtendedUserOptions, MicroMod } from './types';
2
2
  export interface RemoteModuleInfo {
3
3
  key: string;
4
4
  name: string;
@@ -17,10 +17,14 @@ declare global {
17
17
  __MF_GLOBAL_STORE__: {
18
18
  remotes: Map<string, RemoteModuleInfo>;
19
19
  hostRemotes: Map<string, HostRemoteInfo>;
20
+ microMods: Map<string, MicroMod[]>;
21
+ currentModuleName?: string;
20
22
  };
21
23
  }
22
24
  }
23
- export declare function initGlobalStore(options: ExtendedUserOptions): void;
25
+ export declare function getCurrentModuleName(): string;
26
+ export declare function getMicroMod(scope: string): MicroMod;
27
+ export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
24
28
  export declare function generateRemoteKey(name: string, entry: string): string;
25
29
  export declare function getRemoteInfoFromStore(hostName: string, remoteName: string): RemoteModuleInfo | undefined;
26
30
  export declare function hasConflict(hostName: string, remoteName: string): boolean;
@@ -1,11 +1,32 @@
1
1
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
- export function initGlobalStore(options) {
2
+ export function getCurrentModuleName() {
3
+ var _window___MF_GLOBAL_STORE__;
4
+ return (_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleName;
5
+ }
6
+ export function getMicroMod(scope) {
7
+ var _microMods;
8
+ var store = window.__MF_GLOBAL_STORE__;
9
+ var currentModuleName = getCurrentModuleName();
10
+ if (!currentModuleName) {
11
+ return undefined;
12
+ }
13
+ var microMods = store.microMods.get(currentModuleName);
14
+ return (_microMods = microMods) === null || _microMods === void 0 ? void 0 : _microMods.find(function(microMod) {
15
+ return microMod.appName === scope;
16
+ });
17
+ }
18
+ export function initGlobalStore(options, microMods) {
3
19
  if (!window.__MF_GLOBAL_STORE__) {
4
20
  window.__MF_GLOBAL_STORE__ = {
5
21
  remotes: new Map(),
6
- hostRemotes: new Map()
22
+ hostRemotes: new Map(),
23
+ microMods: new Map(),
24
+ currentModuleName: options.name
7
25
  };
8
26
  }
27
+ if (microMods) {
28
+ window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
29
+ }
9
30
  var store = window.__MF_GLOBAL_STORE__;
10
31
  // 获取或创建 hostInfo
11
32
  var existingHostInfo = store.hostRemotes.get(options.name);
package/esm/types.d.ts CHANGED
@@ -10,3 +10,11 @@ export type ExtendedRemote = Remote & {
10
10
  export interface ExtendedUserOptions extends Omit<UserOptions, 'remotes'> {
11
11
  remotes: ExtendedRemote[];
12
12
  }
13
+ export interface MicroMod {
14
+ appName: string;
15
+ version: string;
16
+ publicPath: string;
17
+ remoteEntry: string;
18
+ moduleFederatedName: string;
19
+ extraInfo?: ExtraInfo;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ice/mf-runtime",
3
- "version": "0.0.7",
3
+ "version": "0.0.8-beta.2",
4
4
  "description": "ice mf runtime",
5
5
  "files": [
6
6
  "esm",
@@ -22,7 +22,7 @@
22
22
  "default": "./esm/index.js"
23
23
  }
24
24
  },
25
- "./*": "./*"
25
+ "./types": "./esm/types.js"
26
26
  },
27
27
  "sideEffects": [
28
28
  "dist/*",