@lunora/vite 1.0.0-alpha.419 → 1.0.0-alpha.420
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/README.md
CHANGED
|
@@ -70,7 +70,6 @@ With no options, `lunora()` runs codegen on save, validates `wrangler.jsonc`, in
|
|
|
70
70
|
lunora({
|
|
71
71
|
schemaDir: "lunora", // dir with schema.ts + function files (generated output lands in <schemaDir>/_generated)
|
|
72
72
|
apiSpec: "openapi", // "openapi" | "openrpc" | "both" | "none"
|
|
73
|
-
lazyFunctions: true, // optional per-module lazy function imports; lunora prepare/build/deploy regenerate with their own --lazy-functions flag
|
|
74
73
|
target: "cloudflare", // deploy target the emitted ctx.* surface is tailored to
|
|
75
74
|
allowUnauthenticatedShardAccess: false, // composed class-A worker: allow a client-named shard / fan-out with no authorizeShard
|
|
76
75
|
shard: { cdc: true, reactiveCache: true }, // class-A only: shard DO config for the composed entry (class B/C set this in their own worker entry)
|
|
@@ -83,9 +82,11 @@ lunora({
|
|
|
83
82
|
|
|
84
83
|
`target` must match the target the CLI resolved for the run. `lunora build` and `lunora deploy` set `LUNORA_BUILD_TARGET`, and a plugin whose target differs fails the build rather than emit an artifact for another host. Set the same target in the plugin options and `lunora.config.*`, or leave it unset to use the project's.
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
`
|
|
88
|
-
`lunora
|
|
85
|
+
The plugin has no lazy-functions option. Set `codegen: { lazyFunctions: true }`
|
|
86
|
+
in `lunora.config.ts` instead: codegen reads it on every run, so the plugin and
|
|
87
|
+
`lunora codegen`/`prepare`/`verify`/`build`/`deploy` all generate the same
|
|
88
|
+
registry. `LUNORA_LAZY_FUNCTIONS=1` or `true` also enables lazy imports for one
|
|
89
|
+
run; `lunora dev --lazy-functions` sets it for its bundler child process.
|
|
89
90
|
|
|
90
91
|
`lunora()` returns a flat `Plugin[]`; Vite flattens nested plugin arrays, so `plugins: [lunora()]` works without spreading.
|
|
91
92
|
|
package/dist/index.d.mts
CHANGED
|
@@ -77,8 +77,6 @@ interface LunoraPluginOptions {
|
|
|
77
77
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
78
78
|
/** Pass through to `@cloudflare/vite-plugin`. Pass `false` to opt out. Defaults to `true`. */
|
|
79
79
|
cloudflare?: boolean | CloudflarePluginOptions;
|
|
80
|
-
/** Emit a per-module lazy function registry; omitted keeps the eager registry. */
|
|
81
|
-
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
82
80
|
/**
|
|
83
81
|
* Inject `@visulima/vite-overlay` for runtime errors (dev only). Pass
|
|
84
82
|
* `false` to opt out, or an options object to forward to the overlay.
|
|
@@ -128,6 +126,7 @@ interface ResolvedLunoraPluginOptions {
|
|
|
128
126
|
* build. Derived, so the import base cannot disagree with the emitter.
|
|
129
127
|
*/
|
|
130
128
|
generatedDir: string;
|
|
129
|
+
/** `LUNORA_LAZY_FUNCTIONS`, which `lunora dev`/`build` set for this process; `codegen.lazyFunctions` in `lunora.config.*` is read by codegen itself. */
|
|
131
130
|
lazyFunctions: boolean;
|
|
132
131
|
overlay: false | OverlayPluginOptions;
|
|
133
132
|
projectRoot: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -77,8 +77,6 @@ interface LunoraPluginOptions {
|
|
|
77
77
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
78
78
|
/** Pass through to `@cloudflare/vite-plugin`. Pass `false` to opt out. Defaults to `true`. */
|
|
79
79
|
cloudflare?: boolean | CloudflarePluginOptions;
|
|
80
|
-
/** Emit a per-module lazy function registry; omitted keeps the eager registry. */
|
|
81
|
-
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
82
80
|
/**
|
|
83
81
|
* Inject `@visulima/vite-overlay` for runtime errors (dev only). Pass
|
|
84
82
|
* `false` to opt out, or an options object to forward to the overlay.
|
|
@@ -128,6 +126,7 @@ interface ResolvedLunoraPluginOptions {
|
|
|
128
126
|
* build. Derived, so the import base cannot disagree with the emitter.
|
|
129
127
|
*/
|
|
130
128
|
generatedDir: string;
|
|
129
|
+
/** `LUNORA_LAZY_FUNCTIONS`, which `lunora dev`/`build` set for this process; `codegen.lazyFunctions` in `lunora.config.*` is read by codegen itself. */
|
|
131
130
|
lazyFunctions: boolean;
|
|
132
131
|
overlay: false | OverlayPluginOptions;
|
|
133
132
|
projectRoot: string;
|
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
|
|
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-B0AIEefi.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
|
-
`)}},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)=>
|
|
4
|
-
`,"utf8")}}},R="/_lunora",Be=8787,v=new Map,W=r=>r.command==="serve"&&r.isPreview!==!0,
|
|
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
|
+
`,"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 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};
|
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.420",
|
|
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.390",
|
|
50
|
+
"@lunora/config": "1.0.0-alpha.447",
|
|
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 ce}from"node:fs";import{resolve as E,dirname as ae,sep as D,basename as x,join as G,relative as se}from"node:path";import{readServiceBindings as de,PROJECT_CONFIG_FILENAMES as L,projectConfigCandidatePaths as B,createCodegenProject as Q,runCodegen as le,findTsconfig as fe,isTestPath as ue,fingerprintSchemaSources as U,refreshCodegenProject as ge,CodegenDiagnosticError as me}from"@lunora/codegen";import{LUNORA_TAG as w,isCodegenDisabled as he,CODEGEN_ENV as V,writeApiSpecMarker as pe,reportCodegenFindings as we,blockingFindingsMessage as Se,STRICT_ADVISORIES_ENV as ye,runPostCodegenHook as H}from"@lunora/config";import{WRANGLER_FILES as ve,wranglerCodegenInputs as Ee,reconcileWranglerExtras as Re,reconcileBindingsSafely as ke}from"@lunora/config/cloudflare";import{consumeStudioWrite as Ce}from"@lunora/config/studio-host";import{isRunnableDevEnvironment as je}from"vite";import{c as N,m as $e,o as be}from"./build-session-D75JzvIT.mjs";import De from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as Te,r as Pe}from"./server-close-DWiO4Vxb.mjs";const _e=100,Y=300,J=2,Me=e=>{let i,c=!1,n,f=0;const a=()=>{i&&(clearTimeout(i),i=void 0)},d=(s,y)=>{n&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,e.fingerprint()!==s){if(f+=1,f>J){e.logger.warn(`${w} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(J)} 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()}},Y)},h=(s,y)=>{e.regenerate(s,R=>{d(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)},_e)};return{cancelPending:a,dispose:()=>{a(),n&&(clearTimeout(n),n=void 0)},onSave:s=>{S(s,!0)},onStudioWrite:s=>{S(s,!1)}}},K=/[/\\]tsconfig\..+\.json$/u,Ae=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,Fe=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
|
-
`)},Ie=(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(!ce(f))return Ie(f,i,c),{};try{const a=n??Q(G(e.projectRoot,e.schemaDir)),d=le({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:a,projectRoot:e.projectRoot,target:e.target,...Ee(e.projectRoot)});Re(e.projectRoot,d.cronTriggers,i);let h;try{pe(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 we(d,i),{blockingMessage:Se(d,{strictAdvisories:process.env[ye]!=="0"}),markerFailure:h,outputDirectory:E(d.outputDirectory),project:a}}catch(a){const d=a instanceof Error?a.message:String(a);return i.error(`${w} codegen failed: ${d}`),c?.onError(a,d),{failure:`${w} codegen failed: ${d}`}}},Ne=(e,i,c)=>{let n;for(const[f,a]of Object.entries(e.environments)){if(f==="client"){n=a;continue}je(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:De,type:"custom"})},P={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},X=new WeakMap,q=async(e,i,c)=>{const n=X.get(e)??new Map;return X.set(e,n),n.has(i)||n.set(i,c()),n.get(i)},Ke=(e,i)=>{const c=E(e.projectRoot,e.schemaDir),n=he(process.env[V]);let f=E(e.projectRoot,e.generatedDir),a=0,d=!1,h;const S=new Map;let s,y=!1,R=!1,p,T;const F=new Set,Z=t=>{const u=F.has(t)?void 0:T;return F.add(t),p!=="build"&&(T=void 0),u},z=async()=>{d=!0;let t;try{t=await H({cwd:e.projectRoot,logger:P})}finally{d=!1}return t.ran&&(a=Date.now(),i?.clear()),t.error},ee=async()=>{T=await be(e,"codegen",()=>{const{blockingMessage:t,failure:u,markerFailure:v,outputDirectory:k}=A(e,P);return{blockingMessage:t,failure:u,markerFailure:v,outputDirectory:k}})};return{config(t,u){p=u.command},configResolved(){if(F.clear(),p==="build")return ee();n||(T=A(e,P))},async buildStart(){const t=p!=="build"&&n,u=Z(p==="build"?this.environment.name:"")??(t?{}:A(e,P)),{blockingMessage:v,failure:k,markerFailure:_,outputDirectory:C}=u;p==="build"&&$e(e),p==="build"&&k!==void 0&&this.error(k),p==="build"&&_!==void 0&&this.error(_),f=C??f;const j=C===void 0?void 0:await q(u,"postcodegen",z);p==="build"&&j!==void 0&&this.error(j),p==="build"&&v!==void 0&&this.error(v),await q(u,"reconcile",async()=>ke({...e,cache:i},P,g=>{h?.hot.send({err:{loc:void 0,message:Fe(g),stack:""},type:"error"})})),i?.clear(),h!==void 0&&(s=N(e.projectRoot),y=!0)},configureServer(t){h=t,t.watcher.add(c);const u=de(e.projectRoot).services.filter(r=>r.rpcEntrypoint!==void 0).map(r=>ae(r.wranglerPath));t.watcher.add(u),s=N(e.projectRoot),y=!1;const v={error:r=>{t.config.logger.error(r)},info:r=>{t.config.logger.info(r)},warn:r=>{t.config.logger.warn(r)}};let k=!1;const _={onError(r,o){k=!0;const l=r instanceof me?{column:r.column,file:r.file,line:r.line}:void 0,m=l===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:l,message:m,stack:r instanceof Error?r.stack??"":""},type:"error"})}},C=(r,o)=>r===o||r.startsWith(o+D);let j=!1,g=T?.project;const re=()=>{for(const r of Object.values(t.environments)){const o=r.moduleGraph;for(const l of o.idToModuleMap.values())l.id&&C(l.id,f)&&o.invalidateModule(l)}},te=()=>{g===void 0?g=Q(c):ge(g,c);const{outputDirectory:r}=A(e,v,_,g);return r===void 0?(g=void 0,!1):(f=r,!0)},ne=async(r,o,l)=>{try{if(j||l&&!te())return;const m=U(c);d=!0;let I;try{I=await H({cwd:e.projectRoot,logger:v})}finally{d=!1}if(I.ran&&(a=Date.now(),o(m)),I.error!==void 0)return;re(),Ne(t,r,k),k=!1}catch(m){v.error(`${w} codegen watch: ${m instanceof Error?m.message:String(m)}`)}},M=Me({fingerprint:()=>U(c),logger:v,regenerate:(r,o,l)=>{ne(r,o,l)}}),oe=r=>K.test(r)||L.includes(x(r))&&B(c).includes(r)||r.endsWith(`${D}tsconfig.json`)&&r===fe(c)?(g=void 0,!1):!(!C(r,c)||C(r,f)||!r.endsWith(".ts")||ue(se(c,r).split(D).join("/"))),$=r=>{const o=E(r);if(!(!(Ae.test(o)&&!o.includes(`${D}node_modules${D}`)&&u.some(m=>C(o,m)))&&!oe(o))){if(d||Date.now()-a<Y){M.cancelPending();return}if(Ce(o)){M.onStudioWrite(o);return}M.onSave(o)}},O=r=>{const o=E(r);(o.endsWith(`${D}tsconfig.json`)||K.test(o))&&(g=void 0)};n?t.config.logger.info(`${w} codegen watch disabled (${V}) — _generated/ is written only by an explicit \`lunora codegen\``):(t.watcher.on("add",$),t.watcher.on("change",$),t.watcher.on("unlink",$),t.watcher.on("unlink",O));const W=new Set([...ve.map(r=>E(e.projectRoot,r)),...L.map(r=>E(e.projectRoot,r)),...B(c)]);for(const r of W)t.watcher.add(r);const b=r=>{if(!W.has(E(r))||R)return;const o=N(e.projectRoot);if(!y){s=o;return}if(s===void 0){s=o;return}o!==s&&(s=o,R=!0,t.config.logger.info(`${w} ${x(E(r))} changed — restarting dev server`),Promise.resolve(t.restart()).finally(()=>{R=!1}).catch(l=>{const m=l instanceof Error?l.message:String(l);t.config.logger.error(`${w} dev server restart failed: ${m} — keeping the running server; re-save your config to retry.`),t.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${m}`,stack:""},type:"error"})}))};t.watcher.on("add",b),t.watcher.on("change",b),t.watcher.on("unlink",b);const ie=()=>{j||(j=!0,g=void 0,M.dispose(),t.watcher.off("add",$),t.watcher.off("change",$),t.watcher.off("unlink",$),t.watcher.off("unlink",O),t.watcher.off("add",b),t.watcher.off("change",b),t.watcher.off("unlink",b))};return()=>{Pe(t,S,ie)}},buildEnd(){Te(S,this.environment)},name:"lunora:codegen"}};export{Ke as default};
|