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