rari 0.15.10 → 0.15.12
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/og.d.mts +1 -0
- package/dist/og.mjs +1 -1
- package/dist/proxy/runtime-executor.mjs +1 -1
- package/dist/vite.mjs +31 -31
- package/package.json +11 -11
package/dist/og.d.mts
CHANGED
package/dist/og.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as e,p as t}from"./type-guards-CTkEL8zw.mjs";const n=Symbol.for(`react.memo`),r=Symbol.for(`react.forward_ref`);function i(e){return t(e)&&typeof e.toString==`function`}function a(e){return t(e)&&`then`in e}function o(e){let t=e;for(;i(t);)if(t.$$typeof===n&&t.type!==void 0)t=t.type;else if(t.$$typeof===r&&t.render!==void 0)t=t.render;else break;return typeof t==`function`||i(t)?t:null}var s=class{element;options;constructor(e,t={}){this.element=e,this.options={width:t.width!=null&&t.width!==0?t.width:1200,height:t.height!=null&&t.height!==0?t.height:630}}toJSON(){return{type:`ImageResponse`,element:this.serializeElement(this.element),options:this.options}}resolveAndInvoke(e,t){let n=o(e);if(n==null||typeof n!=`function`)return null;try{let e=n(t);return e!==null&&a(e)?(console.warn(`[ImageResponse] async/server component "${n.name||n.toString()}" is not supported; skipping`),null):this.serializeElement(e)}catch(e){return console.error(`[ImageResponse] failed to render component "${n.name||n.toString()}":`,e),null}}serializeElement(n){if(typeof n==`string`||typeof n==`number`)return{type:`text`,value:String(n)};if(!t(n)||!e(n))return null;let{type:r,props:a={}}=n,s=o(r);if(typeof s==`function`||s!=null&&i(s))return this.resolveAndInvoke(r,a);let c=this.serializeChildren(a.children);return{type:`element`,elementType:r,props:this.serializeProps(a),children:c}}serializeChildren(e){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>{let t=this.serializeElement(e);return t?[t]:[]});let t=this.serializeElement(e);return t?[t]:[]}serializeProps(e){let t={};for(let[n,r]of Object.entries(e))n
|
|
1
|
+
import{f as e,p as t}from"./type-guards-CTkEL8zw.mjs";const n=Symbol.for(`react.memo`),r=Symbol.for(`react.forward_ref`);function i(e){return t(e)&&typeof e.toString==`function`}function a(e){return t(e)&&`then`in e}function o(e){let t=e;for(;i(t);)if(t.$$typeof===n&&t.type!==void 0)t=t.type;else if(t.$$typeof===r&&t.render!==void 0)t=t.render;else break;return typeof t==`function`||i(t)?t:null}var s=class{element;options;constructor(e,t={}){this.element=e,this.options={width:t.width!=null&&t.width!==0?t.width:1200,height:t.height!=null&&t.height!==0?t.height:630}}toJSON(){return{type:`ImageResponse`,element:this.serializeElement(this.element),options:this.options}}resolveAndInvoke(e,t){let n=o(e);if(n==null||typeof n!=`function`)return null;try{let e=n(t);return e!==null&&a(e)?(console.warn(`[ImageResponse] async/server component "${n.name||n.toString()}" is not supported; skipping`),null):this.serializeElement(e)}catch(e){return console.error(`[ImageResponse] failed to render component "${n.name||n.toString()}":`,e),null}}serializeElement(n){if(typeof n==`string`||typeof n==`number`)return{type:`text`,value:String(n)};if(!t(n)||!e(n))return null;let{type:r,props:a={}}=n,s=o(r);if(typeof s==`function`||s!=null&&i(s))return this.resolveAndInvoke(r,a);let c=this.serializeChildren(a.children);return{type:`element`,elementType:r,props:this.serializeProps(a),children:c}}serializeChildren(e){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>{let t=this.serializeElement(e);return t?[t]:[]});let t=this.serializeElement(e);return t?[t]:[]}serializeProps(e){let t={};for(let[n,r]of Object.entries(e)){if(n===`children`)continue;let e=this.serializePropValue(r);e!==void 0&&(t[n]=e)}return t}serializePropValue(e,n=new Set){if(e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(n.has(e))return;n.add(e);try{return e.map(e=>this.serializePropValue(e,n)).filter(e=>e!==void 0)}finally{n.delete(e)}}if(t(e)){if(n.has(e))return;n.add(e);try{let t={};for(let[r,i]of Object.entries(e)){let e=this.serializePropValue(i,n);e!==void 0&&(t[r]=e)}return t}finally{n.delete(e)}}}};export{s as ImageResponse};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as e,u as t}from"../type-guards-CTkEL8zw.mjs";function n(e,t,n){if(Object.hasOwn(e,t)){let r=e[t];e[t]=Array.isArray(r)?[...r,n]:[r,n]}else e[t]=n}function r(e){if(!e)return[];if(typeof e.getSetCookie==`function`)return e.getSetCookie();let t=[];return e.forEach&&e.forEach((e,n)=>{n.toLowerCase()===`set-cookie`&&t.push(e)}),t}function i(e,t){let r=e.cookies;if(!(!r||typeof r.toSetCookieHeaders!=`function`))for(let e of r.toSetCookieHeaders())n(t,`set-cookie`,e)}function a(e){let t={},i={};e?.forEach&&e.forEach((e,r)=>{let a=r.toLowerCase();if(a!==`set-cookie`)if(a.startsWith(`x-rari-proxy-request-`)){let r=a.replace(`x-rari-proxy-request-`,``);n(t,r,e)}else a.startsWith(`x-rari-proxy-`)||n(i,a,e)});for(let t of r(e))n(i,`set-cookie`,t);return{requestHeaders:Object.keys(t).length>0?t:void 0,responseHeaders:Object.keys(i).length>0?i:void 0}}function o(e){let t={};e?.forEach&&e.forEach((e,r)=>{r.toLowerCase()!==`set-cookie`&&n(t,r.toLowerCase(),e)});for(let i of r(e))n(t,`set-cookie`,i);return t}function s(e){if(!e)return null;let t=e.headers?.get?.(`x-rari-proxy-rewrite`);return t!=null&&t!==``?{continue:!1,rewrite:t}:null}function c(e){if(e?.status==null)return null;let t=e.headers?.get?.(`location`);return t!=null&&t!==``&&e.status>=300&&e.status<400?{continue:!1,redirect:{destination:t,permanent:e.status===301||e.status===308}}:null}function l(e){let{requestHeaders:t,responseHeaders:n={}}=a(e.headers);return i(e,n),{continue:!0,requestHeaders:t,responseHeaders:Object.keys(n).length>0?n:void 0}}async function u(e){let t=o(e.headers);i(e,t);let n;try{e.text&&typeof e.text==`function`?n=await e.text():e.body!=null&&typeof e.body==`string`?n=e.body:e.body!=null&&console.warn(`[rari] Proxy: Response body is not extractable as text`)}catch(e){console.error(`[rari] Proxy: Failed to extract response body:`,e)}return{continue:!1,response:{status:e.status??200,headers:t,body:n}}}async function d(e){return e?s(e)||c(e)||(e.headers?.get?.(`x-rari-proxy-continue`)===`true`?l(e):e.status==null?{continue:!0}:u(e)):{continue:!0}}async function f(n,r){try{let i=await import(n);if(!e(i)||!t(i.proxy))return console.error(`[rari] Proxy: proxy function not found in module`),!1;let a=i.proxy,o=await import(r);if(!e(o)||!t(o.RariRequest))return console.error(`[rari] Proxy: RariRequest constructor not found`),!1;let s=o.RariRequest;return Reflect.set(globalThis,`~rariExecuteProxy`,async e=>{try{let t=new s(e.url,{method:e.method,headers:new Headers(e.headers)}),n=[],r=await a(t,{waitUntil:e=>{e.catch(()=>{}),n.push(e)}});return n.length>0&&Promise.allSettled(n).then(e=>{e.forEach((e,t)=>{e.status===`rejected`&&console.error(`[rari] Proxy: waitUntil promise ${t} failed:`,e.reason)})}),await d(r)}catch(e){return console.error(`[rari] Proxy: Proxy execution error:`,e),{continue:!0}}}),!0}catch(e){return console.error(`[rari] Proxy: Failed to initialize proxy executor:`,e),!1}}export{f as initializeProxyExecutor};
|
|
1
|
+
import{p as e,u as t}from"../type-guards-CTkEL8zw.mjs";function n(e,t,n){if(Object.hasOwn(e,t)){let r=e[t];e[t]=Array.isArray(r)?[...r,n]:[r,n]}else e[t]=n}function r(e){if(!e)return[];if(typeof e.getSetCookie==`function`)return e.getSetCookie();let t=[];return e.forEach&&e.forEach((e,n)=>{n.toLowerCase()===`set-cookie`&&t.push(e)}),t}function i(e,t){let r=e.cookies;if(!(!r||typeof r.toSetCookieHeaders!=`function`))for(let e of r.toSetCookieHeaders())n(t,`set-cookie`,e)}function a(e){let t={},i={};e?.forEach&&e.forEach((e,r)=>{let a=r.toLowerCase();if(a!==`set-cookie`){if(a.startsWith(`x-rari-proxy-request-`)){let r=a.replace(`x-rari-proxy-request-`,``);n(t,r,e)}else a.startsWith(`x-rari-proxy-`)||n(i,a,e)}});for(let t of r(e))n(i,`set-cookie`,t);return{requestHeaders:Object.keys(t).length>0?t:void 0,responseHeaders:Object.keys(i).length>0?i:void 0}}function o(e){let t={};e?.forEach&&e.forEach((e,r)=>{r.toLowerCase()!==`set-cookie`&&n(t,r.toLowerCase(),e)});for(let i of r(e))n(t,`set-cookie`,i);return t}function s(e){if(!e)return null;let t=e.headers?.get?.(`x-rari-proxy-rewrite`);return t!=null&&t!==``?{continue:!1,rewrite:t}:null}function c(e){if(e?.status==null)return null;let t=e.headers?.get?.(`location`);return t!=null&&t!==``&&e.status>=300&&e.status<400?{continue:!1,redirect:{destination:t,permanent:e.status===301||e.status===308}}:null}function l(e){let{requestHeaders:t,responseHeaders:n={}}=a(e.headers);return i(e,n),{continue:!0,requestHeaders:t,responseHeaders:Object.keys(n).length>0?n:void 0}}async function u(e){let t=o(e.headers);i(e,t);let n;try{e.text&&typeof e.text==`function`?n=await e.text():e.body!=null&&typeof e.body==`string`?n=e.body:e.body!=null&&console.warn(`[rari] Proxy: Response body is not extractable as text`)}catch(e){console.error(`[rari] Proxy: Failed to extract response body:`,e)}return{continue:!1,response:{status:e.status??200,headers:t,body:n}}}async function d(e){return e?s(e)||c(e)||(e.headers?.get?.(`x-rari-proxy-continue`)===`true`?l(e):e.status==null?{continue:!0}:u(e)):{continue:!0}}async function f(n,r){try{let i=await import(n);if(!e(i)||!t(i.proxy))return console.error(`[rari] Proxy: proxy function not found in module`),!1;let a=i.proxy,o=await import(r);if(!e(o)||!t(o.RariRequest))return console.error(`[rari] Proxy: RariRequest constructor not found`),!1;let s=o.RariRequest;return Reflect.set(globalThis,`~rariExecuteProxy`,async e=>{try{let t=new s(e.url,{method:e.method,headers:new Headers(e.headers)}),n=[],r=await a(t,{waitUntil:e=>{e.catch(()=>{}),n.push(e)}});return n.length>0&&Promise.allSettled(n).then(e=>{e.forEach((e,t)=>{e.status===`rejected`&&console.error(`[rari] Proxy: waitUntil promise ${t} failed:`,e.reason)})}),await d(r)}catch(e){return console.error(`[rari] Proxy: Proxy execution error:`,e),{continue:!0}}}),!0}catch(e){return console.error(`[rari] Proxy: Failed to initialize proxy executor:`,e),!1}}export{f as initializeProxyExecutor};
|
package/dist/vite.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./api-routes-ChRr3O5-.mjs";import{g as t,h as n,m as r,o as i,p as a,r as o,t as s,y as c}from"./type-guards-CTkEL8zw.mjs";import{i as l,n as u,o as d,r as f,t as p}from"./constants-DZuNx7IB.mjs";import{a as m,c as h,d as g,g as _,h as v,i as y,m as b,n as ee,o as te,p as ne,r as re,s as ie,t as x,u as ae}from"./regex-constants-Wm7xRA3u.mjs";import{a as oe,i as se,n as ce,o as S,r as le,t as C}from"./alias-resolver-Cigam7Y7.mjs";import{t as ue}from"./timer-Duul5JHq.mjs";import{t as w}from"./names-N6JRDeT1.mjs";import{builtinModules as T,createRequire as de}from"node:module";import{Buffer as fe}from"node:buffer";import{spawn as pe,spawnSync as
|
|
1
|
+
import{t as e}from"./api-routes-ChRr3O5-.mjs";import{g as t,h as n,m as r,o as i,p as a,r as o,t as s,y as c}from"./type-guards-CTkEL8zw.mjs";import{i as l,n as u,o as d,r as f,t as p}from"./constants-DZuNx7IB.mjs";import{a as m,c as h,d as g,g as _,h as v,i as y,m as b,n as ee,o as te,p as ne,r as re,s as ie,t as x,u as ae}from"./regex-constants-Wm7xRA3u.mjs";import{a as oe,i as se,n as ce,o as S,r as le,t as C}from"./alias-resolver-Cigam7Y7.mjs";import{t as ue}from"./timer-Duul5JHq.mjs";import{t as w}from"./names-N6JRDeT1.mjs";import{builtinModules as T,createRequire as de}from"node:module";import{Buffer as fe}from"node:buffer";import{spawn as pe,spawnSync as me}from"node:child_process";import E,{promises as D}from"node:fs";import O from"node:path";import k from"node:process";import{fileURLToPath as A,pathToFileURL as j}from"node:url";import he from"node:crypto";import{build as M}from"rolldown";function ge(e){return e.map(e=>e)}function _e(e){return e}function ve(e={}){let{root:t=k.cwd(),srcDir:n=`src`,proxyFileName:r=`proxy`,extensions:i=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.mjs`],verbose:a=!1}=e,o=null,s=e=>{a&&console.warn(`[rari] Proxy: ${e}`)};async function c(){for(let e of i){let n=`${r}${e}`,i=O.join(t,n);try{return await D.access(i),s(`Found proxy file: ${n}`),{filePath:i,exists:!0,relativePath:n}}catch{}}let e=O.join(t,n);try{await D.access(e);for(let t of i){let i=`${r}${t}`,a=O.join(e,i);try{return await D.access(a),s(`Found proxy file: ${O.join(n,i)}`),{filePath:a,exists:!0,relativePath:O.join(n,i)}}catch{}}}catch{}return null}return _e({name:`rari:proxy`,async buildStart(){o=await c(),s(o?`Proxy enabled: ${o.relativePath}`:`No proxy file found`)},configureServer(e){o&&(e.watcher.add(o.filePath),e.watcher.on(`change`,t=>{t===o?.filePath&&(s(`Proxy file changed, reloading...`),e.ws.send({type:`custom`,event:`rari:proxy-reload`}))}))},handleHotUpdate({file:e,server:t}){if(e===o?.filePath)return s(`Hot reloading proxy...`),t.ws.send({type:`custom`,event:`rari:proxy-reload`,data:{file:o.relativePath}}),[]}})}function N(e){if(e==null||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null}function P(){let{SERVER_PORT:e,PORT:t,RSC_PORT:n}=k.env;return N(e)??N(t)??N(n)??3e3}function ye(){return`http://localhost:${P()}`}const be=6e4;async function xe(e){let t=j(e).href,n=`
|
|
2
2
|
import { registerHooks } from "node:module";
|
|
3
3
|
registerHooks({
|
|
4
4
|
resolve(specifier, context, nextResolve) {
|
|
@@ -16,15 +16,15 @@ const result =
|
|
|
16
16
|
process.send(result, () => {
|
|
17
17
|
process.disconnect();
|
|
18
18
|
});
|
|
19
|
-
`;return new Promise((t,r)=>{let i=pe(
|
|
20
|
-
`);if(n!==0){r(Error(i||`generateStaticParams worker exited with code ${n}`));return}if(!c){r(Error(i||`generateStaticParams worker exited without an IPC result for ${e}`));return}t(l)})})}const I={PAGE:`page`,LAYOUT:`layout`,LOADING:`loading`,ERROR:`error`,NOT_FOUND:`not-found`,TEMPLATE:`template`,DEFAULT:`default`,ROUTE:`route`,OG_IMAGE:`opengraph-image`,TWITTER_IMAGE:`twitter-image`,ICON:`icon`,APPLE_ICON:`apple-icon`},xe={DYNAMIC:/^\[([^\]]+)\]$/,CATCH_ALL:/^\[\.\.\.([^\]]+)\]$/,OPTIONAL_CATCH_ALL:/^\[\[\.\.\.([^\]]+)\]\]$/},Se=[{pattern:xe.OPTIONAL_CATCH_ALL,type:`optional-catch-all`,format:e=>`[[...${e}]]`},{pattern:xe.CATCH_ALL,type:`catch-all`,format:e=>`[...${e}]`},{pattern:xe.DYNAMIC,type:`dynamic`,format:e=>`[${e}]`}],Ce=/^\([^/]+\)$/;function we(e){return Ce.test(e)}function Te(e){return e?e.replace(x,`/`).split(`/`).filter(Boolean).some(we):!1}function Ee(e){for(let t of Se){let n=e.match(t.pattern);if(n)return{type:t.type,param:n[1],format:t.format}}}function De(e){let t=Ee(e);return t?t.format(t.param):e}function Oe(e){let t=Ee(e);return t?{type:t.type,value:e,param:t.param}:{type:`static`,value:e}}const ke=/export\s+const\s+size\s*=\s*\{\s*width\s*:\s*(\d+)\s*,\s*height\s*:\s*(\d+)\s*[,}]/,Ae=/export\s+const\s+contentType\s*=\s*['"]([^'"]+)['"]/,je=[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`];var Me=class{appDir;extensions;verbose;constructor(e){this.appDir=k.resolve(e.appDir),this.extensions=[...e.extensions??[`.tsx`,`.jsx`,`.ts`,`.js`]],this.verbose=e.verbose??!1}async generateManifest(){this.verbose&&console.warn(`[rari] Router: Scanning app directory: ${this.appDir}`);let e=[],t=[],n=[],r=[],i=[],a=[],o=[],s=[];await this.scanDirectory(``,e,t,n,r,i,a,o,s);for(let o of[t,n,r,i,a,s])this.finalizeGroupEntries(e,o);return this.assertNoDuplicateRoutes(e),this.assertNoDuplicateRoutes(o),this.verbose&&(console.warn(`[rari] Router: Found ${e.length} routes`),console.warn(`[rari] Router: Found ${t.length} layouts`),console.warn(`[rari] Router: Found ${n.length} loading components`),console.warn(`[rari] Router: Found ${r.length} error boundaries`),console.warn(`[rari] Router: Found ${a.length} templates`),console.warn(`[rari] Router: Found ${o.length} API routes`),console.warn(`[rari] Router: Found ${s.length} OG images`)),{routes:this.sortRoutes(e),layouts:this.sortLayouts(t),loading:n,errors:r,notFound:i,templates:this.sortTemplates(a),apiRoutes:this.sortApiRoutes(o),ogImages:s,generated:new Date().toISOString()}}finalizeGroupEntries(e,t){for(let n=t.length-1;n>=0;n--){let r=t[n],i=k.dirname(r.filePath).replace(x,`/`);if(!Te(i))continue;let a=e.filter(e=>{let t=k.dirname(e.filePath).replace(x,`/`);return t===i||t.startsWith(`${i}/`)}).map(e=>e.path);if(a.length===0){t.splice(n,1);continue}let o=Array.from(new Set(a)).sort();r.path=o[0],o.length>1&&(r.additionalPaths=o.slice(1))}}assertNoDuplicateRoutes(e){let t=new Map;for(let n of e){let e=t.get(n.path);if(e!=null&&e!==``)throw Error(`[rari] Route conflict: path '${n.path}' is defined by both '${e}' and '${n.filePath}'.`);t.set(n.path,n.filePath)}}async scanDirectory(e,t,n,r,i,a,o,s,c){let l=k.join(this.appDir,e),u;try{u=await O.readdir(l)}catch{return}let d=[],f=[];for(let e of u){let t=k.join(l,e),n=await O.stat(t);n.isDirectory()?this.shouldScanDirectory(e)&&f.push(e):n.isFile()&&d.push(e)}await this.processSpecialFiles(e,d,t,n,r,i,a,o,s,c);for(let l of f){let u=e?k.join(e,l):l;await this.scanDirectory(u,t,n,r,i,a,o,s,c)}}async processSpecialFiles(e,t,n,r,i,a,o,s,c,l){let u=this.pathToRoute(e),d=this.findFile(t,I.PAGE);if(d!=null&&d!==``){let t=this.parseRouteSegments(e),r=this.extractParams(t);n.push({path:u,filePath:k.join(e,d).replace(x,`/`),segments:t,params:r,isDynamic:r.length>0})}let f=this.findFile(t,I.LAYOUT);if(f!=null&&f!==``){let t=this.getParentPath(e);r.push({path:u,filePath:k.join(e,f).replace(x,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let p=this.findFile(t,I.LOADING);p!=null&&p!==``&&i.push({path:u,filePath:k.join(e,p).replace(x,`/`)});let m=this.findFile(t,I.ERROR);m!=null&&m!==``&&a.push({path:u,filePath:k.join(e,m).replace(x,`/`)});let h=this.findFile(t,I.NOT_FOUND);h!=null&&h!==``&&o.push({path:u,filePath:k.join(e,h).replace(x,`/`)});let g=this.findFile(t,I.TEMPLATE);if(g!=null&&g!==``){let t=this.getParentPath(e);s.push({path:u,filePath:k.join(e,g).replace(x,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let _=this.findFile(t,I.OG_IMAGE);if(_!=null&&_!==``){let t=k.join(e,_).replace(x,`/`),n=k.join(this.appDir,t),r,i,a;try{let e=await O.readFile(n,`utf-8`),t=ke.exec(e);t&&(r=Number.parseInt(t[1],10),i=Number.parseInt(t[2],10));let o=Ae.exec(e);o&&(a=o[1])}catch{}l.push({path:u,filePath:t,width:r,height:i,contentType:a})}let v=this.findFile(t,I.ROUTE);if(v!=null&&v!==``){let t=await this.processApiRouteFile(e,v);c.push(t)}}findFile(e,t){for(let n of this.extensions){let r=`${t}${n}`;if(e.includes(r))return r}}pathToRoute(e){return e?`/${e.replace(x,`/`).split(`/`).filter(Boolean).filter(e=>!we(e)).map(De).join(`/`)}`:`/`}parseRouteSegments(e){return e?e.split(g).filter(Boolean).filter(e=>!we(e)).map(Oe):[]}extractParams(e){return e.filter(e=>e.param!==void 0).map(e=>e.param)}getParentPath(e){if(!e)return null;let t=e.split(g).filter(Boolean);return t.length===0?null:t.slice(0,-1).join(`/`)}shouldScanDirectory(e){return![`node_modules`,`.git`,`dist`,`build`,`__tests__`,`test`,`tests`,`coverage`].includes(e)&&!e.startsWith(`_`)&&!e.startsWith(`.`)}sortRoutes(e){return e.sort((e,t)=>{let n=e=>{if(!e.isDynamic)return 0;let t=e.segments.some(e=>e.type===`catch-all`);return e.segments.some(e=>e.type===`optional-catch-all`)?3:t?2:1},r=n(e),i=n(t);if(r!==i)return r-i;let a=e.path.split(`/`).length,o=t.path.split(`/`).length;return a===o?e.path.localeCompare(t.path):o-a})}sortApiRoutes(e){return e.sort((e,t)=>{if(!e.isDynamic&&t.isDynamic)return-1;if(e.isDynamic&&!t.isDynamic)return 1;let n=e.path.split(`/`).length,r=t.path.split(`/`).length;return n===r?e.path.localeCompare(t.path):n-r})}sortLayouts(e){return e.sort((e,t)=>e.path===`/`&&t.path!==`/`?-1:t.path===`/`&&e.path!==`/`?1:e.path.split(`/`).length-t.path.split(`/`).length)}sortTemplates(e){return e.sort((e,t)=>e.path===`/`&&t.path!==`/`?-1:t.path===`/`&&e.path!==`/`?1:e.path.split(`/`).length-t.path.split(`/`).length)}async detectHttpMethods(e){let t=k.join(this.appDir,e),n=await O.readFile(t,`utf-8`),r=[];for(let e of je){let t=RegExp(`export\\s+(?:async\\s+)?function\\s+${e}\\s*\\(`),i=RegExp(`export\\s+(?:async\\s+)?(?:const|let|var)\\s+${e}\\s*=`);(t.test(n)||i.test(n))&&r.push(e)}return r}async processApiRouteFile(e,t){let n=k.join(e,t).replace(x,`/`),r=this.pathToRoute(e),i=this.parseRouteSegments(e),a=this.extractParams(i),o=await this.detectHttpMethods(n);return{path:r,filePath:n,segments:i,params:a,isDynamic:a.length>0,methods:o}}};async function Ne(e,t={}){return new Me({appDir:e,...t}).generateManifest()}const Pe=/export\s+const\s+metadata\s*(?::\s*\w+\s*)?=\s*(\{[\s\S]*?\n\})/,Fe=/title\s*:\s*['"]([^'"]+)['"]/,Ie=/description\s*:\s*['"]([^'"]+)['"]/,Le=/keywords\s*:\s*\[([\s\S]*?)\]/,Re={appDir:`src/app`,extensions:[`.tsx`,`.jsx`,`.ts`,`.js`],outDir:`dist`};function ze(e){switch(k.basename(e).replace(v,``)){case`page`:return`page`;case`layout`:return`layout`;case`template`:return`template`;case`loading`:return`loading`;case`error`:return`error`;case`not-found`:return`not-found`;case`route`:return`route`;default:return null}}function Be(e){return/^\([^/]+\)$/.test(e)}function Ve(e){if(!e||e===`/`)return`/`;let t=e.replace(x,`/`).split(`/`).filter(e=>!!e&&!Be(e));return t.length>0?`/${t.join(`/`)}`:`/`}function He(e,t){let n=k.relative(t,k.dirname(e));return!n||n===`.`?`/`:Ve(`/${n.replace(x,`/`).split(`/`).filter(Boolean).join(`/`)}`)}function Ue(e,t,n){if(t===`page`)return[e];let r=`${e}${e===`/`?``:`/`}`,i=n.filter(t=>t===e||t.startsWith(r));return i.length>0?i:[e]}function We(e){try{let t=Pe.exec(e);if(!t)return null;let n=t[1],r={},i=Fe.exec(n);i&&(r.title=i[1]);let a=Ie.exec(n);a&&(r.description=a[1]);let o=Le.exec(n);o&&(r.keywords=o[1].split(`,`).map(e=>e.trim().replace(ne,``)).filter(Boolean));for(let e of[`author`,`viewport`,`themeColor`,`robots`,`openGraph`,`twitter`]){let t=RegExp(`${e}\\s*:\\s*['"]([^'"]+)['"]`,`m`),i=n.match(t);i&&(r[e]=i[1])}return Object.keys(r).length>0?r:null}catch(e){return console.error(`[rari] Router: Failed to extract metadata:`,e),null}}function Ge(e){let t=[];for(let n of[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`]){let r=RegExp(`export\\s+(?:async\\s+)?function\\s+${n}\\s*\\(`),i=RegExp(`export\\s+(?:async\\s+)?(?:const|let|var)\\s+${n}\\s*=`);(r.test(e)||i.test(e))&&t.push(n)}return t}function Ke(e){return a(e)&&Array.isArray(e.routes)}async function qe(e){try{let n=await fetch(`${ve()}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`invalidate-api-route`,filePath:e})});if(!n.ok){console.error(`[rari] Router: Failed to invalidate API route cache: ${n.statusText}`);return}let r=t(await n.text());if(r?.success!==!0){let e=typeof r?.error==`string`&&r.error!==``?r.error:`Unknown error`;console.error(`[rari] HMR: Failed to invalidate API route cache: ${e}`)}}catch(e){console.error(`[rari] Router: Failed to notify API route invalidation:`,e)}}function Je(e={}){let n={...Re,...e},i=null,a=new Map,o=null,s=new Set,l=e=>[...e].toSorted().join(`|`),u=async e=>{let t=new Set,r=async e=>{try{let i=await O.readdir(e,{withFileTypes:!0});for(let a of i){let i=k.join(e,a.name);a.isDirectory()?await r(i):a.isFile()&&n.extensions.some(e=>a.name.endsWith(e))&&ze(i)&&t.add(i)}}catch{}};return await r(e),t},d=async(e,t=!1)=>{let r=k.resolve(e,n.appDir);try{await O.access(r)}catch{return null}try{let a=await u(r),c=l(a);if(!t&&o===c&&i!=null&&i!==``)return i;let d=await Ne(r,{extensions:n.extensions}),f=JSON.stringify(d),p=k.resolve(e,n.outDir);await O.mkdir(p,{recursive:!0});let m=k.join(p,`server`);return await O.mkdir(m,{recursive:!0}),await O.writeFile(k.join(m,`routes.json`),f,`utf-8`),o=c,s.clear(),a.forEach(e=>{s.add(e)}),f}catch(e){return console.error(`[rari] Router: Failed to generate app routes:`,e),null}},f=e=>{let t=k.resolve(e.config.root,n.appDir);e.watcher.on(`all`,(r,i)=>{(async()=>{if(i.startsWith(t)&&n.extensions.some(e=>i.endsWith(e)))try{let t=ze(i)!==null,a=r===`add`||r===`unlink`,o=t&&!s.has(i);(a||o)&&(await d(e.config.root,!0),i.includes(n.appDir)&&e.ws.send({type:`full-reload`,path:`*`}))}catch(e){console.error(`[rari] Router: Failed to regenerate app routes:`,e)}})()})},p;return ge({name:`rari-router`,configResolved(e){p=e.root;let t=e.logger.warn.bind(e.logger);e.logger.warn=(e,n)=>{typeof e==`string`&&e.includes(`The above dynamic import cannot be analyzed`)&&e.includes(`packages/rari/dist/`)||t(e,n)}},async writeBundle(){let e=p||A.cwd();i=await d(e,!0)},configureServer(e){f(e)},async handleHotUpdate(e){let{file:r,server:o}=e,c=k.resolve(o.config.root,n.appDir);if(r.startsWith(c)&&n.extensions.some(e=>r.endsWith(e))){let e=ze(r);if(e){let n=a.get(r);n&&clearTimeout(n);let l=setTimeout(()=>{(async()=>{a.delete(r);let n=!s.has(r),l=i;i=await d(o.config.root,n);let u=l!==i,f=He(r,c),p=[f];if(i!=null&&i!==``)try{let e=t(i);e&&Ke(e)&&(p=e.routes.map(e=>e.path))}catch(e){console.error(`[rari] Router: Failed to parse manifest for affected routes:`,e)}let m=Ue(f,e,p),h,g=!1,_;if(e===`page`||e===`layout`)try{let e=We(await O.readFile(r,`utf-8`));e&&(h=e,g=!0)}catch(e){console.error(`[rari] Router: Failed to extract metadata:`,e)}if(e===`route`)try{_=Ge(await O.readFile(r,`utf-8`)),await qe(k.relative(c,r))}catch(e){console.error(`[rari] Router: Failed to detect HTTP methods:`,e)}let v={fileType:e,filePath:k.relative(o.config.root,r),routePath:f,affectedRoutes:m,manifestUpdated:u,timestamp:Date.now(),metadata:h,metadataChanged:g,methods:_};o.ws.send({type:`custom`,event:`rari:app-router-updated`,data:v})})()},200);return a.set(r,l),[]}return i=await d(o.config.root),[]}},async closeBundle(){for(let e of a.values())clearTimeout(e);a.clear();let e=p||A.cwd(),i=k.resolve(e,n.outDir,`server`),o=k.join(i,`routes.json`);try{let e=await O.readFile(o,`utf-8`),n=t(e);if(!n||!Ke(n))return;let a=n,s=a.routes.flatMap(e=>{if(!e.isDynamic)return[];let t=e.componentId;return t==null||t===``?[]:[{route:e,componentId:t}]}),l=Math.min(8,Math.max(1,s.length)),u=s.map(()=>!1),d=0,f=0;await new Promise(e=>{let t=()=>{for(;f<l&&d<s.length;){let n=d++,{route:a,componentId:o}=s[n],l=k.join(i,`${o}.js`);f++,(async()=>{try{let e=await be(l);if(e==null)return;r(e)?(a.staticParams=e,u[n]=!0):c(o)}catch(e){console.warn(`[rari] Failed to evaluate generateStaticParams for ${o}:`,e)}finally{f--,d>=s.length&&f===0?e():t()}})()}s.length===0&&e()};t()}),u.some(Boolean)&&await O.writeFile(o,JSON.stringify(a),`utf-8`)}catch(e){console.warn(`[rari] Failed to enrich routes manifest with static params:`,e)}}})}function Ye(e,t,n,r){let i=e.indexOf(t);if(i===-1)throw Error(`Failed to patch flight browser client: anchor for ${r} not found. The react-server-dom-webpack sources likely changed shape after a version bump; update the anchors in patch-flight-browser-client.ts.`);if(e.includes(t,i+1))throw Error(`Failed to patch flight browser client: anchor for ${r} matched more than once. Update the anchors in patch-flight-browser-client.ts to be unambiguous.`);return e.slice(0,i)+n+e.slice(i+t.length)}function Xe(e,t){let n=t.indexOf(`var boundCache = new WeakMap();`),r=t.indexOf(`function createBoundServerReference`,n);if(n===-1||r===-1)throw Error(`Failed to locate edge client form-action helpers for browser patch`);return Ye(e,`function registerBoundServerReference(reference, id, bound) {
|
|
19
|
+
`;return new Promise((t,r)=>{let i=pe(k.execPath,[`--conditions=react-server`,`--input-type=module`,`--eval`,n],{stdio:[`ignore`,`pipe`,`pipe`,`ipc`],env:k.env}),a=``,o=``,s=!1,c=!1,l,u,d,f=()=>{u!==void 0&&clearTimeout(u),d!==void 0&&clearTimeout(d),u=void 0,d=void 0};u=setTimeout(()=>{s||(s=!0,u!==void 0&&clearTimeout(u),u=void 0,i.kill(`SIGTERM`),d=setTimeout(()=>{i.kill(`SIGKILL`)},1e3),r(Error(`generateStaticParams timed out after ${be}ms for ${e}`)))},be),i.stdout?.setEncoding(`utf8`),i.stderr?.setEncoding(`utf8`),i.stdout?.on(`data`,e=>{a+=e}),i.stderr?.on(`data`,e=>{o+=e}),i.on(`message`,e=>{c=!0,l=e}),i.on(`error`,e=>{s||(s=!0,f(),r(e))}),i.on(`close`,n=>{if(f(),s)return;s=!0;let i=[o.trim(),a.trim()].filter(Boolean).join(`
|
|
20
|
+
`);if(n!==0){r(Error(i||`generateStaticParams worker exited with code ${n}`));return}if(!c){r(Error(i||`generateStaticParams worker exited without an IPC result for ${e}`));return}t(l)})})}const F={PAGE:`page`,LAYOUT:`layout`,LOADING:`loading`,ERROR:`error`,NOT_FOUND:`not-found`,TEMPLATE:`template`,DEFAULT:`default`,ROUTE:`route`,OG_IMAGE:`opengraph-image`,TWITTER_IMAGE:`twitter-image`,ICON:`icon`,APPLE_ICON:`apple-icon`},Se={DYNAMIC:/^\[([^\]]+)\]$/,CATCH_ALL:/^\[\.\.\.([^\]]+)\]$/,OPTIONAL_CATCH_ALL:/^\[\[\.\.\.([^\]]+)\]\]$/},Ce=[{pattern:Se.OPTIONAL_CATCH_ALL,type:`optional-catch-all`,format:e=>`[[...${e}]]`},{pattern:Se.CATCH_ALL,type:`catch-all`,format:e=>`[...${e}]`},{pattern:Se.DYNAMIC,type:`dynamic`,format:e=>`[${e}]`}],we=/^\([^/]+\)$/;function Te(e){return we.test(e)}function Ee(e){return e?e.replace(x,`/`).split(`/`).filter(Boolean).some(Te):!1}function De(e){for(let t of Ce){let n=e.match(t.pattern);if(n)return{type:t.type,param:n[1],format:t.format}}}function Oe(e){let t=De(e);return t?t.format(t.param):e}function ke(e){let t=De(e);return t?{type:t.type,value:e,param:t.param}:{type:`static`,value:e}}const Ae=/export\s+const\s+size\s*=\s*\{\s*width\s*:\s*(\d+)\s*,\s*height\s*:\s*(\d+)\s*[,}]/,je=/export\s+const\s+contentType\s*=\s*['"]([^'"]+)['"]/,Me=[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`];var Ne=class{appDir;extensions;verbose;constructor(e){this.appDir=O.resolve(e.appDir),this.extensions=[...e.extensions??[`.tsx`,`.jsx`,`.ts`,`.js`]],this.verbose=e.verbose??!1}async generateManifest(){this.verbose&&console.warn(`[rari] Router: Scanning app directory: ${this.appDir}`);let e=[],t=[],n=[],r=[],i=[],a=[],o=[],s=[];await this.scanDirectory(``,e,t,n,r,i,a,o,s);for(let o of[t,n,r,i,a,s])this.finalizeGroupEntries(e,o);return this.assertNoDuplicateRoutes(e),this.assertNoDuplicateRoutes(o),this.verbose&&(console.warn(`[rari] Router: Found ${e.length} routes`),console.warn(`[rari] Router: Found ${t.length} layouts`),console.warn(`[rari] Router: Found ${n.length} loading components`),console.warn(`[rari] Router: Found ${r.length} error boundaries`),console.warn(`[rari] Router: Found ${a.length} templates`),console.warn(`[rari] Router: Found ${o.length} API routes`),console.warn(`[rari] Router: Found ${s.length} OG images`)),{routes:this.sortRoutes(e),layouts:this.sortLayouts(t),loading:n,errors:r,notFound:i,templates:this.sortTemplates(a),apiRoutes:this.sortApiRoutes(o),ogImages:s,generated:new Date().toISOString()}}finalizeGroupEntries(e,t){for(let n=t.length-1;n>=0;n--){let r=t[n],i=O.dirname(r.filePath).replace(x,`/`);if(!Ee(i))continue;let a=e.filter(e=>{let t=O.dirname(e.filePath).replace(x,`/`);return t===i||t.startsWith(`${i}/`)}).map(e=>e.path);if(a.length===0){t.splice(n,1);continue}let o=Array.from(new Set(a)).sort();r.path=o[0],o.length>1&&(r.additionalPaths=o.slice(1))}}assertNoDuplicateRoutes(e){let t=new Map;for(let n of e){let e=t.get(n.path);if(e!=null&&e!==``)throw Error(`[rari] Route conflict: path '${n.path}' is defined by both '${e}' and '${n.filePath}'.`);t.set(n.path,n.filePath)}}async scanDirectory(e,t,n,r,i,a,o,s,c){let l=O.join(this.appDir,e),u;try{u=await D.readdir(l)}catch{return}let d=[],f=[];for(let e of u){let t=O.join(l,e),n=await D.stat(t);n.isDirectory()?this.shouldScanDirectory(e)&&f.push(e):n.isFile()&&d.push(e)}await this.processSpecialFiles(e,d,t,n,r,i,a,o,s,c);for(let l of f){let u=e?O.join(e,l):l;await this.scanDirectory(u,t,n,r,i,a,o,s,c)}}async processSpecialFiles(e,t,n,r,i,a,o,s,c,l){let u=this.pathToRoute(e),d=this.findFile(t,F.PAGE);if(d!=null&&d!==``){let t=this.parseRouteSegments(e),r=this.extractParams(t);n.push({path:u,filePath:O.join(e,d).replace(x,`/`),segments:t,params:r,isDynamic:r.length>0})}let f=this.findFile(t,F.LAYOUT);if(f!=null&&f!==``){let t=this.getParentPath(e);r.push({path:u,filePath:O.join(e,f).replace(x,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let p=this.findFile(t,F.LOADING);p!=null&&p!==``&&i.push({path:u,filePath:O.join(e,p).replace(x,`/`)});let m=this.findFile(t,F.ERROR);m!=null&&m!==``&&a.push({path:u,filePath:O.join(e,m).replace(x,`/`)});let h=this.findFile(t,F.NOT_FOUND);h!=null&&h!==``&&o.push({path:u,filePath:O.join(e,h).replace(x,`/`)});let g=this.findFile(t,F.TEMPLATE);if(g!=null&&g!==``){let t=this.getParentPath(e);s.push({path:u,filePath:O.join(e,g).replace(x,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let _=this.findFile(t,F.OG_IMAGE);if(_!=null&&_!==``){let t=O.join(e,_).replace(x,`/`),n=O.join(this.appDir,t),r,i,a;try{let e=await D.readFile(n,`utf-8`),t=Ae.exec(e);t&&(r=Number.parseInt(t[1],10),i=Number.parseInt(t[2],10));let o=je.exec(e);o&&(a=o[1])}catch{}l.push({path:u,filePath:t,width:r,height:i,contentType:a})}let v=this.findFile(t,F.ROUTE);if(v!=null&&v!==``){let t=await this.processApiRouteFile(e,v);c.push(t)}}findFile(e,t){for(let n of this.extensions){let r=`${t}${n}`;if(e.includes(r))return r}}pathToRoute(e){return e?`/${e.replace(x,`/`).split(`/`).filter(Boolean).filter(e=>!Te(e)).map(Oe).join(`/`)}`:`/`}parseRouteSegments(e){return e?e.split(g).filter(Boolean).filter(e=>!Te(e)).map(ke):[]}extractParams(e){return e.filter(e=>e.param!==void 0).map(e=>e.param)}getParentPath(e){if(!e)return null;let t=e.split(g).filter(Boolean);return t.length===0?null:t.slice(0,-1).join(`/`)}shouldScanDirectory(e){return![`node_modules`,`.git`,`dist`,`build`,`__tests__`,`test`,`tests`,`coverage`].includes(e)&&!e.startsWith(`_`)&&!e.startsWith(`.`)}sortRoutes(e){return e.sort((e,t)=>{let n=e=>{if(!e.isDynamic)return 0;let t=e.segments.some(e=>e.type===`catch-all`);return e.segments.some(e=>e.type===`optional-catch-all`)?3:t?2:1},r=n(e),i=n(t);if(r!==i)return r-i;let a=e.path.split(`/`).length,o=t.path.split(`/`).length;return a===o?e.path.localeCompare(t.path):o-a})}sortApiRoutes(e){return e.sort((e,t)=>{if(!e.isDynamic&&t.isDynamic)return-1;if(e.isDynamic&&!t.isDynamic)return 1;let n=e.path.split(`/`).length,r=t.path.split(`/`).length;return n===r?e.path.localeCompare(t.path):n-r})}sortLayouts(e){return e.sort((e,t)=>e.path===`/`&&t.path!==`/`?-1:t.path===`/`&&e.path!==`/`?1:e.path.split(`/`).length-t.path.split(`/`).length)}sortTemplates(e){return e.sort((e,t)=>e.path===`/`&&t.path!==`/`?-1:t.path===`/`&&e.path!==`/`?1:e.path.split(`/`).length-t.path.split(`/`).length)}async detectHttpMethods(e){let t=O.join(this.appDir,e),n=await D.readFile(t,`utf-8`),r=[];for(let e of Me){let t=RegExp(`export\\s+(?:async\\s+)?function\\s+${e}\\s*\\(`),i=RegExp(`export\\s+(?:async\\s+)?(?:const|let|var)\\s+${e}\\s*=`);(t.test(n)||i.test(n))&&r.push(e)}return r}async processApiRouteFile(e,t){let n=O.join(e,t).replace(x,`/`),r=this.pathToRoute(e),i=this.parseRouteSegments(e),a=this.extractParams(i),o=await this.detectHttpMethods(n);return{path:r,filePath:n,segments:i,params:a,isDynamic:a.length>0,methods:o}}};async function Pe(e,t={}){return new Ne({appDir:e,...t}).generateManifest()}const Fe=/export\s+const\s+metadata\s*(?::\s*\w+\s*)?=\s*(\{[\s\S]*?\n\})/,Ie=/title\s*:\s*['"]([^'"]+)['"]/,Le=/description\s*:\s*['"]([^'"]+)['"]/,Re=/keywords\s*:\s*\[([\s\S]*?)\]/,ze={appDir:`src/app`,extensions:[`.tsx`,`.jsx`,`.ts`,`.js`],outDir:`dist`};function Be(e){switch(O.basename(e).replace(v,``)){case`page`:return`page`;case`layout`:return`layout`;case`template`:return`template`;case`loading`:return`loading`;case`error`:return`error`;case`not-found`:return`not-found`;case`route`:return`route`;default:return null}}function Ve(e){return/^\([^/]+\)$/.test(e)}function He(e){if(!e||e===`/`)return`/`;let t=e.replace(x,`/`).split(`/`).filter(e=>!!e&&!Ve(e));return t.length>0?`/${t.join(`/`)}`:`/`}function Ue(e,t){let n=O.relative(t,O.dirname(e));return!n||n===`.`?`/`:He(`/${n.replace(x,`/`).split(`/`).filter(Boolean).join(`/`)}`)}function We(e,t,n){if(t===`page`)return[e];let r=`${e}${e===`/`?``:`/`}`,i=n.filter(t=>t===e||t.startsWith(r));return i.length>0?i:[e]}function Ge(e){try{let t=Fe.exec(e);if(!t)return null;let n=t[1],r={},i=Ie.exec(n);i&&(r.title=i[1]);let a=Le.exec(n);a&&(r.description=a[1]);let o=Re.exec(n);o&&(r.keywords=o[1].split(`,`).map(e=>e.trim().replace(ne,``)).filter(Boolean));for(let e of[`author`,`viewport`,`themeColor`,`robots`,`openGraph`,`twitter`]){let t=RegExp(`${e}\\s*:\\s*['"]([^'"]+)['"]`,`m`),i=n.match(t);i&&(r[e]=i[1])}return Object.keys(r).length>0?r:null}catch(e){return console.error(`[rari] Router: Failed to extract metadata:`,e),null}}function Ke(e){let t=[];for(let n of[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`]){let r=RegExp(`export\\s+(?:async\\s+)?function\\s+${n}\\s*\\(`),i=RegExp(`export\\s+(?:async\\s+)?(?:const|let|var)\\s+${n}\\s*=`);(r.test(e)||i.test(e))&&t.push(n)}return t}function qe(e){return a(e)&&Array.isArray(e.routes)}async function Je(e){try{let n=await fetch(`${ye()}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`invalidate-api-route`,filePath:e})});if(!n.ok){console.error(`[rari] Router: Failed to invalidate API route cache: ${n.statusText}`);return}let r=t(await n.text());if(r?.success!==!0){let e=typeof r?.error==`string`&&r.error!==``?r.error:`Unknown error`;console.error(`[rari] HMR: Failed to invalidate API route cache: ${e}`)}}catch(e){console.error(`[rari] Router: Failed to notify API route invalidation:`,e)}}function Ye(e={}){let n={...ze,...e},i=null,a=new Map,o=null,s=new Set,l=e=>[...e].toSorted().join(`|`),u=async e=>{let t=new Set,r=async e=>{try{let i=await D.readdir(e,{withFileTypes:!0});for(let a of i){let i=O.join(e,a.name);a.isDirectory()?await r(i):a.isFile()&&n.extensions.some(e=>a.name.endsWith(e))&&Be(i)&&t.add(i)}}catch{}};return await r(e),t},d=async(e,t=!1)=>{let r=O.resolve(e,n.appDir);try{await D.access(r)}catch{return null}try{let a=await u(r),c=l(a);if(!t&&o===c&&i!=null&&i!==``)return i;let d=await Pe(r,{extensions:n.extensions}),f=JSON.stringify(d),p=O.resolve(e,n.outDir);await D.mkdir(p,{recursive:!0});let m=O.join(p,`server`);return await D.mkdir(m,{recursive:!0}),await D.writeFile(O.join(m,`routes.json`),f,`utf-8`),o=c,s.clear(),a.forEach(e=>{s.add(e)}),f}catch(e){return console.error(`[rari] Router: Failed to generate app routes:`,e),null}},f=e=>{let t=O.resolve(e.config.root,n.appDir);e.watcher.on(`all`,(r,i)=>{(async()=>{if(i.startsWith(t)&&n.extensions.some(e=>i.endsWith(e)))try{let t=Be(i)!==null,a=r===`add`||r===`unlink`,o=t&&!s.has(i);(a||o)&&(await d(e.config.root,!0),i.includes(n.appDir)&&e.ws.send({type:`full-reload`,path:`*`}))}catch(e){console.error(`[rari] Router: Failed to regenerate app routes:`,e)}})()})},p;return _e({name:`rari-router`,configResolved(e){p=e.root;let t=e.logger.warn.bind(e.logger);e.logger.warn=(e,n)=>{typeof e==`string`&&e.includes(`The above dynamic import cannot be analyzed`)&&e.includes(`packages/rari/dist/`)||t(e,n)}},async writeBundle(){let e=p||k.cwd();i=await d(e,!0)},configureServer(e){f(e)},async handleHotUpdate(e){let{file:r,server:o}=e,c=O.resolve(o.config.root,n.appDir);if(r.startsWith(c)&&n.extensions.some(e=>r.endsWith(e))){let e=Be(r);if(e){let n=a.get(r);n&&clearTimeout(n);let l=setTimeout(()=>{(async()=>{a.delete(r);let n=!s.has(r),l=i;i=await d(o.config.root,n);let u=l!==i,f=Ue(r,c),p=[f];if(i!=null&&i!==``)try{let e=t(i);e&&qe(e)&&(p=e.routes.map(e=>e.path))}catch(e){console.error(`[rari] Router: Failed to parse manifest for affected routes:`,e)}let m=We(f,e,p),h,g=!1,_;if(e===`page`||e===`layout`)try{let e=Ge(await D.readFile(r,`utf-8`));e&&(h=e,g=!0)}catch(e){console.error(`[rari] Router: Failed to extract metadata:`,e)}if(e===`route`)try{_=Ke(await D.readFile(r,`utf-8`)),await Je(O.relative(c,r))}catch(e){console.error(`[rari] Router: Failed to detect HTTP methods:`,e)}let v={fileType:e,filePath:O.relative(o.config.root,r),routePath:f,affectedRoutes:m,manifestUpdated:u,timestamp:Date.now(),metadata:h,metadataChanged:g,methods:_};o.ws.send({type:`custom`,event:`rari:app-router-updated`,data:v})})()},200);return a.set(r,l),[]}return i=await d(o.config.root),[]}},async closeBundle(){for(let e of a.values())clearTimeout(e);a.clear();let e=p||k.cwd(),i=O.resolve(e,n.outDir,`server`),o=O.join(i,`routes.json`);try{let e=await D.readFile(o,`utf-8`),n=t(e);if(!n||!qe(n))return;let a=n,s=a.routes.flatMap(e=>{if(!e.isDynamic)return[];let t=e.componentId;return t==null||t===``?[]:[{route:e,componentId:t}]}),l=Math.min(8,Math.max(1,s.length)),u=s.map(()=>!1),d=0,f=0;await new Promise(e=>{let t=()=>{for(;f<l&&d<s.length;){let n=d++,{route:a,componentId:o}=s[n],l=O.join(i,`${o}.js`);f++,(async()=>{try{let e=await xe(l);if(e==null)return;r(e)?(a.staticParams=e,u[n]=!0):c(o)}catch(e){console.warn(`[rari] Failed to evaluate generateStaticParams for ${o}:`,e)}finally{f--,d>=s.length&&f===0?e():t()}})()}s.length===0&&e()};t()}),u.some(Boolean)&&await D.writeFile(o,JSON.stringify(a),`utf-8`)}catch(e){console.warn(`[rari] Failed to enrich routes manifest with static params:`,e)}}})}function Xe(e,t,n,r){let i=e.indexOf(t);if(i===-1)throw Error(`Failed to patch flight browser client: anchor for ${r} not found. The react-server-dom-webpack sources likely changed shape after a version bump; update the anchors in patch-flight-browser-client.ts.`);if(e.includes(t,i+1))throw Error(`Failed to patch flight browser client: anchor for ${r} matched more than once. Update the anchors in patch-flight-browser-client.ts to be unambiguous.`);return e.slice(0,i)+n+e.slice(i+t.length)}function Ze(e,t){let n=t.indexOf(`var boundCache = new WeakMap();`),r=t.indexOf(`function createBoundServerReference`,n);if(n===-1||r===-1)throw Error(`Failed to locate edge client form-action helpers for browser patch`);return Xe(e,`function registerBoundServerReference(reference, id, bound) {
|
|
21
21
|
knownServerReferences.has(reference) ||
|
|
22
22
|
knownServerReferences.set(reference, {
|
|
23
23
|
id: id,
|
|
24
24
|
originalBind: reference.bind,
|
|
25
25
|
bound: bound
|
|
26
26
|
});
|
|
27
|
-
}`,
|
|
27
|
+
}`,Xe(t.slice(n,r),`return {
|
|
28
28
|
name: referenceClosure,
|
|
29
29
|
method: "POST",
|
|
30
30
|
encType: "multipart/form-data",
|
|
@@ -44,8 +44,8 @@ process.send(result, () => {
|
|
|
44
44
|
encType: "multipart/form-data",
|
|
45
45
|
action: resolveRariFormActionUrl(),
|
|
46
46
|
data: data
|
|
47
|
-
};`,`edge $$FORM_ACTION return block`),`browser registerBoundServerReference`)}function Ze(e){return e.replace(/(?<!\$)\$FORM_ACTION/g,()=>`$$FORM_ACTION`).replace(/(?<!\$)\$IS_SIGNATURE_EQUAL/g,()=>`$$IS_SIGNATURE_EQUAL`)}function L(e,t=8){return me.createHash(`sha256`).update(e).digest(`hex`).slice(0,t)}function Qe(e,t=A.cwd()){let n=k.isAbsolute(e)?e:k.resolve(t,e),r=k.relative(t,n);return k.isAbsolute(r)?n.replace(x,`/`):r.replace(x,`/`)}function $e(e){return e.replace(v,``).replace(ee,`_`).replace(b,``)}function et(e,t=A.cwd()){let n=Qe(e,t);return`${$e(n)}_${L(n)}`}const tt=new Set([`return`,`throw`,`case`,`typeof`,`instanceof`,`new`,`delete`,`void`,`in`,`of`]),nt=8232,rt=8233;function R(e){return e===32||e===9||e===13||e===10||e===nt||e===rt||e===65279}function z(e){return e===13||e===10||e===nt||e===rt}function B(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95||e===36}function it(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function at(e,t,n){for(;t<n&&R(e.charCodeAt(t));)t++;return t}function V(e,t,n){for(;t<n;){let r=at(e,t,n);if(r!==t){t=r;continue}let i=e.charCodeAt(t);if(i===47&&e.charCodeAt(t+1)===47){t=H(e,t,n);continue}if(i===47&&e.charCodeAt(t+1)===42){t=ot(e,t,n);continue}break}return t}function H(e,t,n){for(;t<n&&!z(e.charCodeAt(t));)t++;return t}function ot(e,t,n){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;return t+2}function U(e,t,n,r){for(t++;t<n;){let n=e.charCodeAt(t);if(n===92){t+=2;continue}if(n===r)return t+1;t++}return t}function st(e,t,n){t++;let r=e.charCodeAt(t)===47;for(r&&t++;t<n;){let n=e.charCodeAt(t);if(B(n)||n===46||n===45)t++;else break}let i=+!r;for(;t<n&&i>0;){let a=e.charCodeAt(t);if(a===39||a===34||a===96){t=U(e,t,n,a);continue}if(a===123){t++;let r=1;for(;t<n&&r>0;){let i=e.charCodeAt(t);if(i===39||i===34||i===96){t=U(e,t,n,i);continue}i===123&&r++,i===125&&r--,t++}continue}if(a===47&&e.charCodeAt(t+1)===62){i--,t+=2;continue}if(a===62){t++,r&&i--;continue}if(a===60){let r=e.charCodeAt(t+1);if(r===47||r===46||r===62||it(r)){for(r===47?(i--,t++):r!==33&&i++,t++;t<n;){let n=e.charCodeAt(t);if(B(n)||n===46||n===45)t++;else break}continue}t++;continue}t++}return t}function ct(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function W(e,t,n){if(t+n.length>e.length)return!1;for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;let r=t>0?e.charCodeAt(t-1):-1,i=t+n.length,a=i<e.length?e.charCodeAt(i):-1;return!(r!==-1&&B(r)||a!==-1&&B(a))}function lt(e,t,n){let r=V(e,t,n);if(r>=n)return null;let i=e.charCodeAt(r);if(i!==39&&i!==34)return null;let a=r+1,o=U(e,r,n,i);return o<=a?null:{source:e.slice(a,o-1),end:o}}function ut(e,t,n){if(!W(e,t,`import`))return{sources:[],end:t+6};let r=t+6;if(r=V(e,r,n),W(e,r,`type`)&&(r=V(e,r+4,n)),e.charCodeAt(r)===46){for(r++;r<n&&B(e.charCodeAt(r));)r++;for(;r<n&&e.charCodeAt(r)===46;)for(r++;r<n&&B(e.charCodeAt(r));)r++;return{sources:[],end:r}}if(e.charCodeAt(r)===40){r++;let t=lt(e,r,n);return t?{sources:[t.source],end:t.end}:{sources:[],end:r}}let i=lt(e,r,n);if(i)return{sources:[i.source],end:i.end};let a=0;for(;r<n&&(r=V(e,r,n),!(r>=n));){let t=e.charCodeAt(r);if(a===0&&W(e,r,`from`)){let t=lt(e,r+4,n);if(t)return{sources:[t.source],end:t.end};break}if(t===39||t===34||t===96){r=U(e,r,n,t);continue}t===123||t===40||t===91?a++:(t===125||t===41||t===93)&&(a=Math.max(0,a-1)),r++}return{sources:[],end:r}}function dt(e,t){return e.charCodeAt(t)===101&&e.charCodeAt(t+1)===120&&e.charCodeAt(t+2)===112&&e.charCodeAt(t+3)===111&&e.charCodeAt(t+4)===114&&e.charCodeAt(t+5)===116}function ft(e,t){return e.charCodeAt(t)===100&&e.charCodeAt(t+1)===101&&e.charCodeAt(t+2)===102&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===117&&e.charCodeAt(t+5)===108&&e.charCodeAt(t+6)===116}function G(e){let t={hasUseClient:!1,hasUseServer:!1},n=!1,r=!1,i=!1,a=!1,o=[],s=!0,c=!1,l=0,u=e.length;for(;l<u;){let d=e.charCodeAt(l);if(s&&(d===39||d===34)){let i=l+1,a=U(e,l,u,d);if(a<=i){s=!1,l++;continue}let o=a-1-i,f=o===10&&ct(e,i,`use client`),p=o===10&&ct(e,i,`use server`);c||(c=!0,n=f,r=p),f&&(t.hasUseClient=!0),p&&(t.hasUseServer=!0);let m=a,h=!1;for(;m<u;){let t=e.charCodeAt(m);if(R(t)&&!z(t)){m++;continue}if(z(t)||t===59){h=!0,l=m+1;break}if(t===47&&e.charCodeAt(m+1)===47){m=H(e,m,u);continue}if(t===47&&e.charCodeAt(m+1)===42){m=ot(e,m,u);continue}s=!1,h=!1;break}if(!h){m>=u&&(s=!1),l=s?a:m;continue}continue}let f=q(e,l,u);if(f!==-1){s&&!Ot(e,l)&&(s=!1),l=f;continue}if(s=!1,W(e,l,`import`)){let t=ut(e,l,u);for(let e of t.sources)o.push(e);l=t.end;continue}if(dt(e,l)){let t=l+6;if(t<u){let n=e.charCodeAt(t);if(R(n)||n===123||n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)){let n=V(e,t,u);if(ft(e,n)){i=!0,a=!0;let r=n+7;if(r>=u||!B(e.charCodeAt(r))){l=t;continue}}if(e.charCodeAt(n)===123){let t=n+1;for(;t<u&&(t=V(e,t,u),e.charCodeAt(t)!==125);){let n=t;for(;t<u&&B(e.charCodeAt(t));)t++;let r=t-n;if(r===0)break;t=V(e,t,u);let o=!1;if(e.charCodeAt(t)===97&&e.charCodeAt(t+1)===115){o=!0;let n=t+2;if(n<u&&!B(e.charCodeAt(n))){t=V(e,n,u);let r=t;for(;t<u&&B(e.charCodeAt(t));)t++;t-r===7&&ft(e,r)&&(i=!0,a=!0)}}if(!o&&r===7&&ft(e,n)&&(i=!0,a=!0),e.charCodeAt(t)===44){t++;continue}if(e.charCodeAt(t)===125)break;t++}}else(W(e,n,`async`)||W(e,n,`function`)||W(e,n,`class`))&&(a=!0)}}}l++}return{directives:t,topLevelUseClient:n,topLevelUseServer:r,hasDefaultExport:i,hasComponentExport:a,importSources:[...new Set(o)]}}function K(e,t,n){if(t>=n||!it(e.charCodeAt(t)))return null;let r=t+1;for(;r<n&&B(e.charCodeAt(r));)r++;return{name:e.slice(t,r),end:r}}function pt(e,t,n){let r=t;for(;r<n;){let t=e.charCodeAt(r);if(t===32||t===9){r++;continue}if(t===59)return r+1;break}return t}function mt(e,t,n){let r=[],i=t+1;for(;;){if(i=V(e,i,n),i>=n)return null;if(e.charCodeAt(i)===125)return{named:r,end:i+1};let t=!1;if(W(e,i,`type`)){let r=V(e,i+4,n),a=e.charCodeAt(r);(a===39||a===34||K(e,r,n)!==null)&&!W(e,r,`as`)&&(t=!0,i=r)}let a,o=e.charCodeAt(i);if(o===39||o===34){let t=U(e,i,n,o);a=e.slice(i+1,t-1),i=t}else{let t=K(e,i,n);if(!t)return null;a=t.name,i=t.end}i=V(e,i,n);let s=a;if(W(e,i,`as`)){i=V(e,i+2,n);let t=K(e,i,n);if(!t)return null;s=t.name,i=V(e,t.end,n)}r.push({imported:a,local:s,typeOnly:t});let c=e.charCodeAt(i);if(c===44){i++;continue}return c===125?{named:r,end:i+1}:null}}function ht(e,t,n){let r=V(e,t+6,n);if(r>=n)return null;let i=e.charCodeAt(r);if(i===40||i===46)return null;if(i===39||i===34){let i=lt(e,r,n);return i?{start:t,end:pt(e,i.end,n),source:i.source,typeOnly:!1,sideEffectOnly:!0,defaultBinding:null,namespaceBinding:null,named:[]}:null}let a=!1;if(W(e,r,`type`)){let t=V(e,r+4,n);!W(e,t,`from`)&&e.charCodeAt(t)!==44&&(a=!0,r=t)}let o=null,s=null,c=[],l=e.charCodeAt(r);if(l!==123&&l!==42){let t=K(e,r,n);if(!t)return null;o=t.name,r=V(e,t.end,n),e.charCodeAt(r)===44?(r=V(e,r+1,n),l=e.charCodeAt(r)):l=-1}if(l===42){if(r=V(e,r+1,n),!W(e,r,`as`))return null;r=V(e,r+2,n);let t=K(e,r,n);if(!t)return null;s=t.name,r=t.end}else if(l===123){let t=mt(e,r,n);if(!t)return null;c=t.named,r=t.end}if(r=V(e,r,n),!W(e,r,`from`))return null;let u=lt(e,r+4,n);return u?{start:t,end:pt(e,u.end,n),source:u.source,typeOnly:a,sideEffectOnly:!1,defaultBinding:o,namespaceBinding:s,named:c}:null}function gt(e){let t=[],n=0,r=e.length;for(;n<r;){let i=q(e,n,r);if(i!==-1){n=i;continue}if(W(e,n,`import`)){let i=ht(e,n,r);if(i){t.push(i),n=i.end;continue}n+=6;continue}n++}return t}function _t(e){let t=new Set,n=0,r=e.length;for(;n<r;){let i=q(e,n,r);if(i!==-1){n=i;continue}if(!W(e,n,`export`)){n++;continue}let a=V(e,n+6,r);if(W(e,a,`type`)||W(e,a,`interface`)){n=a+1;continue}if(e.charCodeAt(a)===42){let i=V(e,a+1,r);if(W(e,i,`as`)){i=V(e,i+2,r);let a=K(e,i,r);a&&t.add(a.name),n=a?.end??i+1}else n=a+1;continue}if(W(e,a,`default`)){t.add(`default`),n=a+7;continue}if(e.charCodeAt(a)===123){let i=vt(e,a,r),o=e.slice(a+1,i-1);for(let e of o.split(`,`)){let n=e.trim();if(!n||n.startsWith(`type `)||n.startsWith(`typeof `))continue;let r=(n.split(/\s+as\s+/).at(-1)??``).trim();r!==``&&r!==`type`&&t.add(r)}n=i;continue}if(W(e,a,`async`)&&(a=V(e,a+5,r)),W(e,a,`function`)||W(e,a,`class`)||W(e,a,`const`)||W(e,a,`let`)||W(e,a,`var`)){let i=W(e,a,`function`)?8:W(e,a,`class`)||W(e,a,`const`)?5:3,o=V(e,a+i,r);e.charCodeAt(o)===42&&(o=V(e,o+1,r));let s=K(e,o,r);s&&t.add(s.name),n=s?.end??o+1;continue}n++}return[...t]}function vt(e,t,n){let r=t,i=0;for(;r<n;){let t=e.charCodeAt(r);if(t===39||t===34||t===96){r=U(e,r,n,t);continue}if(t===47&&e.charCodeAt(r+1)===47){r=H(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)===42){r=ot(e,r,n);continue}if(t===123){i++,r++;continue}if(t===125){if(i--,r++,i===0)return r;continue}r++}return r}function yt(e){return G(e).hasDefaultExport}function bt(e){return e===40||e===91||e===123||e===44||e===59||e===61||e===58||e===63||e===33||e===43||e===45||e===42||e===37||e===38||e===124||e===94||e===126||e===60||e===62}function xt(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(R(t)){n--;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===42){for(n-=2;n>=1;){if(e.charCodeAt(n)===42&&e.charCodeAt(n-1)===47){n-=2;break}n--}if(n<0)return;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===47){n-=2;continue}let r=n;for(;r>=0&&e.charCodeAt(r)!==10&&e.charCodeAt(r)!==13;)r--;let i=r+1;for(;i<n&&(e.charCodeAt(i)===32||e.charCodeAt(i)===9);)i++;if(i<n&&e.charCodeAt(i)===47&&e.charCodeAt(i+1)===47){n=i-1;continue}break}if(n<0||!B(e.charCodeAt(n)))return;let r=n;for(;n>=0&&B(e.charCodeAt(n));)n--;return e.slice(n+1,r+1)}function St(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(R(t)){n--;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===42){for(n-=2;n>=1;){if(e.charCodeAt(n)===42&&e.charCodeAt(n-1)===47){n-=2;break}n--}if(n<0)return-1;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===47){n-=2;continue}let r=n;for(;r>=0&&e.charCodeAt(r)!==10&&e.charCodeAt(r)!==13;)r--;let i=r+1;for(;i<n&&(e.charCodeAt(i)===32||e.charCodeAt(i)===9);)i++;if(i<n&&e.charCodeAt(i)===47&&e.charCodeAt(i+1)===47){n=i-1;continue}return t}return-1}function Ct(e,t){let n=St(e,t);if(n===-1||bt(n))return!0;let r=xt(e,t);return r!=null&&r!==``&&tt.has(r)}const wt=new Set([`return`,`throw`,`case`,`default`,`else`,`do`,`typeof`,`void`,`yield`,`await`,`delete`]);function Tt(e,t){let n=St(e,t);if(n===-1)return!0;if(B(n)||n>=48&&n<=57){let n=xt(e,t);return n!=null&&n!==``&&wt.has(n)}return n!==41&&n!==93&&n!==125}function Et(e,t,n){if(!Tt(e,t))return-1;let r=e.charCodeAt(t+1);if(r!==47&&r!==46&&r!==62&&!it(r))return-1;let i=st(e,t,n);return i<n&&e.charCodeAt(i)===62&&i++,i>t&&e.charCodeAt(i-1)===62?i:-1}function Dt(e,t,n){t++;let r=!1;for(;t<n;){let i=e.charCodeAt(t);if(i===92){t+=2;continue}if(r){i===93&&(r=!1),t++;continue}if(i===91){r=!0,t++;continue}if(i===47){for(t++;t<n&&B(e.charCodeAt(t));)t++;return t}if(z(i))return t;t++}return t}function q(e,t,n){if(t>=n)return-1;let r=e.charCodeAt(t);if(R(r))return t+1;if(r===47&&e.charCodeAt(t+1)===47)return H(e,t,n);if(r===47&&e.charCodeAt(t+1)===42)return ot(e,t,n);if(r===39||r===34||r===96)return U(e,t,n,r);if(r===47&&e.charCodeAt(t+1)!==47&&e.charCodeAt(t+1)!==42&&Ct(e,t))return Dt(e,t,n);if(r===60){let r=Et(e,t,n);if(r!==-1)return r}return-1}function Ot(e,t){let n=e.charCodeAt(t);return R(n)?!0:n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)}function kt(e){let t=e.length,n=0;for(;n<t;){let r=q(e,n,t);if(r!==-1){n=r;continue}if(W(e,n,`export`)){let r=V(e,n+6,t);if(!W(e,r,`default`)){n++;continue}let i=V(e,r+7,t),a=i,o=null;if(W(e,a,`async`)){let n=V(e,a+5,t);W(e,n,`function`)&&(a=n)}if(W(e,a,`function`)||W(e,a,`class`)){let n=W(e,a,`function`)?8:5,r=V(e,a+n,t);e.charCodeAt(r)===42&&(r=V(e,r+1,t));let i=K(e,r,t);i&&(o=i.name)}let s=Mt(e,i,t),c=pt(e,s,t);return{exportStart:n,valueStart:i,valueEnd:s,statementEnd:c,bindingName:o}}n++}return null}function At(e,t,n){if(t>=n)return!1;let r=e.charCodeAt(t),i=t+1<n?e.charCodeAt(t+1):-1;return r===46||r===63&&i===46||r===40||r===91||r===96||r===61&&i===62||r===43||r===45||r===42||r===47||r===37||r===38||r===124||r===94||r===60||r===62||r===61||r===33||r===63||r===58||r===44||r===126||W(e,t,`instanceof`)||W(e,t,`in`)||W(e,t,`of`)||W(e,t,`as`)}const jt=new Set([`typeof`,`void`,`delete`,`await`,`yield`,`new`]);function Mt(e,t,n){let r=t,i=0,a=0,o=0,s=!1;for(;r<n;){let t=e.charCodeAt(r);if(t===39||t===34||t===96){r=U(e,r,n,t),s=!0;continue}if(t===47&&e.charCodeAt(r+1)===47){r=H(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)===42){r=ot(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)!==47&&e.charCodeAt(r+1)!==42&&Ct(e,r)){r=Dt(e,r,n),s=!0;continue}if(t===60&&i===0&&a===0&&o===0){let t=Et(e,r,n);if(t!==-1){r=t,s=!0;continue}}if(t===40){i++,s=!1,r++;continue}if(t===41){i=Math.max(0,i-1),s=!0,r++;continue}if(t===123){a++,s=!1,r++;continue}if(t===125){if(a=Math.max(0,a-1),s=!0,r++,i===0&&a===0&&o===0)return r;continue}if(t===91){o++,s=!1,r++;continue}if(t===93){o=Math.max(0,o-1),s=!0,r++;continue}if(i===0&&a===0&&o===0){if(t===59)return r;if(z(t)){let t=V(e,r+1,n);if(!s||At(e,t,n)){r++;continue}return r}}if(it(t)){let t=K(e,r,n);if(t){s=!jt.has(t.name),r=t.end;continue}}if(t>=48&&t<=57){for(s=!0,r++;r<n;){let t=e.charCodeAt(r);if(t>=48&&t<=57||t===46||t===110||t===101||t===69){r++;continue}break}continue}if(t===61&&e.charCodeAt(r+1)===62){s=!1,r+=2;continue}if(t===46||t===44||t===58||t===63||t===61||t===43||t===45||t===42||t===47||t===37||t===38||t===124||t===94||t===33||t===126||t===60||t===62){s=!1,r++;continue}r++}return r}function Nt(e,t){let n=kt(e);if(n==null||n.bindingName!=null)return null;let r=`const ${t} = ${e.slice(n.valueStart,n.valueEnd).trimEnd()};\nexport default ${t}${e.slice(n.statementEnd)}`;return e.slice(0,n.exportStart)+r}const Pt=new Set([`node_modules`,`.git`,`.cache`,`dist`]);function Ft(e,t){let n=new Set,r=e=>{if(!D.existsSync(e))return;let i=D.readdirSync(e,{withFileTypes:!0});for(let a of i){let i=k.join(e,a.name);if(a.isDirectory()){if(Pt.has(a.name))continue;r(i)}else if(a.isFile()&&v.test(a.name)){if(n.has(i))continue;n.add(i),t(i)}}};for(let t of e)t&&D.existsSync(t)&&r(t)}function It(e){let t=[];return Ft(e,e=>{t.push(e)}),t}function Lt(e,t=[]){let n=[e],r=k.resolve(e);for(let e of t){if(!e)continue;let t=k.resolve(e);if(t===r)continue;let i=k.relative(r,t);if(!(i===``||!i.startsWith(`..`)&&!k.isAbsolute(i)))try{D.statSync(e).isDirectory()&&n.push(e)}catch{}}return n}const Rt=new Set(T);function zt(e){return Rt.has(e)}function Bt(e){for(let t of e.importSources)if(t.startsWith(`node:`)||zt(t))return!0;return!1}function Vt(e,t=Rt){let n=[];for(let r of e)!r.startsWith(`.`)&&!r.startsWith(`/`)&&!r.startsWith(`@/`)&&!r.startsWith(`node:`)&&!t.has(r)&&n.push(r);return[...new Set(n)]}function Ht(e){let t=[];for(let n of e)(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`@/`))&&t.push(n);return t}function J(e){try{return D.realpathSync(e)}catch{return k.resolve(e)}}function Ut(e,t){e.delete(t);try{e.delete(D.realpathSync(t))}catch{e.delete(k.resolve(t))}}function Wt(e,t){let n=[];for(let r of It(e))try{t.get(r).directives.hasUseClient&&n.push(r)}catch{}return n}var Gt=class{cache=new Map;get(e,t){let n=J(e),r=this.cache.get(n);if(t!==void 0){if(r?.source===t)return r.analysis}else if(r){let e=this.readMtimeMs(n);if(e>=0&&r.mtimeMs===e)return r.analysis}t??=D.readFileSync(n,`utf-8`);let i=this.readMtimeMs(n),a=G(t);return this.cache.set(n,{mtimeMs:i,source:t,analysis:a}),a}getSource(e){return this.get(e),this.cache.get(J(e)).source}invalidate(e){Ut(this.cache,e)}clear(){this.cache.clear()}readMtimeMs(e){try{return D.statSync(e).mtimeMs}catch{return-1}}},Kt=class extends Error{status;statusText;bodyPreview;constructor(e,t,n){super(`HTTP ${e}: ${t}`),this.name=`HttpError`,this.status=e,this.statusText=t,this.bodyPreview=n}};async function qt(e){if(!e.ok){let t;try{t=await e.text()}catch{t=`<unable to read response body>`}let n=t.length>200?`${t.slice(0,200)}...`:t;throw new Kt(e.status,e.statusText,n)}}var Jt=class{errorCount=0;maxErrors;resetTimeout;resetTimer=null;lastError=null;constructor(e={}){this.maxErrors=e.maxErrors??5,this.resetTimeout=e.resetTimeout??3e4}recordError(e){this.errorCount++,this.lastError=e,this.resetTimer=ue(this.resetTimer),this.resetTimer=setTimeout(()=>{this.reset()},this.resetTimeout),this.errorCount>=this.maxErrors&&this.handleMaxErrorsReached()}reset(){this.errorCount=0,this.lastError=null,this.resetTimer=ue(this.resetTimer)}getErrorCount(){return this.errorCount}getLastError(){return this.lastError}hasReachedMaxErrors(){return this.errorCount>=this.maxErrors}handleMaxErrorsReached(){console.error(`[rari] HMR: Maximum error count (${this.maxErrors}) reached. Consider restarting the dev server if issues persist.`)}dispose(){this.reset()}};function Yt(e,t,n){let r=new Set(t),i=new Set,a=[...t];for(;a.length>0;){let t=a.pop();if(t==null)break;let o=e.get(t);if(o)for(let e of o)r.has(e)||(r.add(e),a.push(e),(n==null||n(e))&&i.add(e))}return i}function Xt(e){return a(e)&&e.success===!0&&typeof e.componentId==`string`&&typeof e.filePath==`string`&&typeof e.relativePath==`string`}function Zt(e){return a(e)&&e.success===!1&&typeof e.filePath==`string`&&typeof e.relativePath==`string`&&e.error instanceof Error}function Qt(e){return e===`info`||e===`success`||e===`warning`||e===`error`}var $t=class{serverComponentBuilder;rustServerUrl;pendingUpdates=new Map;pendingFiles=new Set;batchTimer=null;DEBOUNCE_DELAY=200;errorHandler;logBatch=[];logBatchTimer=null;LOG_BATCH_DELAY=500;constructor(e,t=F()){this.serverComponentBuilder=e,this.rustServerUrl=`http://localhost:${t}`,this.errorHandler=new Jt({maxErrors:5,resetTimeout:3e4})}getErrorCount(){return this.errorHandler.getErrorCount()}async handleClientComponentUpdate(e,t){let n=k.relative(A.cwd(),e);try{let r=t.moduleGraph.getModuleById(e);r?(t.moduleGraph.invalidateModule(r),this.errorHandler.reset()):this.queueLog(`warning`,`Client component module not found in graph: ${n}`)}catch(e){let t=e instanceof Error?e.message:String(e);this.queueLog(`error`,`Failed to update client component: ${n} - ${t}`),this.errorHandler.recordError(e instanceof Error?e:Error(t))}return Promise.resolve()}async handleServerComponentUpdate(e,t){this.pendingFiles.add(e);let n=this.pendingUpdates.get(e);return n&&(clearTimeout(n),this.pendingUpdates.delete(e)),this.batchTimer&&clearTimeout(this.batchTimer),this.batchTimer=setTimeout(()=>{(async()=>{let e=[...this.pendingFiles];if(this.pendingFiles.clear(),this.batchTimer=null,e.length===0)return;let n=this.collectDependentPageComponents(e);for(let e of n)this.serverComponentBuilder.invalidateBuildCacheFor(e);let r=[...e,...n],i=await Promise.allSettled(r.map(async e=>{let t=k.relative(A.cwd(),e);try{let n=await this.serverComponentBuilder.rebuildComponent(e);if(!n.success)throw Error(n.error!=null&&n.error!==``?n.error:`Build failed`);return await this.notifyRustServer(n.componentId,n.bundlePath),{success:!0,componentId:n.componentId,filePath:e,relativePath:t}}catch(n){return{success:!1,filePath:e,relativePath:t,error:n instanceof Error?n:Error(String(n))}}})),a=[],o=[];if(i.forEach(e=>{e.status===`fulfilled`&&Xt(e.value)?a.push(e.value):e.status===`fulfilled`&&Zt(e.value)?o.push(e.value):e.status===`rejected`&&o.push({filePath:``,relativePath:`unknown`,error:Error(String(e.reason))})}),a.length>0){let e=Date.now();a.forEach(({componentId:n})=>{t.hot.send(`rari:server-component-updated`,{id:n,t:e})}),this.errorHandler.reset(),t.ws.send({type:`custom`,event:`rari:hmr-error-cleared`,data:{t:e}})}if(o.length>0){let e=Date.now();o.forEach(({relativePath:n,error:r})=>{let i=r.message,a=(r.stack!=null&&r.stack!==``?r.stack:``).substring(0,500);this.queueLog(`error`,`Failed to rebuild: ${n} - ${i}`),this.errorHandler.recordError(r),t.ws.send({type:`custom`,event:`rari:hmr-error`,data:{msg:i,stack:a,file:n,t:e,count:this.errorHandler.getErrorCount(),max:5}})}),this.errorHandler.hasReachedMaxErrors()&&this.queueLog(`error`,`Maximum error count reached (${this.errorHandler.getErrorCount()}). Consider restarting the dev server if issues persist.`)}})()},this.DEBOUNCE_DELAY),Promise.resolve()}async notifyRustServer(e,t){try{let n=await fetch(`${this.rustServerUrl}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`reload-component`,component_id:e,bundle_path:t})});await qt(n);let r=await n.text(),i;try{i=JSON.parse(r)}catch(e){throw Error(`Failed to parse server response (status ${n.status}): ${e instanceof Error?e.message:String(e)}. Response body: ${r.substring(0,200)}${r.length>200?`...`:``}`)}if(!a(i))throw Error(`Invalid server response (status ${n.status}): expected object, got ${typeof i}. Response body: ${r.substring(0,200)}${r.length>200?`...`:``}`);if(i.success!==!0){let e=typeof i.message==`string`&&i.message!==``?i.message:typeof i.error==`string`&&i.error!==``?i.error:`Component reload failed`;throw Error(e)}}catch(e){throw console.error(`[rari] HMR: Failed to notify Rust server:`,e),e}}collectDependentPageComponents(e){return[...Yt(this.serverComponentBuilder.getImportGraph(),e,e=>e.includes(`/app/`)||e.includes(`\\app\\`))]}detectComponentType(e){try{return this.serverComponentBuilder.getModuleAnalysis(e).topLevelUseClient?`client`:`server`}catch{return`unknown`}}queueLog(e,t){this.logBatch.push({type:e,message:t,timestamp:Date.now()}),this.logBatchTimer&&clearTimeout(this.logBatchTimer),this.logBatchTimer=setTimeout(()=>{this.flushLogs()},this.LOG_BATCH_DELAY)}flushLogs(){if(this.logBatch.length===0)return;let e=this.logBatch.reduce((e,t)=>(e[t.type]??=[],e[t.type].push(t),e),{});for(let[t,n]of Object.entries(e))if(Qt(t))if(n.length===1){let e=n[0];this.outputLog(t,e.message)}else{let e=n.map(e=>e.message).join(`
|
|
48
|
-
• `);this.outputLog(t,`${n.length} updates:\n • ${e}`)}this.logBatch=[],this.logBatchTimer=null}outputLog(e,t){let n=`[rari] HMR:`;switch(e){case`success`:console.warn(`\x1B[32m${n}\x1B[0m ${t}`);break;case`warning`:console.warn(`\x1B[33m${n}\x1B[0m ${t}`);break;case`error`:console.error(`\x1B[31m${n}\x1B[0m ${t}`);break;default:console.warn(`${n} ${t}`)}}dispose(){this.logBatchTimer&&(clearTimeout(this.logBatchTimer),this.flushLogs()),this.batchTimer&&=(clearTimeout(this.batchTimer),null);for(let e of this.pendingUpdates.values())clearTimeout(e);this.pendingUpdates.clear(),this.pendingFiles.clear(),this.errorHandler.dispose()}};function
|
|
47
|
+
};`,`edge $$FORM_ACTION return block`),`browser registerBoundServerReference`)}function I(e,t=8){return he.createHash(`sha256`).update(e).digest(`hex`).slice(0,t)}function Qe(e,t=k.cwd()){let n=O.isAbsolute(e)?e:O.resolve(t,e),r=O.relative(t,n);return O.isAbsolute(r)?n.replace(x,`/`):r.replace(x,`/`)}function $e(e){return e.replace(v,``).replace(ee,`_`).replace(b,``)}function et(e,t=k.cwd()){let n=Qe(e,t);return`${$e(n)}_${I(n)}`}const tt=new Set([`return`,`throw`,`case`,`typeof`,`instanceof`,`new`,`delete`,`void`,`in`,`of`]),nt=8232,rt=8233;function L(e){return e===32||e===9||e===13||e===10||e===nt||e===rt||e===65279}function R(e){return e===13||e===10||e===nt||e===rt}function z(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95||e===36}function it(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function at(e,t,n){for(;t<n&&L(e.charCodeAt(t));)t++;return t}function B(e,t,n){for(;t<n;){let r=at(e,t,n);if(r!==t){t=r;continue}let i=e.charCodeAt(t);if(i===47&&e.charCodeAt(t+1)===47){t=V(e,t,n);continue}if(i===47&&e.charCodeAt(t+1)===42){t=H(e,t,n);continue}break}return t}function V(e,t,n){for(;t<n&&!R(e.charCodeAt(t));)t++;return t}function H(e,t,n){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;return t+2}function U(e,t,n,r){for(t++;t<n;){let n=e.charCodeAt(t);if(n===92){t+=2;continue}if(n===r)return t+1;t++}return t}function ot(e,t,n){t++;let r=e.charCodeAt(t)===47;for(r&&t++;t<n;){let n=e.charCodeAt(t);if(z(n)||n===46||n===45)t++;else break}let i=+!r;for(;t<n&&i>0;){let a=e.charCodeAt(t);if(a===39||a===34||a===96){t=U(e,t,n,a);continue}if(a===123){t++;let r=1;for(;t<n&&r>0;){let i=e.charCodeAt(t);if(i===39||i===34||i===96){t=U(e,t,n,i);continue}i===123&&r++,i===125&&r--,t++}continue}if(a===47&&e.charCodeAt(t+1)===62){i--,t+=2;continue}if(a===62){t++,r&&i--;continue}if(a===60){let r=e.charCodeAt(t+1);if(r===47||r===46||r===62||it(r)){for(r===47?(i--,t++):r!==33&&i++,t++;t<n;){let n=e.charCodeAt(t);if(z(n)||n===46||n===45)t++;else break}continue}t++;continue}t++}return t}function st(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function W(e,t,n){if(t+n.length>e.length)return!1;for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;let r=t>0?e.charCodeAt(t-1):-1,i=t+n.length,a=i<e.length?e.charCodeAt(i):-1;return!(r!==-1&&z(r)||a!==-1&&z(a))}function ct(e,t,n){let r=B(e,t,n);if(r>=n)return null;let i=e.charCodeAt(r);if(i!==39&&i!==34)return null;let a=r+1,o=U(e,r,n,i);return o<=a?null:{source:e.slice(a,o-1),end:o}}function lt(e,t,n){if(!W(e,t,`import`))return{sources:[],end:t+6};let r=t+6;if(r=B(e,r,n),W(e,r,`type`)&&(r=B(e,r+4,n)),e.charCodeAt(r)===46){for(r++;r<n&&z(e.charCodeAt(r));)r++;for(;r<n&&e.charCodeAt(r)===46;)for(r++;r<n&&z(e.charCodeAt(r));)r++;return{sources:[],end:r}}if(e.charCodeAt(r)===40){r++;let t=ct(e,r,n);return t?{sources:[t.source],end:t.end}:{sources:[],end:r}}let i=ct(e,r,n);if(i)return{sources:[i.source],end:i.end};let a=0;for(;r<n&&(r=B(e,r,n),!(r>=n));){let t=e.charCodeAt(r);if(a===0&&W(e,r,`from`)){let t=ct(e,r+4,n);if(t)return{sources:[t.source],end:t.end};break}if(t===39||t===34||t===96){r=U(e,r,n,t);continue}t===123||t===40||t===91?a++:(t===125||t===41||t===93)&&(a=Math.max(0,a-1)),r++}return{sources:[],end:r}}function ut(e,t){return e.charCodeAt(t)===101&&e.charCodeAt(t+1)===120&&e.charCodeAt(t+2)===112&&e.charCodeAt(t+3)===111&&e.charCodeAt(t+4)===114&&e.charCodeAt(t+5)===116}function dt(e,t){return e.charCodeAt(t)===100&&e.charCodeAt(t+1)===101&&e.charCodeAt(t+2)===102&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===117&&e.charCodeAt(t+5)===108&&e.charCodeAt(t+6)===116}function G(e){let t={hasUseClient:!1,hasUseServer:!1},n=!1,r=!1,i=!1,a=!1,o=[],s=!0,c=!1,l=0,u=e.length;for(;l<u;){let d=e.charCodeAt(l);if(s&&(d===39||d===34)){let i=l+1,a=U(e,l,u,d);if(a<=i){s=!1,l++;continue}let o=a-1-i,f=o===10&&st(e,i,`use client`),p=o===10&&st(e,i,`use server`);c||(c=!0,n=f,r=p),f&&(t.hasUseClient=!0),p&&(t.hasUseServer=!0);let m=a,h=!1;for(;m<u;){let t=e.charCodeAt(m);if(L(t)&&!R(t)){m++;continue}if(R(t)||t===59){h=!0,l=m+1;break}if(t===47&&e.charCodeAt(m+1)===47){m=V(e,m,u);continue}if(t===47&&e.charCodeAt(m+1)===42){m=H(e,m,u);continue}s=!1,h=!1;break}if(!h){m>=u&&(s=!1),l=s?a:m;continue}continue}let f=q(e,l,u);if(f!==-1){s&&!Dt(e,l)&&(s=!1),l=f;continue}if(s=!1,W(e,l,`import`)){let t=lt(e,l,u);for(let e of t.sources)o.push(e);l=t.end;continue}if(ut(e,l)){let t=l+6;if(t<u){let n=e.charCodeAt(t);if(L(n)||n===123||n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)){let n=B(e,t,u);if(dt(e,n)){i=!0,a=!0;let r=n+7;if(r>=u||!z(e.charCodeAt(r))){l=t;continue}}if(e.charCodeAt(n)===123){let t=n+1;for(;t<u&&(t=B(e,t,u),e.charCodeAt(t)!==125);){let n=t;for(;t<u&&z(e.charCodeAt(t));)t++;let r=t-n;if(r===0)break;t=B(e,t,u);let o=!1;if(e.charCodeAt(t)===97&&e.charCodeAt(t+1)===115){o=!0;let n=t+2;if(n<u&&!z(e.charCodeAt(n))){t=B(e,n,u);let r=t;for(;t<u&&z(e.charCodeAt(t));)t++;t-r===7&&dt(e,r)&&(i=!0,a=!0)}}if(!o&&r===7&&dt(e,n)&&(i=!0,a=!0),e.charCodeAt(t)===44){t++;continue}if(e.charCodeAt(t)===125)break;t++}}else(W(e,n,`async`)||W(e,n,`function`)||W(e,n,`class`))&&(a=!0)}}}l++}return{directives:t,topLevelUseClient:n,topLevelUseServer:r,hasDefaultExport:i,hasComponentExport:a,importSources:[...new Set(o)]}}function K(e,t,n){if(t>=n||!it(e.charCodeAt(t)))return null;let r=t+1;for(;r<n&&z(e.charCodeAt(r));)r++;return{name:e.slice(t,r),end:r}}function ft(e,t,n){let r=t;for(;r<n;){let t=e.charCodeAt(r);if(t===32||t===9){r++;continue}if(t===59)return r+1;break}return t}function pt(e,t,n){let r=[],i=t+1;for(;;){if(i=B(e,i,n),i>=n)return null;if(e.charCodeAt(i)===125)return{named:r,end:i+1};let t=!1;if(W(e,i,`type`)){let r=B(e,i+4,n),a=e.charCodeAt(r);(a===39||a===34||K(e,r,n)!==null)&&!W(e,r,`as`)&&(t=!0,i=r)}let a,o=e.charCodeAt(i);if(o===39||o===34){let t=U(e,i,n,o);a=e.slice(i+1,t-1),i=t}else{let t=K(e,i,n);if(!t)return null;a=t.name,i=t.end}i=B(e,i,n);let s=a;if(W(e,i,`as`)){i=B(e,i+2,n);let t=K(e,i,n);if(!t)return null;s=t.name,i=B(e,t.end,n)}r.push({imported:a,local:s,typeOnly:t});let c=e.charCodeAt(i);if(c===44){i++;continue}return c===125?{named:r,end:i+1}:null}}function mt(e,t,n){let r=B(e,t+6,n);if(r>=n)return null;let i=e.charCodeAt(r);if(i===40||i===46)return null;if(i===39||i===34){let i=ct(e,r,n);return i?{start:t,end:ft(e,i.end,n),source:i.source,typeOnly:!1,sideEffectOnly:!0,defaultBinding:null,namespaceBinding:null,named:[]}:null}let a=!1;if(W(e,r,`type`)){let t=B(e,r+4,n);!W(e,t,`from`)&&e.charCodeAt(t)!==44&&(a=!0,r=t)}let o=null,s=null,c=[],l=e.charCodeAt(r);if(l!==123&&l!==42){let t=K(e,r,n);if(!t)return null;o=t.name,r=B(e,t.end,n),e.charCodeAt(r)===44?(r=B(e,r+1,n),l=e.charCodeAt(r)):l=-1}if(l===42){if(r=B(e,r+1,n),!W(e,r,`as`))return null;r=B(e,r+2,n);let t=K(e,r,n);if(!t)return null;s=t.name,r=t.end}else if(l===123){let t=pt(e,r,n);if(!t)return null;c=t.named,r=t.end}if(r=B(e,r,n),!W(e,r,`from`))return null;let u=ct(e,r+4,n);return u?{start:t,end:ft(e,u.end,n),source:u.source,typeOnly:a,sideEffectOnly:!1,defaultBinding:o,namespaceBinding:s,named:c}:null}function ht(e){let t=[],n=0,r=e.length;for(;n<r;){let i=q(e,n,r);if(i!==-1){n=i;continue}if(W(e,n,`import`)){let i=mt(e,n,r);if(i){t.push(i),n=i.end;continue}n+=6;continue}n++}return t}function gt(e){let t=new Set,n=0,r=e.length;for(;n<r;){let i=q(e,n,r);if(i!==-1){n=i;continue}if(!W(e,n,`export`)){n++;continue}let a=B(e,n+6,r);if(W(e,a,`type`)||W(e,a,`interface`)){n=a+1;continue}if(e.charCodeAt(a)===42){let i=B(e,a+1,r);if(W(e,i,`as`)){i=B(e,i+2,r);let a=K(e,i,r);a&&t.add(a.name),n=a?.end??i+1}else n=a+1;continue}if(W(e,a,`default`)){t.add(`default`),n=a+7;continue}if(e.charCodeAt(a)===123){let i=_t(e,a,r),o=e.slice(a+1,i-1);for(let e of o.split(`,`)){let n=e.trim();if(!n||n.startsWith(`type `)||n.startsWith(`typeof `))continue;let r=(n.split(/\s+as\s+/).at(-1)??``).trim();r!==``&&r!==`type`&&t.add(r)}n=i;continue}if(W(e,a,`async`)&&(a=B(e,a+5,r)),W(e,a,`function`)||W(e,a,`class`)||W(e,a,`const`)||W(e,a,`let`)||W(e,a,`var`)){let i=W(e,a,`function`)?8:W(e,a,`class`)||W(e,a,`const`)?5:3,o=B(e,a+i,r);e.charCodeAt(o)===42&&(o=B(e,o+1,r));let s=K(e,o,r);s&&t.add(s.name),n=s?.end??o+1;continue}n++}return[...t]}function _t(e,t,n){let r=t,i=0;for(;r<n;){let t=e.charCodeAt(r);if(t===39||t===34||t===96){r=U(e,r,n,t);continue}if(t===47&&e.charCodeAt(r+1)===47){r=V(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)===42){r=H(e,r,n);continue}if(t===123){i++,r++;continue}if(t===125){if(i--,r++,i===0)return r;continue}r++}return r}function vt(e){return G(e).hasDefaultExport}function yt(e){return e===40||e===91||e===123||e===44||e===59||e===61||e===58||e===63||e===33||e===43||e===45||e===42||e===37||e===38||e===124||e===94||e===126||e===60||e===62}function bt(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(L(t)){n--;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===42){for(n-=2;n>=1;){if(e.charCodeAt(n)===42&&e.charCodeAt(n-1)===47){n-=2;break}n--}if(n<0)return;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===47){n-=2;continue}let r=n;for(;r>=0&&e.charCodeAt(r)!==10&&e.charCodeAt(r)!==13;)r--;let i=r+1;for(;i<n&&(e.charCodeAt(i)===32||e.charCodeAt(i)===9);)i++;if(i<n&&e.charCodeAt(i)===47&&e.charCodeAt(i+1)===47){n=i-1;continue}break}if(n<0||!z(e.charCodeAt(n)))return;let r=n;for(;n>=0&&z(e.charCodeAt(n));)n--;return e.slice(n+1,r+1)}function xt(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(L(t)){n--;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===42){for(n-=2;n>=1;){if(e.charCodeAt(n)===42&&e.charCodeAt(n-1)===47){n-=2;break}n--}if(n<0)return-1;continue}if(n>=1&&t===47&&e.charCodeAt(n-1)===47){n-=2;continue}let r=n;for(;r>=0&&e.charCodeAt(r)!==10&&e.charCodeAt(r)!==13;)r--;let i=r+1;for(;i<n&&(e.charCodeAt(i)===32||e.charCodeAt(i)===9);)i++;if(i<n&&e.charCodeAt(i)===47&&e.charCodeAt(i+1)===47){n=i-1;continue}return t}return-1}function St(e,t){let n=xt(e,t);if(n===-1||yt(n))return!0;let r=bt(e,t);return r!=null&&r!==``&&tt.has(r)}const Ct=new Set([`return`,`throw`,`case`,`default`,`else`,`do`,`typeof`,`void`,`yield`,`await`,`delete`]);function wt(e,t){let n=xt(e,t);if(n===-1)return!0;if(z(n)||n>=48&&n<=57){let n=bt(e,t);return n!=null&&n!==``&&Ct.has(n)}return n!==41&&n!==93&&n!==125}function Tt(e,t,n){if(!wt(e,t))return-1;let r=e.charCodeAt(t+1);if(r!==47&&r!==46&&r!==62&&!it(r))return-1;let i=ot(e,t,n);return i<n&&e.charCodeAt(i)===62&&i++,i>t&&e.charCodeAt(i-1)===62?i:-1}function Et(e,t,n){t++;let r=!1;for(;t<n;){let i=e.charCodeAt(t);if(i===92){t+=2;continue}if(r){i===93&&(r=!1),t++;continue}if(i===91){r=!0,t++;continue}if(i===47){for(t++;t<n&&z(e.charCodeAt(t));)t++;return t}if(R(i))return t;t++}return t}function q(e,t,n){if(t>=n)return-1;let r=e.charCodeAt(t);if(L(r))return t+1;if(r===47&&e.charCodeAt(t+1)===47)return V(e,t,n);if(r===47&&e.charCodeAt(t+1)===42)return H(e,t,n);if(r===39||r===34||r===96)return U(e,t,n,r);if(r===47&&e.charCodeAt(t+1)!==47&&e.charCodeAt(t+1)!==42&&St(e,t))return Et(e,t,n);if(r===60){let r=Tt(e,t,n);if(r!==-1)return r}return-1}function Dt(e,t){let n=e.charCodeAt(t);return L(n)?!0:n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)}function Ot(e){let t=e.length,n=0;for(;n<t;){let r=q(e,n,t);if(r!==-1){n=r;continue}if(W(e,n,`export`)){let r=B(e,n+6,t);if(!W(e,r,`default`)){n++;continue}let i=B(e,r+7,t),a=i,o=null;if(W(e,a,`async`)){let n=B(e,a+5,t);W(e,n,`function`)&&(a=n)}if(W(e,a,`function`)||W(e,a,`class`)){let n=W(e,a,`function`)?8:5,r=B(e,a+n,t);e.charCodeAt(r)===42&&(r=B(e,r+1,t));let i=K(e,r,t);i&&(o=i.name)}let s=jt(e,i,t),c=ft(e,s,t);return{exportStart:n,valueStart:i,valueEnd:s,statementEnd:c,bindingName:o}}n++}return null}function kt(e,t,n){if(t>=n)return!1;let r=e.charCodeAt(t),i=t+1<n?e.charCodeAt(t+1):-1;return r===46||r===63&&i===46||r===40||r===91||r===96||r===61&&i===62||r===43||r===45||r===42||r===47||r===37||r===38||r===124||r===94||r===60||r===62||r===61||r===33||r===63||r===58||r===44||r===126||W(e,t,`instanceof`)||W(e,t,`in`)||W(e,t,`of`)||W(e,t,`as`)}const At=new Set([`typeof`,`void`,`delete`,`await`,`yield`,`new`]);function jt(e,t,n){let r=t,i=0,a=0,o=0,s=!1;for(;r<n;){let t=e.charCodeAt(r);if(t===39||t===34||t===96){r=U(e,r,n,t),s=!0;continue}if(t===47&&e.charCodeAt(r+1)===47){r=V(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)===42){r=H(e,r,n);continue}if(t===47&&e.charCodeAt(r+1)!==47&&e.charCodeAt(r+1)!==42&&St(e,r)){r=Et(e,r,n),s=!0;continue}if(t===60&&i===0&&a===0&&o===0){let t=Tt(e,r,n);if(t!==-1){r=t,s=!0;continue}}if(t===40){i++,s=!1,r++;continue}if(t===41){i=Math.max(0,i-1),s=!0,r++;continue}if(t===123){a++,s=!1,r++;continue}if(t===125){if(a=Math.max(0,a-1),s=!0,r++,i===0&&a===0&&o===0)return r;continue}if(t===91){o++,s=!1,r++;continue}if(t===93){o=Math.max(0,o-1),s=!0,r++;continue}if(i===0&&a===0&&o===0){if(t===59)return r;if(R(t)){let t=B(e,r+1,n);if(!s||kt(e,t,n)){r++;continue}return r}}if(it(t)){let t=K(e,r,n);if(t){s=!At.has(t.name),r=t.end;continue}}if(t>=48&&t<=57){for(s=!0,r++;r<n;){let t=e.charCodeAt(r);if(t>=48&&t<=57||t===46||t===110||t===101||t===69){r++;continue}break}continue}if(t===61&&e.charCodeAt(r+1)===62){s=!1,r+=2;continue}if(t===46||t===44||t===58||t===63||t===61||t===43||t===45||t===42||t===47||t===37||t===38||t===124||t===94||t===33||t===126||t===60||t===62){s=!1,r++;continue}r++}return r}function Mt(e,t){let n=Ot(e);if(n==null||n.bindingName!=null)return null;let r=`const ${t} = ${e.slice(n.valueStart,n.valueEnd).trimEnd()};\nexport default ${t}${e.slice(n.statementEnd)}`;return e.slice(0,n.exportStart)+r}const Nt=new Set([`node_modules`,`.git`,`.cache`,`dist`]);function Pt(e,t){let n=new Set,r=e=>{if(!E.existsSync(e))return;let i=E.readdirSync(e,{withFileTypes:!0});for(let a of i){let i=O.join(e,a.name);if(a.isDirectory()){if(Nt.has(a.name))continue;r(i)}else if(a.isFile()&&v.test(a.name)){if(n.has(i))continue;n.add(i),t(i)}}};for(let t of e)t&&E.existsSync(t)&&r(t)}function Ft(e){let t=[];return Pt(e,e=>{t.push(e)}),t}function It(e,t=[]){let n=[e],r=O.resolve(e);for(let e of t){if(!e)continue;let t=O.resolve(e);if(t===r)continue;let i=O.relative(r,t);if(!(i===``||!i.startsWith(`..`)&&!O.isAbsolute(i)))try{E.statSync(e).isDirectory()&&n.push(e)}catch{}}return n}const Lt=new Set(T);function Rt(e){return Lt.has(e)}function zt(e){for(let t of e.importSources)if(t.startsWith(`node:`)||Rt(t))return!0;return!1}function Bt(e,t=Lt){let n=[];for(let r of e)!r.startsWith(`.`)&&!r.startsWith(`/`)&&!r.startsWith(`@/`)&&!r.startsWith(`node:`)&&!t.has(r)&&n.push(r);return[...new Set(n)]}function Vt(e){let t=[];for(let n of e)(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`@/`))&&t.push(n);return t}function J(e){try{return E.realpathSync(e)}catch{return O.resolve(e)}}function Ht(e,t){e.delete(t);try{e.delete(E.realpathSync(t))}catch{e.delete(O.resolve(t))}}function Ut(e,t){let n=[];for(let r of Ft(e))try{t.get(r).directives.hasUseClient&&n.push(r)}catch{}return n}var Wt=class{cache=new Map;get(e,t){let n=J(e),r=this.cache.get(n);if(t!==void 0){if(r?.source===t)return r.analysis}else if(r){let e=this.readMtimeMs(n);if(e>=0&&r.mtimeMs===e)return r.analysis}t??=E.readFileSync(n,`utf-8`);let i=this.readMtimeMs(n),a=G(t);return this.cache.set(n,{mtimeMs:i,source:t,analysis:a}),a}getSource(e){return this.get(e),this.cache.get(J(e)).source}invalidate(e){Ht(this.cache,e)}clear(){this.cache.clear()}readMtimeMs(e){try{return E.statSync(e).mtimeMs}catch{return-1}}},Gt=class extends Error{status;statusText;bodyPreview;constructor(e,t,n){super(`HTTP ${e}: ${t}`),this.name=`HttpError`,this.status=e,this.statusText=t,this.bodyPreview=n}};async function Kt(e){if(!e.ok){let t;try{t=await e.text()}catch{t=`<unable to read response body>`}let n=t.length>200?`${t.slice(0,200)}...`:t;throw new Gt(e.status,e.statusText,n)}}var qt=class{errorCount=0;maxErrors;resetTimeout;resetTimer=null;lastError=null;constructor(e={}){this.maxErrors=e.maxErrors??5,this.resetTimeout=e.resetTimeout??3e4}recordError(e){this.errorCount++,this.lastError=e,this.resetTimer=ue(this.resetTimer),this.resetTimer=setTimeout(()=>{this.reset()},this.resetTimeout),this.errorCount>=this.maxErrors&&this.handleMaxErrorsReached()}reset(){this.errorCount=0,this.lastError=null,this.resetTimer=ue(this.resetTimer)}getErrorCount(){return this.errorCount}getLastError(){return this.lastError}hasReachedMaxErrors(){return this.errorCount>=this.maxErrors}handleMaxErrorsReached(){console.error(`[rari] HMR: Maximum error count (${this.maxErrors}) reached. Consider restarting the dev server if issues persist.`)}dispose(){this.reset()}};function Jt(e,t,n){let r=new Set(t),i=new Set,a=[...t];for(;a.length>0;){let t=a.pop();if(t==null)break;let o=e.get(t);if(o)for(let e of o)r.has(e)||(r.add(e),a.push(e),(n==null||n(e))&&i.add(e))}return i}function Yt(e){return a(e)&&e.success===!0&&typeof e.componentId==`string`&&typeof e.filePath==`string`&&typeof e.relativePath==`string`}function Xt(e){return a(e)&&e.success===!1&&typeof e.filePath==`string`&&typeof e.relativePath==`string`&&e.error instanceof Error}function Zt(e){return e===`info`||e===`success`||e===`warning`||e===`error`}var Qt=class{serverComponentBuilder;rustServerUrl;pendingUpdates=new Map;pendingFiles=new Set;batchTimer=null;DEBOUNCE_DELAY=200;errorHandler;logBatch=[];logBatchTimer=null;LOG_BATCH_DELAY=500;constructor(e,t=P()){this.serverComponentBuilder=e,this.rustServerUrl=`http://localhost:${t}`,this.errorHandler=new qt({maxErrors:5,resetTimeout:3e4})}getErrorCount(){return this.errorHandler.getErrorCount()}async handleClientComponentUpdate(e,t){let n=O.relative(k.cwd(),e);try{let r=t.moduleGraph.getModuleById(e);r?(t.moduleGraph.invalidateModule(r),this.errorHandler.reset()):this.queueLog(`warning`,`Client component module not found in graph: ${n}`)}catch(e){let t=e instanceof Error?e.message:String(e);this.queueLog(`error`,`Failed to update client component: ${n} - ${t}`),this.errorHandler.recordError(e instanceof Error?e:Error(t))}return Promise.resolve()}async handleServerComponentUpdate(e,t){this.pendingFiles.add(e);let n=this.pendingUpdates.get(e);return n&&(clearTimeout(n),this.pendingUpdates.delete(e)),this.batchTimer&&clearTimeout(this.batchTimer),this.batchTimer=setTimeout(()=>{(async()=>{let e=[...this.pendingFiles];if(this.pendingFiles.clear(),this.batchTimer=null,e.length===0)return;let n=this.collectDependentPageComponents(e);for(let e of n)this.serverComponentBuilder.invalidateBuildCacheFor(e);let r=[...e,...n],i=await Promise.allSettled(r.map(async e=>{let t=O.relative(k.cwd(),e);try{let n=await this.serverComponentBuilder.rebuildComponent(e);if(!n.success)throw Error(n.error!=null&&n.error!==``?n.error:`Build failed`);return await this.notifyRustServer(n.componentId,n.bundlePath),{success:!0,componentId:n.componentId,filePath:e,relativePath:t}}catch(n){return{success:!1,filePath:e,relativePath:t,error:n instanceof Error?n:Error(String(n))}}})),a=[],o=[];if(i.forEach(e=>{e.status===`fulfilled`&&Yt(e.value)?a.push(e.value):e.status===`fulfilled`&&Xt(e.value)?o.push(e.value):e.status===`rejected`&&o.push({filePath:``,relativePath:`unknown`,error:Error(String(e.reason))})}),a.length>0){let e=Date.now();a.forEach(({componentId:n})=>{t.hot.send(`rari:server-component-updated`,{id:n,t:e})}),this.errorHandler.reset(),t.ws.send({type:`custom`,event:`rari:hmr-error-cleared`,data:{t:e}})}if(o.length>0){let e=Date.now();o.forEach(({relativePath:n,error:r})=>{let i=r.message,a=(r.stack!=null&&r.stack!==``?r.stack:``).substring(0,500);this.queueLog(`error`,`Failed to rebuild: ${n} - ${i}`),this.errorHandler.recordError(r),t.ws.send({type:`custom`,event:`rari:hmr-error`,data:{msg:i,stack:a,file:n,t:e,count:this.errorHandler.getErrorCount(),max:5}})}),this.errorHandler.hasReachedMaxErrors()&&this.queueLog(`error`,`Maximum error count reached (${this.errorHandler.getErrorCount()}). Consider restarting the dev server if issues persist.`)}})()},this.DEBOUNCE_DELAY),Promise.resolve()}async notifyRustServer(e,t){try{let n=await fetch(`${this.rustServerUrl}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`reload-component`,component_id:e,bundle_path:t})});await Kt(n);let r=await n.text(),i;try{i=JSON.parse(r)}catch(e){throw Error(`Failed to parse server response (status ${n.status}): ${e instanceof Error?e.message:String(e)}. Response body: ${r.substring(0,200)}${r.length>200?`...`:``}`)}if(!a(i))throw Error(`Invalid server response (status ${n.status}): expected object, got ${typeof i}. Response body: ${r.substring(0,200)}${r.length>200?`...`:``}`);if(i.success!==!0){let e=typeof i.message==`string`&&i.message!==``?i.message:typeof i.error==`string`&&i.error!==``?i.error:`Component reload failed`;throw Error(e)}}catch(e){throw console.error(`[rari] HMR: Failed to notify Rust server:`,e),e}}collectDependentPageComponents(e){return[...Jt(this.serverComponentBuilder.getImportGraph(),e,e=>e.includes(`/app/`)||e.includes(`\\app\\`))]}detectComponentType(e){try{return this.serverComponentBuilder.getModuleAnalysis(e).topLevelUseClient?`client`:`server`}catch{return`unknown`}}queueLog(e,t){this.logBatch.push({type:e,message:t,timestamp:Date.now()}),this.logBatchTimer&&clearTimeout(this.logBatchTimer),this.logBatchTimer=setTimeout(()=>{this.flushLogs()},this.LOG_BATCH_DELAY)}flushLogs(){if(this.logBatch.length===0)return;let e=this.logBatch.reduce((e,t)=>(e[t.type]??=[],e[t.type].push(t),e),{});for(let[t,n]of Object.entries(e))if(Zt(t)){if(n.length===1){let e=n[0];this.outputLog(t,e.message)}else{let e=n.map(e=>e.message).join(`
|
|
48
|
+
• `);this.outputLog(t,`${n.length} updates:\n • ${e}`)}}this.logBatch=[],this.logBatchTimer=null}outputLog(e,t){let n=`[rari] HMR:`;switch(e){case`success`:console.warn(`\x1B[32m${n}\x1B[0m ${t}`);break;case`warning`:console.warn(`\x1B[33m${n}\x1B[0m ${t}`);break;case`error`:console.error(`\x1B[31m${n}\x1B[0m ${t}`);break;default:console.warn(`${n} ${t}`)}}dispose(){this.logBatchTimer&&(clearTimeout(this.logBatchTimer),this.flushLogs()),this.batchTimer&&=(clearTimeout(this.batchTimer),null);for(let e of this.pendingUpdates.values())clearTimeout(e);this.pendingUpdates.clear(),this.pendingFiles.clear(),this.errorHandler.dispose()}};function $t(e){let t=e.replace(x,`/`);return t===`rari/mdx/registry`||t.startsWith(`rari/mdx/registry?`)?!0:t.endsWith(`/mdx/registry.ts`)||t.endsWith(`/mdx/registry.mts`)||t.endsWith(`/mdx/registry.mjs`)||t.endsWith(`/mdx/registry.js`)||t.endsWith(`/mdx/registry`)?t.includes(`/node_modules/rari/`)||t.includes(`/packages/rari/`):!1}function en(e,t){let n=e=>{if(E.existsSync(e))for(let r of E.readdirSync(e,{withFileTypes:!0})){let i=O.join(e,r.name);if(r.isDirectory()){if(r.name===`node_modules`||r.name===`.git`||r.name===`dist`)continue;n(i)}else r.isFile()&&r.name.endsWith(`.mdx`)&&t(i)}};for(let t of e)t&&E.existsSync(t)&&n(t)}function tn(e){let t=new Set;return en(e,e=>{try{let n=E.readFileSync(e,`utf-8`);for(let e of w(n))t.add(e)}catch{}}),t}function nn(e,t){try{if(t.get(e).hasDefaultExport)return O.basename(e,O.extname(e));let n=t.getSource(e).match(te);if(n?.[1]!=null&&n[1]!==``)return n[1]}catch{}return O.basename(e,O.extname(e))}function rn(e){let t=tn(e.contentDirs.map(t=>O.join(e.projectRoot,t)));if(t.size===0)return[];let n=Ut(e.componentScanDirs,e.cache),r=[],i=new Set;for(let a of n){let n=nn(a,e.cache);if(n==null||n===``||!t.has(n))continue;let o=Qe(a,e.projectRoot).replace(x,`/`),s=o.startsWith(`/`)?o:`/${o}`,c=n.replace(/[^\w$]/g,`_`);i.has(c)&&(c=`${c}_${r.length}`),i.add(c),r.push({name:n,binding:c,importPath:s,moduleId:o,client:!0})}return r.sort((e,t)=>e.name.localeCompare(t.name))}function an(e){let t=sn(e.projectRoot,e.mdxOptions),n=e.srcDir??O.join(e.projectRoot,`src`),r=cn(e.projectRoot,t.componentsDir,It(n,Object.values(e.alias??{})));return rn({projectRoot:e.projectRoot,componentsDir:t.componentsDir,contentDirs:t.contentDirs,cache:e.cache,componentScanDirs:r})}function on(e,t={}){let n=t.importStyle??`root-absolute`,r=t.mode??`vite`;return e.length===0?`import { defineMdxComponents } from 'rari/mdx/define'
|
|
49
49
|
|
|
50
50
|
export const getMDXComponents = defineMdxComponents([])
|
|
51
51
|
`:r===`production`?`import { defineMdxComponents } from 'rari/mdx/define'
|
|
@@ -62,15 +62,15 @@ export const getMDXComponents = defineMdxComponents([
|
|
|
62
62
|
${e.map(e=>` { name: ${JSON.stringify(e.name)}, component: ${e.binding}, id: ${JSON.stringify(e.moduleId)}, client: ${e.client} }`).join(`,
|
|
63
63
|
`)},
|
|
64
64
|
])
|
|
65
|
-
`}function
|
|
65
|
+
`}function sn(e,t){return{componentsDir:t?.componentsDir??`src/components`,contentDirs:t?.contentDirs??[`public/content`,`content`]}}function cn(e,t,n){let r=O.join(e,t),i=new Set(n);return E.existsSync(r)&&i.add(r),[...i]}function ln(e,t,n){if(n.length===0)return e;let r=ht(e).find(e=>e.source===t&&!e.typeOnly&&!e.sideEffectOnly),i=new Map;if(r!=null)for(let e of r.named)e.typeOnly||i.set(e.imported,e.local);for(let e of n)i.has(e)||i.set(e,e);let a=[...i.entries()].map(([e,t])=>e===t?e:`${e} as ${t}`);if(r?.namespaceBinding!=null||r?.named.some(e=>e.typeOnly)){let i=n.filter(e=>!r.named.some(t=>!t.typeOnly&&t.imported===e));return i.length===0?e:`${`import { ${[...new Set(i)].join(`, `)} } from ${JSON.stringify(t)};`}\n${e}`}let o=`import ${r?.defaultBinding==null?``:`${r.defaultBinding}, `}{ ${a.join(`, `)} } from ${JSON.stringify(t)};`;return r==null?`${o}\n\n${e}`:e.slice(0,r.start)+o+e.slice(r.end)}function un(e,t){return`const ${e} = createClientModuleProxy(${JSON.stringify(t)});`}function dn(e,t,n){return`const ${e} = registerClientReference(
|
|
66
66
|
function() {
|
|
67
67
|
throw new Error("Attempted to call ${e} from the server but it's on the client. It can only be rendered as a Component or passed to props of a Client Component.");
|
|
68
68
|
},
|
|
69
69
|
${JSON.stringify(t)},
|
|
70
70
|
${JSON.stringify(n)}
|
|
71
|
-
);`}function
|
|
72
|
-
`),helpers:[...r]}}function
|
|
73
|
-
`)}\n`}function
|
|
71
|
+
);`}function fn(e,t){let n=[],r=new Set;e.namespaceBinding!=null&&(r.add(`createClientModuleProxy`),n.push(un(e.namespaceBinding,t))),e.defaultBinding!=null&&(r.add(`registerClientReference`),n.push(dn(e.defaultBinding,t,`default`)));for(let i of e.named)i.typeOnly||(r.add(`registerClientReference`),n.push(dn(i.local,t,i.imported)));return n.length===0?{code:``,helpers:[]}:{code:n.join(`
|
|
72
|
+
`),helpers:[...r]}}function pn(e,t){let n=t.length>0?t:[`default`],r=[`import { registerClientReference } from ${JSON.stringify(`react-server-dom-rari/server`)};`];for(let t of n)t==="default"?r.push(`export default registerClientReference(null, ${JSON.stringify(e)}, "default");`):r.push(`export const ${t} = registerClientReference(null, ${JSON.stringify(e)}, ${JSON.stringify(t)});`);return`${r.join(`
|
|
73
|
+
`)}\n`}function mn(e,t,n){let r=n==="default"?`if (Component && typeof Component === 'object' && Component.default) {
|
|
74
74
|
Component = Component.default;
|
|
75
75
|
}`:`if (Component && typeof Component === 'object') {
|
|
76
76
|
Component = Component[${JSON.stringify(n)}] ?? Component.default?.[${JSON.stringify(n)}];
|
|
@@ -90,16 +90,16 @@ const ${e} = (props) => {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
return Component(props);
|
|
93
|
-
}`}function
|
|
93
|
+
}`}function hn(e,t){return`// Component namespace reference: ${t}
|
|
94
94
|
const ${e} = globalThis['~clientComponents']?.[${JSON.stringify(t)}]?.component
|
|
95
95
|
|| globalThis[${JSON.stringify(t)}]
|
|
96
|
-
|| {};`}const
|
|
97
|
-
`)}\n`,actionNames:i,rewrittenExportNames:a}}let
|
|
98
|
-
`)}\n`,i=`${
|
|
99
|
-
`)})}if(t.length===0)return e;let n=e;for(let{start:e,end:r,replacement:i}of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e)+i+n.slice(r);return n}isPageComponent(e){return e.includes(`/app/`)||e.includes(`\\app\\`)}createRolldownModuleInfoPlugin(e){let t=new Set;return{name:`rari-rolldown-module-info`,moduleParsed(e){for(let n of e.importedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n)},buildEnd:()=>{if(t.size===0)return;let n=[...t].sort(),r=this.serverComponents.get(e)??this.serverActions.get(e);r&&(r.dependencies=n);let i=this.buildCache.get(e);i&&(i.bundledDependencies=n)}}}createBuildPlugins(e,t,n,r,i=!1,a){let o=k.dirname(r),s=Wn.test(k.basename(r)),c=new Map,l=new Map;return[{name:`virtual-module`,resolveId(t,n){if(t===e)return t;if(n===e&&(t.startsWith(`./`)||t.startsWith(`../`))){if(t.endsWith(`.module.css`))return null;let e=k.resolve(o,t);for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`,``]){let n=e+t;if(D.existsSync(n)&&D.statSync(n).isFile())return n}for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(e,`index${t}`);if(D.existsSync(n))return n}return e}return null},load(r){return r===e?{code:t,moduleType:n}:null}},{name:`resolve-client-server-boundaries`,enforce:`pre`,resolveId:(t,n)=>{if(n==null||n===``||n.includes(`node_modules`)||tr(n)||t.startsWith(`node:`)||zt(t)||t===`react`||t===`react-dom`||t===`react/jsx-runtime`||t===`react/jsx-dev-runtime`)return null;let r=null,i=this.options.alias;if(r=C(t,i,this.projectRoot),(r==null||r===``)&&(t.startsWith(`./`)||t.startsWith(`../`))){let i=n===e?o:k.dirname(n);r=k.resolve(i,t)}if((r==null||r===``)&&k.isAbsolute(t)&&(r=t),r!==``)for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=r+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)){let e=k.relative(this.projectRoot,t),n=(e.startsWith(`..`)?t:e).replace(x,`/`);return c.set(t,n),e.startsWith(`..`)&&this.discoveredExternalClientComponents.add(t),{id:`\0client-ref:${t}`}}try{let e=this.moduleAnalysisCache.get(t);if(e.directives.hasUseServer){let n=this.getComponentId(t);return l.set(t,{actionId:n,hasDefaultExport:e.hasDefaultExport}),{id:`\0server-action:${t}`}}}catch(e){console.error(`[rari] Failed to read file for server action detection: ${t}`,e)}break}}return null},load:e=>{if(e.startsWith(`\0client-ref:`)){let t=e.slice(12),n=k.relative(this.projectRoot,t),r=(c.get(t)??(n.startsWith(`..`)?t:n)).replace(x,`/`);return{code:this.generateClientReferenceStub(t,r),moduleType:`js`}}if(e.startsWith(`\0server-action:`)){let t=e.slice(15),n=l.get(t)?.actionId??this.getComponentId(t);return{code:this.generateServerActionRuntimeModule(t,n),moduleType:`js`}}return null}},{name:`use-transformed-server-components`,resolveId:(e,t)=>{if(!i)return null;if(e.startsWith(`file://`)){let t=e.replace(h,``);return D.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=C(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?k.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=k.resolve(a,e)),n==null||n===``||a.includes(`node_modules`))return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=n+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=k.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=k.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(D.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:D.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=C(e,this.options.alias,this.projectRoot);if(t==null||t===``)return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let n=t+e;if(D.existsSync(n)&&D.statSync(n).isFile()){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}for(let e of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(t,`index${e}`);if(D.existsSync(n)){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}return t}},{name:`resolve-rari-proxy`,resolveId:e=>{if(s&&e===`rari`){let e=k.join(er,`proxy/RariResponse.mjs`);if(D.existsSync(e))return e;let t=k.join($,`src/proxy/http/response.ts`);if(D.existsSync(t))return t}return null}},{name:`css-modules`,resolveId:(e,t)=>{if(e.endsWith(`.module.css`)){let n=t!=null&&t!==``&&!t.startsWith(`\0`)?k.dirname(t):o,r=k.resolve(n,e);if(D.existsSync(r))return{id:`\0css-module:${r}`}}return null},load:async e=>{if(!e.startsWith(`\0css-module:`))return null;let t=e.slice(12);try{let e=await cr(),n=D.readFileSync(t),r=e({filename:k.relative(this.projectRoot,t),code:n,cssModules:{pattern:Xn}});a&&a.push(new TextDecoder().decode(r.code));let i={};if(r.exports)for(let[e,t]of Object.entries(r.exports))i[e]=t.name;return{code:`export default ${JSON.stringify(i)}`,moduleType:`js`}}catch(t){throw Error(`[rari] Failed to process CSS module ${e}: ${t instanceof Error?t.message:String(t)}`)}}},{name:`externalize-deps`,resolveId:(e,t)=>{if(e.startsWith(`\0`))return null;if(e.startsWith(`node:`)||zt(e)||[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`rari/image`].includes(e)||e in{"rari/runtime/cache-wrapper":`node_modules/rari/dist/runtime/cache-wrapper.mjs`,"react-server-dom-rari/server":`node_modules/rari/dist/runtime/rsc-references.mjs`})return{id:e,external:!0};if(e===`rari`||C(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(Qn(this.projectRoot,e))return{id:e,external:!0};let n=[t!=null&&t!==``&&!t.startsWith(`\0`)?t:null,r].filter(e=>!!e);for(let t of n)try{return{id:de(t).resolve(e)}}catch{try{let n=import.meta.resolve(e,M(t).href);return{id:j(n)}}catch{}}return null}return null}},this.createRolldownModuleInfoPlugin(r),{name:`use-cache`,transform:async(e,t)=>{if(!this.options.experimental?.useCache&&!this.options.experimental?.useCacheRemote)return null;let n=await Un();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await D.promises.readFile(e,`utf-8`),n=Vn(t,this.getComponentId(e))?.code??t,r=this.transformClientImports(n,e),i=this.isPageComponent(e),a=i?this.transformComponentImportsToGlobal(r):r,o=k.extname(e),s;s=o===`.tsx`?`tsx`:o===`.ts`?`ts`:o===`.jsx`?`jsx`:`js`;let c=`\0virtual:${e}`,l=await N({input:c,platform:`node`,write:!1,external:[Yn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${s}`]:s},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(A.env.NODE_ENV!=null&&A.env.NODE_ENV!==``?A.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(c,a,s,e,i,[])});if(l.output.length===0)throw Error(`No output generated from Rolldown`);let u=l.output.find(e=>e.type===`chunk`&&e.isEntry);if(u?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let d=u.code;return d=`// Built: ${new Date().toISOString()}\n${d}`,d}async buildComponentBatch(e,t,n){let r=0,i=0,a=[];if(await new Promise(o=>{let s=()=>{for(;r<n&&i<e.length;){let[n,c]=e[i++],l=k.relative(this.projectRoot,n),u=this.getComponentId(n),d=k.join(this.options.rscDir,`${u}.js`),f=k.join(this.options.outDir,d);r++,(async()=>{try{let e=k.dirname(f);await D.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=M(k.resolve(this.projectRoot,f)).href;t.components[u]={id:u,filePath:n,relativePath:l,bundlePath:d,moduleSpecifier:a,dependencies:[...c.dependencies],hasNodeImports:c.hasNodeImports,css:i}}catch(e){a.push(e instanceof Error?e:Error(String(e)))}finally{r--,i>=e.length&&r===0?o():s()}})()}e.length===0&&o()};s()}),a.length>0)throw a[0]}async buildServerComponents(){let e=k.join(this.options.outDir,this.options.rscDir);await D.promises.mkdir(e,{recursive:!0});let t={components:{},buildTime:new Date().toISOString()},n=this.options.experimental?.useCache===!0||this.options.experimental?.useCacheRemote!=null,r=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),i=[...this.serverComponents.entries()].filter(([e])=>!this.isPageComponent(e)),a=[...this.serverComponents.entries()].filter(([e])=>this.isPageComponent(e)),s=[...this.serverActions.entries()];await Promise.all([this.buildComponentBatch(i,t,r),this.buildComponentBatch(s,t,r)]),await this.buildComponentBatch(a,t,r),n&&(this.useCacheBuildId=L(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=k.join(this.options.outDir,this.options.manifestPath);await D.promises.writeFile(c,JSON.stringify(t),`utf-8`),await this.writeRouteCssEntries(t);let l={};this.options.csp&&(l.csp=this.options.csp),this.options.cacheControl&&(l.cacheControl=this.options.cacheControl),this.options.cache&&(l.cache=this.options.cache),this.options.action&&(l.action=this.options.action),this.options.jsPoolSize!=null&&(l.jsPoolSize=this.options.jsPoolSize);let u=this.options.origin?.trim().replace(/\/+$/,``);u!=null&&u!==``&&(l.origin=u),this.options.htmlLimitedBots!=null&&(l.htmlLimitedBots=this.options.htmlLimitedBots),(this.options.experimental?.useCacheRemote!=null||this.useCacheBuildId!=null&&this.useCacheBuildId!==``)&&(l.useCache={...this.options.experimental?.useCacheRemote?{remote:this.options.experimental.useCacheRemote}:{},...this.useCacheBuildId!=null&&this.useCacheBuildId!==``?{buildId:this.useCacheBuildId}:{}},!this.options.experimental?.useCache&&this.options.experimental?.useCacheRemote&&console.warn(`[server-build] experimental.useCacheRemote is set without experimental.useCache; the 'use cache' transform will still run because useCacheRemote is configured.`));let d=k.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await D.promises.unlink(d)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await D.promises.writeFile(d,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=on({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=k.join(this.options.outDir,this.options.manifestPath),i;if(D.existsSync(r)){let e=await D.promises.readFile(r,`utf-8`),n=t(e);i=n&&lr(n)?n:{components:{},buildTime:new Date().toISOString()}}else i={components:{},buildTime:new Date().toISOString()};i.mdxRegistry=n.map(e=>({name:e.name,id:e.moduleId,client:e.client})),await D.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=k.join(this.options.outDir,`ssr`);await D.promises.mkdir(e,{recursive:!0});let t=[...this.getClientComponentFiles()];for(let e of this.discoveredExternalClientComponents)if(!t.some(t=>t.filePath===e))try{let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=rr();if(e!=null&&e!==``){let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}}catch{}if(t.length===0){let t={};await this.buildExternalClientComponents(t,new Map),await this.writeClientReferenceManifest(e,t);return}let n=new Map;for(let{filePath:e}of t){let t=or(e,this.projectRoot);n.set(k.resolve(e),`file:///ssr/${t}.js`)}let r={},i=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),a=0,o=0;await new Promise(e=>{let s=()=>{for(;a<i&&o<t.length;){let{filePath:i,code:c}=t[o++],l=ar(i,this.projectRoot),u=`ssr/${or(i,this.projectRoot)}.js`,d=k.join(this.options.outDir,u);a++,(async()=>{try{let e=k.dirname(d);await D.promises.mkdir(e,{recursive:!0}),await this.buildSSRSingleClient(i,d,n);let t=this.extractExportNames(c);r[l]={id:l,filePath:i,bundlePath:u,exports:t}}catch(e){console.warn(`[rari] SSR build failed for ${l}:`,e instanceof Error?e.message:e)}finally{a--,o>=t.length&&a===0?e():s()}})()}t.length===0&&e()};s()}),await this.buildExternalClientComponents(r,n),await this.writeClientReferenceManifest(e,r)}async writeClientReferenceManifest(e,t){let n=k.join(e,`manifest.json`);await D.promises.writeFile(n,JSON.stringify(t),`utf-8`);let r={};for(let[e,n]of Object.entries(t))for(let t of n.exports){let i=`${e}#${t}`;r[i]={id:i,chunks:`/${n.bundlePath}`,name:t}}let i=k.join(this.options.outDir,`server`);await D.promises.mkdir(i,{recursive:!0});let a=k.join(i,`client-reference-manifest.json`);await D.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=k.join($,...e);if(D.existsSync(n))return n;try{let e=j(import.meta.resolve(t));if(D.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of $n){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${L(n)}`}.js`,i=k.join(this.options.outDir,r);await D.promises.mkdir(k.dirname(i),{recursive:!0}),await this.buildSSRSingleClient(o,i,t),e[n]={id:n,filePath:o,bundlePath:r,exports:[...a]}}catch(e){console.warn(`[rari] SSR build failed for ${n}:`,e instanceof Error?e.message:e)}}}extractExportNames(e){return _t(e)}generateClientReferenceStub(e,t){let n=[`default`];try{n=_t(D.readFileSync(e,`utf-8`))}catch{}return mn(t,n)}isServerActionFile(e){try{let t=D.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=D.readFileSync(e,`utf-8`),r=this.extractExportNames(n),i=[`const __rariActionMod = globalThis.__rari_rsc_require__(${JSON.stringify(t)});`,`if (!__rariActionMod) throw new Error("Server action module ${t} is not registered");`];for(let e of r)e==="default"?i.push(`export default __rariActionMod.default;`):i.push(`export const ${e} = __rariActionMod.${e};`);return`${i.join(`
|
|
100
|
-
`)}\n`}generateServerActionReferenceModule(e){let t=
|
|
96
|
+
|| {};`}const gn=/import\s*\(\s*["']([^"']+)["']\s*\)|import\s+["']([^"']+)["']/g,_n=/<script\b[^>]*>/gi;function vn(e,t,n){n?.startsWith(`/src/`)&&e.add(J(O.join(t,n.slice(1))))}function yn(e){return/\btype\s*=\s*["']module["']/i.test(e)?/\bsrc\s*=\s*["']([^"']+)["']/i.exec(e)?.[1]??null:null}function bn(e){let t=new Set,n=O.join(e,`index.html`);if(!E.existsSync(n))return t;try{let r=E.readFileSync(n,`utf-8`);for(let n of r.matchAll(gn))vn(t,e,n[1]||n[2]);for(let n of r.matchAll(_n))vn(t,e,yn(n[0]))}catch{}return t}const xn=/(?:^|[\n\r;])\s*import\s*\{[^}]*\bregisterServerReference\b[^}]*\}\s*from\s*["'][^"'\n]+["']/;function Sn(e){return xn.test(e)}const Cn=new Set(`undefined.NaN.Infinity.arguments.Object.Array.String.Number.Boolean.Symbol.BigInt.Math.Date.JSON.Promise.Error.TypeError.RangeError.Map.Set.WeakMap.WeakSet.RegExp.Proxy.Reflect.Function.console.fetch.process.Buffer.globalThis.global.window.document.navigator.location.crypto.TextEncoder.TextDecoder.URL.URLSearchParams.FormData.Headers.Request.Response.AbortController.AbortSignal.setTimeout.clearTimeout.setInterval.clearInterval.queueMicrotask.structuredClone.atob.btoa.React.jsx.jsxs.Fragment`.split(`.`)),wn=new Set(`await.return.throw.if.else.for.while.do.switch.case.break.continue.new.typeof.instanceof.void.delete.yield.class.extends.super.this.try.catch.finally.with.debugger.default.of.in.from.as.import.export.async.function.const.let.var.true.false.null.static.get.set.typeof`.split(`.`));function Tn(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function En(e){return Tn(e)||e>=48&&e<=57}function Y(e,t){let n=e.length;for(;t<n;){let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===65279){t++;continue}if(r===47&&e.charCodeAt(t+1)===47){for(t+=2;t<n&&e.charCodeAt(t)!==10&&e.charCodeAt(t)!==13;)t++;continue}if(r===47&&e.charCodeAt(t+1)===42){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;t+=2;continue}break}return t}function Dn(e,t,n){t++;let r=e.length;for(;t<r;){let r=e.charCodeAt(t);if(r===92){t+=2;continue}if(r===n)return t+1;t++}return t}function X(e,t,n,r){let i=t,a=0,o=e.length;for(;i<o;){let t=q(e,i,o);if(t!==-1){i=t;continue}let s=e.charCodeAt(i);if(s===n)a++;else if(s===r&&(a--,a===0))return i+1;i++}return i}function On(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function kn(e,t,n){let r=Y(e,t+1);if(r>=n)return!1;let i=e.charCodeAt(r);if(i!==39&&i!==34)return!1;let a=r+1,o=Dn(e,r,i);if(o-1-a!=10||!On(e,a,`use server`))return!1;for(r=o;r<n;){let t=e.charCodeAt(r);if(t===32||t===9){r++;continue}return t===59||t===10||t===13||t===47&&e.charCodeAt(r+1)===47||t===47&&e.charCodeAt(r+1)===42}return!0}function An(e,t,n){let r=Y(e,t+1),i=e.charCodeAt(r);return i!==39&&i!==34?e.slice(t+1,n):(r=Y(e,Dn(e,r,i)),e.charCodeAt(r)===59&&r++,r=Y(e,r),e.slice(r,n))}function jn(e,t){if(!Tn(e.charCodeAt(t)))return null;let n=t+1;for(;n<e.length&&En(e.charCodeAt(n));)n++;return{name:e.slice(t,n),end:n}}function Mn(e,t,n){if(!On(e,t,n))return!1;let r=t>0?e.charCodeAt(t-1):-1,i=t+n.length<e.length?e.charCodeAt(t+n.length):-1;return!(r!==-1&&En(r)||i!==-1&&En(i))}function Nn(e){let t=new Set,n=0,r=e.length;for(;n<r&&(n=Y(e,n),!(n>=r));){let r=e.charCodeAt(n);if(r===123||r===91){let i=X(e,n,r,r===123?125:93);for(let r of e.slice(n,i).matchAll(/[a-z_$][\w$]*/gi))r[0]!==`as`&&t.add(r[0]);n=i;continue}if(r===46&&e.charCodeAt(n+1)===46&&e.charCodeAt(n+2)===46){n+=3,n=Y(e,n);let r=jn(e,n);r&&(t.add(r.name),n=r.end);continue}let i=jn(e,n);if(i){t.add(i.name),n=i.end;continue}n++}return t}function Pn(e){let t=new Set;for(let n of e.matchAll(/\b(?:const|let|var|function|class|async\s+function)\s+([A-Za-z_$][\w$]*)/g))t.add(n[1]);return t}function Fn(e){let t=new Set;for(let n of e.matchAll(/\b(?:import|export)\s+(?:type\s+)?(?:\{([^}]+)\}|(\*\s+as\s+[A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*))/g)){if(n[1])for(let e of n[1].split(`,`)){let n=e.trim();if(!n||n.startsWith(`type `))continue;let r=(n.split(/\s+as\s+/).at(-1)??``).trim();r&&t.add(r)}if(n[2]){let e=/as\s+([A-Za-z_$][\w$]*)/.exec(n[2]);e&&t.add(e[1])}n[3]&&n[3]!==`type`&&n[3]!==`async`&&n[3]!==`function`&&n[3]!==`class`&&t.add(n[3])}for(let n of e.matchAll(/(?:^|\n)\s*(?:export\s+)?(?:async\s+)?(?:function|class|const|let|var)\s+([A-Za-z_$][\w$]*)/g))t.add(n[1]);return t}function In(e,t,n){let r=new Set([...Nn(t),...Pn(e),...n,...Cn,...wn]),i=new Set,a=0,o=e.length;for(;a<o;){let t=q(e,a,o);if(t!==-1){a=t;continue}if(!Tn(e.charCodeAt(a))){a++;continue}let n=jn(e,a);if(n==null){a++;continue}if(a>0&&e.charCodeAt(a-1)===46){a=n.end;continue}if(Ln(e,a,n.end)){a=n.end;continue}r.has(n.name)||i.add(n.name),a=n.end}return[...i]}function Z(e,t){for(;t>0;){let n=e.charCodeAt(t-1);if(n===32||n===9||n===10||n===13||n===65279)t--;else break}return t}function Q(e,t,n){let r=t-n.length;return r<0||!Mn(e,r,n)?null:r}function Ln(e,t,n){let r=Y(e,n);if(e.charCodeAt(r)!==58)return!1;let i=Z(e,t);if(i===0)return!1;let a=e.charCodeAt(i-1);return a===123||a===44}function Rn(e,t){let n=Z(e,t),r=Q(e,n,`default`);if(r!=null){n=Z(e,r);let t=Q(e,n,`export`);if(t!=null)return{start:t,exportKind:`default`,bindingName:null}}if(n>0&&e.charCodeAt(n-1)===61){let r=Z(e,n-1),i=r;for(;i>0&&En(e.charCodeAt(i-1));)i--;if(i<r&&Tn(e.charCodeAt(i))){let n=e.slice(i,r),a=Z(e,i),o=Q(e,a,`const`)??Q(e,a,`let`)??Q(e,a,`var`);if(o!=null)return Q(e,Z(e,o),`export`)==null?{start:t,exportKind:null,bindingName:n}:{start:t,exportKind:`named`,bindingName:n}}}let i=Q(e,n,`export`);return i==null?{start:t,exportKind:null,bindingName:null}:{start:i,exportKind:`named`,bindingName:null}}function zn(e){let t=[],n=e.length,r=0;for(;r<n;){let n=e.charCodeAt(r);if(n===39||n===34||n===96){r=Dn(e,r,n);continue}if(n===47&&(e.charCodeAt(r+1)===47||e.charCodeAt(r+1)===42)){r=Y(e,r);continue}if(Mn(e,r,`async`)||Mn(e,r,`function`)){let n=r,i=r,a=!1;if(Mn(e,i,`async`)&&(a=!0,i=Y(e,i+5)),Mn(e,i,`function`)){i=Y(e,i+8),e.charCodeAt(i)===42&&(i=Y(e,i+1));let o=null,s=jn(e,i);if(s&&(o=s.name,i=Y(e,s.end)),e.charCodeAt(i)!==40){r++;continue}let c=X(e,i,40,41),l=e.slice(i+1,c-1);if(i=Y(e,c),e.charCodeAt(i)!==123){r++;continue}let u=X(e,i,123,125)-1;kn(e,i,u)?(t.push({start:n,end:u+1,bodyOpen:i,bodyClose:u,paramsRaw:l,isAsync:a,name:o,kind:o==null?`expression`:`declaration`}),r=u+1):r=i+1;continue}if(a&&e.charCodeAt(i)===40){let a=X(e,i,40,41),o=e.slice(i+1,a-1),s=Y(e,a);if(e.charCodeAt(s)===61&&e.charCodeAt(s+1)===62&&(s=Y(e,s+2),e.charCodeAt(s)===123)){let i=X(e,s,123,125)-1;kn(e,s,i)?(t.push({start:n,end:i+1,bodyOpen:s,bodyClose:i,paramsRaw:o,isAsync:!0,name:null,kind:`arrow`}),r=i+1):r=s+1;continue}}}if(e.charCodeAt(r)===40){let n=X(e,r,40,41),i=Y(e,n);if(e.charCodeAt(i)===61&&e.charCodeAt(i+1)===62&&(i=Y(e,i+2),e.charCodeAt(i)===123)){let a=X(e,i,123,125)-1;kn(e,i,a)?(t.push({start:r,end:a+1,bodyOpen:i,bodyClose:a,paramsRaw:e.slice(r+1,n-1),isAsync:!1,name:null,kind:`arrow`}),r=a+1):r=i+1;continue}}r++}return t}function Bn(e,t){let n=zn(e);if(n.length===0)return null;let r=Fn(e),i=[],a=[],o=e,s=[],c=!1,l=[...n].sort((e,t)=>t.start-e.start),u=n.length-1;for(let e of l){let n=e.name??`anonymous_server_function`,l=`$$ACTION_${u}_${n.replace(/\W/g,`_`)}`;u--,i.unshift(l);let d=An(o,e.bodyOpen,e.bodyClose),f=In(d,e.paramsRaw,r),p=[...f,e.paramsRaw.trim()].filter(e=>e!==``).join(`, `),m=e.isAsync?`async `:``,h=f.length>0?`${l}.bind(null, ${f.join(`, `)})`:l,{start:g,exportKind:_,bindingName:v}=Rn(o,e.start),y=h,b=null;_==="default"?(b=`default`,y=`export default registerServerReference(${h}, ${JSON.stringify(t)}, "default")`):_===`named`&&e.name!=null?(b=e.name,y=`export const ${e.name} = registerServerReference(${h}, ${JSON.stringify(t)}, ${JSON.stringify(e.name)})`):_===`named`&&v!=null?(b=v,y=`registerServerReference(${h}, ${JSON.stringify(t)}, ${JSON.stringify(v)})`):e.kind===`declaration`&&e.name!=null&&(y=`const ${e.name} = ${h}`),b==null?s.unshift(`${m}function ${l}(${p}) {\n${d}\n}`,`registerServerReference(${l}, ${JSON.stringify(t)}, ${JSON.stringify(l)});`):(s.unshift(`${m}function ${l}(${p}) {\n${d}\n}`),a.unshift(b)),c=!0,o=o.slice(0,g)+y+o.slice(e.end)}let d=c?`import { registerServerReference } from ${JSON.stringify(`react-server-dom-rari/server`)};\n`:``;return{code:`${c&&!Sn(o)?d:``}${o}\n\n${s.join(`
|
|
97
|
+
`)}\n`,actionNames:i,rewrittenExportNames:a}}let Vn;async function Hn(){if(Vn!==void 0)return Vn;try{let e=(await import(`@rari/use-cache`)).transformUseCacheModule;return Vn=typeof e==`function`?e:null,Vn}catch{return Vn=null,null}}const Un=/^proxy\.(?:tsx?|jsx?|mts|mjs)$/,Wn=/\/components\/(\w+)(?:\.tsx?|\.jsx?)?$/,Gn=/[/\\]components[/\\]\w+(?:\.tsx?|\.jsx?)?$/,Kn=/^(?:robots|sitemap|feed)\.(?:tsx?|jsx?)$/,qn=/^[./@~#]/,Jn=/^node:/,Yn=`[hash]_[local]`;function Xn(e){if(e.startsWith(`@`)){let t=e.split(`/`);return t.length>=2?`${t[0]}/${t[1]}`:e}return e.split(`/`)[0]??e}function Zn(e,t){let n=Xn(t),r=e;for(;;){let e=O.join(r,`node_modules`,...n.split(`/`));if(E.existsSync(O.join(e,`package.json`)))return!0;let t=O.dirname(r);if(t===r)return!1;r=t}}const Qn=[{componentId:`rari/image`,devSourceSegments:[`src`,`image`,`image.tsx`],publishedExport:`rari/image`,exports:[`Image`]}],$n=O.dirname(A(import.meta.url)),$=O.dirname($n);function er(e){return e.startsWith($)}function tr(e,t){return er(e)?O.join($,`src`):O.join(t,`src`)}function nr(){let e=O.join($,`src`,`runtime`,`boundaries`,`error-boundary-wrapper.tsx`);if(E.existsSync(e))return e;try{let e=A(import.meta.resolve(`rari/runtime/ErrorBoundaryWrapper`));if(E.existsSync(e))return e}catch{}return null}function rr(e){let t=e.replace(x,`/`);return t.includes(`ErrorBoundaryWrapper`)||t.includes(`/boundaries/error-boundary-wrapper`)||t.endsWith(`/error-boundary-wrapper.tsx`)}function ir(e,t){if(rr(e))return`virtual:error-boundary-wrapper.tsx`;let n=O.relative(t,e).replace(x,`/`);return n.startsWith(`..`)||O.isAbsolute(n)?e.replace(x,`/`):n}function ar(e,t){if(rr(e))return`error_boundary_wrapper_${I(`virtual:error-boundary-wrapper.tsx`)}`;if(er(e)){let t=O.relative($,e).replace(x,`/`);return`${$e(t)}_${I(t)}`}return et(e,t)}let or=null;async function sr(){return or||=(await import(`lightningcss`)).transform,or}function cr(e){return a(e)&&a(e.components)}function lr(e,t,n,r){return e.includes(`node_modules`)||n.has(r??J(e))?!1:!t.directives.hasUseClient&&!t.directives.hasUseServer}var ur=class{serverComponents=new Map;serverActions=new Map;options;projectRoot;buildCache=new Map;useCacheBuildId=null;htmlOnlyImports=new Set;fileImporters=new Map;moduleAnalysisCache;discoveredExternalClientComponents=new Set;clientComponentFiles=new Map;recordClientComponent(e,t){this.clientComponentFiles.set(e,t)}getClientComponentFiles(){return[...this.clientComponentFiles.entries()].map(([e,t])=>({filePath:e,code:t}))}getClientComponentPaths(){return[...this.clientComponentFiles.keys()]}getModuleAnalysisCache(){return this.moduleAnalysisCache}clearClientComponentFiles(){this.clientComponentFiles.clear()}getComponentCount(){return this.serverComponents.size+this.serverActions.size}hasComponent(e){return this.serverComponents.has(e)||this.serverActions.has(e)}removeComponent(e){this.serverComponents.delete(e),this.serverActions.delete(e),this.moduleAnalysisCache.invalidate(e)}getImportGraph(){let e=new Map;for(let[t,n]of this.fileImporters)e.set(t,new Set(n));return e}getHtmlOnlyImports(){return new Set(this.htmlOnlyImports)}async writeComponentCssAsset(e,t){if(t.length===0)return[];let n=O.join(this.options.outDir,`assets`,`server`);await E.promises.mkdir(n,{recursive:!0});let r=`${t.join(`
|
|
98
|
+
`)}\n`,i=`${I(e+r,12)}.css`,a=O.join(n,i);return await E.promises.writeFile(a,r,`utf-8`),[`/assets/server/${i}`]}getComponentIdFromRouteManifestPath(e){return this.getComponentId(O.join(this.projectRoot,`src`,`app`,e))}getComponentReferenceId(e){return this.getReadableComponentId(this.getProjectRelativePath(e))}async writeRouteCssEntries(e){let t=O.join(this.options.outDir,this.options.rscDir,`routes.json`);if(!E.existsSync(t))return;let n=await E.promises.readFile(t,`utf-8`),r=JSON.parse(n);if(!a(r))return;let i=r,o=t=>{if(Array.isArray(t))for(let n of t){if(!a(n))continue;let t=n.filePath;if(typeof t!=`string`||t===``)continue;let r=this.getComponentIdFromRouteManifestPath(t);n.componentId=r;let i=e.components[r]?.css??[];i.length?n.css=i:delete n.css}};o(i.routes),o(i.layouts),o(i.loading),o(i.errors),o(i.notFound),o(i.templates);let s=i.apiRoutes;if(Array.isArray(s))for(let e of s){if(!a(e))continue;let t=e.filePath;typeof t==`string`&&t!==``&&(e.componentId=this.getComponentIdFromRouteManifestPath(t))}await E.promises.writeFile(t,JSON.stringify(i),`utf-8`)}constructor(e,t={}){this.projectRoot=e,this.moduleAnalysisCache=t.moduleAnalysisCache??new Wt;let n=t.rscDir!=null&&t.rscDir!==``?t.rscDir:`server`;this.options={outDir:t.outDir!=null&&t.outDir!==``?t.outDir:O.join(e,`dist`),rscDir:n,manifestPath:t.manifestPath!=null&&t.manifestPath!==``?t.manifestPath:O.join(n,`manifest.json`),serverConfigPath:t.serverConfigPath!=null&&t.serverConfigPath!==``?t.serverConfigPath:O.join(n,`config.json`),minify:t.minify??k.env.NODE_ENV===`production`,alias:t.alias??{},define:t.define,csp:t.csp,cacheControl:t.cacheControl,cache:t.cache,action:t.action,jsPoolSize:t.jsPoolSize,origin:t.origin,htmlLimitedBots:t.htmlLimitedBots,experimental:t.experimental,mdx:t.mdx},this.parseHtmlImports()}parseHtmlImports(){for(let e of bn(this.projectRoot))this.htmlOnlyImports.add(e)}getModuleAnalysis(e,t){return this.moduleAnalysisCache.get(e,t)}isServerComponent(e,t){try{return lr(e,this.moduleAnalysisCache.get(e,t),this.htmlOnlyImports)}catch{return!1}}isClientComponent(e,t){try{return this.moduleAnalysisCache.get(e,t).directives.hasUseClient}catch{return!1}}resolveImportedFilePath(e,t){let n=null;if(t.startsWith(`./`)||t.startsWith(`../`)){let r=O.dirname(e);n=O.resolve(r,t)}else if(n=C(t,this.options.alias,this.projectRoot),(n==null||n===``)&&t.startsWith(`@/`)){let e=t.slice(2);n=O.join(this.projectRoot,`src`,e)}return n==null||n===``?null:S(n,[``,`.ts`,`.tsx`,`.js`,`.jsx`])}populateImportGraphFromFiles(e){this.fileImporters.clear();for(let{filePath:t,analysis:n}of e)for(let e of Vt(n.importSources)){let n=this.resolveImportedFilePath(t,e);n!=null&&n!==``&&(this.fileImporters.has(n)||this.fileImporters.set(n,new Set),this.fileImporters.get(n).add(t))}}buildImportGraph(e){let t=dr(this,[e]);this.populateImportGraphFromFiles(t)}isOnlyImportedByClientComponents(e){let t=this.fileImporters.get(e);if(!t||t.size===0)return!1;for(let e of t)if(!this.isClientComponent(e)&&!this.isOnlyImportedByClientComponents(e))return!1;return!0}addServerComponent(e,t,n){let r=t??E.readFileSync(e,`utf-8`),i=n??this.moduleAnalysisCache.get(e,r),a=Bt(i.importSources),o=zt(i);if(i.directives.hasUseServer){this.serverActions.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o});return}lr(e,i,this.htmlOnlyImports)&&this.serverComponents.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o})}isServerAction(e,t){return t!=null&&t!==``?this.moduleAnalysisCache.get(t,e).directives.hasUseServer:G(e).directives.hasUseServer}extractDependencies(e,t){return Bt((t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e)).importSources)}hasNodeImports(e,t){return zt(t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e))}async getTransformedComponentsForDevelopment(e){let t=[];for(let[n]of this.serverComponents){if(e&&!e(n))continue;let r=O.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!1})}for(let[n]of this.serverActions){if(e&&!e(n))continue;let r=O.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!0})}return t}resolveComponentsDirClientImport(e){if(!e.startsWith(`.`)&&!e.startsWith(`@`)&&!e.startsWith(`~`)&&!e.startsWith(`#`))return null;if(e.startsWith(`.`)){if(!e.includes(`/components/`))return null;let t=Wn.exec(e);if(!t)return null;let n=t[1],r=[O.resolve(this.projectRoot,`src`,`components`,`${n}.tsx`),O.resolve(this.projectRoot,`src`,`components`,`${n}.ts`),O.resolve(this.projectRoot,`src`,`components`,`${n}.jsx`),O.resolve(this.projectRoot,`src`,`components`,`${n}.js`)];for(let e of r)if(E.existsSync(e)&&this.isClientComponent(e))return{registryKey:`components/${n}`,absolutePath:e};return null}let t=null;for(let[n,r]of Object.entries(this.options.alias))if(e.startsWith(`${n}/`)||e===n){let i=e.slice(n.length).replace(/^\/+/,``);t=O.join(r,i);break}if(t==null||t===``||!Gn.exec(t))return null;let n=O.isAbsolute(t)?t:O.resolve(this.projectRoot,t),r=[n,`${n}.tsx`,`${n}.ts`,`${n}.jsx`,`${n}.js`];for(let e of r)if(E.existsSync(e)&&this.isClientComponent(e))return{registryKey:this.getComponentReferenceId(e),absolutePath:e};return null}transformComponentImportsToGlobal(e){let t=[];for(let n of ht(e)){if(n.typeOnly||n.sideEffectOnly)continue;let e=this.resolveComponentsDirClientImport(n.source);if(e==null)continue;let r=[];n.namespaceBinding!=null&&r.push(hn(n.namespaceBinding,e.registryKey)),n.defaultBinding!=null&&r.push(mn(n.defaultBinding,e.registryKey,`default`));for(let t of n.named)t.typeOnly||r.push(mn(t.local,e.registryKey,t.imported));r.length!==0&&t.push({start:n.start,end:n.end,replacement:r.join(`
|
|
99
|
+
`)})}if(t.length===0)return e;let n=e;for(let{start:e,end:r,replacement:i}of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e)+i+n.slice(r);return n}isPageComponent(e){return e.includes(`/app/`)||e.includes(`\\app\\`)}createRolldownModuleInfoPlugin(e){let t=new Set;return{name:`rari-rolldown-module-info`,moduleParsed(e){for(let n of e.importedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!Rt(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!Rt(n)&&t.add(n)},buildEnd:()=>{if(t.size===0)return;let n=[...t].sort(),r=this.serverComponents.get(e)??this.serverActions.get(e);r&&(r.dependencies=n);let i=this.buildCache.get(e);i&&(i.bundledDependencies=n)}}}createBuildPlugins(e,t,n,r,i=!1,a){let o=O.dirname(r),s=Un.test(O.basename(r)),c=new Map,l=new Map;return[{name:`virtual-module`,resolveId(t,n){if(t===e)return t;if(n===e&&(t.startsWith(`./`)||t.startsWith(`../`))){if(t.endsWith(`.module.css`))return null;let e=O.resolve(o,t);for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`,``]){let n=e+t;if(E.existsSync(n)&&E.statSync(n).isFile())return n}for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=O.join(e,`index${t}`);if(E.existsSync(n))return n}return e}return null},load(r){return r===e?{code:t,moduleType:n}:null}},{name:`resolve-client-server-boundaries`,enforce:`pre`,resolveId:(t,n)=>{if(n==null||n===``||n.includes(`node_modules`)||er(n)||t.startsWith(`node:`)||Rt(t)||t===`react`||t===`react-dom`||t===`react/jsx-runtime`||t===`react/jsx-dev-runtime`)return null;let r=null,i=this.options.alias;if(r=C(t,i,this.projectRoot),(r==null||r===``)&&(t.startsWith(`./`)||t.startsWith(`../`))){let i=n===e?o:O.dirname(n);r=O.resolve(i,t)}if((r==null||r===``)&&O.isAbsolute(t)&&(r=t),r!==``)for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=r+e;if(E.existsSync(t)&&E.statSync(t).isFile()){if(this.isClientComponent(t)){let e=O.relative(this.projectRoot,t),n=(e.startsWith(`..`)?t:e).replace(x,`/`);return c.set(t,n),e.startsWith(`..`)&&this.discoveredExternalClientComponents.add(t),{id:`\0client-ref:${t}`}}try{let e=this.moduleAnalysisCache.get(t);if(e.directives.hasUseServer){let n=this.getComponentId(t);return l.set(t,{actionId:n,hasDefaultExport:e.hasDefaultExport}),{id:`\0server-action:${t}`}}}catch(e){console.error(`[rari] Failed to read file for server action detection: ${t}`,e)}break}}return null},load:e=>{if(e.startsWith(`\0client-ref:`)){let t=e.slice(12),n=O.relative(this.projectRoot,t),r=(c.get(t)??(n.startsWith(`..`)?t:n)).replace(x,`/`);return{code:this.generateClientReferenceStub(t,r),moduleType:`js`}}if(e.startsWith(`\0server-action:`)){let t=e.slice(15),n=l.get(t)?.actionId??this.getComponentId(t);return{code:this.generateServerActionRuntimeModule(t,n),moduleType:`js`}}return null}},{name:`use-transformed-server-components`,resolveId:(e,t)=>{if(!i)return null;if(e.startsWith(`file://`)){let t=e.replace(h,``);return E.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=C(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?O.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=O.resolve(a,e)),n==null||n===``||a.includes(`node_modules`))return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=n+e;if(E.existsSync(t)&&E.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=O.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=O.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(E.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:E.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=C(e,this.options.alias,this.projectRoot);if(t==null||t===``)return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let n=t+e;if(E.existsSync(n)&&E.statSync(n).isFile()){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}for(let e of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=O.join(t,`index${e}`);if(E.existsSync(n)){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}return t}},{name:`resolve-rari-proxy`,resolveId:e=>{if(s&&e===`rari`){let e=O.join($n,`proxy/RariResponse.mjs`);if(E.existsSync(e))return e;let t=O.join($,`src/proxy/http/response.ts`);if(E.existsSync(t))return t}return null}},{name:`css-modules`,resolveId:(e,t)=>{if(e.endsWith(`.module.css`)){let n=t!=null&&t!==``&&!t.startsWith(`\0`)?O.dirname(t):o,r=O.resolve(n,e);if(E.existsSync(r))return{id:`\0css-module:${r}`}}return null},load:async e=>{if(!e.startsWith(`\0css-module:`))return null;let t=e.slice(12);try{let e=await sr(),n=E.readFileSync(t),r=e({filename:O.relative(this.projectRoot,t),code:n,cssModules:{pattern:Yn}});a&&a.push(new TextDecoder().decode(r.code));let i={};if(r.exports)for(let[e,t]of Object.entries(r.exports))i[e]=t.name;return{code:`export default ${JSON.stringify(i)}`,moduleType:`js`}}catch(t){throw Error(`[rari] Failed to process CSS module ${e}: ${t instanceof Error?t.message:String(t)}`)}}},{name:`externalize-deps`,resolveId:(e,t)=>{if(e.startsWith(`\0`))return null;if(e.startsWith(`node:`)||Rt(e)||[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`rari/image`].includes(e)||e in{"rari/runtime/cache-wrapper":`node_modules/rari/dist/runtime/cache-wrapper.mjs`,"react-server-dom-rari/server":`node_modules/rari/dist/runtime/rsc-references.mjs`})return{id:e,external:!0};if(e===`rari`||C(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(Zn(this.projectRoot,e))return{id:e,external:!0};let n=[t!=null&&t!==``&&!t.startsWith(`\0`)?t:null,r].filter(e=>!!e);for(let t of n)try{return{id:de(t).resolve(e)}}catch{try{let n=import.meta.resolve(e,j(t).href);return{id:A(n)}}catch{}}return null}return null}},this.createRolldownModuleInfoPlugin(r),{name:`use-cache`,transform:async(e,t)=>{if(!this.options.experimental?.useCache&&!this.options.experimental?.useCacheRemote)return null;let n=await Hn();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await E.promises.readFile(e,`utf-8`),n=Bn(t,this.getComponentId(e))?.code??t,r=this.transformClientImports(n,e),i=this.isPageComponent(e),a=i?this.transformComponentImportsToGlobal(r):r,o=O.extname(e),s;s=o===`.tsx`?`tsx`:o===`.ts`?`ts`:o===`.jsx`?`jsx`:`js`;let c=`\0virtual:${e}`,l=await M({input:c,platform:`node`,write:!1,external:[Jn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${s}`]:s},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(k.env.NODE_ENV!=null&&k.env.NODE_ENV!==``?k.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(c,a,s,e,i,[])});if(l.output.length===0)throw Error(`No output generated from Rolldown`);let u=l.output.find(e=>e.type===`chunk`&&e.isEntry);if(u?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let d=u.code;return d=`// Built: ${new Date().toISOString()}\n${d}`,d}async buildComponentBatch(e,t,n){let r=0,i=0,a=[];if(await new Promise(o=>{let s=()=>{for(;r<n&&i<e.length;){let[n,c]=e[i++],l=O.relative(this.projectRoot,n),u=this.getComponentId(n),d=O.join(this.options.rscDir,`${u}.js`),f=O.join(this.options.outDir,d);r++,(async()=>{try{let e=O.dirname(f);await E.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=j(O.resolve(this.projectRoot,f)).href;t.components[u]={id:u,filePath:n,relativePath:l,bundlePath:d,moduleSpecifier:a,dependencies:[...c.dependencies],hasNodeImports:c.hasNodeImports,css:i}}catch(e){a.push(e instanceof Error?e:Error(String(e)))}finally{r--,i>=e.length&&r===0?o():s()}})()}e.length===0&&o()};s()}),a.length>0)throw a[0]}async buildServerComponents(){let e=O.join(this.options.outDir,this.options.rscDir);await E.promises.mkdir(e,{recursive:!0});let t={components:{},buildTime:new Date().toISOString()},n=this.options.experimental?.useCache===!0||this.options.experimental?.useCacheRemote!=null,r=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),i=[...this.serverComponents.entries()].filter(([e])=>!this.isPageComponent(e)),a=[...this.serverComponents.entries()].filter(([e])=>this.isPageComponent(e)),s=[...this.serverActions.entries()];await Promise.all([this.buildComponentBatch(i,t,r),this.buildComponentBatch(s,t,r)]),await this.buildComponentBatch(a,t,r),n&&(this.useCacheBuildId=I(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=O.join(this.options.outDir,this.options.manifestPath);await E.promises.writeFile(c,JSON.stringify(t),`utf-8`),await this.writeRouteCssEntries(t);let l={};this.options.csp&&(l.csp=this.options.csp),this.options.cacheControl&&(l.cacheControl=this.options.cacheControl),this.options.cache&&(l.cache=this.options.cache),this.options.action&&(l.action=this.options.action),this.options.jsPoolSize!=null&&(l.jsPoolSize=this.options.jsPoolSize);let u=this.options.origin?.trim().replace(/\/+$/,``);u!=null&&u!==``&&(l.origin=u),this.options.htmlLimitedBots!=null&&(l.htmlLimitedBots=this.options.htmlLimitedBots),(this.options.experimental?.useCacheRemote!=null||this.useCacheBuildId!=null&&this.useCacheBuildId!==``)&&(l.useCache={...this.options.experimental?.useCacheRemote?{remote:this.options.experimental.useCacheRemote}:{},...this.useCacheBuildId!=null&&this.useCacheBuildId!==``?{buildId:this.useCacheBuildId}:{}},!this.options.experimental?.useCache&&this.options.experimental?.useCacheRemote&&console.warn(`[server-build] experimental.useCacheRemote is set without experimental.useCache; the 'use cache' transform will still run because useCacheRemote is configured.`));let d=O.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await E.promises.unlink(d)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await E.promises.writeFile(d,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=an({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=O.join(this.options.outDir,this.options.manifestPath),i;if(E.existsSync(r)){let e=await E.promises.readFile(r,`utf-8`),n=t(e);i=n&&cr(n)?n:{components:{},buildTime:new Date().toISOString()}}else i={components:{},buildTime:new Date().toISOString()};i.mdxRegistry=n.map(e=>({name:e.name,id:e.moduleId,client:e.client})),await E.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=O.join(this.options.outDir,`ssr`);await E.promises.mkdir(e,{recursive:!0});let t=[...this.getClientComponentFiles()];for(let e of this.discoveredExternalClientComponents)if(!t.some(t=>t.filePath===e))try{let n=E.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=nr();if(e!=null&&e!==``){let n=E.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}}catch{}if(t.length===0){let t={};await this.buildExternalClientComponents(t,new Map),await this.writeClientReferenceManifest(e,t);return}let n=new Map;for(let{filePath:e}of t){let t=ar(e,this.projectRoot);n.set(O.resolve(e),`file:///ssr/${t}.js`)}let r={},i=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),a=0,o=0;await new Promise(e=>{let s=()=>{for(;a<i&&o<t.length;){let{filePath:i,code:c}=t[o++],l=ir(i,this.projectRoot),u=`ssr/${ar(i,this.projectRoot)}.js`,d=O.join(this.options.outDir,u);a++,(async()=>{try{let e=O.dirname(d);await E.promises.mkdir(e,{recursive:!0}),await this.buildSSRSingleClient(i,d,n);let t=this.extractExportNames(c);r[l]={id:l,filePath:i,bundlePath:u,exports:t}}catch(e){console.warn(`[rari] SSR build failed for ${l}:`,e instanceof Error?e.message:e)}finally{a--,o>=t.length&&a===0?e():s()}})()}t.length===0&&e()};s()}),await this.buildExternalClientComponents(r,n),await this.writeClientReferenceManifest(e,r)}async writeClientReferenceManifest(e,t){let n=O.join(e,`manifest.json`);await E.promises.writeFile(n,JSON.stringify(t),`utf-8`);let r={};for(let[e,n]of Object.entries(t))for(let t of n.exports){let i=`${e}#${t}`;r[i]={id:i,chunks:`/${n.bundlePath}`,name:t}}let i=O.join(this.options.outDir,`server`);await E.promises.mkdir(i,{recursive:!0});let a=O.join(i,`client-reference-manifest.json`);await E.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=O.join($,...e);if(E.existsSync(n))return n;try{let e=A(import.meta.resolve(t));if(E.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of Qn){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${I(n)}`}.js`,i=O.join(this.options.outDir,r);await E.promises.mkdir(O.dirname(i),{recursive:!0}),await this.buildSSRSingleClient(o,i,t),e[n]={id:n,filePath:o,bundlePath:r,exports:[...a]}}catch(e){console.warn(`[rari] SSR build failed for ${n}:`,e instanceof Error?e.message:e)}}}extractExportNames(e){return gt(e)}generateClientReferenceStub(e,t){let n=[`default`];try{n=gt(E.readFileSync(e,`utf-8`))}catch{}return pn(t,n)}isServerActionFile(e){try{let t=E.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=E.readFileSync(e,`utf-8`),r=this.extractExportNames(n),i=[`const __rariActionMod = globalThis.__rari_rsc_require__(${JSON.stringify(t)});`,`if (!__rariActionMod) throw new Error("Server action module ${t} is not registered");`];for(let e of r)e==="default"?i.push(`export default __rariActionMod.default;`):i.push(`export const ${e} = __rariActionMod.${e};`);return`${i.join(`
|
|
100
|
+
`)}\n`}generateServerActionReferenceModule(e){let t=E.readFileSync(e,`utf-8`),n=this.extractExportNames(t),r=this.getComponentId(e),i=`import { createServerReference } from 'react-server-dom-webpack/client';
|
|
101
101
|
`;i+=`import { callServer } from 'rari/runtime/call-server';
|
|
102
|
-
`;for(let e of n){let t=`${r}#${e}`;i+=e==="default"?`export default createServerReference(${JSON.stringify(t)}, callServer);\n`:`export const ${e} = createServerReference(${JSON.stringify(t)}, callServer);\n`}return i}async buildSSRSingleClient(e,t,n){let r=(await
|
|
102
|
+
`;for(let e of n){let t=`${r}#${e}`;i+=e==="default"?`export default createServerReference(${JSON.stringify(t)}, callServer);\n`:`export const ${e} = createServerReference(${JSON.stringify(t)}, callServer);\n`}return i}async buildSSRSingleClient(e,t,n){let r=(await E.promises.readFile(e,`utf-8`)).replace(/^['"]use client['"];?\s*/m,``),i=O.extname(e),a;a=i===`.tsx`?`tsx`:i===`.ts`?`ts`:i===`.jsx`?`jsx`:`js`;let o=`\0ssr-virtual:${e}`,s=this.projectRoot,c=tr(e,s),l=e=>this.generateServerActionReferenceModule(e),u=e=>this.isServerActionFile(e),d=(await M({input:o,platform:`node`,write:!1,external:[Jn,`react`,`react-dom`,/^react\//,/^rari/,`react-server-dom-webpack/client`,/^react-server-dom-webpack\//],output:{format:`esm`,minify:!1},moduleTypes:{[`.${a}`]:a},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react-jsx`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(k.env.NODE_ENV!=null&&k.env.NODE_ENV!==``?k.env.NODE_ENV:`production`)}},plugins:[{name:`ssr-client-virtual`,resolveId(e){return e===o?e:null},load(e){if(e===o)return{code:r,moduleType:a};if(e.startsWith(`\0server-action-ref:`)){let t=e.slice(19);return{code:l(t),moduleType:`js`}}return null}},{name:`ssr-client-resolve`,resolveId(t,r){if(t.startsWith(`\0server-action-ref:`))return t;if(t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`@/`)){let i=t;t.startsWith(`@/`)?i=O.join(c,t.slice(2)):r===o?i=O.resolve(O.dirname(e),t):r!=null&&r!==``&&(i=O.resolve(O.dirname(r.replace(`\0ssr-virtual:`,``).replace(`\0server-action-ref:`,``)),t));let a=oe(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]),s=a!=null&&a!==``?a:se(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]);if(s!=null&&s!==``&&u(s))return`\0server-action-ref:${O.resolve(s)}`;if(s!=null&&s!==``&&n!=null){let t=O.resolve(s),r=n.get(t);if(r!=null&&r!==``&&t!==O.resolve(e))return{id:r,external:!0}}return s!=null&&s!==``?s:null}return null}}]})).output[0],f=typeof d==`object`&&`code`in d?d.code:``;return await E.promises.writeFile(t,f,`utf-8`),{code:f}}async buildSingleComponent(e,t){let n=await E.promises.readFile(e,`utf-8`),r=Bn(n,this.getComponentId(e))?.code??n,i=this.transformClientImports(r,e),a=this.isPageComponent(e),o=a?this.transformComponentImportsToGlobal(i):i,s=O.extname(e),c;c=s===`.tsx`?`tsx`:s===`.ts`?`ts`:s===`.jsx`?`jsx`:`js`;let l=`\0virtual:${e}`,u=[],d=await M({input:l,platform:`node`,write:!1,external:[Jn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${c}`]:c},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(k.env.NODE_ENV!=null&&k.env.NODE_ENV!==``?k.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(l,o,c,e,a,u)});if(d.output.length===0)throw Error(`No output generated from Rolldown`);let f=d.output.find(e=>e.type===`chunk`&&e.isEntry);if(f?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let p=f.code;p=`// Built: ${new Date().toISOString()}\n${p}`,await E.promises.writeFile(t,p,`utf-8`);let m=await E.promises.open(t,`r+`);return await m.sync(),await m.close(),{code:p,css:u}}transformClientImports(e,t){let n=Qn.map(e=>e.componentId),r=[],i=!1,a=!1;for(let o of ht(e)){if(o.typeOnly||o.sideEffectOnly)continue;let e=!1,s=o.source;if(n.includes(o.source))e=!0;else if(qn.test(o.source)||Object.keys(this.options.alias).some(e=>o.source===e||o.source.startsWith(`${e}/`))){let n=this.resolveImportPath(o.source,t);this.isClientComponent(n)&&(e=!0,s=O.relative(this.projectRoot,n).replace(x,`/`))}if(!e)continue;let c=[];o.namespaceBinding!=null&&(a=!0,c.push(`const ${o.namespaceBinding} = createClientModuleProxy(${JSON.stringify(s)});`)),o.defaultBinding!=null&&(i=!0,c.push(`const ${o.defaultBinding} = registerClientReference(
|
|
103
103
|
null,
|
|
104
104
|
${JSON.stringify(s)},
|
|
105
105
|
"default"
|
|
@@ -108,19 +108,19 @@ const ${e} = globalThis['~clientComponents']?.[${JSON.stringify(t)}]?.component
|
|
|
108
108
|
${JSON.stringify(s)},
|
|
109
109
|
${JSON.stringify(e.imported)}
|
|
110
110
|
);`));c.length!==0&&r.push({start:o.start,end:o.end,replacement:c.join(`
|
|
111
|
-
`)})}if(r.length===0)return e;let o=e;for(let{start:e,end:t,replacement:n}of[...r].sort((e,t)=>t.start-e.start))o=o.slice(0,e)+n+o.slice(t);let s=[...i?[`registerClientReference`]:[],...a?[`createClientModuleProxy`]:[]];return
|
|
112
|
-
`)},\n])`;return t.replace(
|
|
111
|
+
`)})}if(r.length===0)return e;let o=e;for(let{start:e,end:t,replacement:n}of[...r].sort((e,t)=>t.start-e.start))o=o.slice(0,e)+n+o.slice(t);let s=[...i?[`registerClientReference`]:[],...a?[`createClientModuleProxy`]:[]];return ln(o,`react-server-dom-rari/server`,s)}resolveImportPath(e,t){let n=e,r=this.options.alias;for(let[t,i]of Object.entries(r))if(e.startsWith(`${t}/`)||e===t){let r=e.slice(t.length).replace(/^\/+/,``);n=O.join(i,r);break}O.isAbsolute(n)||(n=O.resolve(O.dirname(t),n));let i=[`.tsx`,`.jsx`,`.ts`,`.js`],a=oe(n,i);if(a!=null&&a!==``)return a;let o=se(n,i);return o!=null&&o!==``?o:`${n}.tsx`}getProjectRelativePath(e){return Qe(e,this.projectRoot)}getReadableComponentId(e){return $e(e)}getComponentId(e){return et(e,this.projectRoot)}async rebuildComponent(e){let t=this.getComponentId(e),n=await E.promises.readFile(e,`utf-8`),r=this.extractDependencies(n,e),i={filePath:e,originalCode:n,dependencies:r,hasNodeImports:this.hasNodeImports(n,e)};this.isServerAction(n,e)?(this.serverActions.set(e,i),this.serverComponents.delete(e)):(this.serverComponents.set(e,i),this.serverActions.delete(e));let a=O.join(this.options.rscDir,`${t}.js`),o=O.join(this.options.outDir,a),s=this.buildCache.get(e),c=(await E.promises.stat(e)).mtimeMs;if(s&&s.timestamp>=c&&JSON.stringify(s.sourceDependencies)===JSON.stringify(r)){let n=this.serverActions.get(e)??this.serverComponents.get(e);return n&&s.bundledDependencies.length>0&&(n.dependencies=s.bundledDependencies),await E.promises.writeFile(o,s.code,`utf-8`),await this.updateManifestForComponent(t,e,a,s.css),{componentId:t,bundlePath:O.join(this.options.outDir,a),success:!0}}let l=O.dirname(o);await E.promises.mkdir(l,{recursive:!0});let u=await this.buildSingleComponent(e,o),d=await this.writeComponentCssAsset(t,u.css),f=this.serverActions.get(e)??this.serverComponents.get(e);return this.buildCache.set(e,{code:u.code,css:d,timestamp:Date.now(),sourceDependencies:r,bundledDependencies:f?.dependencies??r}),await this.updateManifestForComponent(t,e,a,d),{componentId:t,bundlePath:O.join(this.options.outDir,a),success:!0}}manifestCache=null;async updateManifestForComponent(e,n,r,i=[]){let a=O.join(this.options.outDir,this.options.manifestPath),o;if(this.manifestCache)o=this.manifestCache;else if(E.existsSync(a)){let e=await E.promises.readFile(a,`utf-8`),n=t(e);n&&cr(n)?(o=n,this.manifestCache=o):(o={components:{},buildTime:new Date().toISOString()},this.manifestCache=o)}else o={components:{},buildTime:new Date().toISOString()},this.manifestCache=o;let s=this.serverComponents.get(n)??this.serverActions.get(n),c=O.join(this.options.outDir,r),l=j(O.resolve(this.projectRoot,c)).href;if(s)o.components[e]={id:e,filePath:n,relativePath:O.relative(this.projectRoot,n),bundlePath:r,moduleSpecifier:l,dependencies:[...s.dependencies],hasNodeImports:s.hasNodeImports,css:i};else{let t=await E.promises.readFile(n,`utf-8`);o.components[e]={id:e,filePath:n,relativePath:O.relative(this.projectRoot,n),bundlePath:r,moduleSpecifier:l,dependencies:this.extractDependencies(t,n),hasNodeImports:this.hasNodeImports(t,n),css:i}}o.buildTime=new Date().toISOString(),await E.promises.writeFile(a,JSON.stringify(o),`utf-8`),await this.writeRouteCssEntries(o),this.manifestCache=o}clearCache(){this.buildCache.clear(),this.manifestCache=null}invalidateBuildCacheFor(e){this.buildCache.delete(e)}async getTransformedComponentCode(e){return this.buildComponentCodeOnly(e)}};function dr(e,t){let n=[];for(let r of Ft(t))try{let t=J(r),i=E.readFileSync(r,`utf-8`),a=e.getModuleAnalysis(r,i);n.push({filePath:r,cacheKey:t,code:i,analysis:a})}catch(e){console.warn(`[server-build] Error reading ${r}:`,e instanceof Error?e.message:e)}return n}function fr(e,t){return(t??G(e)).hasComponentExport||m.test(e)||y.test(e)||re.test(e)}function pr(e,t,n,r,i){let a=O.basename(e);if(Kn.test(a)||a.endsWith(`.d.ts`))return!1;let o=r??n.getModuleAnalysis(e,t);return o.directives.hasUseClient?!1:o.directives.hasUseServer?!0:!n.isOnlyImportedByClientComponents(e)&&lr(e,o,n.getHtmlOnlyImports(),i)&&fr(t,o)}function mr(e,t,n=[]){let r=dr(t,It(e,n));t.clearClientComponentFiles(),t.populateImportGraphFromFiles(r);let i=[],a=[];for(let{filePath:e,cacheKey:n,code:o,analysis:s}of r)s.directives.hasUseClient&&(a.push(e),t.recordClientComponent(e,o)),pr(e,o,t,s,n)&&(t.addServerComponent(e,o,s),i.push(e));return{serverComponentPaths:i,clientComponentPaths:a}}function hr(e={}){let t=null,n,r=!1,i={};return{name:`rari-server-build`,configResolved(a){n=a.root,r=a.command===`serve`;let o=new Set([`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`react-dom/client`]),s={},c=a.resolve.alias;Array.isArray(c)?c.forEach(e=>{typeof e.find==`string`&&typeof e.replacement==`string`&&!o.has(e.find)&&(s[e.find]=e.replacement)}):typeof c==`object`&&Object.entries(c).forEach(([e,t])=>{typeof t==`string`&&!o.has(e)&&(s[e]=t)}),i=s,t=new ur(n,{...e,alias:s})},buildStart(){if(!t)return;let e=k.env.NODE_ENV===`production`,r=[O.join(n,`dist`,`cache`,`og`),O.join(n,`dist`,`cache`,`images`)];e&&r.push(`/tmp/rari-og-cache`,`/tmp/rari-image-cache`);for(let e of r)try{E.existsSync(e)&&E.rmSync(e,{recursive:!0,force:!0})}catch(t){console.warn(`[rari] Failed to clear cache ${e}:`,t)}let a=O.join(n,`src`);E.existsSync(a)&&mr(a,t,Object.values(i))},async closeBundle(){if(t){await t.buildServerComponents(),await t.buildSSRClientComponents();try{await t.buildMdxRegistry(e.mdx)}catch(e){console.warn(`[rari] Failed to build MDX component registry:`,e)}try{let{generateRobotsFile:e}=await import(`./robots-BGCTYwKN.mjs`);await e({appDir:O.join(n,`src`,`app`),outDir:O.join(n,`dist`)})}catch(e){console.warn(`[rari] Failed to generate robots.txt:`,e)}try{let{generateSitemapFiles:e}=await import(`./sitemap-1n5BIACA.mjs`);await e({appDir:O.join(n,`src`,`app`),outDir:O.join(n,`dist`),aliases:i})}catch(e){console.warn(`[rari] Failed to generate sitemap:`,e)}try{let{generateFeedFile:e}=await import(`./feed-Ixvy9L12.mjs`);await e({appDir:O.join(n,`src`,`app`),outDir:O.join(n,`dist`),aliases:i})}catch(e){console.warn(`[rari] Failed to generate feed:`,e)}}},async handleHotUpdate({file:e}){if(!t||!r)return;let i=O.relative(n,e).replace(x,`/`);if(!(!i.startsWith(`src/`)||!v.test(i)))try{let n=await E.promises.readFile(e,`utf-8`),r=t.getModuleAnalysis(e,n),i=t.hasComponent(e);if(!pr(e,n,t,r)){i&&t.removeComponent(e);return}i||t.addServerComponent(e,n,r),await t.rebuildComponent(e)}catch(e){console.error(`[rari] Build: Error rebuilding ${i}:`,e)}}}}const gr=/import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g,_r=/import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g,vr=/import\s+(\w+)\s*,\s*\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g,yr=/defineMdxComponents\s*\(\s*\{([\s\S]*?)\}\s*\)/;function br(e,t,n){for(let r of t.split(`,`)){let t=r.trim();if(!t||(t=t.replace(/^type\s+/i,``).trim(),!t))continue;let i=t.split(/\s+as\s+/i),a=(i[1]??i[0]).trim();a&&n.set(a,e)}}function xr(e){let t=new Map;for(let n of e.matchAll(vr))t.set(n[1],n[3]),br(n[3],n[2],t);for(let n of e.matchAll(gr))t.set(n[1],n[2]);for(let n of e.matchAll(_r))br(n[2],n[1],t);return t}function Sr(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(!e)continue;let r=e.indexOf(`:`);if(r===-1){t.push({name:e,binding:e});continue}let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();i&&a&&t.push({name:i,binding:a})}return t}function Cr(e){try{return G(E.readFileSync(e,`utf-8`)).topLevelUseClient}catch{return!1}}function wr(e){let{code:t,id:n,projectRoot:r,resolvedAlias:i}=e;if(!t.includes(`defineMdxComponents`)||t.includes(`__RARI_MDX_RESOLVED__`))return null;let a=yr.exec(t);if(!a)return null;let o=xr(t),s=Sr(a[1]);if(s.length===0)return null;let c=`defineMdxComponents(/* __RARI_MDX_RESOLVED__ */[\n${s.map(({name:e,binding:t})=>{let a=o.get(t);if(a==null||a===``)throw Error(`[rari/mdx] Could not resolve import for MDX component "${e}" (binding "${t}") in ${n}`);let s=le(a,n,i),c=Qe(s,r).replace(x,`/`),l=Cr(s);return` { name: ${JSON.stringify(e)}, component: ${t}, id: ${JSON.stringify(c)}, client: ${l} }`}).join(`,
|
|
112
|
+
`)},\n])`;return t.replace(yr,c)}function Tr(e){return a(e)}function Er(e){return a(e)}async function Dr(e){let t=await import(e);return Tr(t)?t:{}}function Or(e,t){e&&(e.notFound&&(t.notFound=!0),e.redirect!=null&&(t.redirect=typeof e.redirect==`string`?e.redirect:e.redirect.destination),e.revalidate!==void 0&&(t.revalidate=e.revalidate),e.props&&(t.props={...t.props,...e.props}))}async function kr(e,t,n,r){typeof e.getData==`function`&&Or(await e.getData({params:t,searchParams:n}),r)}async function Ar(e,t,n,r){typeof e.getServerSideProps==`function`&&Or(await e.getServerSideProps({params:t,searchParams:n}),r)}async function jr(e,t,n){typeof e.getStaticProps==`function`&&Or(await e.getStaticProps({params:t}),n)}async function Mr(e,t,n){try{let r=await Dr(e),i={props:{}};return await kr(r,t,n,i),await Ar(r,t,n,i),await jr(r,t,i),i}catch(t){return console.error(`[rari] Router: Failed to extract server props from ${e}:`,t),{props:{}}}}async function Nr(e,t,n){try{let r=await Dr(e);if(typeof r.generateMetadata==`function`){let e=await r.generateMetadata({params:t,searchParams:n});if(Er(e))return e}return Er(r.metadata)?r.metadata:{}}catch(t){return console.error(`[rari] Router: Failed to extract metadata from ${e}:`,t),{}}}async function Pr(e){try{let t=await xe(e);return t==null?[]:r(t)?t:(c(e),[])}catch(t){return console.error(`[rari] Router: Failed to extract static params from ${e}:`,t),[]}}async function Fr(e){try{let t=await Dr(e);return!!(t.getData??t.getServerSideProps??t.getStaticProps??t.generateMetadata??t.generateStaticParams)}catch{return!1}}const Ir=new Map;async function Lr(e,t,n,r=6e4){let i=`${e}:${JSON.stringify(t)}:${JSON.stringify(n)}`,a=Ir.get(i);if(a&&Date.now()-a.timestamp<r)return a.result;let o=await Mr(e,t,n);return Ir.set(i,{result:o,timestamp:Date.now()}),o}function Rr(){Ir.clear()}function zr(e){for(let t of Ir.keys())t.startsWith(e)&&Ir.delete(t)}const Br="[rari] Runtime dist not built. Run `pnpm build` in the rari package first.",Vr=/import\s+type\s+(\{[^}]+\})\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Hr=/import\s+type\s+(\*\s+as\s+\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Ur=/import\s+type\s+(\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Wr=/import\s+(\{[^}]+\})\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Gr=/import\s+(\*\s+as\s+\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Kr=/import\s+(\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,qr=/import\s+["']\.\.?\/([^"']+)["'];?/g,Jr=/export\s+default\s+(?:async\s+)?function\s+(\w+)/,Yr=/^['"]use client['"];?\s*$/gm,Xr=/import\s+["']([^"']+)["']/g,Zr=/^[./@~#]/;function Qr(e,t){for(let n of Object.keys(t))if(e===n||e.startsWith(`${n}/`))return!0;return!1}const $r=/import\s+\{[^}]*\}\s+from\s+['"]react['"]/,ei=/import\s+[^,\s]+\s*,\s*\{[^}]*\}\s+from\s+['"]react['"]/,ti=/import React(,\s*\{([^}]*)\})?\s+from\s+['"]react['"];?/,ni=/import\s+["']([^"']+)["']/g,ri=/from(\s*)(['"])(?:\.\/vendor\/react-flight-client\/index|rari\/runtime\/vendor\/react-flight-client\/index)\.mjs\2/g,ii=/\bJSX\b/,ai=/\{([^}]*)\}/,oi=/^['"]use client['"];?\s*\n/,si={remotePatterns:[],localPatterns:[],deviceSizes:p,imageSizes:f,formats:u,qualityAllowlist:d,minimumCacheTTL:60,maxCacheSize:l},ci=new Map;async function li(e){let t=ci.get(e);if(t!=null&&t!==``)return t;let n=import.meta.url,r=A(n),i=O.dirname(r),a=[O.join(i,`runtime`,e),O.join(i,`../runtime`,e)];for(let t of a)try{let n=await E.promises.readFile(t,`utf-8`);return t.endsWith(`.ts`)&&(n=n.replace(Vr,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Hr,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Ur,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Wr,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace(Gr,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace(Kr,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace(qr,(e,t)=>`import "rari/${t}";`)),ci.set(e,n),n}catch(e){let n=o(e);n!==`ENOENT`&&n!==`EISDIR`&&console.warn(`[rari] Unexpected error reading ${t}:`,e)}throw Error(`Could not find ${e}. Tried: ${a.join(`, `)}`)}const ui=O.dirname(A(import.meta.url)),di=O.dirname(ui);function fi(e){let t=[O.join(ui,`runtime`,e),O.join(ui,`../runtime`,e)];for(let e of t)if(E.existsSync(e))return e;return null}function pi(e){return e.startsWith(di)}async function mi(){return li(`rsc-client-runtime.mjs`)}async function hi(e,t){return(await li(`entry-client.mjs`)).replace(`/*! @preserve CLIENT_COMPONENT_IMPORTS_PLACEHOLDER */`,e).replace(`/*! @preserve CLIENT_COMPONENT_REGISTRATIONS_PLACEHOLDER */`,t)}async function gi(){return li(`rsc-references.mjs`)}async function _i(e,t){let r=O.join(e,`src`),{getBinaryPath:i}=await import(`./platform.mjs`),a=i(),o=me(a,[`scan-images`,`--src`,r],{encoding:`utf8`,cwd:e,shell:!1,timeout:6e4});if(o.error)throw Error(`Failed to scan for image usage: ${o.error.message}`);if(o.signal)throw Error(`Failed to scan for image usage: process terminated by signal ${o.signal}`);if(o.status!==0)throw Error(`Failed to scan for image usage: ${o.stderr||o.stdout||`exit code ${o.status}`}`);let s;try{s={images:n(o.stdout,`images`)??[]}}catch(e){let t=e instanceof SyntaxError||e instanceof Error?e.message:String(e),n=(o.stdout||o.stderr||`(empty)`).slice(0,500);throw Error(`Failed to parse image scanner output as JSON: ${t}. Scanner output: ${n}`,{cause:e})}let c={...si,...t.images,preoptimizeManifest:s.images},l=O.join(e,`dist`),u=O.join(l,`server`);E.existsSync(u)||E.mkdirSync(u,{recursive:!0});let d=O.join(u,`image.json`);E.writeFileSync(d,JSON.stringify(c))}function vi(e){return e}function yi(e={}){if(e.jsPoolSize!=null){let t=e.jsPoolSize;if(!Number.isInteger(t)||t<1||!Number.isFinite(t))throw Error(`jsPoolSize must be a finite positive integer; received ${String(t)}`)}let n=new Map,r=new Set,c=new Wt,l=null,u=null,d=null,f={},p=null;function m(){p=null}function h(){return p!=null&&p!==``||(p=on(an({projectRoot:e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),mdxOptions:e.mdx,alias:f,cache:c}))),p}function g(e){return n.get(J(e))}function y(e,t){n.set(J(e),t)}function b(e){Ht(n,e)}function ee(e){r.add(J(e))}function ne(e){return r.has(J(e))}function re(e){r.delete(e);try{r.delete(E.realpathSync(e))}catch{r.delete(O.resolve(e))}}function oe(){let e=new Set(r);if(l)for(let t of l.getClientComponentPaths())e.add(t);return e}function se(e){let t={hasUseServer:!1,hasUseClient:!1},n=e.replace(x,`/`);if(!v.test(n)||!n.includes(`/src/`))return t;try{let n=c.get(e);t.hasUseServer=n.directives.hasUseServer,t.hasUseClient=n.directives.hasUseClient}catch{}return t}let S=null,C=null;function ue(){if(l)return l.getHtmlOnlyImports();let t=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),n=O.join(t,`index.html`);try{let e=E.statSync(n).mtimeMs;if(S!==null&&e===C)return S;C=e}catch{return S??=new Set,S}return S=bn(t),S}function w(e){if(e.includes(`node_modules`)||pi(e))return!1;let t=J(e);try{return lr(t,c.get(e),ue(),t)}catch{return!1}}function T(e,t){try{let n=new Set(gt(e));return(t?.hasDefaultExport??vt(e))&&n.add(`default`),[...n]}catch{return[]}}function de(t,n,r){let i=et(n,e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd()),a=Bn(t,i),o=a?.code??t;if(!r.topLevelUseServer)return a==null?t:(o+=`
|
|
113
113
|
|
|
114
114
|
if (import.meta.hot) {
|
|
115
115
|
import.meta.hot.accept(() => {
|
|
116
116
|
});
|
|
117
|
-
}`,o);let s=T(o,r);if(s.length===0&&a==null)return t;let c=JSON.stringify(i);
|
|
117
|
+
}`,o);let s=T(o,r);if(s.length===0&&a==null)return t;let c=JSON.stringify(i);Sn(o)?o+=`
|
|
118
118
|
`:o+=`
|
|
119
119
|
|
|
120
120
|
import {registerServerReference} from "react-server-dom-rari/server";
|
|
121
|
-
`;for(let e of s)if(e==="default"){let t=
|
|
121
|
+
`;for(let e of s)if(e==="default"){let t=Jr.exec(o);if(t){let n=t[1];o+=`
|
|
122
122
|
// Register server reference for default export
|
|
123
|
-
`,o+=`registerServerReference(${n}, ${c}, ${JSON.stringify(e)});\n`}else{let t=`__default_export__`,n=
|
|
123
|
+
`,o+=`registerServerReference(${n}, ${c}, ${JSON.stringify(e)});\n`}else{let t=`__default_export__`,n=Mt(o,t);n!=null&&(o=n,o+=`
|
|
124
124
|
// Register server reference for default export
|
|
125
125
|
`,o+=`if (typeof ${t} === "function") {\n`,o+=` registerServerReference(${t}, ${c}, ${JSON.stringify(e)});\n`,o+=`}
|
|
126
126
|
`)}}else if(a?.rewrittenExportNames.includes(e))continue;else o+=`\n// Register server reference for ${e}\n`,o+=`if (typeof ${e} === "function") {\n`,o+=` registerServerReference(${e}, ${c}, ${JSON.stringify(e)});\n`,o+=`}
|
|
@@ -129,10 +129,10 @@ import {registerServerReference} from "react-server-dom-rari/server";
|
|
|
129
129
|
if (import.meta.hot) {
|
|
130
130
|
import.meta.hot.accept(() => {
|
|
131
131
|
});
|
|
132
|
-
}`,o}function
|
|
132
|
+
}`,o}function me(t,n,r){let i=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),a=w(n);if(r.topLevelUseServer){let e=T(t,r);if(e.length===0)return``;let a=et(n,i),o=`import { createServerReference } from "virtual:react-flight-client";
|
|
133
133
|
`;o+=`import { callServer } from "rari/runtime/call-server";
|
|
134
134
|
`;for(let t of e){let e=`${a}#${t}`,n=JSON.stringify(e);o+=t==="default"?`export default createServerReference(${n}, callServer);\n`:`export const ${t} = createServerReference(${n}, callServer);\n`}return o}if(a)return console.warn(`[rari] Server component ${n} should not be imported in client bundle`),``;if(!r.topLevelUseClient)return t;let o=T(t,r);if(o.length===0)return``;let s=JSON.stringify(n),c=`import {registerClientReference} from "react-server-dom-rari/server";
|
|
135
|
-
`;for(let e of o){if(e==="default"){let e=`Attempted to call the default export of ${n} from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;c+=`export default `,c+=`registerClientReference(function() {`,c+=`throw new Error(${JSON.stringify(e)});`}else{let t=`Attempted to call ${e}() from the server but ${e} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;c+=`export const ${e} = `,c+=`registerClientReference(function() {`,c+=`throw new Error(${JSON.stringify(t)});`}c+=`},`,c+=`${s},`,c+=`${JSON.stringify(e)});\n`}return c}function
|
|
135
|
+
`;for(let e of o){if(e==="default"){let e=`Attempted to call the default export of ${n} from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;c+=`export default `,c+=`registerClientReference(function() {`,c+=`throw new Error(${JSON.stringify(e)});`}else{let t=`Attempted to call ${e}() from the server but ${e} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;c+=`export const ${e} = `,c+=`registerClientReference(function() {`,c+=`throw new Error(${JSON.stringify(t)});`}c+=`},`,c+=`${s},`,c+=`${JSON.stringify(e)});\n`}return c}function D(e,t,n){return!n.topLevelUseClient||T(e,n).length===0?e:e.replace(Yr,``)}let j=!1;async function he(){let e=`http://localhost:${P()}`;try{let t=(await fetch(`${e}/_rari/health`,{signal:AbortSignal.timeout(1e3)})).ok;return j=t,t}catch{return j=!1,!1}}let M=null;async function _e(e){return await he()?!0:(M??=(async()=>{try{let t=Date.now()+e,n=50;for(;Date.now()<t;){if(await new Promise(e=>{setTimeout(e,Math.min(n,t-Date.now()))}),await he())return!0;n=Math.min(n*2,500)}return!1}finally{M=null}})(),M)}let N=[{name:`rari`,config(t,{command:n}){if(t.define??={},n===`serve`||k.env.RARI_SERVER_URL!=null&&k.env.RARI_SERVER_URL!==``||k.env.RARI_HOST!=null&&k.env.RARI_HOST!==``){let e=P(),n;if(k.env.RARI_SERVER_URL!=null&&k.env.RARI_SERVER_URL!==``)n=k.env.RARI_SERVER_URL;else if(k.env.RARI_HOST!=null&&k.env.RARI_HOST!==``){let t=k.env.RARI_HOST.startsWith(`http`)?k.env.RARI_HOST:`http://${k.env.RARI_HOST}`;n=t.replace(ae,``).includes(`:`)?t:`${t}:${e}`}else n=`http://localhost:${e}`;t.define[`import.meta.env.RARI_SERVER_URL`]=JSON.stringify(n)}let r=typeof t.css?.modules==`object`?t.css.modules:{};if(t.css={...t.css,transformer:t.css?.transformer??`lightningcss`,modules:{...r,pattern:Yn}},n===`build`){let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),r=O.join(n,`index.html`);if(E.existsSync(r))try{let e=E.readFileSync(r,`utf-8`),n=[];for(let t of e.matchAll(Xr)){let e=t[1];if(e.startsWith(`/src/`)&&v.test(e)){let t=e.slice(1),r=O.basename(t,O.extname(t));n.push({path:t,name:r})}}if(n.length>0){t.build??={},t.build.rolldownOptions??={};let e=t.build.rolldownOptions.input??{main:`./index.html`},r;r=typeof e==`string`?{main:e}:Array.isArray(e)?{main:e[0]??`./index.html`}:{...e},n.forEach(({path:e,name:t})=>{r[t]=`./${e}`}),t.build.rolldownOptions.input=r}}catch(e){console.warn(`[rari] Error parsing index.html for build inputs:`,e)}}t.resolve??={};let c=t.resolve,l=Array.isArray(c.dedupe)?c.dedupe:[],u=[`react`,`react-dom`];c.dedupe=[...new Set([...l,...u])];let d=[];i(c.alias)?d=c.alias:a(c.alias)&&(d=s(c.alias));let f=new Set(d.map(e=>String(e.find)));try{let e=A(import.meta.resolve(`react`)),t=A(import.meta.resolve(`react-dom/client`)),n=A(import.meta.resolve(`react/jsx-runtime`)),r=[];f.has(`react/jsx-runtime`)||r.push({find:`react/jsx-runtime`,replacement:n});try{let e=A(import.meta.resolve(`react/jsx-dev-runtime`));f.has(`react/jsx-dev-runtime`)||r.push({find:`react/jsx-dev-runtime`,replacement:e})}catch(e){o(e)!==`ENOENT`&&console.warn(`[rari] Unexpected error resolving react/jsx-dev-runtime:`,e)}f.has(`react`)||r.push({find:`react`,replacement:e}),f.has(`react-dom/client`)||r.push({find:`react-dom/client`,replacement:t}),r.length>0&&(c.alias=[...d,...r])}catch(e){o(e)!==`ENOENT`&&console.warn(`[rari] Unexpected error configuring React aliases:`,e)}t.environments??={},t.environments.rsc={resolve:{conditions:[`react-server`,`node`,`import`]},...t.environments.rsc},t.environments.ssr={resolve:{conditions:[`node`,`import`]},...t.environments.ssr},t.environments.client={resolve:{conditions:[`browser`,`import`]},...t.environments.client},t.optimizeDeps??={},t.optimizeDeps.include??=[];for(let e of[`react`,`react-dom`,`react-dom/client`,`react-dom/server`,`react/jsx-runtime`,`react/jsx-dev-runtime`])t.optimizeDeps.include.includes(e)||t.optimizeDeps.include.push(e);if(t.optimizeDeps.exclude??=[],t.optimizeDeps.exclude.includes(`rari`)||t.optimizeDeps.exclude.push(`rari`),n===`build`)for(let e of[`rsc`,`ssr`,`client`]){let n=t.environments[e];n.build!=null&&(n.build.rolldownOptions??={})}t.server??={},t.server.proxy??={};let p=P();if(t.server.proxy[`/api`]={target:`http://localhost:${p}`,changeOrigin:!0,secure:!1,ws:!0},t.server.proxy[`/_rari`]={target:`http://localhost:${p}`,changeOrigin:!0,secure:!1,ws:!0},n===`build`){t.build??={},t.build.rolldownOptions??={},t.build.rolldownOptions.input??={main:`./index.html`},t.build.rolldownOptions.output??={};let e=Array.isArray(t.build.rolldownOptions.output)?t.build.rolldownOptions.output:[t.build.rolldownOptions.output];for(let t of e){if(t.codeSplitting!==!1&&typeof t.codeSplitting!=`object`&&(t.codeSplitting={}),typeof t.codeSplitting==`object`){t.codeSplitting.groups??=[];let e=t.codeSplitting.groups;t.codeSplitting.groups.push({name(t){if(t.includes(`node_modules`)){for(let n of e)if(n.test!=null){let e=!1;if(typeof n.test==`function`?e=!!n.test(t):n.test instanceof RegExp?e=n.test.test(t):typeof n.test==`string`&&(e=t.includes(n.test)),e)return null}return t.includes(`node_modules/react-dom`)?`react-dom`:t.includes(`node_modules/react`)?`react`:`vendor`}return null}})}t.chunkFileNames??=e=>e.moduleIds.some(e=>se(e).hasUseServer)?`client/actions/[name]-[hash].js`:e.moduleIds.some(e=>se(e).hasUseClient)?`client/components/[name]-[hash].js`:`assets/[name]-[hash].js`}}t.environments.client.build??={},t.environments.client.build.rolldownOptions??={},t.environments.client.build.rolldownOptions.input??={},t.environments.client.build.rolldownOptions.external??=[];let m=t.environments.client.build.rolldownOptions.external;if(Array.isArray(m)){let e=m.indexOf(`react-server-dom-webpack/client`);e!==-1&&m.splice(e,1)}return t},configResolved(e){let t=new Set([`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`react-dom/client`]),n=e.resolve.alias;Array.isArray(n)?n.forEach(e=>{typeof e.find==`string`&&typeof e.replacement==`string`&&!t.has(e.find)&&(f[e.find]=e.replacement)}):typeof n==`object`&&Object.entries(n).forEach(([e,n])=>{typeof n==`string`&&!t.has(e)&&(f[e]=n)})},async transform(t,n){if(n.endsWith(`.mdx`)&&m(),/\.(?:tsx?|jsx?|mts|mjs)$/.test(n)&&t.includes(`defineMdxComponents`)){let r=wr({code:t,id:n,projectRoot:e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),resolvedAlias:f});if(r!=null&&r!==``)return{code:r,map:null}}if(!v.test(n))return null;let r=t,i=!1;if(e.experimental?.useCache||e.experimental?.useCacheRemote){let e=await Hn();if(e){let r=e(t,n);r!=null&&r!==``&&(t=r,i=!0)}}let a=this.environment,o=c.get(n,r);if(o.topLevelUseClient){y(n,`client`),ee(n);for(let e of o.importSources){if(!Zr.test(e)&&!Qr(e,f))continue;let t=le(e,n,f);E.existsSync(t)&&(y(t,`client`),ee(t))}return D(t,n,o)}if(g(n)===`client`||ne(n))return D(t,n,o);if(w(n)){if(y(n,`server`),a.name===`rsc`||a.name===`ssr`)return de(t,n,o);{let e=me(t,n,o);return e=`// HMR acceptance for server component
|
|
136
136
|
if (import.meta.hot) {
|
|
137
137
|
import.meta.hot.accept();
|
|
138
138
|
if (typeof globalThis !== 'undefined') {
|
|
@@ -142,8 +142,8 @@ if (import.meta.hot) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
${e}`,e}}if(o.topLevelUseServer)return y(n,`server`),a.name===`rsc`||a.name===`ssr`?de(t,n,o):
|
|
146
|
-
`),t&&(l=t+l),!l.includes(`Suspense`)){let e=
|
|
145
|
+
${e}`,e}}if(o.topLevelUseServer)return y(n,`server`),a.name===`rsc`||a.name===`ssr`?de(t,n,o):me(t,n,o);let s=g(n);if(s===`server`)return a.name===`rsc`||a.name===`ssr`?de(t,n,o):me(t,n,o);if(s===`client`)return D(t,n,o);y(n,`unknown`);let l=t,u=!1,d=!1,p=n.includes(`entry-client`),h=[],_=new Set;for(let e of ht(t)){if(e.typeOnly||e.sideEffectOnly||!Zr.test(e.source)&&!Qr(e.source,f))continue;let t=le(e.source,n,f),r=g(t)===`client`||E.existsSync(t)&&c.get(t).topLevelUseClient;if(r&&(y(t,`client`),ee(t)),!r||p||a.name!==`rsc`&&a.name!==`ssr`)continue;let i=fn(e,t);if(i.code!==``){for(let e of i.helpers)_.add(e);h.push({start:e.start,end:e.end,replacement:i.code}),u=!0,d=!0}}for(let{start:e,end:t,replacement:n}of[...h].sort((e,t)=>t.start-e.start))l=l.slice(0,e)+n+l.slice(t);if(_.size>0&&(l=ln(l,`react-server-dom-rari/server`,[..._])),u){let e=l.includes(`import React`)||$r.test(l)||ei.test(l),t=``;if(d&&!e&&(t+=`import React from 'react';
|
|
146
|
+
`),t&&(l=t+l),!l.includes(`Suspense`)){let e=ti.exec(l);e&&(e[1]&&!e[2].includes(`Suspense`)?l=l.replace(e[0],e[0].replace(ai,`{ Suspense, $1 }`)):e[1]||(l=l.replace(e[0],`import React, { Suspense } from 'react';`)))}let r=k.env.NODE_ENV!==`production`;return(l.includes(`</`)||l.includes(`/>`)||ii.test(l))&&r&&(l=`'use client';\n\n${l}`,y(n,`client`)),l}return i?t:null},async configureServer(n){let r=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),i=O.join(r,`src`);await _i(r,e);let a=async()=>{try{let t=new ur(r,{outDir:`dist`,rscDir:`server`,manifestPath:`server/manifest.json`,serverConfigPath:`server/config.json`,alias:f,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,action:e.action,jsPoolSize:e.jsPoolSize,origin:e.origin,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c});if(l=t,d??=new Qt(t,P()),E.existsSync(i)){let e=mr(i,t,Object.values(f));e.serverComponentPaths.length>0&&n.ws.send({type:`custom`,event:`rari:server-components-registry`,data:{serverComponents:e.serverComponentPaths}})}let a=await t.getTransformedComponentsForDevelopment(),o=`http://localhost:${P()}`;await Promise.all(a.map(async e=>{try{if(e.id.startsWith(`app/`)||e.isAction)return;let t=await fetch(`${o}/_rari/register`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:e.id,component_code:e.code})});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}}catch(t){console.error(`[rari] Runtime: Failed to register component ${e.id}:`,t instanceof Error?t.message:String(t))}}))}catch(e){console.error(`[rari] Runtime: Component discovery failed:`,e instanceof Error?e.message:String(e))}},o=async()=>{try{let e=`http://localhost:${P()}`,t=oe();await Promise.all([...t].map(async t=>{let n=O.relative(k.cwd(),t),r=O.basename(t).replace(ie,``);try{await fetch(`${e}/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:r,file_path:n,export_name:`default`})})}catch(e){console.error(`[rari] Runtime: Failed to pre-register client component ${r}:`,e)}}))}catch(e){console.error(`[rari] Runtime: Failed to pre-register client components:`,e)}},s=async()=>{if(u)return;let{getBinaryPath:t,getInstallationInstructions:r}=await import(`./platform.mjs`),i;try{i=t()}catch(e){console.error(`rari binary not found`),console.error(` ${e instanceof Error?e.message:String(e)}`),console.error(r());return}let s=P(),c=k.env.NODE_ENV===`production`?`production`:`development`,l=n.config.server.port,d=e.origin?.trim().replace(/\/+$/,``),f=k.env.RARI_ORIGIN?.trim().replace(/\/+$/,``),p=[`--mode`,c,`--port`,s.toString(),`--host`,`127.0.0.1`];u=pe(i,p,{stdio:[`ignore`,`pipe`,`pipe`],cwd:k.cwd(),env:{...k.env,RUST_LOG:k.env.RUST_LOG!=null&&k.env.RUST_LOG!==``?k.env.RUST_LOG:`error`,RARI_VITE_PORT:l.toString(),...e.jsPoolSize!=null&&(k.env.RARI_JS_POOL_SIZE==null||k.env.RARI_JS_POOL_SIZE===``)?{RARI_JS_POOL_SIZE:String(e.jsPoolSize)}:{},...d!=null&&d!==``&&(f==null||f===``)?{RARI_ORIGIN:d}:{},...e.htmlLimitedBots!=null&&(k.env.RARI_HTML_LIMITED_BOTS==null||k.env.RARI_HTML_LIMITED_BOTS===``)?{RARI_HTML_LIMITED_BOTS:e.htmlLimitedBots}:{}}}),u.stdout?.on(`data`,e=>{let t=e.toString().trim();t&&console.error(t)}),u.stderr?.on(`data`,e=>{let t=e.toString().trim();t&&!t.includes(`warning`)&&console.error(t)}),u.on(`error`,e=>{j=!1,console.error(`Failed to start rari server:`,e.message),e.message.includes(`ENOENT`)&&console.error(` Binary not found. Please ensure rari is properly installed.`)}),u.on(`exit`,(e,t)=>{u=null,j=!1,t?console.error(`rari server stopped by signal ${t}`):e===0?console.error(`rari server stopped successfully`):e&&console.error(`rari server exited with code ${e}`)}),await _e(1e4)?(await a(),await o()):console.error(`Server failed to become ready for component registration`)},p=async e=>{try{if(!w(e))return;l??await a();let t=l;if(t==null)return;let n=c.getSource(e);t.addServerComponent(e,n);let r=Jt(t.getImportGraph(),[e]);r.add(e);let i=await t.getTransformedComponentsForDevelopment(e=>r.has(e));if(i.length===0)return;let o=`http://localhost:${P()}`;await Promise.all(i.map(async e=>{try{let t=await fetch(`${o}/_rari/register`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:e.id,component_code:e.code})});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}}catch(t){console.error(`[rari] Failed to register component`,`${e.id}:`,t instanceof Error?t.message:String(t))}}))}catch(t){console.error(`[rari] Targeted HMR failed for`,`${e}:`,t instanceof Error?t.message:String(t))}};s().catch(e=>{console.error(`[rari] Failed to start Rust server:`,e)}),n.middlewares.use((e,t,n)=>{(async()=>{let r=e.headers.accept;if(r!=null&&r!==``&&r.includes(`text/x-component`)&&e.url!=null&&e.url!==``&&!e.url.startsWith(`/api`)&&!e.url.startsWith(`/rsc`)&&!e.url.includes(`.`)){if(!j&&!await _e(1e4)){console.error(`[rari] Rust server not ready, cannot proxy RSC request`),t.headersSent||(t.statusCode=503,t.end(`Server not ready`));return}let n=P(),r=`http://localhost:${n}${e.url}`;try{let i={};for(let[t,n]of Object.entries(e.headers))typeof n==`string`?i[t]=n:Array.isArray(n)&&(i[t]=n.join(`,`));i.host=`localhost:${n}`,i[`accept-encoding`]=`identity`;let a=await fetch(r,{method:e.method,headers:i});if(t.statusCode=a.status,a.headers.forEach((e,n)=>{n.toLowerCase()!==`content-encoding`&&t.setHeader(n,e)}),a.body){let e=a.body.getReader();try{let n=!1;for(;!n;){let{done:r,value:i}=await e.read();n=r,!n&&i!=null&&t.write(fe.from(i))}t.end()}catch(e){console.error(`[rari] Stream error:`,e),t.headersSent||(t.statusCode=500),t.end()}}else t.end();return}catch(e){console.error(`[rari] Failed to proxy RSC request:`,e),t.headersSent||(t.statusCode=500,t.end(`Internal Server Error`));return}}n()})()}),n.watcher.on(`change`,e=>{(async()=>{v.test(e)&&(b(e),re(e),c.invalidate(e)),v.test(e)&&e.includes(i)&&w(e)&&(n.ws.send({type:`custom`,event:`rari:register-server-component`,data:{filePath:e}}),await p(e))})()}),n.middlewares.use(`/api/vite/hmr-transform`,(e,n)=>{if(e.method!==`POST`){n.statusCode=405,n.end(`Method Not Allowed`);return}let r=``;e.on(`data`,e=>{r+=e.toString()}),e.on(`end`,()=>{(async()=>{try{let e=t(r),i=e&&typeof e.filePath==`string`?e.filePath:void 0;if(i==null||i===``){n.statusCode=400,n.end(JSON.stringify({error:`filePath is required`}));return}await p(i),n.statusCode=200,n.setHeader(`Content-Type`,`application/json`),n.end(JSON.stringify({success:!0,filePath:i,message:`Component transformation completed`}))}catch(e){n.statusCode=500,n.setHeader(`Content-Type`,`application/json`),n.end(JSON.stringify({success:!1,error:e instanceof Error?e.message:String(e)}))}})()})}),n.httpServer?.on(`close`,()=>{if(d&&=(d.dispose(),null),u){let e=u;u=null,j=!1;let t=!1,n=setTimeout(()=>{t||e.kill(`SIGKILL`)},5e3);n.unref(),e.once(`exit`,()=>{t=!0,clearTimeout(n)}),e.kill(`SIGTERM`);return}j=!1})},resolveId(e,t){if(e===`virtual:rsc-integration`||e===`virtual:rsc-integration.ts`)return`virtual:rsc-integration.ts`;if(e===`virtual:rari-entry-client`||e===`virtual:rari-entry-client.ts`)return`virtual:rari-entry-client.ts`;if(e===`virtual:react-flight-client`||e===`virtual:react-flight-client.ts`)return`virtual:react-flight-client.ts`;if(e===`virtual:app-router-provider`||e===`virtual:app-router-provider.tsx`)return`virtual:app-router-provider.tsx`;if(e===`virtual:error-boundary-wrapper`||e===`virtual:error-boundary-wrapper.tsx`)return`virtual:error-boundary-wrapper.tsx`;if($t(e)||e===`virtual:rari-mdx-components`||e===`virtual:rari-mdx-components.ts`)return`virtual:rari-mdx-components.ts`;if(e===`react-server-dom-webpack/client`||e===`react-server-dom-webpack/client.browser`)return`virtual:react-flight-client.ts`;if(e===`./LoadingErrorBoundary`||e===`./LoadingErrorBoundary.tsx`)return`virtual:loading-error-boundary.tsx`;if(e===`react-server-dom-rari/server`)return e;if(t!=null&&t!==``&&t.startsWith(`virtual:`)&&e.startsWith(`./`)){let t=fi(O.basename(e));if(t!=null&&t!==``)return t}if(t!=null&&t!==``&&t.startsWith(`virtual:`)&&e.startsWith(`../`)){let n=import.meta.url,r=A(n),i=O.dirname(r),a=null,o=[O.join(i,`runtime`),O.join(i,`../runtime`)];for(let e of o)if(E.existsSync(e)){a=e;break}if(a!=null&&a!==``){let t=O.join(a,e);if(E.existsSync(t))return t;let n=O.join(a,`../dist`,O.basename(e));if(E.existsSync(n))return n}else console.warn(`[rari] Runtime directory not found, attempting fallback resolution for virtual import.\n Importer: ${t}\n ID: ${e}\n Current Dir: ${i}\n Hint: Runtime lookup failed, trying currentDir as fallback`);let s=O.join(i,e);if(E.existsSync(s))return s;let c=O.join(i,`../dist`,O.basename(e));if(E.existsSync(c))return c}if(k.env.NODE_ENV===`production`)try{let t=O.resolve(e);if(E.existsSync(t)&&w(t))return{id:e,external:!0}}catch(t){o(t)!==`ENOENT`&&console.warn(`[rari] Unexpected error resolving server component:`,e,t)}return null},async load(t){if(v.test(t)&&this.environment.name===`client`)try{let e=c.get(t);if(e.topLevelUseServer)return me(c.getSource(t),t,e)}catch{}if(t===`virtual:rari-mdx-components.ts`)return h();if(t===`virtual:rari-entry-client.ts`){let t=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),n=Ut(It(O.join(t,`src`),Object.values(f)),c),r=new Set([...oe(),...n]),i=[{path:`rari/image`,exports:[`Image`]},{path:`virtual:error-boundary-wrapper.tsx`,exports:[`ErrorBoundaryWrapper`]}],a=[...r].filter(e=>{try{return c.get(e).topLevelUseClient}catch{return!1}}).map(e=>{let t=O.relative(k.cwd(),e).replace(x,`/`),n=t.replace(v,``),r=t.startsWith(`..`)?e.replace(x,`/`):t,i=!1,a=``;try{if(!c.get(e).hasDefaultExport){let t=c.getSource(e).match(te);t&&(i=!0,a=t[1])}}catch(t){o(t)!==`ENOENT`&&console.warn(`[rari] Unexpected error reading component for export detection:`,e,t)}let s=i?a:`default`,l=i?a:O.basename(e,O.extname(e)),u=r.replace(x,`/`),d=u.startsWith(`/`)||_.test(u)?u:`/${u}`;return` "${r}": {
|
|
147
147
|
id: "${n}",
|
|
148
148
|
path: "${r}",
|
|
149
149
|
exportName: "${s}",
|
|
@@ -168,7 +168,7 @@ globalThis['~clientComponents']["${e.path}"] = globalThis['~clientComponents']["
|
|
|
168
168
|
globalThis['~clientComponents']["${e.path}"].component = ExternalModule${t};
|
|
169
169
|
globalThis['~clientComponentPaths'] = globalThis['~clientComponentPaths'] || {};
|
|
170
170
|
globalThis['~clientComponentPaths']["${e.path}"] = "${n}";`)).join(`
|
|
171
|
-
`);return
|
|
171
|
+
`);return hi(s,[`
|
|
172
172
|
const lazyComponentRegistry = {
|
|
173
173
|
${a}
|
|
174
174
|
};
|
|
@@ -181,9 +181,9 @@ for (const [path, config] of Object.entries(lazyComponentRegistry)) {
|
|
|
181
181
|
globalThis['~clientComponentPaths'][path] = config.id;
|
|
182
182
|
}
|
|
183
183
|
`,l].filter(Boolean).join(`
|
|
184
|
-
`))}if(t===`react-server-dom-rari/server`)return
|
|
184
|
+
`))}if(t===`react-server-dom-rari/server`)return gi();if(t===`virtual:app-router-provider.tsx`){let e=fi(`AppRouterProvider.mjs`);if(e!=null&&e!==``)return E.readFileSync(e,`utf-8`);throw Error(Br)}if(t===`virtual:loading-error-boundary.tsx`){let e=fi(`LoadingErrorBoundary.mjs`);if(e!=null&&e!==``)return E.readFileSync(e,`utf-8`);throw Error(Br)}if(t===`virtual:error-boundary-wrapper.tsx`){let e=fi(`ErrorBoundaryWrapper.mjs`);if(e!=null&&e!==``){let t=E.readFileSync(e,`utf-8`);if(!t.includes(`import React`)&&!t.includes(`from "react"`)&&!t.includes(`from 'react'`)){let e=oi.exec(t);if(e){let n=e[0];return`
|
|
185
185
|
${n}import * as React from 'react';\n${t.slice(n.length)}`}return`
|
|
186
|
-
import * as React from 'react';\n${t}`}return t}throw Error(
|
|
186
|
+
import * as React from 'react';\n${t}`}return t}throw Error(Br)}if(t===`virtual:rsc-integration.ts`)return(await mi()).replace(ri,(e,t,n)=>`from${t}${n}virtual:react-flight-client.ts${n}`);if(t===`virtual:react-flight-client.ts`){let e,t;try{let n=O.dirname(A(import.meta.resolve(`react-server-dom-webpack/package.json`)));e=O.join(n,`cjs/react-server-dom-webpack-client.browser.production.js`),t=O.join(n,`cjs/react-server-dom-webpack-client.edge.production.js`)}catch{let n=O.dirname(A(import.meta.url)),r=O.resolve(n,`../../node_modules`);e=O.join(r,`react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.js`),t=O.join(r,`react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.js`)}return{code:`
|
|
187
187
|
import * as React from 'react';
|
|
188
188
|
import * as ReactDOM from 'react-dom';
|
|
189
189
|
import { callServer as rariCallServer } from 'rari/runtime/call-server';
|
|
@@ -191,7 +191,7 @@ import { callServer as rariCallServer } from 'rari/runtime/call-server';
|
|
|
191
191
|
const module = { exports: {} };
|
|
192
192
|
const exports = module.exports;
|
|
193
193
|
(function(module, exports, require) {
|
|
194
|
-
${Ze(
|
|
194
|
+
${Ze(E.readFileSync(e,`utf-8`),E.readFileSync(t,`utf-8`))}
|
|
195
195
|
})(module, module.exports, function require(id) {
|
|
196
196
|
if (id === 'react') return React;
|
|
197
197
|
if (id === 'react-dom') return ReactDOM;
|
|
@@ -207,4 +207,4 @@ export function createFromReadableStream(stream, options) {
|
|
|
207
207
|
export const createServerReference = module.exports.createServerReference;
|
|
208
208
|
export const encodeReply = module.exports.encodeReply;
|
|
209
209
|
export const createTemporaryReferenceSet = module.exports.createTemporaryReferenceSet;
|
|
210
|
-
`}}if(t.endsWith(`.mjs`)&&
|
|
210
|
+
`}}if(t.endsWith(`.mjs`)&&E.existsSync(t))try{let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),r=E.realpathSync(t),i=O.relative(n,r),a=!i.startsWith(`..`)&&!O.isAbsolute(i),o=r.includes(`${O.sep}node_modules${O.sep}`),s=r.includes(`${O.sep}packages${O.sep}rari${O.sep}`)||r.includes(`${O.sep}node_modules${O.sep}rari${O.sep}`);return a||o||s?E.readFileSync(t,`utf-8`):(console.warn(`[rari] Refusing to load .mjs file outside project root and node_modules: ${t}`),null)}catch(e){return console.warn(`[rari] Error validating .mjs file path: ${t}`,e),null}},async handleHotUpdate({file:e,server:t}){if(ce(),e.endsWith(`.mdx`)&&m(),!v.test(e))return;if(b(e),re(e),c.invalidate(e),m(),e.includes(`/dist/`)||e.includes(`\\dist\\`))return[];let n=d?.detectComponentType(e)??`unknown`,r=e.includes(`/app/`)||e.includes(`\\app\\`),i=(e,t)=>e.endsWith(`${t}.tsx`)||e.endsWith(`${t}.jsx`)||e.endsWith(`${t}.ts`)||e.endsWith(`${t}.js`),a=[`page`,`layout`,`template`,`loading`,`error`,`not-found`].some(t=>i(e,t));if(!(r&&a)&&n!==`client`&&n===`server`)return d&&await d.handleServerComponentUpdate(e,t),[]},transformIndexHtml:{order:`pre`,handler(e){let t=[];for(let n of e.matchAll(ni)){let e=n[1];e.startsWith(`/src/`)&&t.push(e)}let n=[];n.push({tag:`script`,attrs:{type:`module`},children:`import 'virtual:rari-entry-client';`,injectTo:`head-prepend`}),t.length>0&&n.push(...t.map(e=>({tag:`script`,attrs:{type:`module`,src:e},injectTo:`head-prepend`})));let r=e;r=r.replace(/^\s*import\s+["']\/src\/[^"']+["'];?\s*$/gm,``),r=r.replace(/^\s*import\s+["']virtual:rari-entry-client["'];?\s*$/gm,``);let i;do i=r,r=r.replace(/<script\s+type=["']module["'][^>]*>\s*<\/script>/gi,``);while(r!==i);return{html:r,tags:n}}},async writeBundle(){await _i(e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:k.cwd(),e)}},{name:`rari:patch-react-server-dom-webpack`,transform(e){if(!e.includes(`__webpack_require__`)&&!e.includes(`__webpack_chunk_load__`))return null;let t=e;return t.includes(`__webpack_chunk_load__`)&&(t=t.replaceAll(`__webpack_chunk_load__`,`__rari_chunk_load__`)),t.includes(`__webpack_require__.u`)&&(t=t.replaceAll(`__webpack_require__.u`,`({}).u`)),t.includes(`__webpack_require__`)&&(t=t.replaceAll(`__webpack_require__`,`__rari_rsc_require__`)),t===e?null:{code:t,map:null}}},hr({...e.serverBuild,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,action:e.action,jsPoolSize:e.jsPoolSize,origin:e.origin,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c,mdx:e.mdx})];return e.proxy!==!1&&N.push(ve(e.proxy??{})),e.router!==!1&&N.push(Ye(e.router??{})),ge(N)}function bi(e){return{...e,plugins:[yi(),...e.plugins??[]]}}export{e as ApiResponse,Rr as clearPropsCache,zr as clearPropsCacheForComponent,bi as defineRariConfig,vi as defineRariOptions,Nr as extractMetadata,Mr as extractServerProps,Lr as extractServerPropsWithCache,Pr as extractStaticParams,Pe as generateAppRouteManifest,Fr as hasServerSideDataFetching,yi as rari,ve as rariProxy,Ye as rariRouter};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rari",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.12",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -142,25 +142,25 @@
|
|
|
142
142
|
"dependencies": {
|
|
143
143
|
"lightningcss": "^1.33.0",
|
|
144
144
|
"react-server-dom-webpack": "^19.2.8",
|
|
145
|
-
"rolldown": "^1.2.
|
|
145
|
+
"rolldown": "^1.2.4"
|
|
146
146
|
},
|
|
147
147
|
"optionalDependencies": {
|
|
148
|
-
"@rari/use-cache": "0.15.
|
|
149
|
-
"rari-darwin-arm64": "0.15.
|
|
150
|
-
"rari-darwin-x64": "0.15.
|
|
151
|
-
"rari-linux-arm64": "0.15.
|
|
152
|
-
"rari-linux-x64": "0.15.
|
|
153
|
-
"rari-win32-arm64": "0.15.
|
|
154
|
-
"rari-win32-x64": "0.15.
|
|
148
|
+
"@rari/use-cache": "0.15.12",
|
|
149
|
+
"rari-darwin-arm64": "0.15.12",
|
|
150
|
+
"rari-darwin-x64": "0.15.12",
|
|
151
|
+
"rari-linux-arm64": "0.15.12",
|
|
152
|
+
"rari-linux-x64": "0.15.12",
|
|
153
|
+
"rari-win32-arm64": "0.15.12",
|
|
154
|
+
"rari-win32-x64": "0.15.12"
|
|
155
155
|
},
|
|
156
156
|
"devDependencies": {
|
|
157
157
|
"@mdx-js/mdx": "^3.1.1",
|
|
158
|
-
"@types/node": "^26.
|
|
158
|
+
"@types/node": "^26.2.0",
|
|
159
159
|
"@types/react": "^19.2.18",
|
|
160
160
|
"@types/react-dom": "^19.2.4",
|
|
161
161
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
162
162
|
"typescript-7": "npm:typescript@^7.0.2",
|
|
163
|
-
"vite-plus": "^0.2.
|
|
163
|
+
"vite-plus": "^0.2.9",
|
|
164
164
|
"@rari/deploy": "0.0.0",
|
|
165
165
|
"@rari/logger": "0.0.0"
|
|
166
166
|
},
|