@devlusoft/devix 0.4.4 → 0.5.1

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.
Files changed (81) hide show
  1. package/README.md +64 -9
  2. package/dist/cli/build.js +27 -17
  3. package/dist/cli/build.js.map +3 -3
  4. package/dist/cli/dev-server.js +31 -21
  5. package/dist/cli/dev-server.js.map +4 -4
  6. package/dist/cli/generate.js +29 -19
  7. package/dist/cli/generate.js.map +3 -3
  8. package/dist/cli/index.js +30 -20
  9. package/dist/cli/index.js.map +4 -4
  10. package/dist/cli/start.js +1 -1
  11. package/dist/cli/start.js.map +4 -4
  12. package/dist/config.d.ts +61 -0
  13. package/dist/config.js +1 -1
  14. package/dist/config.js.map +3 -3
  15. package/dist/runtime/api-context.d.ts +9 -4
  16. package/dist/runtime/api-context.js +1 -1
  17. package/dist/runtime/api-context.js.map +3 -3
  18. package/dist/runtime/context.d.ts +1 -0
  19. package/dist/runtime/context.js.map +2 -2
  20. package/dist/runtime/create-handler.d.ts +52 -2
  21. package/dist/runtime/create-handler.js +1 -1
  22. package/dist/runtime/create-handler.js.map +3 -3
  23. package/dist/runtime/error-boundary.d.ts +7 -1
  24. package/dist/runtime/error-boundary.js +1 -1
  25. package/dist/runtime/error-boundary.js.map +3 -3
  26. package/dist/runtime/fetch.d.ts +1 -0
  27. package/dist/runtime/fetch.js +1 -1
  28. package/dist/runtime/fetch.js.map +3 -3
  29. package/dist/runtime/index.d.ts +6 -2
  30. package/dist/runtime/index.js +1 -1
  31. package/dist/runtime/index.js.map +4 -4
  32. package/dist/runtime/link.js.map +2 -2
  33. package/dist/runtime/router-provider.d.ts +24 -1
  34. package/dist/runtime/router-provider.js +1 -1
  35. package/dist/runtime/router-provider.js.map +3 -3
  36. package/dist/runtime/server-app.d.ts +2 -1
  37. package/dist/runtime/server-app.js +1 -1
  38. package/dist/runtime/server-app.js.map +3 -3
  39. package/dist/runtime/server-client.d.ts +66 -0
  40. package/dist/runtime/server-client.js +2 -0
  41. package/dist/runtime/server-client.js.map +7 -0
  42. package/dist/server/api.d.ts +2 -1
  43. package/dist/server/api.js +1 -1
  44. package/dist/server/api.js.map +4 -4
  45. package/dist/server/handler-store.d.ts +12 -0
  46. package/dist/server/handler-store.js.map +2 -2
  47. package/dist/server/public-index.js.map +2 -2
  48. package/dist/server/render.d.ts +8 -0
  49. package/dist/server/render.js +1 -1
  50. package/dist/server/render.js.map +4 -4
  51. package/dist/server/routes.d.ts +4 -2
  52. package/dist/server/routes.js +1 -1
  53. package/dist/server/routes.js.map +4 -4
  54. package/dist/server/server-bound.d.ts +11 -0
  55. package/dist/server/server-bound.js +2 -0
  56. package/dist/server/server-bound.js.map +7 -0
  57. package/dist/server/server-proxy.d.ts +15 -0
  58. package/dist/server/server-proxy.js +2 -0
  59. package/dist/server/server-proxy.js.map +7 -0
  60. package/dist/server/types.d.ts +1 -0
  61. package/dist/types.d.ts +22 -0
  62. package/dist/utils/banner.js +1 -1
  63. package/dist/utils/glob.d.ts +11 -0
  64. package/dist/utils/glob.js +2 -0
  65. package/dist/utils/glob.js.map +7 -0
  66. package/dist/utils/response.d.ts +33 -1
  67. package/dist/utils/response.js +1 -1
  68. package/dist/utils/response.js.map +3 -3
  69. package/dist/utils/standard-schema.d.ts +39 -0
  70. package/dist/utils/standard-schema.js +1 -0
  71. package/dist/utils/standard-schema.js.map +7 -0
  72. package/dist/vite/codegen/entry-client.js +5 -3
  73. package/dist/vite/codegen/entry-client.js.map +2 -2
  74. package/dist/vite/codegen/page-types.d.ts +11 -2
  75. package/dist/vite/codegen/page-types.js +3 -3
  76. package/dist/vite/codegen/page-types.js.map +3 -3
  77. package/dist/vite/codegen/server-entry.js +16 -8
  78. package/dist/vite/codegen/server-entry.js.map +2 -2
  79. package/dist/vite/index.js +26 -16
  80. package/dist/vite/index.js.map +3 -3
  81. package/package.json +5 -5
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var c=(e,t)=>()=>(e&&(t=e(e=0)),t);var lt={};import{spawnSync as nt}from"node:child_process";import{fileURLToPath as it}from"node:url";import{dirname as st,resolve as at}from"node:path";var ct,ne=c(()=>{"use strict";ct=st(it(import.meta.url));for(;nt(process.execPath,[at(ct,"dev-server.js")],{stdio:"inherit",env:process.env}).status===75;);});function ie({cssUrls:e}){return`
2
+ var d=(e,t)=>()=>(e&&(t=e(e=0)),t);var xt={};import{spawnSync as pt}from"node:child_process";import{fileURLToPath as ft}from"node:url";import{dirname as mt,resolve as gt}from"node:path";var ht,ce=d(()=>{"use strict";ht=mt(ft(import.meta.url));for(;pt(process.execPath,[gt(ht,"dev-server.js")],{stdio:"inherit",env:process.env}).status===75;);});function le({cssUrls:e}){return`
3
3
  ${e.map(r=>`import '${r}'`).join(`
4
4
  `)}
5
5
  import "@vitejs/plugin-react/preamble"
@@ -17,11 +17,12 @@ if (!window.__DEVIX__) {
17
17
  const {metadata, viewport, clientEntry} = window.__DEVIX__
18
18
  const loaderData = window.__LOADER_DATA__
19
19
  const layoutsData = window.__LAYOUTS_DATA__ ?? []
20
+ const guardData = window.__GUARD_DATA__ ?? null
20
21
 
21
22
  const matched = matchClientRoute(window.location.pathname)
22
23
 
23
24
  if (window.__LOADER_ERROR__) {
24
- const {statusCode, message, data} = window.__LOADER_ERROR__
25
+ const {statusCode, message, code, data} = window.__LOADER_ERROR__
25
26
  const ErrorPage = await loadErrorPage() ?? getDefaultErrorPage()
26
27
  createRoot(root).render(
27
28
  React.createElement(RouterProvider, {
@@ -29,7 +30,7 @@ if (!window.__DEVIX__) {
29
30
  initialData: null,
30
31
  initialParams: {},
31
32
  initialPage: () => null,
32
- initialError: {statusCode, message, data},
33
+ initialError: {statusCode, message, code, data},
33
34
  initialErrorPage: ErrorPage,
34
35
  })
35
36
  )
@@ -47,6 +48,7 @@ if (!window.__DEVIX__) {
47
48
  initialPage: pageMod.default,
48
49
  initialLayouts: layoutMods.map(m => m.default),
49
50
  initialLayoutsData: layoutsData,
51
+ initialGuardData: guardData,
50
52
  initialMeta: metadata,
51
53
  initialViewport: viewport,
52
54
  })
@@ -76,7 +78,7 @@ if (!window.__DEVIX__) {
76
78
  )
77
79
  }
78
80
  }
79
- `}var se=c(()=>{"use strict"});function ae({pagesDir:e,matcherPath:t}){return`
81
+ `}var de=d(()=>{"use strict"});function ue({pagesDir:e,matcherPath:t}){return`
80
82
  import React from 'react'
81
83
  import { createMatcher } from '${t}'
82
84
  const pageFiles = import.meta.glob(['/${e}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
@@ -104,7 +106,7 @@ export function getDefaultErrorPage() {
104
106
  )
105
107
  }
106
108
  }
107
- `}var ce=c(()=>{"use strict"});function le({pagesDir:e,renderPath:t}){return`
109
+ `}var pe=d(()=>{"use strict"});function fe({pagesDir:e,renderPath:t}){return`
108
110
  import { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${t}'
109
111
 
110
112
  const _pages = import.meta.glob(['/${e}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
@@ -127,7 +129,7 @@ export function runLoader(url, request, options) {
127
129
  export function getStaticRoutes() {
128
130
  return _getStaticRoutes(_glob)
129
131
  }
130
- `}var ue=c(()=>{"use strict"});function de({apiPath:e,appDir:t}){return`
132
+ `}var me=d(()=>{"use strict"});function ge({apiPath:e,appDir:t}){return`
131
133
  import { handleApiRequest as _handleApiRequest } from '${e}'
132
134
 
133
135
  const _routes = import.meta.glob(['/${t}/api/**/*.ts', '!**/middleware.ts'])
@@ -142,15 +144,15 @@ const _glob = {
142
144
  export function handleApiRequest(url, request) {
143
145
  return _handleApiRequest(url, request, _glob)
144
146
  }
145
- `}var pe=c(()=>{"use strict"});function me(){return`
147
+ `}var he=d(()=>{"use strict"});function xe(){return`
146
148
  export {RouterContext} from '@devlusoft/devix/runtime/context'
147
- `}var fe=c(()=>{"use strict"});function dt(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function ge(e){let t=new Set;for(let r of dt(e).matchAll(ut))t.add(r[1]);return[...t]}var ut,he=c(()=>{"use strict";ut=/export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g});function ve(e){return e.replace(/\.(tsx|ts|jsx|js)$/,"").replace(/\(.*?\)\//g,"").replace(/^index$|\/index$/,"").replace(/\[([^\]]+)]/g,":$1")||"/"}var xe=c(()=>{"use strict"});function ye(e,t){let r=e.slice(t.length+1).replace(/\\/g,"/"),n=ve(r);return n==="/"?"/api":`/api/${n}`.replace("/api//","/api/")}var Re=c(()=>{"use strict";xe()});function pt(e,t){return"_api_"+e.slice(`${t}/`.length).replace(/\.(ts|tsx)$/,"").replace(/[^a-zA-Z0-9]/g,"_")}function we(e,t,r){return{filePath:e,urlPattern:ye(e,t),identifier:pt(e,t),methods:r}}function I(e,t){if(e.length===0)return`// auto-generado por devix \u2014 no editar
149
+ `}var ye=d(()=>{"use strict"});function vt(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function ve(e){let t=new Set;for(let r of vt(e).matchAll(yt))t.add(r[1]);return[...t]}var yt,Re=d(()=>{"use strict";yt=/export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g});function we(e){return e.replace(/\.(tsx|ts|jsx|js)$/,"").replace(/\(.*?\)\//g,"").replace(/^index$|\/index$/,"").replace(/\[([^\]]+)]/g,":$1")||"/"}var Ee=d(()=>{"use strict"});function _e(e,t){let r=e.slice(t.length+1).replace(/\\/g,"/"),o=we(r);return o==="/"?"/api":`/api/${o}`.replace("/api//","/api/")}var Se=d(()=>{"use strict";Ee()});function Rt(e,t){return"_api_"+e.slice(`${t}/`.length).replace(/\.(ts|tsx)$/,"").replace(/[^a-zA-Z0-9]/g,"_")}function Te(e,t,r){return{filePath:e,urlPattern:_e(e,t),identifier:Rt(e,t),methods:r}}function U(e,t){if(e.length===0)return`// auto-generado por devix \u2014 no editar
148
150
  export {}
149
151
  declare module '@devlusoft/devix' {
150
152
  interface ApiRoutes {}
151
153
  }
152
- `;let r=e.map(o=>{let a="../"+o.filePath.replace(/\.(ts|tsx)$/,"");return`import type * as ${o.identifier} from '${a}'`}).join(`
153
- `),n=e.flatMap(o=>o.methods.map(a=>` '${a} ${o.urlPattern}': InferRoute<(typeof ${o.identifier})['${a}']>`)).join(`
154
+ `;let r=e.map(n=>{let s="../"+n.filePath.replace(/\.(ts|tsx)$/,"");return`import type * as ${n.identifier} from '${s}'`}).join(`
155
+ `),o=e.flatMap(n=>n.methods.map(s=>` '${s} ${n.urlPattern}': InferRoute<(typeof ${n.identifier})['${s}']>`)).join(`
154
156
  `);return`// auto-generado por devix \u2014 no editar
155
157
  ${r}
156
158
 
@@ -171,14 +173,14 @@ type InferRoute<T> =
171
173
 
172
174
  declare module '@devlusoft/devix' {
173
175
  interface ApiRoutes {
174
- ${n}
176
+ ${o}
175
177
  }
176
178
  }
177
- `}var L=c(()=>{"use strict";Re()});import{readFileSync as mt,readdirSync as ft,statSync as gt}from"node:fs";import{join as U,relative as ht}from"node:path";function _e(e,t){let r=[];for(let n of ft(e)){let o=U(e,n);gt(o).isDirectory()?r.push(..._e(o,t)):/\.(ts|tsx)$/.test(n)&&r.push(ht(t,o).replace(/\\/g,"/"))}return r}function k(e,t){let r=U(t,e,"api"),n;try{n=_e(r,t)}catch{return[]}return n.filter(o=>!o.endsWith("middleware.ts")&&!o.endsWith("middleware.tsx")).flatMap(o=>{try{let a=mt(U(t,o),"utf-8"),d=ge(a);return d.length===0?[]:[we(o,`${e}/api`,d)]}catch{return[]}})}var Se=c(()=>{"use strict";he();L()});import{mkdirSync as vt,readFileSync as xt,writeFileSync as yt,existsSync as Rt}from"node:fs";import{join as Ee}from"node:path";function N(e,t){let r=Ee(t,".devix"),n=Ee(r,"routes.d.ts");return vt(r,{recursive:!0}),Rt(n)&&xt(n,"utf-8")===e?!1:(yt(n,e,"utf-8"),!0)}var Pe=c(()=>{"use strict"});function Te({routesPath:e,envPath:t,honoServerPath:r,honoServerStaticPath:n,honoPath:o}){return`
179
+ `}var k=d(()=>{"use strict";Se()});import{readFileSync as wt,readdirSync as Et,statSync as _t}from"node:fs";import{join as N,relative as St}from"node:path";function Pe(e,t){let r=[];for(let o of Et(e)){let n=N(e,o);_t(n).isDirectory()?r.push(...Pe(n,t)):/\.(ts|tsx)$/.test(o)&&r.push(St(t,n).replace(/\\/g,"/"))}return r}function H(e,t){let r=N(t,e,"api"),o;try{o=Pe(r,t)}catch{return[]}return o.filter(n=>!n.endsWith("middleware.ts")&&!n.endsWith("middleware.tsx")).flatMap(n=>{try{let s=wt(N(t,n),"utf-8"),a=ve(s);return a.length===0?[]:[Te(n,`${e}/api`,a)]}catch{return[]}})}var be=d(()=>{"use strict";Re();k()});import{mkdirSync as Tt,readFileSync as Pt,writeFileSync as bt,existsSync as Ct}from"node:fs";import{join as Ce}from"node:path";function B(e,t){let r=Ce(t,".devix"),o=Ce(r,"routes.d.ts");return Tt(r,{recursive:!0}),Ct(o)&&Pt(o,"utf-8")===e?!1:(bt(o,e,"utf-8"),!0)}var De=d(()=>{"use strict"});function $e({routesPath:e,envPath:t,honoServerPath:r,honoServerStaticPath:o,honoPath:n}){return`
178
180
  import { readFileSync } from 'node:fs'
179
181
  import { serve } from '${r}'
180
- import { serveStatic } from '${n}'
181
- import { Hono } from '${o}'
182
+ import { serveStatic } from '${o}'
183
+ import { Hono } from '${n}'
182
184
  import { resolve, join, dirname } from 'node:path'
183
185
  import { pathToFileURL } from 'node:url'
184
186
  import { registerApiRoutes, registerSsrRoute } from '${e}'
@@ -235,9 +237,17 @@ import { readFileSync } from 'node:fs'
235
237
 
236
238
  if (runtimeConfig.output === 'static') {
237
239
  console.log('[devix] Static mode \u2014 serving pre-generated files from dist/client')
238
- } else {
239
- registerApiRoutes(app, { renderModule, apiModule, manifest })
240
- registerSsrRoute(app, { renderModule, apiModule, manifest, loaderTimeout: runtimeConfig.loaderTimeout })
240
+ } else {
241
+ let userServerConfig
242
+ try {
243
+ const userConfigMod = await import(pathToFileURL(resolve(process.cwd(), 'devix.config.ts')).href).catch(() =>
244
+ import(pathToFileURL(resolve(process.cwd(), 'devix.config.js')).href))
245
+ userServerConfig = userConfigMod?.default?.server
246
+ } catch {
247
+ /* config sin server \u2014 sigue normal */
248
+ }
249
+ registerApiRoutes(app, { renderModule, apiModule, manifest, server: userServerConfig })
250
+ registerSsrRoute(app, { renderModule, apiModule, manifest, loaderTimeout: runtimeConfig.loaderTimeout, server: userServerConfig })
241
251
  }
242
252
 
243
253
  const server = serve({ fetch: app.fetch, port, hostname: host }, (info) =>
@@ -245,7 +255,7 @@ import { readFileSync } from 'node:fs'
245
255
 
246
256
  process.on('SIGTERM', () => server.close())
247
257
  process.on('SIGINT', () => server.close())
248
- `}var $e=c(()=>{"use strict"});import{existsSync as De,mkdirSync as wt,readdirSync as _t,readFileSync as be,rmSync as St,statSync as Et,writeFileSync as Pt}from"node:fs";import{join as y,relative as Ce}from"node:path";import{parseSync as Tt}from"oxc-parser";function Ae(e,t){let r=[];for(let n of _t(e)){let o=y(e,n);Et(o).isDirectory()?r.push(...Ae(o,t)):/\.(ts|tsx)$/.test(n)&&n!=="layout.tsx"&&n!=="error.tsx"&&r.push(Ce(t,o).replace(/\\/g,"/"))}return r}function $t(e,t){let r=Tt(t,e,{sourceType:"module"});for(let n of r.program.body){if(n.type!=="ExportNamedDeclaration")continue;let o=n.declaration;if(o?.type==="FunctionDeclaration"&&o.id?.name==="loader")return!0;if(o?.type==="VariableDeclaration"){for(let a of o.declarations)if(a.id.type==="Identifier"&&a.id.name==="loader")return!0}for(let a of n.specifiers??[])if(a.exported.type==="Identifier"&&a.exported.name==="loader")return!0}return!1}function bt(e,t){return t?`// auto-generado por devix \u2014 no editar
258
+ `}var Ae=d(()=>{"use strict"});import{existsSync as je,mkdirSync as Dt,readdirSync as $t,readFileSync as Oe,rmSync as At,statSync as Ot,writeFileSync as jt}from"node:fs";import{join as E,relative as Ie}from"node:path";import{parseSync as It}from"oxc-parser";function Fe(e,t){let r=[];for(let o of $t(e)){let n=E(e,o);Ot(n).isDirectory()?r.push(...Fe(n,t)):/\.(ts|tsx)$/.test(o)&&o!=="layout.tsx"&&o!=="error.tsx"&&r.push(Ie(t,n).replace(/\\/g,"/"))}return r}function Ft(e,t){let r=It(t,e,{sourceType:"module"});for(let o of r.program.body){if(o.type!=="ExportNamedDeclaration")continue;let n=o.declaration;if(n?.type==="FunctionDeclaration"&&n.id?.name==="loader")return{exists:!0,isAsync:n.async,isReExport:!1};if(n?.type==="VariableDeclaration"){for(let s of n.declarations)if(s.id.type==="Identifier"&&s.id.name==="loader"){let a=s.init;return{exists:!0,isAsync:a?.type==="ArrowFunctionExpression"&&a.async||a?.type==="FunctionExpression"&&a.async,isReExport:!1}}}for(let s of o.specifiers??[])if(s.exported.type==="Identifier"&&s.exported.name==="loader")return{exists:!0,isAsync:!1,isReExport:!0}}return{exists:!1,isAsync:!1,isReExport:!1}}function Mt(e,t){return t?`// auto-generado por devix \u2014 no editar
249
259
  import type { loader } from "${e}"
250
260
  import type { Redirect } from "@devlusoft/devix"
251
261
 
@@ -257,7 +267,7 @@ export type PageParams = NonNullable<Parameters<typeof loader>[0]>["params"]
257
267
  `:`// auto-generado por devix - no editar
258
268
  export type PageData = undefined
259
269
  export type PageParams = Record<string, string>
260
- `}function O(e,t){let r=y(t,e),n=be(r,"utf-8"),o=$t(n,r),a=y(t,".devix","pages",e.replace(/\.(tsx?|jsx?)$/,"")),d=y(a,"$types.d.ts"),x=r.replace(/\.(tsx?|jsx?)$/,""),m=Ce(a,x).replace(/\\/g,"/"),f=bt(m,o);De(d)&&be(d,"utf-8")===f||(wt(a,{recursive:!0}),Pt(d,f,"utf-8"))}function Oe(e,t){let r=y(t,".devix","pages",e.replace(/\.(tsx?|jsx?)$/,"")),n=y(r,"$types.d.ts");De(n)&&St(n)}function H(e,t){let r=y(t,e,"pages"),n;try{n=Ae(r,t)}catch{return}for(let o of n)try{O(o,t)}catch{}}var je=c(()=>{"use strict"});import{mergeConfig as Dt}from"vite";import Ct from"@vitejs/plugin-react";import{fileURLToPath as At}from"node:url";import{dirname as Ot,relative as jt,resolve as p}from"node:path";import{createRequire as Mt}from"node:module";import{parseSync as Ft}from"oxc-parser";function Fe(e){let t=e.appDir??"app",r=`${t}/pages`,n=(e.css??[]).map(i=>i.startsWith("/")?i:`/${i.replace(/^\.\//,"")}`),o=p(P,"../server/render.js").replace(/\\/g,"/"),a=p(P,"../server/api.js").replace(/\\/g,"/"),d=p(P,"../runtime/client-router.js").replace(/\\/g,"/"),x=p(P,"../server/routes.js").replace(/\\/g,"/"),m=p(P,"../utils/env.js").replace(/\\/g,"/"),f=Mt(import.meta.url),w=f.resolve("@hono/node-server").replace(/\\/g,"/"),M=f.resolve("@hono/node-server/serve-static").replace(/\\/g,"/"),tt=f.resolve("hono").replace(/\\/g,"/"),rt={name:"devix",enforce:"pre",resolveId(i){if(i===q)return`\0${q}`;if(i===V)return`\0${V}`;if(i===T)return`\0${T}`;if(i===$)return`\0${$}`;if(i===J)return`\0${J}`;if(i===W)return`\0${W}`},load(i){if(i===`\0${q}`)return ie({cssUrls:n});if(i===`\0${V}`)return ae({pagesDir:r,matcherPath:d});if(i===`\0${T}`)return le({pagesDir:r,renderPath:o});if(i===`\0${$}`)return de({apiPath:a,appDir:t});if(i===`\0${J}`)return me();if(i===`\0${W}`)return Te({routesPath:x,envPath:m,honoServerPath:w,honoServerStaticPath:M,honoPath:tt})},transform(i,l,_){if(_?.ssr)return;let S=p(process.cwd(),r);if(!l.startsWith(S))return;let E=Ft(l,i,{sourceType:"module"}),g=[];for(let u of E.program.body){if(u.type!=="ExportNamedDeclaration"||!u.declaration)continue;let h=u.declaration;if(h.type==="FunctionDeclaration"&&h.id&&Me.has(h.id.name)&&g.push({start:u.start,end:u.end,name:h.id.name}),h.type==="VariableDeclaration"){let A=new Set;for(let F of h.declarations)F.id.type==="Identifier"&&Me.has(F.id.name)&&(A.has(u.start)||(A.add(u.start),g.push({start:u.start,end:u.end,name:F.id.name})))}}if(g.length===0)return;g.sort((u,h)=>h.start-u.start);let s=i;for(let{start:u,end:h,name:A}of g)s=s.slice(0,u)+`export const ${A} = undefined`+s.slice(h);return{code:s,map:null}},buildStart(){let i=process.cwd(),l=k(t,i);N(I(l,`${t}/api`),i),H(t,i)},configureServer(i){let l=process.cwd();H(t,l);let _=()=>{let s=k(t,l);N(I(s,`${t}/api`),l)},S=s=>s.startsWith(p(l,r))&&!s.endsWith("layout.tsx")&&!s.endsWith("error.tsx"),E=s=>jt(l,s).replace(/\\/g,"/"),g=s=>{let u=i.moduleGraph.getModuleById(`\0${s}`);u&&i.moduleGraph.invalidateModule(u)};i.watcher.add(p(l,"devix.config.ts")),i.watcher.on("change",s=>{s===p(l,"devix.config.ts")&&(console.log("[devix] Config changed, restarting..."),process.exit(75))}),i.watcher.on("add",s=>{s.startsWith(p(l,r))&&g(T),S(s)&&O(E(s),l),s.includes(`${t}/api`)&&(g($),_())}),i.watcher.on("unlink",s=>{s.startsWith(p(l,r))&&g(T),S(s)&&Oe(E(s),l),s.includes(`${t}/api`)&&(g($),_())}),i.watcher.on("change",s=>{S(s)&&O(E(s),l),s.includes(`${t}/api`)&&!s.endsWith("middleware.ts")&&_()})}},ot={plugins:[Ct(),rt],publicDir:p(process.cwd(),e.publicDir??"public"),ssr:{noExternal:["@devlusoft/devix"]},...e.envPrefix?{envPrefix:e.envPrefix}:{}};return Dt(ot,e.vite??{})}var P,q,V,T,$,J,W,Me,Ie=c(()=>{"use strict";se();ce();ue();pe();fe();Se();L();Pe();$e();je();P=Ot(At(import.meta.url)),q="virtual:devix/entry-client",V="virtual:devix/client-routes",T="virtual:devix/render",$="virtual:devix/api",J="virtual:devix/context",W="virtual:devix/server-entry",Me=new Set(["loader","guard","generateStaticParams","headers"])});function Le(e){if(typeof e=="number")return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);if(!t)throw new Error(`[devix] Invalid duration: "${e}". Use a number (ms) or a string like "5s", "2m", "500ms".`);let r=parseFloat(t[1]);switch(t[2]){case"h":return r*36e5;case"m":return r*6e4;case"s":return r*1e3;default:return r}}var Ue=c(()=>{"use strict"});import{build as It}from"esbuild";import{join as ke}from"node:path";import{unlinkSync as Lt,writeFileSync as Ut}from"node:fs";import{pathToFileURL as kt}from"node:url";async function j(e){let t=await It({entryPoints:[ke(e,"devix.config.ts")],bundle:!0,write:!1,format:"esm",platform:"node",packages:"external"}),r=ke(e,`.devix-config-${Date.now()}.mjs`);Ut(r,t.outputFiles[0].text);try{return(await import(kt(r).href)).default}finally{Lt(r)}}var B=c(()=>{"use strict"});var Ne={};import{writeFileSync as Nt}from"node:fs";import{resolve as Ht}from"node:path";import{build as G}from"vite";var b,X,qt,Y=c(async()=>{"use strict";Ie();Ue();B();b=await j(process.cwd()),X=Fe(b);await G({...X,configFile:!1,build:{outDir:"dist/client",manifest:!0,rolldownOptions:{input:"virtual:devix/entry-client"}}});await G({...X,configFile:!1,build:{ssr:!0,outDir:"dist/server",copyPublicDir:!1,rolldownOptions:{input:{render:"virtual:devix/render",api:"virtual:devix/api"}}}});await G({...X,configFile:!1,build:{ssr:!0,outDir:"dist/server",emptyOutDir:!1,copyPublicDir:!1,rolldownOptions:{input:{index:"virtual:devix/server-entry"}}}});qt={port:b.port??3e3,host:b.host??!1,loaderTimeout:Le(b.loaderTimeout??1e4),output:b.output??"server"};Nt(Ht(process.cwd(),"dist/devix.config.json"),JSON.stringify(qt,null,2),"utf-8")});var Gt={};import{readFileSync as Vt,mkdirSync as He,writeFileSync as qe,rmSync as Jt}from"node:fs";import{resolve as K,join as R}from"node:path";import{pathToFileURL as Wt}from"node:url";var Je,Bt,z,Ve,Z,We=c(async()=>{"use strict";B();Je=await j(process.cwd());Je.output!=="static"&&console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');await Y().then(()=>Ne);Bt=Date.now(),z=await import(Wt(K(process.cwd(),"dist/server/render.js")).href+`?t=${Bt}`),Ve=JSON.parse(Vt(K(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8")),Z=await z.getStaticRoutes();console.log(`[devix] Generating ${Z.length} static page${Z.length===1?"":"s"}...`);for(let e of Z){let t=`http://localhost${e}`,{html:r,statusCode:n}=await z.render(t,new Request(t),{manifest:Ve});if(n!==200){console.warn(`[devix] Skipping ${e} \u2014 status ${n}`);continue}let o=e==="/"?R(process.cwd(),"dist/client/index.html"):R(process.cwd(),"dist/client",e,"index.html");He(R(o,".."),{recursive:!0}),qe(o,`<!DOCTYPE html>${r}`,"utf-8");let a=await z.runLoader(t,new Request(t),{manifest:Ve}),d=e==="/"?R(process.cwd(),"dist/client/_data/index.json"):R(process.cwd(),"dist/client/_data",`${e}.json`);He(R(d,".."),{recursive:!0}),qe(d,JSON.stringify(a),"utf-8"),console.log(` \u2713 ${e}`)}console.log("[devix] Generation complete.");Je.output==="static"&&(Jt(K(process.cwd(),"dist/server"),{recursive:!0,force:!0}),console.log("[devix] Removed dist/server (not needed in static mode)"))});function Be(e,{apiModule:t,renderModule:r,loaderTimeout:n}){e.all("/api/*",async o=>{try{return await t.handleApiRequest(o.req.url,o.req.raw)}catch(a){return console.error(a),o.json({error:"internal error"},500)}}),e.get("/_data/*",async o=>{try{let{pathname:a,search:d}=new URL(o.req.url,"http://localhost"),x=a.replace(/^\/_data/,"")+d,m=await r.runLoader(x,o.req.raw,{loaderTimeout:n});if(m.error)return o.json({error:"internal error"},500);if("loaderError"in m){let{statusCode:f,message:w,data:M}=m.loaderError;return o.json({statusCode:f,message:w,data:M},f)}return o.json(m)}catch(a){return console.error(a),o.json({error:"internal error"},500)}})}function Ge(e,{renderModule:t,manifest:r,loaderTimeout:n}){e.get("*",async o=>{try{let{html:a,statusCode:d,headers:x}=await t.render(o.req.url,o.req.raw,{manifest:r,loaderTimeout:n}),m=o.html(`<!DOCTYPE html>${a}`,d);for(let[f,w]of Object.entries(x))m.headers.set(f,w);return m}catch(a){return console.error(a),o.text("Internal Server Error",500)}})}var Xe=c(()=>{"use strict"});import{loadEnv as Xt}from"vite";function Ye(e){let t=Xt(e,process.cwd(),"");for(let[r,n]of Object.entries(t))process.env[r]===void 0&&(process.env[r]=n)}var ze=c(()=>{"use strict"});var er={};import{readFileSync as Q}from"node:fs";import{serve as Yt}from"@hono/node-server";import{serveStatic as zt}from"@hono/node-server/serve-static";import{Hono as Zt}from"hono";import{resolve as Ze,join as D}from"node:path";import{pathToFileURL as Ke}from"node:url";var ee,te,re,v,Kt,Qt,C,oe,Qe=c(async()=>{"use strict";Xe();ze();Ye("production");try{v=JSON.parse(Q(D(process.cwd(),"dist/devix.config.json"),"utf-8")),v.output!=="static"&&(ee=await import(Ke(Ze(process.cwd(),"dist/server/render.js")).href),te=await import(Ke(Ze(process.cwd(),"dist/server/api.js")).href)),re=JSON.parse(Q(D(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8"))}catch{console.error('[devix] Build not found. Run "devix build" first.'),process.exit(1)}Kt=Number(process.env.PORT)||v.port||3e3,Qt=typeof v.host=="string"?v.host:v.host?"0.0.0.0":process.env.HOST||"0.0.0.0",C=new Zt,oe=D(process.cwd(),"dist/client");v.output==="static"&&C.get("/_data/*",e=>{let t=e.req.path.replace(/^\/_data/,"")||"/",r=t==="/"?D(oe,"_data/index.json"):D(oe,"_data",`${t}.json`);try{let n=Q(r,"utf-8");return e.json(JSON.parse(n))}catch{return e.json({error:"not found"},404)}});C.use("/*",zt({root:oe,onFound:(e,t)=>{t.header("Cache-Control",e.includes("/assets/")?"public, immutable, max-age=31536000":"no-cache")}}));v.output==="static"?console.log("[devix] Static mode \u2014 serving pre-generated files from dist/client"):(Be(C,{renderModule:ee,apiModule:te,manifest:re}),Ge(C,{renderModule:ee,apiModule:te,manifest:re,loaderTimeout:v.loaderTimeout}));Yt({fetch:C.fetch,port:Kt,hostname:Qt},e=>console.log(`http://${e.address}:${e.port}`))});var et=process.argv[2];switch(et){case"dev":await Promise.resolve().then(()=>(ne(),lt));break;case"build":await Y().then(()=>Ne);break;case"generate":await We().then(()=>Gt);break;case"start":await Qe().then(()=>er);break;case"--version":case"-v":{console.log("0.4.4");break}case"--help":case"-h":console.log(`
270
+ `}function J(e,t){let r=E(t,e),o=Oe(r,"utf-8"),n=Ft(o,r),s=[];n.exists&&!n.isAsync&&!n.isReExport&&s.push(`[devix] ${e}: 'loader' must be async. Use 'export async function loader' or 'export const loader = async (...) => ...'.`);let a=E(t,".devix","pages",e.replace(/\.(tsx?|jsx?)$/,"")),m=E(a,"$types.d.ts"),g=r.replace(/\.(tsx?|jsx?)$/,""),l=Ie(a,g).replace(/\\/g,"/"),f=Mt(l,n.exists);return je(m)&&Oe(m,"utf-8")===f?{warnings:s}:(Dt(a,{recursive:!0}),jt(m,f,"utf-8"),{warnings:s})}function Me(e,t){let r=E(t,".devix","pages",e.replace(/\.(tsx?|jsx?)$/,"")),o=E(r,"$types.d.ts");je(o)&&At(o)}function q(e,t){let r=E(t,e,"pages"),o=[],n;try{n=Fe(r,t)}catch{return{warnings:o}}for(let s of n)try{let a=J(s,t);o.push(...a.warnings)}catch{}return{warnings:o}}var Le=d(()=>{"use strict"});import{mergeConfig as Lt}from"vite";import Ut from"@vitejs/plugin-react";import{fileURLToPath as kt}from"node:url";import{dirname as Nt,relative as Ht,resolve as h}from"node:path";import{createRequire as Bt}from"node:module";import{parseSync as Jt}from"oxc-parser";function ke(e){let t=e.appDir??"app",r=`${t}/pages`,o=(e.css??[]).map(c=>c.startsWith("/")?c:`/${c.replace(/^\.\//,"")}`),n=h(D,"../server/render.js").replace(/\\/g,"/"),s=h(D,"../server/api.js").replace(/\\/g,"/"),a=h(D,"../runtime/client-router.js").replace(/\\/g,"/"),m=h(D,"../server/routes.js").replace(/\\/g,"/"),g=h(D,"../utils/env.js").replace(/\\/g,"/"),l=Bt(import.meta.url),f=l.resolve("@hono/node-server").replace(/\\/g,"/"),L=l.resolve("@hono/node-server/serve-static").replace(/\\/g,"/"),lt=l.resolve("hono").replace(/\\/g,"/"),dt={name:"devix",enforce:"pre",resolveId(c){if(c===V)return`\0${V}`;if(c===W)return`\0${W}`;if(c===$)return`\0${$}`;if(c===A)return`\0${A}`;if(c===G)return`\0${G}`;if(c===X)return`\0${X}`},load(c){if(c===`\0${V}`)return le({cssUrls:o});if(c===`\0${W}`)return ue({pagesDir:r,matcherPath:a});if(c===`\0${$}`)return fe({pagesDir:r,renderPath:n});if(c===`\0${A}`)return ge({apiPath:s,appDir:t});if(c===`\0${G}`)return xe();if(c===`\0${X}`)return $e({routesPath:m,envPath:g,honoServerPath:f,honoServerStaticPath:L,honoPath:lt})},transform(c,u,P){if(P?.ssr)return;let w=h(process.cwd(),r);if(!u.startsWith(w))return;let b=Jt(u,c,{sourceType:"module"}),R=[];for(let p of b.program.body){if(p.type!=="ExportNamedDeclaration"||!p.declaration)continue;let i=p.declaration;if(i.type==="FunctionDeclaration"&&i.id&&Ue.has(i.id.name)&&R.push({start:p.start,end:p.end,name:i.id.name}),i.type==="VariableDeclaration"){let y=new Set;for(let C of i.declarations)C.id.type==="Identifier"&&Ue.has(C.id.name)&&(y.has(p.start)||(y.add(p.start),R.push({start:p.start,end:p.end,name:C.id.name})))}}if(R.length===0)return;R.sort((p,i)=>i.start-p.start);let x=c;for(let{start:p,end:i,name:y}of R)x=x.slice(0,p)+`export const ${y} = undefined`+x.slice(i);return{code:x,map:null}},buildStart(){let c=process.cwd(),u=H(t,c);B(U(u,`${t}/api`),c);let{warnings:P}=q(t,c);for(let w of P)console.warn(w)},configureServer(c){let u=process.cwd(),P=q(t,u);for(let i of P.warnings)console.warn(i);let w=()=>{let i=H(t,u);B(U(i,`${t}/api`),u)},b=i=>i.startsWith(h(u,r))&&!i.endsWith("layout.tsx")&&!i.endsWith("error.tsx"),R=i=>Ht(u,i).replace(/\\/g,"/"),x=i=>{let y=c.moduleGraph.getModuleById(`\0${i}`);y&&c.moduleGraph.invalidateModule(y)};c.watcher.add(h(u,"devix.config.ts")),c.watcher.on("change",i=>{i===h(u,"devix.config.ts")&&(console.log("[devix] Config changed, restarting..."),process.exit(75))});let p=i=>{try{let{warnings:y}=J(R(i),u);for(let C of y)console.warn(C)}catch{}};c.watcher.on("add",i=>{i.startsWith(h(u,r))&&x($),b(i)&&p(i),i.includes(`${t}/api`)&&(x(A),w())}),c.watcher.on("unlink",i=>{i.startsWith(h(u,r))&&x($),b(i)&&Me(R(i),u),i.includes(`${t}/api`)&&(x(A),w())}),c.watcher.on("change",i=>{b(i)&&p(i),i.includes(`${t}/api`)&&!i.endsWith("middleware.ts")&&w()})}},ut={plugins:[Ut(),dt],publicDir:h(process.cwd(),e.publicDir??"public"),ssr:{noExternal:["@devlusoft/devix"]},...e.envPrefix?{envPrefix:e.envPrefix}:{}};return Lt(ut,e.vite??{})}var D,V,W,$,A,G,X,Ue,Ne=d(()=>{"use strict";de();pe();me();he();ye();be();k();De();Ae();Le();D=Nt(kt(import.meta.url)),V="virtual:devix/entry-client",W="virtual:devix/client-routes",$="virtual:devix/render",A="virtual:devix/api",G="virtual:devix/context",X="virtual:devix/server-entry",Ue=new Set(["loader","guard","generateStaticParams","headers"])});function He(e){if(typeof e=="number")return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);if(!t)throw new Error(`[devix] Invalid duration: "${e}". Use a number (ms) or a string like "5s", "2m", "500ms".`);let r=parseFloat(t[1]);switch(t[2]){case"h":return r*36e5;case"m":return r*6e4;case"s":return r*1e3;default:return r}}var Be=d(()=>{"use strict"});import{build as qt}from"esbuild";import{join as Je}from"node:path";import{unlinkSync as Vt,writeFileSync as Wt}from"node:fs";import{pathToFileURL as Gt}from"node:url";async function _(e){let t=await qt({entryPoints:[Je(e,"devix.config.ts")],bundle:!0,write:!1,format:"esm",platform:"node",packages:"external"}),r=Je(e,`.devix-config-${Date.now()}.mjs`);Wt(r,t.outputFiles[0].text);try{return(await import(Gt(r).href)).default}finally{Vt(r)}}var F=d(()=>{"use strict"});var qe={};import{writeFileSync as Xt}from"node:fs";import{resolve as Yt}from"node:path";import{build as Y}from"vite";var O,z,zt,K=d(async()=>{"use strict";Ne();Be();F();O=await _(process.cwd()),z=ke(O);await Y({...z,configFile:!1,build:{outDir:"dist/client",manifest:!0,rolldownOptions:{input:"virtual:devix/entry-client"}}});await Y({...z,configFile:!1,build:{ssr:!0,outDir:"dist/server",copyPublicDir:!1,rolldownOptions:{input:{render:"virtual:devix/render",api:"virtual:devix/api"}}}});await Y({...z,configFile:!1,build:{ssr:!0,outDir:"dist/server",emptyOutDir:!1,copyPublicDir:!1,rolldownOptions:{input:{index:"virtual:devix/server-entry"}}}});zt={port:O.port??3e3,host:O.host??!1,loaderTimeout:He(O.loaderTimeout??1e4),output:O.output??"server"};Xt(Yt(process.cwd(),"dist/devix.config.json"),JSON.stringify(zt,null,2),"utf-8")});var tr={};import{readFileSync as Kt,mkdirSync as Ve,writeFileSync as We,rmSync as Zt}from"node:fs";import{resolve as ee,join as S}from"node:path";import{pathToFileURL as Qt}from"node:url";var Xe,er,Z,Ge,Q,Ye=d(async()=>{"use strict";F();Xe=await _(process.cwd());Xe.output!=="static"&&console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');await K().then(()=>qe);er=Date.now(),Z=await import(Qt(ee(process.cwd(),"dist/server/render.js")).href+`?t=${er}`),Ge=JSON.parse(Kt(ee(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8")),Q=await Z.getStaticRoutes();console.log(`[devix] Generating ${Q.length} static page${Q.length===1?"":"s"}...`);for(let e of Q){let t=`http://localhost${e}`,{html:r,statusCode:o}=await Z.render(t,new Request(t),{manifest:Ge});if(o!==200){console.warn(`[devix] Skipping ${e} \u2014 status ${o}`);continue}let n=e==="/"?S(process.cwd(),"dist/client/index.html"):S(process.cwd(),"dist/client",e,"index.html");Ve(S(n,".."),{recursive:!0}),We(n,`<!DOCTYPE html>${r}`,"utf-8");let s=await Z.runLoader(t,new Request(t),{manifest:Ge}),a=e==="/"?S(process.cwd(),"dist/client/_data/index.json"):S(process.cwd(),"dist/client/_data",`${e}.json`);Ve(S(a,".."),{recursive:!0}),We(a,JSON.stringify(s),"utf-8"),console.log(` \u2713 ${e}`)}console.log("[devix] Generation complete.");Xe.output==="static"&&(Zt(ee(process.cwd(),"dist/server"),{recursive:!0,force:!0}),console.log("[devix] Removed dist/server (not needed in static mode)"))});function M(e){let t={statusCode:e.statusCode,message:e.message};return e.code!==void 0&&(t.code=e.code),e.data!==void 0&&(t.data=e.data),t}var te=d(()=>{"use strict"});function rr(e,t){return or(t).test(e)}function re(e,t){if(!t||t.length===0)return!1;for(let r of t)if(rr(e,r))return!0;return!1}function or(e){let t="",r=0;for(;r<e.length;){let o=e[r];if(o==="*"&&e[r+1]==="*")t+=".*",r+=2;else if(o==="*")t+="[^/]*",r+=1;else if(o===":"){for(r+=1;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)r+=1;t+="[^/]+"}else".+?^$()|[]{}\\".includes(o)?(t+="\\"+o,r+=1):(t+=o,r+=1)}return new RegExp(`^${t}$`)}var ze=d(()=>{"use strict"});function T(e,t,r){let o=M({statusCode:e,message:t,code:r});return new Response(JSON.stringify(o),{status:e,headers:{"Content-Type":"application/json"}})}function nr(e){if(!e.startsWith(Ke+"/"))return null;let t=e.slice(Ke.length+1),r=t.indexOf("/");return r===-1?{namespace:t,path:"/"}:{namespace:t.slice(0,r),path:t.slice(r)}}async function Ze(e,t){let r=new URL(e.url),o=nr(r.pathname);if(!o)return T(404,"Not found","PROXY_NOT_FOUND");let n=t?.[o.namespace];if(!n)return T(404,`Backend "${o.namespace}" not configured`,"BACKEND_NOT_FOUND");if(!re(o.path,n.allowedPaths))return T(403,"Path not allowed","PATH_NOT_ALLOWED");if(re(o.path,n.deniedPaths))return T(403,"Path denied","PATH_DENIED");let s=new URL(o.path+r.search,n.url),a=new Headers;if(n.prepare){let l={request:e,headers:a,url:s};try{let f=await n.prepare(l);if(f instanceof Response)return f}catch(f){return console.error(`[devix] server.${o.namespace}.prepare error:`,f),T(500,"Proxy prepare failed","PREPARE_ERROR")}}if(!a.has("Accept")){let l=e.headers.get("Accept");l&&a.set("Accept",l)}let m=e.headers.get("Content-Type");m&&!a.has("Content-Type")&&a.set("Content-Type",m);let g=null;e.method!=="GET"&&e.method!=="HEAD"&&(g=await e.arrayBuffer(),g.byteLength===0&&(g=null));try{let l=await fetch(s,{method:e.method,headers:a,body:g,redirect:"manual"});return new Response(l.body,{status:l.status,statusText:l.statusText,headers:ir(l.headers)})}catch(l){return console.error(`[devix] server.${o.namespace} fetch error:`,l),T(502,"Bad Gateway","BACKEND_UNREACHABLE")}}function ir(e){let t=new Headers;return e.forEach((r,o)=>{sr.has(o.toLowerCase())||t.set(o,r)}),t}var Ke,sr,Qe=d(()=>{"use strict";ze();te();Ke="/_devix/server";sr=new Set(["connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailers","transfer-encoding","upgrade"])});function et(e,{apiModule:t,renderModule:r,loaderTimeout:o,server:n}){n&&e.all("/_devix/server/*",async s=>{try{return await Ze(s.req.raw,n)}catch(a){return console.error("[devix] proxy fatal error:",a),s.json({statusCode:500,message:"Internal Server Error"},500)}}),e.all("/api/*",async s=>{try{return await t.handleApiRequest(s.req.url,s.req.raw,n)}catch(a){return console.error(a),s.json({statusCode:500,message:"Internal Server Error"},500)}}),e.get("/_data/*",async s=>{try{let{pathname:a,search:m}=new URL(s.req.url,"http://localhost"),g=a.replace(/^\/_data/,"")+m,l=await r.runLoader(g,s.req.raw,{loaderTimeout:o,server:n});if(l.error)return s.json({statusCode:500,message:"Internal Server Error"},500);if("loaderError"in l){let f=M(l.loaderError);return s.json(f,f.statusCode)}return s.json(l)}catch(a){return console.error(a),s.json({statusCode:500,message:"Internal Server Error"},500)}})}function tt(e,{renderModule:t,manifest:r,loaderTimeout:o,server:n}){e.get("*",async s=>{try{let{html:a,statusCode:m,headers:g}=await t.render(s.req.url,s.req.raw,{manifest:r,loaderTimeout:o,server:n}),l=s.html(`<!DOCTYPE html>${a}`,m);for(let[f,L]of Object.entries(g))l.headers.set(f,L);return l}catch(a){return console.error(a),s.text("Internal Server Error",500)}})}var rt=d(()=>{"use strict";te();Qe()});import{loadEnv as ar}from"vite";function ot(e){let t=ar(e,process.cwd(),"");for(let[r,o]of Object.entries(t))process.env[r]===void 0&&(process.env[r]=o)}var nt=d(()=>{"use strict"});var fr={};import{readFileSync as oe}from"node:fs";import{serve as cr}from"@hono/node-server";import{serveStatic as lr}from"@hono/node-server/serve-static";import{Hono as dr}from"hono";import{resolve as st,join as j}from"node:path";import{pathToFileURL as it}from"node:url";var ne,se,ie,v,ur,pr,I,ae,at=d(async()=>{"use strict";rt();nt();F();ot("production");try{v=JSON.parse(oe(j(process.cwd(),"dist/devix.config.json"),"utf-8")),v.output!=="static"&&(ne=await import(it(st(process.cwd(),"dist/server/render.js")).href),se=await import(it(st(process.cwd(),"dist/server/api.js")).href)),ie=JSON.parse(oe(j(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8"))}catch{console.error('[devix] Build not found. Run "devix build" first.'),process.exit(1)}ur=Number(process.env.PORT)||v.port||3e3,pr=typeof v.host=="string"?v.host:v.host?"0.0.0.0":process.env.HOST||"0.0.0.0",I=new dr,ae=j(process.cwd(),"dist/client");v.output==="static"&&I.get("/_data/*",e=>{let t=e.req.path.replace(/^\/_data/,"")||"/",r=t==="/"?j(ae,"_data/index.json"):j(ae,"_data",`${t}.json`);try{let o=oe(r,"utf-8");return e.json(JSON.parse(o))}catch{return e.json({error:"not found"},404)}});I.use("/*",lr({root:ae,onFound:(e,t)=>{t.header("Cache-Control",e.includes("/assets/")?"public, immutable, max-age=31536000":"no-cache")}}));if(v.output==="static")console.log("[devix] Static mode \u2014 serving pre-generated files from dist/client");else{let e=await _(process.cwd()).catch(()=>null);et(I,{renderModule:ne,apiModule:se,manifest:ie,server:e?.server}),tt(I,{renderModule:ne,apiModule:se,manifest:ie,loaderTimeout:v.loaderTimeout})}cr({fetch:I.fetch,port:ur,hostname:pr},e=>console.log(`http://${e.address}:${e.port}`))});var ct=process.argv[2];switch(ct){case"dev":await Promise.resolve().then(()=>(ce(),xt));break;case"build":await K().then(()=>qe);break;case"generate":await Ye().then(()=>tr);break;case"start":await at().then(()=>fr);break;case"--version":case"-v":{console.log("0.5.1");break}case"--help":case"-h":console.log(`
261
271
  devix \u2014 a lightweight SSR framework
262
272
 
263
273
  Usage:
@@ -273,5 +283,5 @@ Options:
273
283
  Output modes (set in devix.config.ts):
274
284
  output: "server" SSR mode \u2014 devix start handles requests dynamically (default)
275
285
  output: "static" SSG mode \u2014 devix generate pre-renders all pages; devix start serves static files only
276
- `.trim());break;default:console.error(`Unknown command: ${et}`),console.error("Usage: devix <dev|build|generate|start>"),process.exit(1)}
286
+ `.trim());break;default:console.error(`Unknown command: ${ct}`),console.error("Usage: devix <dev|build|generate|start>"),process.exit(1)}
277
287
  //# sourceMappingURL=index.js.map