rari 0.15.6 → 0.15.7
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/vite.mjs +43 -24
- package/package.json +9 -9
package/dist/vite.mjs
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
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-De7aSsCq.mjs";import{a as m,c as h,d as g,g as _,h as v,i as y,m as ee,n as te,o as ne,p as re,r as ie,s as ae,t as b,u as oe}from"./regex-constants-Wm7xRA3u.mjs";import{a as x,i as S,n as se,o as C,r as ce,t as w}from"./alias-resolver-Cigam7Y7.mjs";import{t as le}from"./timer-Duul5JHq.mjs";import{t as T}from"./names-N6JRDeT1.mjs";import{builtinModules as E,createRequire as D}from"node:module";import{Buffer as ue}from"node:buffer";import{spawn as de,spawnSync as O}from"node:child_process";import k,{promises as A}from"node:fs";import j from"node:path";import M from"node:process";import{fileURLToPath as N,pathToFileURL as P}from"node:url";import F from"node:crypto";import{build as I}from"rolldown";function fe(e){return e.map(e=>e)}function pe(e){return e}function me(e={}){let{root:t=M.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=j.join(t,n);try{return await A.access(i),s(`Found proxy file: ${n}`),{filePath:i,exists:!0,relativePath:n}}catch{}}let e=j.join(t,n);try{await A.access(e);for(let t of i){let i=`${r}${t}`,a=j.join(e,i);try{return await A.access(a),s(`Found proxy file: ${j.join(n,i)}`),{filePath:a,exists:!0,relativePath:j.join(n,i)}}catch{}}}catch{}return null}return pe({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}}),[]}})}const L={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`},he={DYNAMIC:/^\[([^\]]+)\]$/,CATCH_ALL:/^\[\.\.\.([^\]]+)\]$/,OPTIONAL_CATCH_ALL:/^\[\[\.\.\.([^\]]+)\]\]$/},ge=[{pattern:he.OPTIONAL_CATCH_ALL,type:`optional-catch-all`,format:e=>`[[...${e}]]`},{pattern:he.CATCH_ALL,type:`catch-all`,format:e=>`[...${e}]`},{pattern:he.DYNAMIC,type:`dynamic`,format:e=>`[${e}]`}],_e=/^\([^/]+\)$/;function ve(e){return _e.test(e)}function ye(e){return e?e.replace(b,`/`).split(`/`).filter(Boolean).some(ve):!1}function be(e){for(let t of ge){let n=e.match(t.pattern);if(n)return{type:t.type,param:n[1],format:t.format}}}function xe(e){let t=be(e);return t?t.format(t.param):e}function Se(e){let t=be(e);return t?{type:t.type,value:e,param:t.param}:{type:`static`,value:e}}const Ce=/export\s+const\s+size\s*=\s*\{\s*width\s*:\s*(\d+)\s*,\s*height\s*:\s*(\d+)\s*[,}]/,we=/export\s+const\s+contentType\s*=\s*['"]([^'"]+)['"]/,Te=[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`];var Ee=class{appDir;extensions;verbose;constructor(e){this.appDir=j.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=j.dirname(r.filePath).replace(b,`/`);if(!ye(i))continue;let a=e.filter(e=>{let t=j.dirname(e.filePath).replace(b,`/`);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=j.join(this.appDir,e),u;try{u=await A.readdir(l)}catch{return}let d=[],f=[];for(let e of u){let t=j.join(l,e),n=await A.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?j.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,L.PAGE);if(d!=null&&d!==``){let t=this.parseRouteSegments(e),r=this.extractParams(t);n.push({path:u,filePath:j.join(e,d).replace(b,`/`),segments:t,params:r,isDynamic:r.length>0})}let f=this.findFile(t,L.LAYOUT);if(f!=null&&f!==``){let t=this.getParentPath(e);r.push({path:u,filePath:j.join(e,f).replace(b,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let p=this.findFile(t,L.LOADING);p!=null&&p!==``&&i.push({path:u,filePath:j.join(e,p).replace(b,`/`)});let m=this.findFile(t,L.ERROR);m!=null&&m!==``&&a.push({path:u,filePath:j.join(e,m).replace(b,`/`)});let h=this.findFile(t,L.NOT_FOUND);h!=null&&h!==``&&o.push({path:u,filePath:j.join(e,h).replace(b,`/`)});let g=this.findFile(t,L.TEMPLATE);if(g!=null&&g!==``){let t=this.getParentPath(e);s.push({path:u,filePath:j.join(e,g).replace(b,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let _=this.findFile(t,L.OG_IMAGE);if(_!=null&&_!==``){let t=j.join(e,_).replace(b,`/`),n=j.join(this.appDir,t),r,i,a;try{let e=await A.readFile(n,`utf-8`),t=Ce.exec(e);t&&(r=Number.parseInt(t[1],10),i=Number.parseInt(t[2],10));let o=we.exec(e);o&&(a=o[1])}catch{}l.push({path:u,filePath:t,width:r,height:i,contentType:a})}let v=this.findFile(t,L.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(b,`/`).split(`/`).filter(Boolean).filter(e=>!ve(e)).map(xe).join(`/`)}`:`/`}parseRouteSegments(e){return e?e.split(g).filter(Boolean).filter(e=>!ve(e)).map(Se):[]}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=j.join(this.appDir,e),n=await A.readFile(t,`utf-8`),r=[];for(let e of Te){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=j.join(e,t).replace(b,`/`),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 De(e,t={}){return new Ee({appDir:e,...t}).generateManifest()}const Oe=/export\s+const\s+metadata\s*(?::\s*\w+\s*)?=\s*(\{[\s\S]*?\n\})/,ke=/title\s*:\s*['"]([^'"]+)['"]/,Ae=/description\s*:\s*['"]([^'"]+)['"]/,je=/keywords\s*:\s*\[([\s\S]*?)\]/,Me={appDir:`src/app`,extensions:[`.tsx`,`.jsx`,`.ts`,`.js`],outDir:`dist`};function Ne(e){switch(j.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 Pe(e){return/^\([^/]+\)$/.test(e)}function Fe(e){if(!e||e===`/`)return`/`;let t=e.replace(b,`/`).split(`/`).filter(e=>!!e&&!Pe(e));return t.length>0?`/${t.join(`/`)}`:`/`}function Ie(e,t){let n=j.relative(t,j.dirname(e));return!n||n===`.`?`/`:Fe(`/${n.replace(b,`/`).split(`/`).filter(Boolean).join(`/`)}`)}function Le(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 Re(e){try{let t=Oe.exec(e);if(!t)return null;let n=t[1],r={},i=ke.exec(n);i&&(r.title=i[1]);let a=Ae.exec(n);a&&(r.description=a[1]);let o=je.exec(n);o&&(r.keywords=o[1].split(`,`).map(e=>e.trim().replace(re,``)).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 ze(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 Be(e){return a(e)&&Array.isArray(e.routes)}async function Ve(e){try{let n=await fetch(`http://localhost:3000/_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 He(e={}){let n={...Me,...e},i=null,o=new Map,s=null,l=new Set,u=e=>[...e].toSorted().join(`|`),d=async e=>{let t=new Set,r=async e=>{try{let i=await A.readdir(e,{withFileTypes:!0});for(let a of i){let i=j.join(e,a.name);a.isDirectory()?await r(i):a.isFile()&&n.extensions.some(e=>a.name.endsWith(e))&&Ne(i)&&t.add(i)}}catch{}};return await r(e),t},f=async(e,t=!1)=>{let r=j.resolve(e,n.appDir);try{await A.access(r)}catch{return null}try{let a=await d(r),o=u(a);if(!t&&s===o&&i!=null&&i!==``)return i;let c=await De(r,{extensions:n.extensions}),f=JSON.stringify(c),p=j.resolve(e,n.outDir);await A.mkdir(p,{recursive:!0});let m=j.join(p,`server`);return await A.mkdir(m,{recursive:!0}),await A.writeFile(j.join(m,`routes.json`),f,`utf-8`),s=o,l.clear(),a.forEach(e=>{l.add(e)}),f}catch(e){return console.error(`[rari] Router: Failed to generate app routes:`,e),null}},p=e=>{let t=j.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=Ne(i)!==null,a=r===`add`||r===`unlink`,o=t&&!l.has(i);(a||o)&&(await f(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)}})()})},m;return pe({name:`rari-router`,configResolved(e){m=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=m||M.cwd();i=await f(e,!0)},configureServer(e){p(e)},async handleHotUpdate(e){let{file:r,server:a}=e,s=j.resolve(a.config.root,n.appDir);if(r.startsWith(s)&&n.extensions.some(e=>r.endsWith(e))){let e=Ne(r);if(e){let n=o.get(r);n&&clearTimeout(n);let c=setTimeout(()=>{(async()=>{o.delete(r);let n=!l.has(r),c=i;i=await f(a.config.root,n);let u=c!==i,d=Ie(r,s),p=[d];if(i!=null&&i!==``)try{let e=t(i);e&&Be(e)&&(p=e.routes.map(e=>e.path))}catch(e){console.error(`[rari] Router: Failed to parse manifest for affected routes:`,e)}let m=Le(d,e,p),h,g=!1,_;if(e===`page`||e===`layout`)try{let e=Re(await A.readFile(r,`utf-8`));e&&(h=e,g=!0)}catch(e){console.error(`[rari] Router: Failed to extract metadata:`,e)}if(e===`route`)try{_=ze(await A.readFile(r,`utf-8`)),await Ve(j.relative(s,r))}catch(e){console.error(`[rari] Router: Failed to detect HTTP methods:`,e)}let v={fileType:e,filePath:j.relative(a.config.root,r),routePath:d,affectedRoutes:m,manifestUpdated:u,timestamp:Date.now(),metadata:h,metadataChanged:g,methods:_};a.ws.send({type:`custom`,event:`rari:app-router-updated`,data:v})})()},200);return o.set(r,c),[]}return i=await f(a.config.root),[]}},async closeBundle(){for(let e of o.values())clearTimeout(e);o.clear();let e=m||M.cwd(),i=j.resolve(e,n.outDir,`server`),s=j.join(i,`routes.json`);try{let e=t(await A.readFile(s,`utf-8`));if(!e||!Be(e))return;let n=e,o=!1;for(let e of n.routes){if(!e.isDynamic)continue;let t=e.componentId;if(t==null||t===``)continue;let n=j.join(i,`${t}.js`);try{let i=await import(n);if(a(i)&&typeof i.generateStaticParams==`function`){let n=i.generateStaticParams,a=await n();r(a)?a.length>0&&(e.staticParams=a,o=!0):c(t)}}catch(e){console.warn(`[rari] Failed to evaluate generateStaticParams for ${t}:`,e)}}o&&await A.writeFile(s,JSON.stringify(n),`utf-8`)}catch(e){console.warn(`[rari] Failed to enrich routes manifest with static params:`,e)}}})}function Ue(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`);let i=t.slice(n,r).replace(`return {
|
|
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-De7aSsCq.mjs";import{a as m,c as h,d as g,g as _,h as v,i as y,m as ee,n as te,o as ne,p as re,r as ie,s as ae,t as b,u as oe}from"./regex-constants-Wm7xRA3u.mjs";import{a as x,i as S,n as se,o as C,r as ce,t as w}from"./alias-resolver-Cigam7Y7.mjs";import{t as le}from"./timer-Duul5JHq.mjs";import{t as T}from"./names-N6JRDeT1.mjs";import{builtinModules as E,createRequire as D}from"node:module";import{Buffer as ue}from"node:buffer";import{spawn as de,spawnSync as O}from"node:child_process";import k,{promises as A}from"node:fs";import j from"node:path";import M from"node:process";import{fileURLToPath as N,pathToFileURL as P}from"node:url";import F from"node:crypto";import{build as I}from"rolldown";function fe(e){return e.map(e=>e)}function pe(e){return e}function me(e={}){let{root:t=M.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=j.join(t,n);try{return await A.access(i),s(`Found proxy file: ${n}`),{filePath:i,exists:!0,relativePath:n}}catch{}}let e=j.join(t,n);try{await A.access(e);for(let t of i){let i=`${r}${t}`,a=j.join(e,i);try{return await A.access(a),s(`Found proxy file: ${j.join(n,i)}`),{filePath:a,exists:!0,relativePath:j.join(n,i)}}catch{}}}catch{}return null}return pe({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}}),[]}})}const he=6e4;async function ge(e){let t=P(e).href,n=`
|
|
2
|
+
import { registerHooks } from "node:module";
|
|
3
|
+
registerHooks({
|
|
4
|
+
resolve(specifier, context, nextResolve) {
|
|
5
|
+
if (specifier === "react-server-dom-rari/server") {
|
|
6
|
+
return nextResolve("rari/runtime/rsc-references", context);
|
|
7
|
+
}
|
|
8
|
+
return nextResolve(specifier, context);
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
const mod = await import(${JSON.stringify(t)});
|
|
12
|
+
const result =
|
|
13
|
+
typeof mod.generateStaticParams !== "function"
|
|
14
|
+
? null
|
|
15
|
+
: ((await mod.generateStaticParams()) ?? null);
|
|
16
|
+
process.send(result, () => {
|
|
17
|
+
process.disconnect();
|
|
18
|
+
});
|
|
19
|
+
`;return new Promise((t,r)=>{let i=de(M.execPath,[`--conditions=react-server`,`--input-type=module`,`--eval`,n],{stdio:[`ignore`,`pipe`,`pipe`,`ipc`],env:M.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 ${he}ms for ${e}`)))},he),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 L={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`},_e={DYNAMIC:/^\[([^\]]+)\]$/,CATCH_ALL:/^\[\.\.\.([^\]]+)\]$/,OPTIONAL_CATCH_ALL:/^\[\[\.\.\.([^\]]+)\]\]$/},ve=[{pattern:_e.OPTIONAL_CATCH_ALL,type:`optional-catch-all`,format:e=>`[[...${e}]]`},{pattern:_e.CATCH_ALL,type:`catch-all`,format:e=>`[...${e}]`},{pattern:_e.DYNAMIC,type:`dynamic`,format:e=>`[${e}]`}],ye=/^\([^/]+\)$/;function be(e){return ye.test(e)}function xe(e){return e?e.replace(b,`/`).split(`/`).filter(Boolean).some(be):!1}function Se(e){for(let t of ve){let n=e.match(t.pattern);if(n)return{type:t.type,param:n[1],format:t.format}}}function Ce(e){let t=Se(e);return t?t.format(t.param):e}function we(e){let t=Se(e);return t?{type:t.type,value:e,param:t.param}:{type:`static`,value:e}}const Te=/export\s+const\s+size\s*=\s*\{\s*width\s*:\s*(\d+)\s*,\s*height\s*:\s*(\d+)\s*[,}]/,Ee=/export\s+const\s+contentType\s*=\s*['"]([^'"]+)['"]/,De=[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`];var Oe=class{appDir;extensions;verbose;constructor(e){this.appDir=j.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=j.dirname(r.filePath).replace(b,`/`);if(!xe(i))continue;let a=e.filter(e=>{let t=j.dirname(e.filePath).replace(b,`/`);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=j.join(this.appDir,e),u;try{u=await A.readdir(l)}catch{return}let d=[],f=[];for(let e of u){let t=j.join(l,e),n=await A.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?j.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,L.PAGE);if(d!=null&&d!==``){let t=this.parseRouteSegments(e),r=this.extractParams(t);n.push({path:u,filePath:j.join(e,d).replace(b,`/`),segments:t,params:r,isDynamic:r.length>0})}let f=this.findFile(t,L.LAYOUT);if(f!=null&&f!==``){let t=this.getParentPath(e);r.push({path:u,filePath:j.join(e,f).replace(b,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let p=this.findFile(t,L.LOADING);p!=null&&p!==``&&i.push({path:u,filePath:j.join(e,p).replace(b,`/`)});let m=this.findFile(t,L.ERROR);m!=null&&m!==``&&a.push({path:u,filePath:j.join(e,m).replace(b,`/`)});let h=this.findFile(t,L.NOT_FOUND);h!=null&&h!==``&&o.push({path:u,filePath:j.join(e,h).replace(b,`/`)});let g=this.findFile(t,L.TEMPLATE);if(g!=null&&g!==``){let t=this.getParentPath(e);s.push({path:u,filePath:j.join(e,g).replace(b,`/`),parentPath:t===null?void 0:this.pathToRoute(t)})}let _=this.findFile(t,L.OG_IMAGE);if(_!=null&&_!==``){let t=j.join(e,_).replace(b,`/`),n=j.join(this.appDir,t),r,i,a;try{let e=await A.readFile(n,`utf-8`),t=Te.exec(e);t&&(r=Number.parseInt(t[1],10),i=Number.parseInt(t[2],10));let o=Ee.exec(e);o&&(a=o[1])}catch{}l.push({path:u,filePath:t,width:r,height:i,contentType:a})}let v=this.findFile(t,L.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(b,`/`).split(`/`).filter(Boolean).filter(e=>!be(e)).map(Ce).join(`/`)}`:`/`}parseRouteSegments(e){return e?e.split(g).filter(Boolean).filter(e=>!be(e)).map(we):[]}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=j.join(this.appDir,e),n=await A.readFile(t,`utf-8`),r=[];for(let e of De){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=j.join(e,t).replace(b,`/`),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 ke(e,t={}){return new Oe({appDir:e,...t}).generateManifest()}const Ae=/export\s+const\s+metadata\s*(?::\s*\w+\s*)?=\s*(\{[\s\S]*?\n\})/,je=/title\s*:\s*['"]([^'"]+)['"]/,Me=/description\s*:\s*['"]([^'"]+)['"]/,Ne=/keywords\s*:\s*\[([\s\S]*?)\]/,Pe={appDir:`src/app`,extensions:[`.tsx`,`.jsx`,`.ts`,`.js`],outDir:`dist`};function Fe(e){switch(j.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 Ie(e){return/^\([^/]+\)$/.test(e)}function Le(e){if(!e||e===`/`)return`/`;let t=e.replace(b,`/`).split(`/`).filter(e=>!!e&&!Ie(e));return t.length>0?`/${t.join(`/`)}`:`/`}function Re(e,t){let n=j.relative(t,j.dirname(e));return!n||n===`.`?`/`:Le(`/${n.replace(b,`/`).split(`/`).filter(Boolean).join(`/`)}`)}function ze(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 Be(e){try{let t=Ae.exec(e);if(!t)return null;let n=t[1],r={},i=je.exec(n);i&&(r.title=i[1]);let a=Me.exec(n);a&&(r.description=a[1]);let o=Ne.exec(n);o&&(r.keywords=o[1].split(`,`).map(e=>e.trim().replace(re,``)).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 Ve(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 He(e){return a(e)&&Array.isArray(e.routes)}async function Ue(e){try{let n=await fetch(`http://localhost:3000/_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 We(e={}){let n={...Pe,...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 A.readdir(e,{withFileTypes:!0});for(let a of i){let i=j.join(e,a.name);a.isDirectory()?await r(i):a.isFile()&&n.extensions.some(e=>a.name.endsWith(e))&&Fe(i)&&t.add(i)}}catch{}};return await r(e),t},d=async(e,t=!1)=>{let r=j.resolve(e,n.appDir);try{await A.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 ke(r,{extensions:n.extensions}),f=JSON.stringify(d),p=j.resolve(e,n.outDir);await A.mkdir(p,{recursive:!0});let m=j.join(p,`server`);return await A.mkdir(m,{recursive:!0}),await A.writeFile(j.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=j.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=Fe(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 pe({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||M.cwd();i=await d(e,!0)},configureServer(e){f(e)},async handleHotUpdate(e){let{file:r,server:o}=e,c=j.resolve(o.config.root,n.appDir);if(r.startsWith(c)&&n.extensions.some(e=>r.endsWith(e))){let e=Fe(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=Re(r,c),p=[f];if(i!=null&&i!==``)try{let e=t(i);e&&He(e)&&(p=e.routes.map(e=>e.path))}catch(e){console.error(`[rari] Router: Failed to parse manifest for affected routes:`,e)}let m=ze(f,e,p),h,g=!1,_;if(e===`page`||e===`layout`)try{let e=Be(await A.readFile(r,`utf-8`));e&&(h=e,g=!0)}catch(e){console.error(`[rari] Router: Failed to extract metadata:`,e)}if(e===`route`)try{_=Ve(await A.readFile(r,`utf-8`)),await Ue(j.relative(c,r))}catch(e){console.error(`[rari] Router: Failed to detect HTTP methods:`,e)}let v={fileType:e,filePath:j.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||M.cwd(),i=j.resolve(e,n.outDir,`server`),o=j.join(i,`routes.json`);try{let e=t(await A.readFile(o,`utf-8`));if(!e||!He(e))return;let n=e,a=n.routes.flatMap(e=>{if(!e.isDynamic)return[];let t=e.componentId;return t==null||t===``?[]:[{route:e,componentId:t}]}),s=Math.min(8,Math.max(1,a.length)),l=a.map(()=>!1),u=0,d=0;await new Promise(e=>{let t=()=>{for(;d<s&&u<a.length;){let n=u++,{route:o,componentId:s}=a[n],f=j.join(i,`${s}.js`);d++,(async()=>{try{let e=await ge(f);if(e==null)return;r(e)?(o.staticParams=e,l[n]=!0):c(s)}catch(e){console.warn(`[rari] Failed to evaluate generateStaticParams for ${s}:`,e)}finally{d--,u>=a.length&&d===0?e():t()}})()}a.length===0&&e()};t()}),l.some(Boolean)&&await A.writeFile(o,JSON.stringify(n),`utf-8`)}catch(e){console.warn(`[rari] Failed to enrich routes manifest with static params:`,e)}}})}function Ge(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`);let i=t.slice(n,r).replace(`return {
|
|
2
21
|
name: referenceClosure,
|
|
3
22
|
method: "POST",
|
|
4
23
|
encType: "multipart/form-data",
|
|
@@ -25,8 +44,8 @@ import{t as e}from"./api-routes-ChRr3O5-.mjs";import{g as t,h as n,m as r,o as i
|
|
|
25
44
|
originalBind: reference.bind,
|
|
26
45
|
bound: bound
|
|
27
46
|
});
|
|
28
|
-
}`,i)}function We(e){return e.replace(/(?<!\$)\$FORM_ACTION/g,()=>`$$FORM_ACTION`).replace(/(?<!\$)\$IS_SIGNATURE_EQUAL/g,()=>`$$IS_SIGNATURE_EQUAL`)}function R(e,t=8){return F.createHash(`sha256`).update(e).digest(`hex`).slice(0,t)}function z(e,t=M.cwd()){let n=j.isAbsolute(e)?e:j.resolve(t,e),r=j.relative(t,n);return j.isAbsolute(r)?n.replace(b,`/`):r.replace(b,`/`)}function Ge(e){return e.replace(v,``).replace(te,`_`).replace(ee,``)}function B(e,t=M.cwd()){let n=z(e,t);return`${Ge(n)}_${R(n)}`}const Ke=new Set([`return`,`throw`,`case`,`typeof`,`instanceof`,`new`,`delete`,`void`,`in`,`of`]),qe=8232,Je=8233;function V(e){return e===32||e===9||e===13||e===10||e===qe||e===Je||e===65279}function H(e){return e===13||e===10||e===qe||e===Je}function U(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95||e===36}function Ye(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function Xe(e,t,n){for(;t<n&&V(e.charCodeAt(t));)t++;return t}function W(e,t,n){for(;t<n;){let r=Xe(e,t,n);if(r!==t){t=r;continue}let i=e.charCodeAt(t);if(i===47&&e.charCodeAt(t+1)===47){t=Ze(e,t,n);continue}if(i===47&&e.charCodeAt(t+1)===42){t=Qe(e,t,n);continue}break}return t}function Ze(e,t,n){for(;t<n&&!H(e.charCodeAt(t));)t++;return t}function Qe(e,t,n){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;return t+2}function G(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 $e(e,t,n){t++;let r=e.charCodeAt(t)===47;for(r&&t++;t<n;){let n=e.charCodeAt(t);if(U(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=G(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=G(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||Ye(r)){for(r===47?(i--,t++):r!==33&&i++,t++;t<n;){let n=e.charCodeAt(t);if(U(n)||n===46||n===45)t++;else break}continue}t++;continue}t++}return t}function et(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function K(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&&U(r)||a!==-1&&U(a))}function tt(e,t,n){let r=W(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=G(e,r,n,i);return o<=a?null:{source:e.slice(a,o-1),end:o}}function nt(e,t,n){if(!K(e,t,`import`))return{sources:[],end:t+6};let r=t+6;if(r=W(e,r,n),K(e,r,`type`)&&(r=W(e,r+4,n)),e.charCodeAt(r)===46){for(r++;r<n&&U(e.charCodeAt(r));)r++;for(;r<n&&e.charCodeAt(r)===46;)for(r++;r<n&&U(e.charCodeAt(r));)r++;return{sources:[],end:r}}if(e.charCodeAt(r)===40){r++;let t=tt(e,r,n);return t?{sources:[t.source],end:t.end}:{sources:[],end:r}}let i=tt(e,r,n);if(i)return{sources:[i.source],end:i.end};let a=0;for(;r<n&&(r=W(e,r,n),!(r>=n));){let t=e.charCodeAt(r);if(a===0&&K(e,r,`from`)){let t=tt(e,r+4,n);if(t)return{sources:[t.source],end:t.end};break}if(t===39||t===34||t===96){r=G(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 rt(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 it(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 q(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(V(d)){l++;continue}if(d===47&&e.charCodeAt(l+1)===47){l=Ze(e,l,u);continue}if(d===47&&e.charCodeAt(l+1)===42){l=Qe(e,l,u);continue}if(s&&(d===39||d===34)){let i=l+1,a=G(e,l,u,d);if(a<=i){s=!1,l++;continue}let o=a-1-i,f=o===10&&et(e,i,`use client`),p=o===10&&et(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(V(t)&&!H(t)){m++;continue}if(H(t)||t===59){h=!0,l=m+1;break}if(t===47&&e.charCodeAt(m+1)===47){m=Ze(e,m,u);continue}if(t===47&&e.charCodeAt(m+1)===42){m=Qe(e,m,u);continue}s=!1,h=!1;break}if(!h){m>=u&&(s=!1),l=s?a:m;continue}continue}if(s=!1,d===39||d===34||d===96){l=G(e,l,u,d);continue}if(d===47&&e.charCodeAt(l+1)!==47&&e.charCodeAt(l+1)!==42&<(e,l)){l=ut(e,l,u);continue}if(d===60){let t=e.charCodeAt(l+1);if(t===47||t===46||t===62||Ye(t)){l=$e(e,l,u);continue}l++;continue}if(K(e,l,`import`)){let t=nt(e,l,u);for(let e of t.sources)o.push(e);l=t.end;continue}if(rt(e,l)){let t=l+6;if(t<u){let n=e.charCodeAt(t);if(V(n)||n===123||n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)){let n=W(e,t,u);if(it(e,n)){i=!0,a=!0;let r=n+7;if(r>=u||!U(e.charCodeAt(r))){l=t;continue}}if(e.charCodeAt(n)===123){let t=n+1;for(;t<u&&(t=W(e,t,u),e.charCodeAt(t)!==125);){let n=t;for(;t<u&&U(e.charCodeAt(t));)t++;let r=t-n;if(r===0)break;t=W(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&&!U(e.charCodeAt(n))){t=W(e,n,u);let r=t;for(;t<u&&U(e.charCodeAt(t));)t++;t-r===7&&it(e,r)&&(i=!0,a=!0)}}if(!o&&r===7&&it(e,n)&&(i=!0,a=!0),e.charCodeAt(t)===44){t++;continue}if(e.charCodeAt(t)===125)break;t++}}else(K(e,n,`async`)||K(e,n,`function`)||K(e,n,`class`))&&(a=!0)}}}l++}return{directives:t,topLevelUseClient:n,topLevelUseServer:r,hasDefaultExport:i,hasComponentExport:a,importSources:[...new Set(o)]}}function at(e){return q(e).hasDefaultExport}function ot(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 st(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(V(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||!U(e.charCodeAt(n)))return;let r=n;for(;n>=0&&U(e.charCodeAt(n));)n--;return e.slice(n+1,r+1)}function ct(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(V(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 lt(e,t){let n=ct(e,t);if(n===-1||ot(n))return!0;let r=st(e,t);return r!=null&&r!==``&&Ke.has(r)}function ut(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&&U(e.charCodeAt(t));)t++;return t}if(H(i))return t;t++}return t}const dt=new Set([`node_modules`,`.git`,`.cache`,`dist`]);function ft(e,t){let n=new Set,r=e=>{if(!k.existsSync(e))return;let i=k.readdirSync(e,{withFileTypes:!0});for(let a of i){let i=j.join(e,a.name);if(a.isDirectory()){if(dt.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&&k.existsSync(t)&&r(t)}function pt(e){let t=[];return ft(e,e=>{t.push(e)}),t}function mt(e,t=[]){let n=[e],r=j.resolve(e);for(let e of t){if(!e)continue;let t=j.resolve(e);if(t===r)continue;let i=j.relative(r,t);if(!(i===``||!i.startsWith(`..`)&&!j.isAbsolute(i)))try{k.statSync(e).isDirectory()&&n.push(e)}catch{}}return n}const ht=new Set(E);function J(e){return ht.has(e)}function gt(e){for(let t of e.importSources)if(t.startsWith(`node:`)||J(t))return!0;return!1}function _t(e,t=ht){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 Y(e){try{return k.realpathSync(e)}catch{return j.resolve(e)}}function yt(e,t){e.delete(t);try{e.delete(k.realpathSync(t))}catch{e.delete(j.resolve(t))}}function bt(e,t){let n=[];for(let r of pt(e))try{t.get(r).directives.hasUseClient&&n.push(r)}catch{}return n}var xt=class{cache=new Map;get(e,t){let n=Y(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??=k.readFileSync(n,`utf-8`);let i=this.readMtimeMs(n),a=q(t);return this.cache.set(n,{mtimeMs:i,source:t,analysis:a}),a}getSource(e){return this.get(e),this.cache.get(Y(e)).source}invalidate(e){yt(this.cache,e)}clear(){this.cache.clear()}readMtimeMs(e){try{return k.statSync(e).mtimeMs}catch{return-1}}},St=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 Ct(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 St(e.status,e.statusText,n)}}var wt=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=le(this.resetTimer),this.resetTimer=setTimeout(()=>{this.reset()},this.resetTimeout),this.errorCount>=this.maxErrors&&this.handleMaxErrorsReached()}reset(){this.errorCount=0,this.lastError=null,this.resetTimer=le(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 Tt(e){return a(e)&&e.success===!0&&typeof e.componentId==`string`&&typeof e.filePath==`string`&&typeof e.relativePath==`string`}function Et(e){return a(e)&&e.success===!1&&typeof e.filePath==`string`&&typeof e.relativePath==`string`&&e.error instanceof Error}function Dt(e){return e===`info`||e===`success`||e===`warning`||e===`error`}var Ot=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=3e3){this.serverComponentBuilder=e,this.rustServerUrl=`http://localhost:${t}`,this.errorHandler=new wt({maxErrors:5,resetTimeout:3e4})}getErrorCount(){return this.errorHandler.getErrorCount()}async handleClientComponentUpdate(e,t){let n=j.relative(M.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=j.relative(M.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`&&Tt(e.value)?a.push(e.value):e.status===`fulfilled`&&Et(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,n){try{let r=await fetch(`${this.rustServerUrl}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`reload-component`,component_id:e,bundle_path:n})});await Ct(r);let i=await r.text(),a;try{a=JSON.parse(i)}catch(e){throw Error(`Failed to parse server response (status ${r.status}): ${e instanceof Error?e.message:String(e)}. Response body: ${i.substring(0,200)}${i.length>200?`...`:``}`)}let o=t(i);if(!o)throw Error(`Invalid server response (status ${r.status}): expected object, got ${typeof a}. Response body: ${i.substring(0,200)}${i.length>200?`...`:``}`);if(o.success!==!0){let e=typeof o.message==`string`&&o.message!==``?o.message:typeof o.error==`string`&&o.error!==``?o.error:`Component reload failed`;throw Error(e)}}catch(e){throw console.error(`[rari] HMR: Failed to notify Rust server:`,e),e}}collectDependentPageComponents(e){let t=this.serverComponentBuilder.getImportGraph(),n=new Set,r=new Set,i=a=>{if(r.has(a))return;r.add(a);let o=t.get(a);if(o)for(let t of o)(t.includes(`/app/`)||t.includes(`\\app\\`))&&!e.includes(t)&&n.add(t),i(t)};for(let t of e)i(t);return[...n]}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(Dt(t))if(n.length===1){let e=n[0];this.outputLog(t,e.message)}else{let e=n.map(e=>e.message).join(`
|
|
29
|
-
• `);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}`);break}}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
|
+
}`,i)}function Ke(e){return e.replace(/(?<!\$)\$FORM_ACTION/g,()=>`$$FORM_ACTION`).replace(/(?<!\$)\$IS_SIGNATURE_EQUAL/g,()=>`$$IS_SIGNATURE_EQUAL`)}function R(e,t=8){return F.createHash(`sha256`).update(e).digest(`hex`).slice(0,t)}function z(e,t=M.cwd()){let n=j.isAbsolute(e)?e:j.resolve(t,e),r=j.relative(t,n);return j.isAbsolute(r)?n.replace(b,`/`):r.replace(b,`/`)}function qe(e){return e.replace(v,``).replace(te,`_`).replace(ee,``)}function B(e,t=M.cwd()){let n=z(e,t);return`${qe(n)}_${R(n)}`}const Je=new Set([`return`,`throw`,`case`,`typeof`,`instanceof`,`new`,`delete`,`void`,`in`,`of`]),Ye=8232,Xe=8233;function V(e){return e===32||e===9||e===13||e===10||e===Ye||e===Xe||e===65279}function H(e){return e===13||e===10||e===Ye||e===Xe}function U(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95||e===36}function Ze(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function Qe(e,t,n){for(;t<n&&V(e.charCodeAt(t));)t++;return t}function W(e,t,n){for(;t<n;){let r=Qe(e,t,n);if(r!==t){t=r;continue}let i=e.charCodeAt(t);if(i===47&&e.charCodeAt(t+1)===47){t=$e(e,t,n);continue}if(i===47&&e.charCodeAt(t+1)===42){t=et(e,t,n);continue}break}return t}function $e(e,t,n){for(;t<n&&!H(e.charCodeAt(t));)t++;return t}function et(e,t,n){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;return t+2}function G(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 tt(e,t,n){t++;let r=e.charCodeAt(t)===47;for(r&&t++;t<n;){let n=e.charCodeAt(t);if(U(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=G(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=G(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||Ze(r)){for(r===47?(i--,t++):r!==33&&i++,t++;t<n;){let n=e.charCodeAt(t);if(U(n)||n===46||n===45)t++;else break}continue}t++;continue}t++}return t}function nt(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function K(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&&U(r)||a!==-1&&U(a))}function rt(e,t,n){let r=W(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=G(e,r,n,i);return o<=a?null:{source:e.slice(a,o-1),end:o}}function it(e,t,n){if(!K(e,t,`import`))return{sources:[],end:t+6};let r=t+6;if(r=W(e,r,n),K(e,r,`type`)&&(r=W(e,r+4,n)),e.charCodeAt(r)===46){for(r++;r<n&&U(e.charCodeAt(r));)r++;for(;r<n&&e.charCodeAt(r)===46;)for(r++;r<n&&U(e.charCodeAt(r));)r++;return{sources:[],end:r}}if(e.charCodeAt(r)===40){r++;let t=rt(e,r,n);return t?{sources:[t.source],end:t.end}:{sources:[],end:r}}let i=rt(e,r,n);if(i)return{sources:[i.source],end:i.end};let a=0;for(;r<n&&(r=W(e,r,n),!(r>=n));){let t=e.charCodeAt(r);if(a===0&&K(e,r,`from`)){let t=rt(e,r+4,n);if(t)return{sources:[t.source],end:t.end};break}if(t===39||t===34||t===96){r=G(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 at(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 ot(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 q(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(V(d)){l++;continue}if(d===47&&e.charCodeAt(l+1)===47){l=$e(e,l,u);continue}if(d===47&&e.charCodeAt(l+1)===42){l=et(e,l,u);continue}if(s&&(d===39||d===34)){let i=l+1,a=G(e,l,u,d);if(a<=i){s=!1,l++;continue}let o=a-1-i,f=o===10&&nt(e,i,`use client`),p=o===10&&nt(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(V(t)&&!H(t)){m++;continue}if(H(t)||t===59){h=!0,l=m+1;break}if(t===47&&e.charCodeAt(m+1)===47){m=$e(e,m,u);continue}if(t===47&&e.charCodeAt(m+1)===42){m=et(e,m,u);continue}s=!1,h=!1;break}if(!h){m>=u&&(s=!1),l=s?a:m;continue}continue}if(s=!1,d===39||d===34||d===96){l=G(e,l,u,d);continue}if(d===47&&e.charCodeAt(l+1)!==47&&e.charCodeAt(l+1)!==42&&dt(e,l)){l=ft(e,l,u);continue}if(d===60){let t=e.charCodeAt(l+1);if(t===47||t===46||t===62||Ze(t)){l=tt(e,l,u);continue}l++;continue}if(K(e,l,`import`)){let t=it(e,l,u);for(let e of t.sources)o.push(e);l=t.end;continue}if(at(e,l)){let t=l+6;if(t<u){let n=e.charCodeAt(t);if(V(n)||n===123||n===47&&(e.charCodeAt(t+1)===47||e.charCodeAt(t+1)===42)){let n=W(e,t,u);if(ot(e,n)){i=!0,a=!0;let r=n+7;if(r>=u||!U(e.charCodeAt(r))){l=t;continue}}if(e.charCodeAt(n)===123){let t=n+1;for(;t<u&&(t=W(e,t,u),e.charCodeAt(t)!==125);){let n=t;for(;t<u&&U(e.charCodeAt(t));)t++;let r=t-n;if(r===0)break;t=W(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&&!U(e.charCodeAt(n))){t=W(e,n,u);let r=t;for(;t<u&&U(e.charCodeAt(t));)t++;t-r===7&&ot(e,r)&&(i=!0,a=!0)}}if(!o&&r===7&&ot(e,n)&&(i=!0,a=!0),e.charCodeAt(t)===44){t++;continue}if(e.charCodeAt(t)===125)break;t++}}else(K(e,n,`async`)||K(e,n,`function`)||K(e,n,`class`))&&(a=!0)}}}l++}return{directives:t,topLevelUseClient:n,topLevelUseServer:r,hasDefaultExport:i,hasComponentExport:a,importSources:[...new Set(o)]}}function st(e){return q(e).hasDefaultExport}function ct(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 lt(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(V(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||!U(e.charCodeAt(n)))return;let r=n;for(;n>=0&&U(e.charCodeAt(n));)n--;return e.slice(n+1,r+1)}function ut(e,t){let n=t-1;for(;n>=0;){let t=e.charCodeAt(n);if(V(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 dt(e,t){let n=ut(e,t);if(n===-1||ct(n))return!0;let r=lt(e,t);return r!=null&&r!==``&&Je.has(r)}function ft(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&&U(e.charCodeAt(t));)t++;return t}if(H(i))return t;t++}return t}const pt=new Set([`node_modules`,`.git`,`.cache`,`dist`]);function mt(e,t){let n=new Set,r=e=>{if(!k.existsSync(e))return;let i=k.readdirSync(e,{withFileTypes:!0});for(let a of i){let i=j.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&&k.existsSync(t)&&r(t)}function ht(e){let t=[];return mt(e,e=>{t.push(e)}),t}function gt(e,t=[]){let n=[e],r=j.resolve(e);for(let e of t){if(!e)continue;let t=j.resolve(e);if(t===r)continue;let i=j.relative(r,t);if(!(i===``||!i.startsWith(`..`)&&!j.isAbsolute(i)))try{k.statSync(e).isDirectory()&&n.push(e)}catch{}}return n}const _t=new Set(E);function J(e){return _t.has(e)}function vt(e){for(let t of e.importSources)if(t.startsWith(`node:`)||J(t))return!0;return!1}function yt(e,t=_t){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 bt(e){let t=[];for(let n of e)(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`@/`))&&t.push(n);return t}function Y(e){try{return k.realpathSync(e)}catch{return j.resolve(e)}}function xt(e,t){e.delete(t);try{e.delete(k.realpathSync(t))}catch{e.delete(j.resolve(t))}}function St(e,t){let n=[];for(let r of ht(e))try{t.get(r).directives.hasUseClient&&n.push(r)}catch{}return n}var Ct=class{cache=new Map;get(e,t){let n=Y(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??=k.readFileSync(n,`utf-8`);let i=this.readMtimeMs(n),a=q(t);return this.cache.set(n,{mtimeMs:i,source:t,analysis:a}),a}getSource(e){return this.get(e),this.cache.get(Y(e)).source}invalidate(e){xt(this.cache,e)}clear(){this.cache.clear()}readMtimeMs(e){try{return k.statSync(e).mtimeMs}catch{return-1}}},wt=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 Tt(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 wt(e.status,e.statusText,n)}}var Et=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=le(this.resetTimer),this.resetTimer=setTimeout(()=>{this.reset()},this.resetTimeout),this.errorCount>=this.maxErrors&&this.handleMaxErrorsReached()}reset(){this.errorCount=0,this.lastError=null,this.resetTimer=le(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 Dt(e){return a(e)&&e.success===!0&&typeof e.componentId==`string`&&typeof e.filePath==`string`&&typeof e.relativePath==`string`}function Ot(e){return a(e)&&e.success===!1&&typeof e.filePath==`string`&&typeof e.relativePath==`string`&&e.error instanceof Error}function kt(e){return e===`info`||e===`success`||e===`warning`||e===`error`}var At=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=3e3){this.serverComponentBuilder=e,this.rustServerUrl=`http://localhost:${t}`,this.errorHandler=new Et({maxErrors:5,resetTimeout:3e4})}getErrorCount(){return this.errorHandler.getErrorCount()}async handleClientComponentUpdate(e,t){let n=j.relative(M.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=j.relative(M.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`&&Dt(e.value)?a.push(e.value):e.status===`fulfilled`&&Ot(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,n){try{let r=await fetch(`${this.rustServerUrl}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`reload-component`,component_id:e,bundle_path:n})});await Tt(r);let i=await r.text(),a;try{a=JSON.parse(i)}catch(e){throw Error(`Failed to parse server response (status ${r.status}): ${e instanceof Error?e.message:String(e)}. Response body: ${i.substring(0,200)}${i.length>200?`...`:``}`)}let o=t(i);if(!o)throw Error(`Invalid server response (status ${r.status}): expected object, got ${typeof a}. Response body: ${i.substring(0,200)}${i.length>200?`...`:``}`);if(o.success!==!0){let e=typeof o.message==`string`&&o.message!==``?o.message:typeof o.error==`string`&&o.error!==``?o.error:`Component reload failed`;throw Error(e)}}catch(e){throw console.error(`[rari] HMR: Failed to notify Rust server:`,e),e}}collectDependentPageComponents(e){let t=this.serverComponentBuilder.getImportGraph(),n=new Set,r=new Set,i=a=>{if(r.has(a))return;r.add(a);let o=t.get(a);if(o)for(let t of o)(t.includes(`/app/`)||t.includes(`\\app\\`))&&!e.includes(t)&&n.add(t),i(t)};for(let t of e)i(t);return[...n]}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(kt(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}`);break}}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 jt(e){let t=e.replace(b,`/`);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 Mt(e,t){let n=e=>{if(k.existsSync(e))for(let r of k.readdirSync(e,{withFileTypes:!0})){let i=j.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&&k.existsSync(t)&&n(t)}function Nt(e){let t=new Set;return Mt(e,e=>{try{let n=k.readFileSync(e,`utf-8`);for(let e of T(n))t.add(e)}catch{}}),t}function Pt(e,t){try{if(t.get(e).hasDefaultExport)return j.basename(e,j.extname(e));let n=t.getSource(e).match(ne);if(n?.[1]!=null&&n[1]!==``)return n[1]}catch{}return j.basename(e,j.extname(e))}function Ft(e){let t=Nt(e.contentDirs.map(t=>j.join(e.projectRoot,t)));if(t.size===0)return[];let n=St(e.componentScanDirs,e.cache),r=[],i=new Set;for(let a of n){let n=Pt(a,e.cache);if(n==null||n===``||!t.has(n))continue;let o=z(a,e.projectRoot).replace(b,`/`),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 It(e){let t=Rt(e.projectRoot,e.mdxOptions),n=e.srcDir??j.join(e.projectRoot,`src`),r=zt(e.projectRoot,t.componentsDir,gt(n,Object.values(e.alias??{})));return Ft({projectRoot:e.projectRoot,componentsDir:t.componentsDir,contentDirs:t.contentDirs,cache:e.cache,componentScanDirs:r})}function Lt(e,t={}){let n=t.importStyle??`root-absolute`,r=t.mode??`vite`;return e.length===0?`import { defineMdxComponents } from 'rari/mdx/define'
|
|
30
49
|
|
|
31
50
|
export const getMDXComponents = defineMdxComponents([])
|
|
32
51
|
`:r===`production`?`import { defineMdxComponents } from 'rari/mdx/define'
|
|
@@ -43,8 +62,8 @@ export const getMDXComponents = defineMdxComponents([
|
|
|
43
62
|
${e.map(e=>` { name: ${JSON.stringify(e.name)}, component: ${e.binding}, id: ${JSON.stringify(e.moduleId)}, client: ${e.client} }`).join(`,
|
|
44
63
|
`)},
|
|
45
64
|
])
|
|
46
|
-
`}function
|
|
47
|
-
`)}\n`,i=`${R(e+r,12)}.css`,a=j.join(n,i);return await k.promises.writeFile(a,r,`utf-8`),[`/assets/server/${i}`]}getComponentIdFromRouteManifestPath(e){return this.getComponentId(j.join(this.projectRoot,`src`,`app`,e))}getComponentReferenceId(e){return this.getReadableComponentId(this.getProjectRelativePath(e))}async writeRouteCssEntries(e){let t=j.join(this.options.outDir,this.options.rscDir,`routes.json`);if(!k.existsSync(t))return;let n=await k.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 k.promises.writeFile(t,JSON.stringify(i),`utf-8`)}constructor(e,t={}){this.projectRoot=e,this.moduleAnalysisCache=t.moduleAnalysisCache??new
|
|
65
|
+
`}function Rt(e,t){return{componentsDir:t?.componentsDir??`src/components`,contentDirs:t?.contentDirs??[`public/content`,`content`]}}function zt(e,t,n){let r=j.join(e,t),i=new Set(n);return k.existsSync(r)&&i.add(r),[...i]}const Bt=/import\s*\(\s*["']([^"']+)["']\s*\)|import\s+["']([^"']+)["']/g,Vt=/<script\b[^>]*>/gi;function Ht(e,t,n){n?.startsWith(`/src/`)&&e.add(Y(j.join(t,n.slice(1))))}function Ut(e){return/\btype\s*=\s*["']module["']/i.test(e)?/\bsrc\s*=\s*["']([^"']+)["']/i.exec(e)?.[1]??null:null}function Wt(e){let t=new Set,n=j.join(e,`index.html`);if(!k.existsSync(n))return t;try{let r=k.readFileSync(n,`utf-8`);for(let n of r.matchAll(Bt))Ht(t,e,n[1]||n[2]);for(let n of r.matchAll(Vt))Ht(t,e,Ut(n[0]))}catch{}return t}let X;async function Gt(){if(X!==void 0)return X;try{let e=(await import(`@rari/use-cache`)).transformUseCacheModule;return X=typeof e==`function`?e:null,X}catch{return X=null,null}}const Kt=/import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g,qt=/import\s+(?:(\w+)|\{([^}]+)\})\s+from\s+['"]([^'"]+)['"];?\s*$/gm,Jt=/^proxy\.(?:tsx?|jsx?|mts|mjs)$/,Yt=/\/components\/(\w+)(?:\.tsx?|\.jsx?)?$/,Xt=/[/\\]components[/\\](\w+)(?:\.tsx?|\.jsx?)?$/,Zt=/^(?:robots|sitemap|feed)\.(?:tsx?|jsx?)$/,Qt=`react-server-dom-rari/server`,$t=/^node:/,en=`[hash]_[local]`;function tn(e){if(e.startsWith(`@`)){let t=e.split(`/`);return t.length>=2?`${t[0]}/${t[1]}`:e}return e.split(`/`)[0]??e}function nn(e,t){let n=tn(t),r=e;for(;;){let e=j.join(r,`node_modules`,...n.split(`/`));if(k.existsSync(j.join(e,`package.json`)))return!0;let t=j.dirname(r);if(t===r)return!1;r=t}}const rn=[{componentId:`rari/image`,devSourceSegments:[`src`,`image`,`image.tsx`],publishedExport:`rari/image`,exports:[`Image`]}],an=j.dirname(N(import.meta.url)),Z=j.dirname(an);function on(e){return e.startsWith(Z)}function sn(e,t){return on(e)?j.join(Z,`src`):j.join(t,`src`)}function cn(){let e=j.join(Z,`src`,`runtime`,`boundaries`,`error-boundary-wrapper.tsx`);if(k.existsSync(e))return e;try{let e=N(import.meta.resolve(`rari/runtime/ErrorBoundaryWrapper`));if(k.existsSync(e))return e}catch{}return null}function ln(e){let t=e.replace(b,`/`);return t.includes(`ErrorBoundaryWrapper`)||t.includes(`/boundaries/error-boundary-wrapper`)||t.endsWith(`/error-boundary-wrapper.tsx`)}function un(e,t){if(ln(e))return`virtual:error-boundary-wrapper.tsx`;let n=j.relative(t,e).replace(b,`/`);return n.startsWith(`..`)||j.isAbsolute(n)?e.replace(b,`/`):n}function dn(e,t){if(ln(e))return`error_boundary_wrapper_${R(`virtual:error-boundary-wrapper.tsx`)}`;if(on(e)){let t=j.relative(Z,e).replace(b,`/`);return`${qe(t)}_${R(t)}`}return B(e,t)}let fn=null;async function pn(){return fn||=(await import(`lightningcss`)).transform,fn}function mn(e){return a(e)&&a(e.components)}function Q(e,t,n,r){return e.includes(`node_modules`)||n.has(r??Y(e))?!1:!t.directives.hasUseClient&&!t.directives.hasUseServer}var hn=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=j.join(this.options.outDir,`assets`,`server`);await k.promises.mkdir(n,{recursive:!0});let r=`${t.join(`
|
|
66
|
+
`)}\n`,i=`${R(e+r,12)}.css`,a=j.join(n,i);return await k.promises.writeFile(a,r,`utf-8`),[`/assets/server/${i}`]}getComponentIdFromRouteManifestPath(e){return this.getComponentId(j.join(this.projectRoot,`src`,`app`,e))}getComponentReferenceId(e){return this.getReadableComponentId(this.getProjectRelativePath(e))}async writeRouteCssEntries(e){let t=j.join(this.options.outDir,this.options.rscDir,`routes.json`);if(!k.existsSync(t))return;let n=await k.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 k.promises.writeFile(t,JSON.stringify(i),`utf-8`)}constructor(e,t={}){this.projectRoot=e,this.moduleAnalysisCache=t.moduleAnalysisCache??new Ct;let n=t.rscDir!=null&&t.rscDir!==``?t.rscDir:`server`;this.options={outDir:t.outDir!=null&&t.outDir!==``?t.outDir:j.join(e,`dist`),rscDir:n,manifestPath:t.manifestPath!=null&&t.manifestPath!==``?t.manifestPath:j.join(n,`manifest.json`),serverConfigPath:t.serverConfigPath!=null&&t.serverConfigPath!==``?t.serverConfigPath:j.join(n,`config.json`),minify:t.minify??M.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,htmlLimitedBots:t.htmlLimitedBots,experimental:t.experimental,mdx:t.mdx},this.parseHtmlImports()}parseHtmlImports(){for(let e of Wt(this.projectRoot))this.htmlOnlyImports.add(e)}getModuleAnalysis(e,t){return this.moduleAnalysisCache.get(e,t)}isServerComponent(e,t){try{return Q(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=j.dirname(e);n=j.resolve(r,t)}else if(n=w(t,this.options.alias,this.projectRoot),(n==null||n===``)&&t.startsWith(`@/`)){let e=t.slice(2);n=j.join(this.projectRoot,`src`,e)}return n==null||n===``?null:C(n,[``,`.ts`,`.tsx`,`.js`,`.jsx`])}populateImportGraphFromFiles(e){this.fileImporters.clear();for(let{filePath:t,analysis:n}of e)for(let e of bt(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=gn(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??k.readFileSync(e,`utf-8`),i=n??this.moduleAnalysisCache.get(e,r),a=yt(i.importSources),o=vt(i);if(i.directives.hasUseServer){this.serverActions.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o});return}Q(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:q(e).directives.hasUseServer}extractDependencies(e,t){return yt((t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):q(e)).importSources)}hasNodeImports(e,t){return vt(t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):q(e))}async getTransformedComponentsForDevelopment(){let e=[];for(let[t]of this.serverComponents){let n=j.relative(this.projectRoot,t),r=this.getComponentId(n),i=await this.buildComponentCodeOnly(t);e.push({id:r,code:i,isAction:!1})}for(let[t]of this.serverActions){let n=j.relative(this.projectRoot,t),r=this.getComponentId(n),i=await this.buildComponentCodeOnly(t);e.push({id:r,code:i,isAction:!0})}return e}transformComponentImportsToGlobal(e){let t=[];for(let n of e.matchAll(Kt)){let[e,r,i]=n;if(!i.startsWith(`.`)&&!i.startsWith(`@`)&&!i.startsWith(`~`)&&!i.startsWith(`#`))continue;let a=null;if(i.startsWith(`.`)){if(i.includes(`/components/`)){let n=Yt.exec(i);if(n){let i=n[1],a=[j.resolve(this.projectRoot,`src`,`components`,`${i}.tsx`),j.resolve(this.projectRoot,`src`,`components`,`${i}.ts`),j.resolve(this.projectRoot,`src`,`components`,`${i}.jsx`),j.resolve(this.projectRoot,`src`,`components`,`${i}.js`)],o=!1;for(let e of a)if(k.existsSync(e)&&this.isClientComponent(e)){o=!0;break}if(!o)continue;let s=`// Component reference: ${i}
|
|
48
67
|
const ${r} = (props) => {
|
|
49
68
|
let Component = globalThis['~clientComponents']?.['components/${i}']?.component
|
|
50
69
|
|| globalThis['components/${i}'];
|
|
@@ -62,7 +81,7 @@ const ${r} = (props) => {
|
|
|
62
81
|
}
|
|
63
82
|
|
|
64
83
|
return Component(props);
|
|
65
|
-
}`;t.push({original:e,replacement:s})}}continue}let o=this.options.alias;for(let[e,t]of Object.entries(o))if(i.startsWith(`${e}/`)||i===e){let n=i.slice(e.length).replace(/^\/+/,``);a=j.join(t,n);break}if(a!=null&&a!==``){let n=
|
|
84
|
+
}`;t.push({original:e,replacement:s})}}continue}let o=this.options.alias;for(let[e,t]of Object.entries(o))if(i.startsWith(`${e}/`)||i===e){let n=i.slice(e.length).replace(/^\/+/,``);a=j.join(t,n);break}if(a!=null&&a!==``){let n=Xt.exec(a);if(n){let i=n[1],o=j.isAbsolute(a)?a:j.resolve(this.projectRoot,a),s=[o,`${o}.tsx`,`${o}.ts`,`${o}.jsx`,`${o}.js`],c=!1,l=o;for(let e of s)if(k.existsSync(e)){l=e,this.isClientComponent(e)&&(c=!0);break}if(!c)continue;let u=this.getComponentReferenceId(l),d=`// Component reference: ${i}
|
|
66
85
|
const ${r} = (props) => {
|
|
67
86
|
let Component = globalThis['~clientComponents']?.['${u}']?.component
|
|
68
87
|
|| globalThis['${u}'];
|
|
@@ -80,12 +99,12 @@ const ${r} = (props) => {
|
|
|
80
99
|
}
|
|
81
100
|
|
|
82
101
|
return Component(props);
|
|
83
|
-
}`;t.push({original:e,replacement:d})}}}let n=e;for(let{original:e,replacement:r}of t)n=n.replace(e,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:`)&&!J(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!J(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=j.dirname(r),s=
|
|
102
|
+
}`;t.push({original:e,replacement:d})}}}let n=e;for(let{original:e,replacement:r}of t)n=n.replace(e,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:`)&&!J(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!J(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=j.dirname(r),s=Jt.test(j.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=j.resolve(o,t);for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`,``]){let n=e+t;if(k.existsSync(n)&&k.statSync(n).isFile())return n}for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=j.join(e,`index${t}`);if(k.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`)||on(n)||t.startsWith(`node:`)||J(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=w(t,i,this.projectRoot),(r==null||r===``)&&(t.startsWith(`./`)||t.startsWith(`../`))){let i=n===e?o:j.dirname(n);r=j.resolve(i,t)}if((r==null||r===``)&&j.isAbsolute(t)&&(r=t),r!==``)for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=r+e;if(k.existsSync(t)&&k.statSync(t).isFile()){if(this.isClientComponent(t)){let e=j.relative(this.projectRoot,t),n=(e.startsWith(`..`)?t:e).replace(b,`/`);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=j.relative(this.projectRoot,t),r=(c.get(t)??(n.startsWith(`..`)?t:n)).replace(b,`/`);return{code:`import { registerClientReference } from ${JSON.stringify(Qt)};
|
|
84
103
|
export default registerClientReference(null, ${JSON.stringify(r)}, "default");
|
|
85
|
-
`,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 k.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=w(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?j.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=j.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(k.existsSync(t)&&k.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=j.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=j.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(k.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:k.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=w(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(k.existsSync(n)&&k.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=j.join(t,`index${e}`);if(k.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=j.join(nn,`proxy/RariResponse.mjs`);if(k.existsSync(e))return e;let t=j.join(Z,`src/proxy/http/response.ts`);if(k.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`)?j.dirname(t):o,r=j.resolve(n,e);if(k.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 dn(),n=k.readFileSync(t),r=e({filename:j.relative(this.projectRoot,t),code:n,cssModules:{pattern:Qt}});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:`)||J(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`||w(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(en(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:D(t).resolve(e)}}catch{try{return{id:N(import.meta.resolve(e,P(t).href))}}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 Ut();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await k.promises.readFile(e,`utf-8`),n=this.transformClientImports(t,e),r=this.isPageComponent(e),i=r?this.transformComponentImportsToGlobal(n):n,a=j.extname(e),o;o=a===`.tsx`?`tsx`:a===`.ts`?`ts`:a===`.jsx`?`jsx`:`js`;let s=`\0virtual:${e}`,c=await I({input:s,platform:`node`,write:!1,external:[Zt,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${o}`]:o},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(M.env.NODE_ENV!=null&&M.env.NODE_ENV!==``?M.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(s,i,o,e,r,[])});if(c.output.length===0)throw Error(`No output generated from Rolldown`);let l=c.output.find(e=>e.type===`chunk`&&e.isEntry);if(l?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let u=l.code;return u=`// Built: ${new Date().toISOString()}\n${u}`,u}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=j.relative(this.projectRoot,n),u=this.getComponentId(n),d=j.join(this.options.rscDir,`${u}.js`),f=j.join(this.options.outDir,d);r++,(async()=>{try{let e=j.dirname(f);await k.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=P(j.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=j.join(this.options.outDir,this.options.rscDir);await k.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=R(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=j.join(this.options.outDir,this.options.manifestPath);await k.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),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 u=j.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await k.promises.unlink(u)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await k.promises.writeFile(u,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=Pt({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=j.join(this.options.outDir,this.options.manifestPath),i;if(k.existsSync(r)){let e=t(await k.promises.readFile(r,`utf-8`));i=e&&fn(e)?e:{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 k.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=j.join(this.options.outDir,`ssr`);await k.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=k.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=on();if(e!=null&&e!==``){let n=k.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=ln(e,this.projectRoot);n.set(j.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=cn(i,this.projectRoot),u=`ssr/${ln(i,this.projectRoot)}.js`,d=j.join(this.options.outDir,u);a++,(async()=>{try{let e=j.dirname(d);await k.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=j.join(e,`manifest.json`);await k.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=j.join(this.options.outDir,`server`);await k.promises.mkdir(i,{recursive:!0});let a=j.join(i,`client-reference-manifest.json`);await k.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=j.join(Z,...e);if(k.existsSync(n))return n;try{let e=N(import.meta.resolve(t));if(k.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of tn){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${R(n)}`}.js`,i=j.join(this.options.outDir,r);await k.promises.mkdir(j.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){let t=[];/export\s+default\b/.test(e)&&t.push(`default`);for(let n of e.matchAll(/export\s+(?:async\s+)?(?:function|const|let|var|class)\s+(\w+)/g))t.push(n[1]);return t.length>0?t:[`default`]}isServerActionFile(e){try{let t=k.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=k.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(`
|
|
104
|
+
`,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 k.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=w(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?j.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=j.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(k.existsSync(t)&&k.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=j.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=j.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(k.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:k.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=w(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(k.existsSync(n)&&k.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=j.join(t,`index${e}`);if(k.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=j.join(an,`proxy/RariResponse.mjs`);if(k.existsSync(e))return e;let t=j.join(Z,`src/proxy/http/response.ts`);if(k.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`)?j.dirname(t):o,r=j.resolve(n,e);if(k.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 pn(),n=k.readFileSync(t),r=e({filename:j.relative(this.projectRoot,t),code:n,cssModules:{pattern:en}});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:`)||J(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`||w(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(nn(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:D(t).resolve(e)}}catch{try{return{id:N(import.meta.resolve(e,P(t).href))}}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 Gt();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await k.promises.readFile(e,`utf-8`),n=this.transformClientImports(t,e),r=this.isPageComponent(e),i=r?this.transformComponentImportsToGlobal(n):n,a=j.extname(e),o;o=a===`.tsx`?`tsx`:a===`.ts`?`ts`:a===`.jsx`?`jsx`:`js`;let s=`\0virtual:${e}`,c=await I({input:s,platform:`node`,write:!1,external:[$t,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${o}`]:o},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(M.env.NODE_ENV!=null&&M.env.NODE_ENV!==``?M.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(s,i,o,e,r,[])});if(c.output.length===0)throw Error(`No output generated from Rolldown`);let l=c.output.find(e=>e.type===`chunk`&&e.isEntry);if(l?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let u=l.code;return u=`// Built: ${new Date().toISOString()}\n${u}`,u}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=j.relative(this.projectRoot,n),u=this.getComponentId(n),d=j.join(this.options.rscDir,`${u}.js`),f=j.join(this.options.outDir,d);r++,(async()=>{try{let e=j.dirname(f);await k.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=P(j.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=j.join(this.options.outDir,this.options.rscDir);await k.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=R(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=j.join(this.options.outDir,this.options.manifestPath);await k.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),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 u=j.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await k.promises.unlink(u)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await k.promises.writeFile(u,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=It({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=j.join(this.options.outDir,this.options.manifestPath),i;if(k.existsSync(r)){let e=t(await k.promises.readFile(r,`utf-8`));i=e&&mn(e)?e:{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 k.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=j.join(this.options.outDir,`ssr`);await k.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=k.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=cn();if(e!=null&&e!==``){let n=k.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=dn(e,this.projectRoot);n.set(j.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=un(i,this.projectRoot),u=`ssr/${dn(i,this.projectRoot)}.js`,d=j.join(this.options.outDir,u);a++,(async()=>{try{let e=j.dirname(d);await k.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=j.join(e,`manifest.json`);await k.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=j.join(this.options.outDir,`server`);await k.promises.mkdir(i,{recursive:!0});let a=j.join(i,`client-reference-manifest.json`);await k.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=j.join(Z,...e);if(k.existsSync(n))return n;try{let e=N(import.meta.resolve(t));if(k.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of rn){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${R(n)}`}.js`,i=j.join(this.options.outDir,r);await k.promises.mkdir(j.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){let t=[];/export\s+default\b/.test(e)&&t.push(`default`);for(let n of e.matchAll(/export\s+(?:async\s+)?(?:function|const|let|var|class)\s+(\w+)/g))t.push(n[1]);return t.length>0?t:[`default`]}isServerActionFile(e){try{let t=k.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=k.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(`
|
|
86
105
|
`)}\n`}generateServerActionReferenceModule(e){let t=k.readFileSync(e,`utf-8`),n=this.extractExportNames(t),r=this.getComponentId(e),i=`import { createServerReference } from 'react-server-dom-webpack/client';
|
|
87
106
|
`;i+=`import { callServer } from 'rari/runtime/call-server';
|
|
88
|
-
`;for(let e of n){let t=`${r}#${e}`;e==="default"?i+=`export default createServerReference(${JSON.stringify(t)}, callServer);\n`:i+=`export const ${e} = createServerReference(${JSON.stringify(t)}, callServer);\n`}return i}async buildSSRSingleClient(e,t,n){let r=(await k.promises.readFile(e,`utf-8`)).replace(/^['"]use client['"];?\s*/m,``),i=j.extname(e),a;a=i===`.tsx`?`tsx`:i===`.ts`?`ts`:i===`.jsx`?`jsx`:`js`;let o=`\0ssr-virtual:${e}`,s=this.projectRoot,c=
|
|
107
|
+
`;for(let e of n){let t=`${r}#${e}`;e==="default"?i+=`export default createServerReference(${JSON.stringify(t)}, callServer);\n`:i+=`export const ${e} = createServerReference(${JSON.stringify(t)}, callServer);\n`}return i}async buildSSRSingleClient(e,t,n){let r=(await k.promises.readFile(e,`utf-8`)).replace(/^['"]use client['"];?\s*/m,``),i=j.extname(e),a;a=i===`.tsx`?`tsx`:i===`.ts`?`ts`:i===`.jsx`?`jsx`:`js`;let o=`\0ssr-virtual:${e}`,s=this.projectRoot,c=sn(e,s),l=e=>this.generateServerActionReferenceModule(e),u=e=>this.isServerActionFile(e),d=(await I({input:o,platform:`node`,write:!1,external:[$t,`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(M.env.NODE_ENV!=null&&M.env.NODE_ENV!==``?M.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=j.join(c,t.slice(2)):r===o?i=j.resolve(j.dirname(e),t):r!=null&&r!==``&&(i=j.resolve(j.dirname(r.replace(`\0ssr-virtual:`,``).replace(`\0server-action-ref:`,``)),t));let a=x(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]),s=a!=null&&a!==``?a:S(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]);if(s!=null&&s!==``&&u(s))return`\0server-action-ref:${j.resolve(s)}`;if(s!=null&&s!==``&&n!=null){let t=j.resolve(s),r=n.get(t);if(r!=null&&r!==``&&t!==j.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 k.promises.writeFile(t,f,`utf-8`),{code:f}}async buildSingleComponent(e,t){let n=await k.promises.readFile(e,`utf-8`),r=this.transformClientImports(n,e),i=this.isPageComponent(e),a=i?this.transformComponentImportsToGlobal(r):r,o=j.extname(e),s;s=o===`.tsx`?`tsx`:o===`.ts`?`ts`:o===`.jsx`?`jsx`:`js`;let c=`\0virtual:${e}`,l=[],u=await I({input:c,platform:`node`,write:!1,external:[$t,`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(M.env.NODE_ENV!=null&&M.env.NODE_ENV!==``?M.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(c,a,s,e,i,l)});if(u.output.length===0)throw Error(`No output generated from Rolldown`);let d=u.output.find(e=>e.type===`chunk`&&e.isEntry);if(d?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let f=d.code;f=`// Built: ${new Date().toISOString()}\n${f}`,await k.promises.writeFile(t,f,`utf-8`);let p=await k.promises.open(t,`r+`);return await p.sync(),await p.close(),{code:f,css:l}}transformClientImports(e,t){let n=e,r,i=[],a=!1,o=rn.map(e=>e.componentId);for(qt.lastIndex=0;r=qt.exec(e),r!==null;){let[e,n,s,c]=r,l=!1,u=c;if(o.includes(c))l=!0;else{let e=this.resolveImportPath(c,t);this.isClientComponent(e)&&(l=!0,u=j.relative(this.projectRoot,e).replace(b,`/`))}if(l){a=!0;let t=``;n?t=`const ${n} = registerClientReference(
|
|
89
108
|
null,
|
|
90
109
|
${JSON.stringify(u)},
|
|
91
110
|
"default"
|
|
@@ -94,9 +113,9 @@ export default registerClientReference(null, ${JSON.stringify(r)}, "default");
|
|
|
94
113
|
${JSON.stringify(u)},
|
|
95
114
|
${JSON.stringify(t)}
|
|
96
115
|
);`}).join(`
|
|
97
|
-
`)),i.push({original:e,replacement:t})}}a&&(n=`import { registerClientReference } from ${JSON.stringify(
|
|
98
|
-
const ${e} = createClientModuleProxy(${JSON.stringify(t)});`}const
|
|
99
|
-
`)},\n])`;return t.replace(
|
|
116
|
+
`)),i.push({original:e,replacement:t})}}a&&(n=`import { registerClientReference } from ${JSON.stringify(Qt)};\n\n${n}`);for(let{original:e,replacement:t}of i)n=n.replace(e,t);return n}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=j.join(i,r);break}j.isAbsolute(n)||(n=j.resolve(j.dirname(t),n));let i=[`.tsx`,`.jsx`,`.ts`,`.js`],a=x(n,i);if(a!=null&&a!==``)return a;let o=S(n,i);return o!=null&&o!==``?o:`${n}.tsx`}getProjectRelativePath(e){return z(e,this.projectRoot)}getReadableComponentId(e){return qe(e)}getComponentId(e){return B(e,this.projectRoot)}async rebuildComponent(e){let t=this.getComponentId(e),n=await k.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=j.join(this.options.rscDir,`${t}.js`),o=j.join(this.options.outDir,a),s=this.buildCache.get(e),c=(await k.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 k.promises.writeFile(o,s.code,`utf-8`),await this.updateManifestForComponent(t,e,a,s.css),{componentId:t,bundlePath:j.join(this.options.outDir,a),success:!0}}let l=j.dirname(o);await k.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:j.join(this.options.outDir,a),success:!0}}manifestCache=null;async updateManifestForComponent(e,n,r,i=[]){let a=j.join(this.options.outDir,this.options.manifestPath),o;if(this.manifestCache)o=this.manifestCache;else if(k.existsSync(a)){let e=t(await k.promises.readFile(a,`utf-8`));e&&mn(e)?(o=e,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=j.join(this.options.outDir,r),l=P(j.resolve(this.projectRoot,c)).href;if(s)o.components[e]={id:e,filePath:n,relativePath:j.relative(this.projectRoot,n),bundlePath:r,moduleSpecifier:l,dependencies:[...s.dependencies],hasNodeImports:s.hasNodeImports,css:i};else{let t=await k.promises.readFile(n,`utf-8`);o.components[e]={id:e,filePath:n,relativePath:j.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 k.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 gn(e,t){let n=[];for(let r of ht(t))try{let t=Y(r),i=k.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 _n(e,t){return(t??q(e)).hasComponentExport||m.test(e)||y.test(e)||ie.test(e)}function vn(e,t,n,r,i){let a=j.basename(e);if(Zt.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)&&Q(e,o,n.getHtmlOnlyImports(),i)&&_n(t,o)}function yn(e,t,n=[]){let r=gn(t,gt(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)),vn(e,o,t,s,n)&&(t.addServerComponent(e,o,s),i.push(e));return{serverComponentPaths:i,clientComponentPaths:a}}function bn(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 hn(n,{...e,alias:s})},buildStart(){if(!t)return;let e=M.env.NODE_ENV===`production`,r=[j.join(n,`dist`,`cache`,`og`),j.join(n,`dist`,`cache`,`images`)];e&&r.push(`/tmp/rari-og-cache`,`/tmp/rari-image-cache`);for(let e of r)try{k.existsSync(e)&&k.rmSync(e,{recursive:!0,force:!0})}catch(t){console.warn(`[rari] Failed to clear cache ${e}:`,t)}let a=j.join(n,`src`);k.existsSync(a)&&yn(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:j.join(n,`src`,`app`),outDir:j.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:j.join(n,`src`,`app`),outDir:j.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:j.join(n,`src`,`app`),outDir:j.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=j.relative(n,e).replace(b,`/`);if(!(!i.startsWith(`src/`)||!v.test(i)))try{let n=await k.promises.readFile(e,`utf-8`),r=t.getModuleAnalysis(e,n),i=t.hasComponent(e);if(!vn(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 xn=/^\s*import\s+\*\s+as\s+(\w+)\s+from\s+['"]([./@][^'"]+)['"].*$/;function Sn(e,t){return`import { createClientModuleProxy } from "react-server-dom-rari/server";
|
|
117
|
+
const ${e} = createClientModuleProxy(${JSON.stringify(t)});`}const Cn=/import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g,wn=/import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g,Tn=/import\s+(\w+)\s*,\s*\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g,En=/defineMdxComponents\s*\(\s*\{([\s\S]*?)\}\s*\)/;function Dn(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 On(e){let t=new Map;for(let n of e.matchAll(Tn))t.set(n[1],n[3]),Dn(n[3],n[2],t);for(let n of e.matchAll(Cn))t.set(n[1],n[2]);for(let n of e.matchAll(wn))Dn(n[2],n[1],t);return t}function kn(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 An(e){try{return q(k.readFileSync(e,`utf-8`)).topLevelUseClient}catch{return!1}}function jn(e){let{code:t,id:n,projectRoot:r,resolvedAlias:i}=e;if(!t.includes(`defineMdxComponents`)||t.includes(`__RARI_MDX_RESOLVED__`))return null;let a=En.exec(t);if(!a)return null;let o=On(t),s=kn(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=ce(a,n,i),c=z(s,r).replace(b,`/`),l=An(s);return` { name: ${JSON.stringify(e)}, component: ${t}, id: ${JSON.stringify(c)}, client: ${l} }`}).join(`,
|
|
118
|
+
`)},\n])`;return t.replace(En,c)}function Mn(e){return a(e)}function Nn(e){return a(e)}async function Pn(e){let t=await import(e);return Mn(t)?t:{}}function Fn(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 In(e,t,n,r){typeof e.getData==`function`&&Fn(await e.getData({params:t,searchParams:n}),r)}async function Ln(e,t,n,r){typeof e.getServerSideProps==`function`&&Fn(await e.getServerSideProps({params:t,searchParams:n}),r)}async function Rn(e,t,n){typeof e.getStaticProps==`function`&&Fn(await e.getStaticProps({params:t}),n)}async function zn(e,t,n){try{let r=await Pn(e),i={props:{}};return await In(r,t,n,i),await Ln(r,t,n,i),await Rn(r,t,i),i}catch(t){return console.error(`[rari] Router: Failed to extract server props from ${e}:`,t),{props:{}}}}async function Bn(e,t,n){try{let r=await Pn(e);if(typeof r.generateMetadata==`function`){let e=await r.generateMetadata({params:t,searchParams:n});if(Nn(e))return e}return Nn(r.metadata)?r.metadata:{}}catch(t){return console.error(`[rari] Router: Failed to extract metadata from ${e}:`,t),{}}}async function Vn(e){try{let t=await ge(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 Hn(e){try{let t=await Pn(e);return!!(t.getData??t.getServerSideProps??t.getStaticProps??t.generateMetadata??t.generateStaticParams)}catch{return!1}}const $=new Map;async function Un(e,t,n,r=6e4){let i=`${e}:${JSON.stringify(t)}:${JSON.stringify(n)}`,a=$.get(i);if(a&&Date.now()-a.timestamp<r)return a.result;let o=await zn(e,t,n);return $.set(i,{result:o,timestamp:Date.now()}),o}function Wn(){$.clear()}function Gn(e){for(let t of $.keys())t.startsWith(e)&&$.delete(t)}const Kn="[rari] Runtime dist not built. Run `pnpm build` in the rari package first.",qn=/import\s+type\s+(\{[^}]+\})\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Jn=/import\s+type\s+(\*\s+as\s+\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Yn=/import\s+type\s+(\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Xn=/import\s+(\{[^}]+\})\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Zn=/import\s+(\*\s+as\s+\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,Qn=/import\s+(\w+)\s+from\s+["']\.\.?\/([^"']+)["'];?/g,$n=/import\s+["']\.\.?\/([^"']+)["'];?/g,er=/export\s*\{([^}]+)\}/g,tr=/\s+as\s+/,nr=/export\s+default\s+(?:function|class)\s+\w+/,rr=/export\s+default\s+(?:async\s+)?function\s+(\w+)/,ir=/export\s+default\s+([^;]+)/,ar=/export\s+(?:async\s+)?(?:const|let|var|function|class)\s+(\w+)/g,or=/^['"]use client['"];?\s*$/gm,sr=/import\s+["']([^"']+)["']/g,cr=/^\s*import\s+(?:(\w+)(?:\s*,\s*\{\s*(?:(\w+(?:\s*,\s*\w+)*)\s*)?\})?|\{\s*(\w+(?:\s*,\s*\w+)*)\s*\})\s+from\s+['"]([./@][^'"]+)['"].*$/,lr=/import\s+\{[^}]*\}\s+from\s+['"]react['"]/,ur=/import\s+[^,\s]+\s*,\s*\{[^}]*\}\s+from\s+['"]react['"]/,dr=/import React(,\s*\{([^}]*)\})?\s+from\s+['"]react['"];?/,fr=/import\s+["']([^"']+)["']/g,pr=/from(\s*)(['"])(?:\.\/vendor\/react-flight-client\/index|rari\/runtime\/vendor\/react-flight-client\/index)\.mjs\2/g,mr=/\bJSX\b/,hr=/\{([^}]*)\}/,gr=/^['"]use client['"];?\s*\n/;function _r(e,t){let n=[];t!=null&&t!==``&&n.push({bindingName:t,exportName:`default`});let r=/\{([^}]+)\}/.exec(e)?.[1];if(r!=null&&r!==``)for(let e of r.split(`,`)){let t=e.trim();if(!t)continue;let r=t.split(/\s+as\s+/i);r.length===2&&r[0]&&r[1]?n.push({bindingName:r[1].trim(),exportName:r[0].trim()}):n.push({bindingName:t,exportName:t})}return n}function vr(e,t){return`import { registerClientReference } from "react-server-dom-rari/server";
|
|
100
119
|
${e.map(({bindingName:e,exportName:n})=>`const ${e} = registerClientReference(
|
|
101
120
|
function() {
|
|
102
121
|
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.");
|
|
@@ -104,12 +123,12 @@ ${e.map(({bindingName:e,exportName:n})=>`const ${e} = registerClientReference(
|
|
|
104
123
|
${JSON.stringify(t)},
|
|
105
124
|
${JSON.stringify(n)}
|
|
106
125
|
);`).join(`
|
|
107
|
-
`)}`}const
|
|
126
|
+
`)}`}const yr={remotePatterns:[],localPatterns:[],deviceSizes:p,imageSizes:f,formats:u,qualityAllowlist:d,minimumCacheTTL:60,maxCacheSize:l},br=new Map;async function xr(e){let t=br.get(e);if(t!=null&&t!==``)return t;let n=import.meta.url,r=N(n),i=j.dirname(r),a=[j.join(i,`runtime`,e),j.join(i,`../runtime`,e)];for(let t of a)try{let n=await k.promises.readFile(t,`utf-8`);return t.endsWith(`.ts`)&&(n=n.replace(qn,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Jn,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Yn,(e,t,n)=>`import type ${t} from "rari/${n}";`),n=n.replace(Xn,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace(Zn,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace(Qn,(e,t,n)=>`import ${t} from "rari/${n}";`),n=n.replace($n,(e,t)=>`import "rari/${t}";`)),br.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 Sr=j.dirname(N(import.meta.url)),Cr=j.dirname(Sr);function wr(e){let t=[j.join(Sr,`runtime`,e),j.join(Sr,`../runtime`,e)];for(let e of t)if(k.existsSync(e))return e;return null}function Tr(e){return e.startsWith(Cr)}async function Er(){return xr(`rsc-client-runtime.mjs`)}async function Dr(e,t){return(await xr(`entry-client.mjs`)).replace(`/*! @preserve CLIENT_COMPONENT_IMPORTS_PLACEHOLDER */`,e).replace(`/*! @preserve CLIENT_COMPONENT_REGISTRATIONS_PLACEHOLDER */`,t)}async function Or(){return xr(`rsc-references.mjs`)}async function kr(e,t){let r=j.join(e,`src`),{getBinaryPath:i}=await import(`./platform.mjs`),a=O(i(),[`scan-images`,`--src`,r],{encoding:`utf8`,cwd:e,shell:!1,timeout:6e4});if(a.error)throw Error(`Failed to scan for image usage: ${a.error.message}`);if(a.signal)throw Error(`Failed to scan for image usage: process terminated by signal ${a.signal}`);if(a.status!==0)throw Error(`Failed to scan for image usage: ${a.stderr||a.stdout||`exit code ${a.status}`}`);let o;try{o={images:n(a.stdout,`images`)??[]}}catch(e){let t=e instanceof SyntaxError||e instanceof Error?e.message:String(e),n=(a.stdout||a.stderr||`(empty)`).slice(0,500);throw Error(`Failed to parse image scanner output as JSON: ${t}. Scanner output: ${n}`,{cause:e})}let s={...yr,...t.images,preoptimizeManifest:o.images},c=j.join(e,`dist`),l=j.join(c,`server`);k.existsSync(l)||k.mkdirSync(l,{recursive:!0});let u=j.join(l,`image.json`);k.writeFileSync(u,JSON.stringify(s))}function Ar(e){return e}function jr(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 Ct,l=null,u=null,d=null,f={},p=null;function m(){p=null}function h(){return p!=null&&p!==``||(p=Lt(It({projectRoot:e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),mdxOptions:e.mdx,alias:f,cache:c}))),p}function g(e){return n.get(Y(e))}function y(e,t){n.set(Y(e),t)}function ee(e){xt(n,e)}function te(e){r.add(Y(e))}function re(e){return r.has(Y(e))}function ie(e){r.delete(e);try{r.delete(k.realpathSync(e))}catch{r.delete(j.resolve(e))}}function x(){let e=new Set(r);if(l)for(let t of l.getClientComponentPaths())e.add(t);return e}function S(e){let t={hasUseServer:!1,hasUseClient:!1},n=e.replace(b,`/`);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 C=null,w=null;function le(){if(l)return l.getHtmlOnlyImports();let t=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),n=j.join(t,`index.html`);try{let e=k.statSync(n).mtimeMs;if(C!==null&&e===w)return C;w=e}catch{return C??=new Set,C}return C=Wt(t),C}function T(e){if(e.includes(`node_modules`)||Tr(e))return!1;let t=Y(e);try{return Q(t,c.get(e),le(),t)}catch{return!1}}function E(e,t){try{let n=[],r=e.matchAll(er);for(let e of r){let t=e[1].split(`,`);for(let e of t){let t=e.trim().split(tr).at(-1)?.trim();t!=null&&t!==``&&n.push(t)}}(nr.test(e)||(t?.hasDefaultExport??st(e)))&&n.push(`default`);let i=e.matchAll(ar);for(let e of i)e[1]&&n.push(e[1]);return[...new Set(n)]}catch{return[]}}function D(t,n,r){if(!r.topLevelUseServer)return t;let i=E(t,r);if(i.length===0)return t;let a=B(n,e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd()),o=JSON.stringify(a),s=t;s+=`
|
|
108
127
|
|
|
109
128
|
import {registerServerReference} from "react-server-dom-rari/server";
|
|
110
|
-
`;for(let e of i)if(e==="default"){let n=
|
|
129
|
+
`;for(let e of i)if(e==="default"){let n=rr.exec(t);if(n){let t=n[1];s+=`
|
|
111
130
|
// Register server reference for default export
|
|
112
|
-
`,s+=`registerServerReference(${t}, ${o}, ${JSON.stringify(e)});\n`}else{let n=
|
|
131
|
+
`,s+=`registerServerReference(${t}, ${o}, ${JSON.stringify(e)});\n`}else{let n=ir.exec(t);if(n){let t=n[1].trim(),r=`__default_export__`;s=s.replace(ir,`const ${r} = ${t};\nexport default ${r}`),s+=`
|
|
113
132
|
// Register server reference for default export
|
|
114
133
|
`,s+=`if (typeof ${r} === "function") {\n`,s+=` registerServerReference(${r}, ${o}, ${JSON.stringify(e)});\n`,s+=`}
|
|
115
134
|
`}}}else s+=`\n// Register server reference for ${e}\n`,s+=`if (typeof ${e} === "function") {\n`,s+=` registerServerReference(${e}, ${o}, ${JSON.stringify(e)});\n`,s+=`}
|
|
@@ -121,8 +140,8 @@ if (import.meta.hot) {
|
|
|
121
140
|
}`,s}function O(t,n,r){let i=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),a=T(n);if(r.topLevelUseServer){let e=E(t,r);if(e.length===0)return``;let a=B(n,i),o=`import { createServerReference } from "virtual:react-flight-client";
|
|
122
141
|
`;o+=`import { callServer } from "rari/runtime/call-server";
|
|
123
142
|
`;for(let t of e){let e=`${a}#${t}`,n=JSON.stringify(e);t==="default"?o+=`export default createServerReference(${n}, callServer);\n`:o+=`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=E(t,r);if(o.length===0)return``;let s=JSON.stringify(n),c=`import {registerClientReference} from "react-server-dom-rari/server";
|
|
124
|
-
`;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 A(e,t,n){return!n.topLevelUseClient||E(e,n).length===0?e:e.replace(
|
|
125
|
-
`);for(let t of e){let e=t.match(
|
|
143
|
+
`;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 A(e,t,n){return!n.topLevelUseClient||E(e,n).length===0?e:e.replace(or,``)}let P=!1;async function F(){let e=`http://localhost:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`;try{let t=(await fetch(`${e}/_rari/health`,{signal:AbortSignal.timeout(1e3)})).ok;return P=t,t}catch{return P=!1,!1}}let I=[{name:`rari`,config(t,{command:n}){if(t.define??={},n===`serve`||M.env.RARI_SERVER_URL!=null&&M.env.RARI_SERVER_URL!==``||M.env.RARI_HOST!=null&&M.env.RARI_HOST!==``){let e=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3),n;if(M.env.RARI_SERVER_URL!=null&&M.env.RARI_SERVER_URL!==``)n=M.env.RARI_SERVER_URL;else if(M.env.RARI_HOST!=null&&M.env.RARI_HOST!==``){let t=M.env.RARI_HOST.startsWith(`http`)?M.env.RARI_HOST:`http://${M.env.RARI_HOST}`;n=t.replace(oe,``).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:en}},n===`build`){let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),r=j.join(n,`index.html`);if(k.existsSync(r))try{let e=k.readFileSync(r,`utf-8`),n=[];for(let t of e.matchAll(sr)){let e=t[1];if(e.startsWith(`/src/`)&&v.test(e)){let t=e.slice(1),r=j.basename(t,j.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=N(import.meta.resolve(`react`)),t=N(import.meta.resolve(`react-dom/client`)),n=N(import.meta.resolve(`react/jsx-runtime`)),r=[];f.has(`react/jsx-runtime`)||r.push({find:`react/jsx-runtime`,replacement:n});try{let e=N(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=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3);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=>S(e).hasUseServer)?`client/actions/[name]-[hash].js`:e.moduleIds.some(e=>S(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=jn({code:t,id:n,projectRoot:e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.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 Gt();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`),te(n);let e=t.split(`
|
|
144
|
+
`);for(let t of e){let e=t.match(xn),r=e?null:cr.exec(t);if(!e&&!r)continue;let i=e?.[2]??r[4];if(!i)continue;let a=ce(i,n,f);k.existsSync(a)&&(y(a,`client`),te(a))}return A(t,n,o)}if(g(n)===`client`||re(n))return A(t,n,o);if(T(n)){if(y(n,`server`),a.name===`rsc`||a.name===`ssr`)return D(t,n,o);{let e=O(t,n,o);return e=`// HMR acceptance for server component
|
|
126
145
|
if (import.meta.hot) {
|
|
127
146
|
import.meta.hot.accept();
|
|
128
147
|
if (typeof globalThis !== 'undefined') {
|
|
@@ -133,8 +152,8 @@ if (import.meta.hot) {
|
|
|
133
152
|
}
|
|
134
153
|
|
|
135
154
|
${e}`,e}}if(o.topLevelUseServer)return y(n,`server`),a.name===`rsc`||a.name===`ssr`?D(t,n,o):O(t,n,o);let s=g(n);if(s===`server`)return a.name===`rsc`||a.name===`ssr`?D(t,n,o):O(t,n,o);if(s===`client`)return A(t,n,o);y(n,`unknown`);let l=t.split(`
|
|
136
|
-
`),u=t,d=!1,p=!1,h=n.includes(`entry-client`);for(let e of l){let t=e.match(
|
|
137
|
-
`),t&&(u=t+u),!u.includes(`Suspense`)){let e=lr.exec(u);e&&(e[1]&&!e[2].includes(`Suspense`)?u=u.replace(e[0],e[0].replace(pr,`{ Suspense, $1 }`)):e[1]||(u=u.replace(e[0],`import React, { Suspense } from 'react';`)))}let r=M.env.NODE_ENV!==`production`;return(u.includes(`</`)||u.includes(`/>`)||fr.test(u))&&r&&(u=`'use client';\n\n${u}`,y(n,`client`)),u}return i?t:null},async configureServer(n){let r=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),i=j.join(r,`src`);await Dr(r,e);let a=async()=>{try{let t=new pn(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,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c});if(l=t,d||=new Ot(t,M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)),k.existsSync(i)){let e=_n(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:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`;for(let e of a)try{if(e.id.startsWith(`app/`)||e.isAction)continue;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:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`,t=x();for(let n of t){let t=j.relative(M.cwd(),n),r=j.basename(n).replace(ae,``);try{await fetch(`${e}/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:r,file_path:t,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=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3),c=M.env.NODE_ENV===`production`?`production`:`development`,l=n.config.server.port,d=[`--mode`,c,`--port`,s.toString(),`--host`,`127.0.0.1`];u=de(i,d,{stdio:[`ignore`,`pipe`,`pipe`],cwd:M.cwd(),env:{...M.env,RUST_LOG:M.env.RUST_LOG!=null&&M.env.RUST_LOG!==``?M.env.RUST_LOG:`error`,RARI_VITE_PORT:l.toString(),...e.jsPoolSize!=null&&(M.env.RARI_JS_POOL_SIZE==null||M.env.RARI_JS_POOL_SIZE===``)?{RARI_JS_POOL_SIZE:String(e.jsPoolSize)}:{},...e.htmlLimitedBots!=null&&(M.env.RARI_HTML_LIMITED_BOTS==null||M.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=>{P=!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,P=!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}`)});let f=!1;for(let e=0;e<20&&(f=await F(),!f);e++)await new Promise(e=>{setTimeout(e,500)});f?(await a(),await o()):console.error(`Server failed to become ready for component registration`)},p=async e=>{try{if(!T(e))return;l??await a();let t=l;if(t==null)return;let n=c.getSource(e);t.addServerComponent(e,n);let r=await t.getTransformedComponentsForDevelopment();if(r.length===0)return;let i=`http://localhost:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`;for(let e of r)try{let t=await fetch(`${i}/_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)),setTimeout(()=>{a()},1e3)}};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(!P){let e=await F();if(!e){let n=Date.now();for(;Date.now()-n<1e4&&(e=await F(),!e);)await new Promise(e=>{setTimeout(e,100)});if(!e){console.error(`[rari] Rust server not ready, cannot proxy RSC request`),t.headersSent||(t.statusCode=503,t.end(`Server not ready`));return}}}let n=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3),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(ue.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)&&(ee(e),ie(e),c.invalidate(e)),v.test(e)&&e.includes(i)&&(T(e)?(n.ws.send({type:`custom`,event:`rari:register-server-component`,data:{filePath:e}}),await p(e)):setTimeout(()=>{a()},1e3))})()}),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,P=!1;let t=!1,n=setTimeout(()=>{t||e.kill(`SIGKILL`)},5e3);n.unref(),e.once(`exit`,()=>{t=!0,clearTimeout(n)}),e.kill(`SIGTERM`);return}P=!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(kt(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=Sr(j.basename(e));if(t!=null&&t!==``)return t}if(t!=null&&t!==``&&t.startsWith(`virtual:`)&&e.startsWith(`../`)){let n=import.meta.url,r=N(n),i=j.dirname(r),a=null,o=[j.join(i,`runtime`),j.join(i,`../runtime`)];for(let e of o)if(k.existsSync(e)){a=e;break}if(a!=null&&a!==``){let t=j.join(a,e);if(k.existsSync(t))return t;let n=j.join(a,`../dist`,j.basename(e));if(k.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=j.join(i,e);if(k.existsSync(s))return s;let c=j.join(i,`../dist`,j.basename(e));if(k.existsSync(c))return c}if(M.env.NODE_ENV===`production`)try{let t=j.resolve(e);if(k.existsSync(t)&&T(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 O(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:M.cwd(),n=bt(mt(j.join(t,`src`),Object.values(f)),c),r=new Set([...x(),...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=j.relative(M.cwd(),e).replace(b,`/`),n=t.replace(v,``),r=t.startsWith(`..`)?e.replace(b,`/`):t,i=!1,a=``;try{if(!c.get(e).hasDefaultExport){let t=c.getSource(e).match(ne);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:j.basename(e,j.extname(e)),u=r.replace(b,`/`),d=u.startsWith(`/`)||_.test(u)?u:`/${u}`;return` "${r}": {
|
|
155
|
+
`),u=t,d=!1,p=!1,h=n.includes(`entry-client`);for(let e of l){let t=e.match(xn),r=t?null:cr.exec(e);if(!t&&!r)continue;let i=r?.[1],o=ce(t?.[2]??r[4],n,f),s=g(o)===`client`||k.existsSync(o)&&c.get(o).topLevelUseClient;if(s&&(y(o,`client`),te(o)),s&&(a.name===`rsc`||a.name===`ssr`)&&!h){let n=e;if(t){let e=Sn(t[1],o);u=u.replace(n,e),d=!0,p=!0;continue}let r=_r(e,i);if(r.length===0)continue;let a=vr(r,o);u=u.replace(n,a),d=!0,p=!0}}if(d){let e=u.includes(`import React`)||lr.test(u)||ur.test(u),t=``;if(p&&!e&&(t+=`import React from 'react';
|
|
156
|
+
`),t&&(u=t+u),!u.includes(`Suspense`)){let e=dr.exec(u);e&&(e[1]&&!e[2].includes(`Suspense`)?u=u.replace(e[0],e[0].replace(hr,`{ Suspense, $1 }`)):e[1]||(u=u.replace(e[0],`import React, { Suspense } from 'react';`)))}let r=M.env.NODE_ENV!==`production`;return(u.includes(`</`)||u.includes(`/>`)||mr.test(u))&&r&&(u=`'use client';\n\n${u}`,y(n,`client`)),u}return i?t:null},async configureServer(n){let r=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),i=j.join(r,`src`);await kr(r,e);let a=async()=>{try{let t=new hn(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,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c});if(l=t,d||=new At(t,M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)),k.existsSync(i)){let e=yn(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:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`;for(let e of a)try{if(e.id.startsWith(`app/`)||e.isAction)continue;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:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`,t=x();for(let n of t){let t=j.relative(M.cwd(),n),r=j.basename(n).replace(ae,``);try{await fetch(`${e}/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:r,file_path:t,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=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3),c=M.env.NODE_ENV===`production`?`production`:`development`,l=n.config.server.port,d=[`--mode`,c,`--port`,s.toString(),`--host`,`127.0.0.1`];u=de(i,d,{stdio:[`ignore`,`pipe`,`pipe`],cwd:M.cwd(),env:{...M.env,RUST_LOG:M.env.RUST_LOG!=null&&M.env.RUST_LOG!==``?M.env.RUST_LOG:`error`,RARI_VITE_PORT:l.toString(),...e.jsPoolSize!=null&&(M.env.RARI_JS_POOL_SIZE==null||M.env.RARI_JS_POOL_SIZE===``)?{RARI_JS_POOL_SIZE:String(e.jsPoolSize)}:{},...e.htmlLimitedBots!=null&&(M.env.RARI_HTML_LIMITED_BOTS==null||M.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=>{P=!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,P=!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}`)});let f=!1;for(let e=0;e<20&&(f=await F(),!f);e++)await new Promise(e=>{setTimeout(e,500)});f?(await a(),await o()):console.error(`Server failed to become ready for component registration`)},p=async e=>{try{if(!T(e))return;l??await a();let t=l;if(t==null)return;let n=c.getSource(e);t.addServerComponent(e,n);let r=await t.getTransformedComponentsForDevelopment();if(r.length===0)return;let i=`http://localhost:${M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3)}`;for(let e of r)try{let t=await fetch(`${i}/_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)),setTimeout(()=>{a()},1e3)}};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(!P){let e=await F();if(!e){let n=Date.now();for(;Date.now()-n<1e4&&(e=await F(),!e);)await new Promise(e=>{setTimeout(e,100)});if(!e){console.error(`[rari] Rust server not ready, cannot proxy RSC request`),t.headersSent||(t.statusCode=503,t.end(`Server not ready`));return}}}let n=M.env.SERVER_PORT!=null&&M.env.SERVER_PORT!==``?Number(M.env.SERVER_PORT):Number(M.env.PORT!=null&&M.env.PORT!==``?M.env.PORT:M.env.RSC_PORT!=null&&M.env.RSC_PORT!==``?M.env.RSC_PORT:3e3),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(ue.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)&&(ee(e),ie(e),c.invalidate(e)),v.test(e)&&e.includes(i)&&(T(e)?(n.ws.send({type:`custom`,event:`rari:register-server-component`,data:{filePath:e}}),await p(e)):setTimeout(()=>{a()},1e3))})()}),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,P=!1;let t=!1,n=setTimeout(()=>{t||e.kill(`SIGKILL`)},5e3);n.unref(),e.once(`exit`,()=>{t=!0,clearTimeout(n)}),e.kill(`SIGTERM`);return}P=!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(jt(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=wr(j.basename(e));if(t!=null&&t!==``)return t}if(t!=null&&t!==``&&t.startsWith(`virtual:`)&&e.startsWith(`../`)){let n=import.meta.url,r=N(n),i=j.dirname(r),a=null,o=[j.join(i,`runtime`),j.join(i,`../runtime`)];for(let e of o)if(k.existsSync(e)){a=e;break}if(a!=null&&a!==``){let t=j.join(a,e);if(k.existsSync(t))return t;let n=j.join(a,`../dist`,j.basename(e));if(k.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=j.join(i,e);if(k.existsSync(s))return s;let c=j.join(i,`../dist`,j.basename(e));if(k.existsSync(c))return c}if(M.env.NODE_ENV===`production`)try{let t=j.resolve(e);if(k.existsSync(t)&&T(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 O(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:M.cwd(),n=St(gt(j.join(t,`src`),Object.values(f)),c),r=new Set([...x(),...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=j.relative(M.cwd(),e).replace(b,`/`),n=t.replace(v,``),r=t.startsWith(`..`)?e.replace(b,`/`):t,i=!1,a=``;try{if(!c.get(e).hasDefaultExport){let t=c.getSource(e).match(ne);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:j.basename(e,j.extname(e)),u=r.replace(b,`/`),d=u.startsWith(`/`)||_.test(u)?u:`/${u}`;return` "${r}": {
|
|
138
157
|
id: "${n}",
|
|
139
158
|
path: "${r}",
|
|
140
159
|
exportName: "${s}",
|
|
@@ -159,7 +178,7 @@ globalThis['~clientComponents']["${e.path}"] = globalThis['~clientComponents']["
|
|
|
159
178
|
globalThis['~clientComponents']["${e.path}"].component = ExternalModule${t};
|
|
160
179
|
globalThis['~clientComponentPaths'] = globalThis['~clientComponentPaths'] || {};
|
|
161
180
|
globalThis['~clientComponentPaths']["${e.path}"] = "${n}";`)).join(`
|
|
162
|
-
`);return
|
|
181
|
+
`);return Dr(s,[`
|
|
163
182
|
const lazyComponentRegistry = {
|
|
164
183
|
${a}
|
|
165
184
|
};
|
|
@@ -172,9 +191,9 @@ for (const [path, config] of Object.entries(lazyComponentRegistry)) {
|
|
|
172
191
|
globalThis['~clientComponentPaths'][path] = config.id;
|
|
173
192
|
}
|
|
174
193
|
`,l].filter(Boolean).join(`
|
|
175
|
-
`))}if(t===`react-server-dom-rari/server`)return
|
|
194
|
+
`))}if(t===`react-server-dom-rari/server`)return Or();if(t===`virtual:app-router-provider.tsx`){let e=wr(`AppRouterProvider.mjs`);if(e!=null&&e!==``)return k.readFileSync(e,`utf-8`);throw Error(Kn)}if(t===`virtual:loading-error-boundary.tsx`){let e=wr(`LoadingErrorBoundary.mjs`);if(e!=null&&e!==``)return k.readFileSync(e,`utf-8`);throw Error(Kn)}if(t===`virtual:error-boundary-wrapper.tsx`){let e=wr(`ErrorBoundaryWrapper.mjs`);if(e!=null&&e!==``){let t=k.readFileSync(e,`utf-8`);if(!t.includes(`import React`)&&!t.includes(`from "react"`)&&!t.includes(`from 'react'`)){let e=gr.exec(t);if(e){let n=e[0];return`
|
|
176
195
|
${n}import * as React from 'react';\n${t.slice(n.length)}`}return`
|
|
177
|
-
import * as React from 'react';\n${t}`}return t}throw Error(
|
|
196
|
+
import * as React from 'react';\n${t}`}return t}throw Error(Kn)}if(t===`virtual:rsc-integration.ts`)return(await Er()).replace(pr,(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=j.dirname(N(import.meta.resolve(`react-server-dom-webpack/package.json`)));e=j.join(n,`cjs/react-server-dom-webpack-client.browser.production.js`),t=j.join(n,`cjs/react-server-dom-webpack-client.edge.production.js`)}catch{let n=j.dirname(N(import.meta.url)),r=j.resolve(n,`../../node_modules`);e=j.join(r,`react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.js`),t=j.join(r,`react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.js`)}return{code:`
|
|
178
197
|
import * as React from 'react';
|
|
179
198
|
import * as ReactDOM from 'react-dom';
|
|
180
199
|
import { callServer as rariCallServer } from 'rari/runtime/call-server';
|
|
@@ -182,7 +201,7 @@ import { callServer as rariCallServer } from 'rari/runtime/call-server';
|
|
|
182
201
|
const module = { exports: {} };
|
|
183
202
|
const exports = module.exports;
|
|
184
203
|
(function(module, exports, require) {
|
|
185
|
-
${
|
|
204
|
+
${Ke(Ge(k.readFileSync(e,`utf-8`),k.readFileSync(t,`utf-8`)))}
|
|
186
205
|
})(module, module.exports, function require(id) {
|
|
187
206
|
if (id === 'react') return React;
|
|
188
207
|
if (id === 'react-dom') return ReactDOM;
|
|
@@ -198,4 +217,4 @@ export function createFromReadableStream(stream, options) {
|
|
|
198
217
|
export const createServerReference = module.exports.createServerReference;
|
|
199
218
|
export const encodeReply = module.exports.encodeReply;
|
|
200
219
|
export const createTemporaryReferenceSet = module.exports.createTemporaryReferenceSet;
|
|
201
|
-
`}}if(t.endsWith(`.mjs`)&&k.existsSync(t))try{let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),r=k.realpathSync(t),i=j.relative(n,r),a=!i.startsWith(`..`)&&!j.isAbsolute(i),o=r.includes(`${j.sep}node_modules${j.sep}`),s=r.includes(`${j.sep}packages${j.sep}rari${j.sep}`)||r.includes(`${j.sep}node_modules${j.sep}rari${j.sep}`);return a||o||s?k.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(se(),e.endsWith(`.mdx`)&&m(),!v.test(e))return;if(ee(e),ie(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(
|
|
220
|
+
`}}if(t.endsWith(`.mjs`)&&k.existsSync(t))try{let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.cwd(),r=k.realpathSync(t),i=j.relative(n,r),a=!i.startsWith(`..`)&&!j.isAbsolute(i),o=r.includes(`${j.sep}node_modules${j.sep}`),s=r.includes(`${j.sep}packages${j.sep}rari${j.sep}`)||r.includes(`${j.sep}node_modules${j.sep}rari${j.sep}`);return a||o||s?k.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(se(),e.endsWith(`.mdx`)&&m(),!v.test(e))return;if(ee(e),ie(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(fr)){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 kr(e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:M.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}}},bn({...e.serverBuild,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,action:e.action,jsPoolSize:e.jsPoolSize,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c,mdx:e.mdx})];return e.proxy!==!1&&I.push(me(e.proxy??{})),e.router!==!1&&I.push(We(e.router??{})),fe(I)}function Mr(e){return{...e,plugins:[jr(),...e.plugins??[]]}}export{e as ApiResponse,Wn as clearPropsCache,Gn as clearPropsCacheForComponent,Mr as defineRariConfig,Ar as defineRariOptions,Bn as extractMetadata,zn as extractServerProps,Un as extractServerPropsWithCache,Vn as extractStaticParams,ke as generateAppRouteManifest,Hn as hasServerSideDataFetching,jr as rari,me as rariProxy,We 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.7",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -145,17 +145,17 @@
|
|
|
145
145
|
"rolldown": "^1.2.0"
|
|
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.7",
|
|
149
|
+
"rari-darwin-arm64": "0.15.7",
|
|
150
|
+
"rari-darwin-x64": "0.15.7",
|
|
151
|
+
"rari-linux-arm64": "0.15.7",
|
|
152
|
+
"rari-linux-x64": "0.15.7",
|
|
153
|
+
"rari-win32-arm64": "0.15.7",
|
|
154
|
+
"rari-win32-x64": "0.15.7"
|
|
155
155
|
},
|
|
156
156
|
"devDependencies": {
|
|
157
157
|
"@mdx-js/mdx": "^3.1.1",
|
|
158
|
-
"@types/node": "^26.1.
|
|
158
|
+
"@types/node": "^26.1.2",
|
|
159
159
|
"@types/react": "^19.2.17",
|
|
160
160
|
"@types/react-dom": "^19.2.3",
|
|
161
161
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|