rari 0.15.5 → 0.15.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/rsc-client-runtime.mjs +1 -1
- package/dist/vite.d.mts +18 -1
- package/dist/vite.mjs +4 -4
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as e}from"../type-guards-CTkEL8zw.mjs";import{a as t,i as n,n as r,r as i,t as a}from"../rari-global-5vGzhToD.mjs";import{n as o,r as s}from"../get-client-component-CLpyIcLJ.mjs";if(n().isDevelopment=process.env.NODE_ENV!==`production`,i(),a(),r(),typeof window<`u`&&(o(),Reflect.set(globalThis,`__rari_rsc_require__`,s)),typeof window<`u`){let e=t();e.streaming??={bufferedRows:[]}}if(import.meta.hot){function r(){return import.meta.env.RARI_SERVER_URL!=null&&import.meta.env.RARI_SERVER_URL!==``?import.meta.env.RARI_SERVER_URL:typeof window<`u`?window.location.origin:`http://localhost:3000`}function i(e){if(!e)return!1;try{return n().serverComponents?.has(e)===!0}catch{return!1}}let a=!1,o=[],s=new Map;function c(e,t,n){s.set(e,async e=>{n(e)&&await t(e)}),import.meta.hot.on(e,t=>{(async()=>{if(!a){o.push({event:e,data:t});return}try{let n=s.get(e);n&&await n(t)}catch(t){console.error(`[rari] HMR: Error in handler for '${e}':`,t)}})()})}function l(t){return e(t)&&typeof t.filePath==`string`&&t.filePath!==``}function u(t){return e(t)&&Array.isArray(t.serverComponents)}function d(t){return e(t)&&typeof t.path==`string`&&t.path!==``}function f(t){return e(t)}function p(t){return e(t)}function m(t){return e(t)&&typeof t.filePath==`string`&&t.filePath!==``}c(`rari:register-server-component`,e=>{let t=n();t.serverComponents??=new Set,t.serverComponents.add(e.filePath)},l),c(`rari:server-components-registry`,e=>{let t=n();t.serverComponents??=new Set;for(let n of e.serverComponents)t.serverComponents.add(n)},u),c(`vite:beforeFullReload`,e=>{i(e.path)&&window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.path}}))},d),c(`rari:server-component-updated`,e=>{let t=e.id!=null&&e.id!==``?e.id:e.componentId,n=e.t!=null&&e.t!==0?e.t:e.timestamp;t!=null&&t!==``?window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{componentId:t,filePath:e.filePath!=null&&e.filePath!==``?e.filePath:e.file,type:`server-component`,timestamp:n}})):e.path!=null&&e.path!==``&&i(e.path)&&window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.path}}))},f),c(`rari:app-router-updated`,async n=>{if(
|
|
1
|
+
import{p as e}from"../type-guards-CTkEL8zw.mjs";import{a as t,i as n,n as r,r as i,t as a}from"../rari-global-5vGzhToD.mjs";import{n as o,r as s}from"../get-client-component-CLpyIcLJ.mjs";if(n().isDevelopment=process.env.NODE_ENV!==`production`,i(),a(),r(),typeof window<`u`&&(o(),Reflect.set(globalThis,`__rari_rsc_require__`,s)),typeof window<`u`){let e=t();e.streaming??={bufferedRows:[]}}if(import.meta.hot){function r(){return import.meta.env.RARI_SERVER_URL!=null&&import.meta.env.RARI_SERVER_URL!==``?import.meta.env.RARI_SERVER_URL:typeof window<`u`?window.location.origin:`http://localhost:3000`}function i(e){if(!e)return!1;try{return n().serverComponents?.has(e)===!0}catch{return!1}}let a=!1,o=[],s=new Map;function c(e,t,n){s.set(e,async e=>{n(e)&&await t(e)}),import.meta.hot.on(e,t=>{(async()=>{if(!a){o.push({event:e,data:t});return}try{let n=s.get(e);n&&await n(t)}catch(t){console.error(`[rari] HMR: Error in handler for '${e}':`,t)}})()})}function l(t){return e(t)&&typeof t.filePath==`string`&&t.filePath!==``}function u(t){return e(t)&&Array.isArray(t.serverComponents)}function d(t){return e(t)&&typeof t.path==`string`&&t.path!==``}function f(t){return e(t)}function p(t){return e(t)}function m(t){return e(t)&&typeof t.filePath==`string`&&t.filePath!==``}c(`rari:register-server-component`,e=>{let t=n();t.serverComponents??=new Set,t.serverComponents.add(e.filePath)},l),c(`rari:server-components-registry`,e=>{let t=n();t.serverComponents??=new Set;for(let n of e.serverComponents)t.serverComponents.add(n)},u),c(`vite:beforeFullReload`,e=>{i(e.path)&&window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.path}}))},d),c(`rari:server-component-updated`,e=>{let t=e.id!=null&&e.id!==``?e.id:e.componentId,n=e.t!=null&&e.t!==0?e.t:e.timestamp;t!=null&&t!==``?window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{componentId:t,filePath:e.filePath!=null&&e.filePath!==``?e.filePath:e.file,type:`server-component`,timestamp:n}})):e.path!=null&&e.path!==``&&i(e.path)&&window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.path}}))},f),c(`rari:app-router-updated`,async n=>{if(n.routePath!=null&&n.routePath!==``||n.affectedRoutes!=null&&n.affectedRoutes.length!==0)try{let i=r(),a=await fetch(`${i}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`register`,file_path:n.filePath})});if(!a.ok)throw Error(`Component reload failed: ${a.status}`);let o=await a.json(),s=e(o)&&o.success===!0,c=e(o)&&o.reloaded===!0,l=e(o)&&typeof o.error==`string`?o.error:`Component reload unsuccessful`;if(!s&&!c)throw Error(l);if(await fetch(`${i}/_rari/hmr`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`invalidate`,componentId:n.routePath!=null&&n.routePath!==``?n.routePath:n.filePath,filePath:n.filePath})}),n.metadataChanged&&n.metadata&&(n.metadata.title!=null&&n.metadata.title!==``&&(document.title=n.metadata.title),n.metadata.description!=null&&n.metadata.description!==``)){let e=document.querySelector(`meta[name="description"]`);e||(e=document.createElement(`meta`),e.setAttribute(`name`,`description`),document.head.appendChild(e)),e.setAttribute(`content`,n.metadata.description)}let u=t();n.manifestUpdated&&u?.routeInfoCache&&u.routeInfoCache.clear(),window.dispatchEvent(new CustomEvent(`rari:app-router-rerender`,{detail:{routePath:n.routePath,affectedRoutes:n.affectedRoutes??(n.routePath==null?[]:[n.routePath]),currentPath:window.location.pathname,preserveParams:!0}}))}catch(e){console.error(`[rari] HMR: App router update failed:`,e)}},p),c(`rari:server-action-updated`,e=>{window.dispatchEvent(new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.filePath,type:`server-action`}}))},m),o.length>0?(async()=>{try{let e=[...o];o.length=0;for(let{event:t,data:n}of e){let e=s.get(t);e&&await e(n)}}catch(e){console.error(`[rari] HMR: Error during event replay:`,e)}finally{a=!0}})():a=!0}export{};
|
package/dist/vite.d.mts
CHANGED
|
@@ -54,6 +54,10 @@ interface ServerCSPConfig {
|
|
|
54
54
|
readonly connectSrc?: readonly string[];
|
|
55
55
|
readonly defaultSrc?: readonly string[];
|
|
56
56
|
readonly workerSrc?: readonly string[];
|
|
57
|
+
readonly frameAncestors?: readonly string[];
|
|
58
|
+
readonly baseUri?: readonly string[];
|
|
59
|
+
readonly formAction?: readonly string[];
|
|
60
|
+
readonly useNonces?: boolean;
|
|
57
61
|
}
|
|
58
62
|
interface ServerCacheControlConfig {
|
|
59
63
|
readonly routes: Readonly<Record<string, string>>;
|
|
@@ -63,6 +67,7 @@ interface ServerCacheLayerConfig {
|
|
|
63
67
|
readonly url?: string;
|
|
64
68
|
readonly maxEntries?: number;
|
|
65
69
|
readonly defaultTtlSecs?: number;
|
|
70
|
+
readonly maxBytes?: number;
|
|
66
71
|
}
|
|
67
72
|
interface ServerCacheConfig {
|
|
68
73
|
readonly layers?: Readonly<Record<string, ServerCacheLayerConfig>>;
|
|
@@ -71,11 +76,15 @@ interface ServerUseCacheConfig {
|
|
|
71
76
|
readonly remote?: ServerCacheLayerConfig;
|
|
72
77
|
readonly buildId?: string;
|
|
73
78
|
}
|
|
79
|
+
interface ServerActionConfig {
|
|
80
|
+
readonly allowedOrigins?: readonly string[];
|
|
81
|
+
}
|
|
74
82
|
interface ServerConfig {
|
|
75
83
|
csp?: ServerCSPConfig;
|
|
76
84
|
cacheControl?: ServerCacheControlConfig;
|
|
77
85
|
cache?: ServerCacheConfig;
|
|
78
86
|
useCache?: ServerUseCacheConfig;
|
|
87
|
+
action?: ServerActionConfig;
|
|
79
88
|
jsPoolSize?: number;
|
|
80
89
|
htmlLimitedBots?: string;
|
|
81
90
|
}
|
|
@@ -92,6 +101,7 @@ interface ServerBuildOptions {
|
|
|
92
101
|
readonly csp?: ServerCSPConfig;
|
|
93
102
|
readonly cacheControl?: ServerCacheControlConfig;
|
|
94
103
|
readonly cache?: ServerCacheConfig;
|
|
104
|
+
readonly action?: ServerActionConfig;
|
|
95
105
|
readonly jsPoolSize?: number;
|
|
96
106
|
readonly htmlLimitedBots?: string;
|
|
97
107
|
readonly moduleAnalysisCache?: ModuleAnalysisCache;
|
|
@@ -270,10 +280,17 @@ interface RariOptions {
|
|
|
270
280
|
readonly connectSrc?: readonly string[];
|
|
271
281
|
readonly defaultSrc?: readonly string[];
|
|
272
282
|
readonly workerSrc?: readonly string[];
|
|
283
|
+
readonly frameAncestors?: readonly string[];
|
|
284
|
+
readonly baseUri?: readonly string[];
|
|
285
|
+
readonly formAction?: readonly string[];
|
|
286
|
+
readonly useNonces?: boolean;
|
|
273
287
|
};
|
|
274
288
|
readonly cacheControl?: {
|
|
275
289
|
readonly routes: Readonly<Record<string, string>>;
|
|
276
290
|
};
|
|
291
|
+
readonly action?: {
|
|
292
|
+
readonly allowedOrigins?: readonly string[];
|
|
293
|
+
};
|
|
277
294
|
readonly jsPoolSize?: number;
|
|
278
295
|
readonly htmlLimitedBots?: string;
|
|
279
296
|
readonly cache?: ServerCacheConfig;
|
|
@@ -291,4 +308,4 @@ declare function defineRariConfig(config: UserConfig & {
|
|
|
291
308
|
type Request = globalThis.Request;
|
|
292
309
|
type Response = globalThis.Response;
|
|
293
310
|
//#endregion
|
|
294
|
-
export { ApiResponse, type ApiRouteHandlers, type AppRouteEntry, type AppRouteManifest, type AppRouteMatch, type CookieOptions, type ErrorEntry, type ErrorProps, type GenerateMetadata, type GenerateStaticParams, type LayoutEntry, type LayoutProps, type LoadingEntry, type Metadata, type MetadataResult, type NotFoundEntry, type PageProps, type ProxyConfig, type ProxyFunction, type ProxyMatcher, type ProxyModule, type ProxyPluginOptions, type ProxyResult, type RariFetchEvent, RariOptions, type RariPlugin, type RariURL, Request, type RequestCookies, Response, type ResponseCookies, type Robots, type RobotsRule, type RouteContext, type RouteHandler, type RouteSegment, type RouteSegmentType, RouterPluginOptions, type ServerCSPConfig, type ServerCacheConfig, type ServerCacheControlConfig, type ServerCacheLayerConfig, type ServerConfig, type ServerSidePropsResult, type ServerUseCacheConfig, type Sitemap, type SitemapEntry, type SitemapImage, type SitemapVideo, type StaticParamsResult, type TemplateEntry, clearPropsCache, clearPropsCacheForComponent, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, rari, rariProxy, rariRouter };
|
|
311
|
+
export { ApiResponse, type ApiRouteHandlers, type AppRouteEntry, type AppRouteManifest, type AppRouteMatch, type CookieOptions, type ErrorEntry, type ErrorProps, type GenerateMetadata, type GenerateStaticParams, type LayoutEntry, type LayoutProps, type LoadingEntry, type Metadata, type MetadataResult, type NotFoundEntry, type PageProps, type ProxyConfig, type ProxyFunction, type ProxyMatcher, type ProxyModule, type ProxyPluginOptions, type ProxyResult, type RariFetchEvent, RariOptions, type RariPlugin, type RariURL, Request, type RequestCookies, Response, type ResponseCookies, type Robots, type RobotsRule, type RouteContext, type RouteHandler, type RouteSegment, type RouteSegmentType, RouterPluginOptions, type ServerActionConfig, type ServerCSPConfig, type ServerCacheConfig, type ServerCacheControlConfig, type ServerCacheLayerConfig, type ServerConfig, type ServerSidePropsResult, type ServerUseCacheConfig, type Sitemap, type SitemapEntry, type SitemapImage, type SitemapVideo, type StaticParamsResult, type TemplateEntry, clearPropsCache, clearPropsCacheForComponent, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, rari, rariProxy, rariRouter };
|
package/dist/vite.mjs
CHANGED
|
@@ -44,7 +44,7 @@ ${e.map(e=>` { name: ${JSON.stringify(e.name)}, component: ${e.binding}, id: ${
|
|
|
44
44
|
`)},
|
|
45
45
|
])
|
|
46
46
|
`}function It(e,t){return{componentsDir:t?.componentsDir??`src/components`,contentDirs:t?.contentDirs??[`public/content`,`content`]}}function Lt(e,t,n){let r=j.join(e,t),i=new Set(n);return k.existsSync(r)&&i.add(r),[...i]}const Rt=/import\s*\(\s*["']([^"']+)["']\s*\)|import\s+["']([^"']+)["']/g,zt=/<script\b[^>]*>/gi;function Bt(e,t,n){n?.startsWith(`/src/`)&&e.add(Y(j.join(t,n.slice(1))))}function Vt(e){return/\btype\s*=\s*["']module["']/i.test(e)?/\bsrc\s*=\s*["']([^"']+)["']/i.exec(e)?.[1]??null:null}function Ht(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(Rt))Bt(t,e,n[1]||n[2]);for(let n of r.matchAll(zt))Bt(t,e,Vt(n[0]))}catch{}return t}let X;async function Ut(){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 Wt=/import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g,Gt=/import\s+(?:(\w+)|\{([^}]+)\})\s+from\s+['"]([^'"]+)['"];?\s*$/gm,Kt=/^proxy\.(?:tsx?|jsx?|mts|mjs)$/,qt=/\/components\/(\w+)(?:\.tsx?|\.jsx?)?$/,Jt=/[/\\]components[/\\](\w+)(?:\.tsx?|\.jsx?)?$/,Yt=/^(?:robots|sitemap|feed)\.(?:tsx?|jsx?)$/,Xt=`react-server-dom-rari/server`,Zt=/^node:/,Qt=`[hash]_[local]`;function $t(e){if(e.startsWith(`@`)){let t=e.split(`/`);return t.length>=2?`${t[0]}/${t[1]}`:e}return e.split(`/`)[0]??e}function en(e,t){let n=$t(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 tn=[{componentId:`rari/image`,devSourceSegments:[`src`,`image`,`image.tsx`],publishedExport:`rari/image`,exports:[`Image`]}],nn=j.dirname(N(import.meta.url)),Z=j.dirname(nn);function rn(e){return e.startsWith(Z)}function an(e,t){return rn(e)?j.join(Z,`src`):j.join(t,`src`)}function on(){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 sn(e){let t=e.replace(b,`/`);return t.includes(`ErrorBoundaryWrapper`)||t.includes(`/boundaries/error-boundary-wrapper`)||t.endsWith(`/error-boundary-wrapper.tsx`)}function cn(e,t){if(sn(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 ln(e,t){if(sn(e))return`error_boundary_wrapper_${R(`virtual:error-boundary-wrapper.tsx`)}`;if(rn(e)){let t=j.relative(Z,e).replace(b,`/`);return`${Ge(t)}_${R(t)}`}return B(e,t)}let un=null;async function dn(){return un||=(await import(`lightningcss`)).transform,un}function fn(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 pn=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(`
|
|
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 xt;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,jsPoolSize:t.jsPoolSize,htmlLimitedBots:t.htmlLimitedBots,experimental:t.experimental,mdx:t.mdx},this.parseHtmlImports()}parseHtmlImports(){for(let e of Ht(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 vt(n.importSources)){let n=this.resolveImportedFilePath(t,e);n
|
|
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 xt;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 Ht(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 vt(n.importSources)){let n=this.resolveImportedFilePath(t,e);n!=null&&n!==``&&(this.fileImporters.has(n)||this.fileImporters.set(n,new Set),this.fileImporters.get(n).add(t))}}buildImportGraph(e){let t=mn(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=_t(i.importSources),o=gt(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 _t((t!=null&&t!==``?this.moduleAnalysisCache.get(t,e):q(e)).importSources)}hasNodeImports(e,t){return gt(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(Wt)){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=qt.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
48
|
const ${r} = (props) => {
|
|
49
49
|
let Component = globalThis['~clientComponents']?.['components/${i}']?.component
|
|
50
50
|
|| globalThis['components/${i}'];
|
|
@@ -82,7 +82,7 @@ const ${r} = (props) => {
|
|
|
82
82
|
return Component(props);
|
|
83
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=Kt.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`)||rn(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(Xt)};
|
|
84
84
|
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.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(`
|
|
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(`
|
|
86
86
|
`)}\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
87
|
`;i+=`import { callServer } from 'rari/runtime/call-server';
|
|
88
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=an(e,s),l=e=>this.generateServerActionReferenceModule(e),u=e=>this.isServerActionFile(e),d=(await I({input:o,platform:`node`,write:!1,external:[Zt,`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:[Zt,`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=tn.map(e=>e.componentId);for(Gt.lastIndex=0;r=Gt.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(
|
|
@@ -134,7 +134,7 @@ if (import.meta.hot) {
|
|
|
134
134
|
|
|
135
135
|
${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
136
|
`),u=t,d=!1,p=!1,h=n.includes(`entry-client`);for(let e of l){let t=e.match(yn),r=t?null:or.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=bn(t[1],o);u=u.replace(n,e),d=!0,p=!0;continue}let r=hr(e,i);if(r.length===0)continue;let a=gr(r,o);u=u.replace(n,a),d=!0,p=!0}}if(d){let e=u.includes(`import React`)||sr.test(u)||cr.test(u),t=``;if(p&&!e&&(t+=`import React from 'react';
|
|
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,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}": {
|
|
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}": {
|
|
138
138
|
id: "${n}",
|
|
139
139
|
path: "${r}",
|
|
140
140
|
exportName: "${s}",
|
|
@@ -198,4 +198,4 @@ export function createFromReadableStream(stream, options) {
|
|
|
198
198
|
export const createServerReference = module.exports.createServerReference;
|
|
199
199
|
export const encodeReply = module.exports.encodeReply;
|
|
200
200
|
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(ur)){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 Dr(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}}},vn({...e.serverBuild,csp:e.csp,cacheControl:e.cacheControl,cache:e.cache,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(He(e.router??{})),fe(I)}function Ar(e){return{...e,plugins:[kr(),...e.plugins??[]]}}export{e as ApiResponse,Hn as clearPropsCache,Un as clearPropsCacheForComponent,Ar as defineRariConfig,Or as defineRariOptions,Rn as extractMetadata,Ln as extractServerProps,Vn as extractServerPropsWithCache,zn as extractStaticParams,De as generateAppRouteManifest,Bn as hasServerSideDataFetching,kr as rari,me as rariProxy,He as rariRouter};
|
|
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(ur)){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 Dr(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}}},vn({...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(He(e.router??{})),fe(I)}function Ar(e){return{...e,plugins:[kr(),...e.plugins??[]]}}export{e as ApiResponse,Hn as clearPropsCache,Un as clearPropsCacheForComponent,Ar as defineRariConfig,Or as defineRariOptions,Rn as extractMetadata,Ln as extractServerProps,Vn as extractServerPropsWithCache,zn as extractStaticParams,De as generateAppRouteManifest,Bn as hasServerSideDataFetching,kr as rari,me as rariProxy,He 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.6",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
],
|
|
39
39
|
"exports": {
|
|
40
40
|
".": {
|
|
41
|
-
"node": "./dist/index.mjs",
|
|
42
41
|
"types": "./dist/index.d.mts",
|
|
42
|
+
"node": "./dist/index.mjs",
|
|
43
43
|
"default": "./dist/index.mjs"
|
|
44
44
|
},
|
|
45
45
|
"./image": {
|
|
@@ -145,13 +145,13 @@
|
|
|
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.6",
|
|
149
|
+
"rari-darwin-arm64": "0.15.6",
|
|
150
|
+
"rari-darwin-x64": "0.15.6",
|
|
151
|
+
"rari-linux-arm64": "0.15.6",
|
|
152
|
+
"rari-linux-x64": "0.15.6",
|
|
153
|
+
"rari-win32-arm64": "0.15.6",
|
|
154
|
+
"rari-win32-x64": "0.15.6"
|
|
155
155
|
},
|
|
156
156
|
"devDependencies": {
|
|
157
157
|
"@mdx-js/mdx": "^3.1.1",
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
"@types/react-dom": "^19.2.3",
|
|
161
161
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
162
162
|
"typescript-7": "npm:typescript@^7.0.2",
|
|
163
|
-
"vite-plus": "^0.2.
|
|
163
|
+
"vite-plus": "^0.2.6",
|
|
164
164
|
"@rari/deploy": "0.0.0",
|
|
165
165
|
"@rari/lint": "0.0.0",
|
|
166
166
|
"@rari/logger": "0.0.0"
|