@lunora/vite 1.0.0-alpha.420 → 1.0.0-alpha.421
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,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as $}from"node:module";import{sep as O,resolve as h,dirname as B,isAbsolute as F,relative as I}from"node:path";import{cloudflare as M}from"@cloudflare/vite-plugin";import{BUNDLE_META_PATH_ENV as N,canonicalPath as k,DEFAULT_BUNDLE_META_PATH as U,resolveDeployDriver as H,startCelldDevSession as j,formatLunoraEvent as V,lunoraLine as z,detectFramework as G,createDiscoveryCache as K,targetRunsOwnDevServer as q,resolveLazyFunctions as J,resolveTargetOrThrow as Q,isRunnableTarget as Y,runnableTargetIds as X,assertBuildTargetMatches as Z}from"@lunora/config";import{GENERATED_CLASS_MODULES as Cr,detectFramework as xr}from"@lunora/config";import ee from"@visulima/vite-overlay";import{detectAgentRules as re,claimAgentRulesHint as te,lunoraLine as m,AGENT_RULES_HINT as oe}from"@lunora/config/cli";import{reconcileBindingsSafely as ne,findWranglerFile as ie,readWranglerJsonc as se,warnCloudflareCliConfigOnce as ae,hasCloudflareCredentials as ce,withheldBindings as le,describeWithheld as ue,startLocalHyperdrive as de}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Dr}from"@lunora/config/cloudflare";import{o as fe}from"./packem_shared/build-session-D75JzvIT.mjs";import{mkdirSync as pe,writeFileSync as me,statSync as ge,rmSync as ve}from"node:fs";import{r as D,a as L}from"./packem_shared/server-close-DWiO4Vxb.mjs";import he from"./packem_shared/codegenPlugin-
|
|
1
|
+
import{createRequire as $}from"node:module";import{sep as O,resolve as h,dirname as B,isAbsolute as F,relative as I}from"node:path";import{cloudflare as M}from"@cloudflare/vite-plugin";import{BUNDLE_META_PATH_ENV as N,canonicalPath as k,DEFAULT_BUNDLE_META_PATH as U,resolveDeployDriver as H,startCelldDevSession as j,formatLunoraEvent as V,lunoraLine as z,detectFramework as G,createDiscoveryCache as K,targetRunsOwnDevServer as q,resolveLazyFunctions as J,resolveTargetOrThrow as Q,isRunnableTarget as Y,runnableTargetIds as X,assertBuildTargetMatches as Z}from"@lunora/config";import{GENERATED_CLASS_MODULES as Cr,detectFramework as xr}from"@lunora/config";import ee from"@visulima/vite-overlay";import{detectAgentRules as re,claimAgentRulesHint as te,lunoraLine as m,AGENT_RULES_HINT as oe}from"@lunora/config/cli";import{reconcileBindingsSafely as ne,findWranglerFile as ie,readWranglerJsonc as se,warnCloudflareCliConfigOnce as ae,hasCloudflareCredentials as ce,withheldBindings as le,describeWithheld as ue,startLocalHyperdrive as de}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Dr}from"@lunora/config/cloudflare";import{o as fe}from"./packem_shared/build-session-D75JzvIT.mjs";import{mkdirSync as pe,writeFileSync as me,statSync as ge,rmSync as ve}from"node:fs";import{r as D,a as L}from"./packem_shared/server-close-DWiO4Vxb.mjs";import he from"./packem_shared/codegenPlugin-2ycHgwJC.mjs";import we from"./packem_shared/containerLogsPlugin-CWF3LHN3.mjs";import ye from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import Se from"./packem_shared/devVariablesPlugin-Bm5X49VR.mjs";import{frameworkComposePlugin as Pe}from"./packem_shared/CLASS_A_WIRING-CDSSmDqw.mjs";import{CLASS_A_WIRING as Wr,LUNORA_WORKER_VIRTUAL_ID as $r,buildWorkerEntrySource as Br,isAutoComposable as Fr}from"./packem_shared/CLASS_A_WIRING-CDSSmDqw.mjs";import be from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as ke}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 Ur,withRemoteBindings as Hr}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{readServiceBindings as Re}from"@lunora/codegen";import{lunoraSolutionFinders as Ee}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as Vr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as Te}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{buildStudioUrl as Gr}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{withWorkerStartupHint as _e}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as qr,augmentWorkerStartupError as Jr,isWorkerEntryEvalError as Qr}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as Ce}from"./packem_shared/wranglerValidatorPlugin-CPPKubFC.mjs";import{default as Xr}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as et}from"@lunora/config/studio-host";const xe=r=>({apply:"serve",configureServer(e){return()=>{re(r.projectRoot).installed||!te()||e.config.logger.warn(`
|
|
2
2
|
${m(oe)}
|
|
3
3
|
`)}},name:"lunora:agent-rules-hint"}),Oe=(r,e)=>({async config(t,o){if(e?.clear(),o.isPreview===!0)return;const n=async()=>ne({...r,cache:e},{info:i=>{console.info(i)},warn:i=>{console.warn(i)}});await(o.command==="build"?fe(r,"provision",n):n())},enforce:"pre",name:"lunora:bindings-provision"}),De=(r,e=O)=>r.split(e).join("/"),b=(r,e)=>F(e)?De(I(r,e)):e,w=(r,e,t)=>e.map(o=>({kind:t,path:b(r,o)})),Le=/[?#]/,A=r=>{try{return ge(r).size}catch{return}},We=(r,e)=>A(r)??A(r.split(Le)[0]??r)??Buffer.byteLength(e??""),$e=r=>{let e;return{apply:"build",applyToEnvironment:t=>t.config.consumer==="server",name:"lunora:bundle-meta",sharedDuringBuild:!0,generateBundle(t,o){const n={},i={};for(const[u,d]of Object.entries(o)){if(d.type!=="chunk")continue;const f={bytes:Buffer.byteLength(d.code),imports:[...w(r,d.imports,"import-statement"),...w(r,d.dynamicImports,"dynamic-import")],inputs:{}};d.facadeModuleId&&(f.entryPoint=b(r,d.facadeModuleId));for(const[g,y]of Object.entries(d.modules)){const p=b(r,g);if(f.inputs[p]={bytesInOutput:Buffer.byteLength(y.code??"")},!n[p]){const S=this.getModuleInfo(g);n[p]={bytes:We(g,S?.code),imports:[...w(r,S?.importedIds??[],"import-statement"),...w(r,S?.dynamicallyImportedIds??[],"dynamic-import")]}}}i[u]=f}const a=process.env[N],c=a===void 0||a===""?void 0:h(r,a),s=`${k(h(r,".lunora"))}${O}`,l=c!==void 0&&k(c).startsWith(s)?c:h(r,U);if(e!==void 0&&e!==this.environment.name){ve(l,{force:!0}),this.warn(`bundle-meta: environment "${this.environment.name}" built a server bundle after "${e}" wrote one; no bundle-meta.json is written, because the app's own graph cannot be told apart from a service's`);return}e=this.environment.name,pe(B(l),{recursive:!0}),me(l,`${JSON.stringify({inputs:n,outputs:i},void 0,2)}
|
|
4
4
|
`,"utf8")}}},R="/_lunora",Be=8787,v=new Map,W=r=>r.command==="serve"&&r.isPreview!==!0,Fe=(r,e)=>{let t;return()=>{if(t===void 0)try{H(e).projectConfig?.(r,"dev"),t={runs:!0}}catch(o){t={reason:o instanceof Error?o.message:String(o),runs:!1}}return t}},Ie=r=>{const e=ie(r),t=e===void 0?void 0:se(e).parsed?.dev?.port;return typeof t=="number"?t:Be},Me=(r,e)=>r.map(t=>{const o=t.apply;return{...t,apply:(n,i)=>W(i)&&e()?!1:typeof o=="function"?o(n,i):o===void 0||o===i.command}}),Ne=(r,e,{stream:t,tag:o})=>{const n=V(e);n!==void 0?r[n.level](`[lunora] ${n.text}`):t==="stderr"?r.warn(`[${o}] ${e}`):r.info(`[${o}] ${e}`)},Ue=(r,e)=>{const t=Ie(r),o=new Map;return{apply:(n,i)=>W(i)&&e(),buildEnd(){L(o,this.environment)},config:n=>{if(n.server?.proxy?.[R]===void 0)return{server:{proxy:{[R]:{changeOrigin:!0,target:`http://127.0.0.1:${String(t)}`,ws:!0}}}}},async configureServer(n){const{logger:i}=n.config;await v.get(r)?.stop(),v.delete(r),i.info(`[lunora] starting the worker on celld at http://127.0.0.1:${String(t)} …`);const a=await j({log:(s,l)=>{Ne(i,s,l)},port:t,projectRoot:r});v.set(r,a);const c=s=>{i.error(`[lunora] the worker on celld exited (code ${String(s)}) — restart vite dev to bring it back`)};a.exited.then(c).catch(()=>{}),D(n,o,()=>{v.get(r)===a&&v.delete(r),a.stop().catch(s=>{i.error(`[lunora] stopping celld failed: ${s instanceof Error?s.message:String(s)}`)})})},name:"lunora:celld-dev"}},He=r=>({configResolved(e){ae(r.projectRoot,t=>{e.logger.warn(z(t))})},name:"lunora:cf-config-warning"}),je=()=>({}),Ve={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)"},ze=r=>{const e=Ve[r.framework];return r.framework==="none"?m("no meta-framework detected — running standalone."):r.class==="B"?m(`detected ${e} — composition is handled by the framework adapter.`):m(`detected ${e} — composing the Lunora worker into one Cloudflare Worker.`)},Ge=(r,e)=>{let t=!1;const o=()=>{e.framework??=G(r.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&e.framework!==void 0&&(t=!0,console.info(ze(e.framework)))},name:"lunora:framework-detect"}},E=r=>Array.isArray(r)?r:[],P=new WeakSet,Ke=(r,e={})=>{let t=!1;const o=r.experimental?.newConfig,n=o!==void 0&&o!==!1,i=e.hasCredentials??(()=>ce({projectRoot:e.projectRoot})),a=c=>{const s=(l,...u)=>{const d=typeof c=="function"?c(l,...u):c,f=d===void 0?void 0:{...d},g=t?[...E(l.artifacts),...E(f?.artifacts)]:[],y=t?le({ai:l.ai??f?.ai,artifacts:g},i):[];for(const p of y)Reflect.deleteProperty(l,p.kind),Reflect.deleteProperty(f??{},p.kind),console.warn(m(ue(p)));return f};return P.add(s),s};return{config(c,s){if(t=s.command==="serve"&&s.isPreview!==!0,n)return;const l=r;P.has(l.config)||(l.config=a(l.config)),Array.isArray(l.auxiliaryWorkers)&&(l.auxiliaryWorkers=l.auxiliaryWorkers.map(u=>P.has(u.config)?u:{...u,config:a(u.config)}))},enforce:"pre",name:"lunora:local-ai-binding"}},qe=5e3,Je=3e4,T=new Map,_=r=>{const e=T.get(r);if(e!==void 0)return e;const t={databases:[],pending:Promise.resolve(),servers:0,stopping:Promise.resolve()};return T.set(r,t),t},Qe=async r=>{const e=r.databases.splice(0);await Promise.allSettled(e.map(async t=>t.stop()))},C=(r,e)=>{const t=setTimeout(()=>{r.pending.then(async()=>{r.servers===0&&(r.stopping=Qe(r),await r.stopping)}).catch(()=>{})},e);return t.unref(),t},x=({projectRoot:r,start:e=de,wranglerConfigPath:t})=>{const o=new Map,n=i=>{const a=_(r);let c=!1;a.servers+=1,clearTimeout(a.stopTimer),i(()=>{c||(c=!0,a.servers-=1,a.servers===0&&(a.stopTimer=C(a,qe)))})};return{async config(i,a){if(a.command!=="serve")return;const c=_(r);clearTimeout(c.stopTimer);const s=c.pending,l=(async()=>{await s,await c.stopping;const u=await e({onWarning:d=>{console.warn(m(d))},projectRoot:r,wranglerConfigPath:t});u!==void 0&&c.databases.push(u),u!==void 0&&u.bindings.length>0&&console.info(m(`Hyperdrive ${u.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite.`))})();c.pending=l.catch(()=>{});try{await l}finally{c.servers===0&&(clearTimeout(c.stopTimer),c.stopTimer=C(c,Je))}},buildEnd(){L(o,this.environment)},configureServer(i){n(a=>{D(i,o,a)})},configurePreviewServer(i){n(a=>{i.httpServer.once("close",a)})},enforce:"pre",name:"lunora:local-hyperdrive"}},Ye=(r,e)=>({config(t,o){if(o.command!=="serve")return;const{services:n}=Re(e),i=Array.isArray(r.auxiliaryWorkers)?r.auxiliaryWorkers:[],a=new Set(i.map(s=>s.configPath===void 0?"":h(e,s.configPath))),c=[...new Set(n.map(s=>s.wranglerPath))].filter(s=>!a.has(s)).map(s=>({configPath:s}));c.length>0&&(r.auxiliaryWorkers=[...i,...c])},enforce:"pre",name:"lunora:service-workers"}),Xe=r=>{if(r===!1)return!1;const e=r===!0||r===void 0?{}:r;return{...e,forwardedConsoleMethods:e.forwardedConsoleMethods??["error","warn"],solutionFinders:[...Ee,...e.solutionFinders??[]]}},Ze=(r,e)=>{const t=Q(r,e);if(!Y(t)){const o=X();throw new Error(`target "${t}" has no command-line toolchain, so the Lunora Vite plugin cannot build or serve it — it can only generate for it (\`lunora codegen --target ${t}\`). Buildable targets: ${o.join(", ")}`)}return Z(t,r),t},er=r=>{const e=r??{};if(e.lazyFunctions!==void 0)throw new Error("lunora(): the `lazyFunctions` option was removed. Set `codegen: { lazyFunctions: true }` in lunora.config (or pass --lazy-functions for one run).");const t=e.schemaDir??"lunora";let o;e.cloudflare===!1?o=!1:e.cloudflare===!0||e.cloudflare===void 0?o={}:o=e.cloudflare;const n=e.projectRoot??process.cwd(),i=Ze(n,e.target);return{allowUnauthenticatedShardAccess:e.allowUnauthenticatedShardAccess??!1,apiSpec:e.apiSpec??"openapi",lazyFunctions:J(),cloudflare:o,studio:e.studio??!0,generatedDir:`${t}/_generated`,overlay:Xe(e.overlay),projectRoot:n,schemaDir:t,shard:e.shard??{},target:i,validateWrangler:e.validateWrangler??!0}},rr=(r,e)=>{const{configPath:t}=r;return typeof t=="string"&&t!==""?h(e,t):void 0},Rr=r=>{const e=er(r),t=je(),o=K(),n=[Ge(e,t),Pe(e,t),Se(e),Oe(e,o),he(e,o),$e(e.projectRoot),be(),ye(e),xe(e),He(e),ke()];e.studio&&n.push(Te(e)),e.validateWrangler&&n.push(Ce(e,o)),e.overlay!==!1&&n.push(ee(e.overlay)),n.push(we(e,o));const i=e.cloudflare===!1?void 0:{...e.cloudflare};if(n.push(Ae(i,{projectRoot:e.projectRoot})),i===void 0&&n.push(x({projectRoot:e.projectRoot})),i!==void 0){n.push(Ye(i,e.projectRoot));const a=q(e.target),c=Fe(e.projectRoot,e.target),s=()=>a&&c().runs;n.push(...Me([x({projectRoot:e.projectRoot,wranglerConfigPath:rr(i,e.projectRoot)}),Ke(i,{projectRoot:e.projectRoot}),..._e(M(i))],s)),a&&n.push(Ue(e.projectRoot,s),{apply:(l,u)=>u.command==="serve"&&u.isPreview!==!0&&!s(),configureServer(l){l.config.logger.warn(`[lunora] target "${e.target}": vite dev serves the worker in workerd, not on ${e.target} — ${c().reason??"it cannot run this project"}. \`vite build\` then \`lunora deploy\` ships it to ${e.target}.`)},name:"lunora:target-runtime-notice"})}return n},Er=$(import.meta.url)("../package.json").version;export{Wr as CLASS_A_WIRING,Cr as GENERATED_CLASS_MODULES,Xr as LUNORA_API_UPDATED_EVENT,$r as LUNORA_WORKER_VIRTUAL_ID,et as STUDIO_PATH,Er as VERSION,qr as WORKER_STARTUP_HINT,Jr as augmentWorkerStartupError,Gr as buildStudioUrl,Br as buildWorkerEntrySource,Mr as checkLunoraProxy,he as codegenPlugin,we as containerLogsPlugin,xr as detectFramework,ye as devStatePlugin,Se as devVariablesPlugin,Pe as frameworkComposePlugin,Fr as isAutoComposable,Qr as isWorkerEntryEvalError,be as logStreamPlugin,Rr as lunora,Vr as lunoraSolutionFinder,Ee as lunoraSolutionFinders,Ur as planViteRemoteBindings,ke as proxyCheckPlugin,Dr as reconcileWranglerCrons,Ae as remoteBindingsPlugin,Xe as resolveOverlayOption,Te as studioPlugin,Hr as withRemoteBindings,_e as withWorkerStartupHint,Ce as wranglerValidatorPlugin};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{existsSync as se}from"node:fs";import{resolve as S,dirname as de,sep as D,basename as G,join as B,relative as le}from"node:path";import{PROJECT_CONFIG_FILENAMES as O,readServiceBindings as fe,readProjectLazyFunctions as U,projectConfigCandidatePaths as V,createCodegenProject as Z,runCodegen as ue,findTsconfig as ge,isTestPath as me,fingerprintSchemaSources as H,refreshCodegenProject as he,CodegenDiagnosticError as pe}from"@lunora/codegen";import{LUNORA_TAG as y,isCodegenDisabled as we,CODEGEN_ENV as J,writeApiSpecMarker as Se,reportCodegenFindings as ye,blockingFindingsMessage as ve,STRICT_ADVISORIES_ENV as Re,runPostCodegenHook as K}from"@lunora/config";import{WRANGLER_FILES as Ee,wranglerCodegenInputs as ke,reconcileWranglerExtras as je,reconcileBindingsSafely as Ce}from"@lunora/config/cloudflare";import{consumeStudioWrite as $e}from"@lunora/config/studio-host";import{isRunnableDevEnvironment as be}from"vite";import{c as I,m as De,o as Pe}from"./build-session-D75JzvIT.mjs";import Te from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as _e,r as Me}from"./server-close-DWiO4Vxb.mjs";const Fe=e=>{const c=O.some(i=>S(e.projectRoot,i)===e.file);return e.flipped&&(!c||!e.baselineSettled)},Ae=100,z=300,X=2,Ne=e=>{let c,i=!1,n,f=0;const a=()=>{c&&(clearTimeout(c),c=void 0)},l=(s,p)=>{n&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,e.fingerprint()!==s){if(f+=1,f>X){e.logger.warn(`${y} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(X)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${y} schema changed while \`postcodegen\` was running — regenerating`),p()}},z)},h=(s,p)=>{e.regenerate(s,E=>{l(E,()=>{h(s,!0)})},p)},v=(s,p)=>{const E=p||c!==void 0&&i;a(),f=0,i=E,c=setTimeout(()=>{c=void 0,h(s,E)},Ae)};return{cancelPending:a,dispose:()=>{a(),n&&(clearTimeout(n),n=void 0)},onSave:s=>{v(s,!0)},onStudioWrite:s=>{v(s,!1)}}},q=/[/\\]tsconfig\..+\.json$/u,Ie=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,Oe=e=>{const c=e.map(n=>` • ${n.kind} "${n.exportName}" — class ${n.className} is not exported by your worker entry.`),i=[...new Set(e.map(n=>n.module))].map(n=>` export * from "./lunora/_generated/${n}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...c,"","Add to your worker entry:",...i].join(`
|
|
2
|
+
`)},We=(e,c,i)=>{if(c.warn(`${y} schema.ts not found at ${e} — codegen skipped`),i!==void 0){const n=`schema.ts not found at ${e} — generated output is now stale`;i.onError(new Error(n),n)}},F=(e,c,i,n)=>{const f=B(e.projectRoot,e.schemaDir,"schema.ts");if(!se(f))return We(f,c,i),{};try{const a=n??Z(B(e.projectRoot,e.schemaDir)),l=ue({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:a,projectRoot:e.projectRoot,target:e.target,...ke(e.projectRoot)});je(e.projectRoot,l.cronTriggers,c);let h;try{Se(e.projectRoot,e.apiSpec)}catch(v){h=`${y} could not write the API spec marker: ${v instanceof Error?v.message:String(v)}`,c.error(h)}return ye(l,c),{blockingMessage:ve(l,{strictAdvisories:process.env[Re]!=="0"}),markerFailure:h,outputDirectory:S(l.outputDirectory),project:a}}catch(a){const l=a instanceof Error?a.message:String(a);return c.error(`${y} codegen failed: ${l}`),i?.onError(a,l),{failure:`${y} codegen failed: ${l}`}}},xe=(e,c,i)=>{let n;for(const[f,a]of Object.entries(e.environments)){if(f==="client"){n=a;continue}be(a)||a.hot.send({path:"*",triggeredBy:c,type:"full-reload"})}if(n===void 0){e.hot.send({type:"full-reload"});return}if(i){n.hot.send({type:"full-reload"});return}n.hot.send({event:Te,type:"custom"})},T={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Q=new WeakMap,Y=async(e,c,i)=>{const n=Q.get(e)??new Map;return Q.set(e,n),n.has(c)||n.set(c,i()),n.get(c)},Qe=(e,c)=>{const i=S(e.projectRoot,e.schemaDir),n=we(process.env[J]);let f=S(e.projectRoot,e.generatedDir),a=0,l=!1,h;const v=new Map;let s,p=!1,E=!1,w,P;const A=new Set,ee=r=>{const u=A.has(r)?void 0:P;return A.add(r),w!=="build"&&(P=void 0),u},te=async()=>{l=!0;let r;try{r=await K({cwd:e.projectRoot,logger:T})}finally{l=!1}return r.ran&&(a=Date.now(),c?.clear()),r.error},re=async()=>{P=await Pe(e,"codegen",()=>{const{blockingMessage:r,failure:u,markerFailure:R,outputDirectory:k}=F(e,T);return{blockingMessage:r,failure:u,markerFailure:R,outputDirectory:k}})};return{config(r,u){w=u.command},configResolved(){if(A.clear(),w==="build")return re();n||(P=F(e,T))},async buildStart(){const r=w!=="build"&&n,u=ee(w==="build"?this.environment.name:"")??(r?{}:F(e,T)),{blockingMessage:R,failure:k,markerFailure:_,outputDirectory:j}=u;w==="build"&&De(e),w==="build"&&k!==void 0&&this.error(k),w==="build"&&_!==void 0&&this.error(_),f=j??f;const C=j===void 0?void 0:await Y(u,"postcodegen",te);w==="build"&&C!==void 0&&this.error(C),w==="build"&&R!==void 0&&this.error(R),await Y(u,"reconcile",async()=>Ce({...e,cache:c},T,g=>{h?.hot.send({err:{loc:void 0,message:Oe(g),stack:""},type:"error"})})),c?.clear(),h!==void 0&&(s=I(e.projectRoot),p=!0)},configureServer(r){h=r,r.watcher.add(i);const u=fe(e.projectRoot).services.filter(t=>t.rpcEntrypoint!==void 0).map(t=>de(t.wranglerPath));r.watcher.add(u),s=I(e.projectRoot),p=!1;const R={error:t=>{r.config.logger.error(t)},info:t=>{r.config.logger.info(t)},warn:t=>{r.config.logger.warn(t)}};let k=!1;const _={onError(t,o){k=!0;const d=t instanceof pe?{column:t.column,file:t.file,line:t.line}:void 0,m=d===void 0?`[lunora] codegen failed: ${o}
|
|
3
|
+
(see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${o}`;h?.hot.send({err:{loc:d,message:m,stack:t instanceof Error?t.stack??"":""},type:"error"})}},j=(t,o)=>t===o||t.startsWith(o+D);let C=!1,g=P?.project;const ne=()=>{for(const t of Object.values(r.environments)){const o=t.moduleGraph;for(const d of o.idToModuleMap.values())d.id&&j(d.id,f)&&o.invalidateModule(d)}},oe=()=>{g===void 0?g=Z(i):he(g,i);const{outputDirectory:t}=F(e,R,_,g);return t===void 0?(g=void 0,!1):(f=t,!0)},ie=async(t,o,d)=>{try{if(C||d&&!oe())return;const m=H(i);l=!0;let N;try{N=await K({cwd:e.projectRoot,logger:R})}finally{l=!1}if(N.ran&&(a=Date.now(),o(m)),N.error!==void 0)return;ne(),xe(r,t,k),k=!1}catch(m){R.error(`${y} codegen watch: ${m instanceof Error?m.message:String(m)}`)}};let W=U(i);const M=Ne({fingerprint:()=>H(i),logger:R,regenerate:(t,o,d)=>{ie(t,o,d)}}),ce=t=>{if(q.test(t))return g=void 0,!1;if(O.includes(G(t))&&V(i).includes(t)){g=void 0;const o=U(i),d=o!==W;return W=o,Fe({baselineSettled:p,file:t,flipped:d,projectRoot:e.projectRoot})}return t.endsWith(`${D}tsconfig.json`)&&t===ge(i)?(g=void 0,!1):!(!j(t,i)||j(t,f)||!t.endsWith(".ts")||me(le(i,t).split(D).join("/")))},$=t=>{const o=S(t);if(!(!(Ie.test(o)&&!o.includes(`${D}node_modules${D}`)&&u.some(m=>j(o,m)))&&!ce(o))){if(l||Date.now()-a<z){M.cancelPending();return}if($e(o)){M.onStudioWrite(o);return}M.onSave(o)}},x=t=>{const o=S(t);(o.endsWith(`${D}tsconfig.json`)||q.test(o))&&(g=void 0)};n?r.config.logger.info(`${y} codegen watch disabled (${J}) — _generated/ is written only by an explicit \`lunora codegen\``):(r.watcher.on("add",$),r.watcher.on("change",$),r.watcher.on("unlink",$),r.watcher.on("unlink",x));const L=new Set([...Ee.map(t=>S(e.projectRoot,t)),...O.map(t=>S(e.projectRoot,t)),...V(i)]);for(const t of L)r.watcher.add(t);const b=t=>{if(!L.has(S(t))||E)return;const o=I(e.projectRoot);if(!p){s=o;return}if(s===void 0){s=o;return}o!==s&&(s=o,E=!0,r.config.logger.info(`${y} ${G(S(t))} changed — restarting dev server`),Promise.resolve(r.restart()).finally(()=>{E=!1}).catch(d=>{const m=d instanceof Error?d.message:String(d);r.config.logger.error(`${y} dev server restart failed: ${m} — keeping the running server; re-save your config to retry.`),r.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${m}`,stack:""},type:"error"})}))};r.watcher.on("add",b),r.watcher.on("change",b),r.watcher.on("unlink",b);const ae=()=>{C||(C=!0,g=void 0,M.dispose(),r.watcher.off("add",$),r.watcher.off("change",$),r.watcher.off("unlink",$),r.watcher.off("unlink",x),r.watcher.off("add",b),r.watcher.off("change",b),r.watcher.off("unlink",b))};return()=>{Me(r,v,ae)}},buildEnd(){_e(v,this.environment)},name:"lunora:codegen"}};export{Qe as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/vite",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.421",
|
|
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.
|
|
50
|
-
"@lunora/config": "1.0.0-alpha.
|
|
49
|
+
"@lunora/codegen": "1.0.0-alpha.391",
|
|
50
|
+
"@lunora/config": "1.0.0-alpha.448",
|
|
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{existsSync as se}from"node:fs";import{resolve as E,dirname as de,sep as D,basename as L,join as G,relative as le}from"node:path";import{readServiceBindings as fe,readProjectLazyFunctions as B,PROJECT_CONFIG_FILENAMES as U,projectConfigCandidatePaths as V,createCodegenProject as Z,runCodegen as ue,findTsconfig as ge,isTestPath as me,fingerprintSchemaSources as H,refreshCodegenProject as he,CodegenDiagnosticError as pe}from"@lunora/codegen";import{LUNORA_TAG as w,isCodegenDisabled as we,CODEGEN_ENV as J,writeApiSpecMarker as Se,reportCodegenFindings as ye,blockingFindingsMessage as ve,STRICT_ADVISORIES_ENV as Ee,runPostCodegenHook as K}from"@lunora/config";import{WRANGLER_FILES as Re,wranglerCodegenInputs as ke,reconcileWranglerExtras as je,reconcileBindingsSafely as Ce}from"@lunora/config/cloudflare";import{consumeStudioWrite as $e}from"@lunora/config/studio-host";import{isRunnableDevEnvironment as be}from"vite";import{c as I,m as De,o as Pe}from"./build-session-D75JzvIT.mjs";import Te from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as _e,r as Me}from"./server-close-DWiO4Vxb.mjs";const Ae=100,z=300,X=2,Fe=e=>{let i,c=!1,n,f=0;const a=()=>{i&&(clearTimeout(i),i=void 0)},l=(s,y)=>{n&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,e.fingerprint()!==s){if(f+=1,f>X){e.logger.warn(`${w} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(X)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${w} schema changed while \`postcodegen\` was running — regenerating`),y()}},z)},h=(s,y)=>{e.regenerate(s,R=>{l(R,()=>{h(s,!0)})},y)},S=(s,y)=>{const R=y||i!==void 0&&c;a(),f=0,c=R,i=setTimeout(()=>{i=void 0,h(s,R)},Ae)};return{cancelPending:a,dispose:()=>{a(),n&&(clearTimeout(n),n=void 0)},onSave:s=>{S(s,!0)},onStudioWrite:s=>{S(s,!1)}}},q=/[/\\]tsconfig\..+\.json$/u,Ne=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,Ie=e=>{const i=e.map(n=>` • ${n.kind} "${n.exportName}" — class ${n.className} is not exported by your worker entry.`),c=[...new Set(e.map(n=>n.module))].map(n=>` export * from "./lunora/_generated/${n}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...i,"","Add to your worker entry:",...c].join(`
|
|
2
|
-
`)},Oe=(e,i,c)=>{if(i.warn(`${w} schema.ts not found at ${e} — codegen skipped`),c!==void 0){const n=`schema.ts not found at ${e} — generated output is now stale`;c.onError(new Error(n),n)}},A=(e,i,c,n)=>{const f=G(e.projectRoot,e.schemaDir,"schema.ts");if(!se(f))return Oe(f,i,c),{};try{const a=n??Z(G(e.projectRoot,e.schemaDir)),l=ue({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:a,projectRoot:e.projectRoot,target:e.target,...ke(e.projectRoot)});je(e.projectRoot,l.cronTriggers,i);let h;try{Se(e.projectRoot,e.apiSpec)}catch(S){h=`${w} could not write the API spec marker: ${S instanceof Error?S.message:String(S)}`,i.error(h)}return ye(l,i),{blockingMessage:ve(l,{strictAdvisories:process.env[Ee]!=="0"}),markerFailure:h,outputDirectory:E(l.outputDirectory),project:a}}catch(a){const l=a instanceof Error?a.message:String(a);return i.error(`${w} codegen failed: ${l}`),c?.onError(a,l),{failure:`${w} codegen failed: ${l}`}}},We=(e,i,c)=>{let n;for(const[f,a]of Object.entries(e.environments)){if(f==="client"){n=a;continue}be(a)||a.hot.send({path:"*",triggeredBy:i,type:"full-reload"})}if(n===void 0){e.hot.send({type:"full-reload"});return}if(c){n.hot.send({type:"full-reload"});return}n.hot.send({event:Te,type:"custom"})},T={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Q=new WeakMap,Y=async(e,i,c)=>{const n=Q.get(e)??new Map;return Q.set(e,n),n.has(i)||n.set(i,c()),n.get(i)},qe=(e,i)=>{const c=E(e.projectRoot,e.schemaDir),n=we(process.env[J]);let f=E(e.projectRoot,e.generatedDir),a=0,l=!1,h;const S=new Map;let s,y=!1,R=!1,p,P;const F=new Set,ee=r=>{const u=F.has(r)?void 0:P;return F.add(r),p!=="build"&&(P=void 0),u},te=async()=>{l=!0;let r;try{r=await K({cwd:e.projectRoot,logger:T})}finally{l=!1}return r.ran&&(a=Date.now(),i?.clear()),r.error},re=async()=>{P=await Pe(e,"codegen",()=>{const{blockingMessage:r,failure:u,markerFailure:v,outputDirectory:k}=A(e,T);return{blockingMessage:r,failure:u,markerFailure:v,outputDirectory:k}})};return{config(r,u){p=u.command},configResolved(){if(F.clear(),p==="build")return re();n||(P=A(e,T))},async buildStart(){const r=p!=="build"&&n,u=ee(p==="build"?this.environment.name:"")??(r?{}:A(e,T)),{blockingMessage:v,failure:k,markerFailure:_,outputDirectory:j}=u;p==="build"&&De(e),p==="build"&&k!==void 0&&this.error(k),p==="build"&&_!==void 0&&this.error(_),f=j??f;const C=j===void 0?void 0:await Y(u,"postcodegen",te);p==="build"&&C!==void 0&&this.error(C),p==="build"&&v!==void 0&&this.error(v),await Y(u,"reconcile",async()=>Ce({...e,cache:i},T,g=>{h?.hot.send({err:{loc:void 0,message:Ie(g),stack:""},type:"error"})})),i?.clear(),h!==void 0&&(s=I(e.projectRoot),y=!0)},configureServer(r){h=r,r.watcher.add(c);const u=fe(e.projectRoot).services.filter(t=>t.rpcEntrypoint!==void 0).map(t=>de(t.wranglerPath));r.watcher.add(u),s=I(e.projectRoot),y=!1;const v={error:t=>{r.config.logger.error(t)},info:t=>{r.config.logger.info(t)},warn:t=>{r.config.logger.warn(t)}};let k=!1;const _={onError(t,o){k=!0;const d=t instanceof pe?{column:t.column,file:t.file,line:t.line}:void 0,m=d===void 0?`[lunora] codegen failed: ${o}
|
|
3
|
-
(see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${o}`;h?.hot.send({err:{loc:d,message:m,stack:t instanceof Error?t.stack??"":""},type:"error"})}},j=(t,o)=>t===o||t.startsWith(o+D);let C=!1,g=P?.project;const ne=()=>{for(const t of Object.values(r.environments)){const o=t.moduleGraph;for(const d of o.idToModuleMap.values())d.id&&j(d.id,f)&&o.invalidateModule(d)}},oe=()=>{g===void 0?g=Z(c):he(g,c);const{outputDirectory:t}=A(e,v,_,g);return t===void 0?(g=void 0,!1):(f=t,!0)},ie=async(t,o,d)=>{try{if(C||d&&!oe())return;const m=H(c);l=!0;let N;try{N=await K({cwd:e.projectRoot,logger:v})}finally{l=!1}if(N.ran&&(a=Date.now(),o(m)),N.error!==void 0)return;ne(),We(r,t,k),k=!1}catch(m){v.error(`${w} codegen watch: ${m instanceof Error?m.message:String(m)}`)}};let O=B(e.projectRoot);const M=Fe({fingerprint:()=>H(c),logger:v,regenerate:(t,o,d)=>{ie(t,o,d)}}),ce=t=>{if(q.test(t))return g=void 0,!1;if(U.includes(L(t))&&V(c).includes(t)){g=void 0;const o=B(e.projectRoot),d=o!==O;return O=o,d}return t.endsWith(`${D}tsconfig.json`)&&t===ge(c)?(g=void 0,!1):!(!j(t,c)||j(t,f)||!t.endsWith(".ts")||me(le(c,t).split(D).join("/")))},$=t=>{const o=E(t);if(!(!(Ne.test(o)&&!o.includes(`${D}node_modules${D}`)&&u.some(m=>j(o,m)))&&!ce(o))){if(l||Date.now()-a<z){M.cancelPending();return}if($e(o)){M.onStudioWrite(o);return}M.onSave(o)}},W=t=>{const o=E(t);(o.endsWith(`${D}tsconfig.json`)||q.test(o))&&(g=void 0)};n?r.config.logger.info(`${w} codegen watch disabled (${J}) — _generated/ is written only by an explicit \`lunora codegen\``):(r.watcher.on("add",$),r.watcher.on("change",$),r.watcher.on("unlink",$),r.watcher.on("unlink",W));const x=new Set([...Re.map(t=>E(e.projectRoot,t)),...U.map(t=>E(e.projectRoot,t)),...V(c)]);for(const t of x)r.watcher.add(t);const b=t=>{if(!x.has(E(t))||R)return;const o=I(e.projectRoot);if(!y){s=o;return}if(s===void 0){s=o;return}o!==s&&(s=o,R=!0,r.config.logger.info(`${w} ${L(E(t))} changed — restarting dev server`),Promise.resolve(r.restart()).finally(()=>{R=!1}).catch(d=>{const m=d instanceof Error?d.message:String(d);r.config.logger.error(`${w} dev server restart failed: ${m} — keeping the running server; re-save your config to retry.`),r.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${m}`,stack:""},type:"error"})}))};r.watcher.on("add",b),r.watcher.on("change",b),r.watcher.on("unlink",b);const ae=()=>{C||(C=!0,g=void 0,M.dispose(),r.watcher.off("add",$),r.watcher.off("change",$),r.watcher.off("unlink",$),r.watcher.off("unlink",W),r.watcher.off("add",b),r.watcher.off("change",b),r.watcher.off("unlink",b))};return()=>{Me(r,S,ae)}},buildEnd(){_e(S,this.environment)},name:"lunora:codegen"}};export{qe as default};
|