@empjs/share 3.13.9-beta.2 → 4.0.0-alpha.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.
Files changed (132) hide show
  1. package/README.md +202 -62
  2. package/dist/171.js +2 -0
  3. package/dist/171.js.map +1 -0
  4. package/dist/227.js +2 -0
  5. package/dist/227.js.map +1 -0
  6. package/dist/607.js +2 -0
  7. package/dist/607.js.map +1 -0
  8. package/dist/68.js +2 -0
  9. package/dist/68.js.map +1 -0
  10. package/dist/adapter/index.d.ts +1 -0
  11. package/dist/{adapter.d.cts → adapter/react.d.ts} +3 -8
  12. package/dist/adapter/vue.d.ts +1 -0
  13. package/dist/adapter.d.ts +1 -14
  14. package/dist/adapter.js +2 -1
  15. package/dist/adapter.js.map +1 -1
  16. package/dist/adapterVue.d.ts +1 -0
  17. package/dist/adapterVue.js +1 -0
  18. package/dist/forceRemote.d.ts +2 -19
  19. package/dist/forceRemote.js +2 -1
  20. package/dist/forceRemote.js.map +1 -1
  21. package/dist/framework/react/config.d.ts +1 -0
  22. package/dist/framework/react/index.d.ts +3 -0
  23. package/dist/framework/react/shared.d.ts +2 -0
  24. package/dist/framework/vue/config.d.ts +1 -0
  25. package/dist/framework/vue/index.d.ts +3 -0
  26. package/dist/framework/vue/shared.d.ts +2 -0
  27. package/dist/helper/config.d.ts +3 -0
  28. package/dist/helper/index.d.ts +6 -0
  29. package/dist/helper/moduleFederation.d.ts +6 -0
  30. package/dist/helper/resolvePackageExport.d.ts +1 -0
  31. package/dist/helper/rspack.d.ts +1 -0
  32. package/dist/index.d.ts +3 -9
  33. package/dist/index.js +2 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/library/full.d.ts +7 -0
  36. package/dist/library/sdk.d.ts +2 -0
  37. package/dist/library/sdkPolyfill.d.ts +3 -0
  38. package/dist/library/wSdk.d.ts +2 -0
  39. package/dist/mfRuntime.d.ts +1 -1
  40. package/dist/mfRuntime.js +1 -1
  41. package/dist/plugins/rspack/index.d.ts +11 -0
  42. package/dist/plugins/rspack/plugin.d.ts +7 -0
  43. package/dist/plugins/rspack/runtimePlugin/forceRemote.d.ts +13 -0
  44. package/dist/plugins/rspack/runtimePlugin/registerRemotes.d.ts +3 -0
  45. package/dist/plugins/rspack/share.d.ts +30 -0
  46. package/dist/{types-BGnQUQ0O.d.cts → plugins/rspack/types.d.ts} +14 -17
  47. package/dist/plugins/rspack/utils.d.ts +2 -0
  48. package/dist/react.d.ts +1 -9
  49. package/dist/react.js +2 -1
  50. package/dist/react.js.map +1 -1
  51. package/dist/rspack.d.ts +2 -15
  52. package/dist/rspack.js +2 -1
  53. package/dist/rspack.js.map +1 -1
  54. package/dist/{runtime.d.cts → runtime/index.d.ts} +4 -7
  55. package/dist/runtime/index.pre.version.d.ts +22 -0
  56. package/dist/runtime/plugins.d.ts +2 -0
  57. package/dist/runtime/sdk-prev.d.ts +30 -0
  58. package/dist/runtime/sdk.d.ts +31 -0
  59. package/dist/runtime.d.ts +2 -23
  60. package/dist/runtime.js +2 -1
  61. package/dist/runtime.js.map +1 -1
  62. package/dist/sdk.d.ts +1 -34
  63. package/dist/sdk.js +2 -1
  64. package/dist/sdk.js.map +1 -1
  65. package/dist/types/index.d.ts +26 -0
  66. package/dist/vue.d.ts +1 -9
  67. package/dist/vue.js +2 -1
  68. package/dist/vue.js.map +1 -1
  69. package/output/adapter/index.d.ts +1 -0
  70. package/output/adapter/react.d.ts +9 -0
  71. package/output/adapter/vue.d.ts +1 -0
  72. package/output/framework/react/config.d.ts +1 -0
  73. package/output/framework/react/index.d.ts +3 -0
  74. package/output/framework/react/shared.d.ts +2 -0
  75. package/output/framework/vue/config.d.ts +1 -0
  76. package/output/framework/vue/index.d.ts +3 -0
  77. package/output/framework/vue/shared.d.ts +2 -0
  78. package/output/helper/config.d.ts +3 -0
  79. package/output/helper/index.d.ts +6 -0
  80. package/output/helper/moduleFederation.d.ts +6 -0
  81. package/output/helper/resolvePackageExport.d.ts +1 -0
  82. package/output/helper/rspack.d.ts +1 -0
  83. package/output/index.d.ts +3 -0
  84. package/output/library/full.d.ts +7 -0
  85. package/output/library/sdk.d.ts +2 -0
  86. package/output/library/sdkPolyfill.d.ts +3 -0
  87. package/output/library/wSdk.d.ts +2 -0
  88. package/output/plugins/rspack/index.d.ts +11 -0
  89. package/output/plugins/rspack/plugin.d.ts +7 -0
  90. package/output/plugins/rspack/runtimePlugin/forceRemote.d.ts +13 -0
  91. package/output/plugins/rspack/runtimePlugin/registerRemotes.d.ts +3 -0
  92. package/output/plugins/rspack/share.d.ts +30 -0
  93. package/{dist/types-BGnQUQ0O.d.ts → output/plugins/rspack/types.d.ts} +14 -17
  94. package/output/plugins/rspack/utils.d.ts +2 -0
  95. package/output/runtime/index.d.ts +20 -0
  96. package/output/runtime/index.pre.version.d.ts +22 -0
  97. package/output/runtime/mfRuntime.d.ts +1 -0
  98. package/output/runtime/plugins.d.ts +2 -0
  99. package/output/runtime/sdk-prev.d.ts +30 -0
  100. package/output/runtime/sdk.d.ts +31 -0
  101. package/output/sdk.d.ts +1 -0
  102. package/output/sdk.js +5 -1
  103. package/output/types/index.d.ts +26 -0
  104. package/package.json +42 -91
  105. package/dist/adapter.cjs +0 -1
  106. package/dist/adapter.cjs.map +0 -1
  107. package/dist/forceRemote.cjs +0 -1
  108. package/dist/forceRemote.cjs.map +0 -1
  109. package/dist/forceRemote.d.cts +0 -19
  110. package/dist/index-DaSrQPN9.d.cts +0 -21
  111. package/dist/index-DaSrQPN9.d.ts +0 -21
  112. package/dist/index.cjs +0 -1
  113. package/dist/index.cjs.map +0 -1
  114. package/dist/index.d.cts +0 -9
  115. package/dist/mfRuntime.cjs +0 -1
  116. package/dist/mfRuntime.cjs.map +0 -1
  117. package/dist/mfRuntime.js.map +0 -1
  118. package/dist/react.cjs +0 -1
  119. package/dist/react.cjs.map +0 -1
  120. package/dist/react.d.cts +0 -9
  121. package/dist/rspack.cjs +0 -1
  122. package/dist/rspack.cjs.map +0 -1
  123. package/dist/rspack.d.cts +0 -15
  124. package/dist/runtime.cjs +0 -1
  125. package/dist/runtime.cjs.map +0 -1
  126. package/dist/sdk.cjs +0 -1
  127. package/dist/sdk.cjs.map +0 -1
  128. package/dist/sdk.d.cts +0 -34
  129. package/dist/vue.cjs +0 -1
  130. package/dist/vue.cjs.map +0 -1
  131. package/dist/vue.d.cts +0 -9
  132. /package/dist/{mfRuntime.d.cts → runtime/mfRuntime.d.ts} +0 -0
package/README.md CHANGED
@@ -1,94 +1,234 @@
1
- # EMP Share
1
+ # @empjs/share
2
+
3
+ `@empjs/share` 是 EMP 的 Module Federation 封装包,提供 Rspack 插件、EMP runtime、SDK facade、React/Vue adapter 和浏览器端 runtime bundle。
4
+
5
+ v4 版本已切到官方 Module Federation 2.x:
6
+
7
+ - `@module-federation/rspack`
8
+ - `@module-federation/runtime`
9
+ - `@module-federation/sdk`
10
+
11
+ 同时保留 `pluginRspackEmpShare(...)` 用户侧 API,不要求业务项目重写现有 `emp.config.ts`。
12
+
13
+ ## 环境要求
14
+
15
+ ```bash
16
+ node ^20.19.0 || >=22.12.0
2
17
  ```
18
+
19
+ ## 安装
20
+
21
+ ```bash
3
22
  pnpm add @empjs/share
4
23
  ```
5
- ## 01 @empjs/share/rspack - Emp Share Plugin
6
- >
7
- 使用方法
8
- ```js
9
- import {pluginRspackEmpShare} from '@empjs/share/rspack'
24
+
25
+ React 项目通常还需要:
26
+
27
+ ```bash
28
+ pnpm add @empjs/cli @empjs/plugin-react
29
+ ```
30
+
31
+ ## 导出入口
32
+
33
+ | 入口 | 说明 |
34
+ | --- | --- |
35
+ | `@empjs/share` | 默认导出,包含 share 相关公共 API |
36
+ | `@empjs/share/rspack` | Rspack Module Federation 插件入口 |
37
+ | `@empjs/share/sdk` | 业务侧 SDK facade,常用 `loadRemote`、`registerRemotes` |
38
+ | `@empjs/share/runtime` | EMP runtime 实例封装 |
39
+ | `@empjs/share/mfRuntime` | 透出官方 Module Federation runtime |
40
+ | `@empjs/share/adapter` | React adapter |
41
+ | `@empjs/share/adapterVue` | Vue adapter |
42
+ | `@empjs/share/forceRemote` | `forceRemotes` runtime plugin |
43
+ | `@empjs/share/library` | 浏览器端 IIFE bundle,对应 `output/sdk.js` |
44
+ | `@empjs/share/react` / `@empjs/share/vue` | React / Vue framework 配置辅助入口 |
45
+
46
+ ## Rspack 插件
47
+
48
+ 推荐从 `@empjs/share/rspack` 使用:
49
+
50
+ ```ts
10
51
  import {defineConfig} from '@empjs/cli'
52
+ import pluginReact from '@empjs/plugin-react'
53
+ import pluginRspackEmpShare, {externalReact} from '@empjs/share/rspack'
54
+
11
55
  export default defineConfig(store => {
12
56
  return {
13
57
  plugins: [
58
+ pluginReact(),
14
59
  pluginRspackEmpShare({
15
60
  name: 'mfHost',
16
- shared: {
17
- react: {
18
- singleton: true,
19
- requiredVersion: '18',
20
- },
21
- 'react-dom': {
22
- singleton: true,
23
- requiredVersion: '18',
24
- },
25
- },
26
61
  exposes: {
27
62
  './App': './src/App',
28
63
  './CountComp': './src/CountComp',
29
64
  },
65
+ remotes: {
66
+ mfRemote: `mfRemote@http://${store.server.ip}:6002/emp.json`,
67
+ },
68
+ shared: {
69
+ react: {singleton: true},
70
+ 'react-dom': {singleton: true},
71
+ },
72
+ manifest: true,
73
+ dts: {
74
+ generateTypes: true,
75
+ consumeTypes: true,
76
+ },
77
+ empRuntime: {
78
+ framework: {
79
+ global: 'EMP_ADAPTER_REACT',
80
+ libs: [`https://unpkg.com/@empjs/cdn-react@0.19.1/dist/react.${store.mode}.umd.js`],
81
+ },
82
+ runtime: {
83
+ lib: `http://${store.server.ip}:2100/sdk.js`,
84
+ },
85
+ setExternals: externalReact,
86
+ },
30
87
  }),
31
88
  ],
89
+ server: {
90
+ port: 6001,
91
+ open: false,
92
+ },
32
93
  }
33
94
  })
34
95
  ```
35
96
 
36
- ## 02 @empjs/share/library - Module Federation SDK 封装
37
- + `full.js` 为全量函数库、主要应对直接 老项目的桥接、通过 `window`直接调用共享,包含:
38
- + MFRuntime
39
- + MFSDK
40
- + reactAdapter
41
- + runtime
42
- + `sdk.js` 为 SDK库包含 `MFRuntime` 与 `MFSDK`,调用还是需要安装 `pnpm add @empjs/share/runtime`
43
- + `sdkPolyfill.js` 为 `sdk` + `core-js`
97
+ ## `empRuntime`
44
98
 
99
+ `empRuntime` 用于把框架库和 Module Federation runtime 外置到浏览器全局变量,降低业务包体并兼容旧项目接入。
45
100
 
46
- ## 03 @empjs/share/runtime - 运行时引用
47
- ### 项目调用
101
+ ```ts
102
+ pluginRspackEmpShare({
103
+ name: 'mfHost',
104
+ empRuntime: {
105
+ framework: {
106
+ global: 'EMP_ADAPTER_REACT',
107
+ libs: ['https://unpkg.com/@empjs/cdn-react@0.19.1/dist/react.development.umd.js'],
108
+ },
109
+ runtime: {
110
+ lib: 'http://localhost:2100/sdk.js',
111
+ },
112
+ setExternals: externalReact,
113
+ },
114
+ })
115
+ ```
116
+
117
+ 如果不传 `runtime.lib`,插件会把 `@empjs/share/library` 内置到构建入口;如果传入远程地址,插件会自动注入 `<script>` 并把 `@module-federation/runtime`、`@module-federation/sdk` external 到指定全局 runtime。
118
+
119
+ ## `@empjs/share/sdk` 类型
120
+
121
+ 业务代码推荐通过 `@empjs/share/sdk` 调用 Module Federation runtime:
122
+
123
+ ```ts
124
+ import {loadRemote, registerRemotes} from '@empjs/share/sdk'
48
125
 
49
- ```js
50
- import React, {useEffect, useState, version} from 'react'
126
+ const RemoteApp = await loadRemote('mfHost/App')
127
+ ```
128
+
129
+ v4 会在启用 `dts.consumeTypes` 时把 `@empjs/share/sdk` 自动合并进 Module Federation 的 runtime 类型包列表。消费侧生成的 `@mf-types/index.d.ts` 会额外包含:
130
+
131
+ ```ts
132
+ declare module '@empjs/share/sdk' {
133
+ export function loadRemote<T extends string, Y>(packageName: T): Promise<Y>
134
+ }
135
+ ```
136
+
137
+ 这样业务侧从 `@empjs/share/sdk` 调用 `loadRemote` 时,也能获得远程模块类型提示。
138
+
139
+ 如果项目已经配置了自定义 `dts.consumeTypes.runtimePkgs`,EMP 会保留已有配置并追加 `@empjs/share/sdk`。
140
+
141
+ ## `forceRemotes`
142
+
143
+ `forceRemotes` 用于在运行时强制替换 remote 入口,常见于本地调试、灰度验证和版本覆盖:
144
+
145
+ ```ts
146
+ pluginRspackEmpShare({
147
+ name: 'rtHost',
148
+ remotes: {
149
+ rtLayout: '$@http://localhost:4004/emp.json',
150
+ },
151
+ forceRemotes: {
152
+ rtLayout: '$@http://127.0.0.1:4004/emp.json',
153
+ },
154
+ })
155
+ ```
156
+
157
+ 插件内部会通过 `@empjs/share/forceRemote` 注册 runtime plugin,并使用 package export 解析入口路径。
158
+
159
+ ## Runtime 直接调用
160
+
161
+ `@empjs/share/runtime` 适合手动初始化 remote,再用 adapter 接入不同 React 版本或旧项目:
162
+
163
+ ```tsx
164
+ import React from 'react'
51
165
  import ReactDOM from 'react-dom'
52
- import {CountComp as CountComp16, ShowCountComp as ShowCountComp16, Card} from './CountComp'
53
- import {reactAdapter} from '@empjs/share/adapter' // 使用 react
54
- import empRuntime from '@empjs/share/runtime' // runtime 加载器
55
- const entry = process.env.mfhost as string
56
- // 实例化远程 emp
166
+ import {reactAdapter} from '@empjs/share/adapter'
167
+ import empRuntime from '@empjs/share/runtime'
168
+
57
169
  empRuntime.init({
58
- shared: reactAdapter.shared,
170
+ name: 'federationRuntimeDemo',
59
171
  remotes: [
60
172
  {
61
173
  name: 'mfHost',
62
- entry,
174
+ entry: 'http://localhost:6001/emp.js',
63
175
  },
64
176
  ],
65
- name: 'federationRuntimeDemo',
177
+ shared: reactAdapter.shared,
66
178
  })
67
- // 封装 React 18的组件 以便插入到 React 16
179
+
68
180
  const MfApp = reactAdapter.adapter(empRuntime.load('mfHost/App'))
69
- const CountComp = reactAdapter.adapter(empRuntime.load('mfHost/CountComp'), 'CountComp')
70
-
71
- // 创建 React 16 组件
72
- const ParentComponent = () => {
73
- return (
74
- <Card title={() => <>App Inject mfHost</>}>
75
- <CountComp name="a" />
76
- <CountComp16 />
77
- </Card>
78
- )
79
- }
80
- // 封装 React 16的组件 以便插入到 React 18
81
- const ParentComponentAdepter = reactAdapter.adapter(ParentComponent, 'default', React, ReactDOM)
82
- const App = () => {
83
- return (
84
- <>
85
- <h1>App React Version {version}</h1>
86
- <ShowCountComp16 />
87
- <Card title="EMP From mfhost">
88
- <MfApp component={ParentComponentAdepter} />
89
- </Card>
90
- </>
91
- )
92
- }
93
- export default App
181
+
182
+ const LegacyApp = () => <MfApp />
183
+ const LegacyRoot = reactAdapter.adapter(LegacyApp, 'default', React, ReactDOM)
184
+ ```
185
+
186
+ ## Browser bundle
187
+
188
+ `@empjs/share/library` 对应构建产物 `output/sdk.js`,包含:
189
+
190
+ - `MFRuntime`
191
+ - `MFSDK`
192
+ - `reactAdapter`
193
+ - `runtime`
194
+
195
+ 本地启动:
196
+
197
+ ```bash
198
+ pnpm --filter @empjs/share start
199
+ ```
200
+
201
+ 默认端口为 `2100`,可通过以下地址引用:
202
+
203
+ ```html
204
+ <script src="http://localhost:2100/sdk.js"></script>
205
+ ```
206
+
207
+ ## 开发命令
208
+
209
+ ```bash
210
+ pnpm --filter @empjs/share build
211
+ pnpm --filter @empjs/share dev
212
+ pnpm --filter @empjs/share start
213
+ ```
214
+
215
+ 回归验证:
216
+
217
+ ```bash
218
+ pnpm --filter @empjs/share exec tsc --noEmit --pretty false
219
+ node packages/emp-share/test/dts-runtime-pkgs.test.mjs
220
+ ```
221
+
222
+ 真实类型消费链路可使用 `mf-host` + `mf-app` 示例验证:
223
+
224
+ ```bash
225
+ pnpm --filter mf-host build
226
+ pnpm --filter mf-host start
227
+ pnpm --filter mf-app dev
228
+ ```
229
+
230
+ 完成后检查:
231
+
232
+ ```bash
233
+ rg 'declare module "@empjs/share/sdk"' projects/mf-app/@mf-types/index.d.ts
94
234
  ```
package/dist/171.js ADDED
@@ -0,0 +1,2 @@
1
+ let e=(e,t)=>e=Object.assign(e,{react:`${t}.React`,"react-dom":`${t}.ReactDOM`,"react-dom/client":t,"react/jsx-runtime":t,"react/jsx-dev-runtime":t,"react-router-dom":`${t}.ReactRouterDOM`});export{e as externalReact};
2
+ //# sourceMappingURL=171.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"171.js","sources":["../src/framework/react/config.ts"],"sourcesContent":["export const externalReact = (o: any, globalVal: string) => {\n o = Object.assign(o, {\n react: `${globalVal}.React`,\n 'react-dom': `${globalVal}.ReactDOM`,\n 'react-dom/client': globalVal,\n 'react/jsx-runtime': globalVal,\n 'react/jsx-dev-runtime': globalVal,\n 'react-router-dom': `${globalVal}.ReactRouterDOM`,\n })\n return o\n}\n"],"names":["externalReact","o","globalVal","Object"],"mappings":"AAAO,IAAMA,EAAgB,CAACC,EAAQC,IACpCD,EAAIE,OAAO,MAAM,CAACF,EAAG,CACnB,MAAO,CAAC,EAAEC,EAAU,MAAM,CAAC,CAC3B,YAAa,CAAC,EAAEA,EAAU,SAAS,CAAC,CACpC,mBAAoBA,EACpB,oBAAqBA,EACrB,wBAAyBA,EACzB,mBAAoB,CAAC,EAAEA,EAAU,eAAe,CAAC,AACnD,U"}
package/dist/227.js ADDED
@@ -0,0 +1,2 @@
1
+ let t=t=>`data:text/javascript,${t}`;function e(t,...o){for(let i of o)for(let o in i){let r=i[o],c=t[o];if(Object(r)==r&&Object(c)===c){t[o]=e(c,r);continue}t[o]=i[o]}return t}let o=t=>t?Number(t.split(".")[0]):0,i=t=>t&&"[object Promise]"===Object.prototype.toString.call(t),r=()=>{};export{o as checkVersion,e as deepAssign,t as importJsVm,i as isPromise,r as log};
2
+ //# sourceMappingURL=227.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"227.js","sources":["../src/helper/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n"],"names":["importJsVm","content","deepAssign","target","sources","source","k","vs","vt","Object","checkVersion","version","Number","isPromise","p","log"],"mappings":"AAAO,IAAMA,EAAa,AAACC,GAAoB,CAAC,qBAAqB,EAAEA,EAAQ,CAAC,CAEzE,SAASC,EAAcC,CAAW,CAAE,GAAGC,CAAY,EACxD,IAAK,IAAMC,KAAUD,EACnB,IAAK,IAAME,KAAKD,EAAQ,CACtB,IAAME,EAAKF,CAAM,CAACC,EAAE,CAClBE,EAAKL,CAAM,CAACG,EAAE,CAChB,GAAIG,OAAOF,IAAOA,GAAME,OAAOD,KAAQA,EAAI,CACzCL,CAAM,CAACG,EAAE,CAAGJ,EAAWM,EAAID,GAC3B,QACF,CACAJ,CAAM,CAACG,EAAE,CAAGD,CAAM,CAACC,EAAE,AACvB,CAEF,OAAOH,CACT,CAEO,IAAMO,EAAe,AAACC,GAAqBA,EAAUC,OAAOD,EAAQ,KAAK,CAAC,IAAI,CAAC,EAAE,EAAI,EAC/EE,EAAY,AAACC,GAAWA,GAAKL,AAAsC,qBAAtCA,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,CAACK,GAI5DC,EAAyD,KAAO,S"}
package/dist/607.js ADDED
@@ -0,0 +1,2 @@
1
+ let a="EMP_SHARE_RUNTIME",e="EMPShareGlobalVal",l="EMP_FORCE_REMOTES";export{l as shareForceRemote,a as shareGlobalName,e as shareGlobalVal};
2
+ //# sourceMappingURL=607.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"607.js","sources":["../src/helper/config.ts"],"sourcesContent":["export const shareGlobalName = 'EMP_SHARE_RUNTIME'\nexport const shareGlobalVal = 'EMPShareGlobalVal'\nexport const shareForceRemote = 'EMP_FORCE_REMOTES'\n"],"names":["shareGlobalName","shareGlobalVal","shareForceRemote"],"mappings":"AAAO,IAAMA,EAAkB,oBAClBC,EAAiB,oBACjBC,EAAmB,2B"}
package/dist/68.js ADDED
@@ -0,0 +1,2 @@
1
+ let e=(e,u)=>e=Object.assign(e,{vue:`${u}.Vue`,"vue-router":`${u}.VueRouter`});export{e as externalVue};
2
+ //# sourceMappingURL=68.js.map
package/dist/68.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"68.js","sources":["../src/framework/vue/config.ts"],"sourcesContent":["export const externalVue = (o: any, globalVal: string) => {\n o = Object.assign(o, {\n vue: `${globalVal}.Vue`,\n 'vue-router': `${globalVal}.VueRouter`,\n })\n return o\n}\n"],"names":["externalVue","o","globalVal","Object"],"mappings":"AAAO,IAAMA,EAAc,CAACC,EAAQC,IAClCD,EAAIE,OAAO,MAAM,CAACF,EAAG,CACnB,IAAK,CAAC,EAAEC,EAAU,IAAI,CAAC,CACvB,aAAc,CAAC,EAAEA,EAAU,UAAU,CAAC,AACxC,U"}
@@ -0,0 +1 @@
1
+ export * from './react';
@@ -1,14 +1,9 @@
1
- import { b as EMPShareRuntimeAdapterReactType, I as InitOptionsType } from './index-DaSrQPN9.cjs';
2
- import '@module-federation/runtime';
3
- import '@module-federation/sdk';
4
-
5
- declare class ReactAdapter {
1
+ import type { EMPShareRuntimeAdapterReactType, InitOptionsType } from '../types';
2
+ export declare class ReactAdapter {
6
3
  libs: EMPShareRuntimeAdapterReactType;
7
4
  constructor(op?: EMPShareRuntimeAdapterReactType);
8
5
  setup(o?: EMPShareRuntimeAdapterReactType | string): void;
9
6
  get shared(): InitOptionsType['shared'];
10
7
  adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
11
8
  }
12
- declare const reactAdapter: ReactAdapter;
13
-
14
- export { ReactAdapter, reactAdapter };
9
+ export declare const reactAdapter: ReactAdapter;
@@ -0,0 +1 @@
1
+ export declare const Vue2InVue3Adapter: any;
package/dist/adapter.d.ts CHANGED
@@ -1,14 +1 @@
1
- import { b as EMPShareRuntimeAdapterReactType, I as InitOptionsType } from './index-DaSrQPN9.js';
2
- import '@module-federation/runtime';
3
- import '@module-federation/sdk';
4
-
5
- declare class ReactAdapter {
6
- libs: EMPShareRuntimeAdapterReactType;
7
- constructor(op?: EMPShareRuntimeAdapterReactType);
8
- setup(o?: EMPShareRuntimeAdapterReactType | string): void;
9
- get shared(): InitOptionsType['shared'];
10
- adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
11
- }
12
- declare const reactAdapter: ReactAdapter;
13
-
14
- export { ReactAdapter, reactAdapter };
1
+ export * from './adapter/index'
package/dist/adapter.js CHANGED
@@ -1 +1,2 @@
1
- function e(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function t(e,t,n,r,o,i,u){try{var c=e[i](u);var a=c.value}catch(e){n(e);return}if(c.done){t(a)}else{Promise.resolve(a).then(r,o)}}function n(e){return function(){var n=this,r=arguments;return new Promise(function(o,i){var u=e.apply(n,r);function c(e){t(u,o,i,c,a,"next",e)}function a(e){t(u,o,i,c,a,"throw",e)}c(undefined)})}}function r(e,t,n){t=a(t);return s(e,h()?Reflect.construct(t,n||[],a(e).constructor):t.apply(e,n))}function o(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}function u(e,t,n){if(t)i(e.prototype,t);if(n)i(e,n);return e}function c(e,t,n){if(t in e){Object.defineProperty(e,t,{value:n,enumerable:true,configurable:true,writable:true})}else{e[t]=n}return e}function a(e){a=Object.setPrototypeOf?Object.getPrototypeOf:function e(e){return e.__proto__||Object.getPrototypeOf(e)};return a(e)}function l(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});if(t)p(e,t)}function f(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};var r=Object.keys(n);if(typeof Object.getOwnPropertySymbols==="function"){r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))}r.forEach(function(t){c(e,t,n[t])})}return e}function s(t,n){if(n&&(b(n)==="object"||typeof n==="function")){return n}return e(t)}function p(e,t){p=Object.setPrototypeOf||function e(e,t){e.__proto__=t;return e};return p(e,t)}function b(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function h(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(h=function(){return!!e})()}function y(e,t){var n,r,o,i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},u=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return u.next=c(0),u["throw"]=c(1),u["return"]=c(2),typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(e){return function(t){return a([e,t])}}function a(c){if(n)throw new TypeError("Generator is already executing.");while(u&&(u=0,c[0]&&(i=0)),i)try{if(n=1,r&&(o=c[0]&2?r["return"]:c[0]?r["throw"]||((o=r["return"])&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;if(r=0,o)c=[c[0]&2,o.value];switch(c[0]){case 0:case 1:o=c;break;case 4:i.label++;return{value:c[1],done:false};case 5:i.label++;r=c[1];c=[0];continue;case 7:c=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){i=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(c[0]===6&&i.label<o[1]){i.label=o[1];o=c;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(c);break}if(o[2])i.ops.pop();i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e];r=0}finally{n=o=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:true}}}var v=Object.defineProperty;var d=function(e,t,n){return t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n};var m=function(e,t,n){return d(e,(typeof t==="undefined"?"undefined":b(t))!="symbol"?t+"":t,n)};var w=function(e){return e?Number(e.split(".")[0]):0},O=function(e){return e&&Object.prototype.toString.call(e)==="[object Promise]"},g=!1,R=g?console.log.bind(console,"[EMP Share]"):function(){};var P={},_=window;R("process.env.EMPSHARE_ENV","prod");var j=_||{},k=j.EMPShareGlobalVal;k&&k.frameworkLib&&(P=_[k.frameworkLib]);var E=/*#__PURE__*/function(){"use strict";function e(t){o(this,e);m(this,"libs",f({scope:"default"},P));t&&this.setup(t)}u(e,[{key:"setup",value:function e(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=f({},this.libs,e))}},{key:"shared",get:function e(){var e=this.libs,t=e.React,n=e.ReactDOM,r=e.scope;return{react:{lib:function(){return t},version:t.version,scope:r,shareConfig:{singleton:!0,requiredVersion:"^".concat(t.version)}},"react-dom":{lib:function(){return n},version:n.version,scope:r,shareConfig:{singleton:!0,requiredVersion:"^".concat(t.version)}}}}},{key:"adapter",value:function e(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.libs.scope,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.libs.React,c=arguments.length>3&&arguments[3]!==void 0?arguments[3]:this.libs.ReactDOM;var a=w(i.version),f=this;var s=/*#__PURE__*/function(s){l(p,s);function p(e){o(this,p);var t;t=r(this,p,[e]);m(t,"containerRef");m(t,"root");t.containerRef=i.createRef();return t}u(p,[{key:"componentDidMount",value:function e(){R("componentDidMount"),this.mountOriginalComponent(!0)}},{key:"componentDidUpdate",value:function e(){R("componentDidUpdate"),this.mountOriginalComponent()}},{key:"componentWillUnmount",value:function e(){R("componentWillUnmount"),this.unMountOriginalComponent()}},{key:"unMountOriginalComponent",value:function e(){this.containerRef.current&&(a<18?c.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}},{key:"mountOriginalComponent",value:function r(r){return n(function(){var n,o,u,l;return y(this,function(s){switch(s.label){case 0:n=O(e);if(!n)return[3,2];return[4,e.then(function(e){return e[t]})];case 1:n=e=s.sent();s.label=2;case 2:n;o=i.createElement(e,this.props);if(a<18)(r?c.render:c.hydrate)(o,this.containerRef.current),R("shouldRender16",r,a);else if(R("shouldRender18",r,a),r){u=f.libs,l=u.createRoot;this.root=l(this.containerRef.current),this.root.render(o)}else this.root.render();return[2]}})}).call(this)}},{key:"render",value:function e(){return i.createElement("div",{ref:this.containerRef})}}]);return p}(i.Component);return s}}]);return e}(),S=new E;export{E as ReactAdapter,S as reactAdapter};//# sourceMappingURL=adapter.js.map
1
+ import{log as e,checkVersion as t,isPromise as n}from"./227.js";function r(e,t,n,r,o,i,s){try{var c=e[i](s),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){o(e,t,n[t])})}return e}let s={},c=window;e("process.env.EMPSHARE_ENV","prod");let{EMPShareGlobalVal:a}=c||{};a&&a.frameworkLib&&(s=c[a.frameworkLib]);class l{setup(e){e&&("string"==typeof e&&(e=window[e]),this.libs=i({},this.libs,e))}get shared(){let{React:e,ReactDOM:t,scope:n}=this.libs;return{react:{lib:()=>e,version:e.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>t,version:t.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(i,s=this.libs.scope,c=this.libs.React,a=this.libs.ReactDOM){let l=t(c.version),u=this;class h extends c.Component{componentDidMount(){e("componentDidMount"),this.mountOriginalComponent(!0)}componentDidUpdate(){e("componentDidUpdate"),this.mountOriginalComponent()}componentWillUnmount(){e("componentWillUnmount"),this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(l<18?a.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}mountOriginalComponent(t){var o;return(o=function*(){n(i)&&(i=yield i.then(e=>e[s]));let r=c.createElement(i,this.props);if(l<18)(t?a.render:a.hydrate)(r,this.containerRef.current),e("shouldRender16",t,l);else if(e("shouldRender18",t,l),t){let{createRoot:e}=u.libs;this.root=e(this.containerRef.current),this.root.render(r)}else this.root.render()},function(){var e=this,t=arguments;return new Promise(function(n,i){var s=o.apply(e,t);function c(e){r(s,n,i,c,a,"next",e)}function a(e){r(s,n,i,c,a,"throw",e)}c(void 0)})}).call(this)}render(){return React.createElement("div",{ref:this.containerRef})}constructor(e){super(e),o(this,"containerRef",void 0),o(this,"root",void 0),this.containerRef=c.createRef()}}return h}constructor(e){o(this,"libs",i({scope:"default"},s)),e&&this.setup(e)}}let u=new l;export{l as ReactAdapter,u as reactAdapter};
2
+ //# sourceMappingURL=adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/liangxiaoming/Documents/emp/packages/emp-share/dist/adapter.js","../src/helper/index.ts","../src/adapter/react.tsx"],"names":["g","Object","defineProperty","E","t","e","n","enumerable","configurable","writable","value","c","checkVersion","version","Number","split","isPromise","p","prototype","toString","call","isDev","log","console","bind","globalLib","win","window","EMPShareGlobalVal","frameworkLib","ReactAdapter","op","__publicField","scope","setup","o","libs","shared","React","ReactDOM","react","lib","shareConfig","singleton","requiredVersion","adapter","component","reactVersion","self","WrappedComponent","props","containerRef","createRef","componentDidMount","mountOriginalComponent","componentDidUpdate","componentWillUnmount","unMountOriginalComponent","current","unmountComponentAtNode","root","unmount","shouldRender","element","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prototype.toString.call(t)===\"[object Promise]\",P=!1,r=P?console.log.bind(console,\"[EMP Share]\"):()=>{};var d={},y=window;r(\"process.env.EMPSHARE_ENV\",\"prod\");var{EMPShareGlobalVal:l}=y||{};l&&l.frameworkLib&&(d=y[l.frameworkLib]);var u=class{constructor(e){c(this,\"libs\",{scope:\"default\",...d});e&&this.setup(e)}setup(e){e&&(typeof e==\"string\"&&(e=window[e]),this.libs={...this.libs,...e})}get shared(){let{React:e,ReactDOM:n,scope:o}=this.libs;return{react:{lib:()=>e,version:e.version,scope:o,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},\"react-dom\":{lib:()=>n,version:n.version,scope:o,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,n=this.libs.scope,o=this.libs.React,p=this.libs.ReactDOM){let s=h(o.version),b=this;class R extends o.Component{constructor(i){super(i);c(this,\"containerRef\");c(this,\"root\");this.containerRef=o.createRef()}componentDidMount(){r(\"componentDidMount\"),this.mountOriginalComponent(!0)}componentDidUpdate(){r(\"componentDidUpdate\"),this.mountOriginalComponent()}componentWillUnmount(){r(\"componentWillUnmount\"),this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(s<18?p.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(i){f(e)&&(e=await e.then(a=>a[n]));let m=o.createElement(e,this.props);if(s<18)(i?p.render:p.hydrate)(m,this.containerRef.current),r(\"shouldRender16\",i,s);else if(r(\"shouldRender18\",i,s),i){let{createRoot:a}=b.libs;this.root=a(this.containerRef.current),this.root.render(m)}else this.root.render()}render(){return o.createElement(\"div\",{ref:this.containerRef})}}return R}},O=new u;export{u as ReactAdapter,O as reactAdapter};\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport const reactAdapter = new ReactAdapter()\n"]}
1
+ {"version":3,"file":"adapter.js","sources":["../src/adapter/react.tsx"],"sourcesContent":["import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport const reactAdapter = new ReactAdapter()\n"],"names":["globalLib","win","window","log","process","EMPShareGlobalVal","ReactAdapter","o","React1","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","shouldRender","isPromise","m","element","Render","createRoot","props","op","reactAdapter"],"mappings":"8nBAKA,IAAIA,EAAY,CAAC,EACXC,EAAWC,OAEjBC,EAAI,2BAA4BC,QAEhC,GAAM,CAACC,kBAAAA,CAAiB,CAAC,CAAGJ,GAAO,CAAC,CAChCI,CAAAA,GAAqBA,EAAkB,YAAY,EACrDL,CAAAA,EAAYC,CAAG,CAACI,EAAkB,YAAY,CAAC,AAAD,CAGzC,OAAMC,EAQJ,MAAMC,CAA4C,CAAE,CACrDA,IACE,AAAa,UAAb,OAAOA,GAAgBA,CAAAA,EAAIL,MAAM,CAACK,EAAE,AAAD,EACvC,IAAI,CAAC,IAAI,CAAG,KAAI,IAAI,CAAC,IAAI,CAAMA,GAEnC,CACA,IAAI,QAAoC,CACtC,GAAM,CAACC,MAAAA,CAAK,CAAEC,SAAAA,CAAQ,CAAEC,MAAAA,CAAK,CAAC,CAAG,IAAI,CAAC,IAAI,CAC1C,MAAO,CACL,MAAO,CACL,IAAK,IAAMF,EACX,QAASA,EAAM,OAAO,CACtBE,MAAAA,EACA,YAAa,CACX,UAAW,GACX,gBAAiB,CAAC,CAAC,EAAEF,EAAM,OAAO,CAAC,CAAC,AACtC,CACF,EACA,YAAa,CACX,IAAK,IAAMC,EACX,QAASA,EAAS,OAAO,CACzBC,MAAAA,EACA,YAAa,CACX,UAAW,GACX,gBAAiB,CAAC,CAAC,EAAEF,EAAM,OAAO,CAAC,CAAC,AACtC,CACF,CACF,CACF,CACA,QACEG,CAAc,CACdD,EAAgB,IAAI,CAAC,IAAI,CAAC,KAAK,CAC/BF,EAAa,IAAI,CAAC,IAAI,CAAC,KAAK,CAC5BC,EAAgB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAC/B,CACH,IAAMG,EAAeC,EAAaL,EAAM,OAAO,EACzCM,EAAO,IAAI,AACj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A,OAAOO,CACT,CApGA,YAAYQ,CAAoC,CAAE,CAJlD,cAAwC,GACtC,MAAO,S,EACJvB,IAGCuB,GAAI,IAAI,CAAC,KAAK,CAACA,EACrB,CAmGF,CAEO,IAAMC,EAAe,IAAIlB,S"}
@@ -0,0 +1 @@
1
+ export * from './adapter/index'
@@ -0,0 +1 @@
1
+ export{ReactAdapter,reactAdapter}from"./adapter.js";
@@ -1,19 +1,2 @@
1
- import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
2
- import { g as ForceRemoteOptions } from './types-BGnQUQ0O.js';
3
- import '@empjs/module-federation-rspack';
4
-
5
- declare const shareForceRemote = "EMP_FORCE_REMOTES";
6
-
7
- /**
8
- * 运行时插件:根据 window[EMP_FORCE_REMOTES] 配置,在注册 remote 前拦截并改写其 entry/url。
9
- * 支持两种方式二选一:指定完整 entry 地址,或仅指定 version 做 URL 内版本号替换。
10
- */
11
-
12
- declare global {
13
- interface Window {
14
- [shareForceRemote]?: ForceRemoteOptions;
15
- }
16
- }
17
- declare function export_default(): ModuleFederationRuntimePlugin;
18
-
19
- export { export_default as default };
1
+ export {default} from './plugins/rspack/runtimePlugin/forceRemote'
2
+ export * from './plugins/rspack/runtimePlugin/forceRemote'
@@ -1 +1,2 @@
1
- function r(r,e){if(e==null||e>r.length)e=r.length;for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function e(r){if(Array.isArray(r))return r}function t(r,e){var t=r==null?null:typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(t==null)return;var n=[];var i=true;var o=false;var u,f;try{for(t=t.call(r);!(i=(u=t.next()).done);i=true){n.push(u.value);if(e&&n.length===e)break}}catch(r){o=true;f=r}finally{try{if(!i&&t["return"]!=null)t["return"]()}finally{if(o)throw f}}return n}function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function i(r,i){return e(r)||t(r,i)||u(r,i)||n()}function o(r){"@swc/helpers - typeof";return r&&typeof Symbol!=="undefined"&&r.constructor===Symbol?"symbol":typeof r}function u(e,t){if(!e)return;if(typeof e==="string")return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}var f="EMP_FORCE_REMOTES";var a=["entry","url","manifest"];function l(r){return a.find(function(e){return typeof r[e]=="string"})}function c(r){return(typeof r==="undefined"?"undefined":o(r))=="object"&&r!==null&&"entry"in r&&typeof r.entry=="string"}function y(r){if(typeof r=="string")return r;var e=r===null||r===void 0?void 0:r.version;return typeof e=="string"?e:void 0}function d(r){return r&&c(r)?r.entry:void 0}function v(r){return Object.fromEntries(Object.entries(r).flatMap(function(r){var e=i(r,2),t=e[0],n=e[1];if(c(n))return[];var o=y(n);return o?[[t,o]]:[]}))}function s(r,e){if(!Object.keys(e).length)return r;var t=r;var n=true,o=false,u=undefined;try{for(var f=Object.entries(e)[Symbol.iterator](),a;!(n=(a=f.next()).done);n=true){var l=i(a.value,2),c=l[0],y=l[1];if(!y)continue;var d=new RegExp("(".concat(c.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"@)([^/]+)"));t=t.replace(d,"$1".concat(y))}}catch(r){o=true;u=r}finally{try{if(!n&&f.return!=null){f.return()}}finally{if(o){throw u}}}return t}function p(){return{name:"emp-remotes-replacer",beforeRegisterRemote:function r(r){var e=(typeof window==="undefined"?"undefined":o(window))<"u"?window[f]:void 0;if(!e||(typeof e==="undefined"?"undefined":o(e))!="object")return r;var t=r.remote;if(!t)return r;var n=l(t);if(!n)return r;var i=t[n],u=t.alias?e[t.alias]:void 0,a=v(e),c=i?s(i,a):void 0;if(c&&c!==i)return t[n]=c,r;var y=d(u);return y&&(t[n]=y),r}}}export{p as default};//# sourceMappingURL=forceRemote.js.map
1
+ import{shareForceRemote as e}from"./607.js";let t=["entry","url","manifest"];function r(e){return"object"==typeof e&&null!==e&&"entry"in e&&"string"==typeof e.entry}export default function(){return{name:"emp-remotes-replacer",beforeRegisterRemote(n){let i="u">typeof window?window[e]:void 0;if(!i||"object"!=typeof i)return n;let o=n.remote;if(!o)return n;let f=t.find(e=>"string"==typeof o[e]);if(!f)return n;let l=o[f],u=o.alias?i[o.alias]:void 0,p=Object.fromEntries(Object.entries(i).flatMap(([e,t])=>{if(r(t))return[];let n=function(e){if("string"==typeof e)return e;let t=null==e?void 0:e.version;return"string"==typeof t?t:void 0}(t);return n?[[e,n]]:[]})),c=l?function(e,t){if(!Object.keys(t).length)return e;let r=e;for(let[e,n]of Object.entries(t)){if(!n)continue;let t=RegExp(`(${e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}@)([^/]+)`);r=r.replace(t,`$1${n}`)}return r}(l,p):void 0;if(c&&c!==l)return o[f]=c,n;let s=u&&r(u)?u.entry:void 0;return s&&(o[f]=s),n}}};
2
+ //# sourceMappingURL=forceRemote.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helper/config.ts","../src/plugins/rspack/runtimePlugin/forceRemote.ts"],"names":["shareForceRemote","REMOTE_ENTRY_FIELD_KEYS","getRemoteEntryFieldKey","remote","find","k","hasEntryConfig","config","entry","getVersionFromConfig","v","version","getEntryFromConfig","buildVersionReplaceMap","forceRemotes","Object","fromEntries","entries","flatMap","remoteKey","replaceUrlVersions","url","versionMap","keys","length","result","regex","RegExp","replace","forceRemote_default","name","beforeRegisterRemote","args","window","entryFieldKey","currentEntryUrl","forceConfig","alias","versionedEntryUrl","forcedEntryUrl","g","default"],"mappings":"snCAEO,IAAMA,EAAmB,oBCahC,IAAMC,EAA0B,CAAC,QAAS,MAAO,WAAU,CAK3D,SAASC,EAAuBC,CAAAA,EAC9B,OAAOF,EAAwBG,IAAA,CAAMC,SAAAA,UAAM,OAAOF,CAAAA,CAAOE,EAAC,EAAM,UAClE,CAEA,SAASC,EAAeC,CAA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,CAAA,OAAOmB,iCAAP,EAAOA,OAAA,EAAW,IAAcA,MAAA,CAAOjC,EAAgB,CAAI,KAAA,EAChF,GAAI,CAACc,GAAgB,CAAA,OAAOA,4BAAP,EAAOA,EAAAA,GAAiB,SAAU,OAAOkB,EAE9D,IAAM7B,EAAS6B,EAAK7B,MAAA,CACpB,GAAI,CAACA,EAAQ,OAAO6B,EAEpB,IAAME,EAAgBhC,EAAuBC,GAC7C,GAAI,CAAC+B,EAAe,OAAOF,EAE3B,IAAMG,EAAkBhC,CAAAA,CAAO+B,EAAa,CACtCE,EAAcjC,EAAOkC,KAAA,CAAQvB,CAAAA,CAAaX,EAAOkC,KAAK,CAAA,CAAI,KAAA,EAG1Df,EAAaT,EAAuBC,GACpCwB,EAAoBH,EAAkBf,EAAmBe,EAAiBb,GAAc,KAAA,EAC9F,GAAIgB,GAAqBA,IAAsBH,EAC7C,OAAAhC,CAAAA,CAAO+B,EAAa,CAAII,EACjBN,EAIT,IAAMO,EAAiB3B,EAAmBwB,GAC1C,OAAIG,GACFpC,CAAAA,CAAAA,CAAO+B,EAAa,CAAIK,CAAAA,EACjBP,CAIX,CACF,CACF,QAAAQ,KAAAC,OAAA","sourcesContent":["export const shareGlobalName = 'EMP_SHARE_RUNTIME'\nexport const shareGlobalVal = 'EMPShareGlobalVal'\nexport const shareForceRemote = 'EMP_FORCE_REMOTES'\n","/**\n * 运行时插件:根据 window[EMP_FORCE_REMOTES] 配置,在注册 remote 前拦截并改写其 entry/url。\n * 支持两种方式二选一:指定完整 entry 地址,或仅指定 version 做 URL 内版本号替换。\n */\nimport {type ModuleFederationRuntimePlugin} from '@module-federation/runtime'\nimport {shareForceRemote} from 'src/helper/config'\nimport {type ForceRemoteItem, type ForceRemoteOptions, type RemoteInfoForForce} from '../types'\n\ndeclare global {\n interface Window {\n [shareForceRemote]?: ForceRemoteOptions\n }\n}\n\n/** remote 上可能表示入口地址的字段,按优先级 */\nconst REMOTE_ENTRY_FIELD_KEYS = ['entry', 'url', 'manifest'] as const\n\n/**\n * 取当前 remote 用于表示入口的字段名(entry / url / manifest 中第一个为字符串的)\n */\nfunction getRemoteEntryFieldKey(remote: RemoteInfoForForce): (typeof REMOTE_ENTRY_FIELD_KEYS)[number] | undefined {\n return REMOTE_ENTRY_FIELD_KEYS.find((k) => typeof remote[k] === 'string')\n}\n\nfunction hasEntryConfig(config: ForceRemoteItem): boolean {\n return typeof config === 'object' && config !== null && 'entry' in config && typeof (config as {entry?: string}).entry === 'string'\n}\n\nfunction getVersionFromConfig(config: ForceRemoteItem): string | undefined {\n if (typeof config === 'string') return config\n const v = (config as {version?: string})?.version\n return typeof v === 'string' ? v : undefined\n}\n\nfunction getEntryFromConfig(config: ForceRemoteItem | undefined): string | undefined {\n return config && hasEntryConfig(config) ? (config as {entry: string}).entry : undefined\n}\n\n/**\n * 从 forceRemotes 提取「仅 version」项的映射(有 entry 的项不参与,二选一)。\n */\nfunction buildVersionReplaceMap(forceRemotes: ForceRemoteOptions): Record<string, string> {\n return Object.fromEntries(\n Object.entries(forceRemotes).flatMap(([remoteKey, config]) => {\n if (hasEntryConfig(config)) return []\n const version = getVersionFromConfig(config)\n return version ? [[remoteKey, version]] : []\n }),\n )\n}\n\n/**\n * 在 URL 中按 versionMap 替换 common 版本号(匹配 `remoteKey@原版本` -> `remoteKey@新版本`)\n */\nfunction replaceUrlVersions(url: string, versionMap: Record<string, string>): string {\n if (!Object.keys(versionMap).length) return url\n let result = url\n for (const [remoteKey, version] of Object.entries(versionMap)) {\n if (!version) continue\n const regex = new RegExp(`(${remoteKey.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&')}@)([^/]+)`)\n result = result.replace(regex, `$1${version}`)\n }\n return result\n}\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'emp-remotes-replacer',\n beforeRegisterRemote(args) {\n const forceRemotes = typeof window !== 'undefined' ? window[shareForceRemote] : undefined\n if (!forceRemotes || typeof forceRemotes !== 'object') return args\n\n const remote = args.remote as unknown as RemoteInfoForForce\n if (!remote) return args\n\n const entryFieldKey = getRemoteEntryFieldKey(remote)\n if (!entryFieldKey) return args\n\n const currentEntryUrl = remote[entryFieldKey] as string | undefined\n const forceConfig = remote.alias ? forceRemotes[remote.alias] : undefined\n\n // 优先 version:有则替换并直接 return,不再走 entry\n const versionMap = buildVersionReplaceMap(forceRemotes)\n const versionedEntryUrl = currentEntryUrl ? replaceUrlVersions(currentEntryUrl, versionMap) : undefined\n if (versionedEntryUrl && versionedEntryUrl !== currentEntryUrl) {\n remote[entryFieldKey] = versionedEntryUrl\n return args\n }\n\n // 否则判断 entry:有则改写并 return\n const forcedEntryUrl = getEntryFromConfig(forceConfig)\n if (forcedEntryUrl) {\n remote[entryFieldKey] = forcedEntryUrl\n return args\n }\n\n return args\n },\n }\n}\n"]}
1
+ {"version":3,"file":"forceRemote.js","sources":["../src/plugins/rspack/runtimePlugin/forceRemote.ts"],"sourcesContent":["/**\n * 运行时插件:根据 window[EMP_FORCE_REMOTES] 配置,在注册 remote 前拦截并改写其 entry/url。\n * 支持两种方式二选一:指定完整 entry 地址,或仅指定 version 做 URL 内版本号替换。\n */\nimport {type ModuleFederationRuntimePlugin} from '@module-federation/runtime'\nimport {shareForceRemote} from 'src/helper/config'\nimport {type ForceRemoteItem, type ForceRemoteOptions, type RemoteInfoForForce} from '../types'\n\ndeclare global {\n interface Window {\n [shareForceRemote]?: ForceRemoteOptions\n }\n}\n\n/** remote 上可能表示入口地址的字段,按优先级 */\nconst REMOTE_ENTRY_FIELD_KEYS = ['entry', 'url', 'manifest'] as const\n\n/**\n * 取当前 remote 用于表示入口的字段名(entry / url / manifest 中第一个为字符串的)\n */\nfunction getRemoteEntryFieldKey(remote: RemoteInfoForForce): (typeof REMOTE_ENTRY_FIELD_KEYS)[number] | undefined {\n return REMOTE_ENTRY_FIELD_KEYS.find((k) => typeof remote[k] === 'string')\n}\n\nfunction hasEntryConfig(config: ForceRemoteItem): boolean {\n return typeof config === 'object' && config !== null && 'entry' in config && typeof (config as {entry?: string}).entry === 'string'\n}\n\nfunction getVersionFromConfig(config: ForceRemoteItem): string | undefined {\n if (typeof config === 'string') return config\n const v = (config as {version?: string})?.version\n return typeof v === 'string' ? v : undefined\n}\n\nfunction getEntryFromConfig(config: ForceRemoteItem | undefined): string | undefined {\n return config && hasEntryConfig(config) ? (config as {entry: string}).entry : undefined\n}\n\n/**\n * 从 forceRemotes 提取「仅 version」项的映射(有 entry 的项不参与,二选一)。\n */\nfunction buildVersionReplaceMap(forceRemotes: ForceRemoteOptions): Record<string, string> {\n return Object.fromEntries(\n Object.entries(forceRemotes).flatMap(([remoteKey, config]) => {\n if (hasEntryConfig(config)) return []\n const version = getVersionFromConfig(config)\n return version ? [[remoteKey, version]] : []\n }),\n )\n}\n\n/**\n * 在 URL 中按 versionMap 替换 common 版本号(匹配 `remoteKey@原版本` -> `remoteKey@新版本`)\n */\nfunction replaceUrlVersions(url: string, versionMap: Record<string, string>): string {\n if (!Object.keys(versionMap).length) return url\n let result = url\n for (const [remoteKey, version] of Object.entries(versionMap)) {\n if (!version) continue\n const regex = new RegExp(`(${remoteKey.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&')}@)([^/]+)`)\n result = result.replace(regex, `$1${version}`)\n }\n return result\n}\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'emp-remotes-replacer',\n beforeRegisterRemote(args) {\n const forceRemotes = typeof window !== 'undefined' ? window[shareForceRemote] : undefined\n if (!forceRemotes || typeof forceRemotes !== 'object') return args\n\n const remote = args.remote as unknown as RemoteInfoForForce\n if (!remote) return args\n\n const entryFieldKey = getRemoteEntryFieldKey(remote)\n if (!entryFieldKey) return args\n\n const currentEntryUrl = remote[entryFieldKey] as string | undefined\n const forceConfig = remote.alias ? forceRemotes[remote.alias] : undefined\n\n // 优先 version:有则替换并直接 return,不再走 entry\n const versionMap = buildVersionReplaceMap(forceRemotes)\n const versionedEntryUrl = currentEntryUrl ? replaceUrlVersions(currentEntryUrl, versionMap) : undefined\n if (versionedEntryUrl && versionedEntryUrl !== currentEntryUrl) {\n remote[entryFieldKey] = versionedEntryUrl\n return args\n }\n\n // 否则判断 entry:有则改写并 return\n const forcedEntryUrl = getEntryFromConfig(forceConfig)\n if (forcedEntryUrl) {\n remote[entryFieldKey] = forcedEntryUrl\n return args\n }\n\n return args\n },\n }\n}\n"],"names":["REMOTE_ENTRY_FIELD_KEYS","hasEntryConfig","config","args","forceRemotes","window","shareForceRemote","undefined","remote","entryFieldKey","k","currentEntryUrl","forceConfig","versionMap","Object","remoteKey","version","getVersionFromConfig","v","versionedEntryUrl","replaceUrlVersions","url","result","regex","RegExp","forcedEntryUrl"],"mappings":"0DAeA,IAAMA,EAA0B,CAAC,QAAS,MAAO,WAAW,CAS5D,SAASC,EAAeC,CAAuB,EAC7C,MAAO,AAAkB,UAAlB,OAAOA,GAAuBA,AAAW,OAAXA,GAAmB,UAAWA,GAAU,AAA8C,UAA9C,OAAQA,EAA4B,KAAK,AACxH,C,eAuCe,WACb,MAAO,CACL,KAAM,uBACN,qBAAqBC,CAAI,EACvB,IAAMC,EAAe,AAAkB,IAAlB,OAAOC,OAAyBA,MAAM,CAACC,EAAiB,CAAGC,OAChF,GAAI,CAACH,GAAgB,AAAwB,UAAxB,OAAOA,EAA2B,OAAOD,EAE9D,IAAMK,EAASL,EAAK,MAAM,CAC1B,GAAI,CAACK,EAAQ,OAAOL,EAEpB,IAAMM,EAtDHT,EAAwB,IAAI,CAAC,AAACU,GAAM,AAAqB,UAArB,OAAOF,AAsDDA,CAtDO,CAACE,EAAE,EAuDvD,GAAI,CAACD,EAAe,OAAON,EAE3B,IAAMQ,EAAkBH,CAAM,CAACC,EAAc,CACvCG,EAAcJ,EAAO,KAAK,CAAGJ,CAAY,CAACI,EAAO,KAAK,CAAC,CAAGD,OAG1DM,EAxCHC,OAAO,WAAW,CACvBA,OAAO,OAAO,CAuC8BV,GAvCf,OAAO,CAAC,CAAC,CAACW,EAAWb,EAAO,IACvD,GAAID,EAAeC,GAAS,MAAO,EAAE,CACrC,IAAMc,EAAUC,AAjBtB,SAA8Bf,CAAuB,EACnD,GAAI,AAAkB,UAAlB,OAAOA,EAAqB,OAAOA,EACvC,IAAMgB,EAAKhB,MAAAA,EAAAA,KAAAA,EAAAA,EAA+B,OAAO,CACjD,MAAO,AAAa,UAAb,OAAOgB,EAAiBA,EAAIX,MACrC,EAa2CL,GACrC,OAAOc,EAAU,CAAC,CAACD,EAAWC,EAAQ,CAAC,CAAG,EAAE,AAC9C,IAoCQG,EAAoBR,EAAkBS,AA7BlD,SAA4BC,CAAW,CAAER,CAAkC,EACzE,GAAI,CAACC,OAAO,IAAI,CAACD,GAAY,MAAM,CAAE,OAAOQ,EAC5C,IAAIC,EAASD,EACb,IAAK,GAAM,CAACN,EAAWC,EAAQ,GAAIF,OAAO,OAAO,CAACD,GAAa,CAC7D,GAAI,CAACG,EAAS,SACd,IAAMO,EAAQ,AAAIC,OAAO,CAAC,CAAC,EAAET,EAAU,OAAO,CAAC,wBAAyB,QAAQ,SAAS,CAAC,EAC1FO,EAASA,EAAO,OAAO,CAACC,EAAO,CAAC,EAAE,EAAEP,EAAQ,CAAC,CAC/C,CACA,OAAOM,CACT,EAoBqEX,EAAiBE,GAAcN,OAC9F,GAAIY,GAAqBA,IAAsBR,EAE7C,OADAH,CAAM,CAACC,EAAc,CAAGU,EACjBhB,EAIT,IAAMsB,EAvDHvB,AAuDuCU,GAvD7BX,EAuD6BW,GAvDHV,AAuDGU,EAvDwB,KAAK,CAAGL,OA6D1E,OALIkB,GACFjB,CAAAA,CAAM,CAACC,EAAc,CAAGgB,CAAa,EAIhCtB,CACT,CACF,CACF,C"}
@@ -0,0 +1 @@
1
+ export declare const externalReact: (o: any, globalVal: string) => any;
@@ -0,0 +1,3 @@
1
+ import { shared } from './shared';
2
+ declare const external: (o: any, globalVal: string) => any;
3
+ export { shared, external };
@@ -0,0 +1,2 @@
1
+ import { InitOptionsType } from '../../types';
2
+ export declare const shared: () => InitOptionsType["shared"];
@@ -0,0 +1 @@
1
+ export declare const externalVue: (o: any, globalVal: string) => any;
@@ -0,0 +1,3 @@
1
+ import { shared } from './shared';
2
+ declare const external: (o: any, globalVal: string) => any;
3
+ export { shared, external };
@@ -0,0 +1,2 @@
1
+ import { InitOptionsType } from '../../types';
2
+ export declare const shared: () => InitOptionsType["shared"];
@@ -0,0 +1,3 @@
1
+ export declare const shareGlobalName = "EMP_SHARE_RUNTIME";
2
+ export declare const shareGlobalVal = "EMPShareGlobalVal";
3
+ export declare const shareForceRemote = "EMP_FORCE_REMOTES";
@@ -0,0 +1,6 @@
1
+ export declare const importJsVm: (content: string) => string;
2
+ export declare function deepAssign<T>(target: any, ...sources: any): T;
3
+ export declare const checkVersion: (version: string) => number;
4
+ export declare const isPromise: (p: any) => any;
5
+ export declare const isDev: boolean;
6
+ export declare const log: (...args: any[]) => void;
@@ -0,0 +1,6 @@
1
+ import * as MFRuntime from '@module-federation/runtime';
2
+ import * as MFSDK from '@module-federation/sdk';
3
+ export { MFRuntime, MFSDK };
4
+ import type { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
5
+ export type FederationRuntimePlugin = ModuleFederationRuntimePlugin;
6
+ export type { ModuleFederationRuntimePlugin };
@@ -0,0 +1 @@
1
+ export declare function resolvePackageExport(specifier: string): string;
@@ -0,0 +1 @@
1
+ export { ModuleFederationPlugin } from '@module-federation/rspack';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,3 @@
1
- import pluginRspackEmpShare from './rspack.js';
2
- export { externalReact, externalVue } from './rspack.js';
3
- export { E as EMPPluginShareType, a as EMPSHARERuntimeOptions, h as ExternalsItemType, d as ForceRemoteEntryOption, e as ForceRemoteItem, g as ForceRemoteOptions, F as ForceRemoteVersion, c as ForceRemoteVersionOption, M as ModuleFederationPluginOptions, R as RemoteInfoForForce, f as frameworLibType, b as frameworkOptions, r as runtimeLibType } from './types-BGnQUQ0O.js';
4
- import '@empjs/cli';
5
- import '@empjs/module-federation-rspack';
6
-
7
-
8
-
9
- export { pluginRspackEmpShare as default, pluginRspackEmpShare };
1
+ import { default as pluginRspackEmpShare } from './plugins/rspack';
2
+ export default pluginRspackEmpShare;
3
+ export * from './plugins/rspack';