rari 0.15.9 → 0.15.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/og.d.mts +1 -0
- package/dist/og.mjs +1 -1
- package/dist/vite.d.mts +3 -0
- package/dist/vite.mjs +4 -4
- package/package.json +8 -8
package/dist/og.d.mts
CHANGED
package/dist/og.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as e,p as t}from"./type-guards-CTkEL8zw.mjs";const n=Symbol.for(`react.memo`),r=Symbol.for(`react.forward_ref`);function i(e){return t(e)&&typeof e.toString==`function`}function a(e){return t(e)&&`then`in e}function o(e){let t=e;for(;i(t);)if(t.$$typeof===n&&t.type!==void 0)t=t.type;else if(t.$$typeof===r&&t.render!==void 0)t=t.render;else break;return typeof t==`function`||i(t)?t:null}var s=class{element;options;constructor(e,t={}){this.element=e,this.options={width:t.width!=null&&t.width!==0?t.width:1200,height:t.height!=null&&t.height!==0?t.height:630}}toJSON(){return{type:`ImageResponse`,element:this.serializeElement(this.element),options:this.options}}resolveAndInvoke(e,t){let n=o(e);if(n==null||typeof n!=`function`)return null;try{let e=n(t);return e!==null&&a(e)?(console.warn(`[ImageResponse] async/server component "${n.name||n.toString()}" is not supported; skipping`),null):this.serializeElement(e)}catch(e){return console.error(`[ImageResponse] failed to render component "${n.name||n.toString()}":`,e),null}}serializeElement(n){if(typeof n==`string`||typeof n==`number`)return{type:`text`,value:String(n)};if(!t(n)||!e(n))return null;let{type:r,props:a={}}=n,s=o(r);if(typeof s==`function`||s!=null&&i(s))return this.resolveAndInvoke(r,a);let c=this.serializeChildren(a.children);return{type:`element`,elementType:r,props:this.serializeProps(a),children:c}}serializeChildren(e){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>{let t=this.serializeElement(e);return t?[t]:[]});let t=this.serializeElement(e);return t?[t]:[]}serializeProps(e){let t={};for(let[n,r]of Object.entries(e))n
|
|
1
|
+
import{f as e,p as t}from"./type-guards-CTkEL8zw.mjs";const n=Symbol.for(`react.memo`),r=Symbol.for(`react.forward_ref`);function i(e){return t(e)&&typeof e.toString==`function`}function a(e){return t(e)&&`then`in e}function o(e){let t=e;for(;i(t);)if(t.$$typeof===n&&t.type!==void 0)t=t.type;else if(t.$$typeof===r&&t.render!==void 0)t=t.render;else break;return typeof t==`function`||i(t)?t:null}var s=class{element;options;constructor(e,t={}){this.element=e,this.options={width:t.width!=null&&t.width!==0?t.width:1200,height:t.height!=null&&t.height!==0?t.height:630}}toJSON(){return{type:`ImageResponse`,element:this.serializeElement(this.element),options:this.options}}resolveAndInvoke(e,t){let n=o(e);if(n==null||typeof n!=`function`)return null;try{let e=n(t);return e!==null&&a(e)?(console.warn(`[ImageResponse] async/server component "${n.name||n.toString()}" is not supported; skipping`),null):this.serializeElement(e)}catch(e){return console.error(`[ImageResponse] failed to render component "${n.name||n.toString()}":`,e),null}}serializeElement(n){if(typeof n==`string`||typeof n==`number`)return{type:`text`,value:String(n)};if(!t(n)||!e(n))return null;let{type:r,props:a={}}=n,s=o(r);if(typeof s==`function`||s!=null&&i(s))return this.resolveAndInvoke(r,a);let c=this.serializeChildren(a.children);return{type:`element`,elementType:r,props:this.serializeProps(a),children:c}}serializeChildren(e){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>{let t=this.serializeElement(e);return t?[t]:[]});let t=this.serializeElement(e);return t?[t]:[]}serializeProps(e){let t={};for(let[n,r]of Object.entries(e)){if(n===`children`)continue;let e=this.serializePropValue(r);e!==void 0&&(t[n]=e)}return t}serializePropValue(e,n=new Set){if(e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(n.has(e))return;n.add(e);try{return e.map(e=>this.serializePropValue(e,n)).filter(e=>e!==void 0)}finally{n.delete(e)}}if(t(e)){if(n.has(e))return;n.add(e);try{let t={};for(let[r,i]of Object.entries(e)){let e=this.serializePropValue(i,n);e!==void 0&&(t[r]=e)}return t}finally{n.delete(e)}}}};export{s as ImageResponse};
|
package/dist/vite.d.mts
CHANGED
|
@@ -86,6 +86,7 @@ interface ServerConfig {
|
|
|
86
86
|
useCache?: ServerUseCacheConfig;
|
|
87
87
|
action?: ServerActionConfig;
|
|
88
88
|
jsPoolSize?: number;
|
|
89
|
+
origin?: string;
|
|
89
90
|
htmlLimitedBots?: string;
|
|
90
91
|
}
|
|
91
92
|
//#endregion
|
|
@@ -103,6 +104,7 @@ interface ServerBuildOptions {
|
|
|
103
104
|
readonly cache?: ServerCacheConfig;
|
|
104
105
|
readonly action?: ServerActionConfig;
|
|
105
106
|
readonly jsPoolSize?: number;
|
|
107
|
+
readonly origin?: string;
|
|
106
108
|
readonly htmlLimitedBots?: string;
|
|
107
109
|
readonly moduleAnalysisCache?: ModuleAnalysisCache;
|
|
108
110
|
readonly experimental?: {
|
|
@@ -292,6 +294,7 @@ interface RariOptions {
|
|
|
292
294
|
readonly allowedOrigins?: readonly string[];
|
|
293
295
|
};
|
|
294
296
|
readonly jsPoolSize?: number;
|
|
297
|
+
readonly origin?: string;
|
|
295
298
|
readonly htmlLimitedBots?: string;
|
|
296
299
|
readonly cache?: ServerCacheConfig;
|
|
297
300
|
readonly experimental?: {
|
package/dist/vite.mjs
CHANGED
|
@@ -95,8 +95,8 @@ const ${e} = globalThis['~clientComponents']?.[${JSON.stringify(t)}]?.component
|
|
|
95
95
|
|| globalThis[${JSON.stringify(t)}]
|
|
96
96
|
|| {};`}const _n=/import\s*\(\s*["']([^"']+)["']\s*\)|import\s+["']([^"']+)["']/g,vn=/<script\b[^>]*>/gi;function yn(e,t,n){n?.startsWith(`/src/`)&&e.add(J(k.join(t,n.slice(1))))}function bn(e){return/\btype\s*=\s*["']module["']/i.test(e)?/\bsrc\s*=\s*["']([^"']+)["']/i.exec(e)?.[1]??null:null}function xn(e){let t=new Set,n=k.join(e,`index.html`);if(!D.existsSync(n))return t;try{let r=D.readFileSync(n,`utf-8`);for(let n of r.matchAll(_n))yn(t,e,n[1]||n[2]);for(let n of r.matchAll(vn))yn(t,e,bn(n[0]))}catch{}return t}const Sn=/(?:^|[\n\r;])\s*import\s*\{[^}]*\bregisterServerReference\b[^}]*\}\s*from\s*["'][^"'\n]+["']/;function Cn(e){return Sn.test(e)}const wn=new Set(`undefined.NaN.Infinity.arguments.Object.Array.String.Number.Boolean.Symbol.BigInt.Math.Date.JSON.Promise.Error.TypeError.RangeError.Map.Set.WeakMap.WeakSet.RegExp.Proxy.Reflect.Function.console.fetch.process.Buffer.globalThis.global.window.document.navigator.location.crypto.TextEncoder.TextDecoder.URL.URLSearchParams.FormData.Headers.Request.Response.AbortController.AbortSignal.setTimeout.clearTimeout.setInterval.clearInterval.queueMicrotask.structuredClone.atob.btoa.React.jsx.jsxs.Fragment`.split(`.`)),Tn=new Set(`await.return.throw.if.else.for.while.do.switch.case.break.continue.new.typeof.instanceof.void.delete.yield.class.extends.super.this.try.catch.finally.with.debugger.default.of.in.from.as.import.export.async.function.const.let.var.true.false.null.static.get.set.typeof`.split(`.`));function En(e){return e>=97&&e<=122||e>=65&&e<=90||e===95||e===36}function Dn(e){return En(e)||e>=48&&e<=57}function Y(e,t){let n=e.length;for(;t<n;){let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===65279){t++;continue}if(r===47&&e.charCodeAt(t+1)===47){for(t+=2;t<n&&e.charCodeAt(t)!==10&&e.charCodeAt(t)!==13;)t++;continue}if(r===47&&e.charCodeAt(t+1)===42){for(t+=2;t<n-1&&(e.charCodeAt(t)!==42||e.charCodeAt(t+1)!==47);)t++;t+=2;continue}break}return t}function On(e,t,n){t++;let r=e.length;for(;t<r;){let r=e.charCodeAt(t);if(r===92){t+=2;continue}if(r===n)return t+1;t++}return t}function X(e,t,n,r){let i=t,a=0,o=e.length;for(;i<o;){let t=q(e,i,o);if(t!==-1){i=t;continue}let s=e.charCodeAt(i);if(s===n)a++;else if(s===r&&(a--,a===0))return i+1;i++}return i}function kn(e,t,n){for(let r=0;r<n.length;r++)if(e.charCodeAt(t+r)!==n.charCodeAt(r))return!1;return!0}function An(e,t,n){let r=Y(e,t+1);if(r>=n)return!1;let i=e.charCodeAt(r);if(i!==39&&i!==34)return!1;let a=r+1,o=On(e,r,i);if(o-1-a!=10||!kn(e,a,`use server`))return!1;for(r=o;r<n;){let t=e.charCodeAt(r);if(t===32||t===9){r++;continue}return t===59||t===10||t===13||t===47&&e.charCodeAt(r+1)===47||t===47&&e.charCodeAt(r+1)===42}return!0}function jn(e,t,n){let r=Y(e,t+1),i=e.charCodeAt(r);return i!==39&&i!==34?e.slice(t+1,n):(r=Y(e,On(e,r,i)),e.charCodeAt(r)===59&&r++,r=Y(e,r),e.slice(r,n))}function Mn(e,t){if(!En(e.charCodeAt(t)))return null;let n=t+1;for(;n<e.length&&Dn(e.charCodeAt(n));)n++;return{name:e.slice(t,n),end:n}}function Nn(e,t,n){if(!kn(e,t,n))return!1;let r=t>0?e.charCodeAt(t-1):-1,i=t+n.length<e.length?e.charCodeAt(t+n.length):-1;return!(r!==-1&&Dn(r)||i!==-1&&Dn(i))}function Pn(e){let t=new Set,n=0,r=e.length;for(;n<r&&(n=Y(e,n),!(n>=r));){let r=e.charCodeAt(n);if(r===123||r===91){let i=X(e,n,r,r===123?125:93);for(let r of e.slice(n,i).matchAll(/[a-z_$][\w$]*/gi))r[0]!==`as`&&t.add(r[0]);n=i;continue}if(r===46&&e.charCodeAt(n+1)===46&&e.charCodeAt(n+2)===46){n+=3,n=Y(e,n);let r=Mn(e,n);r&&(t.add(r.name),n=r.end);continue}let i=Mn(e,n);if(i){t.add(i.name),n=i.end;continue}n++}return t}function Fn(e){let t=new Set;for(let n of e.matchAll(/\b(?:const|let|var|function|class|async\s+function)\s+([A-Za-z_$][\w$]*)/g))t.add(n[1]);return t}function In(e){let t=new Set;for(let n of e.matchAll(/\b(?:import|export)\s+(?:type\s+)?(?:\{([^}]+)\}|(\*\s+as\s+[A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*))/g)){if(n[1])for(let e of n[1].split(`,`)){let n=e.trim();if(!n||n.startsWith(`type `))continue;let r=(n.split(/\s+as\s+/).at(-1)??``).trim();r&&t.add(r)}if(n[2]){let e=/as\s+([A-Za-z_$][\w$]*)/.exec(n[2]);e&&t.add(e[1])}n[3]&&n[3]!==`type`&&n[3]!==`async`&&n[3]!==`function`&&n[3]!==`class`&&t.add(n[3])}for(let n of e.matchAll(/(?:^|\n)\s*(?:export\s+)?(?:async\s+)?(?:function|class|const|let|var)\s+([A-Za-z_$][\w$]*)/g))t.add(n[1]);return t}function Ln(e,t,n){let r=new Set([...Pn(t),...Fn(e),...n,...wn,...Tn]),i=new Set,a=0,o=e.length;for(;a<o;){let t=q(e,a,o);if(t!==-1){a=t;continue}if(!En(e.charCodeAt(a))){a++;continue}let n=Mn(e,a);if(n==null){a++;continue}if(a>0&&e.charCodeAt(a-1)===46){a=n.end;continue}if(Rn(e,a,n.end)){a=n.end;continue}r.has(n.name)||i.add(n.name),a=n.end}return[...i]}function Z(e,t){for(;t>0;){let n=e.charCodeAt(t-1);if(n===32||n===9||n===10||n===13||n===65279)t--;else break}return t}function Q(e,t,n){let r=t-n.length;return r<0||!Nn(e,r,n)?null:r}function Rn(e,t,n){let r=Y(e,n);if(e.charCodeAt(r)!==58)return!1;let i=Z(e,t);if(i===0)return!1;let a=e.charCodeAt(i-1);return a===123||a===44}function zn(e,t){let n=Z(e,t),r=Q(e,n,`default`);if(r!=null){n=Z(e,r);let t=Q(e,n,`export`);if(t!=null)return{start:t,exportKind:`default`,bindingName:null}}if(n>0&&e.charCodeAt(n-1)===61){let r=Z(e,n-1),i=r;for(;i>0&&Dn(e.charCodeAt(i-1));)i--;if(i<r&&En(e.charCodeAt(i))){let n=e.slice(i,r),a=Z(e,i),o=Q(e,a,`const`)??Q(e,a,`let`)??Q(e,a,`var`);if(o!=null)return Q(e,Z(e,o),`export`)==null?{start:t,exportKind:null,bindingName:n}:{start:t,exportKind:`named`,bindingName:n}}}let i=Q(e,n,`export`);return i==null?{start:t,exportKind:null,bindingName:null}:{start:i,exportKind:`named`,bindingName:null}}function Bn(e){let t=[],n=e.length,r=0;for(;r<n;){let n=e.charCodeAt(r);if(n===39||n===34||n===96){r=On(e,r,n);continue}if(n===47&&(e.charCodeAt(r+1)===47||e.charCodeAt(r+1)===42)){r=Y(e,r);continue}if(Nn(e,r,`async`)||Nn(e,r,`function`)){let n=r,i=r,a=!1;if(Nn(e,i,`async`)&&(a=!0,i=Y(e,i+5)),Nn(e,i,`function`)){i=Y(e,i+8),e.charCodeAt(i)===42&&(i=Y(e,i+1));let o=null,s=Mn(e,i);if(s&&(o=s.name,i=Y(e,s.end)),e.charCodeAt(i)!==40){r++;continue}let c=X(e,i,40,41),l=e.slice(i+1,c-1);if(i=Y(e,c),e.charCodeAt(i)!==123){r++;continue}let u=X(e,i,123,125)-1;An(e,i,u)?(t.push({start:n,end:u+1,bodyOpen:i,bodyClose:u,paramsRaw:l,isAsync:a,name:o,kind:o==null?`expression`:`declaration`}),r=u+1):r=i+1;continue}if(a&&e.charCodeAt(i)===40){let a=X(e,i,40,41),o=e.slice(i+1,a-1),s=Y(e,a);if(e.charCodeAt(s)===61&&e.charCodeAt(s+1)===62&&(s=Y(e,s+2),e.charCodeAt(s)===123)){let i=X(e,s,123,125)-1;An(e,s,i)?(t.push({start:n,end:i+1,bodyOpen:s,bodyClose:i,paramsRaw:o,isAsync:!0,name:null,kind:`arrow`}),r=i+1):r=s+1;continue}}}if(e.charCodeAt(r)===40){let n=X(e,r,40,41),i=Y(e,n);if(e.charCodeAt(i)===61&&e.charCodeAt(i+1)===62&&(i=Y(e,i+2),e.charCodeAt(i)===123)){let a=X(e,i,123,125)-1;An(e,i,a)?(t.push({start:r,end:a+1,bodyOpen:i,bodyClose:a,paramsRaw:e.slice(r+1,n-1),isAsync:!1,name:null,kind:`arrow`}),r=a+1):r=i+1;continue}}r++}return t}function Vn(e,t){let n=Bn(e);if(n.length===0)return null;let r=In(e),i=[],a=[],o=e,s=[],c=!1,l=[...n].sort((e,t)=>t.start-e.start),u=n.length-1;for(let e of l){let n=e.name??`anonymous_server_function`,l=`$$ACTION_${u}_${n.replace(/\W/g,`_`)}`;u--,i.unshift(l);let d=jn(o,e.bodyOpen,e.bodyClose),f=Ln(d,e.paramsRaw,r),p=[...f,e.paramsRaw.trim()].filter(e=>e!==``).join(`, `),m=e.isAsync?`async `:``,h=f.length>0?`${l}.bind(null, ${f.join(`, `)})`:l,{start:g,exportKind:_,bindingName:v}=zn(o,e.start),y=h,b=null;_==="default"?(b=`default`,y=`export default registerServerReference(${h}, ${JSON.stringify(t)}, "default")`):_===`named`&&e.name!=null?(b=e.name,y=`export const ${e.name} = registerServerReference(${h}, ${JSON.stringify(t)}, ${JSON.stringify(e.name)})`):_===`named`&&v!=null?(b=v,y=`registerServerReference(${h}, ${JSON.stringify(t)}, ${JSON.stringify(v)})`):e.kind===`declaration`&&e.name!=null&&(y=`const ${e.name} = ${h}`),b==null?s.unshift(`${m}function ${l}(${p}) {\n${d}\n}`,`registerServerReference(${l}, ${JSON.stringify(t)}, ${JSON.stringify(l)});`):(s.unshift(`${m}function ${l}(${p}) {\n${d}\n}`),a.unshift(b)),c=!0,o=o.slice(0,g)+y+o.slice(e.end)}let d=c?`import { registerServerReference } from ${JSON.stringify(`react-server-dom-rari/server`)};\n`:``;return{code:`${c&&!Cn(o)?d:``}${o}\n\n${s.join(`
|
|
97
97
|
`)}\n`,actionNames:i,rewrittenExportNames:a}}let Hn;async function Un(){if(Hn!==void 0)return Hn;try{let e=(await import(`@rari/use-cache`)).transformUseCacheModule;return Hn=typeof e==`function`?e:null,Hn}catch{return Hn=null,null}}const Wn=/^proxy\.(?:tsx?|jsx?|mts|mjs)$/,Gn=/\/components\/(\w+)(?:\.tsx?|\.jsx?)?$/,Kn=/[/\\]components[/\\]\w+(?:\.tsx?|\.jsx?)?$/,qn=/^(?:robots|sitemap|feed)\.(?:tsx?|jsx?)$/,Jn=/^[./@~#]/,Yn=/^node:/,Xn=`[hash]_[local]`;function Zn(e){if(e.startsWith(`@`)){let t=e.split(`/`);return t.length>=2?`${t[0]}/${t[1]}`:e}return e.split(`/`)[0]??e}function Qn(e,t){let n=Zn(t),r=e;for(;;){let e=k.join(r,`node_modules`,...n.split(`/`));if(D.existsSync(k.join(e,`package.json`)))return!0;let t=k.dirname(r);if(t===r)return!1;r=t}}const $n=[{componentId:`rari/image`,devSourceSegments:[`src`,`image`,`image.tsx`],publishedExport:`rari/image`,exports:[`Image`]}],er=k.dirname(j(import.meta.url)),$=k.dirname(er);function tr(e){return e.startsWith($)}function nr(e,t){return tr(e)?k.join($,`src`):k.join(t,`src`)}function rr(){let e=k.join($,`src`,`runtime`,`boundaries`,`error-boundary-wrapper.tsx`);if(D.existsSync(e))return e;try{let e=j(import.meta.resolve(`rari/runtime/ErrorBoundaryWrapper`));if(D.existsSync(e))return e}catch{}return null}function ir(e){let t=e.replace(x,`/`);return t.includes(`ErrorBoundaryWrapper`)||t.includes(`/boundaries/error-boundary-wrapper`)||t.endsWith(`/error-boundary-wrapper.tsx`)}function ar(e,t){if(ir(e))return`virtual:error-boundary-wrapper.tsx`;let n=k.relative(t,e).replace(x,`/`);return n.startsWith(`..`)||k.isAbsolute(n)?e.replace(x,`/`):n}function or(e,t){if(ir(e))return`error_boundary_wrapper_${L(`virtual:error-boundary-wrapper.tsx`)}`;if(tr(e)){let t=k.relative($,e).replace(x,`/`);return`${$e(t)}_${L(t)}`}return et(e,t)}let sr=null;async function cr(){return sr||=(await import(`lightningcss`)).transform,sr}function lr(e){return a(e)&&a(e.components)}function ur(e,t,n,r){return e.includes(`node_modules`)||n.has(r??J(e))?!1:!t.directives.hasUseClient&&!t.directives.hasUseServer}var dr=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=k.join(this.options.outDir,`assets`,`server`);await D.promises.mkdir(n,{recursive:!0});let r=`${t.join(`
|
|
98
|
-
`)}\n`,i=`${L(e+r,12)}.css`,a=k.join(n,i);return await D.promises.writeFile(a,r,`utf-8`),[`/assets/server/${i}`]}getComponentIdFromRouteManifestPath(e){return this.getComponentId(k.join(this.projectRoot,`src`,`app`,e))}getComponentReferenceId(e){return this.getReadableComponentId(this.getProjectRelativePath(e))}async writeRouteCssEntries(e){let t=k.join(this.options.outDir,this.options.rscDir,`routes.json`);if(!D.existsSync(t))return;let n=await D.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 D.promises.writeFile(t,JSON.stringify(i),`utf-8`)}constructor(e,t={}){this.projectRoot=e,this.moduleAnalysisCache=t.moduleAnalysisCache??new Gt;let n=t.rscDir!=null&&t.rscDir!==``?t.rscDir:`server`;this.options={outDir:t.outDir!=null&&t.outDir!==``?t.outDir:k.join(e,`dist`),rscDir:n,manifestPath:t.manifestPath!=null&&t.manifestPath!==``?t.manifestPath:k.join(n,`manifest.json`),serverConfigPath:t.serverConfigPath!=null&&t.serverConfigPath!==``?t.serverConfigPath:k.join(n,`config.json`),minify:t.minify??A.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 xn(this.projectRoot))this.htmlOnlyImports.add(e)}getModuleAnalysis(e,t){return this.moduleAnalysisCache.get(e,t)}isServerComponent(e,t){try{return ur(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=k.dirname(e);n=k.resolve(r,t)}else if(n=C(t,this.options.alias,this.projectRoot),(n==null||n===``)&&t.startsWith(`@/`)){let e=t.slice(2);n=k.join(this.projectRoot,`src`,e)}return n==null||n===``?null:S(n,[``,`.ts`,`.tsx`,`.js`,`.jsx`])}populateImportGraphFromFiles(e){this.fileImporters.clear();for(let{filePath:t,analysis:n}of e)for(let e of Ht(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=fr(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??D.readFileSync(e,`utf-8`),i=n??this.moduleAnalysisCache.get(e,r),a=Vt(i.importSources),o=Bt(i);if(i.directives.hasUseServer){this.serverActions.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o});return}ur(e,i,this.htmlOnlyImports)&&this.serverComponents.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o})}isServerAction(e,t){return t!=null&&t!==``?this.moduleAnalysisCache.get(t,e).directives.hasUseServer:G(e).directives.hasUseServer}extractDependencies(e,t){return Vt((t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e)).importSources)}hasNodeImports(e,t){return Bt(t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e))}async getTransformedComponentsForDevelopment(e){let t=[];for(let[n]of this.serverComponents){if(e&&!e(n))continue;let r=k.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!1})}for(let[n]of this.serverActions){if(e&&!e(n))continue;let r=k.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!0})}return t}resolveComponentsDirClientImport(e){if(!e.startsWith(`.`)&&!e.startsWith(`@`)&&!e.startsWith(`~`)&&!e.startsWith(`#`))return null;if(e.startsWith(`.`)){if(!e.includes(`/components/`))return null;let t=Gn.exec(e);if(!t)return null;let n=t[1],r=[k.resolve(this.projectRoot,`src`,`components`,`${n}.tsx`),k.resolve(this.projectRoot,`src`,`components`,`${n}.ts`),k.resolve(this.projectRoot,`src`,`components`,`${n}.jsx`),k.resolve(this.projectRoot,`src`,`components`,`${n}.js`)];for(let e of r)if(D.existsSync(e)&&this.isClientComponent(e))return{registryKey:`components/${n}`,absolutePath:e};return null}let t=null;for(let[n,r]of Object.entries(this.options.alias))if(e.startsWith(`${n}/`)||e===n){let i=e.slice(n.length).replace(/^\/+/,``);t=k.join(r,i);break}if(t==null||t===``||!Kn.exec(t))return null;let n=k.isAbsolute(t)?t:k.resolve(this.projectRoot,t),r=[n,`${n}.tsx`,`${n}.ts`,`${n}.jsx`,`${n}.js`];for(let e of r)if(D.existsSync(e)&&this.isClientComponent(e))return{registryKey:this.getComponentReferenceId(e),absolutePath:e};return null}transformComponentImportsToGlobal(e){let t=[];for(let n of gt(e)){if(n.typeOnly||n.sideEffectOnly)continue;let e=this.resolveComponentsDirClientImport(n.source);if(e==null)continue;let r=[];n.namespaceBinding!=null&&r.push(gn(n.namespaceBinding,e.registryKey)),n.defaultBinding!=null&&r.push(hn(n.defaultBinding,e.registryKey,`default`));for(let t of n.named)t.typeOnly||r.push(hn(t.local,e.registryKey,t.imported));r.length!==0&&t.push({start:n.start,end:n.end,replacement:r.join(`
|
|
99
|
-
`)})}if(t.length===0)return e;let n=e;for(let{start:e,end:r,replacement:i}of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e)+i+n.slice(r);return n}isPageComponent(e){return e.includes(`/app/`)||e.includes(`\\app\\`)}createRolldownModuleInfoPlugin(e){let t=new Set;return{name:`rari-rolldown-module-info`,moduleParsed(e){for(let n of e.importedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n)},buildEnd:()=>{if(t.size===0)return;let n=[...t].sort(),r=this.serverComponents.get(e)??this.serverActions.get(e);r&&(r.dependencies=n);let i=this.buildCache.get(e);i&&(i.bundledDependencies=n)}}}createBuildPlugins(e,t,n,r,i=!1,a){let o=k.dirname(r),s=Wn.test(k.basename(r)),c=new Map,l=new Map;return[{name:`virtual-module`,resolveId(t,n){if(t===e)return t;if(n===e&&(t.startsWith(`./`)||t.startsWith(`../`))){if(t.endsWith(`.module.css`))return null;let e=k.resolve(o,t);for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`,``]){let n=e+t;if(D.existsSync(n)&&D.statSync(n).isFile())return n}for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(e,`index${t}`);if(D.existsSync(n))return n}return e}return null},load(r){return r===e?{code:t,moduleType:n}:null}},{name:`resolve-client-server-boundaries`,enforce:`pre`,resolveId:(t,n)=>{if(n==null||n===``||n.includes(`node_modules`)||tr(n)||t.startsWith(`node:`)||zt(t)||t===`react`||t===`react-dom`||t===`react/jsx-runtime`||t===`react/jsx-dev-runtime`)return null;let r=null,i=this.options.alias;if(r=C(t,i,this.projectRoot),(r==null||r===``)&&(t.startsWith(`./`)||t.startsWith(`../`))){let i=n===e?o:k.dirname(n);r=k.resolve(i,t)}if((r==null||r===``)&&k.isAbsolute(t)&&(r=t),r!==``)for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=r+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)){let e=k.relative(this.projectRoot,t),n=(e.startsWith(`..`)?t:e).replace(x,`/`);return c.set(t,n),e.startsWith(`..`)&&this.discoveredExternalClientComponents.add(t),{id:`\0client-ref:${t}`}}try{let e=this.moduleAnalysisCache.get(t);if(e.directives.hasUseServer){let n=this.getComponentId(t);return l.set(t,{actionId:n,hasDefaultExport:e.hasDefaultExport}),{id:`\0server-action:${t}`}}}catch(e){console.error(`[rari] Failed to read file for server action detection: ${t}`,e)}break}}return null},load:e=>{if(e.startsWith(`\0client-ref:`)){let t=e.slice(12),n=k.relative(this.projectRoot,t),r=(c.get(t)??(n.startsWith(`..`)?t:n)).replace(x,`/`);return{code:this.generateClientReferenceStub(t,r),moduleType:`js`}}if(e.startsWith(`\0server-action:`)){let t=e.slice(15),n=l.get(t)?.actionId??this.getComponentId(t);return{code:this.generateServerActionRuntimeModule(t,n),moduleType:`js`}}return null}},{name:`use-transformed-server-components`,resolveId:(e,t)=>{if(!i)return null;if(e.startsWith(`file://`)){let t=e.replace(h,``);return D.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=C(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?k.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=k.resolve(a,e)),n==null||n===``||a.includes(`node_modules`))return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=n+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=k.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=k.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(D.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:D.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=C(e,this.options.alias,this.projectRoot);if(t==null||t===``)return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let n=t+e;if(D.existsSync(n)&&D.statSync(n).isFile()){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}for(let e of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(t,`index${e}`);if(D.existsSync(n)){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}return t}},{name:`resolve-rari-proxy`,resolveId:e=>{if(s&&e===`rari`){let e=k.join(er,`proxy/RariResponse.mjs`);if(D.existsSync(e))return e;let t=k.join($,`src/proxy/http/response.ts`);if(D.existsSync(t))return t}return null}},{name:`css-modules`,resolveId:(e,t)=>{if(e.endsWith(`.module.css`)){let n=t!=null&&t!==``&&!t.startsWith(`\0`)?k.dirname(t):o,r=k.resolve(n,e);if(D.existsSync(r))return{id:`\0css-module:${r}`}}return null},load:async e=>{if(!e.startsWith(`\0css-module:`))return null;let t=e.slice(12);try{let e=await cr(),n=D.readFileSync(t),r=e({filename:k.relative(this.projectRoot,t),code:n,cssModules:{pattern:Xn}});a&&a.push(new TextDecoder().decode(r.code));let i={};if(r.exports)for(let[e,t]of Object.entries(r.exports))i[e]=t.name;return{code:`export default ${JSON.stringify(i)}`,moduleType:`js`}}catch(t){throw Error(`[rari] Failed to process CSS module ${e}: ${t instanceof Error?t.message:String(t)}`)}}},{name:`externalize-deps`,resolveId:(e,t)=>{if(e.startsWith(`\0`))return null;if(e.startsWith(`node:`)||zt(e)||[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`rari/image`].includes(e)||e in{"rari/runtime/cache-wrapper":`node_modules/rari/dist/runtime/cache-wrapper.mjs`,"react-server-dom-rari/server":`node_modules/rari/dist/runtime/rsc-references.mjs`})return{id:e,external:!0};if(e===`rari`||C(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(Qn(this.projectRoot,e))return{id:e,external:!0};let n=[t!=null&&t!==``&&!t.startsWith(`\0`)?t:null,r].filter(e=>!!e);for(let t of n)try{return{id:de(t).resolve(e)}}catch{try{let n=import.meta.resolve(e,M(t).href);return{id:j(n)}}catch{}}return null}return null}},this.createRolldownModuleInfoPlugin(r),{name:`use-cache`,transform:async(e,t)=>{if(!this.options.experimental?.useCache&&!this.options.experimental?.useCacheRemote)return null;let n=await Un();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await D.promises.readFile(e,`utf-8`),n=Vn(t,this.getComponentId(e))?.code??t,r=this.transformClientImports(n,e),i=this.isPageComponent(e),a=i?this.transformComponentImportsToGlobal(r):r,o=k.extname(e),s;s=o===`.tsx`?`tsx`:o===`.ts`?`ts`:o===`.jsx`?`jsx`:`js`;let c=`\0virtual:${e}`,l=await N({input:c,platform:`node`,write:!1,external:[Yn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${s}`]:s},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(A.env.NODE_ENV!=null&&A.env.NODE_ENV!==``?A.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(c,a,s,e,i,[])});if(l.output.length===0)throw Error(`No output generated from Rolldown`);let u=l.output.find(e=>e.type===`chunk`&&e.isEntry);if(u?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let d=u.code;return d=`// Built: ${new Date().toISOString()}\n${d}`,d}async buildComponentBatch(e,t,n){let r=0,i=0,a=[];if(await new Promise(o=>{let s=()=>{for(;r<n&&i<e.length;){let[n,c]=e[i++],l=k.relative(this.projectRoot,n),u=this.getComponentId(n),d=k.join(this.options.rscDir,`${u}.js`),f=k.join(this.options.outDir,d);r++,(async()=>{try{let e=k.dirname(f);await D.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=M(k.resolve(this.projectRoot,f)).href;t.components[u]={id:u,filePath:n,relativePath:l,bundlePath:d,moduleSpecifier:a,dependencies:[...c.dependencies],hasNodeImports:c.hasNodeImports,css:i}}catch(e){a.push(e instanceof Error?e:Error(String(e)))}finally{r--,i>=e.length&&r===0?o():s()}})()}e.length===0&&o()};s()}),a.length>0)throw a[0]}async buildServerComponents(){let e=k.join(this.options.outDir,this.options.rscDir);await D.promises.mkdir(e,{recursive:!0});let t={components:{},buildTime:new Date().toISOString()},n=this.options.experimental?.useCache===!0||this.options.experimental?.useCacheRemote!=null,r=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),i=[...this.serverComponents.entries()].filter(([e])=>!this.isPageComponent(e)),a=[...this.serverComponents.entries()].filter(([e])=>this.isPageComponent(e)),s=[...this.serverActions.entries()];await Promise.all([this.buildComponentBatch(i,t,r),this.buildComponentBatch(s,t,r)]),await this.buildComponentBatch(a,t,r),n&&(this.useCacheBuildId=L(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=k.join(this.options.outDir,this.options.manifestPath);await D.promises.writeFile(c,JSON.stringify(t),`utf-8`),await this.writeRouteCssEntries(t);let l={};this.options.csp&&(l.csp=this.options.csp),this.options.cacheControl&&(l.cacheControl=this.options.cacheControl),this.options.cache&&(l.cache=this.options.cache),this.options.action&&(l.action=this.options.action),this.options.jsPoolSize!=null&&(l.jsPoolSize=this.options.jsPoolSize),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=k.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await D.promises.unlink(u)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await D.promises.writeFile(u,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=on({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=k.join(this.options.outDir,this.options.manifestPath),i;if(D.existsSync(r)){let e=await D.promises.readFile(r,`utf-8`),n=t(e);i=n&&lr(n)?n:{components:{},buildTime:new Date().toISOString()}}else i={components:{},buildTime:new Date().toISOString()};i.mdxRegistry=n.map(e=>({name:e.name,id:e.moduleId,client:e.client})),await D.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=k.join(this.options.outDir,`ssr`);await D.promises.mkdir(e,{recursive:!0});let t=[...this.getClientComponentFiles()];for(let e of this.discoveredExternalClientComponents)if(!t.some(t=>t.filePath===e))try{let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=rr();if(e!=null&&e!==``){let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}}catch{}if(t.length===0){let t={};await this.buildExternalClientComponents(t,new Map),await this.writeClientReferenceManifest(e,t);return}let n=new Map;for(let{filePath:e}of t){let t=or(e,this.projectRoot);n.set(k.resolve(e),`file:///ssr/${t}.js`)}let r={},i=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),a=0,o=0;await new Promise(e=>{let s=()=>{for(;a<i&&o<t.length;){let{filePath:i,code:c}=t[o++],l=ar(i,this.projectRoot),u=`ssr/${or(i,this.projectRoot)}.js`,d=k.join(this.options.outDir,u);a++,(async()=>{try{let e=k.dirname(d);await D.promises.mkdir(e,{recursive:!0}),await this.buildSSRSingleClient(i,d,n);let t=this.extractExportNames(c);r[l]={id:l,filePath:i,bundlePath:u,exports:t}}catch(e){console.warn(`[rari] SSR build failed for ${l}:`,e instanceof Error?e.message:e)}finally{a--,o>=t.length&&a===0?e():s()}})()}t.length===0&&e()};s()}),await this.buildExternalClientComponents(r,n),await this.writeClientReferenceManifest(e,r)}async writeClientReferenceManifest(e,t){let n=k.join(e,`manifest.json`);await D.promises.writeFile(n,JSON.stringify(t),`utf-8`);let r={};for(let[e,n]of Object.entries(t))for(let t of n.exports){let i=`${e}#${t}`;r[i]={id:i,chunks:`/${n.bundlePath}`,name:t}}let i=k.join(this.options.outDir,`server`);await D.promises.mkdir(i,{recursive:!0});let a=k.join(i,`client-reference-manifest.json`);await D.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=k.join($,...e);if(D.existsSync(n))return n;try{let e=j(import.meta.resolve(t));if(D.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of $n){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${L(n)}`}.js`,i=k.join(this.options.outDir,r);await D.promises.mkdir(k.dirname(i),{recursive:!0}),await this.buildSSRSingleClient(o,i,t),e[n]={id:n,filePath:o,bundlePath:r,exports:[...a]}}catch(e){console.warn(`[rari] SSR build failed for ${n}:`,e instanceof Error?e.message:e)}}}extractExportNames(e){return _t(e)}generateClientReferenceStub(e,t){let n=[`default`];try{n=_t(D.readFileSync(e,`utf-8`))}catch{}return mn(t,n)}isServerActionFile(e){try{let t=D.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=D.readFileSync(e,`utf-8`),r=this.extractExportNames(n),i=[`const __rariActionMod = globalThis.__rari_rsc_require__(${JSON.stringify(t)});`,`if (!__rariActionMod) throw new Error("Server action module ${t} is not registered");`];for(let e of r)e==="default"?i.push(`export default __rariActionMod.default;`):i.push(`export const ${e} = __rariActionMod.${e};`);return`${i.join(`
|
|
98
|
+
`)}\n`,i=`${L(e+r,12)}.css`,a=k.join(n,i);return await D.promises.writeFile(a,r,`utf-8`),[`/assets/server/${i}`]}getComponentIdFromRouteManifestPath(e){return this.getComponentId(k.join(this.projectRoot,`src`,`app`,e))}getComponentReferenceId(e){return this.getReadableComponentId(this.getProjectRelativePath(e))}async writeRouteCssEntries(e){let t=k.join(this.options.outDir,this.options.rscDir,`routes.json`);if(!D.existsSync(t))return;let n=await D.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 D.promises.writeFile(t,JSON.stringify(i),`utf-8`)}constructor(e,t={}){this.projectRoot=e,this.moduleAnalysisCache=t.moduleAnalysisCache??new Gt;let n=t.rscDir!=null&&t.rscDir!==``?t.rscDir:`server`;this.options={outDir:t.outDir!=null&&t.outDir!==``?t.outDir:k.join(e,`dist`),rscDir:n,manifestPath:t.manifestPath!=null&&t.manifestPath!==``?t.manifestPath:k.join(n,`manifest.json`),serverConfigPath:t.serverConfigPath!=null&&t.serverConfigPath!==``?t.serverConfigPath:k.join(n,`config.json`),minify:t.minify??A.env.NODE_ENV===`production`,alias:t.alias??{},define:t.define,csp:t.csp,cacheControl:t.cacheControl,cache:t.cache,action:t.action,jsPoolSize:t.jsPoolSize,origin:t.origin,htmlLimitedBots:t.htmlLimitedBots,experimental:t.experimental,mdx:t.mdx},this.parseHtmlImports()}parseHtmlImports(){for(let e of xn(this.projectRoot))this.htmlOnlyImports.add(e)}getModuleAnalysis(e,t){return this.moduleAnalysisCache.get(e,t)}isServerComponent(e,t){try{return ur(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=k.dirname(e);n=k.resolve(r,t)}else if(n=C(t,this.options.alias,this.projectRoot),(n==null||n===``)&&t.startsWith(`@/`)){let e=t.slice(2);n=k.join(this.projectRoot,`src`,e)}return n==null||n===``?null:S(n,[``,`.ts`,`.tsx`,`.js`,`.jsx`])}populateImportGraphFromFiles(e){this.fileImporters.clear();for(let{filePath:t,analysis:n}of e)for(let e of Ht(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=fr(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??D.readFileSync(e,`utf-8`),i=n??this.moduleAnalysisCache.get(e,r),a=Vt(i.importSources),o=Bt(i);if(i.directives.hasUseServer){this.serverActions.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o});return}ur(e,i,this.htmlOnlyImports)&&this.serverComponents.set(e,{filePath:e,originalCode:r,dependencies:a,hasNodeImports:o})}isServerAction(e,t){return t!=null&&t!==``?this.moduleAnalysisCache.get(t,e).directives.hasUseServer:G(e).directives.hasUseServer}extractDependencies(e,t){return Vt((t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e)).importSources)}hasNodeImports(e,t){return Bt(t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):G(e))}async getTransformedComponentsForDevelopment(e){let t=[];for(let[n]of this.serverComponents){if(e&&!e(n))continue;let r=k.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!1})}for(let[n]of this.serverActions){if(e&&!e(n))continue;let r=k.relative(this.projectRoot,n),i=this.getComponentId(r),a=await this.buildComponentCodeOnly(n);t.push({id:i,code:a,isAction:!0})}return t}resolveComponentsDirClientImport(e){if(!e.startsWith(`.`)&&!e.startsWith(`@`)&&!e.startsWith(`~`)&&!e.startsWith(`#`))return null;if(e.startsWith(`.`)){if(!e.includes(`/components/`))return null;let t=Gn.exec(e);if(!t)return null;let n=t[1],r=[k.resolve(this.projectRoot,`src`,`components`,`${n}.tsx`),k.resolve(this.projectRoot,`src`,`components`,`${n}.ts`),k.resolve(this.projectRoot,`src`,`components`,`${n}.jsx`),k.resolve(this.projectRoot,`src`,`components`,`${n}.js`)];for(let e of r)if(D.existsSync(e)&&this.isClientComponent(e))return{registryKey:`components/${n}`,absolutePath:e};return null}let t=null;for(let[n,r]of Object.entries(this.options.alias))if(e.startsWith(`${n}/`)||e===n){let i=e.slice(n.length).replace(/^\/+/,``);t=k.join(r,i);break}if(t==null||t===``||!Kn.exec(t))return null;let n=k.isAbsolute(t)?t:k.resolve(this.projectRoot,t),r=[n,`${n}.tsx`,`${n}.ts`,`${n}.jsx`,`${n}.js`];for(let e of r)if(D.existsSync(e)&&this.isClientComponent(e))return{registryKey:this.getComponentReferenceId(e),absolutePath:e};return null}transformComponentImportsToGlobal(e){let t=[];for(let n of gt(e)){if(n.typeOnly||n.sideEffectOnly)continue;let e=this.resolveComponentsDirClientImport(n.source);if(e==null)continue;let r=[];n.namespaceBinding!=null&&r.push(gn(n.namespaceBinding,e.registryKey)),n.defaultBinding!=null&&r.push(hn(n.defaultBinding,e.registryKey,`default`));for(let t of n.named)t.typeOnly||r.push(hn(t.local,e.registryKey,t.imported));r.length!==0&&t.push({start:n.start,end:n.end,replacement:r.join(`
|
|
99
|
+
`)})}if(t.length===0)return e;let n=e;for(let{start:e,end:r,replacement:i}of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e)+i+n.slice(r);return n}isPageComponent(e){return e.includes(`/app/`)||e.includes(`\\app\\`)}createRolldownModuleInfoPlugin(e){let t=new Set;return{name:`rari-rolldown-module-info`,moduleParsed(e){for(let n of e.importedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n);for(let n of e.dynamicallyImportedIds)!n.startsWith(`.`)&&!n.startsWith(`/`)&&!n.startsWith(`node:`)&&!zt(n)&&t.add(n)},buildEnd:()=>{if(t.size===0)return;let n=[...t].sort(),r=this.serverComponents.get(e)??this.serverActions.get(e);r&&(r.dependencies=n);let i=this.buildCache.get(e);i&&(i.bundledDependencies=n)}}}createBuildPlugins(e,t,n,r,i=!1,a){let o=k.dirname(r),s=Wn.test(k.basename(r)),c=new Map,l=new Map;return[{name:`virtual-module`,resolveId(t,n){if(t===e)return t;if(n===e&&(t.startsWith(`./`)||t.startsWith(`../`))){if(t.endsWith(`.module.css`))return null;let e=k.resolve(o,t);for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`,``]){let n=e+t;if(D.existsSync(n)&&D.statSync(n).isFile())return n}for(let t of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(e,`index${t}`);if(D.existsSync(n))return n}return e}return null},load(r){return r===e?{code:t,moduleType:n}:null}},{name:`resolve-client-server-boundaries`,enforce:`pre`,resolveId:(t,n)=>{if(n==null||n===``||n.includes(`node_modules`)||tr(n)||t.startsWith(`node:`)||zt(t)||t===`react`||t===`react-dom`||t===`react/jsx-runtime`||t===`react/jsx-dev-runtime`)return null;let r=null,i=this.options.alias;if(r=C(t,i,this.projectRoot),(r==null||r===``)&&(t.startsWith(`./`)||t.startsWith(`../`))){let i=n===e?o:k.dirname(n);r=k.resolve(i,t)}if((r==null||r===``)&&k.isAbsolute(t)&&(r=t),r!==``)for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=r+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)){let e=k.relative(this.projectRoot,t),n=(e.startsWith(`..`)?t:e).replace(x,`/`);return c.set(t,n),e.startsWith(`..`)&&this.discoveredExternalClientComponents.add(t),{id:`\0client-ref:${t}`}}try{let e=this.moduleAnalysisCache.get(t);if(e.directives.hasUseServer){let n=this.getComponentId(t);return l.set(t,{actionId:n,hasDefaultExport:e.hasDefaultExport}),{id:`\0server-action:${t}`}}}catch(e){console.error(`[rari] Failed to read file for server action detection: ${t}`,e)}break}}return null},load:e=>{if(e.startsWith(`\0client-ref:`)){let t=e.slice(12),n=k.relative(this.projectRoot,t),r=(c.get(t)??(n.startsWith(`..`)?t:n)).replace(x,`/`);return{code:this.generateClientReferenceStub(t,r),moduleType:`js`}}if(e.startsWith(`\0server-action:`)){let t=e.slice(15),n=l.get(t)?.actionId??this.getComponentId(t);return{code:this.generateServerActionRuntimeModule(t,n),moduleType:`js`}}return null}},{name:`use-transformed-server-components`,resolveId:(e,t)=>{if(!i)return null;if(e.startsWith(`file://`)){let t=e.replace(h,``);return D.existsSync(t)?{id:`\0transformed:${t}`}:null}let n=null,r=this.options.alias;n=C(e,r,this.projectRoot);let a=t?.startsWith(`\0`)?o:t!=null&&t!==``?k.dirname(t):o;if((n==null||n===``)&&(e.startsWith(`./`)||e.startsWith(`../`))&&(n=k.resolve(a,e)),n==null||n===``||a.includes(`node_modules`))return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let t=n+e;if(D.existsSync(t)&&D.statSync(t).isFile()){if(this.isClientComponent(t)||this.isServerActionFile(t))return null;let e=k.join(this.projectRoot,`src`);if(!t.startsWith(e))return null;let n=this.getComponentId(t),r=k.join(this.options.outDir,this.options.rscDir,`${n}.js`);if(D.existsSync(r))return{id:`\0transformed:${r}`};break}}return null},load(e){if(e.startsWith(`\0transformed:`)){let t=e.slice(13);return{code:D.readFileSync(t,`utf-8`),moduleType:`js`}}return null}},{name:`resolve-aliases`,resolveId:e=>{if(e.startsWith(`\0`))return null;let t=C(e,this.options.alias,this.projectRoot);if(t==null||t===``)return null;for(let e of[``,`.ts`,`.tsx`,`.js`,`.jsx`]){let n=t+e;if(D.existsSync(n)&&D.statSync(n).isFile()){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}for(let e of[`.ts`,`.tsx`,`.js`,`.jsx`]){let n=k.join(t,`index${e}`);if(D.existsSync(n)){if(this.isServerActionFile(n)){let e=this.getComponentId(n);return l.set(n,{actionId:e,hasDefaultExport:this.moduleAnalysisCache.get(n).hasDefaultExport}),{id:`\0server-action:${n}`}}return n}}return t}},{name:`resolve-rari-proxy`,resolveId:e=>{if(s&&e===`rari`){let e=k.join(er,`proxy/RariResponse.mjs`);if(D.existsSync(e))return e;let t=k.join($,`src/proxy/http/response.ts`);if(D.existsSync(t))return t}return null}},{name:`css-modules`,resolveId:(e,t)=>{if(e.endsWith(`.module.css`)){let n=t!=null&&t!==``&&!t.startsWith(`\0`)?k.dirname(t):o,r=k.resolve(n,e);if(D.existsSync(r))return{id:`\0css-module:${r}`}}return null},load:async e=>{if(!e.startsWith(`\0css-module:`))return null;let t=e.slice(12);try{let e=await cr(),n=D.readFileSync(t),r=e({filename:k.relative(this.projectRoot,t),code:n,cssModules:{pattern:Xn}});a&&a.push(new TextDecoder().decode(r.code));let i={};if(r.exports)for(let[e,t]of Object.entries(r.exports))i[e]=t.name;return{code:`export default ${JSON.stringify(i)}`,moduleType:`js`}}catch(t){throw Error(`[rari] Failed to process CSS module ${e}: ${t instanceof Error?t.message:String(t)}`)}}},{name:`externalize-deps`,resolveId:(e,t)=>{if(e.startsWith(`\0`))return null;if(e.startsWith(`node:`)||zt(e)||[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`rari/image`].includes(e)||e in{"rari/runtime/cache-wrapper":`node_modules/rari/dist/runtime/cache-wrapper.mjs`,"react-server-dom-rari/server":`node_modules/rari/dist/runtime/rsc-references.mjs`})return{id:e,external:!0};if(e===`rari`||C(e,this.options.alias,this.projectRoot)!=null)return null;if(!e.startsWith(`.`)&&!e.startsWith(`/`)){if(Qn(this.projectRoot,e))return{id:e,external:!0};let n=[t!=null&&t!==``&&!t.startsWith(`\0`)?t:null,r].filter(e=>!!e);for(let t of n)try{return{id:de(t).resolve(e)}}catch{try{let n=import.meta.resolve(e,M(t).href);return{id:j(n)}}catch{}}return null}return null}},this.createRolldownModuleInfoPlugin(r),{name:`use-cache`,transform:async(e,t)=>{if(!this.options.experimental?.useCache&&!this.options.experimental?.useCacheRemote)return null;let n=await Un();return n?n(e,t,{hashSalt:`${this.useCacheBuildId??`development`}:rari-use-cache-v1`}):null}}]}async buildComponentCodeOnly(e){let t=await D.promises.readFile(e,`utf-8`),n=Vn(t,this.getComponentId(e))?.code??t,r=this.transformClientImports(n,e),i=this.isPageComponent(e),a=i?this.transformComponentImportsToGlobal(r):r,o=k.extname(e),s;s=o===`.tsx`?`tsx`:o===`.ts`?`ts`:o===`.jsx`?`jsx`:`js`;let c=`\0virtual:${e}`,l=await N({input:c,platform:`node`,write:!1,external:[Yn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${s}`]:s},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(A.env.NODE_ENV!=null&&A.env.NODE_ENV!==``?A.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(c,a,s,e,i,[])});if(l.output.length===0)throw Error(`No output generated from Rolldown`);let u=l.output.find(e=>e.type===`chunk`&&e.isEntry);if(u?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let d=u.code;return d=`// Built: ${new Date().toISOString()}\n${d}`,d}async buildComponentBatch(e,t,n){let r=0,i=0,a=[];if(await new Promise(o=>{let s=()=>{for(;r<n&&i<e.length;){let[n,c]=e[i++],l=k.relative(this.projectRoot,n),u=this.getComponentId(n),d=k.join(this.options.rscDir,`${u}.js`),f=k.join(this.options.outDir,d);r++,(async()=>{try{let e=k.dirname(f);await D.promises.mkdir(e,{recursive:!0});let r=await this.buildSingleComponent(n,f),i=await this.writeComponentCssAsset(u,r.css),a=M(k.resolve(this.projectRoot,f)).href;t.components[u]={id:u,filePath:n,relativePath:l,bundlePath:d,moduleSpecifier:a,dependencies:[...c.dependencies],hasNodeImports:c.hasNodeImports,css:i}}catch(e){a.push(e instanceof Error?e:Error(String(e)))}finally{r--,i>=e.length&&r===0?o():s()}})()}e.length===0&&o()};s()}),a.length>0)throw a[0]}async buildServerComponents(){let e=k.join(this.options.outDir,this.options.rscDir);await D.promises.mkdir(e,{recursive:!0});let t={components:{},buildTime:new Date().toISOString()},n=this.options.experimental?.useCache===!0||this.options.experimental?.useCacheRemote!=null,r=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),i=[...this.serverComponents.entries()].filter(([e])=>!this.isPageComponent(e)),a=[...this.serverComponents.entries()].filter(([e])=>this.isPageComponent(e)),s=[...this.serverActions.entries()];await Promise.all([this.buildComponentBatch(i,t,r),this.buildComponentBatch(s,t,r)]),await this.buildComponentBatch(a,t,r),n&&(this.useCacheBuildId=L(JSON.stringify(t.components),16),t.useCacheBuildId=this.useCacheBuildId);let c=k.join(this.options.outDir,this.options.manifestPath);await D.promises.writeFile(c,JSON.stringify(t),`utf-8`),await this.writeRouteCssEntries(t);let l={};this.options.csp&&(l.csp=this.options.csp),this.options.cacheControl&&(l.cacheControl=this.options.cacheControl),this.options.cache&&(l.cache=this.options.cache),this.options.action&&(l.action=this.options.action),this.options.jsPoolSize!=null&&(l.jsPoolSize=this.options.jsPoolSize);let u=this.options.origin?.trim().replace(/\/+$/,``);u!=null&&u!==``&&(l.origin=u),this.options.htmlLimitedBots!=null&&(l.htmlLimitedBots=this.options.htmlLimitedBots),(this.options.experimental?.useCacheRemote!=null||this.useCacheBuildId!=null&&this.useCacheBuildId!==``)&&(l.useCache={...this.options.experimental?.useCacheRemote?{remote:this.options.experimental.useCacheRemote}:{},...this.useCacheBuildId!=null&&this.useCacheBuildId!==``?{buildId:this.useCacheBuildId}:{}},!this.options.experimental?.useCache&&this.options.experimental?.useCacheRemote&&console.warn(`[server-build] experimental.useCacheRemote is set without experimental.useCache; the 'use cache' transform will still run because useCacheRemote is configured.`));let d=k.join(this.options.outDir,this.options.serverConfigPath);if(Object.keys(l).length===0)try{await D.promises.unlink(d)}catch(e){o(e)!==`ENOENT`&&console.warn(`Failed to remove server config file:`,e)}else await D.promises.writeFile(d,JSON.stringify(l),`utf-8`);return t}async buildMdxRegistry(e){let n=on({projectRoot:this.projectRoot,mdxOptions:e,alias:this.options.alias,cache:this.moduleAnalysisCache}),r=k.join(this.options.outDir,this.options.manifestPath),i;if(D.existsSync(r)){let e=await D.promises.readFile(r,`utf-8`),n=t(e);i=n&&lr(n)?n:{components:{},buildTime:new Date().toISOString()}}else i={components:{},buildTime:new Date().toISOString()};i.mdxRegistry=n.map(e=>({name:e.name,id:e.moduleId,client:e.client})),await D.promises.writeFile(r,JSON.stringify(i),`utf-8`)}async buildSSRClientComponents(){let e=k.join(this.options.outDir,`ssr`);await D.promises.mkdir(e,{recursive:!0});let t=[...this.getClientComponentFiles()];for(let e of this.discoveredExternalClientComponents)if(!t.some(t=>t.filePath===e))try{let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}catch{}try{let e=rr();if(e!=null&&e!==``){let n=D.readFileSync(e,`utf-8`);t.push({filePath:e,code:n})}}catch{}if(t.length===0){let t={};await this.buildExternalClientComponents(t,new Map),await this.writeClientReferenceManifest(e,t);return}let n=new Map;for(let{filePath:e}of t){let t=or(e,this.projectRoot);n.set(k.resolve(e),`file:///ssr/${t}.js`)}let r={},i=Math.min(8,Math.max(1,(await import(`node:os`)).cpus().length)),a=0,o=0;await new Promise(e=>{let s=()=>{for(;a<i&&o<t.length;){let{filePath:i,code:c}=t[o++],l=ar(i,this.projectRoot),u=`ssr/${or(i,this.projectRoot)}.js`,d=k.join(this.options.outDir,u);a++,(async()=>{try{let e=k.dirname(d);await D.promises.mkdir(e,{recursive:!0}),await this.buildSSRSingleClient(i,d,n);let t=this.extractExportNames(c);r[l]={id:l,filePath:i,bundlePath:u,exports:t}}catch(e){console.warn(`[rari] SSR build failed for ${l}:`,e instanceof Error?e.message:e)}finally{a--,o>=t.length&&a===0?e():s()}})()}t.length===0&&e()};s()}),await this.buildExternalClientComponents(r,n),await this.writeClientReferenceManifest(e,r)}async writeClientReferenceManifest(e,t){let n=k.join(e,`manifest.json`);await D.promises.writeFile(n,JSON.stringify(t),`utf-8`);let r={};for(let[e,n]of Object.entries(t))for(let t of n.exports){let i=`${e}#${t}`;r[i]={id:i,chunks:`/${n.bundlePath}`,name:t}}let i=k.join(this.options.outDir,`server`);await D.promises.mkdir(i,{recursive:!0});let a=k.join(i,`client-reference-manifest.json`);await D.promises.writeFile(a,JSON.stringify(r),`utf-8`)}resolveExternalClientSourcePath(e,t){let n=k.join($,...e);if(D.existsSync(n))return n;try{let e=j(import.meta.resolve(t));if(D.existsSync(e))return e}catch{}return null}async buildExternalClientComponents(e,t){for(let{componentId:n,devSourceSegments:r,publishedExport:i,exports:a}of $n){let o=this.resolveExternalClientSourcePath(r,i);if(o!=null&&o!==``)try{let r=`ssr/${`external_${L(n)}`}.js`,i=k.join(this.options.outDir,r);await D.promises.mkdir(k.dirname(i),{recursive:!0}),await this.buildSSRSingleClient(o,i,t),e[n]={id:n,filePath:o,bundlePath:r,exports:[...a]}}catch(e){console.warn(`[rari] SSR build failed for ${n}:`,e instanceof Error?e.message:e)}}}extractExportNames(e){return _t(e)}generateClientReferenceStub(e,t){let n=[`default`];try{n=_t(D.readFileSync(e,`utf-8`))}catch{}return mn(t,n)}isServerActionFile(e){try{let t=D.readFileSync(e,`utf-8`);return this.isServerAction(t,e)}catch{return!1}}generateServerActionRuntimeModule(e,t){let n=D.readFileSync(e,`utf-8`),r=this.extractExportNames(n),i=[`const __rariActionMod = globalThis.__rari_rsc_require__(${JSON.stringify(t)});`,`if (!__rariActionMod) throw new Error("Server action module ${t} is not registered");`];for(let e of r)e==="default"?i.push(`export default __rariActionMod.default;`):i.push(`export const ${e} = __rariActionMod.${e};`);return`${i.join(`
|
|
100
100
|
`)}\n`}generateServerActionReferenceModule(e){let t=D.readFileSync(e,`utf-8`),n=this.extractExportNames(t),r=this.getComponentId(e),i=`import { createServerReference } from 'react-server-dom-webpack/client';
|
|
101
101
|
`;i+=`import { callServer } from 'rari/runtime/call-server';
|
|
102
102
|
`;for(let e of n){let t=`${r}#${e}`;i+=e==="default"?`export default createServerReference(${JSON.stringify(t)}, callServer);\n`:`export const ${e} = createServerReference(${JSON.stringify(t)}, callServer);\n`}return i}async buildSSRSingleClient(e,t,n){let r=(await D.promises.readFile(e,`utf-8`)).replace(/^['"]use client['"];?\s*/m,``),i=k.extname(e),a;a=i===`.tsx`?`tsx`:i===`.ts`?`ts`:i===`.jsx`?`jsx`:`js`;let o=`\0ssr-virtual:${e}`,s=this.projectRoot,c=nr(e,s),l=e=>this.generateServerActionReferenceModule(e),u=e=>this.isServerActionFile(e),d=(await N({input:o,platform:`node`,write:!1,external:[Yn,`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(A.env.NODE_ENV!=null&&A.env.NODE_ENV!==``?A.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=k.join(c,t.slice(2)):r===o?i=k.resolve(k.dirname(e),t):r!=null&&r!==``&&(i=k.resolve(k.dirname(r.replace(`\0ssr-virtual:`,``).replace(`\0server-action-ref:`,``)),t));let a=oe(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]),s=a!=null&&a!==``?a:se(i,[`.mjs`,`.mts`,`.ts`,`.tsx`,`.js`,`.jsx`]);if(s!=null&&s!==``&&u(s))return`\0server-action-ref:${k.resolve(s)}`;if(s!=null&&s!==``&&n!=null){let t=k.resolve(s),r=n.get(t);if(r!=null&&r!==``&&t!==k.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 D.promises.writeFile(t,f,`utf-8`),{code:f}}async buildSingleComponent(e,t){let n=await D.promises.readFile(e,`utf-8`),r=Vn(n,this.getComponentId(e))?.code??n,i=this.transformClientImports(r,e),a=this.isPageComponent(e),o=a?this.transformComponentImportsToGlobal(i):i,s=k.extname(e),c;c=s===`.tsx`?`tsx`:s===`.ts`?`ts`:s===`.jsx`?`jsx`:`js`;let l=`\0virtual:${e}`,u=[],d=await N({input:l,platform:`node`,write:!1,external:[Yn,`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`],output:{format:`esm`,minify:this.options.minify},moduleTypes:{[`.${c}`]:c},resolve:{mainFields:[`module`,`main`],conditionNames:[`import`,`module`,`default`],extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},transform:{jsx:`react`,define:{global:`globalThis`,"process.env.NODE_ENV":JSON.stringify(A.env.NODE_ENV!=null&&A.env.NODE_ENV!==``?A.env.NODE_ENV:`production`),...this.options.define}},plugins:this.createBuildPlugins(l,o,c,e,a,u)});if(d.output.length===0)throw Error(`No output generated from Rolldown`);let f=d.output.find(e=>e.type===`chunk`&&e.isEntry);if(f?.type!==`chunk`)throw Error(`No entry chunk found in Rolldown output`);let p=f.code;p=`// Built: ${new Date().toISOString()}\n${p}`,await D.promises.writeFile(t,p,`utf-8`);let m=await D.promises.open(t,`r+`);return await m.sync(),await m.close(),{code:p,css:u}}transformClientImports(e,t){let n=$n.map(e=>e.componentId),r=[],i=!1,a=!1;for(let o of gt(e)){if(o.typeOnly||o.sideEffectOnly)continue;let e=!1,s=o.source;if(n.includes(o.source))e=!0;else if(Jn.test(o.source)||Object.keys(this.options.alias).some(e=>o.source===e||o.source.startsWith(`${e}/`))){let n=this.resolveImportPath(o.source,t);this.isClientComponent(n)&&(e=!0,s=k.relative(this.projectRoot,n).replace(x,`/`))}if(!e)continue;let c=[];o.namespaceBinding!=null&&(a=!0,c.push(`const ${o.namespaceBinding} = createClientModuleProxy(${JSON.stringify(s)});`)),o.defaultBinding!=null&&(i=!0,c.push(`const ${o.defaultBinding} = registerClientReference(
|
|
@@ -143,7 +143,7 @@ if (import.meta.hot) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
${e}`,e}}if(o.topLevelUseServer)return y(n,`server`),a.name===`rsc`||a.name===`ssr`?de(t,n,o):E(t,n,o);let s=g(n);if(s===`server`)return a.name===`rsc`||a.name===`ssr`?de(t,n,o):E(t,n,o);if(s===`client`)return O(t,n,o);y(n,`unknown`);let l=t,u=!1,d=!1,p=n.includes(`entry-client`),h=[],_=new Set;for(let e of gt(t)){if(e.typeOnly||e.sideEffectOnly||!Qr.test(e.source)&&!$r(e.source,f))continue;let t=le(e.source,n,f),r=g(t)===`client`||D.existsSync(t)&&c.get(t).topLevelUseClient;if(r&&(y(t,`client`),ee(t)),!r||p||a.name!==`rsc`&&a.name!==`ssr`)continue;let i=pn(e,t);if(i.code!==``){for(let e of i.helpers)_.add(e);h.push({start:e.start,end:e.end,replacement:i.code}),u=!0,d=!0}}for(let{start:e,end:t,replacement:n}of[...h].sort((e,t)=>t.start-e.start))l=l.slice(0,e)+n+l.slice(t);if(_.size>0&&(l=un(l,`react-server-dom-rari/server`,[..._])),u){let e=l.includes(`import React`)||ei.test(l)||ti.test(l),t=``;if(d&&!e&&(t+=`import React from 'react';
|
|
146
|
-
`),t&&(l=t+l),!l.includes(`Suspense`)){let e=ni.exec(l);e&&(e[1]&&!e[2].includes(`Suspense`)?l=l.replace(e[0],e[0].replace(oi,`{ Suspense, $1 }`)):e[1]||(l=l.replace(e[0],`import React, { Suspense } from 'react';`)))}let r=A.env.NODE_ENV!==`production`;return(l.includes(`</`)||l.includes(`/>`)||ai.test(l))&&r&&(l=`'use client';\n\n${l}`,y(n,`client`)),l}return i?t:null},async configureServer(n){let r=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.cwd(),i=k.join(r,`src`);await vi(r,e);let a=async()=>{try{let t=new dr(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 $t(t,F()),D.existsSync(i)){let e=hr(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:${F()}`;await Promise.all(a.map(async e=>{try{if(e.id.startsWith(`app/`)||e.isAction)return;let t=await fetch(`${o}/_rari/register`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:e.id,component_code:e.code})});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}}catch(t){console.error(`[rari] Runtime: Failed to register component ${e.id}:`,t instanceof Error?t.message:String(t))}}))}catch(e){console.error(`[rari] Runtime: Component discovery failed:`,e instanceof Error?e.message:String(e))}},o=async()=>{try{let e=`http://localhost:${F()}`,t=oe();await Promise.all([...t].map(async t=>{let n=k.relative(A.cwd(),t),r=k.basename(t).replace(ie,``);try{await fetch(`${e}/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:r,file_path:n,export_name:`default`})})}catch(e){console.error(`[rari] Runtime: Failed to pre-register client component ${r}:`,e)}}))}catch(e){console.error(`[rari] Runtime: Failed to pre-register client components:`,e)}},s=async()=>{if(u)return;let{getBinaryPath:t,getInstallationInstructions:r}=await import(`./platform.mjs`),i;try{i=t()}catch(e){console.error(`rari binary not found`),console.error(` ${e instanceof Error?e.message:String(e)}`),console.error(r());return}let s=F(),c=A.env.NODE_ENV===`production`?`production`:`development`,l=n.config.server.port,d=[`--mode`,c,`--port`,s.toString(),`--host`,`127.0.0.1`];u=pe(i,
|
|
146
|
+
`),t&&(l=t+l),!l.includes(`Suspense`)){let e=ni.exec(l);e&&(e[1]&&!e[2].includes(`Suspense`)?l=l.replace(e[0],e[0].replace(oi,`{ Suspense, $1 }`)):e[1]||(l=l.replace(e[0],`import React, { Suspense } from 'react';`)))}let r=A.env.NODE_ENV!==`production`;return(l.includes(`</`)||l.includes(`/>`)||ai.test(l))&&r&&(l=`'use client';\n\n${l}`,y(n,`client`)),l}return i?t:null},async configureServer(n){let r=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.cwd(),i=k.join(r,`src`);await vi(r,e);let a=async()=>{try{let t=new dr(r,{outDir:`dist`,rscDir:`server`,manifestPath:`server/manifest.json`,serverConfigPath:`server/config.json`,alias:f,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,action:e.action,jsPoolSize:e.jsPoolSize,origin:e.origin,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c});if(l=t,d??=new $t(t,F()),D.existsSync(i)){let e=hr(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:${F()}`;await Promise.all(a.map(async e=>{try{if(e.id.startsWith(`app/`)||e.isAction)return;let t=await fetch(`${o}/_rari/register`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:e.id,component_code:e.code})});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}}catch(t){console.error(`[rari] Runtime: Failed to register component ${e.id}:`,t instanceof Error?t.message:String(t))}}))}catch(e){console.error(`[rari] Runtime: Component discovery failed:`,e instanceof Error?e.message:String(e))}},o=async()=>{try{let e=`http://localhost:${F()}`,t=oe();await Promise.all([...t].map(async t=>{let n=k.relative(A.cwd(),t),r=k.basename(t).replace(ie,``);try{await fetch(`${e}/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:r,file_path:n,export_name:`default`})})}catch(e){console.error(`[rari] Runtime: Failed to pre-register client component ${r}:`,e)}}))}catch(e){console.error(`[rari] Runtime: Failed to pre-register client components:`,e)}},s=async()=>{if(u)return;let{getBinaryPath:t,getInstallationInstructions:r}=await import(`./platform.mjs`),i;try{i=t()}catch(e){console.error(`rari binary not found`),console.error(` ${e instanceof Error?e.message:String(e)}`),console.error(r());return}let s=F(),c=A.env.NODE_ENV===`production`?`production`:`development`,l=n.config.server.port,d=e.origin?.trim().replace(/\/+$/,``),f=A.env.RARI_ORIGIN?.trim().replace(/\/+$/,``),p=[`--mode`,c,`--port`,s.toString(),`--host`,`127.0.0.1`];u=pe(i,p,{stdio:[`ignore`,`pipe`,`pipe`],cwd:A.cwd(),env:{...A.env,RUST_LOG:A.env.RUST_LOG!=null&&A.env.RUST_LOG!==``?A.env.RUST_LOG:`error`,RARI_VITE_PORT:l.toString(),...e.jsPoolSize!=null&&(A.env.RARI_JS_POOL_SIZE==null||A.env.RARI_JS_POOL_SIZE===``)?{RARI_JS_POOL_SIZE:String(e.jsPoolSize)}:{},...d!=null&&d!==``&&(f==null||f===``)?{RARI_ORIGIN:d}:{},...e.htmlLimitedBots!=null&&(A.env.RARI_HTML_LIMITED_BOTS==null||A.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=>{M=!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,M=!1,t?console.error(`rari server stopped by signal ${t}`):e===0?console.error(`rari server stopped successfully`):e&&console.error(`rari server exited with code ${e}`)}),await ge(1e4)?(await a(),await o()):console.error(`Server failed to become ready for component registration`)},p=async e=>{try{if(!w(e))return;l??await a();let t=l;if(t==null)return;let n=c.getSource(e);t.addServerComponent(e,n);let r=Yt(t.getImportGraph(),[e]);r.add(e);let i=await t.getTransformedComponentsForDevelopment(e=>r.has(e));if(i.length===0)return;let o=`http://localhost:${F()}`;await Promise.all(i.map(async e=>{try{let t=await fetch(`${o}/_rari/register`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:e.id,component_code:e.code})});if(!t.ok){let e=await t.text();throw Error(`HTTP ${t.status}: ${e}`)}}catch(t){console.error(`[rari] Failed to register component`,`${e.id}:`,t instanceof Error?t.message:String(t))}}))}catch(t){console.error(`[rari] Targeted HMR failed for`,`${e}:`,t instanceof Error?t.message:String(t))}};s().catch(e=>{console.error(`[rari] Failed to start Rust server:`,e)}),n.middlewares.use((e,t,n)=>{(async()=>{let r=e.headers.accept;if(r!=null&&r!==``&&r.includes(`text/x-component`)&&e.url!=null&&e.url!==``&&!e.url.startsWith(`/api`)&&!e.url.startsWith(`/rsc`)&&!e.url.includes(`.`)){if(!M&&!await ge(1e4)){console.error(`[rari] Rust server not ready, cannot proxy RSC request`),t.headersSent||(t.statusCode=503,t.end(`Server not ready`));return}let n=F(),r=`http://localhost:${n}${e.url}`;try{let i={};for(let[t,n]of Object.entries(e.headers))typeof n==`string`?i[t]=n:Array.isArray(n)&&(i[t]=n.join(`,`));i.host=`localhost:${n}`,i[`accept-encoding`]=`identity`;let a=await fetch(r,{method:e.method,headers:i});if(t.statusCode=a.status,a.headers.forEach((e,n)=>{n.toLowerCase()!==`content-encoding`&&t.setHeader(n,e)}),a.body){let e=a.body.getReader();try{let n=!1;for(;!n;){let{done:r,value:i}=await e.read();n=r,!n&&i!=null&&t.write(fe.from(i))}t.end()}catch(e){console.error(`[rari] Stream error:`,e),t.headersSent||(t.statusCode=500),t.end()}}else t.end();return}catch(e){console.error(`[rari] Failed to proxy RSC request:`,e),t.headersSent||(t.statusCode=500,t.end(`Internal Server Error`));return}}n()})()}),n.watcher.on(`change`,e=>{(async()=>{v.test(e)&&(b(e),re(e),c.invalidate(e)),v.test(e)&&e.includes(i)&&w(e)&&(n.ws.send({type:`custom`,event:`rari:register-server-component`,data:{filePath:e}}),await p(e))})()}),n.middlewares.use(`/api/vite/hmr-transform`,(e,n)=>{if(e.method!==`POST`){n.statusCode=405,n.end(`Method Not Allowed`);return}let r=``;e.on(`data`,e=>{r+=e.toString()}),e.on(`end`,()=>{(async()=>{try{let e=t(r),i=e&&typeof e.filePath==`string`?e.filePath:void 0;if(i==null||i===``){n.statusCode=400,n.end(JSON.stringify({error:`filePath is required`}));return}await p(i),n.statusCode=200,n.setHeader(`Content-Type`,`application/json`),n.end(JSON.stringify({success:!0,filePath:i,message:`Component transformation completed`}))}catch(e){n.statusCode=500,n.setHeader(`Content-Type`,`application/json`),n.end(JSON.stringify({success:!1,error:e instanceof Error?e.message:String(e)}))}})()})}),n.httpServer?.on(`close`,()=>{if(d&&=(d.dispose(),null),u){let e=u;u=null,M=!1;let t=!1,n=setTimeout(()=>{t||e.kill(`SIGKILL`)},5e3);n.unref(),e.once(`exit`,()=>{t=!0,clearTimeout(n)}),e.kill(`SIGTERM`);return}M=!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(en(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=pi(k.basename(e));if(t!=null&&t!==``)return t}if(t!=null&&t!==``&&t.startsWith(`virtual:`)&&e.startsWith(`../`)){let n=import.meta.url,r=j(n),i=k.dirname(r),a=null,o=[k.join(i,`runtime`),k.join(i,`../runtime`)];for(let e of o)if(D.existsSync(e)){a=e;break}if(a!=null&&a!==``){let t=k.join(a,e);if(D.existsSync(t))return t;let n=k.join(a,`../dist`,k.basename(e));if(D.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=k.join(i,e);if(D.existsSync(s))return s;let c=k.join(i,`../dist`,k.basename(e));if(D.existsSync(c))return c}if(A.env.NODE_ENV===`production`)try{let t=k.resolve(e);if(D.existsSync(t)&&w(t))return{id:e,external:!0}}catch(t){o(t)!==`ENOENT`&&console.warn(`[rari] Unexpected error resolving server component:`,e,t)}return null},async load(t){if(v.test(t)&&this.environment.name===`client`)try{let e=c.get(t);if(e.topLevelUseServer)return E(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:A.cwd(),n=Wt(Lt(k.join(t,`src`),Object.values(f)),c),r=new Set([...oe(),...n]),i=[{path:`rari/image`,exports:[`Image`]},{path:`virtual:error-boundary-wrapper.tsx`,exports:[`ErrorBoundaryWrapper`]}],a=[...r].filter(e=>{try{return c.get(e).topLevelUseClient}catch{return!1}}).map(e=>{let t=k.relative(A.cwd(),e).replace(x,`/`),n=t.replace(v,``),r=t.startsWith(`..`)?e.replace(x,`/`):t,i=!1,a=``;try{if(!c.get(e).hasDefaultExport){let t=c.getSource(e).match(te);t&&(i=!0,a=t[1])}}catch(t){o(t)!==`ENOENT`&&console.warn(`[rari] Unexpected error reading component for export detection:`,e,t)}let s=i?a:`default`,l=i?a:k.basename(e,k.extname(e)),u=r.replace(x,`/`),d=u.startsWith(`/`)||_.test(u)?u:`/${u}`;return` "${r}": {
|
|
147
147
|
id: "${n}",
|
|
148
148
|
path: "${r}",
|
|
149
149
|
exportName: "${s}",
|
|
@@ -207,4 +207,4 @@ export function createFromReadableStream(stream, options) {
|
|
|
207
207
|
export const createServerReference = module.exports.createServerReference;
|
|
208
208
|
export const encodeReply = module.exports.encodeReply;
|
|
209
209
|
export const createTemporaryReferenceSet = module.exports.createTemporaryReferenceSet;
|
|
210
|
-
`}}if(t.endsWith(`.mjs`)&&D.existsSync(t))try{let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.cwd(),r=D.realpathSync(t),i=k.relative(n,r),a=!i.startsWith(`..`)&&!k.isAbsolute(i),o=r.includes(`${k.sep}node_modules${k.sep}`),s=r.includes(`${k.sep}packages${k.sep}rari${k.sep}`)||r.includes(`${k.sep}node_modules${k.sep}rari${k.sep}`);return a||o||s?D.readFileSync(t,`utf-8`):(console.warn(`[rari] Refusing to load .mjs file outside project root and node_modules: ${t}`),null)}catch(e){return console.warn(`[rari] Error validating .mjs file path: ${t}`,e),null}},async handleHotUpdate({file:e,server:t}){if(ce(),e.endsWith(`.mdx`)&&m(),!v.test(e))return;if(b(e),re(e),c.invalidate(e),m(),e.includes(`/dist/`)||e.includes(`\\dist\\`))return[];let n=d?.detectComponentType(e)??`unknown`,r=e.includes(`/app/`)||e.includes(`\\app\\`),i=(e,t)=>e.endsWith(`${t}.tsx`)||e.endsWith(`${t}.jsx`)||e.endsWith(`${t}.ts`)||e.endsWith(`${t}.js`),a=[`page`,`layout`,`template`,`loading`,`error`,`not-found`].some(t=>i(e,t));if(!(r&&a)&&n!==`client`&&n===`server`)return d&&await d.handleServerComponentUpdate(e,t),[]},transformIndexHtml:{order:`pre`,handler(e){let t=[];for(let n of e.matchAll(ri)){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 vi(e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.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}}},gr({...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&&P.push(_e(e.proxy??{})),e.router!==!1&&P.push(Je(e.router??{})),he(P)}function xi(e){return{...e,plugins:[bi(),...e.plugins??[]]}}export{e as ApiResponse,zr as clearPropsCache,Br as clearPropsCacheForComponent,xi as defineRariConfig,yi as defineRariOptions,Pr as extractMetadata,Nr as extractServerProps,Rr as extractServerPropsWithCache,Fr as extractStaticParams,Ne as generateAppRouteManifest,Ir as hasServerSideDataFetching,bi as rari,_e as rariProxy,Je as rariRouter};
|
|
210
|
+
`}}if(t.endsWith(`.mjs`)&&D.existsSync(t))try{let n=e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.cwd(),r=D.realpathSync(t),i=k.relative(n,r),a=!i.startsWith(`..`)&&!k.isAbsolute(i),o=r.includes(`${k.sep}node_modules${k.sep}`),s=r.includes(`${k.sep}packages${k.sep}rari${k.sep}`)||r.includes(`${k.sep}node_modules${k.sep}rari${k.sep}`);return a||o||s?D.readFileSync(t,`utf-8`):(console.warn(`[rari] Refusing to load .mjs file outside project root and node_modules: ${t}`),null)}catch(e){return console.warn(`[rari] Error validating .mjs file path: ${t}`,e),null}},async handleHotUpdate({file:e,server:t}){if(ce(),e.endsWith(`.mdx`)&&m(),!v.test(e))return;if(b(e),re(e),c.invalidate(e),m(),e.includes(`/dist/`)||e.includes(`\\dist\\`))return[];let n=d?.detectComponentType(e)??`unknown`,r=e.includes(`/app/`)||e.includes(`\\app\\`),i=(e,t)=>e.endsWith(`${t}.tsx`)||e.endsWith(`${t}.jsx`)||e.endsWith(`${t}.ts`)||e.endsWith(`${t}.js`),a=[`page`,`layout`,`template`,`loading`,`error`,`not-found`].some(t=>i(e,t));if(!(r&&a)&&n!==`client`&&n===`server`)return d&&await d.handleServerComponentUpdate(e,t),[]},transformIndexHtml:{order:`pre`,handler(e){let t=[];for(let n of e.matchAll(ri)){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 vi(e.projectRoot!=null&&e.projectRoot!==``?e.projectRoot:A.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}}},gr({...e.serverBuild,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,action:e.action,jsPoolSize:e.jsPoolSize,origin:e.origin,htmlLimitedBots:e.htmlLimitedBots,experimental:e.experimental,moduleAnalysisCache:c,mdx:e.mdx})];return e.proxy!==!1&&P.push(_e(e.proxy??{})),e.router!==!1&&P.push(Je(e.router??{})),he(P)}function xi(e){return{...e,plugins:[bi(),...e.plugins??[]]}}export{e as ApiResponse,zr as clearPropsCache,Br as clearPropsCacheForComponent,xi as defineRariConfig,yi as defineRariOptions,Pr as extractMetadata,Nr as extractServerProps,Rr as extractServerPropsWithCache,Fr as extractStaticParams,Ne as generateAppRouteManifest,Ir as hasServerSideDataFetching,bi as rari,_e as rariProxy,Je 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.11",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -145,13 +145,13 @@
|
|
|
145
145
|
"rolldown": "^1.2.3"
|
|
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.11",
|
|
149
|
+
"rari-darwin-arm64": "0.15.11",
|
|
150
|
+
"rari-darwin-x64": "0.15.11",
|
|
151
|
+
"rari-linux-arm64": "0.15.11",
|
|
152
|
+
"rari-linux-x64": "0.15.11",
|
|
153
|
+
"rari-win32-arm64": "0.15.11",
|
|
154
|
+
"rari-win32-x64": "0.15.11"
|
|
155
155
|
},
|
|
156
156
|
"devDependencies": {
|
|
157
157
|
"@mdx-js/mdx": "^3.1.1",
|