@lunora/vite 1.0.0-alpha.103 → 1.0.0-alpha.104

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.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { CodegenOptions } from '@lunora/codegen';
2
2
  import errorOverlayPlugin from '@visulima/vite-overlay';
3
3
  import { Plugin } from 'vite';
4
- import { FrameworkDetection, DetectedFramework, materializeRemoteWranglerConfig, readProjectRemotePreference } from '@lunora/config';
5
- export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, type ReconcileCronsResult as ReconcileResult, detectFramework, reconcileWranglerCrons } from '@lunora/config';
4
+ import { materializeRemoteWranglerConfig } from '@lunora/config/cloudflare';
5
+ export { type ReconcileCronsResult as ReconcileResult, reconcileWranglerCrons } from '@lunora/config/cloudflare';
6
+ import { FrameworkDetection, DetectedFramework, readProjectRemotePreference } from '@lunora/config';
7
+ export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, detectFramework } from '@lunora/config';
6
8
  import { AddressInfo } from 'node:net';
7
9
  /** Options forwarded to `@cloudflare/vite-plugin`'s cloudflare plugin. */
8
10
  type CloudflarePluginOptions = Record<string, unknown>;
@@ -47,6 +49,16 @@ interface LunoraPluginOptions {
47
49
  schemaDir?: string;
48
50
  /** Serve the Lunora studio at `/__lunora` during dev. Pass `false` to opt out. Defaults to `true`. */
49
51
  studio?: boolean;
52
+ /**
53
+ * Deploy target the emitted `ctx.*` surface is tailored to. Defaults to
54
+ * `"target"` in `lunora.json`, then `"cloudflare"` — so an existing project
55
+ * emits byte-identical output.
56
+ *
57
+ * Set it here only to override the project config for one build — keeping
58
+ * this and `lunora deploy` on the same target is what the shared resolution
59
+ * in `@lunora/config` exists to guarantee.
60
+ */
61
+ target?: string;
50
62
  /** Validate that `wrangler.jsonc` declares the bindings the schema implies. Defaults to `true`. */
51
63
  validateWrangler?: boolean;
52
64
  }
@@ -60,6 +72,7 @@ interface ResolvedLunoraPluginOptions {
60
72
  projectRoot: string;
61
73
  schemaDir: string;
62
74
  studio: boolean;
75
+ target: string;
63
76
  validateWrangler: boolean;
64
77
  }
65
78
  /**
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { CodegenOptions } from '@lunora/codegen';
2
2
  import errorOverlayPlugin from '@visulima/vite-overlay';
3
3
  import { Plugin } from 'vite';
4
- import { FrameworkDetection, DetectedFramework, materializeRemoteWranglerConfig, readProjectRemotePreference } from '@lunora/config';
5
- export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, type ReconcileCronsResult as ReconcileResult, detectFramework, reconcileWranglerCrons } from '@lunora/config';
4
+ import { materializeRemoteWranglerConfig } from '@lunora/config/cloudflare';
5
+ export { type ReconcileCronsResult as ReconcileResult, reconcileWranglerCrons } from '@lunora/config/cloudflare';
6
+ import { FrameworkDetection, DetectedFramework, readProjectRemotePreference } from '@lunora/config';
7
+ export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, detectFramework } from '@lunora/config';
6
8
  import { AddressInfo } from 'node:net';
7
9
  /** Options forwarded to `@cloudflare/vite-plugin`'s cloudflare plugin. */
8
10
  type CloudflarePluginOptions = Record<string, unknown>;
@@ -47,6 +49,16 @@ interface LunoraPluginOptions {
47
49
  schemaDir?: string;
48
50
  /** Serve the Lunora studio at `/__lunora` during dev. Pass `false` to opt out. Defaults to `true`. */
49
51
  studio?: boolean;
52
+ /**
53
+ * Deploy target the emitted `ctx.*` surface is tailored to. Defaults to
54
+ * `"target"` in `lunora.json`, then `"cloudflare"` — so an existing project
55
+ * emits byte-identical output.
56
+ *
57
+ * Set it here only to override the project config for one build — keeping
58
+ * this and `lunora deploy` on the same target is what the shared resolution
59
+ * in `@lunora/config` exists to guarantee.
60
+ */
61
+ target?: string;
50
62
  /** Validate that `wrangler.jsonc` declares the bindings the schema implies. Defaults to `true`. */
51
63
  validateWrangler?: boolean;
52
64
  }
@@ -60,6 +72,7 @@ interface ResolvedLunoraPluginOptions {
60
72
  projectRoot: string;
61
73
  schemaDir: string;
62
74
  studio: boolean;
75
+ target: string;
63
76
  validateWrangler: boolean;
64
77
  }
65
78
  /**
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import{createRequire as u}from"node:module";import{cloudflare as m}from"@cloudflare/vite-plugin";import d from"@visulima/vite-overlay";import{detectAgentRules as c,claimAgentRulesHint as p,AGENT_RULES_HINT as f,detectFramework as g}from"@lunora/config";import{detectFramework as sr,reconcileWranglerCrons as lr}from"@lunora/config";import{g as i}from"./packem_shared/log-DTdeAemA.mjs";import S from"./packem_shared/codegenPlugin-Cw1lSUC0.mjs";import R from"./packem_shared/containerLogsPlugin-QOsfYAYL.mjs";import k from"./packem_shared/devStatePlugin-CMRBp9zZ.mjs";import h from"./packem_shared/devVariablesPlugin-0SvpKjRJ.mjs";import{createCommandProbe as v,withDevWorkerEnv as w}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{DEV_WORKER_ENV_VALUE as mr,DEV_WORKER_ENV_VAR as dr}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{frameworkComposePlugin as P}from"./packem_shared/CLASS_A_WIRING-QlSvg7Ku.mjs";import{CLASS_A_WIRING as pr,LUNORA_WORKER_VIRTUAL_ID as fr,buildWorkerEntrySource as gr,isAutoComposable as Sr}from"./packem_shared/CLASS_A_WIRING-QlSvg7Ku.mjs";import E from"./packem_shared/logStreamPlugin-CFlQAr0R.mjs";import{proxyCheckPlugin as A}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{checkLunoraProxy as kr}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{planViteRemoteBindings as _,remoteBindingsCleanupPlugin as W,remoteBindingsConfigPlugin as x}from"./packem_shared/planViteRemoteBindings-BDAdqq6D.mjs";import{withRemoteBindings as vr}from"./packem_shared/planViteRemoteBindings-BDAdqq6D.mjs";import{lunoraSolutionFinders as C}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{lunoraSolutionFinder as Pr}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{studioPlugin as D}from"./packem_shared/STUDIO_PATH-CCACdfgp.mjs";import{STUDIO_PATH as Ar,buildStudioUrl as _r}from"./packem_shared/STUDIO_PATH-CCACdfgp.mjs";import{withWorkerStartupHint as V}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{WORKER_STARTUP_HINT as xr,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as Dr}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{wranglerValidatorPlugin as $}from"./packem_shared/wranglerValidatorPlugin-CHmNBKbO.mjs";import{default as $r}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";const y=o=>({apply:"serve",configureServer(r){return()=>{c(o.projectRoot).installed||!p()||r.config.logger.warn(`
2
- ${i(f)}
3
- `)}},name:"lunora:agent-rules-hint"}),T=()=>({}),N={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)"},U=o=>{const r=N[o.framework];return o.framework==="none"?i("no meta-framework detected — running standalone."):o.class==="B"?i(`detected ${r} — composition is handled by the framework adapter.`):i(`detected ${r} — composing the Lunora worker into one Cloudflare Worker.`)},L=(o,r)=>{let t=!1;const e=()=>{r.framework??=g(o.projectRoot)};return{config(){e()},configResolved(){e()},configureServer(){e(),!t&&r.framework!==void 0&&(t=!0,console.info(U(r.framework)))},name:"lunora:framework-detect"}},O=o=>{if(o===!1)return!1;const r=o===!0||o===void 0?{}:o;return{...r,forwardedConsoleMethods:r.forwardedConsoleMethods??["error","warn"],solutionFinders:[...C,...r.solutionFinders??[]]}},I=o=>{const r=o??{},t=r.schemaDir??"lunora";let e;return r.cloudflare===!1?e=!1:r.cloudflare===!0||r.cloudflare===void 0?e={}:e=r.cloudflare,{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess??!1,apiSpec:r.apiSpec??"openapi",cloudflare:e,studio:r.studio??!0,generatedDir:r.generatedDir??`${t}/_generated`,overlay:O(r.overlay),projectRoot:r.projectRoot??process.cwd(),schemaDir:t,validateWrangler:r.validateWrangler??!0}},tr=o=>{const r=I(o),t=T(),{isServe:e,plugin:l}=v(),a=[l,L(r,t),P(r,t),h(r),S(r),E(),k(r),y(r),A()];if(r.studio&&a.push(D()),r.validateWrangler&&a.push($(r)),r.overlay!==!1&&a.push(d(r.overlay)),r.cloudflare!==!1){a.push(R(r));const n=_({projectRoot:r.projectRoot}),s=w(r.cloudflare,e);n.enabled&&(n.configPath!==void 0&&a.push(W(n.cleanup)),a.push(x(s,n))),a.push(...V(m(s)))}return a},ar=u(import.meta.url)("../package.json").version;export{pr as CLASS_A_WIRING,mr as DEV_WORKER_ENV_VALUE,dr as DEV_WORKER_ENV_VAR,$r as LUNORA_API_UPDATED_EVENT,fr as LUNORA_WORKER_VIRTUAL_ID,Ar as STUDIO_PATH,ar as VERSION,xr as WORKER_STARTUP_HINT,Cr as augmentWorkerStartupError,_r as buildStudioUrl,gr as buildWorkerEntrySource,kr as checkLunoraProxy,S as codegenPlugin,R as containerLogsPlugin,v as createCommandProbe,sr as detectFramework,k as devStatePlugin,h as devVariablesPlugin,P as frameworkComposePlugin,Sr as isAutoComposable,Dr as isWorkerEntryEvalError,E as logStreamPlugin,tr as lunora,Pr as lunoraSolutionFinder,C as lunoraSolutionFinders,_ as planViteRemoteBindings,A as proxyCheckPlugin,lr as reconcileWranglerCrons,W as remoteBindingsCleanupPlugin,x as remoteBindingsConfigPlugin,O as resolveOverlayOption,D as studioPlugin,w as withDevWorkerEnv,vr as withRemoteBindings,V as withWorkerStartupHint,$ as wranglerValidatorPlugin};
1
+ import{createRequire as u}from"node:module";import{cloudflare as m}from"@cloudflare/vite-plugin";import{detectAgentRules as d,claimAgentRulesHint as c,AGENT_RULES_HINT as f,detectFramework as p,resolveTargetOrThrow as g}from"@lunora/config";import{detectFramework as lr}from"@lunora/config";import S from"@visulima/vite-overlay";import{g as s}from"./packem_shared/log-DTdeAemA.mjs";import R from"./packem_shared/codegenPlugin-WF3hffSY.mjs";import k from"./packem_shared/containerLogsPlugin-QOsfYAYL.mjs";import h from"./packem_shared/devStatePlugin-CMRBp9zZ.mjs";import v from"./packem_shared/devVariablesPlugin-0SvpKjRJ.mjs";import{createCommandProbe as w,withDevWorkerEnv as P}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{DEV_WORKER_ENV_VALUE as mr,DEV_WORKER_ENV_VAR as dr}from"./packem_shared/DEV_WORKER_ENV_VALUE-CdVg3e_J.mjs";import{frameworkComposePlugin as E}from"./packem_shared/CLASS_A_WIRING-QlSvg7Ku.mjs";import{CLASS_A_WIRING as fr,LUNORA_WORKER_VIRTUAL_ID as pr,buildWorkerEntrySource as gr,isAutoComposable as Sr}from"./packem_shared/CLASS_A_WIRING-QlSvg7Ku.mjs";import A from"./packem_shared/logStreamPlugin-CFlQAr0R.mjs";import{proxyCheckPlugin as _}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{checkLunoraProxy as kr}from"./packem_shared/checkLunoraProxy-n_jVuOU-.mjs";import{planViteRemoteBindings as W,remoteBindingsCleanupPlugin as x,remoteBindingsConfigPlugin as C}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{withRemoteBindings as vr}from"./packem_shared/planViteRemoteBindings-DGYDapgM.mjs";import{lunoraSolutionFinders as D}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{lunoraSolutionFinder as Pr}from"./packem_shared/lunoraSolutionFinder-Dl5pUZK2.mjs";import{studioPlugin as T}from"./packem_shared/STUDIO_PATH-CCACdfgp.mjs";import{STUDIO_PATH as Ar,buildStudioUrl as _r}from"./packem_shared/STUDIO_PATH-CCACdfgp.mjs";import{withWorkerStartupHint as V}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{WORKER_STARTUP_HINT as xr,augmentWorkerStartupError as Cr,isWorkerEntryEvalError as Dr}from"./packem_shared/WORKER_STARTUP_HINT-Dsm2vG6Q.mjs";import{wranglerValidatorPlugin as $}from"./packem_shared/wranglerValidatorPlugin-CjW1aQLs.mjs";import{default as Vr}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{reconcileWranglerCrons as yr}from"@lunora/config/cloudflare";const y=e=>({apply:"serve",configureServer(r){return()=>{d(e.projectRoot).installed||!c()||r.config.logger.warn(`
2
+ ${s(f)}
3
+ `)}},name:"lunora:agent-rules-hint"}),N=()=>({}),O={astro:"Astro",none:"standalone (SPA / SSR-less)",nuxt:"Nuxt","react-router":"React Router","solid-start":"SolidStart",sveltekit:"SvelteKit","tanstack-start":"TanStack Start","tanstack-start-solid":"TanStack Start (Solid)"},U=e=>{const r=O[e.framework];return e.framework==="none"?s("no meta-framework detected — running standalone."):e.class==="B"?s(`detected ${r} — composition is handled by the framework adapter.`):s(`detected ${r} — composing the Lunora worker into one Cloudflare Worker.`)},L=(e,r)=>{let t=!1;const o=()=>{r.framework??=p(e.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&r.framework!==void 0&&(t=!0,console.info(U(r.framework)))},name:"lunora:framework-detect"}},b=e=>{if(e===!1)return!1;const r=e===!0||e===void 0?{}:e;return{...r,forwardedConsoleMethods:r.forwardedConsoleMethods??["error","warn"],solutionFinders:[...D,...r.solutionFinders??[]]}},I=e=>{const r=e??{},t=r.schemaDir??"lunora";let o;r.cloudflare===!1?o=!1:r.cloudflare===!0||r.cloudflare===void 0?o={}:o=r.cloudflare;const n=r.projectRoot??process.cwd();return{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess??!1,apiSpec:r.apiSpec??"openapi",cloudflare:o,studio:r.studio??!0,generatedDir:r.generatedDir??`${t}/_generated`,overlay:b(r.overlay),projectRoot:n,schemaDir:t,target:g(n,r.target),validateWrangler:r.validateWrangler??!0}},ar=e=>{const r=I(e),t=N(),{isServe:o,plugin:n}=w(),a=[n,L(r,t),E(r,t),v(r),R(r),A(),h(r),y(r),_()];if(r.studio&&a.push(T()),r.validateWrangler&&a.push($(r)),r.overlay!==!1&&a.push(S(r.overlay)),r.cloudflare!==!1){a.push(k(r));const i=W({projectRoot:r.projectRoot}),l=P(r.cloudflare,o);i.enabled&&(i.configPath!==void 0&&a.push(x(i.cleanup)),a.push(C(l,i))),a.push(...V(m(l)))}return a},nr=u(import.meta.url)("../package.json").version;export{fr as CLASS_A_WIRING,mr as DEV_WORKER_ENV_VALUE,dr as DEV_WORKER_ENV_VAR,Vr as LUNORA_API_UPDATED_EVENT,pr as LUNORA_WORKER_VIRTUAL_ID,Ar as STUDIO_PATH,nr as VERSION,xr as WORKER_STARTUP_HINT,Cr as augmentWorkerStartupError,_r as buildStudioUrl,gr as buildWorkerEntrySource,kr as checkLunoraProxy,R as codegenPlugin,k as containerLogsPlugin,w as createCommandProbe,lr as detectFramework,h as devStatePlugin,v as devVariablesPlugin,E as frameworkComposePlugin,Sr as isAutoComposable,Dr as isWorkerEntryEvalError,A as logStreamPlugin,ar as lunora,Pr as lunoraSolutionFinder,D as lunoraSolutionFinders,W as planViteRemoteBindings,_ as proxyCheckPlugin,yr as reconcileWranglerCrons,x as remoteBindingsCleanupPlugin,C as remoteBindingsConfigPlugin,b as resolveOverlayOption,T as studioPlugin,P as withDevWorkerEnv,vr as withRemoteBindings,V as withWorkerStartupHint,$ as wranglerValidatorPlugin};
@@ -0,0 +1,3 @@
1
+ import{existsSync as C}from"node:fs";import{join as x,resolve as p,sep as j,basename as A}from"node:path";import{createCodegenProject as F,refreshCodegenProject as G,runCodegen as L,CodegenDiagnosticError as T}from"@lunora/codegen";import{LUNORA_CONFIG_FILE as O,inferLunoraBindings as M}from"@lunora/config";import{findWranglerFile as B,readWranglerJsonc as I,WRANGLER_FILES as J,collectWranglerSecretVariables as V,reconcileWranglerBindings as K,reconcileWranglerCrons as Q,reconcileWranglerCompatibilityDate as U}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as X}from"vite";import Y from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{s as g,A as S}from"./log-DTdeAemA.mjs";import{r as Z,a as q}from"./server-close-C8zGVydc.mjs";const D=(r,o)=>{try{const{parsed:n,text:e}=I(r);return n===void 0?`raw:${e}`:JSON.stringify(o?o(n):n)}catch{return"unreadable"}},z=r=>{const o={...r},{triggers:n}=o;if(n!==null&&typeof n=="object"){const e={...n};delete e.crons,Object.keys(e).length>0?o.triggers=e:delete o.triggers}return o},k=r=>{const o=B(r),n=o===void 0?"absent":D(o,z),e=x(r,O),c=C(e)?D(e):"absent";return`${n}\0${c}`},H=100,ee=/[/\\]tsconfig\..+\.json$/u,re=r=>{const o=r.map(e=>` • ${e.kind} "${e.exportName}" — class ${e.className} is not exported by your worker entry.`),n=[...new Set(r.map(e=>e.module))].map(e=>` export * from "./lunora/_generated/${e}";`);return[`[lunora] ${String(r.length)} declared ${r.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...o,"","Add to your worker entry:",...n].join(`
2
+ `)},oe=async(r,o,n)=>{try{const e=await M({projectRoot:r.projectRoot,schemaDir:r.schemaDir}),c=K(r.projectRoot,e);c.changed&&o.info?.(`${g} inferred bindings → ${c.added.join(", ")} (written to ${c.wranglerPath??"wrangler.jsonc"})`);for(const s of c.warnings)o.warn(`${g} ${s}`);c.exportGaps.length>0&&n?.(c.exportGaps)}catch(e){const c=e instanceof Error?e.message:String(e);o.warn(`${g} binding inference skipped: ${c}`)}},te=(r,o,n)=>{try{const e=Q(r,o);e.changed&&n.info?.(`${g} synced ${o.length.toFixed(0)} cron trigger(s) into ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const c=e instanceof Error?e.message:String(e);n.warn(`${g} cron trigger sync skipped: ${c}`)}try{const e=U(r);e.changed&&n.info?.(`${g} bumped compatibility_date to ${e.date??"unknown"} (Workers Cache enabled) → ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const c=e instanceof Error?e.message:String(e);n.warn(`${g} compatibility date sync skipped: ${c}`)}},W=(r,o,n,e)=>{const c=x(r.projectRoot,r.schemaDir,"schema.ts");if(!C(c)){o.warn(`${g} schema.ts not found at ${c} — codegen skipped`);return}try{const s=L({apiSpec:r.apiSpec,lunoraDirectory:r.schemaDir,project:e,projectRoot:r.projectRoot,target:r.target,wranglerVariables:V(r.projectRoot)});te(r.projectRoot,s.cronTriggers,o);for(const l of s.advisories){const u=S(l.level,l.name,l.detail,l.remediation);l.level==="ERROR"?o.error(u):o.warn(u)}for(const l of s.platformDiagnostics){const u=S(l.level==="error"?"ERROR":"WARN",l.name,l.message,l.remediation);l.level==="error"?o.error(u):o.warn(u)}return p(s.outputDirectory)}catch(s){const l=s instanceof Error?s.message:String(s);o.error(`${g} codegen failed: ${l}`),n?.onError(s,l);return}},ne=(r,o,n)=>{let e;for(const[c,s]of Object.entries(r.environments)){if(c==="client"){e=s;continue}X(s)||s.hot.send({path:"*",triggeredBy:o,type:"full-reload"})}if(e===void 0){r.hot.send({type:"full-reload"});return}if(n){e.hot.send({type:"full-reload"});return}e.hot.send({event:Y,type:"custom"})},pe=r=>{const o=p(r.projectRoot,r.schemaDir);let n=p(r.projectRoot,r.generatedDir),e;const c=new Map;let s,l=!1,u=!1;return{async buildStart(){const t={error:f=>{console.error(f)},info:f=>{console.info(f)},warn:f=>{console.warn(f)}},$=W(r,t);$!==void 0&&(n=$),await oe(r,t,f=>{e?.hot.send({err:{loc:void 0,message:re(f),stack:""},type:"error"})}),e!==void 0&&(s=k(r.projectRoot),l=!0)},configureServer(t){e=t,t.watcher.add(o),s=k(r.projectRoot),l=!1;const $={error:a=>{t.config.logger.error(a)},info:a=>{t.config.logger.info(a)},warn:a=>{t.config.logger.warn(a)}};let f=!1;const _={onError(a,i){f=!0;const d=a instanceof T?{column:a.column,file:a.file,line:a.line}:void 0,y=d===void 0?`[lunora] codegen failed: ${i}
3
+ (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${i}`;e?.hot.send({err:{loc:d,message:y,stack:a instanceof Error?a.stack??"":""},type:"error"})}},R=(a,i)=>a===i||a.startsWith(i+j);let b=!1,m,h;const P=()=>{for(const a of Object.values(t.environments)){const i=a.moduleGraph;for(const d of i.idToModuleMap.values())d.id&&R(d.id,n)&&i.invalidateModule(d)}},w=a=>{const i=p(a);if(R(i,o)&&!R(i,n)){if(i.endsWith(`${j}tsconfig.json`)||ee.test(i)){h=void 0;return}i.endsWith(".ts")&&(i.includes(`${j}__tests__${j}`)||i.endsWith(".test.ts")||i.endsWith(".spec.ts")||(m&&clearTimeout(m),m=setTimeout(()=>{if(m=void 0,b)return;h===void 0?h=F(o):G(h,o);const d=W(r,$,_,h);if(d===void 0){h=void 0;return}n=d,P(),ne(t,i,f),f=!1},H)))}};t.watcher.on("add",w),t.watcher.on("change",w),t.watcher.on("unlink",w);const E=new Set([...J.map(a=>p(r.projectRoot,a)),p(r.projectRoot,O)]);for(const a of E)t.watcher.add(a);const v=a=>{if(!E.has(p(a))||u)return;const i=k(r.projectRoot);if(!l){s=i;return}if(s===void 0){s=i;return}i!==s&&(s=i,u=!0,t.config.logger.info(`${g} ${A(p(a))} changed — restarting dev server`),Promise.resolve(t.restart()).finally(()=>{u=!1}).catch(d=>{const y=d instanceof Error?d.message:String(d);t.config.logger.error(`${g} dev server restart failed: ${y} — keeping the running server; re-save your config to retry.`),t.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${y}`,stack:""},type:"error"})}))};t.watcher.on("add",v),t.watcher.on("change",v),t.watcher.on("unlink",v);const N=()=>{b||(b=!0,h=void 0,m&&(clearTimeout(m),m=void 0),t.watcher.off("add",w),t.watcher.off("change",w),t.watcher.off("unlink",w),t.watcher.off("add",v),t.watcher.off("change",v),t.watcher.off("unlink",v))};return()=>{q(t,c,N)}},buildEnd(){Z(c,this.environment)},name:"lunora:codegen"}};export{pe as default};
@@ -0,0 +1 @@
1
+ import{readProjectRemotePreference as a}from"@lunora/config";import{resolveRemoteEnabled as c,materializeRemoteWranglerConfig as g}from"@lunora/config/cloudflare";import{g as f}from"./log-DTdeAemA.mjs";const s=()=>{},p=e=>{const o=e.readPreference??a;if(!c({configPreference:o(e.projectRoot),envValue:e.remoteEnv??process.env.LUNORA_REMOTE}))return{cleanup:s,enabled:!1};const n=(e.materialize??g)({enabled:!0,projectRoot:e.projectRoot});return{cleanup:n.cleanup,configPath:n.configPath,enabled:!0,reason:n.reason}},d=(e,o)=>!o.enabled||o.configPath===void 0||typeof e.configPath=="string"?e:{...e,configPath:o.configPath},P=(e,o)=>({config(n,r){if(r.command!=="serve")return;const i=d(e,o),t=e;i.configPath!==void 0&&t.configPath===void 0?t.configPath=i.configPath:o.enabled&&o.configPath===void 0&&o.reason!==void 0&&console.info(f(`remote bindings requested but not applied: ${o.reason}`))},enforce:"pre",name:"lunora:remote-bindings-config"}),h=e=>({buildEnd(){e()},closeBundle(){e()},enforce:"pre",name:"lunora:remote-bindings-cleanup"});export{p as planViteRemoteBindings,h as remoteBindingsCleanupPlugin,P as remoteBindingsConfigPlugin,d as withRemoteBindings};
@@ -0,0 +1,3 @@
1
+ import{spawnSync as t}from"node:child_process";import{validateWranglerProject as i,readWranglerJsonc as s}from"@lunora/config/cloudflare";import{LunoraError as l}from"@lunora/errors";import{g as a}from"./log-DTdeAemA.mjs";const c=r=>r.startsWith("./")||r.startsWith("../")||r.startsWith("/")||r.includes("Dockerfile"),g=()=>{try{return t("docker",["info"],{stdio:"ignore"}).status===0}catch{return!1}},d=(r,e=g)=>{const{parsed:n}=s(r);!(n?.containers??[]).some(o=>typeof o?.image=="string"&&c(o.image))||e()||console.warn(a("wrangler.jsonc declares containers built from a local Dockerfile, but no Docker-compatible engine is running. Start Docker (or Colima) before `vite dev`, or the container instances will fail to start."))},m=(r,e)=>{const n=["[lunora] wrangler configuration is missing bindings required by your schema.",` file: ${r}`,"",...e.map(o=>` - ${o}`),""," Update your wrangler.jsonc and restart the dev server."];return new Error(n.join(`
2
+ `))},p=r=>({configResolved(){const e=i({projectRoot:r.projectRoot,schemaDir:r.schemaDir});if(!e.wranglerPath)throw new l("INTERNAL",["[lunora] wrangler.jsonc not found.",` searched in: ${r.projectRoot}`," create a wrangler.jsonc declaring at least the SHARD durable object binding."].join(`
3
+ `));if(e.report.warnings.length>0)for(const n of e.report.warnings)console.warn(a(`wrangler validator: ${n}`));if(e.problems.length>0)throw m(e.wranglerPath,e.problems);d(e.wranglerPath)},name:"lunora:wrangler-validator"});export{d as warnWhenDockerMissing,p as wranglerValidatorPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/vite",
3
- "version": "1.0.0-alpha.103",
3
+ "version": "1.0.0-alpha.104",
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.47.0",
49
- "@lunora/codegen": "1.0.0-alpha.77",
50
- "@lunora/config": "1.0.0-alpha.103",
49
+ "@lunora/codegen": "1.0.0-alpha.79",
50
+ "@lunora/config": "1.0.0-alpha.104",
51
51
  "@lunora/errors": "1.0.0-alpha.9",
52
52
  "@visulima/vite-overlay": "2.0.5",
53
53
  "jsonc-parser": "^3.3.1",
@@ -1,3 +0,0 @@
1
- import{existsSync as W}from"node:fs";import{join as C,resolve as p,sep as j,basename as N}from"node:path";import{createCodegenProject as F,refreshCodegenProject as G,runCodegen as L,CodegenDiagnosticError as T}from"@lunora/codegen";import{findWranglerFile as A,LUNORA_CONFIG_FILE as x,readWranglerJsonc as M,WRANGLER_FILES as B,collectWranglerSecretVariables as I,inferLunoraBindings as J,reconcileWranglerBindings as V,reconcileWranglerCrons as K,reconcileWranglerCompatibilityDate as Q}from"@lunora/config";import{isRunnableDevEnvironment as U}from"vite";import X from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{s as g,A as Y}from"./log-DTdeAemA.mjs";import{r as Z,a as q}from"./server-close-C8zGVydc.mjs";const E=(r,o)=>{try{const{parsed:n,text:e}=M(r);return n===void 0?`raw:${e}`:JSON.stringify(o?o(n):n)}catch{return"unreadable"}},z=r=>{const o={...r},{triggers:n}=o;if(n!==null&&typeof n=="object"){const e={...n};delete e.crons,Object.keys(e).length>0?o.triggers=e:delete o.triggers}return o},k=r=>{const o=A(r),n=o===void 0?"absent":E(o,z),e=C(r,x),a=W(e)?E(e):"absent";return`${n}\0${a}`},H=100,ee=/[/\\]tsconfig\..+\.json$/u,re=r=>{const o=r.map(e=>` • ${e.kind} "${e.exportName}" — class ${e.className} is not exported by your worker entry.`),n=[...new Set(r.map(e=>e.module))].map(e=>` export * from "./lunora/_generated/${e}";`);return[`[lunora] ${String(r.length)} declared ${r.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...o,"","Add to your worker entry:",...n].join(`
2
- `)},oe=async(r,o,n)=>{try{const e=await J({projectRoot:r.projectRoot,schemaDir:r.schemaDir}),a=V(r.projectRoot,e);a.changed&&o.info?.(`${g} inferred bindings → ${a.added.join(", ")} (written to ${a.wranglerPath??"wrangler.jsonc"})`);for(const c of a.warnings)o.warn(`${g} ${c}`);a.exportGaps.length>0&&n?.(a.exportGaps)}catch(e){const a=e instanceof Error?e.message:String(e);o.warn(`${g} binding inference skipped: ${a}`)}},te=(r,o,n)=>{try{const e=K(r,o);e.changed&&n.info?.(`${g} synced ${o.length.toFixed(0)} cron trigger(s) into ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const a=e instanceof Error?e.message:String(e);n.warn(`${g} cron trigger sync skipped: ${a}`)}try{const e=Q(r);e.changed&&n.info?.(`${g} bumped compatibility_date to ${e.date??"unknown"} (Workers Cache enabled) → ${e.wranglerPath??"wrangler.jsonc"}`)}catch(e){const a=e instanceof Error?e.message:String(e);n.warn(`${g} compatibility date sync skipped: ${a}`)}},D=(r,o,n,e)=>{const a=C(r.projectRoot,r.schemaDir,"schema.ts");if(!W(a)){o.warn(`${g} schema.ts not found at ${a} — codegen skipped`);return}try{const c=L({apiSpec:r.apiSpec,lunoraDirectory:r.schemaDir,project:e,projectRoot:r.projectRoot,wranglerVariables:I(r.projectRoot)});te(r.projectRoot,c.cronTriggers,o);for(const d of c.advisories){const m=Y(d.level,d.name,d.detail,d.remediation);d.level==="ERROR"?o.error(m):o.warn(m)}return p(c.outputDirectory)}catch(c){const d=c instanceof Error?c.message:String(c);o.error(`${g} codegen failed: ${d}`),n?.onError(c,d);return}},ne=(r,o,n)=>{let e;for(const[a,c]of Object.entries(r.environments)){if(a==="client"){e=c;continue}U(c)||c.hot.send({path:"*",triggeredBy:o,type:"full-reload"})}if(e===void 0){r.hot.send({type:"full-reload"});return}if(n){e.hot.send({type:"full-reload"});return}e.hot.send({event:X,type:"custom"})},pe=r=>{const o=p(r.projectRoot,r.schemaDir);let n=p(r.projectRoot,r.generatedDir),e;const a=new Map;let c,d=!1,m=!1;return{async buildStart(){const t={error:f=>{console.error(f)},info:f=>{console.info(f)},warn:f=>{console.warn(f)}},v=D(r,t);v!==void 0&&(n=v),await oe(r,t,f=>{e?.hot.send({err:{loc:void 0,message:re(f),stack:""},type:"error"})}),e!==void 0&&(c=k(r.projectRoot),d=!0)},configureServer(t){e=t,t.watcher.add(o),c=k(r.projectRoot),d=!1;const v={error:s=>{t.config.logger.error(s)},info:s=>{t.config.logger.info(s)},warn:s=>{t.config.logger.warn(s)}};let f=!1;const _={onError(s,i){f=!0;const l=s instanceof T?{column:s.column,file:s.file,line:s.line}:void 0,y=l===void 0?`[lunora] codegen failed: ${i}
3
- (see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${i}`;e?.hot.send({err:{loc:l,message:y,stack:s instanceof Error?s.stack??"":""},type:"error"})}},b=(s,i)=>s===i||s.startsWith(i+j);let R=!1,u,h;const P=()=>{for(const s of Object.values(t.environments)){const i=s.moduleGraph;for(const l of i.idToModuleMap.values())l.id&&b(l.id,n)&&i.invalidateModule(l)}},w=s=>{const i=p(s);if(b(i,o)&&!b(i,n)){if(i.endsWith(`${j}tsconfig.json`)||ee.test(i)){h=void 0;return}i.endsWith(".ts")&&(i.includes(`${j}__tests__${j}`)||i.endsWith(".test.ts")||i.endsWith(".spec.ts")||(u&&clearTimeout(u),u=setTimeout(()=>{if(u=void 0,R)return;h===void 0?h=F(o):G(h,o);const l=D(r,v,_,h);if(l===void 0){h=void 0;return}n=l,P(),ne(t,i,f),f=!1},H)))}};t.watcher.on("add",w),t.watcher.on("change",w),t.watcher.on("unlink",w);const S=new Set([...B.map(s=>p(r.projectRoot,s)),p(r.projectRoot,x)]);for(const s of S)t.watcher.add(s);const $=s=>{if(!S.has(p(s))||m)return;const i=k(r.projectRoot);if(!d){c=i;return}if(c===void 0){c=i;return}i!==c&&(c=i,m=!0,t.config.logger.info(`${g} ${N(p(s))} changed — restarting dev server`),Promise.resolve(t.restart()).finally(()=>{m=!1}).catch(l=>{const y=l instanceof Error?l.message:String(l);t.config.logger.error(`${g} dev server restart failed: ${y} — keeping the running server; re-save your config to retry.`),t.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${y}`,stack:""},type:"error"})}))};t.watcher.on("add",$),t.watcher.on("change",$),t.watcher.on("unlink",$);const O=()=>{R||(R=!0,h=void 0,u&&(clearTimeout(u),u=void 0),t.watcher.off("add",w),t.watcher.off("change",w),t.watcher.off("unlink",w),t.watcher.off("add",$),t.watcher.off("change",$),t.watcher.off("unlink",$))};return()=>{q(t,a,O)}},buildEnd(){Z(a,this.environment)},name:"lunora:codegen"}};export{pe as default};
@@ -1 +0,0 @@
1
- import{resolveRemoteEnabled as a,materializeRemoteWranglerConfig as c,readProjectRemotePreference as g}from"@lunora/config";import{g as s}from"./log-DTdeAemA.mjs";const f=()=>{},u=e=>{const n=e.readPreference??g;if(!a({configPreference:n(e.projectRoot),envValue:e.remoteEnv??process.env.LUNORA_REMOTE}))return{cleanup:f,enabled:!1};const o=(e.materialize??c)({enabled:!0,projectRoot:e.projectRoot});return{cleanup:o.cleanup,configPath:o.configPath,enabled:!0,reason:o.reason}},d=(e,n)=>!n.enabled||n.configPath===void 0||typeof e.configPath=="string"?e:{...e,configPath:n.configPath},p=(e,n)=>({config(o,r){if(r.command!=="serve")return;const i=d(e,n),t=e;i.configPath!==void 0&&t.configPath===void 0?t.configPath=i.configPath:n.enabled&&n.configPath===void 0&&n.reason!==void 0&&console.info(s(`remote bindings requested but not applied: ${n.reason}`))},enforce:"pre",name:"lunora:remote-bindings-config"}),P=e=>({buildEnd(){e()},closeBundle(){e()},enforce:"pre",name:"lunora:remote-bindings-cleanup"});export{u as planViteRemoteBindings,P as remoteBindingsCleanupPlugin,p as remoteBindingsConfigPlugin,d as withRemoteBindings};
@@ -1,3 +0,0 @@
1
- import{spawnSync as t}from"node:child_process";import{validateWranglerProject as i,readWranglerJsonc as s}from"@lunora/config";import{LunoraError as l}from"@lunora/errors";import{g as a}from"./log-DTdeAemA.mjs";const c=r=>r.startsWith("./")||r.startsWith("../")||r.startsWith("/")||r.includes("Dockerfile"),g=()=>{try{return t("docker",["info"],{stdio:"ignore"}).status===0}catch{return!1}},d=(r,e=g)=>{const{parsed:n}=s(r);!(n?.containers??[]).some(o=>typeof o?.image=="string"&&c(o.image))||e()||console.warn(a("wrangler.jsonc declares containers built from a local Dockerfile, but no Docker-compatible engine is running. Start Docker (or Colima) before `vite dev`, or the container instances will fail to start."))},m=(r,e)=>{const n=["[lunora] wrangler configuration is missing bindings required by your schema.",` file: ${r}`,"",...e.map(o=>` - ${o}`),""," Update your wrangler.jsonc and restart the dev server."];return new Error(n.join(`
2
- `))},p=r=>({configResolved(){const e=i({projectRoot:r.projectRoot,schemaDir:r.schemaDir});if(!e.wranglerPath)throw new l("INTERNAL",["[lunora] wrangler.jsonc not found.",` searched in: ${r.projectRoot}`," create a wrangler.jsonc declaring at least the SHARD durable object binding."].join(`
3
- `));if(e.report.warnings.length>0)for(const n of e.report.warnings)console.warn(a(`wrangler validator: ${n}`));if(e.problems.length>0)throw m(e.wranglerPath,e.problems);d(e.wranglerPath)},name:"lunora:wrangler-validator"});export{d as warnWhenDockerMissing,p as wranglerValidatorPlugin};