@fulgurjs/federation 1.0.0 → 2.0.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/dist/runtime.js CHANGED
@@ -1,3 +1,3 @@
1
- var X=/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/;function T(t){let n=X.exec(String(t).trim());return n?{major:Number(n[1]),minor:Number(n[2]??0),patch:Number(n[3]??0),pre:n[4]?n[4].split("."):[]}:null}function Y(t,n){if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;let o=Math.max(t.length,n.length);for(let r=0;r<o;r++){let l=t[r],m=n[r];if(l===void 0)return-1;if(m===void 0)return 1;let y=/^\d+$/.test(l),E=/^\d+$/.test(m);if(y&&E){let w=Number(l)-Number(m);if(w!==0)return w}else{if(y!==E)return y?-1:1;if(l!==m)return l<m?-1:1}}return 0}function M(t,n){let o=T(t),r=T(n);return!o||!r?t<n?-1:t>n?1:0:o.major!==r.major?o.major-r.major:o.minor!==r.minor?o.minor-r.minor:o.patch!==r.patch?o.patch-r.patch:Y(o.pre,r.pre)}var Z=/^[a-z]+[+:-]/i;function O(t,n){if(n===!1||n==null||n==="")return!0;let o=String(n).trim();return!o||o==="*"||o==="latest"||Z.test(o)?!0:o.split("||").some(r=>Q(t,r.trim()))}function Q(t,n){if(!n||n==="*")return!T(t)?.pre.length;let o=n.split(/\s+-\s+/);if(o.length===2){let m=o[0].trim(),y=o[1].trim();return!(!O(t,`>=${m}`)||!O(t,`<=${y}`))}let r=T(t);if(!r)return!1;let l=ee(n);if(l===null)return!0;for(let m of l)if(!ie(r,t,m))return!1;return!(r.pre.length>0&&!l.some(m=>m.ver.pre.length>0)&&!l.some(y=>y.ver.major===r.major&&y.ver.minor===r.minor&&y.ver.patch===r.patch))}function ee(t){let n=[],o=t.trim().split(/\s+/).filter(Boolean);if(o.length===0)return null;for(let r of o){let l=/^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(r);if(!l)return null;let m=l[1],y=l[2],E=re(m,y);if(E===null)return null;n.push(...E)}return n}function re(t,n){let o=ne(n);if(!o)return null;let{ver:r,partial:l}=o;switch(t){case"^":{let m=te(r);return m?[{op:">=",ver:r},{op:"<",ver:m}]:null}case"~":{let m=l>=2?{major:r.major,minor:r.minor+1,patch:0,pre:[]}:{major:r.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:r},{op:"<",ver:m}]}case">=":return[{op:">=",ver:r}];case">":return l===1?[{op:">=",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:">",ver:r}];case"<":return l===1?[{op:"<",ver:{major:r.major,minor:0,patch:0,pre:[]}}]:l===2?[{op:"<",ver:{major:r.major,minor:r.minor,patch:0,pre:[]}}]:[{op:"<",ver:r}];case"<=":return[{op:"<=",ver:r}];case"=":case void 0:return l===1?[{op:">=",ver:r},{op:"<",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:r},{op:"<",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:r}];default:return null}}function te(t){return t.major>0?{major:t.major+1,minor:0,patch:0,pre:[]}:t.minor>0?{major:0,minor:t.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:t.patch+1,pre:[]}}function ne(t){let n=t.replace(/^v/,"").trim();if(!n||n==="*"||n==="x"||n==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let o=n.split("."),r=[],l=0;for(let E of o.slice(0,3))if(/^\d+$/.test(E))r.push(Number(E)),l++;else{if(E==="x"||E==="X"||E==="*")break;break}let m=n.split("-"),y=m.length>1?m.slice(1).join("-").split("+")[0].split("."):[];return l===0&&y.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:r[0]??0,minor:r[1]??0,patch:r[2]??0,pre:y},partial:l}}function oe(t,n){switch(n){case">=":return t>=0;case">":return t>0;case"<":return t<0;case"<=":return t<=0;case"=":return t===0}}function ie(t,n,o){let r=`${t.major}.${t.minor}.${t.patch}`+(t.pre.length?`-${t.pre.join(".")}`:"");if(o.upper)return!(!(M(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:""))>=0)||!(M(r,`${o.upper.major}.${o.upper.minor}.${o.upper.patch}`)<0));let l=M(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:"")),m=oe(l,o.op);return o.ver.pre.length>0&&t.pre.length===0&&(o.op===">"||o.op==="<")?!1:m}var g=class extends Error{code;details;constructor(n,o,r){super(`[fulgurjs:${n}] ${o}`),this.name="FulgurjsError",this.code=n,this.details=r}},S={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"};var U="1.0.0";var A=15e3,P=2,ae=5,se=3e4;function ce(){let t={},n=new Map,o=[],r=new Map,l=new WeakMap,m={},y=()=>{for(let e of o)try{e.init?.(m)}catch(i){console.warn("[fulgurjs] runtimePlugin init failed:",e.name,i)}},E=e=>t[e]??={};function w(e){try{m.onRemoteError?.(e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent("fulgurjs:error",{detail:e}))}function F(e="default"){return E(e),t}function V(e,i,a,c,R={}){let s=E(e||"default"),u=s[i]??={};u[a]||(u[a]={version:a,get:c,from:R.from??"unknown",eager:!!R.eager,loaded:!!R.loaded})}function I(e){for(let i of e){let a=n.get(i.name);n.set(i.name,{timeout:A,retries:P,...a,...i,state:a?.state??"idle",breakerState:a?.breakerState??{fails:0,openUntil:0},debug:a?.debug??{entry:i.entry,status:"idle"}})}}function D(e){I([e])}function H(e){o.push(...e),y()}async function K(e,i={}){let a=i.shareScope||"default",c=i.shareKey||e,s=E(a)[c]||{},u=Object.keys(s),d=i.requiredVersion,f=u.filter(p=>d===void 0||d===!1||O(p,d)),_;if(i.singleton&&u.length>0){let p=u.filter(h=>s[h].loaded);if(_=[...p.length?p:u].sort(M).pop(),u.length>1||!f.includes(_)){let h=s[_],v=`singleton skew "${c}": req "${d??"any"}" use ${_} from ${h.from}`;if(i.strictVersion){let j=new g(S.SHARE_STRICT_VERSION,v,{shareKey:c,requiredVersion:d});throw w({remote:h.from,error:j}),j}console.warn(`[fulgurjs:MFU-010] ${v}`)}}else if(_=[...f].sort(M).pop(),!_){if(i.strictVersion){let h=new g(S.SHARE_STRICT_VERSION,`no satisfying version for "${c}" (required "${d}") in share scope "${a}"`);throw w({remote:c,error:h}),h}if(i.fallback)return i.fallback();let p=new g(S.SHARE_NOT_AVAILABLE,`shared "${c}" (${d??"any"}) unavailable in scope "${a}" (no local fallback)`,{shareKey:c,requiredVersion:d});throw w({remote:c,error:p}),p}let $=s[_];if(m.resolveShare){let p=await m.resolveShare({shareKey:c,shareScope:a,requiredVersion:d,picked:$,available:Object.values(s)});p&&($=p)}return $.loaded=!0,$.get()}function q(e,i,a){return new Promise((c,R)=>{let s=setTimeout(()=>R(new Error(`timeout after ${i}ms: ${a}`)),i);e.then(u=>{clearTimeout(s),c(u)},u=>{clearTimeout(s),R(u)})})}let z=e=>new Promise(i=>setTimeout(i,e));function k(e,i){if(!e||typeof e.get!="function")throw new Error(`remoteEntry of "${i.name}" does not export a container interface (get/init)`);if(e.name&&i.name&&e.name!==i.name){let a=`remoteEntry self-reported name "${e.name}" mismatches configured name "${i.name}"`;if(i.promise)console.warn(`[fulgurjs] ${a} (promise-based remote, continuing)`);else throw Object.assign(new Error(a),{code:S.REMOTE_NAME_MISMATCH})}}async function L(e,i){return q(import(e),i.timeout??A,`load remoteEntry ${e}`)}async function x(e,i){let a=e.shareScope||"default";if(e.container){let s=l.get(e.container);if(s&&s!==a)throw new g(S.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${s}", cannot re-init with "${a}"`);return e.container}if(e.containerPromise)return e.containerPromise;let c=e.breakerState;if(c.openUntil>Date.now()){let s=new g(S.REMOTE_LOAD_FAILED,`circuit breaker open for remote "${e.name}" until ${new Date(c.openUntil).toISOString()}`,{remote:e.name});throw w({remote:e.name,error:s}),s}e.state="loading",e.debug.status="loading";let R=(async()=>{let s=[];if(e.promise)s.push(async()=>{let p=await e.promise(),h=typeof p=="string"?await L(p,e):p;return k(h,e),h});else for(let p of[e.entry,...e.fallback??[]])s.push(async()=>{let h=await L(p,e);return k(h,e),h});let u,d,f=!1,_=i?.retries??e.retries??P;for(let p of s){for(let h=0;h<=_;h++){let v=performance.now();try{u=await p(),e.lastLoadMs=Math.round(performance.now()-v),e.debug.lastLoadMs=e.lastLoadMs,f=!0;break}catch(j){if(d=j,j?.code)throw j;h<_&&await z(200*2**h)}}if(f)break}if(!f||!u){let p=[];throw/^https?:\/\//.test(e.entry)&&typeof location<"u"?(p.push(`1. is the remote dev server running? try opening ${e.entry} in the browser \u2014 it must return JS, not HTML/an error`),p.push("2. is the URL correct in federation({ remotes })? dev and prod entries can differ"),p.push("3. CORS: the remote dev server must allow cross-origin requests (fulgurjs-federation enables server.cors automatically; a custom server config may have disabled it)")):(p.push(`1. is the remote deployed and reachable? try opening ${e.entry} in the browser \u2014 it must return JS`),p.push("2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)")),new g(S.REMOTE_LOAD_FAILED,`failed to load remote "${e.name}" from ${e.entry}: ${String(d?.message??d)}
1
+ var X=/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/;function T(t){let n=X.exec(String(t).trim());return n?{major:Number(n[1]),minor:Number(n[2]??0),patch:Number(n[3]??0),pre:n[4]?n[4].split("."):[]}:null}function Y(t,n){if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;let o=Math.max(t.length,n.length);for(let r=0;r<o;r++){let l=t[r],m=n[r];if(l===void 0)return-1;if(m===void 0)return 1;let y=/^\d+$/.test(l),E=/^\d+$/.test(m);if(y&&E){let w=Number(l)-Number(m);if(w!==0)return w}else{if(y!==E)return y?-1:1;if(l!==m)return l<m?-1:1}}return 0}function v(t,n){let o=T(t),r=T(n);return!o||!r?t<n?-1:t>n?1:0:o.major!==r.major?o.major-r.major:o.minor!==r.minor?o.minor-r.minor:o.patch!==r.patch?o.patch-r.patch:Y(o.pre,r.pre)}var Z=/^[a-z]+[+:-]/i;function O(t,n){if(n===!1||n==null||n==="")return!0;let o=String(n).trim();return!o||o==="*"||o==="latest"||Z.test(o)?!0:o.split("||").some(r=>Q(t,r.trim()))}function Q(t,n){if(!n||n==="*")return!T(t)?.pre.length;let o=n.split(/\s+-\s+/);if(o.length===2){let m=o[0].trim(),y=o[1].trim();return!(!O(t,`>=${m}`)||!O(t,`<=${y}`))}let r=T(t);if(!r)return!1;let l=ee(n);if(l===null)return!0;for(let m of l)if(!ie(r,t,m))return!1;return!(r.pre.length>0&&!l.some(m=>m.ver.pre.length>0)&&!l.some(y=>y.ver.major===r.major&&y.ver.minor===r.minor&&y.ver.patch===r.patch))}function ee(t){let n=[],o=t.trim().split(/\s+/).filter(Boolean);if(o.length===0)return null;for(let r of o){let l=/^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(r);if(!l)return null;let m=l[1],y=l[2],E=re(m,y);if(E===null)return null;n.push(...E)}return n}function re(t,n){let o=ne(n);if(!o)return null;let{ver:r,partial:l}=o;switch(t){case"^":{let m=te(r);return m?[{op:">=",ver:r},{op:"<",ver:m}]:null}case"~":{let m=l>=2?{major:r.major,minor:r.minor+1,patch:0,pre:[]}:{major:r.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:r},{op:"<",ver:m}]}case">=":return[{op:">=",ver:r}];case">":return l===1?[{op:">=",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:">",ver:r}];case"<":return l===1?[{op:"<",ver:{major:r.major,minor:0,patch:0,pre:[]}}]:l===2?[{op:"<",ver:{major:r.major,minor:r.minor,patch:0,pre:[]}}]:[{op:"<",ver:r}];case"<=":return[{op:"<=",ver:r}];case"=":case void 0:return l===1?[{op:">=",ver:r},{op:"<",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:r},{op:"<",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:r}];default:return null}}function te(t){return t.major>0?{major:t.major+1,minor:0,patch:0,pre:[]}:t.minor>0?{major:0,minor:t.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:t.patch+1,pre:[]}}function ne(t){let n=t.replace(/^v/,"").trim();if(!n||n==="*"||n==="x"||n==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let o=n.split("."),r=[],l=0;for(let E of o.slice(0,3))if(/^\d+$/.test(E))r.push(Number(E)),l++;else{if(E==="x"||E==="X"||E==="*")break;break}let m=n.split("-"),y=m.length>1?m.slice(1).join("-").split("+")[0].split("."):[];return l===0&&y.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:r[0]??0,minor:r[1]??0,patch:r[2]??0,pre:y},partial:l}}function oe(t,n){switch(n){case">=":return t>=0;case">":return t>0;case"<":return t<0;case"<=":return t<=0;case"=":return t===0}}function ie(t,n,o){let r=`${t.major}.${t.minor}.${t.patch}`+(t.pre.length?`-${t.pre.join(".")}`:"");if(o.upper)return!(!(v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:""))>=0)||!(v(r,`${o.upper.major}.${o.upper.minor}.${o.upper.patch}`)<0));let l=v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:"")),m=oe(l,o.op);return o.ver.pre.length>0&&t.pre.length===0&&(o.op===">"||o.op==="<")?!1:m}var g=class extends Error{code;details;constructor(n,o,r){super(`[fulgurjs:${n}] ${o}`),this.name="FgError",this.code=n,this.details=r}},S={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"};var U="2.0.0";var A=15e3,P=2,ae=5,se=3e4;function ce(){let t={},n=new Map,o=[],r=new Map,l=new WeakMap,m={},y=()=>{for(let e of o)try{e.init?.(m)}catch(i){console.warn("[fulgurjs] runtimePlugin init failed:",e.name,i)}},E=e=>t[e]??={};function w(e){try{m.onRemoteError?.(e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent("fulgurjs:error",{detail:e}))}function F(e="default"){return E(e),t}function V(e,i,a,c,R={}){let s=E(e||"default"),u=s[i]??={};u[a]||(u[a]={version:a,get:c,from:R.from??"unknown",eager:!!R.eager,loaded:!!R.loaded})}function I(e){for(let i of e){let a=n.get(i.name);n.set(i.name,{timeout:A,retries:P,...a,...i,state:a?.state??"idle",breakerState:a?.breakerState??{fails:0,openUntil:0},debug:a?.debug??{entry:i.entry,status:"idle"}})}}function D(e){I([e])}function H(e){o.push(...e),y()}async function K(e,i={}){let a=i.shareScope||"default",c=i.shareKey||e,s=E(a)[c]||{},u=Object.keys(s),d=i.requiredVersion,f=u.filter(p=>d===void 0||d===!1||O(p,d)),_;if(i.singleton&&u.length>0){let p=u.filter(h=>s[h].loaded);if(_=[...p.length?p:u].sort(v).pop(),u.length>1||!f.includes(_)){let h=s[_],j=`singleton skew "${c}": req "${d??"any"}" use ${_} from ${h.from}`;if(i.strictVersion){let M=new g(S.SHARE_STRICT_VERSION,j,{shareKey:c,requiredVersion:d});throw w({remote:h.from,error:M}),M}console.warn(`[fulgurjs:MFU-010] ${j}`)}}else if(_=[...f].sort(v).pop(),!_){if(i.strictVersion){let h=new g(S.SHARE_STRICT_VERSION,`no satisfying version for "${c}" (required "${d}") in share scope "${a}"`);throw w({remote:c,error:h}),h}if(i.fallback)return i.fallback();let p=new g(S.SHARE_NOT_AVAILABLE,`shared "${c}" (${d??"any"}) unavailable in scope "${a}" (no local fallback)`,{shareKey:c,requiredVersion:d});throw w({remote:c,error:p}),p}let $=s[_];if(m.resolveShare){let p=await m.resolveShare({shareKey:c,shareScope:a,requiredVersion:d,picked:$,available:Object.values(s)});p&&($=p)}return $.loaded=!0,$.get()}function q(e,i,a){return new Promise((c,R)=>{let s=setTimeout(()=>R(new Error(`timeout after ${i}ms: ${a}`)),i);e.then(u=>{clearTimeout(s),c(u)},u=>{clearTimeout(s),R(u)})})}let z=e=>new Promise(i=>setTimeout(i,e));function k(e,i){if(!e||typeof e.get!="function")throw new Error(`remoteEntry of "${i.name}" does not export a container interface (get/init)`);if(e.name&&i.name&&e.name!==i.name){let a=`remoteEntry self-reported name "${e.name}" mismatches configured name "${i.name}"`;if(i.promise)console.warn(`[fulgurjs] ${a} (promise-based remote, continuing)`);else throw Object.assign(new Error(a),{code:S.REMOTE_NAME_MISMATCH})}}async function L(e,i){return q(import(e),i.timeout??A,`load remoteEntry ${e}`)}async function x(e,i){let a=e.shareScope||"default";if(e.container){let s=l.get(e.container);if(s&&s!==a)throw new g(S.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${s}", cannot re-init with "${a}"`);return e.container}if(e.containerPromise)return e.containerPromise;let c=e.breakerState;if(c.openUntil>Date.now()){let s=new g(S.REMOTE_LOAD_FAILED,`circuit breaker open for remote "${e.name}" until ${new Date(c.openUntil).toISOString()}`,{remote:e.name});throw w({remote:e.name,error:s}),s}e.state="loading",e.debug.status="loading";let R=(async()=>{let s=[];if(e.promise)s.push(async()=>{let p=await e.promise(),h=typeof p=="string"?await L(p,e):p;return k(h,e),h});else for(let p of[e.entry,...e.fallback??[]])s.push(async()=>{let h=await L(p,e);return k(h,e),h});let u,d,f=!1,_=i?.retries??e.retries??P;for(let p of s){for(let h=0;h<=_;h++){let j=performance.now();try{u=await p(),e.lastLoadMs=Math.round(performance.now()-j),e.debug.lastLoadMs=e.lastLoadMs,f=!0;break}catch(M){if(d=M,M?.code)throw M;h<_&&await z(200*2**h)}}if(f)break}if(!f||!u){let p=[];throw/^https?:\/\//.test(e.entry)&&typeof location<"u"?(p.push(`1. is the remote dev server running? try opening ${e.entry} in the browser \u2014 it must return JS, not HTML/an error`),p.push("2. is the URL correct in federation({ remotes })? dev and prod entries can differ"),p.push("3. CORS: the remote dev server must allow cross-origin requests (fulgurjs-federation enables server.cors automatically; a custom server config may have disabled it)")):(p.push(`1. is the remote deployed and reachable? try opening ${e.entry} in the browser \u2014 it must return JS`),p.push("2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)")),new g(S.REMOTE_LOAD_FAILED,`failed to load remote "${e.name}" from ${e.entry}: ${String(d?.message??d)}
2
2
  `+p.join(`
3
- `),{remote:e.name})}k(u,e);let $=l.get(u);if($&&$!==a)throw new g(S.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${$}", cannot re-init with "${a}"`);return typeof u.init=="function"&&await u.init(t),l.set(u,a),e.container=u,e.state="loaded",e.debug.status="loaded",c.fails=0,u})();e.containerPromise=R;try{return await R}catch(s){if(e.containerPromise=void 0,e.state="failed",e.debug.status="failed",e.debug.error=String(s?.message??s),c.fails+=1,c.fails>=ae&&(c.openUntil=Date.now()+se,c.fails=0),s instanceof g)throw w({remote:e.name,error:s}),s;if(s?.code)throw w({remote:e.name,error:s}),s;let u=new g(S.REMOTE_LOAD_FAILED,String(s?.message??s),{remote:e.name});throw w({remote:e.name,error:u}),u}}function N(e){let i=e.indexOf("/");return i===-1?{remote:e,module:""}:{remote:e.slice(0,i),module:G(e.slice(i+1))}}function G(e){return e?e.startsWith(".")?e:`./${e}`:""}async function J(e,i){let{remote:a,module:c}=N(e);m.beforeLoadRemote?.({remote:a,module:c});let R=n.get(a);if(!R)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${a}". Register it via federation({ remotes }) or registerRemote().`,{remote:a});let s;try{s=await x(R,{retries:i?.retries})}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\u663E\u5F0F\u964D\u7EA7\uFF0C\u9519\u8BEF\u5DF2\u900F\u51FA)`,f),w({remote:a,error:f}),await i.fallbackModule();throw f}if(!c)return s;let u=`${a}@${R.shareScope||"default"}#${c}`;r.has(u)||r.set(u,s.get(c).catch(f=>{throw r.delete(u),f instanceof g||f?.code?f:new g(S.REMOTE_LOAD_FAILED,`failed to load module "${c}" from remote "${a}": ${String(f?.message??f)}`,{remote:a,module:c})}));let d;try{d=await r.get(u)}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\u663E\u5F0F\u964D\u7EA7\uFF0C\u9519\u8BEF\u5DF2\u900F\u51FA)`,f),w({remote:a,error:f}),await i.fallbackModule();throw f}if(m.afterLoadRemote?.({remote:a,module:c,module_ns:d}),d&&typeof d=="object"&&Object.keys(d).length===0){let f=new g(S.EMPTY_EXPORTS,`no exports: ${c} @ ${a}`,{remote:a,module:c});w({remote:a,error:f}),console.error(`[fulgurjs:MFU-009] ${f.message}`)}return d}function W(e){let i=n.get(e);if(!i)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${e}"`,{remote:e});return x(i)}async function B(e,i={}){let{remote:a}=N(e),c=n.get(a);if(!c)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${a}"`,{remote:a});let R=i.mode??"preload",s=(u,d)=>{if(typeof document>"u"||document.querySelector(`link[href="${u}"]`))return;let f=document.createElement("link");f.rel=d==="style"?"stylesheet":"modulepreload",f.href=u,R==="prefetch"&&(f.fetchPriority="low"),document.head.appendChild(f)};try{if(c.manifestUrl){let u=await fetch(c.manifestUrl,{cache:"no-cache"});if(u.ok){let d=await u.json();s(c.entry,"modulepreload");let f=d.exposes??{};for(let _ of Object.keys(f)){let $=f[_];$?.file&&s(new URL($.file,c.entry).href,"modulepreload");for(let p of $?.css??[])s(new URL(p,c.entry).href,"style")}return}}s(c.entry,"modulepreload")}catch(u){w({remote:a,error:new g(S.PRELOAD_FAILED,String(u?.message??u),{remote:a})})}}return typeof window>"u"||(window.__FULGURJS_SCOPE__=t,window.__FULGURJS_INFO__={get remotes(){let e={};for(let[i,a]of n)e[i]={...a.debug,entry:a.entry};return e},errors:[]}),{shareScopeMap:t,initSharing:F,registerShare:V,registerRemotes:I,registerRemote:D,registerPlugins:H,loadShare:K,loadRemote:J,getContainer:W,preloadRemote:B,parseSpec:N}}var C=globalThis,b=C.__FULGURJS_RUNTIME__??ce();C.__FULGURJS_RUNTIME__=b;try{Object.freeze(b)}catch{}var he=U;function ye(){return b}var Ee=b.initSharing,Re=b.registerShare,Se=b.registerRemotes,we=b.registerRemote,be=b.registerPlugins,_e=b.loadShare,$e=b.loadRemote,je=b.getContainer,Me=b.preloadRemote,ve=b.shareScopeMap;function Te(t){if(t&&typeof t=="object"&&"default"in t){let n=t.default;return n!==void 0?n:t}return t}var Oe=b;export{Oe as default,je as getContainer,ye as getRuntime,Ee as initSharing,$e as loadRemote,_e as loadShare,Me as preloadRemote,be as registerPlugins,we as registerRemote,Se as registerRemotes,Re as registerShare,b as runtime,ve as shareScopeMap,Te as unwrapDefault,he as version};
3
+ `),{remote:e.name})}k(u,e);let $=l.get(u);if($&&$!==a)throw new g(S.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${$}", cannot re-init with "${a}"`);return typeof u.init=="function"&&await u.init(t),l.set(u,a),e.container=u,e.state="loaded",e.debug.status="loaded",c.fails=0,u})();e.containerPromise=R;try{return await R}catch(s){if(e.containerPromise=void 0,e.state="failed",e.debug.status="failed",e.debug.error=String(s?.message??s),c.fails+=1,c.fails>=ae&&(c.openUntil=Date.now()+se,c.fails=0),s instanceof g)throw w({remote:e.name,error:s}),s;if(s?.code)throw w({remote:e.name,error:s}),s;let u=new g(S.REMOTE_LOAD_FAILED,String(s?.message??s),{remote:e.name});throw w({remote:e.name,error:u}),u}}function N(e){let i=e.indexOf("/");return i===-1?{remote:e,module:""}:{remote:e.slice(0,i),module:G(e.slice(i+1))}}function G(e){return e?e.startsWith(".")?e:`./${e}`:""}async function J(e,i){let{remote:a,module:c}=N(e);m.beforeLoadRemote?.({remote:a,module:c});let R=n.get(a);if(!R)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${a}". Register it via federation({ remotes }) or registerRemote().`,{remote:a});let s;try{s=await x(R,{retries:i?.retries})}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\u663E\u5F0F\u964D\u7EA7\uFF0C\u9519\u8BEF\u5DF2\u900F\u51FA)`,f),w({remote:a,error:f}),await i.fallbackModule();throw f}if(!c)return s;let u=`${a}@${R.shareScope||"default"}#${c}`;r.has(u)||r.set(u,s.get(c).catch(f=>{throw r.delete(u),f instanceof g||f?.code?f:new g(S.REMOTE_LOAD_FAILED,`failed to load module "${c}" from remote "${a}": ${String(f?.message??f)}`,{remote:a,module:c})}));let d;try{d=await r.get(u)}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\u663E\u5F0F\u964D\u7EA7\uFF0C\u9519\u8BEF\u5DF2\u900F\u51FA)`,f),w({remote:a,error:f}),await i.fallbackModule();throw f}if(m.afterLoadRemote?.({remote:a,module:c,module_ns:d}),d&&typeof d=="object"&&Object.keys(d).length===0){let f=new g(S.EMPTY_EXPORTS,`no exports: ${c} @ ${a}`,{remote:a,module:c});w({remote:a,error:f}),console.error(`[fulgurjs:MFU-009] ${f.message}`)}return d}function W(e){let i=n.get(e);if(!i)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${e}"`,{remote:e});return x(i)}async function B(e,i={}){let{remote:a}=N(e),c=n.get(a);if(!c)throw new g(S.REMOTE_UNKNOWN,`unknown remote "${a}"`,{remote:a});let R=i.mode??"preload",s=(u,d)=>{if(typeof document>"u"||document.querySelector(`link[href="${u}"]`))return;let f=document.createElement("link");f.rel=d==="style"?"stylesheet":"modulepreload",f.href=u,R==="prefetch"&&(f.fetchPriority="low"),document.head.appendChild(f)};try{if(c.manifestUrl){let u=await fetch(c.manifestUrl,{cache:"no-cache"});if(u.ok){let d=await u.json();s(c.entry,"modulepreload");let f=d.exposes??{};for(let _ of Object.keys(f)){let $=f[_];$?.file&&s(new URL($.file,c.entry).href,"modulepreload");for(let p of $?.css??[])s(new URL(p,c.entry).href,"style")}return}}s(c.entry,"modulepreload")}catch(u){w({remote:a,error:new g(S.PRELOAD_FAILED,String(u?.message??u),{remote:a})})}}return typeof window>"u"||(window.__FULGURJS_SCOPE__=t,window.__FULGURJS_INFO__={get remotes(){let e={};for(let[i,a]of n)e[i]={...a.debug,entry:a.entry};return e},errors:[]}),{shareScopeMap:t,initSharing:F,registerShare:V,registerRemotes:I,registerRemote:D,registerPlugins:H,loadShare:K,loadRemote:J,getContainer:W,preloadRemote:B,parseSpec:N}}var C=globalThis,b=C.__FULGURJS_RUNTIME__??ce();C.__FULGURJS_RUNTIME__=b;try{Object.freeze(b)}catch{}var he=U;function ye(){return b}var Ee=b.initSharing,Re=b.registerShare,Se=b.registerRemotes,we=b.registerRemote,be=b.registerPlugins,_e=b.loadShare,$e=b.loadRemote,Me=b.getContainer,ve=b.preloadRemote,je=b.shareScopeMap;function Te(t){if(t&&typeof t=="object"&&"default"in t){let n=t.default;return n!==void 0?n:t}return t}var Oe=b;export{Oe as default,Me as getContainer,ye as getRuntime,Ee as initSharing,$e as loadRemote,_e as loadShare,ve as preloadRemote,be as registerPlugins,we as registerRemote,Se as registerRemotes,Re as registerShare,b as runtime,je as shareScopeMap,Te as unwrapDefault,he as version};
package/dist/vue.cjs CHANGED
@@ -224,12 +224,12 @@ function testComparator(v, versionStr, c) {
224
224
  }
225
225
 
226
226
  // src/runtime/errors.ts
227
- var FulgurjsError = class extends Error {
227
+ var FgError = class extends Error {
228
228
  code;
229
229
  details;
230
230
  constructor(code, message, details) {
231
231
  super(`[fulgurjs:${code}] ${message}`);
232
- this.name = "FulgurjsError";
232
+ this.name = "FgError";
233
233
  this.code = code;
234
234
  this.details = details;
235
235
  }
@@ -339,7 +339,7 @@ function createRuntime() {
339
339
  const entry0 = byName[pick];
340
340
  const msg = `singleton skew "${shareKey}": req "${req ?? "any"}" use ${pick} from ${entry0.from}`;
341
341
  if (opts.strictVersion) {
342
- const err = new FulgurjsError(ErrorCodes.SHARE_STRICT_VERSION, msg, {
342
+ const err = new FgError(ErrorCodes.SHARE_STRICT_VERSION, msg, {
343
343
  shareKey,
344
344
  requiredVersion: req
345
345
  });
@@ -352,7 +352,7 @@ function createRuntime() {
352
352
  pick = [...satisfying].sort(compareVersions).pop();
353
353
  if (!pick) {
354
354
  if (opts.strictVersion) {
355
- const err2 = new FulgurjsError(
355
+ const err2 = new FgError(
356
356
  ErrorCodes.SHARE_STRICT_VERSION,
357
357
  `no satisfying version for "${shareKey}" (required "${req}") in share scope "${scopeName}"`
358
358
  );
@@ -360,7 +360,7 @@ function createRuntime() {
360
360
  throw err2;
361
361
  }
362
362
  if (opts.fallback) return opts.fallback();
363
- const err = new FulgurjsError(
363
+ const err = new FgError(
364
364
  ErrorCodes.SHARE_NOT_AVAILABLE,
365
365
  `shared "${shareKey}" (${req ?? "any"}) unavailable in scope "${scopeName}" (no local fallback)`,
366
366
  { shareKey, requiredVersion: req }
@@ -429,7 +429,7 @@ function createRuntime() {
429
429
  if (remote.container) {
430
430
  const prevScope = containerInitScopes.get(remote.container);
431
431
  if (prevScope && prevScope !== scopeKey) {
432
- throw new FulgurjsError(
432
+ throw new FgError(
433
433
  ErrorCodes.CONTAINER_REINIT_CONFLICT,
434
434
  `container "${remote.name}" already initialized with share scope "${prevScope}", cannot re-init with "${scopeKey}"`
435
435
  );
@@ -439,7 +439,7 @@ function createRuntime() {
439
439
  if (remote.containerPromise) return remote.containerPromise;
440
440
  const b = remote.breakerState;
441
441
  if (b.openUntil > Date.now()) {
442
- const err = new FulgurjsError(
442
+ const err = new FgError(
443
443
  ErrorCodes.REMOTE_LOAD_FAILED,
444
444
  `circuit breaker open for remote "${remote.name}" until ${new Date(b.openUntil).toISOString()}`,
445
445
  { remote: remote.name }
@@ -500,7 +500,7 @@ function createRuntime() {
500
500
  hints.push(`1. is the remote deployed and reachable? try opening ${remote.entry} in the browser \u2014 it must return JS`);
501
501
  hints.push(`2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)`);
502
502
  }
503
- throw new FulgurjsError(
503
+ throw new FgError(
504
504
  ErrorCodes.REMOTE_LOAD_FAILED,
505
505
  `failed to load remote "${remote.name}" from ${remote.entry}: ${String(lastErr?.message ?? lastErr)}
506
506
  ` + hints.join("\n"),
@@ -510,7 +510,7 @@ function createRuntime() {
510
510
  validateContainerInterface(container, remote);
511
511
  const prevScope = containerInitScopes.get(container);
512
512
  if (prevScope && prevScope !== scopeKey) {
513
- throw new FulgurjsError(
513
+ throw new FgError(
514
514
  ErrorCodes.CONTAINER_REINIT_CONFLICT,
515
515
  `container "${remote.name}" already initialized with share scope "${prevScope}", cannot re-init with "${scopeKey}"`
516
516
  );
@@ -538,7 +538,7 @@ function createRuntime() {
538
538
  b.openUntil = Date.now() + BREAKER_RESET_MS;
539
539
  b.fails = 0;
540
540
  }
541
- if (err instanceof FulgurjsError) {
541
+ if (err instanceof FgError) {
542
542
  emitError({ remote: remote.name, error: err });
543
543
  throw err;
544
544
  }
@@ -546,7 +546,7 @@ function createRuntime() {
546
546
  emitError({ remote: remote.name, error: err });
547
547
  throw err;
548
548
  }
549
- const wrapped = new FulgurjsError(ErrorCodes.REMOTE_LOAD_FAILED, String(err?.message ?? err), {
549
+ const wrapped = new FgError(ErrorCodes.REMOTE_LOAD_FAILED, String(err?.message ?? err), {
550
550
  remote: remote.name
551
551
  });
552
552
  emitError({ remote: remote.name, error: wrapped });
@@ -567,7 +567,7 @@ function createRuntime() {
567
567
  hooks.beforeLoadRemote?.({ remote: name, module: module2 });
568
568
  const remote = remotes.get(name);
569
569
  if (!remote) {
570
- throw new FulgurjsError(
570
+ throw new FgError(
571
571
  ErrorCodes.REMOTE_UNKNOWN,
572
572
  `unknown remote "${name}". Register it via federation({ remotes }) or registerRemote().`,
573
573
  { remote: name }
@@ -591,8 +591,8 @@ function createRuntime() {
591
591
  cacheKey,
592
592
  container.get(module2).catch((err) => {
593
593
  loadedModules.delete(cacheKey);
594
- if (err instanceof FulgurjsError || err?.code) throw err;
595
- throw new FulgurjsError(
594
+ if (err instanceof FgError || err?.code) throw err;
595
+ throw new FgError(
596
596
  ErrorCodes.REMOTE_LOAD_FAILED,
597
597
  `failed to load module "${module2}" from remote "${name}": ${String(err?.message ?? err)}`,
598
598
  { remote: name, module: module2 }
@@ -613,7 +613,7 @@ function createRuntime() {
613
613
  }
614
614
  hooks.afterLoadRemote?.({ remote: name, module: module2, module_ns: ns });
615
615
  if (ns && typeof ns === "object" && Object.keys(ns).length === 0) {
616
- const err = new FulgurjsError(
616
+ const err = new FgError(
617
617
  ErrorCodes.EMPTY_EXPORTS,
618
618
  `no exports: ${module2} @ ${name}`,
619
619
  { remote: name, module: module2 }
@@ -626,7 +626,7 @@ function createRuntime() {
626
626
  function getContainer2(name) {
627
627
  const remote = remotes.get(name);
628
628
  if (!remote) {
629
- throw new FulgurjsError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
629
+ throw new FgError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
630
630
  }
631
631
  return acquireContainer(remote);
632
632
  }
@@ -634,7 +634,7 @@ function createRuntime() {
634
634
  const { remote: name } = parseSpec(spec);
635
635
  const remote = remotes.get(name);
636
636
  if (!remote) {
637
- throw new FulgurjsError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
637
+ throw new FgError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
638
638
  }
639
639
  const mode = opts.mode ?? "preload";
640
640
  const inject = (href, as) => {
@@ -668,7 +668,7 @@ function createRuntime() {
668
668
  } catch (err) {
669
669
  emitError({
670
670
  remote: name,
671
- error: new FulgurjsError(ErrorCodes.PRELOAD_FAILED, String(err?.message ?? err), {
671
+ error: new FgError(ErrorCodes.PRELOAD_FAILED, String(err?.message ?? err), {
672
672
  remote: name
673
673
  })
674
674
  });
package/dist/vue.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  ErrorCodes,
3
- FulgurjsError
4
- } from "./chunk-CK42RK2O.js";
5
- import "./chunk-B5ZMYRN5.js";
3
+ FgError
4
+ } from "./chunk-3VBYOVH4.js";
5
+ import "./chunk-5GZKZWP2.js";
6
6
 
7
7
  // src/vue.ts
8
8
  import { defineAsyncComponent, defineComponent, h } from "vue";
@@ -287,7 +287,7 @@ function createRuntime() {
287
287
  const entry0 = byName[pick];
288
288
  const msg = `singleton skew "${shareKey}": req "${req ?? "any"}" use ${pick} from ${entry0.from}`;
289
289
  if (opts.strictVersion) {
290
- const err = new FulgurjsError(ErrorCodes.SHARE_STRICT_VERSION, msg, {
290
+ const err = new FgError(ErrorCodes.SHARE_STRICT_VERSION, msg, {
291
291
  shareKey,
292
292
  requiredVersion: req
293
293
  });
@@ -300,7 +300,7 @@ function createRuntime() {
300
300
  pick = [...satisfying].sort(compareVersions).pop();
301
301
  if (!pick) {
302
302
  if (opts.strictVersion) {
303
- const err2 = new FulgurjsError(
303
+ const err2 = new FgError(
304
304
  ErrorCodes.SHARE_STRICT_VERSION,
305
305
  `no satisfying version for "${shareKey}" (required "${req}") in share scope "${scopeName}"`
306
306
  );
@@ -308,7 +308,7 @@ function createRuntime() {
308
308
  throw err2;
309
309
  }
310
310
  if (opts.fallback) return opts.fallback();
311
- const err = new FulgurjsError(
311
+ const err = new FgError(
312
312
  ErrorCodes.SHARE_NOT_AVAILABLE,
313
313
  `shared "${shareKey}" (${req ?? "any"}) unavailable in scope "${scopeName}" (no local fallback)`,
314
314
  { shareKey, requiredVersion: req }
@@ -377,7 +377,7 @@ function createRuntime() {
377
377
  if (remote.container) {
378
378
  const prevScope = containerInitScopes.get(remote.container);
379
379
  if (prevScope && prevScope !== scopeKey) {
380
- throw new FulgurjsError(
380
+ throw new FgError(
381
381
  ErrorCodes.CONTAINER_REINIT_CONFLICT,
382
382
  `container "${remote.name}" already initialized with share scope "${prevScope}", cannot re-init with "${scopeKey}"`
383
383
  );
@@ -387,7 +387,7 @@ function createRuntime() {
387
387
  if (remote.containerPromise) return remote.containerPromise;
388
388
  const b = remote.breakerState;
389
389
  if (b.openUntil > Date.now()) {
390
- const err = new FulgurjsError(
390
+ const err = new FgError(
391
391
  ErrorCodes.REMOTE_LOAD_FAILED,
392
392
  `circuit breaker open for remote "${remote.name}" until ${new Date(b.openUntil).toISOString()}`,
393
393
  { remote: remote.name }
@@ -448,7 +448,7 @@ function createRuntime() {
448
448
  hints.push(`1. is the remote deployed and reachable? try opening ${remote.entry} in the browser \u2014 it must return JS`);
449
449
  hints.push(`2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)`);
450
450
  }
451
- throw new FulgurjsError(
451
+ throw new FgError(
452
452
  ErrorCodes.REMOTE_LOAD_FAILED,
453
453
  `failed to load remote "${remote.name}" from ${remote.entry}: ${String(lastErr?.message ?? lastErr)}
454
454
  ` + hints.join("\n"),
@@ -458,7 +458,7 @@ function createRuntime() {
458
458
  validateContainerInterface(container, remote);
459
459
  const prevScope = containerInitScopes.get(container);
460
460
  if (prevScope && prevScope !== scopeKey) {
461
- throw new FulgurjsError(
461
+ throw new FgError(
462
462
  ErrorCodes.CONTAINER_REINIT_CONFLICT,
463
463
  `container "${remote.name}" already initialized with share scope "${prevScope}", cannot re-init with "${scopeKey}"`
464
464
  );
@@ -486,7 +486,7 @@ function createRuntime() {
486
486
  b.openUntil = Date.now() + BREAKER_RESET_MS;
487
487
  b.fails = 0;
488
488
  }
489
- if (err instanceof FulgurjsError) {
489
+ if (err instanceof FgError) {
490
490
  emitError({ remote: remote.name, error: err });
491
491
  throw err;
492
492
  }
@@ -494,7 +494,7 @@ function createRuntime() {
494
494
  emitError({ remote: remote.name, error: err });
495
495
  throw err;
496
496
  }
497
- const wrapped = new FulgurjsError(ErrorCodes.REMOTE_LOAD_FAILED, String(err?.message ?? err), {
497
+ const wrapped = new FgError(ErrorCodes.REMOTE_LOAD_FAILED, String(err?.message ?? err), {
498
498
  remote: remote.name
499
499
  });
500
500
  emitError({ remote: remote.name, error: wrapped });
@@ -515,7 +515,7 @@ function createRuntime() {
515
515
  hooks.beforeLoadRemote?.({ remote: name, module });
516
516
  const remote = remotes.get(name);
517
517
  if (!remote) {
518
- throw new FulgurjsError(
518
+ throw new FgError(
519
519
  ErrorCodes.REMOTE_UNKNOWN,
520
520
  `unknown remote "${name}". Register it via federation({ remotes }) or registerRemote().`,
521
521
  { remote: name }
@@ -539,8 +539,8 @@ function createRuntime() {
539
539
  cacheKey,
540
540
  container.get(module).catch((err) => {
541
541
  loadedModules.delete(cacheKey);
542
- if (err instanceof FulgurjsError || err?.code) throw err;
543
- throw new FulgurjsError(
542
+ if (err instanceof FgError || err?.code) throw err;
543
+ throw new FgError(
544
544
  ErrorCodes.REMOTE_LOAD_FAILED,
545
545
  `failed to load module "${module}" from remote "${name}": ${String(err?.message ?? err)}`,
546
546
  { remote: name, module }
@@ -561,7 +561,7 @@ function createRuntime() {
561
561
  }
562
562
  hooks.afterLoadRemote?.({ remote: name, module, module_ns: ns });
563
563
  if (ns && typeof ns === "object" && Object.keys(ns).length === 0) {
564
- const err = new FulgurjsError(
564
+ const err = new FgError(
565
565
  ErrorCodes.EMPTY_EXPORTS,
566
566
  `no exports: ${module} @ ${name}`,
567
567
  { remote: name, module }
@@ -574,7 +574,7 @@ function createRuntime() {
574
574
  function getContainer2(name) {
575
575
  const remote = remotes.get(name);
576
576
  if (!remote) {
577
- throw new FulgurjsError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
577
+ throw new FgError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
578
578
  }
579
579
  return acquireContainer(remote);
580
580
  }
@@ -582,7 +582,7 @@ function createRuntime() {
582
582
  const { remote: name } = parseSpec(spec);
583
583
  const remote = remotes.get(name);
584
584
  if (!remote) {
585
- throw new FulgurjsError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
585
+ throw new FgError(ErrorCodes.REMOTE_UNKNOWN, `unknown remote "${name}"`, { remote: name });
586
586
  }
587
587
  const mode = opts.mode ?? "preload";
588
588
  const inject = (href, as) => {
@@ -616,7 +616,7 @@ function createRuntime() {
616
616
  } catch (err) {
617
617
  emitError({
618
618
  remote: name,
619
- error: new FulgurjsError(ErrorCodes.PRELOAD_FAILED, String(err?.message ?? err), {
619
+ error: new FgError(ErrorCodes.PRELOAD_FAILED, String(err?.message ?? err), {
620
620
  remote: name
621
621
  })
622
622
  });
@@ -75,27 +75,27 @@ const FederatedBusinessForm = remoteComponent('demo-host/FormRouterPage')
75
75
  `(globalThis as any).__FULGURJS_RUNTIME__` 直取全局单例仅剩"独立访问远程页 vs 联邦加载"的
76
76
  realm 检测等特殊场景,常规集成无需使用。
77
77
 
78
- ## 三C、跨应用传值:FulgurjsAppContext
78
+ ## 三C、跨应用传值:AppContext
79
79
 
80
80
  原 qiankun `props` / `globalState` / `window.*` 裸口子,统一收编为 context 一等公民通道(对标乾坤 props,带类型与错误契约):
81
81
 
82
82
  ```ts
83
83
  // 宿主桥(admin/src/fulgurjs/host/bridge.ts)——登录完成后一次性提供
84
- import { provideFulgurjsAppContext } from '@fulgurjs/federation/context'
85
- provideFulgurjsAppContext({
84
+ import { provideAppContext } from '@fulgurjs/federation/context'
85
+ provideAppContext({
86
86
  user, getToken, store, hostApp, locale, // 只传有真实消费的键(token 一律 getToken() 拉取)
87
87
  events: { main: mainEvents }, // 方法池:宿主提供 main.*,子应用反向注册 bpm.* / lowcode.*
88
88
  // 项目扩展位:自定义键按需自行提供(如 baseUrl)
89
89
  })
90
90
 
91
91
  // 远程启动引导(xxx/src/fulgurjs/exposes/federatedBoot.ts)——显式校验消费
92
- import { requireFulgurjsAppContext } from '@fulgurjs/federation/context'
93
- const { store, user, hostApp } = requireFulgurjsAppContext('store', 'user', 'hostApp')
92
+ import { requireAppContext } from '@fulgurjs/federation/context'
93
+ const { store, user, hostApp } = requireAppContext('store', 'user', 'hostApp')
94
94
  // 缺键 → [fulgurjs:CC-001](三段式,指向宿主桥);独立直开远程页 → [fulgurjs:CC-002]
95
95
 
96
96
  // 页面读点(替代 window.mainAppProps?.xxx)
97
- import { getFulgurjsAppContext } from '@fulgurjs/federation/context'
98
- const dict = getFulgurjsAppContext().events?.main?.getDictItems?.('sex')
97
+ import { getAppContext } from '@fulgurjs/federation/context'
98
+ const dict = getAppContext().events?.main?.getDictItems?.('sex')
99
99
  ```
100
100
 
101
101
  要点:
@@ -111,7 +111,7 @@ const dict = getFulgurjsAppContext().events?.main?.getDictItems?.('sex')
111
111
 
112
112
  | 资源 | 清理方式 |
113
113
  |---|---|
114
- | `context.events.bpm.xxx = fn` 反向注册 | `onUnmounted(() => { delete getFulgurjsAppContext().events?.bpm?.xxx })` |
114
+ | `context.events.bpm.xxx = fn` 反向注册 | `onUnmounted(() => { delete getAppContext().events?.bpm?.xxx })` |
115
115
  | `window.addEventListener(...)` | 记住函数引用,`onUnmounted` 里 `removeEventListener` |
116
116
  | `setInterval` / `setTimeout` | `onUnmounted` 里 `clearInterval` / `clearTimeout` |
117
117
  | `window.__FULGURJS_INFO__.errors.push(...)` 之外的自挂全局 | 同理显式删除 |
@@ -119,9 +119,9 @@ const dict = getFulgurjsAppContext().events?.main?.getDictItems?.('sex')
119
119
  ```ts
120
120
  import { onUnmounted } from 'vue'
121
121
  const onBpmEvent = (e: unknown) => { /* ... */ }
122
- getFulgurjsAppContext().events!.bpm!.formEvent = onBpmEvent
122
+ getAppContext().events!.bpm!.formEvent = onBpmEvent
123
123
  onUnmounted(() => {
124
- const events = getFulgurjsAppContext().events
124
+ const events = getAppContext().events
125
125
  if (events?.bpm?.formEvent === onBpmEvent) delete events.bpm.formEvent
126
126
  })
127
127
  ```
@@ -3,9 +3,9 @@
3
3
  * 用法:npx fulgurjs init --config examples/fulgurjs.config.example.ts
4
4
  * 完整字段说明见 `fulgurjs init` 生成的起步模板(fulgurjs init --template fulgurjs.config.ts)。
5
5
  */
6
- import { defineFulgurjsConfig } from '@fulgurjs/federation/config'
6
+ import { defineRepoConfig } from '@fulgurjs/federation/config'
7
7
 
8
- export default defineFulgurjsConfig({
8
+ export default defineRepoConfig({
9
9
  root: process.cwd(),
10
10
  apps: [
11
11
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fulgurjs/federation",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "Vite Module Federation with full Webpack MF parity. Dev & production, no compromise.",
6
6
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  "docs/vite-upstream-issue-irregexp.md"
70
70
  ],
71
71
  "scripts": {
72
- "build": "cp ../../README.md README.md && mkdir -p docs && cp ../../docs/\u8fc1\u79fb\u6307\u5357.md ../../docs/webpack-mf-\u5bf9\u7167\u4e0e\u7f3a\u53e3.md ../../docs/\u6c99\u7bb1\u8fb9\u754c\u5ba1\u8ba1.md ../../docs/P5-vite7-8\u517c\u5bb9\u77e9\u9635.md ../../docs/vite-upstream-issue-irregexp.md docs/ && cp ../../CHANGELOG.md CHANGELOG.md && cp ../../DESIGN.md DESIGN.md && rm -rf examples && cp -r ../../examples examples && esbuild src/runtime/index.ts --bundle --format=esm --target=es2022 --minify --outfile=dist/runtime.js && node scripts/gen-runtime.mjs && tsup src/index.ts src/pages.ts src/config.ts src/vue.ts src/context.ts --format esm,cjs --dts --external vite --target node18 --clean && esbuild src/cli.ts --bundle --format=esm --target=node18 --platform=node --outfile=dist/cli.js && esbuild src/runtime/index.ts --bundle --format=esm --target=es2022 --minify --outfile=dist/runtime.js && node scripts/check-gzip.mjs",
72
+ "build": "cp ../../README.md README.md && mkdir -p docs && cp ../../docs/\u8fc1\u79fb\u6307\u5357.md ../../docs/webpack-mf-\u5bf9\u7167\u4e0e\u7f3a\u53e3.md ../../docs/\u6c99\u7bb1\u8fb9\u754c\u5ba1\u8ba1.md ../../docs/P5-vite7-8\u517c\u5bb9\u77e9\u9635.md ../../docs/vite-upstream-issue-irregexp.md docs/ && cp ../../CHANGELOG.md CHANGELOG.md && cp ../../DESIGN.md DESIGN.md && rm -rf examples && cp -r ../../examples examples && esbuild src/runtime/index.ts --bundle --format=esm --target=es2022 --minify --outfile=dist/runtime.js && node scripts/gen-runtime.mjs && tsup src/index.ts src/pages.ts src/config.ts src/vue.ts src/context.ts --format esm,cjs --dts --external vite --target node18 --clean && esbuild src/cli.ts --bundle --format=esm --target=node18 --platform=node --outfile=dist/cli.js && esbuild src/runtime/index.ts --bundle --format=esm --target=es2022 --minify --outfile=dist/runtime.js && node scripts/check-gzip.mjs && node scripts/check-manual-codes.mjs",
73
73
  "dev": "tsup --watch",
74
74
  "test": "vitest run",
75
75
  "typecheck": "tsc --noEmit",