@ice/mf-runtime 0.0.8 → 0.0.9
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/RemoteModule.js +6 -1
- 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/RemoteModule.js +6 -1
- 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/RemoteModule.js
CHANGED
|
@@ -7,8 +7,13 @@ 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 })=>{
|
|
11
|
-
var _runtime, _runtime1;
|
|
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
|
+
}
|
|
12
17
|
if (publicPath) {
|
|
13
18
|
setFederatedModulePublicPath(scope, publicPath);
|
|
14
19
|
}
|
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/RemoteModule.js
CHANGED
|
@@ -9,9 +9,14 @@ 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;
|
|
14
|
-
var _runtime, _runtime1;
|
|
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
|
+
}
|
|
15
20
|
if (publicPath) {
|
|
16
21
|
setFederatedModulePublicPath(scope, publicPath);
|
|
17
22
|
}
|
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.9",
|
|
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
|
}
|