@lunora/vite 1.0.0-alpha.136 → 1.0.0-alpha.137

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/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import{createRequire as u}from"node:module";import{cloudflare as m}from"@cloudflare/vite-plugin";import{detectAgentRules as d,claimAgentRulesHint as c,AGENT_RULES_HINT as f,detectFramework as p,resolveTargetOrThrow as g}from"@lunora/config";import{detectFramework as lr}from"@lunora/config";import S from"@visulima/vite-overlay";import{g as s}from"./packem_shared/log-DTdeAemA.mjs";import R from"./packem_shared/codegenPlugin-CAs97KEK.mjs";import v from"./packem_shared/containerLogsPlugin-QOsfYAYL.mjs";import k from"./packem_shared/devStatePlugin-CMRBp9zZ.mjs";import h from"./packem_shared/devVariablesPlugin-0SvpKjRJ.mjs";import{createCommandProbe as w,withDevWorkerEnv as P}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{DEV_WORKER_ENV_VALUE as mr,DEV_WORKER_ENV_VAR as dr}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{frameworkComposePlugin as E}from"./packem_shared/CLASS_A_WIRING-CucVpjQI.mjs";import{CLASS_A_WIRING as fr,LUNORA_WORKER_VIRTUAL_ID as pr,buildWorkerEntrySource as gr,isAutoComposable as Sr}from"./packem_shared/CLASS_A_WIRING-CucVpjQI.mjs";import A from"./packem_shared/logStreamPlugin-CFlQAr0R.mjs";import{proxyCheckPlugin as _}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{checkLunoraProxy as vr}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{planViteRemoteBindings as x,remoteBindingsCleanupPlugin as W,remoteBindingsConfigPlugin as C}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{withRemoteBindings as hr}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{lunoraSolutionFinders as V}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{lunoraSolutionFinder as Pr}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{studioPlugin as D}from"./packem_shared/STUDIO_PATH-onjC3IB9.mjs";import{STUDIO_PATH as Ar,buildStudioUrl as _r}from"./packem_shared/STUDIO_PATH-onjC3IB9.mjs";import{withWorkerStartupHint as T}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{WORKER_STARTUP_HINT as Wr,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as Vr}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{wranglerValidatorPlugin as $}from"./packem_shared/wranglerValidatorPlugin-pzoKmqgc.mjs";import{default as Tr}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{reconcileWranglerCrons as yr}from"@lunora/config/cloudflare";const y=e=>({apply:"serve",configureServer(r){return()=>{d(e.projectRoot).installed||!c()||r.config.logger.warn(`
1
+ import{createRequire as u}from"node:module";import{cloudflare as m}from"@cloudflare/vite-plugin";import{detectAgentRules as d,claimAgentRulesHint as c,AGENT_RULES_HINT as f,detectFramework as p,resolveTargetOrThrow as g}from"@lunora/config";import{detectFramework as lr}from"@lunora/config";import S from"@visulima/vite-overlay";import{g as s}from"./packem_shared/log-DTdeAemA.mjs";import R from"./packem_shared/codegenPlugin-Bb24SdIf.mjs";import v from"./packem_shared/containerLogsPlugin-QOsfYAYL.mjs";import k from"./packem_shared/devStatePlugin-CMRBp9zZ.mjs";import h from"./packem_shared/devVariablesPlugin-0SvpKjRJ.mjs";import{createCommandProbe as w,withDevWorkerEnv as P}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{DEV_WORKER_ENV_VALUE as mr,DEV_WORKER_ENV_VAR as dr}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{frameworkComposePlugin as E}from"./packem_shared/CLASS_A_WIRING-CucVpjQI.mjs";import{CLASS_A_WIRING as fr,LUNORA_WORKER_VIRTUAL_ID as pr,buildWorkerEntrySource as gr,isAutoComposable as Sr}from"./packem_shared/CLASS_A_WIRING-CucVpjQI.mjs";import A from"./packem_shared/logStreamPlugin-CFlQAr0R.mjs";import{proxyCheckPlugin as _}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{checkLunoraProxy as vr}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{planViteRemoteBindings as x,remoteBindingsCleanupPlugin as W,remoteBindingsConfigPlugin as C}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{withRemoteBindings as hr}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{lunoraSolutionFinders as V}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{lunoraSolutionFinder as Pr}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{studioPlugin as D}from"./packem_shared/STUDIO_PATH-onjC3IB9.mjs";import{STUDIO_PATH as Ar,buildStudioUrl as _r}from"./packem_shared/STUDIO_PATH-onjC3IB9.mjs";import{withWorkerStartupHint as T}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{WORKER_STARTUP_HINT as Wr,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as Vr}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{wranglerValidatorPlugin as $}from"./packem_shared/wranglerValidatorPlugin-pzoKmqgc.mjs";import{default as Tr}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{reconcileWranglerCrons as yr}from"@lunora/config/cloudflare";const y=e=>({apply:"serve",configureServer(r){return()=>{d(e.projectRoot).installed||!c()||r.config.logger.warn(`
2
2
  ${s(f)}
3
3
  `)}},name:"lunora:agent-rules-hint"}),N=()=>({}),O={astro:"Astro",none:"standalone (SPA / SSR-less)",nuxt:"Nuxt","react-router":"React Router","solid-start":"SolidStart",sveltekit:"SvelteKit","tanstack-start":"TanStack Start","tanstack-start-solid":"TanStack Start (Solid)",vinext:"Next.js on Vite (vinext)"},U=e=>{const r=O[e.framework];return e.framework==="none"?s("no meta-framework detected — running standalone."):e.class==="B"?s(`detected ${r} — composition is handled by the framework adapter.`):s(`detected ${r} — composing the Lunora worker into one Cloudflare Worker.`)},L=(e,r)=>{let t=!1;const o=()=>{r.framework??=p(e.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&r.framework!==void 0&&(t=!0,console.info(U(r.framework)))},name:"lunora:framework-detect"}},b=e=>{if(e===!1)return!1;const r=e===!0||e===void 0?{}:e;return{...r,forwardedConsoleMethods:r.forwardedConsoleMethods??["error","warn"],solutionFinders:[...V,...r.solutionFinders??[]]}},I=e=>{const r=e??{},t=r.schemaDir??"lunora";let o;r.cloudflare===!1?o=!1:r.cloudflare===!0||r.cloudflare===void 0?o={}:o=r.cloudflare;const n=r.projectRoot??process.cwd();return{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess??!1,apiSpec:r.apiSpec??"openapi",cloudflare:o,studio:r.studio??!0,generatedDir:r.generatedDir??`${t}/_generated`,overlay:b(r.overlay),projectRoot:n,schemaDir:t,target:g(n,r.target),validateWrangler:r.validateWrangler??!0}},ar=e=>{const r=I(e),t=N(),{isServe:o,plugin:n}=w(),a=[n,L(r,t),E(r,t),h(r),R(r),A(),k(r),y(r),_()];if(r.studio&&a.push(D()),r.validateWrangler&&a.push($(r)),r.overlay!==!1&&a.push(S(r.overlay)),r.cloudflare!==!1){a.push(v(r));const i=x({projectRoot:r.projectRoot}),l=P(r.cloudflare,o);i.enabled&&(i.configPath!==void 0&&a.push(W(i.cleanup)),a.push(C(l,i))),a.push(...T(m(l)))}return a},nr=u(import.meta.url)("../package.json").version;export{fr as CLASS_A_WIRING,mr as DEV_WORKER_ENV_VALUE,dr as DEV_WORKER_ENV_VAR,Tr as LUNORA_API_UPDATED_EVENT,pr as LUNORA_WORKER_VIRTUAL_ID,Ar as STUDIO_PATH,nr as VERSION,Wr as WORKER_STARTUP_HINT,Cr as augmentWorkerStartupError,_r as buildStudioUrl,gr as buildWorkerEntrySource,vr as checkLunoraProxy,R as codegenPlugin,v as containerLogsPlugin,w as createCommandProbe,lr as detectFramework,k as devStatePlugin,h as devVariablesPlugin,E as frameworkComposePlugin,Sr as isAutoComposable,Vr as isWorkerEntryEvalError,A as logStreamPlugin,ar as lunora,Pr as lunoraSolutionFinder,V as lunoraSolutionFinders,x as planViteRemoteBindings,_ as proxyCheckPlugin,yr as reconcileWranglerCrons,W as remoteBindingsCleanupPlugin,C as remoteBindingsConfigPlugin,b as resolveOverlayOption,D as studioPlugin,P as withDevWorkerEnv,hr as withRemoteBindings,T as withWorkerStartupHint,$ as wranglerValidatorPlugin};
@@ -0,0 +1,3 @@
1
+ import{existsSync as N}from"node:fs";import{join as P,resolve as m,sep as j,basename as M}from"node:path";import{findTsconfig as T,createCodegenProject as G,refreshCodegenProject as B,runCodegen as I,describeErrorLevelFindings as J,CodegenDiagnosticError as V}from"@lunora/codegen";import{LUNORA_CONFIG_FILE as A,inferLunoraBindings as U}from"@lunora/config";import{findWranglerFile as q,readWranglerJsonc as z,WRANGLER_FILES as H,collectWranglerSecretVariables as K,reconcileWranglerBindings as Q,reconcileWranglerCrons as X,reconcileWranglerCompatibilityDate as Y}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as Z}from"vite";import ee from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{s as g,A as C}from"./log-DTdeAemA.mjs";import{r as re,a as oe}from"./server-close-C8zGVydc.mjs";const x=(r,o)=>{try{const{parsed:n,text:e}=z(r);return n===void 0?`raw:${e}`:JSON.stringify(o?o(n):n)}catch{return"unreadable"}},te=r=>{const o={...r},{triggers:n}=o;if(n!==null&&typeof n=="object"){const e={...n};delete e.crons,Object.keys(e).length>0?o.triggers=e:delete o.triggers}return o},S=r=>{const o=q(r),n=o===void 0?"absent":x(o,te),e=P(r,A),c=N(e)?x(e):"absent";return`${n}\0${c}`},ne=100,O=/[/\\]tsconfig\..+\.json$/u,se=r=>{const o=r.map(e=>` • ${e.kind} "${e.exportName}" — class ${e.className} is not exported by your worker entry.`),n=[...new Set(r.map(e=>e.module))].map(e=>` export * from "./lunora/_generated/${e}";`);return[`[lunora] ${String(r.length)} declared ${r.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...o,"","Add to your worker entry:",...n].join(`
2
+ `)},ae=async(r,o,n)=>{try{const e=await U({projectRoot:r.projectRoot,schemaDir:r.schemaDir}),c=Q(r.projectRoot,e);c.changed&&o.info?.(`${g} inferred bindings → ${c.added.join(", ")} (written to ${c.wranglerPath??"wrangler.jsonc"})`);for(const i of c.warnings)o.warn(`${g} ${i}`);c.exportGaps.length>0&&n?.(c.exportGaps)}catch(e){const c=e instanceof Error?e.message:String(e);o.warn(`${g} binding inference skipped: ${c}`)}},ie=(r,o,n)=>{try{const e=X(r,o);e.changed&&n.info?.(`${g} synced ${o.length.toFixed(0)} cron trigger(s) into ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const c=e instanceof Error?e.message:String(e);n.warn(`${g} cron trigger sync skipped: ${c}`)}try{const e=Y(r);e.changed&&n.info?.(`${g} bumped compatibility_date to ${e.date??"unknown"} (Workers Cache enabled) → ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const c=e instanceof Error?e.message:String(e);n.warn(`${g} compatibility date sync skipped: ${c}`)}},ce=r=>{const{advisoryNames:o,platformDiagnosticNames:n}=J(r),e=[...new Set([...o,...n])].toSorted((i,l)=>i.localeCompare(l));if(e.length===0)return;const c=e.length===1?"advisory/platform diagnostic":"advisories/platform diagnostics";return`${g} ${String(e.length)} ERROR-level ${c} (${e.join(", ")}) — see the log above for detail.`},_=(r,o,n,e)=>{const c=P(r.projectRoot,r.schemaDir,"schema.ts");if(!N(c))return o.warn(`${g} schema.ts not found at ${c} — codegen skipped`),{};try{const i=I({apiSpec:r.apiSpec,lunoraDirectory:r.schemaDir,project:e,projectRoot:r.projectRoot,target:r.target,wranglerVariables:K(r.projectRoot)});ie(r.projectRoot,i.cronTriggers,o);for(const l of i.advisories){const f=C(l.level,l.name,l.detail,l.remediation);l.level==="ERROR"?o.error(f):o.warn(f)}for(const l of i.platformDiagnostics){const f=C(l.level==="error"?"ERROR":"WARN",l.name,l.message,l.remediation);l.level==="error"?o.error(f):o.warn(f)}return{blockingMessage:ce(i),outputDirectory:m(i.outputDirectory)}}catch(i){const l=i instanceof Error?i.message:String(i);return o.error(`${g} codegen failed: ${l}`),n?.onError(i,l),{}}},le=(r,o,n)=>{let e;for(const[c,i]of Object.entries(r.environments)){if(c==="client"){e=i;continue}Z(i)||i.hot.send({path:"*",triggeredBy:o,type:"full-reload"})}if(e===void 0){r.hot.send({type:"full-reload"});return}if(n){e.hot.send({type:"full-reload"});return}e.hot.send({event:ee,type:"custom"})},$e=r=>{const o=m(r.projectRoot,r.schemaDir);let n=m(r.projectRoot,r.generatedDir),e;const c=new Map;let i,l=!1,f=!1,E;return{config(t,v){E=v.command},async buildStart(){const t={error:u=>{console.error(u)},info:u=>{console.info(u)},warn:u=>{console.warn(u)}},{blockingMessage:v,outputDirectory:w}=_(r,t);w!==void 0&&(n=w),E==="build"&&v!==void 0&&this.error(v),await ae(r,t,u=>{e?.hot.send({err:{loc:void 0,message:se(u),stack:""},type:"error"})}),e!==void 0&&(i=S(r.projectRoot),l=!0)},configureServer(t){e=t,t.watcher.add(o),i=S(r.projectRoot),l=!1;const v={error:s=>{t.config.logger.error(s)},info:s=>{t.config.logger.info(s)},warn:s=>{t.config.logger.warn(s)}};let w=!1;const u={onError(s,a){w=!0;const d=s instanceof V?{column:s.column,file:s.file,line:s.line}:void 0,b=d===void 0?`[lunora] codegen failed: ${a}
3
+ (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${a}`;e?.hot.send({err:{loc:d,message:b,stack:s instanceof Error?s.stack??"":""},type:"error"})}},R=(s,a)=>s===a||s.startsWith(a+j);let k=!1,h,p;const F=()=>{for(const s of Object.values(t.environments)){const a=s.moduleGraph;for(const d of a.idToModuleMap.values())d.id&&R(d.id,n)&&a.invalidateModule(d)}},$=s=>{const a=m(s);if(O.test(a)){p=void 0;return}if(a.endsWith(`${j}tsconfig.json`)&&a===T(o)){p=void 0;return}R(a,o)&&(R(a,n)||a.endsWith(".ts")&&(a.includes(`${j}__tests__${j}`)||a.endsWith(".test.ts")||a.endsWith(".spec.ts")||(h&&clearTimeout(h),h=setTimeout(()=>{if(h=void 0,k)return;p===void 0?p=G(o):B(p,o);const{outputDirectory:d}=_(r,v,u,p);if(d===void 0){p=void 0;return}n=d,F(),le(t,a,w),w=!1},ne))))},D=s=>{const a=m(s);(a.endsWith(`${j}tsconfig.json`)||O.test(a))&&(p=void 0)};t.watcher.on("add",$),t.watcher.on("change",$),t.watcher.on("unlink",$),t.watcher.on("unlink",D);const W=new Set([...H.map(s=>m(r.projectRoot,s)),m(r.projectRoot,A)]);for(const s of W)t.watcher.add(s);const y=s=>{if(!W.has(m(s))||f)return;const a=S(r.projectRoot);if(!l){i=a;return}if(i===void 0){i=a;return}a!==i&&(i=a,f=!0,t.config.logger.info(`${g} ${M(m(s))} changed — restarting dev server`),Promise.resolve(t.restart()).finally(()=>{f=!1}).catch(d=>{const b=d instanceof Error?d.message:String(d);t.config.logger.error(`${g} dev server restart failed: ${b} — keeping the running server; re-save your config to retry.`),t.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${b}`,stack:""},type:"error"})}))};t.watcher.on("add",y),t.watcher.on("change",y),t.watcher.on("unlink",y);const L=()=>{k||(k=!0,p=void 0,h&&(clearTimeout(h),h=void 0),t.watcher.off("add",$),t.watcher.off("change",$),t.watcher.off("unlink",$),t.watcher.off("unlink",D),t.watcher.off("add",y),t.watcher.off("change",y),t.watcher.off("unlink",y))};return()=>{oe(t,c,L)}},buildEnd(){re(c,this.environment)},name:"lunora:codegen"}};export{$e as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/vite",
3
- "version": "1.0.0-alpha.136",
3
+ "version": "1.0.0-alpha.137",
4
4
  "description": "The Lunora Vite plugin: codegen, type sync, wrangler validation, and an error overlay over @cloudflare/vite-plugin",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,11 +46,10 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@cloudflare/vite-plugin": "1.47.0",
49
- "@lunora/codegen": "1.0.0-alpha.107",
50
- "@lunora/config": "1.0.0-alpha.136",
49
+ "@lunora/codegen": "1.0.0-alpha.108",
50
+ "@lunora/config": "1.0.0-alpha.137",
51
51
  "@lunora/errors": "1.0.0-alpha.21",
52
52
  "@visulima/vite-overlay": "2.0.5",
53
- "jsonc-parser": "^3.3.1",
54
53
  "ts-morph": "^28.0.0"
55
54
  },
56
55
  "peerDependencies": {
@@ -1,3 +0,0 @@
1
- import{existsSync as O}from"node:fs";import{join as _,resolve as p,sep as b,basename as L}from"node:path";import{createCodegenProject as M,refreshCodegenProject as A,runCodegen as G,describeErrorLevelFindings as T,CodegenDiagnosticError as B}from"@lunora/codegen";import{LUNORA_CONFIG_FILE as N,inferLunoraBindings as I}from"@lunora/config";import{findWranglerFile as J,readWranglerJsonc as V,WRANGLER_FILES as U,collectWranglerSecretVariables as X,reconcileWranglerBindings as Y,reconcileWranglerCrons as Z,reconcileWranglerCompatibilityDate as q}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as z}from"vite";import H from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{s as g,A as W}from"./log-DTdeAemA.mjs";import{r as K,a as Q}from"./server-close-C8zGVydc.mjs";const C=(r,o)=>{try{const{parsed:t,text:e}=V(r);return t===void 0?`raw:${e}`:JSON.stringify(o?o(t):t)}catch{return"unreadable"}},ee=r=>{const o={...r},{triggers:t}=o;if(t!==null&&typeof t=="object"){const e={...t};delete e.crons,Object.keys(e).length>0?o.triggers=e:delete o.triggers}return o},S=r=>{const o=J(r),t=o===void 0?"absent":C(o,ee),e=_(r,N),i=O(e)?C(e):"absent";return`${t}\0${i}`},re=100,oe=/[/\\]tsconfig\..+\.json$/u,te=r=>{const o=r.map(e=>` • ${e.kind} "${e.exportName}" — class ${e.className} is not exported by your worker entry.`),t=[...new Set(r.map(e=>e.module))].map(e=>` export * from "./lunora/_generated/${e}";`);return[`[lunora] ${String(r.length)} declared ${r.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...o,"","Add to your worker entry:",...t].join(`
2
- `)},ne=async(r,o,t)=>{try{const e=await I({projectRoot:r.projectRoot,schemaDir:r.schemaDir}),i=Y(r.projectRoot,e);i.changed&&o.info?.(`${g} inferred bindings → ${i.added.join(", ")} (written to ${i.wranglerPath??"wrangler.jsonc"})`);for(const s of i.warnings)o.warn(`${g} ${s}`);i.exportGaps.length>0&&t?.(i.exportGaps)}catch(e){const i=e instanceof Error?e.message:String(e);o.warn(`${g} binding inference skipped: ${i}`)}},se=(r,o,t)=>{try{const e=Z(r,o);e.changed&&t.info?.(`${g} synced ${o.length.toFixed(0)} cron trigger(s) into ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const i=e instanceof Error?e.message:String(e);t.warn(`${g} cron trigger sync skipped: ${i}`)}try{const e=q(r);e.changed&&t.info?.(`${g} bumped compatibility_date to ${e.date??"unknown"} (Workers Cache enabled) → ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const i=e instanceof Error?e.message:String(e);t.warn(`${g} compatibility date sync skipped: ${i}`)}},ae=r=>{const{advisoryNames:o,platformDiagnosticNames:t}=T(r),e=[...new Set([...o,...t])].toSorted((s,l)=>s.localeCompare(l));if(e.length===0)return;const i=e.length===1?"advisory/platform diagnostic":"advisories/platform diagnostics";return`${g} ${String(e.length)} ERROR-level ${i} (${e.join(", ")}) — see the log above for detail.`},x=(r,o,t,e)=>{const i=_(r.projectRoot,r.schemaDir,"schema.ts");if(!O(i))return o.warn(`${g} schema.ts not found at ${i} — codegen skipped`),{};try{const s=G({apiSpec:r.apiSpec,lunoraDirectory:r.schemaDir,project:e,projectRoot:r.projectRoot,target:r.target,wranglerVariables:X(r.projectRoot)});se(r.projectRoot,s.cronTriggers,o);for(const l of s.advisories){const f=W(l.level,l.name,l.detail,l.remediation);l.level==="ERROR"?o.error(f):o.warn(f)}for(const l of s.platformDiagnostics){const f=W(l.level==="error"?"ERROR":"WARN",l.name,l.message,l.remediation);l.level==="error"?o.error(f):o.warn(f)}return{blockingMessage:ae(s),outputDirectory:p(s.outputDirectory)}}catch(s){const l=s instanceof Error?s.message:String(s);return o.error(`${g} codegen failed: ${l}`),t?.onError(s,l),{}}},ie=(r,o,t)=>{let e;for(const[i,s]of Object.entries(r.environments)){if(i==="client"){e=s;continue}z(s)||s.hot.send({path:"*",triggeredBy:o,type:"full-reload"})}if(e===void 0){r.hot.send({type:"full-reload"});return}if(t){e.hot.send({type:"full-reload"});return}e.hot.send({event:H,type:"custom"})},ve=r=>{const o=p(r.projectRoot,r.schemaDir);let t=p(r.projectRoot,r.generatedDir),e;const i=new Map;let s,l=!1,f=!1,E;return{config(n,v){E=v.command},async buildStart(){const n={error:u=>{console.error(u)},info:u=>{console.info(u)},warn:u=>{console.warn(u)}},{blockingMessage:v,outputDirectory:w}=x(r,n);w!==void 0&&(t=w),E==="build"&&v!==void 0&&this.error(v),await ne(r,n,u=>{e?.hot.send({err:{loc:void 0,message:te(u),stack:""},type:"error"})}),e!==void 0&&(s=S(r.projectRoot),l=!0)},configureServer(n){e=n,n.watcher.add(o),s=S(r.projectRoot),l=!1;const v={error:a=>{n.config.logger.error(a)},info:a=>{n.config.logger.info(a)},warn:a=>{n.config.logger.warn(a)}};let w=!1;const u={onError(a,c){w=!0;const d=a instanceof B?{column:a.column,file:a.file,line:a.line}:void 0,j=d===void 0?`[lunora] codegen failed: ${c}
3
- (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${c}`;e?.hot.send({err:{loc:d,message:j,stack:a instanceof Error?a.stack??"":""},type:"error"})}},R=(a,c)=>a===c||a.startsWith(c+b);let k=!1,m,h;const P=()=>{for(const a of Object.values(n.environments)){const c=a.moduleGraph;for(const d of c.idToModuleMap.values())d.id&&R(d.id,t)&&c.invalidateModule(d)}},$=a=>{const c=p(a);if(R(c,o)&&!R(c,t)){if(c.endsWith(`${b}tsconfig.json`)||oe.test(c)){h=void 0;return}c.endsWith(".ts")&&(c.includes(`${b}__tests__${b}`)||c.endsWith(".test.ts")||c.endsWith(".spec.ts")||(m&&clearTimeout(m),m=setTimeout(()=>{if(m=void 0,k)return;h===void 0?h=M(o):A(h,o);const{outputDirectory:d}=x(r,v,u,h);if(d===void 0){h=void 0;return}t=d,P(),ie(n,c,w),w=!1},re)))}};n.watcher.on("add",$),n.watcher.on("change",$),n.watcher.on("unlink",$);const D=new Set([...U.map(a=>p(r.projectRoot,a)),p(r.projectRoot,N)]);for(const a of D)n.watcher.add(a);const y=a=>{if(!D.has(p(a))||f)return;const c=S(r.projectRoot);if(!l){s=c;return}if(s===void 0){s=c;return}c!==s&&(s=c,f=!0,n.config.logger.info(`${g} ${L(p(a))} changed — restarting dev server`),Promise.resolve(n.restart()).finally(()=>{f=!1}).catch(d=>{const j=d instanceof Error?d.message:String(d);n.config.logger.error(`${g} dev server restart failed: ${j} — keeping the running server; re-save your config to retry.`),n.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${j}`,stack:""},type:"error"})}))};n.watcher.on("add",y),n.watcher.on("change",y),n.watcher.on("unlink",y);const F=()=>{k||(k=!0,h=void 0,m&&(clearTimeout(m),m=void 0),n.watcher.off("add",$),n.watcher.off("change",$),n.watcher.off("unlink",$),n.watcher.off("add",y),n.watcher.off("change",y),n.watcher.off("unlink",y))};return()=>{Q(n,i,F)}},buildEnd(){K(i,this.environment)},name:"lunora:codegen"}};export{ve as default};