@ice/mf-runtime 1.0.2 → 1.0.3-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.
@@ -2,10 +2,10 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as React from "react";
4
4
  import { getExtraInfo, getRemoteInfoFromStore, hasConflict } from "./mf-global-store";
5
- import { FallBack } from "./FallBack";
5
+ import { createRuntimePluginWrapper } from "./types";
6
6
  var loadRemotePackagedReactAndRender = function() {
7
7
  var _ref = _async_to_generator(function(args) {
8
- var _args_origin_options_shared_reactdom_, _args_origin_options_shared_reactdom, _args_origin_options_shared, _args_origin_options, _remoteInstance_options_shared_reactdom_, _remoteInstance_options_shared_reactdom, _remoteInstance_options_shared, _remoteInstance_options, hostVersion, remoteInstance, remoteVersion, _sharedOptions_find, remoteReactDOM, _sharedOptions_find1, remoteReact, wrappedRender;
8
+ var _args_origin_options_shared_reactdom_, _args_origin_options_shared_reactdom, _args_origin_options_shared, _args_origin_options, _remoteInstance_options_shared_reactdom_, _remoteInstance_options_shared_reactdom, _remoteInstance_options_shared, _remoteInstance_options, hostVersion, remoteInstance, remoteVersion, _sharedOptions_find, remoteReactDOM, _sharedOptions_find1, remoteReact;
9
9
  return _ts_generator(this, function(_state) {
10
10
  switch(_state.label){
11
11
  case 0:
@@ -23,8 +23,8 @@ var loadRemotePackagedReactAndRender = function() {
23
23
  4,
24
24
  remoteInstance.loadShare("react-dom", {
25
25
  resolver: function(sharedOptions) {
26
- return (_sharedOptions_find = sharedOptions.find(function(i) {
27
- return i.version === remoteVersion;
26
+ return (_sharedOptions_find = sharedOptions.find(function(option) {
27
+ return option.version === remoteVersion;
28
28
  })) !== null && _sharedOptions_find !== void 0 ? _sharedOptions_find : sharedOptions[0];
29
29
  }
30
30
  })
@@ -35,8 +35,8 @@ var loadRemotePackagedReactAndRender = function() {
35
35
  4,
36
36
  remoteInstance.loadShare("react", {
37
37
  resolver: function(sharedOptions) {
38
- return (_sharedOptions_find1 = sharedOptions.find(function(i) {
39
- return i.version === remoteVersion;
38
+ return (_sharedOptions_find1 = sharedOptions.find(function(option) {
39
+ return option.version === remoteVersion;
40
40
  })) !== null && _sharedOptions_find1 !== void 0 ? _sharedOptions_find1 : sharedOptions[0];
41
41
  }
42
42
  })
@@ -49,26 +49,22 @@ var loadRemotePackagedReactAndRender = function() {
49
49
  null
50
50
  ];
51
51
  }
52
- wrappedRender = function(mountNode, containerClassName) {
53
- return FallBack({
54
- Original: args.exposeModule.default,
55
- remoteVersion: function() {
56
- return remoteVersion;
57
- },
58
- hostVersion: function() {
59
- return hostVersion;
60
- },
61
- remoteReactDOM: remoteReactDOM,
62
- remoteReact: remoteReact,
63
- mountNode: mountNode,
64
- containerClassName: containerClassName
65
- });
66
- };
67
- // 添加标记,用于在 RemoteModule 中识别
68
- wrappedRender.__ICE_MF_RUNTIME_WRAPPER__ = true;
52
+ // 创建 Runtime Plugin 包装器对象,返回原始组件和运行时信息
53
+ // 让 RemoteModule 控制 HOC 的正确层级顺序
69
54
  return [
70
55
  2,
71
- wrappedRender
56
+ createRuntimePluginWrapper(// 原始组件
57
+ args.exposeModule.default, // 运行时信息
58
+ {
59
+ remoteVersion: remoteVersion,
60
+ hostVersion: hostVersion,
61
+ remoteReact: remoteReact,
62
+ remoteReactDOM: remoteReactDOM
63
+ }, // React 实例信息
64
+ {
65
+ react: remoteReact(),
66
+ reactDOM: remoteReactDOM()
67
+ })
72
68
  ];
73
69
  case 3:
74
70
  return [
@@ -99,7 +95,7 @@ export var runtimePlugin = function() {
99
95
  },
100
96
  onLoad: function onLoad(args) {
101
97
  return _async_to_generator(function() {
102
- var _args_origin_options_shared_reactdom_, _args_origin_options_shared_reactdom, _args_origin_options_shared, _args_origin_options, _extraInfo, hostName, remoteName, hostVersion, extraInfo, externalReact, externalReactDOM, remoteReact, remoteReactDOM, wrappedRender, fallBackRender;
98
+ var _args_origin_options_shared_reactdom_, _args_origin_options_shared_reactdom, _args_origin_options_shared, _args_origin_options, _extraInfo, hostName, remoteName, hostVersion, extraInfo, externalReact, externalReactDOM, remoteReact, remoteReactDOM, fallBackRender;
103
99
  return _ts_generator(this, function(_state) {
104
100
  switch(_state.label){
105
101
  case 0:
@@ -124,20 +120,20 @@ export var runtimePlugin = function() {
124
120
  args
125
121
  ];
126
122
  }
127
- wrappedRender = function(mountNode, containerClassName) {
128
- return FallBack({
129
- Original: args.exposeModule.default,
130
- remoteReactDOM: remoteReactDOM,
131
- remoteReact: remoteReact,
132
- mountNode: mountNode,
133
- containerClassName: containerClassName
134
- });
135
- };
136
- // 添加标记,用于在 RemoteModule 中识别
137
- wrappedRender.__ICE_MF_RUNTIME_WRAPPER__ = true;
123
+ // 创建 Runtime Plugin 包装器对象,返回原始组件和运行时信息
124
+ // 让 RemoteModule 控制 HOC 的正确层级顺序
138
125
  return [
139
126
  2,
140
- wrappedRender
127
+ createRuntimePluginWrapper(// 原始组件
128
+ args.exposeModule.default, // 运行时信息
129
+ {
130
+ remoteReact: remoteReact,
131
+ remoteReactDOM: remoteReactDOM
132
+ }, // React 实例信息
133
+ {
134
+ react: remoteReact(),
135
+ reactDOM: remoteReactDOM()
136
+ })
141
137
  ];
142
138
  }
143
139
  }
package/esm/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { UserOptions } from '@module-federation/runtime-core';
2
2
  import type { Remote } from '@module-federation/runtime-core/dist/src/types';
3
+ import * as React from 'react';
3
4
  export interface ExtraInfo {
4
5
  external?: Record<string, string>;
5
6
  legacy?: boolean;
@@ -18,3 +19,69 @@ export interface MicroMod {
18
19
  moduleFederatedName: string;
19
20
  extraInfo?: ExtraInfo;
20
21
  }
22
+ export interface FederationRuntimePlugin {
23
+ name: string;
24
+ afterResolve?: (args: any) => any;
25
+ onLoad?: (args: any) => any;
26
+ beforeRequest?: (args: any) => any;
27
+ }
28
+ export interface WrapperContext {
29
+ remoteName: string;
30
+ moduleName: string;
31
+ props: Record<string, any>;
32
+ React: typeof import('react');
33
+ ReactDOM?: typeof import('react-dom');
34
+ }
35
+ export interface InjectionContext {
36
+ remoteName: string;
37
+ moduleName: string;
38
+ }
39
+ export interface ComponentWrapper {
40
+ (WrappedComponent: React.ComponentType<any>, context: WrapperContext): React.ComponentType<any>;
41
+ }
42
+ export interface PropInjector {
43
+ (props: Record<string, any>, context: InjectionContext): Record<string, any>;
44
+ }
45
+ export interface EnhancedRuntimePlugin {
46
+ name: string;
47
+ wrapComponent?: ComponentWrapper;
48
+ injectProps?: PropInjector;
49
+ }
50
+ /**
51
+ * Runtime Plugin 包装器对象的接口
52
+ * 包含原始组件和运行时信息,让 RemoteModule 控制 HOC 层级顺序
53
+ */
54
+ export interface RuntimePluginWrapper {
55
+ readonly type: 'runtime-plugin-wrapper';
56
+ readonly originalComponent: React.ComponentType<any>;
57
+ readonly runtimeInfo: {
58
+ readonly remoteVersion?: string;
59
+ readonly hostVersion?: string;
60
+ readonly remoteReact: () => typeof import('react');
61
+ readonly remoteReactDOM: () => typeof import('react-dom');
62
+ readonly mountNode?: HTMLElement;
63
+ readonly containerClassName?: string;
64
+ };
65
+ readonly reactInstances: {
66
+ readonly react: typeof import('react');
67
+ readonly reactDOM?: typeof import('react-dom');
68
+ };
69
+ }
70
+ /**
71
+ * 类型守卫:检查是否为 Runtime Plugin 包装器
72
+ */
73
+ export declare function isRuntimePluginWrapper(value: any): value is () => RuntimePluginWrapper;
74
+ /**
75
+ * 创建 Runtime Plugin 包装器的工厂函数
76
+ */
77
+ export declare function createRuntimePluginWrapper(originalComponent: React.ComponentType<any>, runtimeInfo: {
78
+ remoteVersion?: string;
79
+ hostVersion?: string;
80
+ remoteReact: () => typeof import('react');
81
+ remoteReactDOM: () => typeof import('react-dom');
82
+ mountNode?: HTMLElement;
83
+ containerClassName?: string;
84
+ }, reactInstances: {
85
+ react: typeof import('react');
86
+ reactDOM?: typeof import('react-dom');
87
+ }): () => RuntimePluginWrapper;
package/esm/types.js CHANGED
@@ -1 +1,20 @@
1
- export { };
1
+ import * as React from "react";
2
+ /**
3
+ * 类型守卫:检查是否为 Runtime Plugin 包装器
4
+ */ export function isRuntimePluginWrapper(value) {
5
+ return value && value.__mf_fallback_render;
6
+ }
7
+ /**
8
+ * 创建 Runtime Plugin 包装器的工厂函数
9
+ */ export function createRuntimePluginWrapper(originalComponent, runtimeInfo, reactInstances) {
10
+ var wrapper = function() {
11
+ return {
12
+ type: "runtime-plugin-wrapper",
13
+ originalComponent: originalComponent,
14
+ runtimeInfo: runtimeInfo,
15
+ reactInstances: reactInstances
16
+ };
17
+ };
18
+ wrapper.__mf_fallback_render = true;
19
+ return wrapper;
20
+ } // 不再需要联合类型,两种插件分开管理
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.3-beta.1",
4
4
  "description": "ice mf runtime",
5
5
  "files": [
6
6
  "esm",
@@ -34,6 +34,9 @@
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",
37
40
  "eslint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./",
38
41
  "eslint:fix": "npm run eslint -- --fix",
39
42
  "stylelint": "stylelint \"**/*.{css,scss,less}\"",
@@ -57,12 +60,19 @@
57
60
  "@applint/spec": "^1.2.3",
58
61
  "@ice/pkg": "^1.0.0",
59
62
  "@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",
60
66
  "@types/react": "^18.0.0",
61
67
  "@types/react-dom": "^18.0.0",
68
+ "@vitest/coverage-v8": "^1.0.0",
62
69
  "eslint": "^8.0.0",
70
+ "jsdom": "^23.0.0",
63
71
  "react": "^18.0.0",
64
72
  "react-dom": "^18.0.0",
65
- "stylelint": "^15.0.0"
73
+ "stylelint": "^15.0.0",
74
+ "typescript": "^5.0.0",
75
+ "vitest": "^1.0.0"
66
76
  },
67
77
  "publishConfig": {
68
78
  "access": "public",