@lunora/vite 1.0.0-alpha.354 → 1.0.0-alpha.356

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 E}from"node:module";import{resolve as k}from"node:path";import{cloudflare as b}from"@cloudflare/vite-plugin";import{resolveDeployDriver as W,startCelldDevSession as O,formatLunoraEvent as D,lunoraLine as L,detectFramework as $,targetRunsOwnDevServer as j,resolveLazyFunctions as F,resolveTargetOrThrow as U,isRunnableTarget as N,runnableTargetIds as I}from"@lunora/config";import{GENERATED_CLASS_MODULES as ir,detectFramework as ar}from"@lunora/config";import M from"@visulima/vite-overlay";import{detectAgentRules as B,claimAgentRulesHint as H,lunoraLine as d,AGENT_RULES_HINT as V}from"@lunora/config/cli";import{reconcileBindingsSafely as G,findWranglerFile as K,readWranglerJsonc as z,warnCloudflareCliConfigOnce as q,hasCloudflareCredentials as J,withheldBindings as Q,describeWithheld as X,startLocalHyperdrive as Y}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as lr}from"@lunora/config/cloudflare";import{r as A,a as C}from"./packem_shared/server-close-DWiO4Vxb.mjs";import Z from"./packem_shared/codegenPlugin-B9ggEipn.mjs";import ee from"./packem_shared/containerLogsPlugin-BCqWF6EU.mjs";import re from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import oe from"./packem_shared/devVariablesPlugin-DbD6cSF0.mjs";import{frameworkComposePlugin as te}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import{CLASS_A_WIRING as ur,LUNORA_WORKER_VIRTUAL_ID as dr,buildWorkerEntrySource as fr,isAutoComposable as pr}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import ne from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as ie}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as mr}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as ae}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{planViteRemoteBindings as hr,withRemoteBindings as wr}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{readServiceBindings as se}from"@lunora/codegen";import{lunoraSolutionFinders as le}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as yr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as ce}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{buildStudioUrl as Rr}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{withWorkerStartupHint as ue}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as Ar,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as xr}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as de}from"./packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs";import{default as _r}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as br}from"@lunora/config/studio-host";const fe=r=>({apply:"serve",configureServer(e){return()=>{B(r.projectRoot).installed||!H()||e.config.logger.warn(`
1
+ import{createRequire as E}from"node:module";import{resolve as k}from"node:path";import{cloudflare as b}from"@cloudflare/vite-plugin";import{resolveDeployDriver as W,startCelldDevSession as O,formatLunoraEvent as D,lunoraLine as L,detectFramework as $,targetRunsOwnDevServer as j,resolveLazyFunctions as F,resolveTargetOrThrow as U,isRunnableTarget as N,runnableTargetIds as I}from"@lunora/config";import{GENERATED_CLASS_MODULES as ir,detectFramework as ar}from"@lunora/config";import M from"@visulima/vite-overlay";import{detectAgentRules as B,claimAgentRulesHint as H,lunoraLine as d,AGENT_RULES_HINT as V}from"@lunora/config/cli";import{reconcileBindingsSafely as G,findWranglerFile as K,readWranglerJsonc as z,warnCloudflareCliConfigOnce as q,hasCloudflareCredentials as J,withheldBindings as Q,describeWithheld as X,startLocalHyperdrive as Y}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as lr}from"@lunora/config/cloudflare";import{r as A,a as C}from"./packem_shared/server-close-DWiO4Vxb.mjs";import Z from"./packem_shared/codegenPlugin-C5-M07Rw.mjs";import ee from"./packem_shared/containerLogsPlugin-BCqWF6EU.mjs";import re from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import oe from"./packem_shared/devVariablesPlugin-DbD6cSF0.mjs";import{frameworkComposePlugin as te}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import{CLASS_A_WIRING as ur,LUNORA_WORKER_VIRTUAL_ID as dr,buildWorkerEntrySource as fr,isAutoComposable as pr}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import ne from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as ie}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as mr}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as ae}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{planViteRemoteBindings as hr,withRemoteBindings as wr}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{readServiceBindings as se}from"@lunora/codegen";import{lunoraSolutionFinders as le}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as yr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as ce}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{buildStudioUrl as Rr}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{withWorkerStartupHint as ue}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as Ar,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as xr}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as de}from"./packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs";import{default as _r}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as br}from"@lunora/config/studio-host";const fe=r=>({apply:"serve",configureServer(e){return()=>{B(r.projectRoot).installed||!H()||e.config.logger.warn(`
2
2
  ${d(V)}
3
3
  `)}},name:"lunora:agent-rules-hint"}),pe=r=>({async config(e,o){o.isPreview!==!0&&await G(r,{info:t=>{console.info(t)},warn:t=>{console.warn(t)}})},enforce:"pre",name:"lunora:bindings-provision"}),h="/_lunora",ge=8787,f=new Map,x=r=>r.command==="serve"&&r.isPreview!==!0,me=(r,e)=>{let o;return()=>{if(o===void 0)try{W(e).projectConfig?.(r,"dev"),o={runs:!0}}catch(t){o={reason:t instanceof Error?t.message:String(t),runs:!1}}return o}},ve=r=>{const e=K(r),o=e===void 0?void 0:z(e).parsed?.dev?.port;return typeof o=="number"?o:ge},he=(r,e)=>r.map(o=>{const t=o.apply;return{...o,apply:(n,i)=>x(i)&&e()?!1:typeof t=="function"?t(n,i):t===void 0||t===i.command}}),we=(r,e,{stream:o,tag:t})=>{const n=D(e);n!==void 0?r[n.level](`[lunora] ${n.text}`):o==="stderr"?r.warn(`[${t}] ${e}`):r.info(`[${t}] ${e}`)},Se=(r,e)=>{const o=ve(r),t=new Map;return{apply:(n,i)=>x(i)&&e(),buildEnd(){C(t,this.environment)},config:n=>{if(n.server?.proxy?.[h]===void 0)return{server:{proxy:{[h]:{changeOrigin:!0,target:`http://127.0.0.1:${String(o)}`,ws:!0}}}}},async configureServer(n){const{logger:i}=n.config;await f.get(r)?.stop(),f.delete(r),i.info(`[lunora] starting the worker on celld at http://127.0.0.1:${String(o)} …`);const l=await O({log:(a,c)=>{we(i,a,c)},port:o,projectRoot:r});f.set(r,l);const s=a=>{i.error(`[lunora] the worker on celld exited (code ${String(a)}) — restart vite dev to bring it back`)};l.exited.then(s).catch(()=>{}),A(n,t,()=>{f.get(r)===l&&f.delete(r),l.stop().catch(a=>{i.error(`[lunora] stopping celld failed: ${a instanceof Error?a.message:String(a)}`)})})},name:"lunora:celld-dev"}},ye=r=>({configResolved(e){q(r.projectRoot,o=>{e.logger.warn(L(o))})},name:"lunora:cf-config-warning"}),Pe=()=>({}),Re={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)"},ke=r=>{const e=Re[r.framework];return r.framework==="none"?d("no meta-framework detected — running standalone."):r.class==="B"?d(`detected ${e} — composition is handled by the framework adapter.`):d(`detected ${e} — composing the Lunora worker into one Cloudflare Worker.`)},Ae=(r,e)=>{let o=!1;const t=()=>{e.framework??=$(r.projectRoot)};return{config(){t()},configResolved(){t()},configureServer(){t(),!o&&e.framework!==void 0&&(o=!0,console.info(ke(e.framework)))},name:"lunora:framework-detect"}},w=r=>Array.isArray(r)?r:[],v=new WeakSet,Ce=(r,e={})=>{let o=!1;const t=r.experimental?.newConfig,n=t!==void 0&&t!==!1,i=e.hasCredentials??(()=>J({projectRoot:e.projectRoot})),l=s=>{const a=(c,...u)=>{const p=typeof s=="function"?s(c,...u):s,g=p===void 0?void 0:{...p},T=o?[...w(c.artifacts),...w(g?.artifacts)]:[],_=o?Q({ai:c.ai??g?.ai,artifacts:T},i):[];for(const m of _)Reflect.deleteProperty(c,m.kind),Reflect.deleteProperty(g??{},m.kind),console.warn(d(X(m)));return g};return v.add(a),a};return{config(s,a){if(o=a.command==="serve"&&a.isPreview!==!0,n)return;const c=r;v.has(c.config)||(c.config=l(c.config)),Array.isArray(c.auxiliaryWorkers)&&(c.auxiliaryWorkers=c.auxiliaryWorkers.map(u=>v.has(u.config)?u:{...u,config:l(u.config)}))},enforce:"pre",name:"lunora:local-ai-binding"}},xe=5e3,Te=3e4,S=new Map,y=r=>{const e=S.get(r);if(e!==void 0)return e;const o={databases:[],pending:Promise.resolve(),servers:0,stopping:Promise.resolve()};return S.set(r,o),o},_e=async r=>{const e=r.databases.splice(0);await Promise.allSettled(e.map(async o=>o.stop()))},P=(r,e)=>{const o=setTimeout(()=>{r.pending.then(async()=>{r.servers===0&&(r.stopping=_e(r),await r.stopping)}).catch(()=>{})},e);return o.unref(),o},R=({projectRoot:r,start:e=Y,wranglerConfigPath:o})=>{const t=new Map,n=i=>{const l=y(r);let s=!1;l.servers+=1,clearTimeout(l.stopTimer),i(()=>{s||(s=!0,l.servers-=1,l.servers===0&&(l.stopTimer=P(l,xe)))})};return{async config(i,l){if(l.command!=="serve")return;const s=y(r);clearTimeout(s.stopTimer);const a=s.pending,c=(async()=>{await a,await s.stopping;const u=await e({onWarning:p=>{console.warn(d(p))},projectRoot:r,wranglerConfigPath:o});u!==void 0&&s.databases.push(u),u!==void 0&&u.bindings.length>0&&console.info(d(`Hyperdrive ${u.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite.`))})();s.pending=c.catch(()=>{});try{await c}finally{s.servers===0&&(clearTimeout(s.stopTimer),s.stopTimer=P(s,Te))}},buildEnd(){C(t,this.environment)},configureServer(i){n(l=>{A(i,t,l)})},configurePreviewServer(i){n(l=>{i.httpServer.once("close",l)})},enforce:"pre",name:"lunora:local-hyperdrive"}},Ee=(r,e)=>({config(o,t){if(t.command!=="serve")return;const{services:n}=se(e),i=Array.isArray(r.auxiliaryWorkers)?r.auxiliaryWorkers:[],l=new Set(i.map(a=>a.configPath===void 0?"":k(e,a.configPath))),s=[...new Set(n.map(a=>a.wranglerPath))].filter(a=>!l.has(a)).map(a=>({configPath:a}));s.length>0&&(r.auxiliaryWorkers=[...i,...s])},enforce:"pre",name:"lunora:service-workers"}),be=r=>{if(r===!1)return!1;const e=r===!0||r===void 0?{}:r;return{...e,forwardedConsoleMethods:e.forwardedConsoleMethods??["error","warn"],solutionFinders:[...le,...e.solutionFinders??[]]}},We=(r,e)=>{const o=U(r,e);if(!N(o)){const t=I();throw new Error(`target "${o}" has no command-line toolchain, so the Lunora Vite plugin cannot build or serve it — it can only generate for it (\`lunora codegen --target ${o}\`). Buildable targets: ${t.join(", ")}`)}return o},Oe=r=>{const e=r??{},o=e.schemaDir??"lunora";let t;e.cloudflare===!1?t=!1:e.cloudflare===!0||e.cloudflare===void 0?t={}:t=e.cloudflare;const n=e.projectRoot??process.cwd(),i=We(n,e.target);return{allowUnauthenticatedShardAccess:e.allowUnauthenticatedShardAccess??!1,apiSpec:e.apiSpec??"openapi",lazyFunctions:F(e.lazyFunctions),cloudflare:t,studio:e.studio??!0,generatedDir:`${o}/_generated`,overlay:be(e.overlay),projectRoot:n,schemaDir:o,shard:e.shard??{},target:i,validateWrangler:e.validateWrangler??!0}},De=(r,e)=>{const{configPath:o}=r;return typeof o=="string"&&o!==""?k(e,o):void 0},rr=r=>{const e=Oe(r),o=Pe(),t=[Ae(e,o),te(e,o),oe(e),pe(e),Z(e),ne(),re(e),fe(e),ye(e),ie()];e.studio&&t.push(ce(e)),e.validateWrangler&&t.push(de(e)),e.overlay!==!1&&t.push(M(e.overlay)),t.push(ee(e));const n=e.cloudflare===!1?void 0:{...e.cloudflare};if(t.push(ae(n,{projectRoot:e.projectRoot})),n===void 0&&t.push(R({projectRoot:e.projectRoot})),n!==void 0){t.push(Ee(n,e.projectRoot));const i=j(e.target),l=me(e.projectRoot,e.target),s=()=>i&&l().runs;t.push(...he([R({projectRoot:e.projectRoot,wranglerConfigPath:De(n,e.projectRoot)}),Ce(n,{projectRoot:e.projectRoot}),...ue(b(n))],s)),i&&t.push(Se(e.projectRoot,s),{apply:(a,c)=>c.command==="serve"&&c.isPreview!==!0&&!s(),configureServer(a){a.config.logger.warn(`[lunora] target "${e.target}": vite dev serves the worker in workerd, not on ${e.target} — ${l().reason??"it cannot run this project"}. \`vite build\` then \`lunora deploy\` ships it to ${e.target}.`)},name:"lunora:target-runtime-notice"})}return t},or=E(import.meta.url)("../package.json").version;export{ur as CLASS_A_WIRING,ir as GENERATED_CLASS_MODULES,_r as LUNORA_API_UPDATED_EVENT,dr as LUNORA_WORKER_VIRTUAL_ID,br as STUDIO_PATH,or as VERSION,Ar as WORKER_STARTUP_HINT,Cr as augmentWorkerStartupError,Rr as buildStudioUrl,fr as buildWorkerEntrySource,mr as checkLunoraProxy,Z as codegenPlugin,ee as containerLogsPlugin,ar as detectFramework,re as devStatePlugin,oe as devVariablesPlugin,te as frameworkComposePlugin,pr as isAutoComposable,xr as isWorkerEntryEvalError,ne as logStreamPlugin,rr as lunora,yr as lunoraSolutionFinder,le as lunoraSolutionFinders,hr as planViteRemoteBindings,ie as proxyCheckPlugin,lr as reconcileWranglerCrons,ae as remoteBindingsPlugin,be as resolveOverlayOption,ce as studioPlugin,wr as withRemoteBindings,ue as withWorkerStartupHint,de as wranglerValidatorPlugin};
@@ -0,0 +1,3 @@
1
+ import{readFileSync as Q,existsSync as Y}from"node:fs";import{resolve as h,dirname as Z,sep as C,basename as A,join as z,relative as ee}from"node:path";import{findProjectConfigFile as ne,readServiceBindings as te,PROJECT_CONFIG_FILENAMES as I,projectConfigCandidatePaths as G,runCodegen as re,findTsconfig as oe,isTestPath as ie,fingerprintSchemaSources as L,createCodegenProject as ce,refreshCodegenProject as ae,CodegenDiagnosticError as se}from"@lunora/codegen";import{LUNORA_TAG as m,isCodegenDisabled as le,CODEGEN_ENV as W,runPostCodegenHook as U,reportCodegenFindings as de,blockingFindingsMessage as fe}from"@lunora/config";import{findWranglerFile as ge,readWranglerJsonc as ue,WRANGLER_FILES as he,reconcileBindingsSafely as me,wranglerCodegenInputs as pe,reconcileWranglerExtras as we}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as ye}from"vite";import{createHash as ve}from"node:crypto";import Se from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as Ee,r as Re}from"./server-close-DWiO4Vxb.mjs";const $e=(e,t)=>{try{const{parsed:i,text:r}=ue(e);return i===void 0?`raw:${r}`:JSON.stringify(t?t(i):i)}catch{return"unreadable"}},Ce=e=>{const t={...e},{triggers:i}=t;if(i!==null&&typeof i=="object"){const r={...i};delete r.crons,Object.keys(r).length>0?t.triggers=r:delete t.triggers}return t},F=e=>{const t=ge(e),i=t===void 0?"absent":$e(t,Ce),r=ne(e);let l="absent";try{r!==void 0&&(l=ve("sha256").update(Q(r)).digest("hex"))}catch{}return`${i}\0${l}`},ke=100,V=300,B=2,je=e=>{let t,i,r=0;const l=()=>{t&&(clearTimeout(t),t=void 0)},a=(u,f)=>{i&&clearTimeout(i),i=setTimeout(()=>{if(i=void 0,e.fingerprint()!==u){if(r+=1,r>B){e.logger.warn(`${m} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(B)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${m} schema changed while \`postcodegen\` was running — regenerating`),f()}},V)},d=u=>{e.regenerate(u,f=>{a(f,()=>{d(u)})})};return{cancelPending:l,dispose:()=>{l(),i&&(clearTimeout(i),i=void 0)},onSave:u=>{l(),r=0,t=setTimeout(()=>{t=void 0,d(u)},ke)}}},J=/[/\\]tsconfig\..+\.json$/u,be=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,De=e=>{const t=e.map(r=>` • ${r.kind} "${r.exportName}" — class ${r.className} is not exported by your worker entry.`),i=[...new Set(e.map(r=>r.module))].map(r=>` export * from "./lunora/_generated/${r}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...t,"","Add to your worker entry:",...i].join(`
2
+ `)},Te=(e,t,i)=>{if(t.warn(`${m} schema.ts not found at ${e} — codegen skipped`),i!==void 0){const r=`schema.ts not found at ${e} — generated output is now stale`;i.onError(new Error(r),r)}},M=(e,t,i,r)=>{const l=z(e.projectRoot,e.schemaDir,"schema.ts");if(!Y(l))return Te(l,t,i),{};try{const a=re({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:r,projectRoot:e.projectRoot,target:e.target,...pe(e.projectRoot)});return we(e.projectRoot,a.cronTriggers,t),de(a,t),{blockingMessage:fe(a),outputDirectory:h(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return t.error(`${m} codegen failed: ${d}`),i?.onError(a,d),{failure:`${m} codegen failed: ${d}`}}},Pe=(e,t,i)=>{let r;for(const[l,a]of Object.entries(e.environments)){if(l==="client"){r=a;continue}ye(a)||a.hot.send({path:"*",triggeredBy:t,type:"full-reload"})}if(r===void 0){e.hot.send({type:"full-reload"});return}if(i){r.hot.send({type:"full-reload"});return}r.hot.send({event:Se,type:"custom"})},j={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Le=e=>{const t=h(e.projectRoot,e.schemaDir),i=le(process.env[W]);let r=h(e.projectRoot,e.generatedDir),l=0,a=!1,d;const u=new Map;let f,b=!1,D=!1,S,T;return{config(o,y){S=y.command},configResolved(){S!=="build"&&i||(T=M(e,j))},async buildStart(){const o=S!=="build"&&i,{blockingMessage:y,failure:v,outputDirectory:E}=T??(o?{}:M(e,j));if(T=void 0,S==="build"&&v!==void 0&&this.error(v),E!==void 0){r=E,a=!0;let p;try{p=await U({cwd:e.projectRoot,logger:j})}finally{a=!1}p.ran&&(l=Date.now()),S==="build"&&p.error!==void 0&&this.error(p.error)}S==="build"&&y!==void 0&&this.error(y),await me(e,j,p=>{d?.hot.send({err:{loc:void 0,message:De(p),stack:""},type:"error"})}),d!==void 0&&(f=F(e.projectRoot),b=!0)},configureServer(o){d=o,o.watcher.add(t);const y=te(e.projectRoot).services.filter(n=>n.rpcEntrypoint!==void 0).map(n=>Z(n.wranglerPath));o.watcher.add(y),f=F(e.projectRoot),b=!1;const v={error:n=>{o.config.logger.error(n)},info:n=>{o.config.logger.info(n)},warn:n=>{o.config.logger.warn(n)}};let E=!1;const p={onError(n,c){E=!0;const s=n instanceof se?{column:n.column,file:n.file,line:n.line}:void 0,w=s===void 0?`[lunora] codegen failed: ${c}
3
+ (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${c}`;d?.hot.send({err:{loc:s,message:w,stack:n instanceof Error?n.stack??"":""},type:"error"})}},k=(n,c)=>n===c||n.startsWith(c+C);let P=!1,g;const H=()=>{for(const n of Object.values(o.environments)){const c=n.moduleGraph;for(const s of c.idToModuleMap.values())s.id&&k(s.id,r)&&c.invalidateModule(s)}},K=async(n,c)=>{try{if(P)return;g===void 0?g=ce(t):ae(g,t);const{outputDirectory:s}=M(e,v,p,g);if(s===void 0){g=void 0;return}r=s;const w=L(t);a=!0;let O;try{O=await U({cwd:e.projectRoot,logger:v})}finally{a=!1}if(O.ran&&(l=Date.now(),c(w)),O.error!==void 0)return;H(),Pe(o,n,E),E=!1}catch(s){v.error(`${m} codegen watch: ${s instanceof Error?s.message:String(s)}`)}},_=je({fingerprint:()=>L(t),logger:v,regenerate:(n,c)=>{K(n,c)}}),X=n=>J.test(n)||I.includes(A(n))&&G(t).includes(n)||n.endsWith(`${C}tsconfig.json`)&&n===oe(t)?(g=void 0,!1):!(!k(n,t)||k(n,r)||!n.endsWith(".ts")||ie(ee(t,n).split(C).join("/"))),R=n=>{const c=h(n);if(!(!(be.test(c)&&!c.includes(`${C}node_modules${C}`)&&y.some(w=>k(c,w)))&&!X(c))){if(a||Date.now()-l<V){_.cancelPending();return}_.onSave(c)}},N=n=>{const c=h(n);(c.endsWith(`${C}tsconfig.json`)||J.test(c))&&(g=void 0)};i?o.config.logger.info(`${m} codegen watch disabled (${W}) — _generated/ is written only by an explicit \`lunora codegen\``):(o.watcher.on("add",R),o.watcher.on("change",R),o.watcher.on("unlink",R),o.watcher.on("unlink",N));const x=new Set([...he.map(n=>h(e.projectRoot,n)),...I.map(n=>h(e.projectRoot,n)),...G(t)]);for(const n of x)o.watcher.add(n);const $=n=>{if(!x.has(h(n))||D)return;const c=F(e.projectRoot);if(!b){f=c;return}if(f===void 0){f=c;return}c!==f&&(f=c,D=!0,o.config.logger.info(`${m} ${A(h(n))} changed — restarting dev server`),Promise.resolve(o.restart()).finally(()=>{D=!1}).catch(s=>{const w=s instanceof Error?s.message:String(s);o.config.logger.error(`${m} dev server restart failed: ${w} — keeping the running server; re-save your config to retry.`),o.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${w}`,stack:""},type:"error"})}))};o.watcher.on("add",$),o.watcher.on("change",$),o.watcher.on("unlink",$);const q=()=>{P||(P=!0,g=void 0,_.dispose(),o.watcher.off("add",R),o.watcher.off("change",R),o.watcher.off("unlink",R),o.watcher.off("unlink",N),o.watcher.off("add",$),o.watcher.off("change",$),o.watcher.off("unlink",$))};return()=>{Re(o,u,q)}},buildEnd(){Ee(u,this.environment)},name:"lunora:codegen"}};export{Le as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/vite",
3
- "version": "1.0.0-alpha.354",
3
+ "version": "1.0.0-alpha.356",
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,8 +46,8 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@cloudflare/vite-plugin": "1.63.1",
49
- "@lunora/codegen": "1.0.0-alpha.330",
50
- "@lunora/config": "1.0.0-alpha.380",
49
+ "@lunora/codegen": "1.0.0-alpha.333",
50
+ "@lunora/config": "1.0.0-alpha.382",
51
51
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
52
52
  "@visulima/vite-overlay": "2.0.41"
53
53
  },
@@ -1,3 +0,0 @@
1
- import{readFileSync as K,existsSync as X}from"node:fs";import{resolve as h,dirname as q,sep as k,basename as Q,join as Y,relative as Z}from"node:path";import{findProjectConfigFile as z,readServiceBindings as ee,PROJECT_CONFIG_FILENAMES as ne,runCodegen as te,findTsconfig as re,isTestPath as oe,fingerprintSchemaSources as A,createCodegenProject as ie,refreshCodegenProject as ce,CodegenDiagnosticError as ae}from"@lunora/codegen";import{LUNORA_TAG as m,isCodegenDisabled as se,CODEGEN_ENV as I,runPostCodegenHook as G,reportCodegenFindings as le,blockingFindingsMessage as de}from"@lunora/config";import{findWranglerFile as fe,readWranglerJsonc as ge,WRANGLER_FILES as ue,reconcileBindingsSafely as he,wranglerCodegenInputs as me,reconcileWranglerExtras as pe}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as we}from"vite";import{createHash as ye}from"node:crypto";import ve from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as Se,r as Ee}from"./server-close-DWiO4Vxb.mjs";const Re=(e,t)=>{try{const{parsed:i,text:r}=ge(e);return i===void 0?`raw:${r}`:JSON.stringify(t?t(i):i)}catch{return"unreadable"}},$e=e=>{const t={...e},{triggers:i}=t;if(i!==null&&typeof i=="object"){const r={...i};delete r.crons,Object.keys(r).length>0?t.triggers=r:delete t.triggers}return t},F=e=>{const t=fe(e),i=t===void 0?"absent":Re(t,$e),r=z(e);let l="absent";try{r!==void 0&&(l=ye("sha256").update(K(r)).digest("hex"))}catch{}return`${i}\0${l}`},ke=100,U=300,L=2,Ce=e=>{let t,i,r=0;const l=()=>{t&&(clearTimeout(t),t=void 0)},a=(g,f)=>{i&&clearTimeout(i),i=setTimeout(()=>{if(i=void 0,e.fingerprint()!==g){if(r+=1,r>L){e.logger.warn(`${m} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(L)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${m} schema changed while \`postcodegen\` was running — regenerating`),f()}},U)},d=g=>{e.regenerate(g,f=>{a(f,()=>{d(g)})})};return{cancelPending:l,dispose:()=>{l(),i&&(clearTimeout(i),i=void 0)},onSave:g=>{l(),r=0,t=setTimeout(()=>{t=void 0,d(g)},ke)}}},W=/[/\\]tsconfig\..+\.json$/u,be=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,je=e=>{const t=e.map(r=>` • ${r.kind} "${r.exportName}" — class ${r.className} is not exported by your worker entry.`),i=[...new Set(e.map(r=>r.module))].map(r=>` export * from "./lunora/_generated/${r}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...t,"","Add to your worker entry:",...i].join(`
2
- `)},De=(e,t,i)=>{if(t.warn(`${m} schema.ts not found at ${e} — codegen skipped`),i!==void 0){const r=`schema.ts not found at ${e} — generated output is now stale`;i.onError(new Error(r),r)}},M=(e,t,i,r)=>{const l=Y(e.projectRoot,e.schemaDir,"schema.ts");if(!X(l))return De(l,t,i),{};try{const a=te({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:r,projectRoot:e.projectRoot,target:e.target,...me(e.projectRoot)});return pe(e.projectRoot,a.cronTriggers,t),le(a,t),{blockingMessage:de(a),outputDirectory:h(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return t.error(`${m} codegen failed: ${d}`),i?.onError(a,d),{failure:`${m} codegen failed: ${d}`}}},Te=(e,t,i)=>{let r;for(const[l,a]of Object.entries(e.environments)){if(l==="client"){r=a;continue}we(a)||a.hot.send({path:"*",triggeredBy:t,type:"full-reload"})}if(r===void 0){e.hot.send({type:"full-reload"});return}if(i){r.hot.send({type:"full-reload"});return}r.hot.send({event:ve,type:"custom"})},b={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Ge=e=>{const t=h(e.projectRoot,e.schemaDir),i=se(process.env[I]);let r=h(e.projectRoot,e.generatedDir),l=0,a=!1,d;const g=new Map;let f,j=!1,D=!1,S,T;return{config(o,y){S=y.command},configResolved(){S!=="build"&&i||(T=M(e,b))},async buildStart(){const o=S!=="build"&&i,{blockingMessage:y,failure:v,outputDirectory:E}=T??(o?{}:M(e,b));if(T=void 0,S==="build"&&v!==void 0&&this.error(v),E!==void 0){r=E,a=!0;let p;try{p=await G({cwd:e.projectRoot,logger:b})}finally{a=!1}p.ran&&(l=Date.now()),S==="build"&&p.error!==void 0&&this.error(p.error)}S==="build"&&y!==void 0&&this.error(y),await he(e,b,p=>{d?.hot.send({err:{loc:void 0,message:je(p),stack:""},type:"error"})}),d!==void 0&&(f=F(e.projectRoot),j=!0)},configureServer(o){d=o,o.watcher.add(t);const y=ee(e.projectRoot).services.filter(n=>n.rpcEntrypoint!==void 0).map(n=>q(n.wranglerPath));o.watcher.add(y),f=F(e.projectRoot),j=!1;const v={error:n=>{o.config.logger.error(n)},info:n=>{o.config.logger.info(n)},warn:n=>{o.config.logger.warn(n)}};let E=!1;const p={onError(n,c){E=!0;const s=n instanceof ae?{column:n.column,file:n.file,line:n.line}:void 0,w=s===void 0?`[lunora] codegen failed: ${c}
3
- (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${c}`;d?.hot.send({err:{loc:s,message:w,stack:n instanceof Error?n.stack??"":""},type:"error"})}},C=(n,c)=>n===c||n.startsWith(c+k);let _=!1,u;const B=()=>{for(const n of Object.values(o.environments)){const c=n.moduleGraph;for(const s of c.idToModuleMap.values())s.id&&C(s.id,r)&&c.invalidateModule(s)}},J=async(n,c)=>{try{if(_)return;u===void 0?u=ie(t):ce(u,t);const{outputDirectory:s}=M(e,v,p,u);if(s===void 0){u=void 0;return}r=s;const w=A(t);a=!0;let O;try{O=await G({cwd:e.projectRoot,logger:v})}finally{a=!1}if(O.ran&&(l=Date.now(),c(w)),O.error!==void 0)return;B(),Te(o,n,E),E=!1}catch(s){v.error(`${m} codegen watch: ${s instanceof Error?s.message:String(s)}`)}},P=Ce({fingerprint:()=>A(t),logger:v,regenerate:(n,c)=>{J(n,c)}}),V=n=>W.test(n)||n.endsWith(`${k}tsconfig.json`)&&n===re(t)?(u=void 0,!1):!(!C(n,t)||C(n,r)||!n.endsWith(".ts")||oe(Z(t,n).split(k).join("/"))),R=n=>{const c=h(n);if(!(!(be.test(c)&&!c.includes(`${k}node_modules${k}`)&&y.some(w=>C(c,w)))&&!V(c))){if(a||Date.now()-l<U){P.cancelPending();return}P.onSave(c)}},N=n=>{const c=h(n);(c.endsWith(`${k}tsconfig.json`)||W.test(c))&&(u=void 0)};i?o.config.logger.info(`${m} codegen watch disabled (${I}) — _generated/ is written only by an explicit \`lunora codegen\``):(o.watcher.on("add",R),o.watcher.on("change",R),o.watcher.on("unlink",R),o.watcher.on("unlink",N));const x=new Set([...ue.map(n=>h(e.projectRoot,n)),...ne.map(n=>h(e.projectRoot,n))]);for(const n of x)o.watcher.add(n);const $=n=>{if(!x.has(h(n))||D)return;const c=F(e.projectRoot);if(!j){f=c;return}if(f===void 0){f=c;return}c!==f&&(f=c,D=!0,o.config.logger.info(`${m} ${Q(h(n))} changed — restarting dev server`),Promise.resolve(o.restart()).finally(()=>{D=!1}).catch(s=>{const w=s instanceof Error?s.message:String(s);o.config.logger.error(`${m} dev server restart failed: ${w} — keeping the running server; re-save your config to retry.`),o.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${w}`,stack:""},type:"error"})}))};o.watcher.on("add",$),o.watcher.on("change",$),o.watcher.on("unlink",$);const H=()=>{_||(_=!0,u=void 0,P.dispose(),o.watcher.off("add",R),o.watcher.off("change",R),o.watcher.off("unlink",R),o.watcher.off("unlink",N),o.watcher.off("add",$),o.watcher.off("change",$),o.watcher.off("unlink",$))};return()=>{Ee(o,g,H)}},buildEnd(){Se(g,this.environment)},name:"lunora:codegen"}};export{Ge as default};