@fulgurjs/federation 6.8.7 → 6.9.0
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 +10 -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 +7 -7
- 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 +7 -7
- 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 +11 -11
- 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 +7 -7
- 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 +7 -7
- 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
package/dist/runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ve=/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/;function N(l){let d=ve.exec(String(l).trim());return d?{major:Number(d[1]),minor:Number(d[2]??0),patch:Number(d[3]??0),pre:d[4]?d[4].split("."):[]}:null}function $e(l,d){if(l.length===0&&d.length===0)return 0;if(l.length===0)return 1;if(d.length===0)return-1;let f=Math.max(l.length,d.length);for(let c=0;c<f;c++){let m=l[c],y=d[c];if(m===void 0)return-1;if(y===void 0)return 1;let b=/^\d+$/.test(m),v=/^\d+$/.test(y);if(b&&v){let M=Number(m)-Number(y);if(M!==0)return M}else{if(b!==v)return b?-1:1;if(m!==y)return m<y?-1:1}}return 0}function I(l,d){let f=N(l),c=N(d);return!f||!c?l<d?-1:l>d?1:0:f.major!==c.major?f.major-c.major:f.minor!==c.minor?f.minor-c.minor:f.patch!==c.patch?f.patch-c.patch:$e(f.pre,c.pre)}var Pe=/^[a-z]+[+:-]/i;function x(l,d){if(d===!1||d==null||d==="")return!0;let f=String(d).trim();return!f||f==="*"||f==="latest"||Pe.test(f)?!0:f.split("||").some(c=>_e(l,c.trim()))}function _e(l,d){if(!d||d==="*")return!N(l)?.pre.length;let f=d.split(/\s+-\s+/);if(f.length===2){let y=f[0].trim(),b=f[1].trim();return!(!x(l,`>=${y}`)||!x(l,`<=${b}`))}let c=N(l);if(!c)return!1;let m=ke(d);if(m===null)return!0;for(let y of m)if(!Te(c,l,y))return!1;return!(c.pre.length>0&&!m.some(y=>y.ver.pre.length>0)&&!m.some(b=>b.ver.major===c.major&&b.ver.minor===c.minor&&b.ver.patch===c.patch))}function ke(l){let d=[],f=l.trim().split(/\s+/).filter(Boolean);if(f.length===0)return null;for(let c of f){let m=/^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(c);if(!m)return null;let y=m[1],b=m[2],v=Le(y,b);if(v===null)return null;d.push(...v)}return d}function Le(l,d){let f=Ae(d);if(!f)return null;let{ver:c,partial:m}=f;switch(l){case"^":{let y=Oe(c);return y?[{op:">=",ver:c},{op:"<",ver:y}]:null}case"~":{let y=m>=2?{major:c.major,minor:c.minor+1,patch:0,pre:[]}:{major:c.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:c},{op:"<",ver:y}]}case">=":return[{op:">=",ver:c}];case">":return m===1?[{op:">=",ver:{major:c.major+1,minor:0,patch:0,pre:[]}}]:m===2?[{op:">=",ver:{major:c.major,minor:c.minor+1,patch:0,pre:[]}}]:[{op:">",ver:c}];case"<":return m===1?[{op:"<",ver:{major:c.major,minor:0,patch:0,pre:[]}}]:m===2?[{op:"<",ver:{major:c.major,minor:c.minor,patch:0,pre:[]}}]:[{op:"<",ver:c}];case"<=":return[{op:"<=",ver:c}];case"=":case void 0:return m===1?[{op:">=",ver:c},{op:"<",ver:{major:c.major+1,minor:0,patch:0,pre:[]}}]:m===2?[{op:">=",ver:c},{op:"<",ver:{major:c.major,minor:c.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:c}];default:return null}}function Oe(l){return l.major>0?{major:l.major+1,minor:0,patch:0,pre:[]}:l.minor>0?{major:0,minor:l.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:l.patch+1,pre:[]}}function Ae(l){let d=l.replace(/^v/,"").trim();if(!d||d==="*"||d==="x"||d==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let f=d.split("."),c=[],m=0;for(let v of f.slice(0,3))if(/^\d+$/.test(v))c.push(Number(v)),m++;else{if(v==="x"||v==="X"||v==="*")break;break}let y=d.split("-"),b=y.length>1?y.slice(1).join("-").split("+")[0].split("."):[];return m===0&&b.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:c[0]??0,minor:c[1]??0,patch:c[2]??0,pre:b},partial:m}}function Me(l,d){switch(d){case">=":return l>=0;case">":return l>0;case"<":return l<0;case"<=":return l<=0;case"=":return l===0}}function Te(l,d,f){let c=`${l.major}.${l.minor}.${l.patch}`+(l.pre.length?`-${l.pre.join(".")}`:"");if(f.upper)return!(!(I(c,`${f.ver.major}.${f.ver.minor}.${f.ver.patch}`+(f.ver.pre.length?`-${f.ver.pre.join(".")}`:""))>=0)||!(I(c,`${f.upper.major}.${f.upper.minor}.${f.upper.patch}`)<0));let m=I(c,`${f.ver.major}.${f.ver.minor}.${f.ver.patch}`+(f.ver.pre.length?`-${f.ver.pre.join(".")}`:"")),y=Me(m,f.op);return f.ver.pre.length>0&&l.pre.length===0&&(f.op===">"||f.op==="<")?!1:y}var w=class extends Error{code;details;constructor(d,f,c,m){super(`[fulgurjs:${d}] ${f}`,m),this.name="FgError",this.code=d,this.details=c}},E={REMOTE_LOAD_FAILED:"MFU-001",REMOTE_NAME_MISMATCH:"MFU-002",SHARE_STRICT_VERSION:"MFU-003",SHARE_NOT_AVAILABLE:"MFU-004",CONTAINER_REINIT_CONFLICT:"MFU-005",MODULE_NOT_EXPOSED:"MFU-006",PRELOAD_FAILED:"MFU-007",REMOTE_UNKNOWN:"MFU-008",EMPTY_EXPORTS:"MFU-009",SINGLETON_SKEW:"MFU-010",SETUP_INVALID_EXPORT:"MFU-011",SETUP_RUN_FAILED:"MFU-012",SETUP_SESSION_KEY_MISSING:"MFU-013",SETUP_RECURSION:"MFU-014"};var te="6.
|
|
1
|
+
var ve=/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/;function N(l){let d=ve.exec(String(l).trim());return d?{major:Number(d[1]),minor:Number(d[2]??0),patch:Number(d[3]??0),pre:d[4]?d[4].split("."):[]}:null}function $e(l,d){if(l.length===0&&d.length===0)return 0;if(l.length===0)return 1;if(d.length===0)return-1;let f=Math.max(l.length,d.length);for(let c=0;c<f;c++){let m=l[c],y=d[c];if(m===void 0)return-1;if(y===void 0)return 1;let b=/^\d+$/.test(m),v=/^\d+$/.test(y);if(b&&v){let M=Number(m)-Number(y);if(M!==0)return M}else{if(b!==v)return b?-1:1;if(m!==y)return m<y?-1:1}}return 0}function I(l,d){let f=N(l),c=N(d);return!f||!c?l<d?-1:l>d?1:0:f.major!==c.major?f.major-c.major:f.minor!==c.minor?f.minor-c.minor:f.patch!==c.patch?f.patch-c.patch:$e(f.pre,c.pre)}var Pe=/^[a-z]+[+:-]/i;function x(l,d){if(d===!1||d==null||d==="")return!0;let f=String(d).trim();return!f||f==="*"||f==="latest"||Pe.test(f)?!0:f.split("||").some(c=>_e(l,c.trim()))}function _e(l,d){if(!d||d==="*")return!N(l)?.pre.length;let f=d.split(/\s+-\s+/);if(f.length===2){let y=f[0].trim(),b=f[1].trim();return!(!x(l,`>=${y}`)||!x(l,`<=${b}`))}let c=N(l);if(!c)return!1;let m=ke(d);if(m===null)return!0;for(let y of m)if(!Te(c,l,y))return!1;return!(c.pre.length>0&&!m.some(y=>y.ver.pre.length>0)&&!m.some(b=>b.ver.major===c.major&&b.ver.minor===c.minor&&b.ver.patch===c.patch))}function ke(l){let d=[],f=l.trim().split(/\s+/).filter(Boolean);if(f.length===0)return null;for(let c of f){let m=/^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(c);if(!m)return null;let y=m[1],b=m[2],v=Le(y,b);if(v===null)return null;d.push(...v)}return d}function Le(l,d){let f=Ae(d);if(!f)return null;let{ver:c,partial:m}=f;switch(l){case"^":{let y=Oe(c);return y?[{op:">=",ver:c},{op:"<",ver:y}]:null}case"~":{let y=m>=2?{major:c.major,minor:c.minor+1,patch:0,pre:[]}:{major:c.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:c},{op:"<",ver:y}]}case">=":return[{op:">=",ver:c}];case">":return m===1?[{op:">=",ver:{major:c.major+1,minor:0,patch:0,pre:[]}}]:m===2?[{op:">=",ver:{major:c.major,minor:c.minor+1,patch:0,pre:[]}}]:[{op:">",ver:c}];case"<":return m===1?[{op:"<",ver:{major:c.major,minor:0,patch:0,pre:[]}}]:m===2?[{op:"<",ver:{major:c.major,minor:c.minor,patch:0,pre:[]}}]:[{op:"<",ver:c}];case"<=":return[{op:"<=",ver:c}];case"=":case void 0:return m===1?[{op:">=",ver:c},{op:"<",ver:{major:c.major+1,minor:0,patch:0,pre:[]}}]:m===2?[{op:">=",ver:c},{op:"<",ver:{major:c.major,minor:c.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:c}];default:return null}}function Oe(l){return l.major>0?{major:l.major+1,minor:0,patch:0,pre:[]}:l.minor>0?{major:0,minor:l.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:l.patch+1,pre:[]}}function Ae(l){let d=l.replace(/^v/,"").trim();if(!d||d==="*"||d==="x"||d==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let f=d.split("."),c=[],m=0;for(let v of f.slice(0,3))if(/^\d+$/.test(v))c.push(Number(v)),m++;else{if(v==="x"||v==="X"||v==="*")break;break}let y=d.split("-"),b=y.length>1?y.slice(1).join("-").split("+")[0].split("."):[];return m===0&&b.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:c[0]??0,minor:c[1]??0,patch:c[2]??0,pre:b},partial:m}}function Me(l,d){switch(d){case">=":return l>=0;case">":return l>0;case"<":return l<0;case"<=":return l<=0;case"=":return l===0}}function Te(l,d,f){let c=`${l.major}.${l.minor}.${l.patch}`+(l.pre.length?`-${l.pre.join(".")}`:"");if(f.upper)return!(!(I(c,`${f.ver.major}.${f.ver.minor}.${f.ver.patch}`+(f.ver.pre.length?`-${f.ver.pre.join(".")}`:""))>=0)||!(I(c,`${f.upper.major}.${f.upper.minor}.${f.upper.patch}`)<0));let m=I(c,`${f.ver.major}.${f.ver.minor}.${f.ver.patch}`+(f.ver.pre.length?`-${f.ver.pre.join(".")}`:"")),y=Me(m,f.op);return f.ver.pre.length>0&&l.pre.length===0&&(f.op===">"||f.op==="<")?!1:y}var w=class extends Error{code;details;constructor(d,f,c,m){super(`[fulgurjs:${d}] ${f}`,m),this.name="FgError",this.code=d,this.details=c}},E={REMOTE_LOAD_FAILED:"MFU-001",REMOTE_NAME_MISMATCH:"MFU-002",SHARE_STRICT_VERSION:"MFU-003",SHARE_NOT_AVAILABLE:"MFU-004",CONTAINER_REINIT_CONFLICT:"MFU-005",MODULE_NOT_EXPOSED:"MFU-006",PRELOAD_FAILED:"MFU-007",REMOTE_UNKNOWN:"MFU-008",EMPTY_EXPORTS:"MFU-009",SINGLETON_SKEW:"MFU-010",SETUP_INVALID_EXPORT:"MFU-011",SETUP_RUN_FAILED:"MFU-012",SETUP_SESSION_KEY_MISSING:"MFU-013",SETUP_RECURSION:"MFU-014"};var te="6.9.0";var Ie="__fulgurjsSetup",xe="__FULGURJS_APP_CONFIG__",G=15e3,oe=2,je=5,Ne=3e4,Ce=4e3,Ue=.2;function Ve(){let l=Object.create(null),d=new Map,f=[],c=new Set,m=new Map,y=(e,r)=>JSON.stringify([r.shareScope||"default",r.shareKey||e,r.requiredVersion??null,!!r.singleton,!!r.strictVersion]),b=new Map,v=new Map,M=new WeakMap,C=new WeakMap,_={},ie=()=>{for(let e of f)try{e.init?.(_)}catch(r){console.warn("[fulgurjs] \u8FD0\u884C\u65F6\u6269\u5C55\u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BE5\u6269\u5C55\u5C06\u4E0D\u53EF\u7528\uFF1A",e.name,r)}},U=new Map,V,F=e=>{let r=U.get(e);return r||U.set(e,r={}),r},X=()=>globalThis[xe]??{};async function B(e,r,n,o){let t=u=>u instanceof w?u:new w(E.SETUP_RUN_FAILED,`\u73B0\u8C61\uFF1A\u8FDC\u7A0B\u5E94\u7528 "${e}" \u7684 ${o} \u521D\u59CB\u5316\u5931\u8D25\u3002
|
|
2
2
|
\u539F\u56E0\uFF1A${String(u?.message??u)}
|
|
3
3
|
\u4FEE\u6CD5\uFF1A\u68C0\u67E5\u5E76\u4FEE\u590D\u8BE5 ${o} \u51FD\u6570\u540E\u91CD\u65B0\u52A0\u8F7D\uFF1B\u5931\u8D25\u7F13\u5B58\u5DF2\u6E05\u9664\uFF0C\u53EF\u4EE5\u76F4\u63A5\u91CD\u8BD5\u3002`,{remote:e,phase:o},{cause:u});V=e;let s;try{s=r(n)}catch(u){throw t(u)}finally{V=void 0}try{await s}catch(u){throw t(u)}}async function ae(e,r,n,o){e.debug.setup="pending";try{if(e.manifestUrl)try{await H(`${e.name}/${n}`)}catch{}let t=await r.get(n),s=t?.default;if(typeof s!="function")throw new w(E.SETUP_INVALID_EXPORT,`\u73B0\u8C61\uFF1A\u8FDC\u7A0B\u5E94\u7528 "${e.name}" \u7684 setup \u6A21\u5757 "${n}" \u65E0\u6CD5\u521D\u59CB\u5316\u3002
|
|
4
4
|
\u539F\u56E0\uFF1A\u9ED8\u8BA4\u5BFC\u51FA\u7C7B\u578B\u4E3A ${t==null?String(t):typeof s}\uFF0C\u5E94\u4E3A\u51FD\u6570\u3002
|
package/dist/vue-adapter.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefineComponent, Component } from 'vue';
|
|
2
2
|
import { PageRouteLike } from './pages.cjs';
|
|
3
3
|
import { R as ResolvedHostPage, H as HostPagesCoreOptions } from './host-pages-core-BFxp-IOj.cjs';
|
|
4
|
-
import { b as FgModuleDefault, c as FgComponentLike, d as FgComponentEntry } from './remote-types-
|
|
4
|
+
import { b as FgModuleDefault, c as FgComponentLike, d as FgComponentEntry } from './remote-types-CStGOJwu.cjs';
|
|
5
5
|
import { FgRemoteTypes } from '@fulgurjs/federation/internal/registry.js';
|
|
6
6
|
import './bridge-core-77BT1__I.cjs';
|
|
7
7
|
import './context.cjs';
|
package/dist/vue-adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefineComponent, Component } from 'vue';
|
|
2
2
|
import { PageRouteLike } from './pages.js';
|
|
3
3
|
import { R as ResolvedHostPage, H as HostPagesCoreOptions } from './host-pages-core-DLfMeDrO.js';
|
|
4
|
-
import { b as FgModuleDefault, c as FgComponentLike, d as FgComponentEntry } from './remote-types-
|
|
4
|
+
import { b as FgModuleDefault, c as FgComponentLike, d as FgComponentEntry } from './remote-types-COmBhjRc.js';
|
|
5
5
|
import { FgRemoteTypes } from '@fulgurjs/federation/internal/registry.js';
|
|
6
6
|
import './bridge-core-CoQRVgnZ.js';
|
|
7
7
|
import './context.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vue-store.ts
|
|
21
|
+
var vue_store_exports = {};
|
|
22
|
+
__export(vue_store_exports, {
|
|
23
|
+
bindStoreToApp: () => bindStoreToApp
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vue_store_exports);
|
|
26
|
+
function bindStoreToApp(useStore, pinia) {
|
|
27
|
+
return new Proxy(useStore, {
|
|
28
|
+
apply(target, receiver, args) {
|
|
29
|
+
if (args[0] == null) {
|
|
30
|
+
args[0] = typeof pinia === "function" ? pinia() : pinia;
|
|
31
|
+
if (args[0] == null) throw new Error("\u672C\u5E94\u7528\u7684 Pinia \u5C1A\u672A\u521B\u5EFA\u3002\u5148\u5728\u5E94\u7528\u88C5\u914D\u4E2D\u521B\u5EFA/\u5B89\u88C5 Pinia\uFF0C\u518D\u8C03\u7528\u7ED1\u5B9A\u7684 store\u3002");
|
|
32
|
+
}
|
|
33
|
+
return Reflect.apply(target, receiver, args);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
bindStoreToApp
|
|
40
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Explicit ownership for Pinia-like store definitions; no Pinia dependency or global switching. */
|
|
2
|
+
declare function bindStoreToApp<T extends (...args: never[]) => unknown>(useStore: T, pinia: Parameters<T>[0] | (() => Parameters<T>[0])): T;
|
|
3
|
+
|
|
4
|
+
export { bindStoreToApp };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Explicit ownership for Pinia-like store definitions; no Pinia dependency or global switching. */
|
|
2
|
+
declare function bindStoreToApp<T extends (...args: never[]) => unknown>(useStore: T, pinia: Parameters<T>[0] | (() => Parameters<T>[0])): T;
|
|
3
|
+
|
|
4
|
+
export { bindStoreToApp };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/vue-store.ts
|
|
2
|
+
function bindStoreToApp(useStore, pinia) {
|
|
3
|
+
return new Proxy(useStore, {
|
|
4
|
+
apply(target, receiver, args) {
|
|
5
|
+
if (args[0] == null) {
|
|
6
|
+
args[0] = typeof pinia === "function" ? pinia() : pinia;
|
|
7
|
+
if (args[0] == null) throw new Error("\u672C\u5E94\u7528\u7684 Pinia \u5C1A\u672A\u521B\u5EFA\u3002\u5148\u5728\u5E94\u7528\u88C5\u914D\u4E2D\u521B\u5EFA/\u5B89\u88C5 Pinia\uFF0C\u518D\u8C03\u7528\u7ED1\u5B9A\u7684 store\u3002");
|
|
8
|
+
}
|
|
9
|
+
return Reflect.apply(target, receiver, args);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
bindStoreToApp
|
|
15
|
+
};
|
package/dist/vue.d.ts
CHANGED
|
@@ -189,7 +189,7 @@ type FgComponentEntry<S extends string> = [keyof FgRemoteTypes] extends [never]
|
|
|
189
189
|
*/
|
|
190
190
|
type FgBridgeEntry<S extends string> = [keyof FgRemoteTypes] extends [never] ? string : string extends S ? string : S extends keyof FgRemoteTypes ? FgRemoteTypes[S] extends {
|
|
191
191
|
default: infer D;
|
|
192
|
-
} ? D extends BridgeApp ? S : `非桥接入口 ${S}
|
|
192
|
+
} ? D extends BridgeApp ? S : `非桥接入口 ${S}:需要 defineApplication 或 defineBridgeApp 的默认导出(普通组件用 remoteComponent)` : `非桥接入口 ${S}:需要 defineApplication 或 defineBridgeApp 的默认导出(普通组件用 remoteComponent)` : `未知远程入口 ${S}:请核对该远程的 exposes,或运行 npx @fulgurjs/federation types 同步类型`;
|
|
193
193
|
/** 桥接提供方声明的 props(defineBridgeApp<P> 的 phantom 标记 → 宿主侧提取) */
|
|
194
194
|
type FgBridgePropsOf<B> = B extends {
|
|
195
195
|
__fgBridgeProps?: infer P;
|
|
@@ -592,8 +592,21 @@ declare function createHostPages$1(options: HostPagesOptions, load: (spec: strin
|
|
|
592
592
|
consumerApp?: unknown;
|
|
593
593
|
}) => Promise<any>): HostPages;
|
|
594
594
|
|
|
595
|
+
/** Shared start/stop bookkeeping; framework contracts retain their own rendering semantics. */
|
|
596
|
+
|
|
597
|
+
interface ApplicationHandle {
|
|
598
|
+
element: HTMLElement;
|
|
599
|
+
/** Only disposes this start generation; an old handle cannot stop a replacement. */
|
|
600
|
+
unmount(): void;
|
|
601
|
+
}
|
|
602
|
+
type Application<P extends object> = BridgeApp & {
|
|
603
|
+
__fgBridgeProps?: P;
|
|
604
|
+
} & {
|
|
605
|
+
start(target: string | HTMLElement, ...props: {} extends P ? [props?: P] : [props: P]): Promise<ApplicationHandle>;
|
|
606
|
+
};
|
|
607
|
+
|
|
595
608
|
/**
|
|
596
|
-
* Vue 子应用桥接适配(/
|
|
609
|
+
* Vue 子应用桥接适配(/vue 导出 defineBridgeApp 与 defineApplication)。
|
|
597
610
|
*
|
|
598
611
|
* 工厂返回 VueApp,或已装配业务插件与守卫的 { app, router };后者自动接线 memory
|
|
599
612
|
* router、等待初始导航再安装。helper 管理挂载/卸载及每容器每代次的路由释放。
|
|
@@ -606,7 +619,7 @@ declare function createHostPages$1(options: HostPagesOptions, load: (spec: strin
|
|
|
606
619
|
* - unmount 未知容器为 no-op;mount/unmount 的原始错误**原样抛出**——MFU-016 包装
|
|
607
620
|
* (真实 spec + phase + cause)由宿主适配器在生命周期边界统一完成(见 bridgeHostError)。
|
|
608
621
|
*
|
|
609
|
-
* 本文件零 React:/
|
|
622
|
+
* 本文件零 React:/vue 导入图隔离由 tests/runtime-entry-graph.test.ts 守护。
|
|
610
623
|
*/
|
|
611
624
|
|
|
612
625
|
/** 工厂第二参数:挂载生命周期与路由通道(URL 同步;不混入业务 props) */
|
|
@@ -633,7 +646,7 @@ type VueBridgeAppFactory<P = Record<string, unknown>> = (props: P, ctx?: VueBrid
|
|
|
633
646
|
* 经注册表提取为包装组件的 appProps 类型;未声明具体 P 的远程保持
|
|
634
647
|
* Record<string, unknown>(诚实通用面,绝不凭空推导业务字段)。
|
|
635
648
|
*/
|
|
636
|
-
type FgBridgePropsMarker<P extends
|
|
649
|
+
type FgBridgePropsMarker<P extends object> = {
|
|
637
650
|
__fgBridgeProps?: P;
|
|
638
651
|
};
|
|
639
652
|
interface DefineVueBridgeAppOptions {
|
|
@@ -652,7 +665,21 @@ interface DefineVueBridgeAppOptions {
|
|
|
652
665
|
* export default defineBridgeApp((props) => { const app = createApp(App, props); app.use(router); return app })
|
|
653
666
|
* ```
|
|
654
667
|
*/
|
|
655
|
-
declare function defineBridgeApp$1<P extends
|
|
668
|
+
declare function defineBridgeApp$1<P extends object = Record<string, unknown>>(factory: VueBridgeAppFactory<P>, options?: DefineVueBridgeAppOptions): BridgeApp & FgBridgePropsMarker<P>;
|
|
669
|
+
interface VueApplicationContext extends VueBridgeAppContext {
|
|
670
|
+
mode: 'standalone' | 'bridge';
|
|
671
|
+
/** Always present; aborts when this application instance is stopped. */
|
|
672
|
+
signal: AbortSignal;
|
|
673
|
+
}
|
|
674
|
+
interface VueApplicationSetup extends VueBridgeAppSetup {
|
|
675
|
+
router: VueRouterLike & {
|
|
676
|
+
install(app: App): void;
|
|
677
|
+
isReady(): Promise<void>;
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
type VueApplicationFactory<P = Record<string, unknown>> = (props: P, context: VueApplicationContext) => App | VueApplicationSetup | Promise<App | VueApplicationSetup>;
|
|
681
|
+
/** One assembly function for the standalone entry and the exposed application. */
|
|
682
|
+
declare function defineApplication<P extends object = Record<string, unknown>>(factory: VueApplicationFactory<P>, options?: DefineVueBridgeAppOptions): Application<P>;
|
|
656
683
|
|
|
657
684
|
/** Vue Router 4/5 的宿主导航端口与子应用 memory router 接线(统一入口 /vue 提供)。 */
|
|
658
685
|
|
|
@@ -729,11 +756,15 @@ declare function createBridgeSession(options?: {
|
|
|
729
756
|
storageKey?: string;
|
|
730
757
|
}): BridgeSession;
|
|
731
758
|
|
|
759
|
+
/** Explicit ownership for Pinia-like store definitions; no Pinia dependency or global switching. */
|
|
760
|
+
declare function bindStoreToApp<T extends (...args: never[]) => unknown>(useStore: T, pinia: Parameters<T>[0] | (() => Parameters<T>[0])): T;
|
|
761
|
+
|
|
732
762
|
declare const remoteComponent: <S extends string>(spec: S & FgComponentEntry<S>, opts?: RemoteComponentOptions) => FgRemoteVueComponent<S>;
|
|
733
763
|
/** 宿主页面适配器(绑定本包运行时的 loadRemote;选项与返回值类型见 vue-adapter) */
|
|
734
764
|
declare function createHostPages(options: Parameters<typeof createHostPages$1>[0]): HostPages;
|
|
735
765
|
/** Vue 子应用桥接契约(远程 ./bridge 模块默认导出) */
|
|
736
766
|
declare const defineBridgeApp: typeof defineBridgeApp$1;
|
|
767
|
+
|
|
737
768
|
/** Vue 宿主桥接工厂:返回 `{ appProps: P; sessionKey?: string | null }` 形态的包装组件 */
|
|
738
769
|
declare const createVueBridgeApp: <P0 = _fulgurjs_federation_internal_registry_js.FgTypeAuto, S extends string = string>(spec: S & FgBridgeEntry<S>, options?: VueBridgeAppOptions) => FgVueBridgeWrapperResolved<P0, S>;
|
|
739
770
|
|
|
@@ -741,4 +772,4 @@ type RemoteSchema = Record<string, RemoteSchemaEntry>;
|
|
|
741
772
|
/** 无插件转换的场景(构建、Node 导入)如实返回空清单。 */
|
|
742
773
|
declare const remoteSchema: RemoteSchema;
|
|
743
774
|
|
|
744
|
-
export { type AppContext, type BridgeApp, type BridgeHostRouting, type BridgeSession, type FgBridgeAppProps, type FgBridgeEntry, type FgBridgePropsOf, type FgComponentEntry, type FgRemoteVueComponent, type FgRuntime, type FgVueBridgeWrapper, type HostPages, type HostPagesOptions, type LoadRemoteOptions, type LoadShareOptions, type PageRouteLike, type PageViolation, type PagesOptions, type PreloadRemoteOptions, type RemoteComponentOptions, type RemoteConfig, type RemoteDebugInfo, type RemoteSchema, type RemoteSchemaEntry, type RemoteSetupContext, type RemoteSetupModule, type ResolvedHostPage, type RuntimeHooks, type RuntimePlugin, type ShareEntry, type ShareScope, type ShareScopeMap, type VueBridgeAppContext, type VueBridgeAppFactory, type VueBridgeAppOptions, type VueBridgeAppSetup, type VueBridgeRouterConnection, clearAppContext, clearSessionState, connectVueBridgeRouter, createBridgeSession, createHostPages, createVueBridgeApp, createVueBridgeNavigation, defineBridgeApp, definePages, getAppContext, getContainer, getLoadedShare, getRuntime, hasBridgeMount, initSharing, installVueBridgeRouter, loadRemote, loadShare, parseSpec, pinLoadedShare, preloadRemote, provideAppContext, registerPlugins, registerRemote, registerRemotes, registerShare, remoteComponent, remoteSchema, requireAppContext, shareScopeMap, unwrapDefault, validatePages, version };
|
|
775
|
+
export { type AppContext, type Application, type ApplicationHandle, type BridgeApp, type BridgeHostRouting, type BridgeSession, type DefineVueBridgeAppOptions, type FgBridgeAppProps, type FgBridgeEntry, type FgBridgePropsOf, type FgComponentEntry, type FgRemoteVueComponent, type FgRuntime, type FgVueBridgeWrapper, type HostPages, type HostPagesOptions, type LoadRemoteOptions, type LoadShareOptions, type PageRouteLike, type PageViolation, type PagesOptions, type PreloadRemoteOptions, type RemoteComponentOptions, type RemoteConfig, type RemoteDebugInfo, type RemoteSchema, type RemoteSchemaEntry, type RemoteSetupContext, type RemoteSetupModule, type ResolvedHostPage, type RuntimeHooks, type RuntimePlugin, type ShareEntry, type ShareScope, type ShareScopeMap, type VueApplicationContext, type VueApplicationFactory, type VueApplicationSetup, type VueBridgeAppContext, type VueBridgeAppFactory, type VueBridgeAppOptions, type VueBridgeAppSetup, type VueBridgeRouterConnection, bindStoreToApp, clearAppContext, clearSessionState, connectVueBridgeRouter, createBridgeSession, createHostPages, createVueBridgeApp, createVueBridgeNavigation, defineApplication, defineBridgeApp, definePages, getAppContext, getContainer, getLoadedShare, getRuntime, hasBridgeMount, initSharing, installVueBridgeRouter, loadRemote, loadShare, parseSpec, pinLoadedShare, preloadRemote, provideAppContext, registerPlugins, registerRemote, registerRemotes, registerShare, remoteComponent, remoteSchema, requireAppContext, shareScopeMap, unwrapDefault, validatePages, version };
|
package/dist/vue.js
CHANGED
|
@@ -11,6 +11,8 @@ import { hasBridgeMount } from "./bridge-core.js";
|
|
|
11
11
|
export const remoteComponent = createRemoteComponent(loadRemote);
|
|
12
12
|
export const createHostPages = (options) => createHostPagesWithLoader(options, loadRemote);
|
|
13
13
|
export const defineBridgeApp = defineVueBridgeApp;
|
|
14
|
+
export { defineApplication } from "./bridge-app-vue.js";
|
|
15
|
+
export { bindStoreToApp } from "./vue-store.js";
|
|
14
16
|
export const createVueBridgeApp = createVueBridgeAppWithLoader(loadRemote);
|
|
15
17
|
export { createVueBridgeNavigation, connectVueBridgeRouter, installVueBridgeRouter };
|
|
16
18
|
export { createBridgeSession };
|
package/docs/en/reference/api.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
| Entry | Purpose | Export surface |
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| `@fulgurjs/federation` (package root) | Vite config | the `federation(options)` plugin + the `FederationOptions` type (full field set in the [configuration reference](configuration.md)) |
|
|
10
|
-
| `@fulgurjs/federation/vue` | **The single entry for Vue apps** | full runtime + `provideAppContext`/`getAppContext`/`requireAppContext`/`clearAppContext` + `definePages`/`validatePages` + `remoteComponent` + `createHostPages` + `defineBridgeApp` + `createVueBridgeApp` + `createVueBridgeNavigation` + `connectVueBridgeRouter` + `remoteSchema` |
|
|
11
|
-
| `@fulgurjs/federation/react` | **The single entry for React apps** | the same full runtime + context + pages (`createReactHostPages`) + `remoteComponent`/`useLoadRemote`/`RemoteErrorBoundary` + `defineBridgeApp` + `createReactBridgeApp` + `createReactBridgeNavigation` + `createReactBridgeRouter` + `remoteSchema` |
|
|
10
|
+
| `@fulgurjs/federation/vue` | **The single entry for Vue apps** | full runtime + `provideAppContext`/`getAppContext`/`requireAppContext`/`clearAppContext` + `definePages`/`validatePages` + `remoteComponent` + `bindStoreToApp` + `createHostPages` + `defineApplication` + `defineBridgeApp` + `createVueBridgeApp` + `createVueBridgeNavigation` + `connectVueBridgeRouter` + `remoteSchema` |
|
|
11
|
+
| `@fulgurjs/federation/react` | **The single entry for React apps** | the same full runtime + context + pages (`createReactHostPages`) + `remoteComponent`/`useLoadRemote`/`RemoteErrorBoundary` + `defineApplication` + `defineBridgeApp` + `createReactBridgeApp` + `createReactBridgeNavigation` + `createReactBridgeRouter` + `remoteSchema` |
|
|
12
12
|
| `@fulgurjs/federation/runtime` | **Framework-agnostic** | full runtime (loadRemote/loadShare/initSharing/registerRemotes/registerShare/registerRemote/registerPlugins/preloadRemote/getContainer/getLoadedShare/pinLoadedShare/parseSpec/getRuntime/shareScopeMap/unwrapDefault/version/clearSessionState) + context + pages (`definePages`/`validatePages`) + `remoteSchema`; zero Vue/React/router dependency |
|
|
13
13
|
|
|
14
14
|
<a id="runtime-api"></a>
|
|
@@ -644,3 +644,39 @@ A project can build its own runtime diagnostics page (route `meta.ignoreAuth`),
|
|
|
644
644
|
## Complete public types
|
|
645
645
|
|
|
646
646
|
The [public type reference](types.md) lists every exported type and its fields by current import location.
|
|
647
|
+
|
|
648
|
+
## One application for standalone and bridge startup: `defineApplication`
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
Import from `@fulgurjs/federation/vue` or `@fulgurjs/federation/react`; no additional subpath. See [existing application assembly](../guide/existing-apps.md) for complete examples. `defineBridgeApp` remains available for bridge-only applications.
|
|
652
|
+
|
|
653
|
+
| Item | Contract |
|
|
654
|
+
|---|---|
|
|
655
|
+
| Signature | `defineApplication<P extends object>(factory, options?) => Application<P>`; ordinary interfaces need no index signature |
|
|
656
|
+
| Options | Existing `DefineVueBridgeAppOptions` / `DefineReactBridgeAppOptions`; routing defaults to false, set true for host URL synchronization |
|
|
657
|
+
| Factory | Called for each mount/container; Vue accepts an asynchronous result, React requires a synchronous result |
|
|
658
|
+
| context.mode | Required: standalone or bridge |
|
|
659
|
+
| context.signal | Required, owned by this instance; aborted on unmount/external mount cancellation. Asynchronous tasks must observe it |
|
|
660
|
+
| context.routing | Provided by a routing-enabled bridge host, absent during standalone startup |
|
|
661
|
+
| Vue result | app or { app, router }; prefer the latter. Assemble stores, components, Providers and guards before returning an app whose router is not yet installed. Standalone uses a real web/hash router, installed and awaited by the plugin; bridge uses memory history: routing:true for host URL sync, or an automatically installed/awaited local memory router when sync is omitted |
|
|
662
|
+
| React result | ReactElement or { element: ReactElement, dispose?: () => void }. Dispose synchronously releases instance-owned resources. Return createReactBridgeRouter's element/dispose for bridge mode or RouterProvider plus router.dispose for standalone mode |
|
|
663
|
+
| start(target, props) | Selector or HTMLElement; props is required when P contains required fields. Resolves { element, unmount() } after Vue initial navigation/mount or React first root commit; does not await every page loader/request |
|
|
664
|
+
| Pending cancellation | application.unmount(element) cancels a pending start with AbortError; callers handle rejection and late factory results do not remount |
|
|
665
|
+
| Unmount | A handle only stops its own generation. Old handles cannot stop replacement instances. Failed unmount seals that definition's container until page refresh |
|
|
666
|
+
| Repeated mounts | Unmount before another start/mount in the same container. Different containers need different app/router/store instances |
|
|
667
|
+
| Host | The result implements BridgeApp (mount/unmount/routing) and is loaded by createVueBridgeApp/createReactBridgeApp; hosts do not call start |
|
|
668
|
+
|
|
669
|
+
### Explicit store ownership: `bindStoreToApp` (Vue only)
|
|
670
|
+
|
|
671
|
+
```ts
|
|
672
|
+
import { bindStoreToApp } from '@fulgurjs/federation/vue'
|
|
673
|
+
import { createPinia } from 'pinia'
|
|
674
|
+
import { useCounterStore } from './stores/counter'
|
|
675
|
+
const pinia = createPinia()
|
|
676
|
+
const useCounter = bindStoreToApp(useCounterStore, pinia)
|
|
677
|
+
const counter = useCounter()
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
Signature: `bindStoreToApp<T extends (...args: never[]) => unknown>(useStore: T, pinia: Parameters<T>[0] | (() => Parameters<T>[0])): T`. A proxy retains the function's parameter/return types and properties such as $id. An omitted/null first argument gets the bound instance; explicitly supplied instances are respected. No Pinia import, global activePinia mutation or global business store is introduced.
|
|
681
|
+
|
|
682
|
+
A getter is suitable only for a module with one unambiguous default instance initialized later; an unavailable instance throws a readable error. Concurrent application containers must bind their actual instances per factory and inject the bound functions into their own trees. Do not use a module variable overwritten by each mount. Normal component injection can keep native useStore.
|
|
@@ -217,6 +217,8 @@ Import from: `@fulgurjs/federation/react`, `@fulgurjs/federation/runtime`, `@ful
|
|
|
217
217
|
| `onSession` | yes | `(ctx: RemoteSetupContext) => void \| Promise<void>` | See the owning API for lifecycle and runtime defaults. |
|
|
218
218
|
| `globalComponents` | yes | `Record<string, unknown>` | Static components retain their identity. Zero-argument functions with displayName/props/emits metadata are components; unmarked zero-argument functions are lazy loaders. See the setup API for installation and retry semantics. |
|
|
219
219
|
|
|
220
|
+
| `pageProviders` | yes | `unknown[]` | Ancestor Providers required by remote components; each item is a component or zero-argument loader. Adapters wrap the actual consumer tree without copying the provider application. |
|
|
221
|
+
|
|
220
222
|
## AppContext
|
|
221
223
|
|
|
222
224
|
Application and session context supplied by the host.
|
|
@@ -613,3 +615,28 @@ Return value of `createReactBridgeRouter`.
|
|
|
613
615
|
| `element` | `ReactElement` | Return as the child application's root from the bridge factory. |
|
|
614
616
|
| `routerReady` | `Promise<Router>` | Resolves when the memory router is wired; rejects if dependencies cannot load. Await this promise instead of assuming `element.props.router` exists synchronously. |
|
|
615
617
|
| `dispose` | `() => void` | Release routing subscriptions and wiring during bridge cleanup. |
|
|
618
|
+
|
|
619
|
+
## Application / ApplicationHandle
|
|
620
|
+
|
|
621
|
+
入口 / Entry: `@fulgurjs/federation/vue`, `@fulgurjs/federation/react`.
|
|
622
|
+
|
|
623
|
+
| 类型 / Type | 字段 / Fields |
|
|
624
|
+
|---|---|
|
|
625
|
+
| Application<P extends object> | BridgeApp + `__fgBridgeProps?: P` + `start(target: string \| HTMLElement, ...props: {} extends P ? [props?: P] : [props: P]): Promise<ApplicationHandle>` |
|
|
626
|
+
| ApplicationHandle | `element: HTMLElement`, `unmount(): void` |
|
|
627
|
+
| VueApplicationContext | `mode: 'standalone' \| 'bridge'`, `signal: AbortSignal`, `routing?: BridgeChildRoute` |
|
|
628
|
+
| VueApplicationSetup | `app: VueApp`, `router: VueRouterLike & { install(app: VueApp): void; isReady(): Promise<void> }` |
|
|
629
|
+
| VueApplicationFactory<P> | `(props: P, context: VueApplicationContext) => VueApp \| VueApplicationSetup \| Promise<VueApp \| VueApplicationSetup>` |
|
|
630
|
+
| ReactApplicationContext | `mode: 'standalone' \| 'bridge'`, `signal: AbortSignal`, `routing?: BridgeChildRoute` |
|
|
631
|
+
| ReactApplicationSetup | `element: ReactElement`, `dispose?: () => void` |
|
|
632
|
+
| ReactApplicationFactory<P> | `(props: P, context: ReactApplicationContext) => ReactElement \| ReactApplicationSetup` |
|
|
633
|
+
|
|
634
|
+
See the [API reference](api.md#one-application-for-standalone-and-bridge-startup-defineapplication) for lifecycle and defaults.
|
|
635
|
+
|
|
636
|
+
## DefineVueBridgeAppOptions / DefineReactBridgeAppOptions
|
|
637
|
+
|
|
638
|
+
Import Vue options from /vue and React options from /react. defineApplication and defineBridgeApp share their framework options type.
|
|
639
|
+
|
|
640
|
+
| Field | Optional | Type | Default and purpose |
|
|
641
|
+
|---|---|---|---|
|
|
642
|
+
| routing | yes | boolean | false; true declares host URL synchronization. defineApplication can also install a local memory router without synchronization. |
|
package/docs/zh/reference/api.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
| 入口 | 用途 | 导出面 |
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| `@fulgurjs/federation`(包根) | Vite 配置 | `federation(options)` 插件 + `FederationOptions` 类型(字段全集见[配置参考](configuration.md)) |
|
|
10
|
-
| `@fulgurjs/federation/vue` | **Vue 应用唯一入口** | 运行时全量 + `provideAppContext`/`getAppContext`/`requireAppContext`/`clearAppContext` + `definePages`/`validatePages` + `remoteComponent` + `createHostPages` + `defineBridgeApp` + `createVueBridgeApp` + `createVueBridgeNavigation` + `connectVueBridgeRouter` + `remoteSchema` |
|
|
11
|
-
| `@fulgurjs/federation/react` | **React 应用唯一入口** | 同一运行时全量 + context + pages(`createReactHostPages`)+ `remoteComponent`/`useLoadRemote`/`RemoteErrorBoundary` + `defineBridgeApp` + `createReactBridgeApp` + `createReactBridgeNavigation` + `createReactBridgeRouter` + `remoteSchema` |
|
|
10
|
+
| `@fulgurjs/federation/vue` | **Vue 应用唯一入口** | 运行时全量 + `provideAppContext`/`getAppContext`/`requireAppContext`/`clearAppContext` + `definePages`/`validatePages` + `remoteComponent` + `bindStoreToApp` + `createHostPages` + `defineApplication` + `defineBridgeApp` + `createVueBridgeApp` + `createVueBridgeNavigation` + `connectVueBridgeRouter` + `remoteSchema` |
|
|
11
|
+
| `@fulgurjs/federation/react` | **React 应用唯一入口** | 同一运行时全量 + context + pages(`createReactHostPages`)+ `remoteComponent`/`useLoadRemote`/`RemoteErrorBoundary` + `defineApplication` + `defineBridgeApp` + `createReactBridgeApp` + `createReactBridgeNavigation` + `createReactBridgeRouter` + `remoteSchema` |
|
|
12
12
|
| `@fulgurjs/federation/runtime` | **框架无关** | 运行时全量(loadRemote/loadShare/initSharing/registerRemotes/registerShare/registerRemote/registerPlugins/preloadRemote/getContainer/getLoadedShare/pinLoadedShare/parseSpec/getRuntime/shareScopeMap/unwrapDefault/version/clearSessionState)+ context + pages(`definePages`/`validatePages`)+ `remoteSchema`;零 Vue/React/router 依赖 |
|
|
13
13
|
|
|
14
14
|
<a id="runtime-api"></a>
|
|
@@ -640,3 +640,47 @@ const PREFETCH_REMOTES: string[] = []
|
|
|
640
640
|
## 完整公共类型
|
|
641
641
|
|
|
642
642
|
[公共类型参考](types.md) 按当前入口列出全部公开类型及字段。
|
|
643
|
+
|
|
644
|
+
## 同一应用独立启动与桥接:`defineApplication`
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
Vue 从 `@fulgurjs/federation/vue` 导入,React 从 `@fulgurjs/federation/react` 导入;不新增子路径。完整例子见[已有应用统一装配](../guide/existing-apps.md)。只需要桥接、不需要独立启动时,仍可使用 `defineBridgeApp`。
|
|
648
|
+
|
|
649
|
+
```ts
|
|
650
|
+
// Vue;React 使用同名入口,工厂返回 ReactElement 或 { element, dispose? }
|
|
651
|
+
import { defineApplication } from '@fulgurjs/federation/vue'
|
|
652
|
+
// application.ts 默认导出这个返回值;exposes 指向 application.ts。
|
|
653
|
+
// 独立 main.ts 导入该默认导出,只调用 application.start('#app', props)。
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
| 项目 | 合同 |
|
|
657
|
+
|---|---|
|
|
658
|
+
| 签名 | `defineApplication<P extends object>(factory, options?) => Application<P>`;普通 interface 可用,不需要索引签名 |
|
|
659
|
+
| options | 对应框架的 `DefineVueBridgeAppOptions` / `DefineReactBridgeAppOptions`;`routing` 默认 false,启用宿主 URL 同步时设 true |
|
|
660
|
+
| 工厂调用 | 每个容器、每次挂载新调用;Vue 可返回 Promise,React 工厂必须同步返回 |
|
|
661
|
+
| context.mode | 必有;`standalone` 为独立启动,`bridge` 为宿主挂载 |
|
|
662
|
+
| context.signal | 必有;仅属于这次实例,卸载或外部挂载取消时 abort;异步任务必须自行遵守 signal |
|
|
663
|
+
| context.routing | 桥接启用路由时由宿主提供;独立启动不提供,不能对它调用桥接连接器 |
|
|
664
|
+
| Vue 返回值 | `app` 或 `{ app, router }`。推荐后者;工厂装配 Pinia、组件、Providers、守卫后返回尚未安装 router 的 app。独立模式传真实 web/hash router,插件安装并等待 isReady;桥接模式传 memory router;需要宿主 URL 同步时声明 routing:true,不同步时也可返回本地 router 自动安装/等待 |
|
|
665
|
+
| React 返回值 | `ReactElement` 或 `{ element: ReactElement, dispose?: () => void }`;dispose 同步释放这次创建的 router/资源。桥接 createReactBridgeRouter 的 element/dispose 可直接返回;独立模式返回 RouterProvider 与 router.dispose |
|
|
666
|
+
| `start(target, props)` | target 为选择器或 HTMLElement;P 有必填字段时 props 必填,否则可省略。Promise 成功得到 `{ element, unmount() }`;Vue 已等待初始路由、挂载,React 已完成首次根提交,不表示接口/页面所有异步内容完成 |
|
|
667
|
+
| 启动途中取消 | 调用 `application.unmount(element)`;start 拒绝 AbortError。迟到工厂结果不得重挂载,调用方应处理拒绝 |
|
|
668
|
+
| 卸载 | handle.unmount 只停止自己的启动代次;旧 handle 不停止同容器新实例。卸载失败后该定义会封锁容器,整页刷新后再用,不伪装成可重试成功 |
|
|
669
|
+
| 重复挂载 | 同容器未卸载不得再次 start 或 mount;多容器必须各自创建 app/router/状态实例 |
|
|
670
|
+
| 宿主使用 | 返回值也实现 BridgeApp(mount/unmount/routing),由 createVueBridgeApp/createReactBridgeApp 加载;宿主不会调用 start |
|
|
671
|
+
|
|
672
|
+
### 显式绑定业务状态:`bindStoreToApp`(仅 Vue)
|
|
673
|
+
|
|
674
|
+
```ts
|
|
675
|
+
import { bindStoreToApp } from '@fulgurjs/federation/vue'
|
|
676
|
+
import { createPinia } from 'pinia'
|
|
677
|
+
import { useCounterStore } from './stores/counter'
|
|
678
|
+
const pinia = createPinia()
|
|
679
|
+
const useCounter = bindStoreToApp(useCounterStore, pinia)
|
|
680
|
+
// 在这次 app 的装配中 provide useCounter;异步回调里无需依赖全局 activePinia。
|
|
681
|
+
const counter = useCounter()
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
签名 `bindStoreToApp<T extends (...args: never[]) => unknown>(useStore: T, pinia: Parameters<T>[0] | (() => Parameters<T>[0])): T`。返回代理保持原函数的参数/返回类型和 `$id` 等属性;只有首参数省略或 null 时补绑定实例,显式传其他实例时尊重调用参数。不导入 Pinia、不调用 setActivePinia、不建立全局业务 store。
|
|
685
|
+
|
|
686
|
+
getter 仅适合本模块明确只有一个默认实例且初始化较晚的情形;未就绪时抛可读错误。多容器并发请每次工厂绑定实际实例并向自身组件注入,不能用一个会被下一次挂载覆盖的模块变量。组件内正常 Pinia 注入继续使用原生 useStore。
|
|
@@ -217,6 +217,8 @@ setup/onSession 收到的上下文.
|
|
|
217
217
|
| `onSession` | yes | `(ctx: RemoteSetupContext) => void \| Promise<void>` | 见对应 API 合同。 |
|
|
218
218
|
| `globalComponents` | yes | `Record<string, unknown>` | 远程暴露面依赖的「宿主全局注册组件」声明(键=组件注册名,值=组件对象或零参 loader): 组件联邦(remoteComponent)把远程组件渲染进消费方 app 上下文,模板里的 字符串标签(如 <a-divider>)按消费方 app 的全局注册表解析——消费方没注册就 渲染成死元素。提供方在此声明后,运行时在每次 loadRemote 时把它们幂等注册到 当次传入的 consumerApp 上;无 consumerApp(无组件上下文的手动加载)时静默跳过。 值推荐「零参 loader(() => import('./X.vue'))」:setup 模块保持零重依赖, 组件只在本框架消费方真实渲染时才加载——Vue 适配器注册时自动包 defineAsyncComponent; 静态组件值仍支持;带 displayName/props/emits 的零参函数保留组件身份,未标记零参函数作 loader。运行时对值原样透传。 |
|
|
219
219
|
|
|
220
|
+
| `pageProviders` | yes | `unknown[]` | 远程组件所需的祖先 Provider;元素为组件或零参 loader。由组件适配器包裹实际消费树,不复制提供方整个 app。 |
|
|
221
|
+
|
|
220
222
|
## AppContext
|
|
221
223
|
|
|
222
224
|
宿主提供给远程模块的应用与会话上下文.
|
|
@@ -599,3 +601,28 @@ import type { ReactBridgeRouterConnection } from '@fulgurjs/federation/react'
|
|
|
599
601
|
| `element` | `ReactElement` | 返回给桥接工厂,作为子应用根节点。 |
|
|
600
602
|
| `routerReady` | `Promise<Router>` | 等待 memory router 完成接线;依赖缺失会 reject。需要访问 router 时等待此 Promise,不假设 `element.props.router` 同步存在。 |
|
|
601
603
|
| `dispose` | `() => void` | 卸载时解除路由订阅与接线。与桥接生命周期清理一起调用。 |
|
|
604
|
+
|
|
605
|
+
## Application / ApplicationHandle
|
|
606
|
+
|
|
607
|
+
入口 / Entry: `@fulgurjs/federation/vue`, `@fulgurjs/federation/react`.
|
|
608
|
+
|
|
609
|
+
| 类型 / Type | 字段 / Fields |
|
|
610
|
+
|---|---|
|
|
611
|
+
| Application<P extends object> | BridgeApp + `__fgBridgeProps?: P` + `start(target: string \| HTMLElement, ...props: {} extends P ? [props?: P] : [props: P]): Promise<ApplicationHandle>` |
|
|
612
|
+
| ApplicationHandle | `element: HTMLElement`, `unmount(): void` |
|
|
613
|
+
| VueApplicationContext | `mode: 'standalone' \| 'bridge'`, `signal: AbortSignal`, `routing?: BridgeChildRoute` |
|
|
614
|
+
| VueApplicationSetup | `app: VueApp`, `router: VueRouterLike & { install(app: VueApp): void; isReady(): Promise<void> }` |
|
|
615
|
+
| VueApplicationFactory<P> | `(props: P, context: VueApplicationContext) => VueApp \| VueApplicationSetup \| Promise<VueApp \| VueApplicationSetup>` |
|
|
616
|
+
| ReactApplicationContext | `mode: 'standalone' \| 'bridge'`, `signal: AbortSignal`, `routing?: BridgeChildRoute` |
|
|
617
|
+
| ReactApplicationSetup | `element: ReactElement`, `dispose?: () => void` |
|
|
618
|
+
| ReactApplicationFactory<P> | `(props: P, context: ReactApplicationContext) => ReactElement \| ReactApplicationSetup` |
|
|
619
|
+
|
|
620
|
+
调用顺序和默认值见 [API 参考](api.md#同一应用独立启动与桥接defineapplication)。
|
|
621
|
+
|
|
622
|
+
## DefineVueBridgeAppOptions / DefineReactBridgeAppOptions
|
|
623
|
+
|
|
624
|
+
Vue 从 `/vue` 导入,React 从 `/react` 导入;defineApplication 与 defineBridgeApp 共用对应框架的选项类型。
|
|
625
|
+
|
|
626
|
+
| 字段 | 可省略 | 类型 | 默认与用途 |
|
|
627
|
+
|---|---|---|---|
|
|
628
|
+
| `routing` | 是 | `boolean` | false;true 声明宿主 URL 同步协议。defineApplication 不启用同步时也能安装本地 memory router。 |
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# fulgurjs-federation 模板(examples/templates/)
|
|
2
2
|
|
|
3
|
+
> 五个模板统一使用 6.9.0 的 defineApplication 装配。按各模板 README 的冻结安装命令安装 registry 正式包。
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
五个可独立复制、`pnpm install` 后直接运行的联邦接入模板。全部使用 **npm registry 正式包** `@fulgurjs/federation`(精确版本 + pnpm 锁文件,钉定版本见各模板 package.json;统一入口 /vue、/react、/runtime——模板代码即统一入口用法),不依赖本仓库源码、workspace 或父目录。
|
|
4
7
|
|
|
5
8
|
## 获取模板的两种方式
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# react-host-vue-remote:完整子应用桥接模板
|
|
2
2
|
|
|
3
|
+
> 本目录是 6.9.0 源码候选:已改用 defineApplication,尚未测试和发布。源码依赖已锁定 6.9.0;正式发布前不要拿旧 registry 包运行这份代码。验收先使用本次候选 tarball,发布后再按下列冻结安装命令验证正式包。
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
`react-host/` 是宿主,`vue-remote/` 是子应用。复制整个模板目录,在根目录运行:
|
|
4
7
|
|
|
5
8
|
```bash
|
|
@@ -22,3 +25,24 @@ pnpm dev
|
|
|
22
25
|
- 改vue-remote(默认 5313):① `vue-remote/package.json` 的 `dev` 与 `preview` 两个脚本的 `--port 5313`;② `react-host/fulgurjs.config.ts` 里 `remotes['bridge-vue-remote'].dev` 的 `http://localhost:5313`;③ 根 `scripts/dev.config.json` 里 vue-remote 的 `port`(**必改**:启动器预检/探活都读它);④ 本 README 顶部端口表。
|
|
23
26
|
- 改react-host(默认 5304):① `react-host/package.json` 的 `dev`/`preview` `--port 5304`;② `scripts/dev.config.json`;③ 本 README 端口表。
|
|
24
27
|
- 生产部署地址(`prod`,如 `/vue-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-host/src/application.tsx` | 本应用唯一装配;main 只负责调用 start |
|
|
43
|
+
| `vue-remote/src/application.ts` | 本应用唯一装配;main 只负责调用 start |
|
|
44
|
+
| `react-host/fulgurjs.config.ts` | 本应用的远程地址、exposes、实际共享依赖 |
|
|
45
|
+
| `vue-remote/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 vue-remote dev",
|
|
7
7
|
"dev:host": "pnpm --dir react-host dev",
|
|
8
8
|
"dev": "node scripts/dev.mjs",
|
|
9
|
-
"build": "pnpm --dir vue-remote build && pnpm --dir react-host build"
|
|
9
|
+
"build": "pnpm --dir vue-remote build && pnpm --dir react-host build",
|
|
10
|
+
"prod": "node scripts/prod.mjs"
|
|
10
11
|
}
|
|
11
12
|
}
|
|
@@ -11,8 +11,8 @@ importers:
|
|
|
11
11
|
react-host:
|
|
12
12
|
dependencies:
|
|
13
13
|
'@fulgurjs/federation':
|
|
14
|
-
specifier: 6.
|
|
15
|
-
version: 6.
|
|
14
|
+
specifier: 6.9.0
|
|
15
|
+
version: 6.9.0(react-dom@19.3.0(react@19.3.0))(react@19.3.0)(vite@6.4.4)(vue-router@4.6.4(vue@3.5.43(typescript@5.9.3)))(vue@3.5.43(typescript@5.9.3))
|
|
16
16
|
react:
|
|
17
17
|
specifier: ^19.1.0
|
|
18
18
|
version: 19.3.0
|
|
@@ -42,8 +42,8 @@ importers:
|
|
|
42
42
|
vue-remote:
|
|
43
43
|
dependencies:
|
|
44
44
|
'@fulgurjs/federation':
|
|
45
|
-
specifier: 6.
|
|
46
|
-
version: 6.
|
|
45
|
+
specifier: 6.9.0
|
|
46
|
+
version: 6.9.0(react-dom@19.3.0(react@19.3.0))(react@19.3.0)(vite@6.4.4)(vue-router@4.6.4(vue@3.5.43(typescript@5.9.3)))(vue@3.5.43(typescript@5.9.3))
|
|
47
47
|
vue:
|
|
48
48
|
specifier: ^3.5.13
|
|
49
49
|
version: 3.5.43(typescript@5.9.3)
|
|
@@ -461,8 +461,8 @@ packages:
|
|
|
461
461
|
cpu: [x64]
|
|
462
462
|
os: [win32]
|
|
463
463
|
|
|
464
|
-
'@fulgurjs/federation@6.
|
|
465
|
-
resolution: {
|
|
464
|
+
'@fulgurjs/federation@6.9.0':
|
|
465
|
+
resolution: {tarball: https://registry.npmjs.org/@fulgurjs/federation/-/federation-6.9.0.tgz}
|
|
466
466
|
engines: {node: '>=18'}
|
|
467
467
|
hasBin: true
|
|
468
468
|
peerDependencies:
|
|
@@ -1259,7 +1259,7 @@ snapshots:
|
|
|
1259
1259
|
'@esbuild/win32-x64@0.27.7':
|
|
1260
1260
|
optional: true
|
|
1261
1261
|
|
|
1262
|
-
'@fulgurjs/federation@6.
|
|
1262
|
+
'@fulgurjs/federation@6.9.0(react-dom@19.3.0(react@19.3.0))(react@19.3.0)(vite@6.4.4)(vue-router@4.6.4(vue@3.5.43(typescript@5.9.3)))(vue@3.5.43(typescript@5.9.3))':
|
|
1263
1263
|
dependencies:
|
|
1264
1264
|
es-module-lexer: 1.7.0
|
|
1265
1265
|
esbuild: 0.27.7
|
|
@@ -2,7 +2,7 @@ packages:
|
|
|
2
2
|
- react-host
|
|
3
3
|
- vue-remote
|
|
4
4
|
minimumReleaseAgeExclude:
|
|
5
|
-
- '@fulgurjs/federation@6.
|
|
5
|
+
- '@fulgurjs/federation@6.9.0'
|
|
6
6
|
# pnpm >=12 构建脚本批准(12 起弃用 onlyBuiltDependencies;pnpm 9-11 忽略本键:
|
|
7
7
|
# esbuild >=0.16 二进制经 optionalDependencies 平台包分发,postinstall 仅校验,不阻塞安装)
|
|
8
8
|
allowBuilds:
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { StrictMode, useCallback, useState } from 'react'
|
|
2
|
+
import { defineApplication } from '@fulgurjs/federation/react'
|
|
3
|
+
import { clearAppContext } from '@fulgurjs/federation/react'
|
|
4
|
+
import { createReactBridgeApp } from '@fulgurjs/federation/react'
|
|
5
|
+
import { getLatestHostContext, login, logout } from './host-session'
|
|
6
|
+
|
|
7
|
+
// 工厂选项:fallback(pending 占位)、error(节点或 (error, retry) => ReactNode)、
|
|
8
|
+
// retries、timeout、getContext 与 Vue 宿主同语义
|
|
9
|
+
const RemoteVueApp = createReactBridgeApp('bridge-vue-remote/bridge', {
|
|
10
|
+
retries: 1,
|
|
11
|
+
getContext: () => getLatestHostContext(),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
function Host() {
|
|
15
|
+
const [sessionKey, setSessionKey] = useState<string | null>('login-1-alice')
|
|
16
|
+
const [userName, setUserName] = useState('Alice')
|
|
17
|
+
const [label, setLabel] = useState('来自 React 宿主')
|
|
18
|
+
const [readyCount, setReadyCount] = useState(0)
|
|
19
|
+
|
|
20
|
+
const handleReady = useCallback(() => setReadyCount((c) => c + 1), [])
|
|
21
|
+
|
|
22
|
+
const nextFrame = async (): Promise<void> => {
|
|
23
|
+
await new Promise((r) => requestAnimationFrame(() => r(null)))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const switchUser = async (): Promise<void> => {
|
|
27
|
+
setSessionKey(null)
|
|
28
|
+
await nextFrame()
|
|
29
|
+
clearAppContext()
|
|
30
|
+
login('login-2-bob', { id: 2, name: 'Bob' })
|
|
31
|
+
setUserName('Bob')
|
|
32
|
+
setSessionKey('login-2-bob')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const doLogout = async (): Promise<void> => {
|
|
36
|
+
setSessionKey(null)
|
|
37
|
+
await nextFrame()
|
|
38
|
+
clearAppContext()
|
|
39
|
+
logout()
|
|
40
|
+
setUserName('')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div style={{ fontFamily: 'sans-serif', padding: 16, maxWidth: 720 }}>
|
|
45
|
+
<h1>React 宿主 × Vue 子应用(@fulgurjs/federation/react)</h1>
|
|
46
|
+
<p data-testid="demo-session">{`会话:${sessionKey ?? '未登录'}(${userName || '—'})· onReady 次数:${readyCount}`}</p>
|
|
47
|
+
<p>
|
|
48
|
+
<button data-testid="demo-switch" onClick={() => void switchUser()}>切换到 Bob(clearAppContext → 重挂)</button>
|
|
49
|
+
<button data-testid="demo-logout" onClick={() => void doLogout()}>登出(sessionKey → null)</button>
|
|
50
|
+
</p>
|
|
51
|
+
<section style={{ marginTop: 12 }}>
|
|
52
|
+
<RemoteVueApp sessionKey={sessionKey} appProps={{ label, onReady: handleReady }} />
|
|
53
|
+
</section>
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default defineApplication(() => (
|
|
59
|
+
<StrictMode>
|
|
60
|
+
<Host />
|
|
61
|
+
</StrictMode>
|
|
62
|
+
))
|