@useavalon/avalon 0.1.31 → 0.1.33
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function createMDXPlugin(e={}){let{remarkPlugins:t=[],rehypePlugins:n=[],development:r=!1,jsxImportSource:i=`preact`,syntaxHighlighting:a=!0}=e;try{let{default:e}=await import(`@mdx-js/rollup`),{default:o}=await import(`remark-frontmatter`),{default:s}=await import(`remark-mdx-frontmatter`),{default:c}=await import(`remark-gfm`),l=[];if(a)try{let{default:e}=await import(`rehype-highlight`);l.push(e)}catch{console.warn(`[avalon:mdx] rehype-highlight not installed, syntax highlighting disabled. Install it with: npm install rehype-highlight`)}
|
|
1
|
+
export async function createMDXPlugin(e={}){let{remarkPlugins:t=[],rehypePlugins:n=[],development:r=!1,jsxImportSource:i=`preact`,syntaxHighlighting:a=!0}=e;try{let{default:e}=await import(`@mdx-js/rollup`),{default:o}=await import(`remark-frontmatter`),{default:s}=await import(`remark-mdx-frontmatter`),{default:c}=await import(`remark-gfm`),l=[];if(a)try{let{default:e}=await import(`rehype-highlight`);l.push(e)}catch{console.warn(`[avalon:mdx] rehype-highlight not installed, syntax highlighting disabled. Install it with: npm install rehype-highlight`)}l.push(...n);let u=e({remarkPlugins:[o,s,c,...t],rehypePlugins:l,jsxImportSource:i,development:r,format:`mdx`});return u.sharedDuringBuild=!0,[u]}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(`❌ Failed to configure MDX plugin:`,t),console.warn(`💡 Install missing dependencies or check import map`),console.warn(`⚠️ MDX plugin disabled - .mdx files will not be processed`),[]}}
|
|
@@ -11,12 +11,14 @@ import type { ResolvedAvalonConfig } from './types.ts';
|
|
|
11
11
|
import { type AvalonNitroConfig, type NitroConfigOutput } from '../nitro/config.ts';
|
|
12
12
|
export declare const VIRTUAL_MODULE_IDS: {
|
|
13
13
|
readonly PAGE_ROUTES: "virtual:avalon/page-routes";
|
|
14
|
+
readonly PAGE_LOADER: "virtual:avalon/page-loader";
|
|
14
15
|
readonly ISLAND_MANIFEST: "virtual:avalon/island-manifest";
|
|
15
16
|
readonly RUNTIME_CONFIG: "virtual:avalon/runtime-config";
|
|
16
17
|
readonly CONFIG: "virtual:avalon/config";
|
|
17
18
|
};
|
|
18
19
|
export declare const RESOLVED_VIRTUAL_IDS: {
|
|
19
20
|
readonly PAGE_ROUTES: string;
|
|
21
|
+
readonly PAGE_LOADER: string;
|
|
20
22
|
readonly ISLAND_MANIFEST: string;
|
|
21
23
|
readonly RUNTIME_CONFIG: string;
|
|
22
24
|
readonly CONFIG: string;
|
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import{nitro as e}from"nitro/vite";import{stat as t}from"node:fs/promises";import{existsSync as n}from"node:fs";import{createRequire as r}from"node:module";import{dirname as i,join as a}from"node:path";import{createNitroConfig as o}from"../nitro/config.js";import{createNitroBuildPlugin as s,createIslandManifestPlugin as c,createSourceMapPlugin as l,createSourceMapConfig as u}from"../nitro/index.js";import{discoverScopedMiddleware as d,executeScopedMiddleware as f,clearMiddlewareCache as p}from"../middleware/index.js";import{generateErrorPage as m,generateFallback404 as h}from"../render/error-pages.js";import{collectCssFromModuleGraph as g,injectSsrCss as _}from"../render/collect-css.js";import{getUniversalCSSForHead as v}from"../islands/universal-css-collector.js";import{getUniversalHeadForInjection as y}from"../islands/universal-head-collector.js";function b(e){let t=a(i(r(import.meta.url).resolve(`@useavalon/avalon`)),e);if(e.endsWith(`.ts`)&&!n(t)){let e=t.replace(/\.ts$/,`.js`);if(n(e))return e}return t}function x(e,t){let o=a(i(r(a(process.cwd(),`package.json`)).resolve(`@useavalon/${e}`)),t);if(t.endsWith(`.ts`)&&!n(o)){let e=o.replace(/\.ts$/,`.js`);if(n(e))return e}return o}export const VIRTUAL_MODULE_IDS={PAGE_ROUTES:`virtual:avalon/page-routes`,ISLAND_MANIFEST:`virtual:avalon/island-manifest`,RUNTIME_CONFIG:`virtual:avalon/runtime-config`,CONFIG:`virtual:avalon/config`};export const RESOLVED_VIRTUAL_IDS={PAGE_ROUTES:`\0`+VIRTUAL_MODULE_IDS.PAGE_ROUTES,ISLAND_MANIFEST:`\0`+VIRTUAL_MODULE_IDS.ISLAND_MANIFEST,RUNTIME_CONFIG:`\0`+VIRTUAL_MODULE_IDS.RUNTIME_CONFIG,CONFIG:`\0`+VIRTUAL_MODULE_IDS.CONFIG};export function createNitroIntegration(t,n={}){let r=o(n,t),i={preset:r.preset,serverDir:n.serverDir??r.serverDir??`./server`,routeRules:r.routeRules,runtimeConfig:r.runtimeConfig,renderer:n.renderer===!1?!1:r.renderer,compatibilityDate:r.compatibilityDate,scanDirs:[`.`]};r.publicRuntimeConfig&&(i.publicRuntimeConfig=r.publicRuntimeConfig),r.publicAssets&&(i.publicAssets=r.publicAssets),r.compressPublicAssets&&(i.compressPublicAssets=r.compressPublicAssets),r.serverEntry&&(i.serverEntry=r.serverEntry);let a=e(i),d=createNitroCoordinationPlugin({avalonConfig:t,nitroConfig:n,verbose:t.verbose}),f=createVirtualModulesPlugin({avalonConfig:t,nitroConfig:n,verbose:t.verbose}),p=s(t,n),m=c(t,{verbose:t.verbose,generatePreloadHints:!0}),h=l(u(n.preset??`node_server`,t.isDev));return{nitroOptions:r,plugins:[...Array.isArray(a)?a:[a],d,f,p,m,h]}}export function createNitroCoordinationPlugin(e){let{avalonConfig:t,verbose:n}=e;return{name:`avalon:nitro-coordination`,enforce:`pre`,configResolved(e){globalThis.__avalonConfig=t},configureServer(e){globalThis.__viteDevServer=e;let r=null;async function i(){return r||=await d({baseDir:`${e.config.root||process.cwd()}/src`,devMode:!1}),r}function a(){r=null}A(e,t,n,a),i().catch(e=>{console.warn(`[middleware] Failed to discover middleware:`,e)}),O(e,t.integrations,n).catch(e=>{console.error(`[prewarm] Core modules pre-warm failed:`,e)}),e.middlewares.use(async(r,a,o)=>{let s=r.url||`/`;if(s.endsWith(`.html`)&&(s=s.slice(0,-5)||`/`),s===`/index`&&(s=`/`),s.startsWith(`/@`)||s.startsWith(`/__`)||s.startsWith(`/node_modules/`)||s.startsWith(`/src/client/`)||s.startsWith(`/packages/`)||s.includes(`.`)&&!s.endsWith(`/`)||s.startsWith(`/api/`))return o();try{if(await E(e,s,r,a,i,n)||await
|
|
1
|
+
import{nitro as e}from"nitro/vite";import{stat as t}from"node:fs/promises";import{existsSync as n}from"node:fs";import{createRequire as r}from"node:module";import{dirname as i,join as a}from"node:path";import{createNitroConfig as o}from"../nitro/config.js";import{createNitroBuildPlugin as s,createIslandManifestPlugin as c,createSourceMapPlugin as l,createSourceMapConfig as u}from"../nitro/index.js";import{discoverScopedMiddleware as d,executeScopedMiddleware as f,clearMiddlewareCache as p}from"../middleware/index.js";import{generateErrorPage as m,generateFallback404 as h}from"../render/error-pages.js";import{collectCssFromModuleGraph as g,injectSsrCss as _}from"../render/collect-css.js";import{getUniversalCSSForHead as v}from"../islands/universal-css-collector.js";import{getUniversalHeadForInjection as y}from"../islands/universal-head-collector.js";function b(e){let t=a(i(r(import.meta.url).resolve(`@useavalon/avalon`)),e);if(e.endsWith(`.ts`)&&!n(t)){let e=t.replace(/\.ts$/,`.js`);if(n(e))return e}return t}function x(e,t){let o=a(i(r(a(process.cwd(),`package.json`)).resolve(`@useavalon/${e}`)),t);if(t.endsWith(`.ts`)&&!n(o)){let e=o.replace(/\.ts$/,`.js`);if(n(e))return e}return o}export const VIRTUAL_MODULE_IDS={PAGE_ROUTES:`virtual:avalon/page-routes`,PAGE_LOADER:`virtual:avalon/page-loader`,ISLAND_MANIFEST:`virtual:avalon/island-manifest`,RUNTIME_CONFIG:`virtual:avalon/runtime-config`,CONFIG:`virtual:avalon/config`};export const RESOLVED_VIRTUAL_IDS={PAGE_ROUTES:`\0`+VIRTUAL_MODULE_IDS.PAGE_ROUTES,PAGE_LOADER:`\0`+VIRTUAL_MODULE_IDS.PAGE_LOADER,ISLAND_MANIFEST:`\0`+VIRTUAL_MODULE_IDS.ISLAND_MANIFEST,RUNTIME_CONFIG:`\0`+VIRTUAL_MODULE_IDS.RUNTIME_CONFIG,CONFIG:`\0`+VIRTUAL_MODULE_IDS.CONFIG};export function createNitroIntegration(t,n={}){let r=o(n,t),i={preset:r.preset,serverDir:n.serverDir??r.serverDir??`./server`,routeRules:r.routeRules,runtimeConfig:r.runtimeConfig,renderer:n.renderer===!1?!1:r.renderer,compatibilityDate:r.compatibilityDate,scanDirs:[`.`]};r.publicRuntimeConfig&&(i.publicRuntimeConfig=r.publicRuntimeConfig),r.publicAssets&&(i.publicAssets=r.publicAssets),r.compressPublicAssets&&(i.compressPublicAssets=r.compressPublicAssets),r.serverEntry&&(i.serverEntry=r.serverEntry);let a=e(i),d=createNitroCoordinationPlugin({avalonConfig:t,nitroConfig:n,verbose:t.verbose}),f=createVirtualModulesPlugin({avalonConfig:t,nitroConfig:n,verbose:t.verbose}),p=s(t,n),m=c(t,{verbose:t.verbose,generatePreloadHints:!0}),h=l(u(n.preset??`node_server`,t.isDev));return{nitroOptions:r,plugins:[...Array.isArray(a)?a:[a],d,f,p,m,h]}}export function createNitroCoordinationPlugin(e){let{avalonConfig:t,verbose:n}=e;return{name:`avalon:nitro-coordination`,enforce:`pre`,configResolved(e){globalThis.__avalonConfig=t},configureServer(e){globalThis.__viteDevServer=e;let r=null;async function i(){return r||=await d({baseDir:`${e.config.root||process.cwd()}/src`,devMode:!1}),r}function a(){r=null}A(e,t,n,a),i().catch(e=>{console.warn(`[middleware] Failed to discover middleware:`,e)}),O(e,t.integrations,n).catch(e=>{console.error(`[prewarm] Core modules pre-warm failed:`,e)}),e.middlewares.use(async(r,a,o)=>{let s=r.url||`/`;if(s.endsWith(`.html`)&&(s=s.slice(0,-5)||`/`),s===`/index`&&(s=`/`),s.startsWith(`/@`)||s.startsWith(`/__`)||s.startsWith(`/node_modules/`)||s.startsWith(`/src/client/`)||s.startsWith(`/packages/`)||s.includes(`.`)&&!s.endsWith(`/`)||s.startsWith(`/api/`))return o();try{if(await E(e,s,r,a,i,n)||await R(e,s,t,a))return;let o=await z(e,s,t);if(o){a.statusCode=200,a.setHeader(`Content-Type`,`text/html`),a.end(o);return}await D(e,s,a,t)}catch(e){console.error(`[SSR Error]`,e),a.statusCode=500,a.setHeader(`Content-Type`,`text/html`),a.end(m(e))}})},buildStart(){}}}async function E(e,t,n,r,i,a){let o=performance.now(),s=await i();if(s.length===0)return!1;let c={};for(let[e,t]of Object.entries(n.headers))typeof t==`string`?c[e]=t:Array.isArray(t)&&(c[e]=t.join(`, `));let l=`http://${n.headers.host||`localhost`}${t}`,u=await f({url:l,method:n.method||`GET`,path:t,node:{req:n,res:r},req:new Request(l,{method:n.method||`GET`,headers:c}),context:{}},s,{devMode:!1}),d=performance.now()-o;return d>100&&console.warn(`⚠️ Slow middleware: ${d.toFixed(0)}ms for ${t}`),u?(r.statusCode=u.status,u.headers.forEach((e,t)=>{r.setHeader(t,e)}),r.end(await u.text()),!0):!1}async function D(e,t,n,r){try{let{discoverErrorPages:i,getErrorPageModule:a,generateDefaultErrorPage:o}=await import(`../nitro/error-handler.js`),s=a(404,await i({isDev:r.isDev,pagesDir:r.pagesDir,loadPageModule:async t=>await e.ssrLoadModule(t)}));if(s?.default&&typeof s.default==`function`){let{renderToHtml:e}=await import(`../render/ssr.js`),r=s.default,i=await e({component:()=>r({statusCode:404,message:`Page not found: ${t}`,url:t})},{});n.statusCode=404,n.setHeader(`Content-Type`,`text/html`),n.end(i);return}let c=o(404,`Page not found: ${t}`,r.isDev);n.statusCode=404,n.setHeader(`Content-Type`,`text/html`),n.end(c)}catch{n.statusCode=404,n.setHeader(`Content-Type`,`text/html`),n.end(h(t))}}async function O(e,t,n){let r=performance.now(),i=[{path:b(`src/render/ssr.ts`),assignTo:`ssr`},{path:b(`src/core/layout/enhanced-layout-resolver.ts`),assignTo:`layout`},{path:b(`src/middleware/index.ts`),assignTo:null},...t.map(e=>({path:x(e,`server/renderer.ts`),assignTo:null}))],a=(await Promise.allSettled(i.map(async({path:t,assignTo:n})=>{let r=await e.ssrLoadModule(t);n===`ssr`&&(I=r),n===`layout`&&(L=r)}))).filter(e=>e.status===`fulfilled`).length,o=performance.now()-r;n&&a>0&&console.log(`🔥 SSR ready in ${o.toFixed(0)}ms (${a}/${i.length} core modules)`)}export function createVirtualModulesPlugin(e){let{avalonConfig:t,nitroConfig:n,verbose:r}=e;return{name:`avalon:nitro-virtual-modules`,enforce:`pre`,resolveId(e){return e===VIRTUAL_MODULE_IDS.PAGE_ROUTES?RESOLVED_VIRTUAL_IDS.PAGE_ROUTES:e===VIRTUAL_MODULE_IDS.PAGE_LOADER?RESOLVED_VIRTUAL_IDS.PAGE_LOADER:e===VIRTUAL_MODULE_IDS.ISLAND_MANIFEST?RESOLVED_VIRTUAL_IDS.ISLAND_MANIFEST:e===VIRTUAL_MODULE_IDS.RUNTIME_CONFIG?RESOLVED_VIRTUAL_IDS.RUNTIME_CONFIG:e===VIRTUAL_MODULE_IDS.CONFIG?RESOLVED_VIRTUAL_IDS.CONFIG:null},async load(e){return e===RESOLVED_VIRTUAL_IDS.PAGE_ROUTES?await j(t,r):e===RESOLVED_VIRTUAL_IDS.PAGE_LOADER?await M(t,r):e===RESOLVED_VIRTUAL_IDS.ISLAND_MANIFEST?N():e===RESOLVED_VIRTUAL_IDS.RUNTIME_CONFIG?P(t,n):e===RESOLVED_VIRTUAL_IDS.CONFIG?generateConfigModule(t,n):null},handleHotUpdate({file:e,server:n}){if(e.includes(t.pagesDir)){let e=n.moduleGraph.getModuleById(RESOLVED_VIRTUAL_IDS.PAGE_ROUTES);e&&n.moduleGraph.invalidateModule(e)}if(e.includes(`vite.config`)||e.includes(`avalon.config`)||e.includes(`nitro.config`)){let e=n.moduleGraph.getModuleById(RESOLVED_VIRTUAL_IDS.CONFIG);e&&n.moduleGraph.invalidateModule(e)}}}}function A(e,t,n,r){e.watcher.on(`change`,e=>{e.includes(`_middleware`)&&(p(),r?.()),(e.includes(`/render/`)||e.includes(`/layout/`)||e.includes(`/islands/`))&&(I=null,L=null),(e.includes(`/layouts/`)||e.includes(`_layout`))&&globalThis.__avalonLayoutResolver?.clearCache?.()}),e.watcher.on(`add`,e=>{e.includes(`_middleware`)&&(p(),r?.())}),e.watcher.on(`unlink`,e=>{e.includes(`_middleware`)&&(p(),r?.())})}async function j(e,t){try{let{getAllPageDirs:t}=await import(`./module-discovery.js`),{discoverPageRoutesFromMultipleDirs:n}=await import(`../nitro/route-discovery.js`),r=await n(await t(e.pagesDir,e.modules,process.cwd()),{developmentMode:e.isDev});return`export const pageRoutes = ${JSON.stringify(r,null,2)};\nexport default pageRoutes;\n`}catch{return`export const pageRoutes = [];
|
|
2
2
|
export default pageRoutes;
|
|
3
|
-
`}}function M(){
|
|
3
|
+
`}}async function M(e,t){try{let{getAllPageDirs:t}=await import(`./module-discovery.js`),{discoverPageRoutesFromMultipleDirs:n,matchRoutePattern:r}=await import(`../nitro/route-discovery.js`),i=await n(await t(e.pagesDir,e.modules,process.cwd()),{developmentMode:e.isDev}),a=[],o=[];for(let e=0;e<i.length;e++){let t=i[e],n=`page_${e}`,r=t.filePath.replaceAll(`\\`,`/`);a.push(`import * as ${n} from '/${r}';`),o.push(` { pattern: ${JSON.stringify(t.pattern)}, params: ${JSON.stringify(t.params)}, module: ${n} }`)}return[...a,``,`const routes = [`,o.join(`,
|
|
4
|
+
`),`];`,``,`/**`,` * Match a pathname against discovered routes and return the page module.`,` * Uses the same pattern matching as Avalon's route discovery.`,` */`,`export function loadPage(pathname) {`,` const cleanPath = pathname.split('?')[0];`,` for (const route of routes) {`,` if (matchRoute(cleanPath, route.pattern, route.params)) {`,` return route.module;`,` }`,` }`,` return null;`,`}`,``,`function matchRoute(pathname, pattern, paramNames) {`,` // Exact match`,` if (pattern === pathname) return true;`,` // Normalize trailing slashes`,` const normPath = pathname === '/' ? '/' : pathname.replace(/\\/$/, '');`,` const normPattern = pattern === '/' ? '/' : pattern.replace(/\\/$/, '');`,` if (normPath === normPattern) return true;`,` // Dynamic segments: /users/:id matches /users/123`,` if (paramNames.length > 0) {`,` const patternParts = normPattern.split('/');`,` const pathParts = normPath.split('/');`,` if (patternParts.length !== pathParts.length) return false;`,` return patternParts.every((part, i) => part.startsWith(':') || part === pathParts[i]);`,` }`,` return false;`,`}`,``,`export default { loadPage, routes };`,``].join(`
|
|
5
|
+
`)}catch(e){return console.error(`[page-loader] Failed to generate page loader:`,e),`export function loadPage() { return null; }
|
|
6
|
+
export default { loadPage, routes: [] };
|
|
7
|
+
`}}function N(){return`export const islandManifest = { islands: {}, clientEntry: "", css: [] };
|
|
4
8
|
export default islandManifest;
|
|
5
|
-
`}function
|
|
9
|
+
`}function P(e,t){let n={avalon:{streaming:t.streaming??!0,pagesDir:e.pagesDir,layoutsDir:e.layoutsDir,isDev:e.isDev},...t.runtimeConfig};return`export const runtimeConfig = ${JSON.stringify(n,null,2)};\nexport function useRuntimeConfig() { return runtimeConfig; }\nexport default runtimeConfig;\n`}export function generateConfigModule(e,t){let n={streaming:t.streaming??!0,pagesDir:e.pagesDir,layoutsDir:e.layoutsDir,isDev:e.isDev,...t.runtimeConfig};return`const config = ${JSON.stringify(n,null,2)};\nexport function useAvalonConfig() { return config; }\nexport default config;\n`}export function getViteDevServer(){return globalThis.__viteDevServer}export function getAvalonConfig(){return globalThis.__avalonConfig}export function isDevelopmentMode(){return globalThis.__avalonConfig?.isDev??!0}const F=`<!--AVALON_STREAM_BOUNDARY-->`;let I=null,L=null;async function R(e,t,n,r){if(!n.modules)return!1;let i=t.split(`?`)[0],a=await U(i,n,e);if(!a)return!1;try{let t=await e.ssrLoadModule(a),n=t.default;if(!n)return!1;let o=t.layoutConfig,s=await g(e,a),c=await H(i,e),l=[];for(let t of c){let n=await e.ssrLoadModule(t);l.push({file:t,module:n})}for(let t of c){let n=await g(e,t);s.push(...n)}if(l.length===0)return!1;let{render:u}=await e.ssrLoadModule(`preact-render-to-string`),{h:d}=await e.ssrLoadModule(`preact`),f=o?.skipLayouts||[],p=l.filter(({file:e})=>{let t=e.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``;return!f.includes(t)}),m=t.frontmatter,h=t.metadata,_={children:null,frontmatter:{...m,...h,currentPath:i},params:{},url:i},b=[],x=[];for(let e of p){let t=e.module.default;if(!(!t||typeof t!=`function`))try{let n=t({..._,children:d(`div`,null,`test`)}),r=u(n instanceof Promise?await n:n);r.trim().startsWith(`<html`)||r.includes(`<!DOCTYPE`)?b.push(e):x.push(e)}catch{x.push(e)}}if(b.length===0)return!1;let{module:S}=b[b.length-1],C=S.default;if(!C||typeof C!=`function`)return!1;let w;try{let e=C({..._,children:d(`div`,{dangerouslySetInnerHTML:{__html:F}})});w=u(e instanceof Promise?await e:e)}catch{return!1}let T=w.indexOf(F);if(T===-1)return!1;let E=w.slice(0,T),D=w.slice(T+29),O=E;if(s.length>0){let e=`<style data-avalon-ssr-css>${s.join(`
|
|
6
10
|
`)}</style>`;O=E.includes(`</head>`)?E.replace(`</head>`,`${e}\n</head>`):E+e}O.trim().toLowerCase().startsWith(`<!doctype`)||(O=`<!DOCTYPE html>
|
|
7
11
|
`+O);let k=v(!0);k&&O.includes(`</head>`)&&(O=O.replace(`</head>`,`${k}\n</head>`));let A=y(!0);A&&O.includes(`</head>`)&&(O=O.replace(`</head>`,`${A}\n</head>`)),r.statusCode=200,r.setHeader(`Content-Type`,`text/html; charset=utf-8`),r.setHeader(`Transfer-Encoding`,`chunked`),r.setHeader(`X-Avalon-Streaming`,`1`),r.flushHeaders(),r.write(O);let j;try{let e=typeof n==`function`?n():n;j=u(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR Streaming] Error rendering page component:`,e),j=`<div>Error rendering page</div>`}if(j.trim().startsWith(`<!DOCTYPE html>`)||j.trim().startsWith(`<html`))return r.end(j),!0;let M=j;for(let{module:e}of x){let t=e.default;if(!(!t||typeof t!=`function`))try{let e=t({..._,children:d(`div`,{dangerouslySetInnerHTML:{__html:M}})});M=u(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR Streaming] Error rendering wrapper layout:`,e)}}let N=M+D;if(!N.includes(`/src/client/main.js`)&&!N.includes(`/@vite/client`)){let e=N.lastIndexOf(`</body>`);e!==-1&&(N=N.slice(0,e)+`
|
|
8
12
|
<script type="module" src="/@vite/client"><\/script>
|
|
9
13
|
<script type="module" src="/src/client/main.js"><\/script>
|
|
10
|
-
`+N.slice(e))}return r.end(N),!0}catch(e){return r.headersSent?(r.end(`<div>Streaming SSR error: ${e.message}</div></body></html>`),!0):!1}}async function
|
|
14
|
+
`+N.slice(e))}return r.end(N),!0}catch(e){return r.headersSent?(r.end(`<div>Streaming SSR error: ${e.message}</div></body></html>`),!0):!1}}async function z(e,t,n){let r=t.split(`?`)[0],i=await U(r,n,e);if(!i)return null;try{let t=await e.ssrLoadModule(i),a=t.default;if(!a)return console.warn(`[SSR] Page ${i} has no default export`),null;let o=await g(e,i),s=await H(r,e),c=[];for(let t of s){let n=await e.ssrLoadModule(t);c.push({file:t,module:n})}for(let t of s){let n=await g(e,t);o.push(...n)}let l;return l=n.modules&&c.length>0?await B(a,t,c,r,n,e):await W(a,t,r,n,e),o.length>0&&(l=_(l,o)),l}catch(e){throw console.error(`[SSR] Error rendering ${i}:`,e),e}}async function B(e,t,n,r,i,a){let{render:o}=await a.ssrLoadModule(`preact-render-to-string`),{h:s}=await a.ssrLoadModule(`preact`),c=t.layoutConfig?.skipLayouts||[],l=n.filter(({file:e})=>{let t=e.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``;return!c.includes(t)}),u;try{let t=typeof e==`function`?e():e;u=o(t instanceof Promise?await t:t)}catch(e){console.error(`[SSR] Error rendering page component:`,e),u=`<div>Error rendering page</div>`}if(u.trim().startsWith(`<!DOCTYPE html>`)||u.trim().startsWith(`<html`))return V(u);let d=t.frontmatter,f=t.metadata,p={children:null,frontmatter:{...d,...f,currentPath:r},params:{},url:r},m=[],h=[];for(let e of l){let t=e.module.default;if(!(!t||typeof t!=`function`))try{let n=t({...p,children:s(`div`,null,`test`)}),r=o(n instanceof Promise?await n:n);r.trim().startsWith(`<html`)||r.includes(`<!DOCTYPE`)?m.push(e):h.push(e)}catch{h.push(e)}}let g=u;for(let{module:e}of h){let t=e.default;if(!(!t||typeof t!=`function`))try{let e=t({...p,children:s(`div`,{dangerouslySetInnerHTML:{__html:g}})});g=o(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR] Error rendering wrapper layout:`,e)}}if(m.length>0){let{module:e}=m[m.length-1],t=e.default;if(t&&typeof t==`function`)try{let e=t({...p,children:s(`div`,{dangerouslySetInnerHTML:{__html:g}})});g=o(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR] Error rendering shell layout:`,e)}}if(g.trim().startsWith(`<!DOCTYPE html>`)||g.trim().startsWith(`<html`))return V(g);let _=t.metadata||{},v=_.title||`Avalon App`,y=_.description||``;return`<!DOCTYPE html>
|
|
11
15
|
<html lang="en">
|
|
12
16
|
<head>
|
|
13
17
|
<meta charset="utf-8">
|
|
14
18
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
15
|
-
<title>${
|
|
16
|
-
${y?`<meta name="description" content="${
|
|
19
|
+
<title>${G(v)}</title>
|
|
20
|
+
${y?`<meta name="description" content="${G(y)}">`:``}
|
|
17
21
|
<script type="module" src="/@vite/client"><\/script>
|
|
18
22
|
</head>
|
|
19
23
|
<body>
|
|
20
24
|
${g}
|
|
21
25
|
<script type="module" src="/src/client/main.js"><\/script>
|
|
22
26
|
</body>
|
|
23
|
-
</html>`}function
|
|
27
|
+
</html>`}function V(e){let t=e;if(t.trim().toLowerCase().startsWith(`<!doctype`)||(t=`<!DOCTYPE html>
|
|
24
28
|
`+t),!t.includes(`data-universal-ssr="true"`)){let e=v(!0);e&&t.includes(`</head>`)&&(t=t.replace(`</head>`,`${e}\n</head>`))}let n=y(!0);if(n&&t.includes(`</head>`)&&(t=t.replace(`</head>`,`${n}\n</head>`)),t.includes(`/src/client/main.js`)||t.includes(`/@vite/client`))return t;let r=t.lastIndexOf(`</body>`);return r===-1?t+`
|
|
25
29
|
<script type="module" src="/@vite/client"><\/script>
|
|
26
30
|
<script type="module" src="/src/client/main.js"><\/script>`:t.slice(0,r)+`
|
|
27
31
|
<script type="module" src="/@vite/client"><\/script>
|
|
28
32
|
<script type="module" src="/src/client/main.js"><\/script>
|
|
29
|
-
`+t.slice(r)}async function
|
|
33
|
+
`+t.slice(r)}async function H(e,n){let r=n.config.root||process.cwd(),i=globalThis.__avalonConfig,a=`_layout.tsx`,o=[],s=e.split(`/`).filter(Boolean),c=[``];for(let e=0;e<s.length;e++)c.push(`/`+s.slice(0,e+1).join(`/`));async function l(e){try{if((await t(e)).isFile()){let t=e.slice(r.length);o.includes(t)||o.push(t)}}catch{}}if(i?.layoutsDir&&await l(`${`${r}/${i.layoutsDir}`}/${a}`),i?.modules){let e=`${r}/${i.modules.dir}`,t=i.modules.layoutsDirName,n=s[0]||``,o=[`home`,`root`,`main`,`index`];if(!n||o.includes(n.toLowerCase()))for(let n of o)await l(`${e}/${n}/${t}/${a}`);else await l(`${e}/${n}/${t}/${a}`)}let u=`${r}/src/layouts`;for(let e of c)await l(e===``?`${u}/${a}`:`${u}${e}/${a}`);return o}async function U(e,n,r){let i=e;i.endsWith(`/`)&&i!==`/`&&(i=i.slice(0,-1)),i===`/`&&(i=`/index`);let a=[`.tsx`,`.ts`,`.jsx`,`.js`,`.mdx`,`.md`],o=r.config.root||process.cwd();async function s(e){try{if((await t(`${o}/${e}`)).isFile())return`/${e}`}catch{}return null}if(n.modules){let t=n.modules.dir,r=n.modules.pagesDirName,o=e.split(`/`).filter(Boolean),c=o[0]||``,l=[`home`,`root`,`main`,`index`],u,d;if(!c||l.includes(c.toLowerCase()))u=`home`,d=i;else{u=c;let e=o.slice(1);d=e.length>0?`/`+e.join(`/`):`/index`}for(let e of a){let n=await s(`${t}/${u}/${r}${d}${e}`);if(n)return n}if(!d.endsWith(`/index`))for(let e of a){let n=await s(`${t}/${u}/${r}${d}/index${e}`);if(n)return n}}let c=n.pagesDir;for(let e of a){let t=await s(`${c}${i}${e}`);if(t)return t}if(!i.endsWith(`/index`))for(let e of a){let t=await s(`${c}${i}/index${e}`);if(t)return t}return null}async function W(e,t,n,r,i){let a=t.metadata||{};try{I||=await i.ssrLoadModule(b(`src/render/ssr.ts`));let o=I;L||=await i.ssrLoadModule(b(`src/core/layout/enhanced-layout-resolver.ts`));let s=L,c={component:()=>typeof e==`function`?e():e,options:{title:a.title||`Avalon App`},frontmatter:t.frontmatter};if(o.renderToHtmlWithLayouts&&s.EnhancedLayoutResolver&&s.EnhancedLayoutResolverUtils)try{let e=i.config.root||process.cwd();if(!globalThis.__avalonLayoutResolver){let t=s.EnhancedLayoutResolver,n=r.layoutsDir||`src/layouts`;globalThis.__avalonLayoutResolver=new t({baseDirectory:`${e}/${n}`,filePattern:`_layout.tsx`,excludeDirectories:[`node_modules`,`.git`,`dist`,`build`],enableWatching:!0,developmentMode:!1,enableCaching:!0,cacheTTL:60*1e3,maxCacheSize:100,enableStreaming:!0,enableErrorBoundaries:!0,enableMetrics:!1,enableDebugInfo:!1,modulesDir:r.modules?`${e}/${r.modules.dir}`:void 0,modulesLayoutsDirName:r.modules?.layoutsDirName})}let t=`http://localhost${n}`,l={params:{},query:{},url:t,request:{method:`GET`,url:t,headers:new Headers}};return await o.renderToHtmlWithLayouts(c,globalThis.__avalonLayoutResolver,l,n,{title:a.title||`Avalon App`},void 0,{suppressWarnings:!0})}catch{}if(o.renderToHtml)return await o.renderToHtml(c,{title:a.title||`Avalon App`},void 0,{suppressWarnings:!0})}catch{}let o=a.title||`Avalon App`,s=a.description||``,c=``;try{let t=await i.ssrLoadModule(`preact-render-to-string`);t.render&&typeof e==`function`&&(c=t.render(e()))}catch{c=`<p>Loading page: ${G(n)}</p>`}return`<!DOCTYPE html>
|
|
30
34
|
<html lang="en">
|
|
31
35
|
<head>
|
|
32
36
|
<meta charset="utf-8">
|
|
33
37
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
34
|
-
<title>${
|
|
35
|
-
${s?`<meta name="description" content="${
|
|
38
|
+
<title>${G(o)}</title>
|
|
39
|
+
${s?`<meta name="description" content="${G(s)}">`:``}
|
|
36
40
|
<script type="module" src="/@vite/client"><\/script>
|
|
37
41
|
</head>
|
|
38
42
|
<body>
|
|
39
43
|
<div id="app">${c}</div>
|
|
40
44
|
<script type="module" src="/src/client/main.js"><\/script>
|
|
41
45
|
</body>
|
|
42
|
-
</html>`}function
|
|
46
|
+
</html>`}function G(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useavalon/avalon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"description": "Multi-framework islands architecture for the modern web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
"dependencies": {
|
|
111
|
-
"@useavalon/core": "^0.1.
|
|
111
|
+
"@useavalon/core": "^0.1.6",
|
|
112
112
|
"@mdx-js/rollup": "^3.0.0",
|
|
113
113
|
"h3": "^2.0.1-rc.16",
|
|
114
114
|
"marked": "^17.0.4",
|