@empjs/share 3.13.9-beta.2 → 4.0.0-alpha.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 +202 -62
- package/dist/171.js +2 -0
- package/dist/171.js.map +1 -0
- package/dist/227.js +2 -0
- package/dist/227.js.map +1 -0
- package/dist/607.js +2 -0
- package/dist/607.js.map +1 -0
- package/dist/68.js +2 -0
- package/dist/68.js.map +1 -0
- package/dist/adapter/index.d.ts +1 -0
- package/dist/{adapter.d.cts → adapter/react.d.ts} +3 -8
- package/dist/adapter/vue.d.ts +1 -0
- package/dist/adapter.d.ts +1 -14
- package/dist/adapter.js +2 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapterVue.d.ts +1 -0
- package/dist/adapterVue.js +1 -0
- package/dist/forceRemote.d.ts +2 -19
- package/dist/forceRemote.js +2 -1
- package/dist/forceRemote.js.map +1 -1
- package/dist/framework/react/config.d.ts +1 -0
- package/dist/framework/react/index.d.ts +3 -0
- package/dist/framework/react/shared.d.ts +2 -0
- package/dist/framework/vue/config.d.ts +1 -0
- package/dist/framework/vue/index.d.ts +3 -0
- package/dist/framework/vue/shared.d.ts +2 -0
- package/dist/helper/config.d.ts +3 -0
- package/dist/helper/index.d.ts +6 -0
- package/dist/helper/moduleFederation.d.ts +6 -0
- package/dist/helper/resolvePackageExport.d.ts +1 -0
- package/dist/helper/rspack.d.ts +1 -0
- package/dist/index.d.ts +3 -9
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/library/full.d.ts +7 -0
- package/dist/library/sdk.d.ts +2 -0
- package/dist/library/sdkPolyfill.d.ts +3 -0
- package/dist/library/wSdk.d.ts +2 -0
- package/dist/mfRuntime.d.ts +1 -1
- package/dist/mfRuntime.js +1 -1
- package/dist/plugins/rspack/index.d.ts +11 -0
- package/dist/plugins/rspack/plugin.d.ts +7 -0
- package/dist/plugins/rspack/runtimePlugin/forceRemote.d.ts +13 -0
- package/dist/plugins/rspack/runtimePlugin/registerRemotes.d.ts +3 -0
- package/dist/plugins/rspack/share.d.ts +30 -0
- package/dist/{types-BGnQUQ0O.d.cts → plugins/rspack/types.d.ts} +14 -17
- package/dist/plugins/rspack/utils.d.ts +2 -0
- package/dist/react.d.ts +1 -9
- package/dist/react.js +2 -1
- package/dist/react.js.map +1 -1
- package/dist/rspack.d.ts +2 -15
- package/dist/rspack.js +2 -1
- package/dist/rspack.js.map +1 -1
- package/dist/{runtime.d.cts → runtime/index.d.ts} +4 -7
- package/dist/runtime/index.pre.version.d.ts +22 -0
- package/dist/runtime/plugins.d.ts +2 -0
- package/dist/runtime/sdk-prev.d.ts +30 -0
- package/dist/runtime/sdk.d.ts +31 -0
- package/dist/runtime.d.ts +2 -23
- package/dist/runtime.js +2 -1
- package/dist/runtime.js.map +1 -1
- package/dist/sdk.d.ts +1 -34
- package/dist/sdk.js +2 -1
- package/dist/sdk.js.map +1 -1
- package/dist/types/index.d.ts +26 -0
- package/dist/vue.d.ts +1 -9
- package/dist/vue.js +2 -1
- package/dist/vue.js.map +1 -1
- package/output/adapter/index.d.ts +1 -0
- package/output/adapter/react.d.ts +9 -0
- package/output/adapter/vue.d.ts +1 -0
- package/output/framework/react/config.d.ts +1 -0
- package/output/framework/react/index.d.ts +3 -0
- package/output/framework/react/shared.d.ts +2 -0
- package/output/framework/vue/config.d.ts +1 -0
- package/output/framework/vue/index.d.ts +3 -0
- package/output/framework/vue/shared.d.ts +2 -0
- package/output/helper/config.d.ts +3 -0
- package/output/helper/index.d.ts +6 -0
- package/output/helper/moduleFederation.d.ts +6 -0
- package/output/helper/resolvePackageExport.d.ts +1 -0
- package/output/helper/rspack.d.ts +1 -0
- package/output/index.d.ts +3 -0
- package/output/library/full.d.ts +7 -0
- package/output/library/sdk.d.ts +2 -0
- package/output/library/sdkPolyfill.d.ts +3 -0
- package/output/library/wSdk.d.ts +2 -0
- package/output/plugins/rspack/index.d.ts +11 -0
- package/output/plugins/rspack/plugin.d.ts +7 -0
- package/output/plugins/rspack/runtimePlugin/forceRemote.d.ts +13 -0
- package/output/plugins/rspack/runtimePlugin/registerRemotes.d.ts +3 -0
- package/output/plugins/rspack/share.d.ts +30 -0
- package/{dist/types-BGnQUQ0O.d.ts → output/plugins/rspack/types.d.ts} +14 -17
- package/output/plugins/rspack/utils.d.ts +2 -0
- package/output/runtime/index.d.ts +20 -0
- package/output/runtime/index.pre.version.d.ts +22 -0
- package/output/runtime/mfRuntime.d.ts +1 -0
- package/output/runtime/plugins.d.ts +2 -0
- package/output/runtime/sdk-prev.d.ts +30 -0
- package/output/runtime/sdk.d.ts +31 -0
- package/output/sdk.d.ts +1 -0
- package/output/sdk.js +5 -1
- package/output/types/index.d.ts +26 -0
- package/package.json +42 -90
- package/dist/adapter.cjs +0 -1
- package/dist/adapter.cjs.map +0 -1
- package/dist/forceRemote.cjs +0 -1
- package/dist/forceRemote.cjs.map +0 -1
- package/dist/forceRemote.d.cts +0 -19
- package/dist/index-DaSrQPN9.d.cts +0 -21
- package/dist/index-DaSrQPN9.d.ts +0 -21
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -9
- package/dist/mfRuntime.cjs +0 -1
- package/dist/mfRuntime.cjs.map +0 -1
- package/dist/mfRuntime.js.map +0 -1
- package/dist/react.cjs +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.d.cts +0 -9
- package/dist/rspack.cjs +0 -1
- package/dist/rspack.cjs.map +0 -1
- package/dist/rspack.d.cts +0 -15
- package/dist/runtime.cjs +0 -1
- package/dist/runtime.cjs.map +0 -1
- package/dist/sdk.cjs +0 -1
- package/dist/sdk.cjs.map +0 -1
- package/dist/sdk.d.cts +0 -34
- package/dist/vue.cjs +0 -1
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.d.cts +0 -9
- /package/dist/{mfRuntime.d.cts → runtime/mfRuntime.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,94 +1,234 @@
|
|
|
1
|
-
#
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
```
|
|
9
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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 {
|
|
53
|
-
import
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
177
|
+
shared: reactAdapter.shared,
|
|
66
178
|
})
|
|
67
|
-
|
|
179
|
+
|
|
68
180
|
const MfApp = reactAdapter.adapter(empRuntime.load('mfHost/App'))
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
package/dist/171.js.map
ADDED
|
@@ -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
|
package/dist/227.js.map
ADDED
|
@@ -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
package/dist/607.js.map
ADDED
|
@@ -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
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 {
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/dist/adapter.js.map
CHANGED
|
@@ -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","createRoot","then","m","createElement","render","hydrate","ref","Component","reactAdapter"],"mappings":"swGAAA,IAAIA,EAAEC,OAAOC,cAAc,CAAC,IAAIC,EAAE,SAACC,EAAEC,EAAEC,UAAID,KAAKD,EAAEJ,EAAEI,EAAEC,EAAE,CAACE,WAAW,CAAC,EAAEC,aAAa,CAAC,EAAEC,SAAS,CAAC,EAAEC,MAAMJ,CAAC,GAAGF,CAAC,CAACC,EAAE,CAAC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CAAAA,CAAEjC,EACV,aAFDa,EAAY,4BAGRiB,EAAUzB,EAAM6B,aAAA,CAAcrB,EAAW,IAAA,CAAKI,KAAK,EAEzD,GAAIH,EAAe,GAAA,AACFe,CAAAA,EAAevB,EAAS6B,MAAA,CAAS7B,EAAS8B,OAAA,EAClDN,EAAS,IAAA,CAAKZ,YAAA,CAAaO,OAAO,EACzCpC,EAAI,iBAAkBwC,EAAcf,QAAY,GAEhDzB,EAAI,iBAAkBwC,EAAcf,GAChCe,EAAc,CACKd,EAAAA,EAAKZ,IAAA,CAAnB4B,EAAchB,EAAdgB,UACP,CAAA,IAAA,CAAKJ,IAAA,CAAOI,EAAW,IAAA,CAAKb,YAAA,CAAaO,OAAQ,EACjD,IAAA,CAAKE,IAAA,CAAKQ,MAAA,CAAOL,EACnB,MAGE,IAAA,CAAKH,IAAA,CAAKQ,MAAA,eAGhB,iBAEAA,IAAAA,eAAAA,SAAAA,IACE,OAAO9B,EAAA6B,aAAA,CAAC,MAAA,CAAIG,IAAK,IAAA,CAAKnB,YAAA,EACxB,YAzDIF,GAAyBX,EAAMiC,SAAU,EA2D/C,OAAOtB,CACT,iBAGWuB,EAAe,IAAI1C,SAAAA,KAAAA,YAAAA,CAAAA,KAAAA,YAAAA","sourcesContent":["var g=Object.defineProperty;var E=(t,e,n)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var c=(t,e,n)=>E(t,typeof e!=\"symbol\"?e+\"\":e,n);var h=t=>t?Number(t.split(\".\")[0]):0,f=t=>t&&Object.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,GAA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apter}from"./adapter.js";
|
package/dist/forceRemote.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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'
|
package/dist/forceRemote.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
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
|
package/dist/forceRemote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 @@
|
|
|
1
|
+
export declare const externalVue: (o: any, globalVal: string) => any;
|
|
@@ -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
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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';
|