@fulgurjs/federation 6.8.7 → 6.9.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.
- package/CHANGELOG.md +14 -0
- package/README.en.md +3 -0
- package/README.md +3 -0
- package/dist/application-core-BuhXQmLF.d.cts +16 -0
- package/dist/application-core-DWI3eKme.d.ts +16 -0
- package/dist/bridge-app-react.cjs +177 -9
- package/dist/bridge-app-react.d.cts +15 -3
- package/dist/bridge-app-react.d.ts +15 -3
- package/dist/bridge-app-react.js +101 -9
- package/dist/bridge-app-vue.cjs +138 -12
- package/dist/bridge-app-vue.d.cts +20 -5
- package/dist/bridge-app-vue.d.ts +20 -5
- package/dist/bridge-app-vue.js +62 -12
- package/dist/bridge-host-react.d.cts +1 -1
- package/dist/bridge-host-react.d.ts +1 -1
- package/dist/bridge-host-vue.d.cts +1 -1
- package/dist/bridge-host-vue.d.ts +1 -1
- package/dist/chunk-6OB47FSR.js +81 -0
- package/dist/cli.js +349 -23
- package/dist/index.cjs +7 -6
- package/dist/index.js +7 -6
- package/dist/react-adapter.d.cts +1 -1
- package/dist/react-adapter.d.ts +1 -1
- package/dist/react.d.ts +29 -4
- package/dist/react.js +1 -0
- package/dist/{remote-types-xf1B6_pK.d.ts → remote-types-COmBhjRc.d.ts} +1 -1
- package/dist/{remote-types-58hdbx6x.d.cts → remote-types-CStGOJwu.d.cts} +1 -1
- package/dist/runtime.js +1 -1
- package/dist/vue-adapter.d.cts +1 -1
- package/dist/vue-adapter.d.ts +1 -1
- package/dist/vue-store.cjs +40 -0
- package/dist/vue-store.d.cts +4 -0
- package/dist/vue-store.d.ts +4 -0
- package/dist/vue-store.js +15 -0
- package/dist/vue.d.ts +37 -6
- package/dist/vue.js +2 -0
- package/docs/en/reference/api.md +38 -2
- package/docs/en/reference/types.md +27 -0
- package/docs/zh/reference/api.md +46 -2
- package/docs/zh/reference/types.md +27 -0
- package/examples/templates/README.md +3 -0
- package/examples/templates/react-host-vue-remote/README.md +24 -0
- package/examples/templates/react-host-vue-remote/package.json +2 -1
- package/examples/templates/react-host-vue-remote/pnpm-lock.yaml +189 -189
- package/examples/templates/react-host-vue-remote/pnpm-workspace.yaml +1 -1
- package/examples/templates/react-host-vue-remote/react-host/package.json +1 -1
- package/examples/templates/react-host-vue-remote/react-host/src/application.tsx +62 -0
- package/examples/templates/react-host-vue-remote/react-host/src/main.tsx +2 -62
- package/examples/templates/react-host-vue-remote/scripts/prod.mjs +101 -0
- package/examples/templates/react-host-vue-remote/vue-remote/README.md +17 -16
- package/examples/templates/react-host-vue-remote/vue-remote/fulgurjs.config.ts +2 -2
- package/examples/templates/react-host-vue-remote/vue-remote/package.json +1 -1
- package/examples/templates/react-host-vue-remote/vue-remote/src/AboutPage.vue +1 -0
- package/examples/templates/react-host-vue-remote/vue-remote/src/App.vue +15 -5
- package/examples/templates/react-host-vue-remote/vue-remote/src/HomePage.vue +1 -0
- package/examples/templates/react-host-vue-remote/vue-remote/src/application.ts +19 -0
- package/examples/templates/react-host-vue-remote/vue-remote/src/main.ts +2 -15
- package/examples/templates/react-react/README.md +25 -1
- package/examples/templates/react-react/host/package.json +1 -1
- package/examples/templates/react-react/host/src/application.tsx +33 -0
- package/examples/templates/react-react/host/src/main.tsx +3 -32
- package/examples/templates/react-react/package.json +2 -1
- package/examples/templates/react-react/pnpm-lock.yaml +123 -123
- package/examples/templates/react-react/pnpm-workspace.yaml +1 -1
- package/examples/templates/react-react/remote/package.json +1 -1
- package/examples/templates/react-react/remote/src/application.tsx +11 -0
- package/examples/templates/react-react/remote/src/main.tsx +3 -10
- package/examples/templates/react-react/scripts/prod.mjs +101 -0
- package/examples/templates/showcase/README.md +35 -7
- package/examples/templates/showcase/package.json +2 -1
- package/examples/templates/showcase/pnpm-lock.yaml +196 -196
- package/examples/templates/showcase/pnpm-workspace.yaml +1 -1
- package/examples/templates/showcase/react-host/package.json +1 -1
- package/examples/templates/showcase/react-host/src/application.tsx +28 -0
- package/examples/templates/showcase/react-host/src/demo-log.ts +5 -8
- package/examples/templates/showcase/react-host/src/main.tsx +2 -33
- package/examples/templates/showcase/react-host/src/routing.ts +2 -2
- package/examples/templates/showcase/react-remote/fulgurjs.config.ts +1 -1
- package/examples/templates/showcase/react-remote/package.json +1 -1
- package/examples/templates/showcase/react-remote/src/ChildLayout.tsx +3 -2
- package/examples/templates/showcase/react-remote/src/{bridge.tsx → application.tsx} +21 -21
- package/examples/templates/showcase/react-remote/src/child-bus.ts +23 -23
- package/examples/templates/showcase/react-remote/src/main.tsx +2 -18
- package/examples/templates/showcase/react-remote/src/pages/Locked.tsx +2 -1
- package/examples/templates/showcase/react-remote/src/pages/OrderDetail.tsx +2 -1
- package/examples/templates/showcase/react-remote/src/pages/OrderList.tsx +2 -1
- package/examples/templates/showcase/scripts/prod.mjs +101 -0
- package/examples/templates/showcase/vue-host/package.json +1 -1
- package/examples/templates/showcase/vue-host/src/application.ts +28 -0
- package/examples/templates/showcase/vue-host/src/demo-log.ts +4 -7
- package/examples/templates/showcase/vue-host/src/main.ts +2 -30
- package/examples/templates/showcase/vue-host/src/routing.ts +2 -2
- package/examples/templates/showcase/vue-remote/fulgurjs.config.ts +1 -1
- package/examples/templates/showcase/vue-remote/package.json +1 -1
- package/examples/templates/showcase/vue-remote/src/ChildLayout.vue +3 -2
- package/examples/templates/showcase/vue-remote/src/{bridge.ts → application.ts} +10 -13
- package/examples/templates/showcase/vue-remote/src/child-bus.ts +23 -23
- package/examples/templates/showcase/vue-remote/src/main.ts +2 -16
- package/examples/templates/showcase/vue-remote/src/pages/Locked.vue +2 -1
- package/examples/templates/showcase/vue-remote/src/pages/OrderDetail.vue +2 -1
- package/examples/templates/showcase/vue-remote/src/pages/OrderList.vue +2 -1
- package/examples/templates/vue-host-react-remote/README.md +24 -0
- package/examples/templates/vue-host-react-remote/package.json +2 -1
- package/examples/templates/vue-host-react-remote/pnpm-lock.yaml +184 -184
- package/examples/templates/vue-host-react-remote/pnpm-workspace.yaml +1 -1
- package/examples/templates/vue-host-react-remote/react-remote/README.md +17 -17
- package/examples/templates/vue-host-react-remote/react-remote/fulgurjs.config.ts +2 -2
- package/examples/templates/vue-host-react-remote/react-remote/package.json +1 -1
- package/examples/templates/vue-host-react-remote/react-remote/src/{bridge.tsx → application.tsx} +13 -24
- package/examples/templates/vue-host-react-remote/react-remote/src/main.tsx +2 -7
- package/examples/templates/vue-host-react-remote/scripts/prod.mjs +101 -0
- package/examples/templates/vue-host-react-remote/vue-host/package.json +1 -1
- package/examples/templates/vue-host-react-remote/vue-host/src/application.ts +5 -0
- package/examples/templates/vue-host-react-remote/vue-host/src/main.ts +2 -4
- package/examples/templates/vue-vue/README.md +25 -1
- package/examples/templates/vue-vue/host/package.json +1 -1
- package/examples/templates/vue-vue/host/src/application.ts +54 -0
- package/examples/templates/vue-vue/host/src/main.ts +3 -50
- package/examples/templates/vue-vue/package.json +2 -1
- package/examples/templates/vue-vue/pnpm-lock.yaml +182 -182
- package/examples/templates/vue-vue/pnpm-workspace.yaml +1 -1
- package/examples/templates/vue-vue/remote/package.json +1 -1
- package/examples/templates/vue-vue/remote/src/application.ts +6 -0
- package/examples/templates/vue-vue/remote/src/main.ts +3 -5
- package/examples/templates/vue-vue/scripts/prod.mjs +101 -0
- package/package.json +14 -9
- package/examples/templates/react-host-vue-remote/react-host/src/fulgurjs/types/bridge-vue-remote/metadata.json +0 -15
- package/examples/templates/react-host-vue-remote/react-host/src/fulgurjs/types/bridge-vue-remote/modules.d.ts +0 -14
- package/examples/templates/react-host-vue-remote/react-host/src/fulgurjs/types/bridge-vue-remote/registry.d.ts +0 -10
- package/examples/templates/react-host-vue-remote/vue-remote/src/bridge.ts +0 -57
- package/examples/templates/showcase/react-host/src/fulgurjs/types/vue-remote/metadata.json +0 -16
- package/examples/templates/showcase/react-host/src/fulgurjs/types/vue-remote/modules.d.ts +0 -71
- package/examples/templates/showcase/react-host/src/fulgurjs/types/vue-remote/registry.d.ts +0 -10
- package/examples/templates/showcase/vue-host/src/fulgurjs/types/react-remote/metadata.json +0 -16
- package/examples/templates/showcase/vue-host/src/fulgurjs/types/react-remote/modules.d.ts +0 -79
- package/examples/templates/showcase/vue-host/src/fulgurjs/types/react-remote/registry.d.ts +0 -10
- package/examples/templates/vue-host-react-remote/vue-host/src/fulgurjs/types/bridge-react-remote/metadata.json +0 -16
- package/examples/templates/vue-host-react-remote/vue-host/src/fulgurjs/types/bridge-react-remote/modules.d.ts +0 -10
- package/examples/templates/vue-host-react-remote/vue-host/src/fulgurjs/types/bridge-react-remote/registry.d.ts +0 -10
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
* examples/templates/showcase/vue-remote/src/bridge.ts — Vue 子应用桥接契约(exposes './bridge')。
|
|
3
|
-
* defineBridgeApp(factory, { routing: true }) 声明路由协议(缺失时宿主启用同步即 MFU-031 占位)。
|
|
4
|
-
* 返回 { app, router },插件等待初始位置、安装路由、挂载并在卸载时释放连接。
|
|
5
|
-
*/
|
|
1
|
+
// 独立与桥接装配唯一入口;返回未安装的 app/router,交给插件等待与挂载。
|
|
6
2
|
import { createApp } from 'vue'
|
|
7
|
-
import { createMemoryHistory, createRouter, type RouteRecordRaw } from 'vue-router'
|
|
8
|
-
import {
|
|
3
|
+
import { createMemoryHistory, createWebHistory, createRouter, type RouteRecordRaw } from 'vue-router'
|
|
4
|
+
import { defineApplication } from '@fulgurjs/federation/vue'
|
|
9
5
|
import ChildLayout from './ChildLayout.vue'
|
|
10
6
|
import OrderList from './pages/OrderList.vue'
|
|
11
7
|
import OrderDetail from './pages/OrderDetail.vue'
|
|
12
8
|
import Settings from './pages/Settings.vue'
|
|
13
9
|
import Locked from './pages/Locked.vue'
|
|
14
|
-
import {
|
|
10
|
+
import { createChildReporter, childReporterKey, type ChildProps } from './child-bus'
|
|
15
11
|
|
|
16
12
|
const routes: RouteRecordRaw[] = [
|
|
17
13
|
// 根路径以 replace 规范化到 /orders(不产生额外历史条目)
|
|
@@ -22,19 +18,20 @@ const routes: RouteRecordRaw[] = [
|
|
|
22
18
|
{ path: '/locked', component: Locked },
|
|
23
19
|
]
|
|
24
20
|
|
|
25
|
-
export default
|
|
26
|
-
|
|
21
|
+
export default defineApplication<ChildProps>((props, ctx) => {
|
|
22
|
+
const reporter = createChildReporter(props, ctx.signal)
|
|
27
23
|
// 初始位置先读快照(规范化 replace 后对比上报)
|
|
28
24
|
const init = ctx?.routing?.getLocation()
|
|
29
25
|
const initPath = init ? init.pathname + init.search + init.hash : ''
|
|
30
|
-
const router = createRouter({ history: createMemoryHistory(), routes })
|
|
31
|
-
const app = createApp(ChildLayout
|
|
26
|
+
const router = createRouter({ history: ctx.mode === 'bridge' ? createMemoryHistory() : createWebHistory(import.meta.env.BASE_URL), routes })
|
|
27
|
+
const app = createApp(ChildLayout)
|
|
28
|
+
app.provide(childReporterKey, reporter)
|
|
32
29
|
// afterEach 记录初始导航结果;路由安装与连接清理由插件负责。
|
|
33
30
|
let reported = false
|
|
34
31
|
router.afterEach((to, _from, failure) => {
|
|
35
32
|
if (reported || failure) return
|
|
36
33
|
reported = true
|
|
37
|
-
reportNav(
|
|
34
|
+
reporter.reportNav(
|
|
38
35
|
'子应用初始化',
|
|
39
36
|
'init',
|
|
40
37
|
to.fullPath !== initPath
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* 宿主经 appProps 传入稳定回调 onChildEvent;本模块持有该引用并维护挂载计数。
|
|
4
|
-
* 单页单实例假设:同一宿主页同时只挂一个本子应用实例(路由同步前缀互斥的常规形态)。
|
|
5
|
-
*/
|
|
6
|
-
export type DemoChildNavAction = 'push' | 'replace' | 'go' | 'init'
|
|
1
|
+
/** 应用实例自己的观测回调,通过原生 provide/Context 传给实际消费树。 */
|
|
2
|
+
import { inject, type InjectionKey } from 'vue'
|
|
7
3
|
|
|
4
|
+
export type DemoChildNavAction = 'push' | 'replace' | 'go' | 'init'
|
|
8
5
|
export type DemoChildEvent =
|
|
9
6
|
| { type: 'mounted'; mountCount: number }
|
|
10
7
|
| { type: 'nav'; source: string; action: DemoChildNavAction; detail: string }
|
|
11
|
-
|
|
12
8
|
export type DemoChildReporter = (event: DemoChildEvent) => void
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/** 桥接工厂内调用:从 props 快照中取出宿主回调,并上报本次挂载计数 */
|
|
18
|
-
export function bindReporter(props: Record<string, unknown> | undefined): void {
|
|
19
|
-
const candidate = (props as { onChildEvent?: DemoChildReporter } | undefined)?.onChildEvent
|
|
20
|
-
bus.report = typeof candidate === 'function' ? candidate : undefined
|
|
21
|
-
mountCount += 1
|
|
22
|
-
bus.report?.({ type: 'mounted', mountCount })
|
|
9
|
+
export interface ChildReporter {
|
|
10
|
+
reportNav(source: string, action: DemoChildNavAction, detail: string): void
|
|
11
|
+
getMountCount(): number
|
|
23
12
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
export interface ChildProps { onChildEvent?: DemoChildReporter }
|
|
14
|
+
// 仅观测编号跨挂载累加;回调和所属实例不放在模块全局。
|
|
15
|
+
let nextMount = 0
|
|
16
|
+
export function createChildReporter(props: ChildProps, signal: AbortSignal): ChildReporter {
|
|
17
|
+
const mountCount = ++nextMount
|
|
18
|
+
if (!signal.aborted) props.onChildEvent?.({ type: 'mounted', mountCount })
|
|
19
|
+
return {
|
|
20
|
+
getMountCount: () => mountCount,
|
|
21
|
+
reportNav(source, action, detail) {
|
|
22
|
+
if (!signal.aborted) props.onChildEvent?.({ type: 'nav', source, action, detail })
|
|
23
|
+
},
|
|
24
|
+
}
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export
|
|
31
|
-
|
|
27
|
+
export const childReporterKey: InjectionKey<ChildReporter> = Symbol('child-reporter')
|
|
28
|
+
export function useChildReporter(): ChildReporter {
|
|
29
|
+
const reporter = inject(childReporterKey)
|
|
30
|
+
if (!reporter) throw new Error('子应用观测台未装配;从 application 工厂启动本应用。')
|
|
31
|
+
return reporter
|
|
32
32
|
}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 子应用真实能力经 exposes './bridge' 被宿主加载;直开本页仅作 dev server 健康检查。
|
|
4
|
-
*/
|
|
5
|
-
import { createApp, h } from 'vue'
|
|
6
|
-
|
|
7
|
-
createApp({
|
|
8
|
-
render: () =>
|
|
9
|
-
h('div', { style: "font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif; padding: 24px" }, [
|
|
10
|
-
h('h1', null, 'vue-remote(联邦子应用,默认端口 5335,改端口见 README「改端口」清单)'),
|
|
11
|
-
h('p', null, '本应用通过 expose ./bridge(defineBridgeApp + routing 协议)被宿主加载。'),
|
|
12
|
-
h('p', null, [
|
|
13
|
-
h('a', { href: 'http://localhost:5336/br-vue/orders' }, '打开 React 宿主桥接页(默认 5336)'),
|
|
14
|
-
]),
|
|
15
|
-
]),
|
|
16
|
-
}).mount('#app')
|
|
1
|
+
import application from './application'
|
|
2
|
+
void application.start('#app').catch(console.error)
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* 前往本页的导航会被宿主守卫(Vue:异步 beforeEach;React:useBlocker)拦截,等待「继续/取消」。
|
|
5
5
|
*/
|
|
6
6
|
import { useRouter } from 'vue-router'
|
|
7
|
-
import {
|
|
7
|
+
import { useChildReporter } from '../child-bus'
|
|
8
|
+
const { reportNav } = useChildReporter()
|
|
8
9
|
|
|
9
10
|
const router = useRouter()
|
|
10
11
|
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { computed } from 'vue'
|
|
7
7
|
import { useRoute, useRouter } from 'vue-router'
|
|
8
|
-
import {
|
|
8
|
+
import { useChildReporter } from '../child-bus'
|
|
9
|
+
const { reportNav } = useChildReporter()
|
|
9
10
|
|
|
10
11
|
const route = useRoute()
|
|
11
12
|
const router = useRouter()
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { computed, ref } from 'vue'
|
|
8
8
|
import { useRoute, useRouter } from 'vue-router'
|
|
9
|
-
import {
|
|
9
|
+
import { useChildReporter } from '../child-bus'
|
|
10
|
+
const { reportNav } = useChildReporter()
|
|
10
11
|
|
|
11
12
|
interface OrderItem {
|
|
12
13
|
id: number
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# vue-host-react-remote:完整子应用桥接模板
|
|
2
2
|
|
|
3
|
+
> 本目录是 6.9.0 源码候选:已改用 defineApplication,尚未测试和发布。源码依赖已锁定 6.9.0;正式发布前不要拿旧 registry 包运行这份代码。验收先使用本次候选 tarball,发布后再按下列冻结安装命令验证正式包。
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
`vue-host/` 是宿主,`react-remote/` 是子应用。复制整个模板目录,在根目录运行:
|
|
4
7
|
|
|
5
8
|
```bash
|
|
@@ -22,3 +25,24 @@ pnpm dev
|
|
|
22
25
|
- 改react-remote(默认 5303):① `react-remote/package.json` 的 `dev` 与 `preview` 两个脚本的 `--port 5303`;② `vue-host/fulgurjs.config.ts` 里 `remotes['bridge-react-remote'].dev` 的 `http://localhost:5303`;③ 根 `scripts/dev.config.json` 里 react-remote 的 `port`(**必改**:启动器预检/探活都读它);④ 本 README 顶部端口表。
|
|
23
26
|
- 改vue-host(默认 5314):① `vue-host/package.json` 的 `dev`/`preview` `--port 5314`;② `scripts/dev.config.json`;③ 本 README 端口表。
|
|
24
27
|
- 生产部署地址(`prod`,如 `/react-remote`)是站点路径,与 dev 端口无关,改端口不要动它。改名(容器名)不建议:还需同步 spec 前缀与页面表。
|
|
28
|
+
|
|
29
|
+
## 一键运行生产产物
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm build
|
|
33
|
+
pnpm prod
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`prod` 只服务本次 dist,不启动远程开发服务器。它复用 scripts/dev.config.json 的宿主端口,从实际构建入口推导 base,并把远程静态产物挂在同源子路径。无需为本地复现手写 Nginx;部署真实服务器时仍按部署指南配置。多宿主模板分别启动各宿主地址,不把两个宿主的根资源混在一起。先停止 dev,端口占用会失败并停止本次已起服务;不会关闭已有占用进程。Ctrl+C 关闭本次生产服务。
|
|
37
|
+
|
|
38
|
+
## 插件代码阅读地图
|
|
39
|
+
|
|
40
|
+
| 文件 | 职责 |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `react-remote/src/application.tsx` | 本应用唯一装配;main 只负责调用 start |
|
|
43
|
+
| `vue-host/src/application.ts` | 本应用唯一装配;main 只负责调用 start |
|
|
44
|
+
| `react-remote/fulgurjs.config.ts` | 本应用的远程地址、exposes、实际共享依赖 |
|
|
45
|
+
| `vue-host/fulgurjs.config.ts` | 本应用的远程地址、exposes、实际共享依赖 |
|
|
46
|
+
| `scripts/dev.mjs` / `scripts/prod.mjs` | 统一开发/生产启动器;业务接入不复制它们到应用源码 |
|
|
47
|
+
|
|
48
|
+
`application` 是新增的插件装配文件,`main` 是已有入口接线;页面组件、业务路由、权限和数据不是每个项目都必写的联邦配置。跨框架基础组合不逐页登记子应用菜单;逐页远程页面模板的页面表仅服务它所展示的逐页场景。`src/fulgurjs/types/` 是插件生成目录,按远程实际版本同步,不维护人工伪造的声明或旧缓存。
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"dev:remote": "pnpm --dir react-remote dev",
|
|
7
7
|
"dev:host": "pnpm --dir vue-host dev",
|
|
8
8
|
"dev": "node scripts/dev.mjs",
|
|
9
|
-
"build": "pnpm --dir react-remote build && pnpm --dir vue-host build"
|
|
9
|
+
"build": "pnpm --dir react-remote build && pnpm --dir vue-host build",
|
|
10
|
+
"prod": "node scripts/prod.mjs"
|
|
10
11
|
}
|
|
11
12
|
}
|