@ice/mf-runtime 1.0.0 → 1.0.1-beta.1
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/mf-global-store.d.ts +2 -2
- package/es2017/mf-global-store.js +31 -12
- package/esm/mf-global-store.d.ts +2 -2
- package/esm/mf-global-store.js +69 -14
- package/package.json +1 -1
|
@@ -18,12 +18,12 @@ declare global {
|
|
|
18
18
|
remotes: Map<string, RemoteModuleInfo>;
|
|
19
19
|
hostRemotes: Map<string, HostRemoteInfo>;
|
|
20
20
|
microMods?: Map<string, MicroMod[]>;
|
|
21
|
-
|
|
21
|
+
currentModuleNames?: string[];
|
|
22
22
|
};
|
|
23
23
|
getCurrentIceMicroMods?: () => MicroMod[];
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function getCurrentModuleNames(): string[];
|
|
27
27
|
export declare function getMicroMod(scope: string): MicroMod;
|
|
28
28
|
export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
29
29
|
export declare function generateRemoteKey(name: string, entry: string): string;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function getCurrentModuleNames() {
|
|
2
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__.
|
|
3
|
+
return ((_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleNames) || [];
|
|
4
4
|
}
|
|
5
5
|
export function getMicroMod(scope) {
|
|
6
|
-
var _store_microMods, _microMods;
|
|
7
6
|
const store = window.__MF_GLOBAL_STORE__;
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
7
|
+
const currentModuleNames = getCurrentModuleNames();
|
|
8
|
+
if (currentModuleNames.length === 0) {
|
|
10
9
|
return undefined;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
// 遍历所有当前模块名,查找匹配的 microMod
|
|
12
|
+
for (const moduleName of currentModuleNames){
|
|
13
|
+
var _store_microMods, _microMods;
|
|
14
|
+
const microMods = (_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(moduleName);
|
|
15
|
+
const microMod = (_microMods = microMods) === null || _microMods === void 0 ? void 0 : _microMods.find((microMod)=>microMod.appName === scope);
|
|
16
|
+
if (microMod) {
|
|
17
|
+
return microMod;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
14
21
|
}
|
|
15
22
|
export function initGlobalStore(options, microMods) {
|
|
16
23
|
if (!window.__MF_GLOBAL_STORE__) {
|
|
@@ -19,7 +26,13 @@ export function initGlobalStore(options, microMods) {
|
|
|
19
26
|
hostRemotes: new Map()
|
|
20
27
|
};
|
|
21
28
|
}
|
|
22
|
-
|
|
29
|
+
// 将新的模块名添加到数组中(如果不存在)
|
|
30
|
+
if (!window.__MF_GLOBAL_STORE__.currentModuleNames) {
|
|
31
|
+
window.__MF_GLOBAL_STORE__.currentModuleNames = [];
|
|
32
|
+
}
|
|
33
|
+
if (!window.__MF_GLOBAL_STORE__.currentModuleNames.includes(options.name)) {
|
|
34
|
+
window.__MF_GLOBAL_STORE__.currentModuleNames.push(options.name);
|
|
35
|
+
}
|
|
23
36
|
if (microMods) {
|
|
24
37
|
if (!window.__MF_GLOBAL_STORE__.microMods) {
|
|
25
38
|
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
@@ -29,12 +42,18 @@ export function initGlobalStore(options, microMods) {
|
|
|
29
42
|
const store = window.__MF_GLOBAL_STORE__;
|
|
30
43
|
if (!window.getCurrentIceMicroMods) {
|
|
31
44
|
window.getCurrentIceMicroMods = ()=>{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!currentModuleName) {
|
|
45
|
+
const currentModuleNames = getCurrentModuleNames();
|
|
46
|
+
if (currentModuleNames.length === 0) {
|
|
35
47
|
return [];
|
|
36
48
|
}
|
|
37
|
-
|
|
49
|
+
// 合并所有当前模块的 microMods
|
|
50
|
+
const allMicroMods = [];
|
|
51
|
+
for (const moduleName of currentModuleNames){
|
|
52
|
+
var _store_microMods;
|
|
53
|
+
const microMods = ((_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(moduleName)) || [];
|
|
54
|
+
allMicroMods.push(...microMods);
|
|
55
|
+
}
|
|
56
|
+
return allMicroMods;
|
|
38
57
|
};
|
|
39
58
|
}
|
|
40
59
|
// 获取或创建 hostInfo
|
package/esm/mf-global-store.d.ts
CHANGED
|
@@ -18,12 +18,12 @@ declare global {
|
|
|
18
18
|
remotes: Map<string, RemoteModuleInfo>;
|
|
19
19
|
hostRemotes: Map<string, HostRemoteInfo>;
|
|
20
20
|
microMods?: Map<string, MicroMod[]>;
|
|
21
|
-
|
|
21
|
+
currentModuleNames?: string[];
|
|
22
22
|
};
|
|
23
23
|
getCurrentIceMicroMods?: () => MicroMod[];
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function getCurrentModuleNames(): string[];
|
|
27
27
|
export declare function getMicroMod(scope: string): MicroMod;
|
|
28
28
|
export declare function initGlobalStore(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
29
29
|
export declare function generateRemoteKey(name: string, entry: string): string;
|
package/esm/mf-global-store.js
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
-
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
export function getCurrentModuleNames() {
|
|
3
4
|
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__.
|
|
5
|
+
return ((_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleNames) || [];
|
|
5
6
|
}
|
|
6
7
|
export function getMicroMod(scope) {
|
|
7
|
-
var _store_microMods, _microMods;
|
|
8
8
|
var store = window.__MF_GLOBAL_STORE__;
|
|
9
|
-
var
|
|
10
|
-
if (
|
|
9
|
+
var currentModuleNames = getCurrentModuleNames();
|
|
10
|
+
if (currentModuleNames.length === 0) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
14
|
+
try {
|
|
15
|
+
// 遍历所有当前模块名,查找匹配的 microMod
|
|
16
|
+
for(var _iterator = currentModuleNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
17
|
+
var moduleName = _step.value;
|
|
18
|
+
var _store_microMods, _microMods;
|
|
19
|
+
var microMods = (_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(moduleName);
|
|
20
|
+
var microMod = (_microMods = microMods) === null || _microMods === void 0 ? void 0 : _microMods.find(function(microMod) {
|
|
21
|
+
return microMod.appName === scope;
|
|
22
|
+
});
|
|
23
|
+
if (microMod) {
|
|
24
|
+
return microMod;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
_didIteratorError = true;
|
|
29
|
+
_iteratorError = err;
|
|
30
|
+
} finally{
|
|
31
|
+
try {
|
|
32
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
33
|
+
_iterator.return();
|
|
34
|
+
}
|
|
35
|
+
} finally{
|
|
36
|
+
if (_didIteratorError) {
|
|
37
|
+
throw _iteratorError;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
17
42
|
}
|
|
18
43
|
export function initGlobalStore(options, microMods) {
|
|
19
44
|
if (!window.__MF_GLOBAL_STORE__) {
|
|
@@ -22,7 +47,13 @@ export function initGlobalStore(options, microMods) {
|
|
|
22
47
|
hostRemotes: new Map()
|
|
23
48
|
};
|
|
24
49
|
}
|
|
25
|
-
|
|
50
|
+
// 将新的模块名添加到数组中(如果不存在)
|
|
51
|
+
if (!window.__MF_GLOBAL_STORE__.currentModuleNames) {
|
|
52
|
+
window.__MF_GLOBAL_STORE__.currentModuleNames = [];
|
|
53
|
+
}
|
|
54
|
+
if (!window.__MF_GLOBAL_STORE__.currentModuleNames.includes(options.name)) {
|
|
55
|
+
window.__MF_GLOBAL_STORE__.currentModuleNames.push(options.name);
|
|
56
|
+
}
|
|
26
57
|
if (microMods) {
|
|
27
58
|
if (!window.__MF_GLOBAL_STORE__.microMods) {
|
|
28
59
|
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
@@ -32,12 +63,36 @@ export function initGlobalStore(options, microMods) {
|
|
|
32
63
|
var store = window.__MF_GLOBAL_STORE__;
|
|
33
64
|
if (!window.getCurrentIceMicroMods) {
|
|
34
65
|
window.getCurrentIceMicroMods = function() {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
if (!currentModuleName) {
|
|
66
|
+
var currentModuleNames = getCurrentModuleNames();
|
|
67
|
+
if (currentModuleNames.length === 0) {
|
|
38
68
|
return [];
|
|
39
69
|
}
|
|
40
|
-
|
|
70
|
+
// 合并所有当前模块的 microMods
|
|
71
|
+
var allMicroMods = [];
|
|
72
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
73
|
+
try {
|
|
74
|
+
for(var _iterator = currentModuleNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
75
|
+
var moduleName = _step.value;
|
|
76
|
+
var _allMicroMods;
|
|
77
|
+
var _store_microMods;
|
|
78
|
+
var _$microMods = ((_store_microMods = store.microMods) === null || _store_microMods === void 0 ? void 0 : _store_microMods.get(moduleName)) || [];
|
|
79
|
+
(_allMicroMods = allMicroMods).push.apply(_allMicroMods, _to_consumable_array(_$microMods));
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_didIteratorError = true;
|
|
83
|
+
_iteratorError = err;
|
|
84
|
+
} finally{
|
|
85
|
+
try {
|
|
86
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
87
|
+
_iterator.return();
|
|
88
|
+
}
|
|
89
|
+
} finally{
|
|
90
|
+
if (_didIteratorError) {
|
|
91
|
+
throw _iteratorError;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return allMicroMods;
|
|
41
96
|
};
|
|
42
97
|
}
|
|
43
98
|
// 获取或创建 hostInfo
|