@ice/mf-runtime 1.0.3-beta.1 → 1.0.3-beta.3
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/README.md +1 -221
- package/es2017/RemoteModule.js +21 -73
- package/es2017/index.d.ts +0 -2
- package/es2017/index.js +3 -5
- package/es2017/runtime-plugin.js +27 -29
- package/es2017/types.d.ts +0 -67
- package/es2017/types.js +1 -18
- package/esm/RemoteModule.js +30 -73
- package/esm/index.d.ts +0 -2
- package/esm/index.js +3 -5
- package/esm/runtime-plugin.js +37 -33
- package/esm/types.d.ts +0 -67
- package/esm/types.js +1 -20
- package/package.json +2 -12
- package/es2017/__tests__/plugin-manager.test.d.ts +0 -1
- package/es2017/__tests__/plugin-manager.test.js +0 -291
- package/es2017/__tests__/setup.d.ts +0 -1
- package/es2017/__tests__/setup.js +0 -28
- package/es2017/plugin-manager.d.ts +0 -74
- package/es2017/plugin-manager.js +0 -128
- package/esm/__tests__/plugin-manager.test.d.ts +0 -1
- package/esm/__tests__/plugin-manager.test.js +0 -343
- package/esm/__tests__/setup.d.ts +0 -1
- package/esm/__tests__/setup.js +0 -43
- package/esm/plugin-manager.d.ts +0 -74
- package/esm/plugin-manager.js +0 -201
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
4
|
-
import { EnhancedPluginManager, getEnhancedPluginManager, registerEnhancedPlugins } from "../plugin-manager";
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
describe("EnhancedPluginManager", function() {
|
|
7
|
-
var manager;
|
|
8
|
-
beforeEach(function() {
|
|
9
|
-
manager = new EnhancedPluginManager();
|
|
10
|
-
});
|
|
11
|
-
describe("Plugin Registration", function() {
|
|
12
|
-
it("should register an enhanced plugin", function() {
|
|
13
|
-
var enhancedPlugin = {
|
|
14
|
-
name: "test-enhanced",
|
|
15
|
-
wrapComponent: function(Component) {
|
|
16
|
-
return Component;
|
|
17
|
-
},
|
|
18
|
-
injectProps: function(props) {
|
|
19
|
-
return props;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
manager.register(enhancedPlugin);
|
|
23
|
-
var plugins = manager.getPlugins();
|
|
24
|
-
expect(plugins).toHaveLength(1);
|
|
25
|
-
expect(plugins[0].name).toBe("test-enhanced");
|
|
26
|
-
});
|
|
27
|
-
it("should replace existing plugin with same name", function() {
|
|
28
|
-
var plugin1 = {
|
|
29
|
-
name: "test-plugin",
|
|
30
|
-
wrapComponent: function(Component) {
|
|
31
|
-
return Component;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var plugin2 = {
|
|
35
|
-
name: "test-plugin",
|
|
36
|
-
injectProps: function(props) {
|
|
37
|
-
return props;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
manager.register(plugin1);
|
|
41
|
-
manager.register(plugin2);
|
|
42
|
-
var plugins = manager.getPlugins();
|
|
43
|
-
expect(plugins).toHaveLength(1);
|
|
44
|
-
expect(plugins[0]).toBe(plugin2);
|
|
45
|
-
});
|
|
46
|
-
it("should register multiple plugins", function() {
|
|
47
|
-
var plugins = [
|
|
48
|
-
{
|
|
49
|
-
name: "plugin1",
|
|
50
|
-
wrapComponent: function(Component) {
|
|
51
|
-
return Component;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "plugin2",
|
|
56
|
-
injectProps: function(props) {
|
|
57
|
-
return props;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
manager.registerPlugins(plugins);
|
|
62
|
-
expect(manager.getPlugins()).toHaveLength(2);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("Component Wrapping", function() {
|
|
66
|
-
it("should wrap component with single plugin", function() {
|
|
67
|
-
var TestComponent = function() {
|
|
68
|
-
return React.createElement("div", null, "test");
|
|
69
|
-
};
|
|
70
|
-
var mockWrapper = vi.fn(function(Component) {
|
|
71
|
-
return Component;
|
|
72
|
-
});
|
|
73
|
-
var plugin = {
|
|
74
|
-
name: "wrapper-plugin",
|
|
75
|
-
wrapComponent: mockWrapper
|
|
76
|
-
};
|
|
77
|
-
manager.register(plugin);
|
|
78
|
-
var context = {
|
|
79
|
-
remoteName: "test-remote",
|
|
80
|
-
moduleName: "test-module",
|
|
81
|
-
props: {
|
|
82
|
-
test: true
|
|
83
|
-
},
|
|
84
|
-
React: React,
|
|
85
|
-
ReactDOM: undefined
|
|
86
|
-
};
|
|
87
|
-
var wrappedComponent = manager.wrapComponent(TestComponent, context);
|
|
88
|
-
expect(mockWrapper).toHaveBeenCalledWith(TestComponent, context);
|
|
89
|
-
expect(wrappedComponent).toBe(TestComponent);
|
|
90
|
-
});
|
|
91
|
-
it("should apply multiple wrappers in order", function() {
|
|
92
|
-
var TestComponent = function() {
|
|
93
|
-
return React.createElement("div", null, "original");
|
|
94
|
-
};
|
|
95
|
-
var Wrapper1 = function() {
|
|
96
|
-
return React.createElement("div", null, "wrapper1");
|
|
97
|
-
};
|
|
98
|
-
var Wrapper2 = function() {
|
|
99
|
-
return React.createElement("div", null, "wrapper2");
|
|
100
|
-
};
|
|
101
|
-
var plugin1 = {
|
|
102
|
-
name: "wrapper1",
|
|
103
|
-
wrapComponent: function() {
|
|
104
|
-
return Wrapper1;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var plugin2 = {
|
|
108
|
-
name: "wrapper2",
|
|
109
|
-
wrapComponent: function() {
|
|
110
|
-
return Wrapper2;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
// 注册顺序很重要
|
|
114
|
-
manager.register(plugin1);
|
|
115
|
-
manager.register(plugin2);
|
|
116
|
-
var context = {
|
|
117
|
-
remoteName: "test-remote",
|
|
118
|
-
moduleName: "test-module",
|
|
119
|
-
props: {},
|
|
120
|
-
React: React,
|
|
121
|
-
ReactDOM: undefined
|
|
122
|
-
};
|
|
123
|
-
var result = manager.wrapComponent(TestComponent, context);
|
|
124
|
-
// plugin2 应该最后执行,所以返回 Wrapper2
|
|
125
|
-
expect(result).toBe(Wrapper2);
|
|
126
|
-
});
|
|
127
|
-
it("should handle wrapper errors gracefully", function() {
|
|
128
|
-
var TestComponent = function() {
|
|
129
|
-
return React.createElement("div", null, "test");
|
|
130
|
-
};
|
|
131
|
-
var consoleSpy = vi.spyOn(console, "error").mockImplementation(function() {});
|
|
132
|
-
var plugin = {
|
|
133
|
-
name: "error-plugin",
|
|
134
|
-
wrapComponent: function() {
|
|
135
|
-
throw new Error("Wrapper error");
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
manager.register(plugin);
|
|
139
|
-
var context = {
|
|
140
|
-
remoteName: "test-remote",
|
|
141
|
-
moduleName: "test-module",
|
|
142
|
-
props: {},
|
|
143
|
-
React: React,
|
|
144
|
-
ReactDOM: undefined
|
|
145
|
-
};
|
|
146
|
-
var result = manager.wrapComponent(TestComponent, context);
|
|
147
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Error applying wrapper from plugin "error-plugin"'), expect.any(Error));
|
|
148
|
-
expect(result).toBe(TestComponent); // 应该返回原始组件
|
|
149
|
-
consoleSpy.mockRestore();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
describe("Props Injection", function() {
|
|
153
|
-
it("should inject props with single plugin", function() {
|
|
154
|
-
var mockInjector = vi.fn(function(props) {
|
|
155
|
-
return _object_spread_props(_object_spread({}, props), {
|
|
156
|
-
injected: true
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
var plugin = {
|
|
160
|
-
name: "injector-plugin",
|
|
161
|
-
injectProps: mockInjector
|
|
162
|
-
};
|
|
163
|
-
manager.register(plugin);
|
|
164
|
-
var context = {
|
|
165
|
-
remoteName: "test-remote",
|
|
166
|
-
moduleName: "test-module"
|
|
167
|
-
};
|
|
168
|
-
var result = manager.injectProps({
|
|
169
|
-
original: true
|
|
170
|
-
}, context);
|
|
171
|
-
expect(mockInjector).toHaveBeenCalledWith({
|
|
172
|
-
original: true
|
|
173
|
-
}, context);
|
|
174
|
-
expect(result).toEqual({
|
|
175
|
-
original: true,
|
|
176
|
-
injected: true
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
it("should apply multiple injectors in order", function() {
|
|
180
|
-
var plugin1 = {
|
|
181
|
-
name: "injector1",
|
|
182
|
-
injectProps: function(props) {
|
|
183
|
-
return _object_spread_props(_object_spread({}, props), {
|
|
184
|
-
step1: true
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var plugin2 = {
|
|
189
|
-
name: "injector2",
|
|
190
|
-
injectProps: function(props) {
|
|
191
|
-
return _object_spread_props(_object_spread({}, props), {
|
|
192
|
-
step2: true
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
manager.register(plugin1);
|
|
197
|
-
manager.register(plugin2);
|
|
198
|
-
var context = {
|
|
199
|
-
remoteName: "test-remote",
|
|
200
|
-
moduleName: "test-module"
|
|
201
|
-
};
|
|
202
|
-
var result = manager.injectProps({
|
|
203
|
-
original: true
|
|
204
|
-
}, context);
|
|
205
|
-
expect(result).toEqual({
|
|
206
|
-
original: true,
|
|
207
|
-
step1: true,
|
|
208
|
-
step2: true
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
it("should handle injection errors gracefully", function() {
|
|
212
|
-
var consoleSpy = vi.spyOn(console, "error").mockImplementation(function() {});
|
|
213
|
-
var plugin = {
|
|
214
|
-
name: "error-plugin",
|
|
215
|
-
injectProps: function() {
|
|
216
|
-
throw new Error("Injection error");
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
manager.register(plugin);
|
|
220
|
-
var context = {
|
|
221
|
-
remoteName: "test-remote",
|
|
222
|
-
moduleName: "test-module"
|
|
223
|
-
};
|
|
224
|
-
var result = manager.injectProps({
|
|
225
|
-
original: true
|
|
226
|
-
}, context);
|
|
227
|
-
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Error injecting props from plugin "error-plugin"'), expect.any(Error));
|
|
228
|
-
expect(result).toEqual({
|
|
229
|
-
original: true
|
|
230
|
-
}); // 应该返回原始props
|
|
231
|
-
consoleSpy.mockRestore();
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
describe("Plugin Management", function() {
|
|
235
|
-
it("should get plugin info", function() {
|
|
236
|
-
var wrapperPlugin = {
|
|
237
|
-
name: "wrapper-plugin",
|
|
238
|
-
wrapComponent: function(Component) {
|
|
239
|
-
return Component;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
var injectorPlugin = {
|
|
243
|
-
name: "injector-plugin",
|
|
244
|
-
injectProps: function(props) {
|
|
245
|
-
return props;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var hybridPlugin = {
|
|
249
|
-
name: "hybrid-plugin",
|
|
250
|
-
wrapComponent: function(Component) {
|
|
251
|
-
return Component;
|
|
252
|
-
},
|
|
253
|
-
injectProps: function(props) {
|
|
254
|
-
return props;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
manager.register(wrapperPlugin);
|
|
258
|
-
manager.register(injectorPlugin);
|
|
259
|
-
manager.register(hybridPlugin);
|
|
260
|
-
var info = manager.getPluginInfo();
|
|
261
|
-
expect(info).toHaveLength(3);
|
|
262
|
-
expect(info[0]).toEqual({
|
|
263
|
-
name: "wrapper-plugin",
|
|
264
|
-
hasWrapper: true,
|
|
265
|
-
hasInjector: false
|
|
266
|
-
});
|
|
267
|
-
expect(info[1]).toEqual({
|
|
268
|
-
name: "injector-plugin",
|
|
269
|
-
hasWrapper: false,
|
|
270
|
-
hasInjector: true
|
|
271
|
-
});
|
|
272
|
-
expect(info[2]).toEqual({
|
|
273
|
-
name: "hybrid-plugin",
|
|
274
|
-
hasWrapper: true,
|
|
275
|
-
hasInjector: true
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
it("should remove plugin", function() {
|
|
279
|
-
var plugin = {
|
|
280
|
-
name: "test-plugin",
|
|
281
|
-
wrapComponent: function(Component) {
|
|
282
|
-
return Component;
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
manager.register(plugin);
|
|
286
|
-
expect(manager.getPlugins()).toHaveLength(1);
|
|
287
|
-
var removed = manager.removePlugin("test-plugin");
|
|
288
|
-
expect(removed).toBe(true);
|
|
289
|
-
expect(manager.getPlugins()).toHaveLength(0);
|
|
290
|
-
});
|
|
291
|
-
it("should return false when removing non-existent plugin", function() {
|
|
292
|
-
var removed = manager.removePlugin("non-existent");
|
|
293
|
-
expect(removed).toBe(false);
|
|
294
|
-
});
|
|
295
|
-
it("should clear all plugins", function() {
|
|
296
|
-
manager.register({
|
|
297
|
-
name: "plugin1",
|
|
298
|
-
wrapComponent: function(Component) {
|
|
299
|
-
return Component;
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
manager.register({
|
|
303
|
-
name: "plugin2",
|
|
304
|
-
injectProps: function(props) {
|
|
305
|
-
return props;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
expect(manager.getPlugins()).toHaveLength(2);
|
|
309
|
-
manager.clear();
|
|
310
|
-
expect(manager.getPlugins()).toHaveLength(0);
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
describe("Global Enhanced Plugin Manager", function() {
|
|
314
|
-
beforeEach(function() {
|
|
315
|
-
// 清理全局状态
|
|
316
|
-
getEnhancedPluginManager().clear();
|
|
317
|
-
});
|
|
318
|
-
it("should provide singleton instance", function() {
|
|
319
|
-
var manager1 = getEnhancedPluginManager();
|
|
320
|
-
var manager2 = getEnhancedPluginManager();
|
|
321
|
-
expect(manager1).toBe(manager2);
|
|
322
|
-
});
|
|
323
|
-
it("should register multiple plugins via convenience function", function() {
|
|
324
|
-
var plugins = [
|
|
325
|
-
{
|
|
326
|
-
name: "plugin1",
|
|
327
|
-
wrapComponent: function(Component) {
|
|
328
|
-
return Component;
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
name: "plugin2",
|
|
333
|
-
injectProps: function(props) {
|
|
334
|
-
return props;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
];
|
|
338
|
-
registerEnhancedPlugins(plugins);
|
|
339
|
-
var manager = getEnhancedPluginManager();
|
|
340
|
-
expect(manager.getPlugins()).toHaveLength(2);
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
});
|
package/esm/__tests__/setup.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/__tests__/setup.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import { vi } from "vitest";
|
|
3
|
-
// Test setup for ice-mf-runtime
|
|
4
|
-
// Mock @ice/stark-app dependency
|
|
5
|
-
vi.mock("@ice/stark-app", function() {
|
|
6
|
-
return {
|
|
7
|
-
getBasename: function() {
|
|
8
|
-
return "/app";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
// Mock @module-federation/runtime
|
|
13
|
-
vi.mock("@module-federation/runtime", function() {
|
|
14
|
-
return {
|
|
15
|
-
init: vi.fn(),
|
|
16
|
-
registerPlugins: vi.fn(),
|
|
17
|
-
loadRemote: vi.fn()
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
// Mock performance API
|
|
21
|
-
Object.defineProperty(globalThis, "performance", {
|
|
22
|
-
value: {
|
|
23
|
-
now: function() {
|
|
24
|
-
return Date.now();
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
writable: true
|
|
28
|
-
});
|
|
29
|
-
// Suppress console warnings during tests
|
|
30
|
-
var originalWarn = console.warn;
|
|
31
|
-
console.warn = function() {
|
|
32
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
33
|
-
args[_key] = arguments[_key];
|
|
34
|
-
}
|
|
35
|
-
var _originalWarn;
|
|
36
|
-
var _args__includes, _args_;
|
|
37
|
-
if ((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : (_args__includes = _args_.includes) === null || _args__includes === void 0 ? void 0 : _args__includes.call(_args_, "Warning: ReactDOM.render is no longer supported")) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
(_originalWarn = originalWarn).call.apply(_originalWarn, [
|
|
41
|
-
console
|
|
42
|
-
].concat(_to_consumable_array(args)));
|
|
43
|
-
};
|
package/esm/plugin-manager.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRuntimePlugin, WrapperContext, InjectionContext } from './types';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* 增强插件管理器 - 专门负责管理和执行增强运行时插件
|
|
5
|
-
* 标准 MF 插件交由底层 @module-federation/runtime 管理
|
|
6
|
-
*/
|
|
7
|
-
export declare class EnhancedPluginManager {
|
|
8
|
-
private plugins;
|
|
9
|
-
/**
|
|
10
|
-
* 注册增强插件
|
|
11
|
-
* @param plugin 增强运行时插件
|
|
12
|
-
*/
|
|
13
|
-
register(plugin: EnhancedRuntimePlugin): void;
|
|
14
|
-
/**
|
|
15
|
-
* 注册多个增强插件
|
|
16
|
-
* @param plugins 增强插件数组
|
|
17
|
-
*/
|
|
18
|
-
registerPlugins(plugins: EnhancedRuntimePlugin[]): void;
|
|
19
|
-
/**
|
|
20
|
-
* 获取所有增强插件列表
|
|
21
|
-
* @returns 增强插件数组
|
|
22
|
-
*/
|
|
23
|
-
getPlugins(): EnhancedRuntimePlugin[];
|
|
24
|
-
/**
|
|
25
|
-
* 应用组件包装器
|
|
26
|
-
* 按插件注册顺序依次应用所有组件包装器
|
|
27
|
-
* @param Component 原始组件
|
|
28
|
-
* @param context 包装器上下文
|
|
29
|
-
* @returns 包装后的组件
|
|
30
|
-
*/
|
|
31
|
-
wrapComponent(Component: React.ComponentType, context: WrapperContext): React.ComponentType;
|
|
32
|
-
/**
|
|
33
|
-
* 注入属性
|
|
34
|
-
* 按插件注册顺序依次应用所有属性注入器
|
|
35
|
-
* @param props 原始属性
|
|
36
|
-
* @param context 注入上下文
|
|
37
|
-
* @returns 注入后的属性
|
|
38
|
-
*/
|
|
39
|
-
injectProps(props: Record<string, any>, context: InjectionContext): Record<string, any>;
|
|
40
|
-
/**
|
|
41
|
-
* 获取所有插件信息
|
|
42
|
-
* @returns 插件信息数组
|
|
43
|
-
*/
|
|
44
|
-
getPluginInfo(): Array<{
|
|
45
|
-
name: string;
|
|
46
|
-
hasWrapper: boolean;
|
|
47
|
-
hasInjector: boolean;
|
|
48
|
-
}>;
|
|
49
|
-
/**
|
|
50
|
-
* 移除插件
|
|
51
|
-
* @param name 插件名称
|
|
52
|
-
* @returns 是否成功移除
|
|
53
|
-
*/
|
|
54
|
-
removePlugin(name: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* 清空所有插件
|
|
57
|
-
*/
|
|
58
|
-
clear(): void;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 获取全局增强插件管理器实例
|
|
62
|
-
* @returns 增强插件管理器实例
|
|
63
|
-
*/
|
|
64
|
-
export declare function getEnhancedPluginManager(): EnhancedPluginManager;
|
|
65
|
-
/**
|
|
66
|
-
* 注册多个增强插件(便捷函数)
|
|
67
|
-
* @param plugins 增强插件数组
|
|
68
|
-
*/
|
|
69
|
-
export declare function registerEnhancedPlugins(plugins: EnhancedRuntimePlugin[]): void;
|
|
70
|
-
/**
|
|
71
|
-
* React Hook:使用增强插件管理器
|
|
72
|
-
* @returns 增强插件管理器实例
|
|
73
|
-
*/
|
|
74
|
-
export declare function useEnhancedPluginManager(): EnhancedPluginManager;
|
package/esm/plugin-manager.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
5
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
/**
|
|
8
|
-
* 增强插件管理器 - 专门负责管理和执行增强运行时插件
|
|
9
|
-
* 标准 MF 插件交由底层 @module-federation/runtime 管理
|
|
10
|
-
*/ export var EnhancedPluginManager = /*#__PURE__*/ function() {
|
|
11
|
-
"use strict";
|
|
12
|
-
function EnhancedPluginManager() {
|
|
13
|
-
_class_call_check(this, EnhancedPluginManager);
|
|
14
|
-
_define_property(this, "plugins", []);
|
|
15
|
-
}
|
|
16
|
-
_create_class(EnhancedPluginManager, [
|
|
17
|
-
{
|
|
18
|
-
/**
|
|
19
|
-
* 注册增强插件
|
|
20
|
-
* @param plugin 增强运行时插件
|
|
21
|
-
*/ key: "register",
|
|
22
|
-
value: function register(plugin) {
|
|
23
|
-
// 检查是否已存在同名插件
|
|
24
|
-
var existingIndex = this.plugins.findIndex(function(p) {
|
|
25
|
-
return p.name === plugin.name;
|
|
26
|
-
});
|
|
27
|
-
if (existingIndex >= 0) {
|
|
28
|
-
console.warn('Enhanced plugin "'.concat(plugin.name, '" already exists, replacing it.'));
|
|
29
|
-
this.plugins[existingIndex] = plugin;
|
|
30
|
-
} else {
|
|
31
|
-
this.plugins.push(plugin);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
/**
|
|
37
|
-
* 注册多个增强插件
|
|
38
|
-
* @param plugins 增强插件数组
|
|
39
|
-
*/ key: "registerPlugins",
|
|
40
|
-
value: function registerPlugins(plugins) {
|
|
41
|
-
var _this = this;
|
|
42
|
-
plugins.forEach(function(plugin) {
|
|
43
|
-
return _this.register(plugin);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
/**
|
|
49
|
-
* 获取所有增强插件列表
|
|
50
|
-
* @returns 增强插件数组
|
|
51
|
-
*/ key: "getPlugins",
|
|
52
|
-
value: function getPlugins() {
|
|
53
|
-
return _to_consumable_array(this.plugins);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
/**
|
|
58
|
-
* 应用组件包装器
|
|
59
|
-
* 按插件注册顺序依次应用所有组件包装器
|
|
60
|
-
* @param Component 原始组件
|
|
61
|
-
* @param context 包装器上下文
|
|
62
|
-
* @returns 包装后的组件
|
|
63
|
-
*/ key: "wrapComponent",
|
|
64
|
-
value: function wrapComponent(Component, context) {
|
|
65
|
-
var WrappedComponent = Component;
|
|
66
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
67
|
-
try {
|
|
68
|
-
// 按数组顺序依次应用所有组件包装器
|
|
69
|
-
for(var _iterator = this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
70
|
-
var plugin = _step.value;
|
|
71
|
-
if (plugin.wrapComponent) {
|
|
72
|
-
try {
|
|
73
|
-
WrappedComponent = plugin.wrapComponent(WrappedComponent, context);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error('Error applying wrapper from plugin "'.concat(plugin.name, '":'), error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} catch (err) {
|
|
80
|
-
_didIteratorError = true;
|
|
81
|
-
_iteratorError = err;
|
|
82
|
-
} finally{
|
|
83
|
-
try {
|
|
84
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
85
|
-
_iterator.return();
|
|
86
|
-
}
|
|
87
|
-
} finally{
|
|
88
|
-
if (_didIteratorError) {
|
|
89
|
-
throw _iteratorError;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return WrappedComponent;
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
/**
|
|
98
|
-
* 注入属性
|
|
99
|
-
* 按插件注册顺序依次应用所有属性注入器
|
|
100
|
-
* @param props 原始属性
|
|
101
|
-
* @param context 注入上下文
|
|
102
|
-
* @returns 注入后的属性
|
|
103
|
-
*/ key: "injectProps",
|
|
104
|
-
value: function injectProps(props, context) {
|
|
105
|
-
var injectedProps = _object_spread({}, props);
|
|
106
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
107
|
-
try {
|
|
108
|
-
// 按数组顺序依次应用所有属性注入器
|
|
109
|
-
for(var _iterator = this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
110
|
-
var plugin = _step.value;
|
|
111
|
-
if (plugin.injectProps) {
|
|
112
|
-
try {
|
|
113
|
-
injectedProps = plugin.injectProps(injectedProps, context);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.error('Error injecting props from plugin "'.concat(plugin.name, '":'), error);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
} catch (err) {
|
|
120
|
-
_didIteratorError = true;
|
|
121
|
-
_iteratorError = err;
|
|
122
|
-
} finally{
|
|
123
|
-
try {
|
|
124
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
125
|
-
_iterator.return();
|
|
126
|
-
}
|
|
127
|
-
} finally{
|
|
128
|
-
if (_didIteratorError) {
|
|
129
|
-
throw _iteratorError;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return injectedProps;
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
/**
|
|
138
|
-
* 获取所有插件信息
|
|
139
|
-
* @returns 插件信息数组
|
|
140
|
-
*/ key: "getPluginInfo",
|
|
141
|
-
value: function getPluginInfo() {
|
|
142
|
-
return this.plugins.map(function(plugin) {
|
|
143
|
-
return {
|
|
144
|
-
name: plugin.name,
|
|
145
|
-
hasWrapper: !!plugin.wrapComponent,
|
|
146
|
-
hasInjector: !!plugin.injectProps
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
/**
|
|
153
|
-
* 移除插件
|
|
154
|
-
* @param name 插件名称
|
|
155
|
-
* @returns 是否成功移除
|
|
156
|
-
*/ key: "removePlugin",
|
|
157
|
-
value: function removePlugin(name) {
|
|
158
|
-
var index = this.plugins.findIndex(function(p) {
|
|
159
|
-
return p.name === name;
|
|
160
|
-
});
|
|
161
|
-
if (index !== -1) {
|
|
162
|
-
this.plugins.splice(index, 1);
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
/**
|
|
170
|
-
* 清空所有插件
|
|
171
|
-
*/ key: "clear",
|
|
172
|
-
value: function clear() {
|
|
173
|
-
this.plugins = [];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
]);
|
|
177
|
-
return EnhancedPluginManager;
|
|
178
|
-
}();
|
|
179
|
-
// 全局增强插件管理器实例
|
|
180
|
-
var globalEnhancedPluginManager = null;
|
|
181
|
-
/**
|
|
182
|
-
* 获取全局增强插件管理器实例
|
|
183
|
-
* @returns 增强插件管理器实例
|
|
184
|
-
*/ export function getEnhancedPluginManager() {
|
|
185
|
-
if (!globalEnhancedPluginManager) {
|
|
186
|
-
globalEnhancedPluginManager = new EnhancedPluginManager();
|
|
187
|
-
}
|
|
188
|
-
return globalEnhancedPluginManager;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* 注册多个增强插件(便捷函数)
|
|
192
|
-
* @param plugins 增强插件数组
|
|
193
|
-
*/ export function registerEnhancedPlugins(plugins) {
|
|
194
|
-
getEnhancedPluginManager().registerPlugins(plugins);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* React Hook:使用增强插件管理器
|
|
198
|
-
* @returns 增强插件管理器实例
|
|
199
|
-
*/ export function useEnhancedPluginManager() {
|
|
200
|
-
return getEnhancedPluginManager();
|
|
201
|
-
}
|