@ice/mf-runtime 0.0.8 → 0.0.10-beta.0
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.
- package/es2017/FallBack.js +6 -7
- package/es2017/RemoteModule.js +13 -22
- package/es2017/index.d.ts +3 -2
- package/es2017/index.js +28 -2
- package/es2017/mf-global-store.d.ts +7 -2
- package/es2017/mf-global-store.js +32 -1
- package/es2017/types.d.ts +8 -0
- package/esm/FallBack.js +2 -3
- package/esm/RemoteModule.js +13 -22
- package/esm/index.d.ts +3 -2
- package/esm/index.js +28 -2
- package/esm/mf-global-store.d.ts +7 -2
- package/esm/mf-global-store.js +34 -1
- package/esm/types.d.ts +8 -0
- package/package.json +4 -3
package/es2017/FallBack.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
class Component extends React.Component {
|
|
5
4
|
render() {
|
|
6
5
|
const { containerRef } = this.props;
|
|
7
|
-
return /*#__PURE__*/
|
|
6
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
8
7
|
ref: containerRef
|
|
9
8
|
});
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
11
|
export const FallBack = ({ Original, remoteReactDOM, remoteReact })=>{
|
|
13
12
|
const ReactDOM = remoteReactDOM();
|
|
14
|
-
const
|
|
15
|
-
class WrappedComponent extends
|
|
13
|
+
const React1 = remoteReact();
|
|
14
|
+
class WrappedComponent extends React1.Component {
|
|
16
15
|
componentDidMount() {
|
|
17
16
|
this.mountOriginalComponent(true);
|
|
18
17
|
}
|
|
@@ -25,18 +24,18 @@ export const FallBack = ({ Original, remoteReactDOM, remoteReact })=>{
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
mountOriginalComponent(shouldRender = false) {
|
|
28
|
-
const element =
|
|
27
|
+
const element = React1.createElement(Original, this.props);
|
|
29
28
|
const renderMethod = shouldRender ? ReactDOM.render : ReactDOM.hydrate;
|
|
30
29
|
renderMethod(element, this.containerRef.current);
|
|
31
30
|
}
|
|
32
31
|
render() {
|
|
33
|
-
return /*#__PURE__*/
|
|
32
|
+
return /*#__PURE__*/ React.createElement(Component, {
|
|
34
33
|
containerRef: this.containerRef
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
constructor(...args){
|
|
38
37
|
super(...args);
|
|
39
|
-
_define_property(this, "containerRef",
|
|
38
|
+
_define_property(this, "containerRef", React1.createRef());
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
return WrappedComponent;
|
package/es2017/RemoteModule.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
4
1
|
import { loadRemote } from '@module-federation/runtime';
|
|
5
2
|
import * as React from 'react';
|
|
6
3
|
import { useMemo } from 'react';
|
|
7
4
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
8
5
|
import { FallBack } from './FallBack';
|
|
9
6
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
7
|
+
import { getMicroMod } from './mf-global-store';
|
|
10
8
|
export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, componentProps = {}, children = null })=>{
|
|
11
|
-
var _runtime, _runtime1;
|
|
9
|
+
var _microMod, _runtime, _runtime1;
|
|
10
|
+
const microMod = getMicroMod(scope);
|
|
11
|
+
if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
|
|
12
|
+
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
13
|
+
}
|
|
12
14
|
if (publicPath) {
|
|
13
15
|
setFederatedModulePublicPath(scope, publicPath);
|
|
14
16
|
}
|
|
@@ -42,24 +44,13 @@ export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingCompon
|
|
|
42
44
|
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
43
45
|
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
|
|
44
46
|
]);
|
|
45
|
-
const Loading = LoadingComponent || /*#__PURE__*/
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
const ErrorFallback = ({ error })=>ErrorComponent || /*#__PURE__*/ _jsxs("div", {
|
|
49
|
-
children: [
|
|
50
|
-
"远程模块加载失败: ",
|
|
51
|
-
error.message
|
|
52
|
-
]
|
|
53
|
-
});
|
|
47
|
+
const Loading = LoadingComponent || /*#__PURE__*/ React.createElement("div", null, "Loading...");
|
|
48
|
+
const ErrorFallback = ({ error })=>ErrorComponent || /*#__PURE__*/ React.createElement("div", null, "远程模块加载失败: ", error.message);
|
|
54
49
|
if (!Component) return Loading;
|
|
55
|
-
return /*#__PURE__*/
|
|
50
|
+
return /*#__PURE__*/ React.createElement(ErrorBoundary, {
|
|
56
51
|
FallbackComponent: ErrorFallback,
|
|
57
|
-
onError: onError
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
children: children
|
|
62
|
-
}))
|
|
63
|
-
})
|
|
64
|
-
});
|
|
52
|
+
onError: onError
|
|
53
|
+
}, /*#__PURE__*/ React.createElement(React.Suspense, {
|
|
54
|
+
fallback: Loading
|
|
55
|
+
}, /*#__PURE__*/ React.createElement(Component, componentProps, children)));
|
|
65
56
|
};
|
package/es2017/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
6
|
+
export declare function initByMicroMods(microMods: MicroMod[], hostName?: string): void;
|
package/es2017/index.js
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
|
+
import { getBasename } from '@ice/stark-app';
|
|
1
2
|
import { registerPlugins, init as mfInit } from '@module-federation/runtime';
|
|
2
3
|
import { runtimePlugin } from './runtime-plugin';
|
|
3
4
|
import { initGlobalStore } from './mf-global-store';
|
|
4
5
|
export { loadRemote, registerPlugins } from '@module-federation/runtime';
|
|
5
6
|
export * from './FallBack';
|
|
6
7
|
export * from './RemoteModule';
|
|
7
|
-
export function init(options) {
|
|
8
|
-
initGlobalStore(options);
|
|
8
|
+
export function init(options, microMods) {
|
|
9
|
+
initGlobalStore(options, microMods);
|
|
9
10
|
mfInit(options);
|
|
10
11
|
registerPlugins([
|
|
11
12
|
runtimePlugin()
|
|
12
13
|
]);
|
|
13
14
|
}
|
|
15
|
+
// 需要一个稳定的,微应用唯一的 ID
|
|
16
|
+
function generateUniqueId() {
|
|
17
|
+
const prefix = 'ice_standard';
|
|
18
|
+
const baseName = getBasename().split('/').join('_');
|
|
19
|
+
return `${prefix}_${baseName}`;
|
|
20
|
+
}
|
|
21
|
+
export function initByMicroMods(microMods, hostName) {
|
|
22
|
+
const remotes = microMods.map((microMod)=>{
|
|
23
|
+
var _microMod_remoteEntry;
|
|
24
|
+
const isLegacy = !((_microMod_remoteEntry = microMod.remoteEntry) === null || _microMod_remoteEntry === void 0 ? void 0 : _microMod_remoteEntry.match(/\/mf\/remoteEntry\.js$/));
|
|
25
|
+
const remote = {
|
|
26
|
+
name: microMod.moduleFederatedName,
|
|
27
|
+
entry: microMod.remoteEntry,
|
|
28
|
+
alias: microMod.appName,
|
|
29
|
+
extraInfo: Object.assign(microMod.extraInfo || {}, {
|
|
30
|
+
legacy: isLegacy
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
return remote;
|
|
34
|
+
});
|
|
35
|
+
init({
|
|
36
|
+
remotes,
|
|
37
|
+
name: generateUniqueId() || hostName
|
|
38
|
+
}, microMods);
|
|
39
|
+
}
|
|
@@ -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,15 @@ 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
|
};
|
|
23
|
+
getCurrentIceMicroMods?: () => MicroMod[];
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
|
-
export declare function
|
|
26
|
+
export declare function getCurrentModuleName(): string;
|
|
27
|
+
export declare function getMicroMod(scope: string): MicroMod;
|
|
28
|
+
export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
24
29
|
export declare function generateRemoteKey(name: string, entry: string): string;
|
|
25
30
|
export declare function getRemoteInfoFromStore(hostName: string, remoteName: string): RemoteModuleInfo | undefined;
|
|
26
31
|
export declare function hasConflict(hostName: string, remoteName: string): boolean;
|
|
@@ -1,11 +1,42 @@
|
|
|
1
|
-
export function
|
|
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 _store_microMods, _microMods;
|
|
7
|
+
const store = window.__MF_GLOBAL_STORE__;
|
|
8
|
+
const currentModuleName = getCurrentModuleName();
|
|
9
|
+
if (!currentModuleName) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const microMods = (_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _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
19
|
hostRemotes: new Map()
|
|
6
20
|
};
|
|
7
21
|
}
|
|
22
|
+
window.__MF_GLOBAL_STORE__.currentModuleName = options.name;
|
|
23
|
+
if (microMods) {
|
|
24
|
+
if (!window.__MF_GLOBAL_STORE__.microMods) {
|
|
25
|
+
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
26
|
+
}
|
|
27
|
+
window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
|
|
28
|
+
}
|
|
8
29
|
const store = window.__MF_GLOBAL_STORE__;
|
|
30
|
+
if (!window.getCurrentIceMicroMods) {
|
|
31
|
+
window.getCurrentIceMicroMods = ()=>{
|
|
32
|
+
var _store_microMods;
|
|
33
|
+
const currentModuleName = getCurrentModuleName();
|
|
34
|
+
if (!currentModuleName) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
return ((_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(currentModuleName)) || [];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
9
40
|
// 获取或创建 hostInfo
|
|
10
41
|
const existingHostInfo = store.hostRemotes.get(options.name);
|
|
11
42
|
const hostInfo = existingHostInfo || {
|
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
|
+
}
|
package/esm/FallBack.js
CHANGED
|
@@ -4,7 +4,6 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
|
4
4
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
5
5
|
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
|
6
6
|
import { _ as _create_super } from "@swc/helpers/_/_create_super";
|
|
7
|
-
import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
var Component = /*#__PURE__*/ function(_React_Component) {
|
|
10
9
|
"use strict";
|
|
@@ -19,7 +18,7 @@ var Component = /*#__PURE__*/ function(_React_Component) {
|
|
|
19
18
|
key: "render",
|
|
20
19
|
value: function render() {
|
|
21
20
|
var containerRef = this.props.containerRef;
|
|
22
|
-
return /*#__PURE__*/
|
|
21
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
23
22
|
ref: containerRef
|
|
24
23
|
});
|
|
25
24
|
}
|
|
@@ -75,7 +74,7 @@ export var FallBack = function(param) {
|
|
|
75
74
|
{
|
|
76
75
|
key: "render",
|
|
77
76
|
value: function render() {
|
|
78
|
-
return /*#__PURE__*/
|
|
77
|
+
return /*#__PURE__*/ React.createElement(Component, {
|
|
79
78
|
containerRef: this.containerRef
|
|
80
79
|
});
|
|
81
80
|
}
|
package/esm/RemoteModule.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
6
3
|
import { loadRemote } from "@module-federation/runtime";
|
|
7
4
|
import * as React from "react";
|
|
8
5
|
import { useMemo } from "react";
|
|
9
6
|
import { ErrorBoundary } from "react-error-boundary";
|
|
10
7
|
import { FallBack } from "./FallBack";
|
|
11
8
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
9
|
+
import { getMicroMod } from "./mf-global-store";
|
|
12
10
|
export var RemoteModule = function(param) {
|
|
13
11
|
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;
|
|
14
|
-
var _runtime, _runtime1;
|
|
12
|
+
var _microMod, _runtime, _runtime1;
|
|
13
|
+
var microMod = getMicroMod(scope);
|
|
14
|
+
if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
|
|
15
|
+
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
16
|
+
}
|
|
15
17
|
if (publicPath) {
|
|
16
18
|
setFederatedModulePublicPath(scope, publicPath);
|
|
17
19
|
}
|
|
@@ -68,27 +70,16 @@ export var RemoteModule = function(param) {
|
|
|
68
70
|
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
69
71
|
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
|
|
70
72
|
]);
|
|
71
|
-
var Loading = LoadingComponent || /*#__PURE__*/
|
|
72
|
-
children: "Loading..."
|
|
73
|
-
});
|
|
73
|
+
var Loading = LoadingComponent || /*#__PURE__*/ React.createElement("div", null, "Loading...");
|
|
74
74
|
var ErrorFallback = function(param) {
|
|
75
75
|
var error = param.error;
|
|
76
|
-
return ErrorComponent || /*#__PURE__*/
|
|
77
|
-
children: [
|
|
78
|
-
"远程模块加载失败: ",
|
|
79
|
-
error.message
|
|
80
|
-
]
|
|
81
|
-
});
|
|
76
|
+
return ErrorComponent || /*#__PURE__*/ React.createElement("div", null, "远程模块加载失败: ", error.message);
|
|
82
77
|
};
|
|
83
78
|
if (!Component) return Loading;
|
|
84
|
-
return /*#__PURE__*/
|
|
79
|
+
return /*#__PURE__*/ React.createElement(ErrorBoundary, {
|
|
85
80
|
FallbackComponent: ErrorFallback,
|
|
86
|
-
onError: onError
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
children: children
|
|
91
|
-
}))
|
|
92
|
-
})
|
|
93
|
-
});
|
|
81
|
+
onError: onError
|
|
82
|
+
}, /*#__PURE__*/ React.createElement(React.Suspense, {
|
|
83
|
+
fallback: Loading
|
|
84
|
+
}, /*#__PURE__*/ React.createElement(Component, componentProps, children)));
|
|
94
85
|
};
|
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
6
|
+
export declare function initByMicroMods(microMods: MicroMod[], hostName?: string): void;
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
|
+
import { getBasename } from "@ice/stark-app";
|
|
1
2
|
import { registerPlugins, init as mfInit } from "@module-federation/runtime";
|
|
2
3
|
import { runtimePlugin } from "./runtime-plugin";
|
|
3
4
|
import { initGlobalStore } from "./mf-global-store";
|
|
4
5
|
export { loadRemote, registerPlugins } from "@module-federation/runtime";
|
|
5
6
|
export * from "./FallBack";
|
|
6
7
|
export * from "./RemoteModule";
|
|
7
|
-
export function init(options) {
|
|
8
|
-
initGlobalStore(options);
|
|
8
|
+
export function init(options, microMods) {
|
|
9
|
+
initGlobalStore(options, microMods);
|
|
9
10
|
mfInit(options);
|
|
10
11
|
registerPlugins([
|
|
11
12
|
runtimePlugin()
|
|
12
13
|
]);
|
|
13
14
|
}
|
|
15
|
+
// 需要一个稳定的,微应用唯一的 ID
|
|
16
|
+
function generateUniqueId() {
|
|
17
|
+
var prefix = "ice_standard";
|
|
18
|
+
var baseName = getBasename().split("/").join("_");
|
|
19
|
+
return "".concat(prefix, "_").concat(baseName);
|
|
20
|
+
}
|
|
21
|
+
export function initByMicroMods(microMods, hostName) {
|
|
22
|
+
var remotes = microMods.map(function(microMod) {
|
|
23
|
+
var _microMod_remoteEntry;
|
|
24
|
+
var isLegacy = !((_microMod_remoteEntry = microMod.remoteEntry) === null || _microMod_remoteEntry === void 0 ? void 0 : _microMod_remoteEntry.match(/\/mf\/remoteEntry\.js$/));
|
|
25
|
+
var remote = {
|
|
26
|
+
name: microMod.moduleFederatedName,
|
|
27
|
+
entry: microMod.remoteEntry,
|
|
28
|
+
alias: microMod.appName,
|
|
29
|
+
extraInfo: Object.assign(microMod.extraInfo || {}, {
|
|
30
|
+
legacy: isLegacy
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
return remote;
|
|
34
|
+
});
|
|
35
|
+
init({
|
|
36
|
+
remotes: remotes,
|
|
37
|
+
name: generateUniqueId() || hostName
|
|
38
|
+
}, microMods);
|
|
39
|
+
}
|
package/esm/mf-global-store.d.ts
CHANGED
|
@@ -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,15 @@ 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
|
};
|
|
23
|
+
getCurrentIceMicroMods?: () => MicroMod[];
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
|
-
export declare function
|
|
26
|
+
export declare function getCurrentModuleName(): string;
|
|
27
|
+
export declare function getMicroMod(scope: string): MicroMod;
|
|
28
|
+
export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
24
29
|
export declare function generateRemoteKey(name: string, entry: string): string;
|
|
25
30
|
export declare function getRemoteInfoFromStore(hostName: string, remoteName: string): RemoteModuleInfo | undefined;
|
|
26
31
|
export declare function hasConflict(hostName: string, remoteName: string): boolean;
|
package/esm/mf-global-store.js
CHANGED
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
-
export function
|
|
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 _store_microMods, _microMods;
|
|
8
|
+
var store = window.__MF_GLOBAL_STORE__;
|
|
9
|
+
var currentModuleName = getCurrentModuleName();
|
|
10
|
+
if (!currentModuleName) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
var microMods = (_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _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
22
|
hostRemotes: new Map()
|
|
7
23
|
};
|
|
8
24
|
}
|
|
25
|
+
window.__MF_GLOBAL_STORE__.currentModuleName = options.name;
|
|
26
|
+
if (microMods) {
|
|
27
|
+
if (!window.__MF_GLOBAL_STORE__.microMods) {
|
|
28
|
+
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
29
|
+
}
|
|
30
|
+
window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
|
|
31
|
+
}
|
|
9
32
|
var store = window.__MF_GLOBAL_STORE__;
|
|
33
|
+
if (!window.getCurrentIceMicroMods) {
|
|
34
|
+
window.getCurrentIceMicroMods = function() {
|
|
35
|
+
var _store_microMods;
|
|
36
|
+
var currentModuleName = getCurrentModuleName();
|
|
37
|
+
if (!currentModuleName) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return ((_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(currentModuleName)) || [];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
10
43
|
// 获取或创建 hostInfo
|
|
11
44
|
var existingHostInfo = store.hostRemotes.get(options.name);
|
|
12
45
|
var hostInfo = existingHostInfo || {
|
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.
|
|
3
|
+
"version": "0.0.10-beta.0",
|
|
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/*",
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"registry": "https://registry.npmjs.org"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"react": "^16 || ^17 || ^18"
|
|
72
|
+
"react": "^16 || ^17 || ^18",
|
|
73
|
+
"@ice/stark-app": "^1.5.0"
|
|
73
74
|
},
|
|
74
75
|
"license": "MIT"
|
|
75
76
|
}
|