@lunora/vite 1.0.0-alpha.376 → 1.0.0-alpha.378
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 I,relative as M}from"node:path";import{cloudflare as N}from"@cloudflare/vite-plugin";import{BUNDLE_META_PATH_ENV as U,canonicalPath as k,DEFAULT_BUNDLE_META_PATH as F,resolveDeployDriver as H,startCelldDevSession as j,formatLunoraEvent as V,lunoraLine as G,detectFramework as z,targetRunsOwnDevServer as K,resolveLazyFunctions as q,resolveTargetOrThrow as J,isRunnableTarget as Q,runnableTargetIds as Y,assertBuildTargetMatches as X}from"@lunora/config";import{GENERATED_CLASS_MODULES as Er,detectFramework as Tr}from"@lunora/config";import Z from"@visulima/vite-overlay";import{detectAgentRules as ee,claimAgentRulesHint as re,lunoraLine as m,AGENT_RULES_HINT as te}from"@lunora/config/cli";import{reconcileBindingsSafely as oe,findWranglerFile as ne,readWranglerJsonc as ie,warnCloudflareCliConfigOnce as se,hasCloudflareCredentials as ae,withheldBindings as le,describeWithheld as ce,startLocalHyperdrive as ue}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Cr}from"@lunora/config/cloudflare";import{mkdirSync as de,writeFileSync as fe,statSync as pe,rmSync as me}from"node:fs";import{r as L,a as D}from"./packem_shared/server-close-DWiO4Vxb.mjs";import ge from"./packem_shared/codegenPlugin-
|
|
1
|
+
import{createRequire as $}from"node:module";import{sep as O,resolve as h,dirname as B,isAbsolute as I,relative as M}from"node:path";import{cloudflare as N}from"@cloudflare/vite-plugin";import{BUNDLE_META_PATH_ENV as U,canonicalPath as k,DEFAULT_BUNDLE_META_PATH as F,resolveDeployDriver as H,startCelldDevSession as j,formatLunoraEvent as V,lunoraLine as G,detectFramework as z,targetRunsOwnDevServer as K,resolveLazyFunctions as q,resolveTargetOrThrow as J,isRunnableTarget as Q,runnableTargetIds as Y,assertBuildTargetMatches as X}from"@lunora/config";import{GENERATED_CLASS_MODULES as Er,detectFramework as Tr}from"@lunora/config";import Z from"@visulima/vite-overlay";import{detectAgentRules as ee,claimAgentRulesHint as re,lunoraLine as m,AGENT_RULES_HINT as te}from"@lunora/config/cli";import{reconcileBindingsSafely as oe,findWranglerFile as ne,readWranglerJsonc as ie,warnCloudflareCliConfigOnce as se,hasCloudflareCredentials as ae,withheldBindings as le,describeWithheld as ce,startLocalHyperdrive as ue}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Cr}from"@lunora/config/cloudflare";import{mkdirSync as de,writeFileSync as fe,statSync as pe,rmSync as me}from"node:fs";import{r as L,a as D}from"./packem_shared/server-close-DWiO4Vxb.mjs";import ge from"./packem_shared/codegenPlugin-C1aM7GMx.mjs";import ve from"./packem_shared/containerLogsPlugin-BCqWF6EU.mjs";import he from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import we from"./packem_shared/devVariablesPlugin-DbD6cSF0.mjs";import{frameworkComposePlugin as ye}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import{CLASS_A_WIRING as Or,LUNORA_WORKER_VIRTUAL_ID as Lr,buildWorkerEntrySource as Dr,isAutoComposable as Wr}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import Se from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as Pe}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as Br}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as be}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{planViteRemoteBindings as Mr,withRemoteBindings as Nr}from"./packem_shared/planViteRemoteBindings-DYUUW67d.mjs";import{readServiceBindings as ke}from"@lunora/codegen";import{lunoraSolutionFinders as Ae}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as Fr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as Re}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{buildStudioUrl as jr}from"./packem_shared/buildStudioUrl-B9K0wAjC.mjs";import{withWorkerStartupHint as Ee}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as Gr,augmentWorkerStartupError as zr,isWorkerEntryEvalError as Kr}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as Te}from"./packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs";import{default as Jr}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as Yr}from"@lunora/config/studio-host";const _e=r=>({apply:"serve",configureServer(e){return()=>{ee(r.projectRoot).installed||!re()||e.config.logger.warn(`
|
|
2
2
|
${m(te)}
|
|
3
3
|
`)}},name:"lunora:agent-rules-hint"}),Ce=r=>({async config(e,t){t.isPreview!==!0&&await oe(r,{info:o=>{console.info(o)},warn:o=>{console.warn(o)}})},enforce:"pre",name:"lunora:bindings-provision"}),xe=(r,e=O)=>r.split(e).join("/"),b=(r,e)=>I(e)?xe(M(r,e)):e,w=(r,e,t)=>e.map(o=>({kind:t,path:b(r,o)})),Oe=/[?#]/,A=r=>{try{return pe(r).size}catch{return}},Le=(r,e)=>A(r)??A(r.split(Oe)[0]??r)??Buffer.byteLength(e??""),De=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:Le(g,S?.code),imports:[...w(r,S?.importedIds??[],"import-statement"),...w(r,S?.dynamicallyImportedIds??[],"dynamic-import")]}}}i[u]=f}const a=process.env[U],s=a===void 0||a===""?void 0:h(r,a),l=`${k(h(r,".lunora"))}${O}`,c=s!==void 0&&k(s).startsWith(l)?s:h(r,F);if(e!==void 0&&e!==this.environment.name){me(c,{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,de(B(c),{recursive:!0}),fe(c,`${JSON.stringify({inputs:n,outputs:i},void 0,2)}
|
|
4
4
|
`,"utf8")}}},R="/_lunora",We=8787,v=new Map,W=r=>r.command==="serve"&&r.isPreview!==!0,$e=(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}},Be=r=>{const e=ne(r),t=e===void 0?void 0:ie(e).parsed?.dev?.port;return typeof t=="number"?t:We},Ie=(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}}),Me=(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}`)},Ne=(r,e)=>{const t=Be(r),o=new Map;return{apply:(n,i)=>W(i)&&e(),buildEnd(){D(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:(l,c)=>{Me(i,l,c)},port:t,projectRoot:r});v.set(r,a);const s=l=>{i.error(`[lunora] the worker on celld exited (code ${String(l)}) — restart vite dev to bring it back`)};a.exited.then(s).catch(()=>{}),L(n,o,()=>{v.get(r)===a&&v.delete(r),a.stop().catch(l=>{i.error(`[lunora] stopping celld failed: ${l instanceof Error?l.message:String(l)}`)})})},name:"lunora:celld-dev"}},Ue=r=>({configResolved(e){se(r.projectRoot,t=>{e.logger.warn(G(t))})},name:"lunora:cf-config-warning"}),Fe=()=>({}),He={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)"},je=r=>{const e=He[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.`)},Ve=(r,e)=>{let t=!1;const o=()=>{e.framework??=z(r.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&e.framework!==void 0&&(t=!0,console.info(je(e.framework)))},name:"lunora:framework-detect"}},E=r=>Array.isArray(r)?r:[],P=new WeakSet,Ge=(r,e={})=>{let t=!1;const o=r.experimental?.newConfig,n=o!==void 0&&o!==!1,i=e.hasCredentials??(()=>ae({projectRoot:e.projectRoot})),a=s=>{const l=(c,...u)=>{const d=typeof s=="function"?s(c,...u):s,f=d===void 0?void 0:{...d},g=t?[...E(c.artifacts),...E(f?.artifacts)]:[],y=t?le({ai:c.ai??f?.ai,artifacts:g},i):[];for(const p of y)Reflect.deleteProperty(c,p.kind),Reflect.deleteProperty(f??{},p.kind),console.warn(m(ce(p)));return f};return P.add(l),l};return{config(s,l){if(t=l.command==="serve"&&l.isPreview!==!0,n)return;const c=r;P.has(c.config)||(c.config=a(c.config)),Array.isArray(c.auxiliaryWorkers)&&(c.auxiliaryWorkers=c.auxiliaryWorkers.map(u=>P.has(u.config)?u:{...u,config:a(u.config)}))},enforce:"pre",name:"lunora:local-ai-binding"}},ze=5e3,Ke=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=ue,wranglerConfigPath:t})=>{const o=new Map,n=i=>{const a=_(r);let s=!1;a.servers+=1,clearTimeout(a.stopTimer),i(()=>{s||(s=!0,a.servers-=1,a.servers===0&&(a.stopTimer=C(a,ze)))})};return{async config(i,a){if(a.command!=="serve")return;const s=_(r);clearTimeout(s.stopTimer);const l=s.pending,c=(async()=>{await l,await s.stopping;const u=await e({onWarning:d=>{console.warn(m(d))},projectRoot:r,wranglerConfigPath:t});u!==void 0&&s.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.`))})();s.pending=c.catch(()=>{});try{await c}finally{s.servers===0&&(clearTimeout(s.stopTimer),s.stopTimer=C(s,Ke))}},buildEnd(){D(o,this.environment)},configureServer(i){n(a=>{L(i,o,a)})},configurePreviewServer(i){n(a=>{i.httpServer.once("close",a)})},enforce:"pre",name:"lunora:local-hyperdrive"}},Je=(r,e)=>({config(t,o){if(o.command!=="serve")return;const{services:n}=ke(e),i=Array.isArray(r.auxiliaryWorkers)?r.auxiliaryWorkers:[],a=new Set(i.map(l=>l.configPath===void 0?"":h(e,l.configPath))),s=[...new Set(n.map(l=>l.wranglerPath))].filter(l=>!a.has(l)).map(l=>({configPath:l}));s.length>0&&(r.auxiliaryWorkers=[...i,...s])},enforce:"pre",name:"lunora:service-workers"}),Qe=r=>{if(r===!1)return!1;const e=r===!0||r===void 0?{}:r;return{...e,forwardedConsoleMethods:e.forwardedConsoleMethods??["error","warn"],solutionFinders:[...Ae,...e.solutionFinders??[]]}},Ye=(r,e)=>{const t=J(r,e);if(!Q(t)){const o=Y();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 X(t,r),t},Xe=r=>{const e=r??{},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=Ye(n,e.target);return{allowUnauthenticatedShardAccess:e.allowUnauthenticatedShardAccess??!1,apiSpec:e.apiSpec??"openapi",lazyFunctions:q(e.lazyFunctions),cloudflare:o,studio:e.studio??!0,generatedDir:`${t}/_generated`,overlay:Qe(e.overlay),projectRoot:n,schemaDir:t,shard:e.shard??{},target:i,validateWrangler:e.validateWrangler??!0}},Ze=(r,e)=>{const{configPath:t}=r;return typeof t=="string"&&t!==""?h(e,t):void 0},br=r=>{const e=Xe(r),t=Fe(),o=[Ve(e,t),ye(e,t),we(e),Ce(e),ge(e),De(e.projectRoot),Se(),he(e),_e(e),Ue(e),Pe()];e.studio&&o.push(Re(e)),e.validateWrangler&&o.push(Te(e)),e.overlay!==!1&&o.push(Z(e.overlay)),o.push(ve(e));const n=e.cloudflare===!1?void 0:{...e.cloudflare};if(o.push(be(n,{projectRoot:e.projectRoot})),n===void 0&&o.push(x({projectRoot:e.projectRoot})),n!==void 0){o.push(Je(n,e.projectRoot));const i=K(e.target),a=$e(e.projectRoot,e.target),s=()=>i&&a().runs;o.push(...Ie([x({projectRoot:e.projectRoot,wranglerConfigPath:Ze(n,e.projectRoot)}),Ge(n,{projectRoot:e.projectRoot}),...Ee(N(n))],s)),i&&o.push(Ne(e.projectRoot,s),{apply:(l,c)=>c.command==="serve"&&c.isPreview!==!0&&!s(),configureServer(l){l.config.logger.warn(`[lunora] target "${e.target}": vite dev serves the worker in workerd, not on ${e.target} — ${a().reason??"it cannot run this project"}. \`vite build\` then \`lunora deploy\` ships it to ${e.target}.`)},name:"lunora:target-runtime-notice"})}return o},kr=$(import.meta.url)("../package.json").version;export{Or as CLASS_A_WIRING,Er as GENERATED_CLASS_MODULES,Jr as LUNORA_API_UPDATED_EVENT,Lr as LUNORA_WORKER_VIRTUAL_ID,Yr as STUDIO_PATH,kr as VERSION,Gr as WORKER_STARTUP_HINT,zr as augmentWorkerStartupError,jr as buildStudioUrl,Dr as buildWorkerEntrySource,Br as checkLunoraProxy,ge as codegenPlugin,ve as containerLogsPlugin,Tr as detectFramework,he as devStatePlugin,we as devVariablesPlugin,ye as frameworkComposePlugin,Wr as isAutoComposable,Kr as isWorkerEntryEvalError,Se as logStreamPlugin,br as lunora,Fr as lunoraSolutionFinder,Ae as lunoraSolutionFinders,Mr as planViteRemoteBindings,Pe as proxyCheckPlugin,Cr as reconcileWranglerCrons,be as remoteBindingsPlugin,Qe as resolveOverlayOption,Re as studioPlugin,Nr as withRemoteBindings,Ee as withWorkerStartupHint,Te as wranglerValidatorPlugin};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{readFileSync as Y,existsSync as Z}from"node:fs";import{resolve as v,dirname as z,sep as b,basename as I,join as ee,relative as re}from"node:path";import{findProjectConfigFile as te,readServiceBindings as ne,PROJECT_CONFIG_FILENAMES as x,projectConfigCandidatePaths as W,runCodegen as oe,findTsconfig as ie,isTestPath as ce,fingerprintSchemaSources as G,createCodegenProject as ae,refreshCodegenProject as se,CodegenDiagnosticError as le}from"@lunora/codegen";import{LUNORA_TAG as w,isCodegenDisabled as de,CODEGEN_ENV as L,runPostCodegenHook as U,writeApiSpecMarker as fe,reportCodegenFindings as ge,blockingFindingsMessage as ue,STRICT_ADVISORIES_ENV as he}from"@lunora/config";import{findWranglerFile as me,readWranglerJsonc as pe,WRANGLER_FILES as we,reconcileBindingsSafely as ye,wranglerCodegenInputs as Se,reconcileWranglerExtras as ve}from"@lunora/config/cloudflare";import{consumeStudioWrite as Ee}from"@lunora/config/studio-host";import{isRunnableDevEnvironment as Re}from"vite";import{createHash as Ce}from"node:crypto";import $e from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as ke,r as be}from"./server-close-DWiO4Vxb.mjs";const je=(e,t)=>{try{const{parsed:c,text:n}=pe(e);return c===void 0?`raw:${n}`:JSON.stringify(t?t(c):c)}catch{return"unreadable"}},De=e=>{const t={...e},{triggers:c}=t;if(c!==null&&typeof c=="object"){const n={...c};delete n.crons,Object.keys(n).length>0?t.triggers=n:delete t.triggers}return t},O=e=>{const t=me(e),c=t===void 0?"absent":je(t,De),n=te(e);let s="absent";try{n!==void 0&&(s=Ce("sha256").update(Y(n)).digest("hex"))}catch{}return`${c}\0${s}`},Te=100,J=300,V=2,_e=e=>{let t,c=!1,n,s=0;const a=()=>{t&&(clearTimeout(t),t=void 0)},d=(f,S)=>{n&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,e.fingerprint()!==f){if(s+=1,s>V){e.logger.warn(`${w} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(V)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${w} schema changed while \`postcodegen\` was running — regenerating`),S()}},J)},y=(f,S)=>{e.regenerate(f,g=>{d(g,()=>{y(f,!0)})},S)},m=(f,S)=>{const g=S||t!==void 0&&c;a(),s=0,c=g,t=setTimeout(()=>{t=void 0,y(f,g)},Te)};return{cancelPending:a,dispose:()=>{a(),n&&(clearTimeout(n),n=void 0)},onSave:f=>{m(f,!0)},onStudioWrite:f=>{m(f,!1)}}},B=/[/\\]tsconfig\..+\.json$/u,Pe=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,Fe=e=>{const t=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.`,...t,"","Add to your worker entry:",...c].join(`
|
|
2
|
+
`)},Oe=(e,t,c)=>{if(t.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,t,c,n)=>{const s=ee(e.projectRoot,e.schemaDir,"schema.ts");if(!Z(s))return Oe(s,t,c),{};try{const a=oe({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:n,projectRoot:e.projectRoot,target:e.target,...Se(e.projectRoot)});ve(e.projectRoot,a.cronTriggers,t);let d;try{fe(e.projectRoot,e.apiSpec)}catch(y){d=`${w} could not write the API spec marker: ${y instanceof Error?y.message:String(y)}`,t.error(d)}return ge(a,t),{blockingMessage:ue(a,{strictAdvisories:process.env[he]!=="0"}),markerFailure:d,outputDirectory:v(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return t.error(`${w} codegen failed: ${d}`),c?.onError(a,d),{failure:`${w} codegen failed: ${d}`}}},Ae=(e,t,c)=>{let n;for(const[s,a]of Object.entries(e.environments)){if(s==="client"){n=a;continue}Re(a)||a.hot.send({path:"*",triggeredBy:t,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:$e,type:"custom"})},T={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Je=e=>{const t=v(e.projectRoot,e.schemaDir),c=de(process.env[L]);let n=v(e.projectRoot,e.generatedDir),s=0,a=!1,d;const y=new Map;let m,f=!1,S=!1,g,_;return{config(o,E){g=E.command},configResolved(){g!=="build"&&c||(_=A(e,T))},async buildStart(){const o=g!=="build"&&c,{blockingMessage:E,failure:R,markerFailure:C,outputDirectory:j}=_??(o?{}:A(e,T));if(_=void 0,g==="build"&&R!==void 0&&this.error(R),g==="build"&&C!==void 0&&this.error(C),j!==void 0){n=j,a=!0;let h;try{h=await U({cwd:e.projectRoot,logger:T})}finally{a=!1}h.ran&&(s=Date.now()),g==="build"&&h.error!==void 0&&this.error(h.error)}g==="build"&&E!==void 0&&this.error(E),await ye(e,T,h=>{d?.hot.send({err:{loc:void 0,message:Fe(h),stack:""},type:"error"})}),d!==void 0&&(m=O(e.projectRoot),f=!0)},configureServer(o){d=o,o.watcher.add(t);const E=ne(e.projectRoot).services.filter(r=>r.rpcEntrypoint!==void 0).map(r=>z(r.wranglerPath));o.watcher.add(E),m=O(e.projectRoot),f=!1;const R={error:r=>{o.config.logger.error(r)},info:r=>{o.config.logger.info(r)},warn:r=>{o.config.logger.warn(r)}};let C=!1;const j={onError(r,i){C=!0;const l=r instanceof le?{column:r.column,file:r.file,line:r.line}:void 0,u=l===void 0?`[lunora] codegen failed: ${i}
|
|
3
|
+
(see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${i}`;d?.hot.send({err:{loc:l,message:u,stack:r instanceof Error?r.stack??"":""},type:"error"})}},h=(r,i)=>r===i||r.startsWith(i+b);let P=!1,p;const H=()=>{for(const r of Object.values(o.environments)){const i=r.moduleGraph;for(const l of i.idToModuleMap.values())l.id&&h(l.id,n)&&i.invalidateModule(l)}},K=()=>{p===void 0?p=ae(t):se(p,t);const{outputDirectory:r}=A(e,R,j,p);return r===void 0?(p=void 0,!1):(n=r,!0)},X=async(r,i,l)=>{try{if(P||l&&!K())return;const u=G(t);a=!0;let F;try{F=await U({cwd:e.projectRoot,logger:R})}finally{a=!1}if(F.ran&&(s=Date.now(),i(u)),F.error!==void 0)return;H(),Ae(o,r,C),C=!1}catch(u){R.error(`${w} codegen watch: ${u instanceof Error?u.message:String(u)}`)}},D=_e({fingerprint:()=>G(t),logger:R,regenerate:(r,i,l)=>{X(r,i,l)}}),q=r=>B.test(r)||x.includes(I(r))&&W(t).includes(r)||r.endsWith(`${b}tsconfig.json`)&&r===ie(t)?(p=void 0,!1):!(!h(r,t)||h(r,n)||!r.endsWith(".ts")||ce(re(t,r).split(b).join("/"))),$=r=>{const i=v(r);if(!(!(Pe.test(i)&&!i.includes(`${b}node_modules${b}`)&&E.some(u=>h(i,u)))&&!q(i))){if(a||Date.now()-s<J){D.cancelPending();return}if(Ee(i)){D.onStudioWrite(i);return}D.onSave(i)}},N=r=>{const i=v(r);(i.endsWith(`${b}tsconfig.json`)||B.test(i))&&(p=void 0)};c?o.config.logger.info(`${w} codegen watch disabled (${L}) — _generated/ is written only by an explicit \`lunora codegen\``):(o.watcher.on("add",$),o.watcher.on("change",$),o.watcher.on("unlink",$),o.watcher.on("unlink",N));const M=new Set([...we.map(r=>v(e.projectRoot,r)),...x.map(r=>v(e.projectRoot,r)),...W(t)]);for(const r of M)o.watcher.add(r);const k=r=>{if(!M.has(v(r))||S)return;const i=O(e.projectRoot);if(!f){m=i;return}if(m===void 0){m=i;return}i!==m&&(m=i,S=!0,o.config.logger.info(`${w} ${I(v(r))} changed — restarting dev server`),Promise.resolve(o.restart()).finally(()=>{S=!1}).catch(l=>{const u=l instanceof Error?l.message:String(l);o.config.logger.error(`${w} dev server restart failed: ${u} — keeping the running server; re-save your config to retry.`),o.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${u}`,stack:""},type:"error"})}))};o.watcher.on("add",k),o.watcher.on("change",k),o.watcher.on("unlink",k);const Q=()=>{P||(P=!0,p=void 0,D.dispose(),o.watcher.off("add",$),o.watcher.off("change",$),o.watcher.off("unlink",$),o.watcher.off("unlink",N),o.watcher.off("add",k),o.watcher.off("change",k),o.watcher.off("unlink",k))};return()=>{be(o,y,Q)}},buildEnd(){ke(y,this.environment)},name:"lunora:codegen"}};export{Je 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.378",
|
|
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.351",
|
|
50
|
+
"@lunora/config": "1.0.0-alpha.404",
|
|
51
51
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
52
52
|
"@visulima/vite-overlay": "2.0.41"
|
|
53
53
|
},
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{readFileSync as Q,existsSync as Y}from"node:fs";import{resolve as p,dirname as Z,sep as k,basename as I,join as z,relative as ee}from"node:path";import{findProjectConfigFile as re,readServiceBindings as te,PROJECT_CONFIG_FILENAMES as x,projectConfigCandidatePaths as G,runCodegen as ne,findTsconfig as oe,isTestPath as ie,fingerprintSchemaSources as L,createCodegenProject as ce,refreshCodegenProject as ae,CodegenDiagnosticError as se}from"@lunora/codegen";import{LUNORA_TAG as m,isCodegenDisabled as le,CODEGEN_ENV as W,runPostCodegenHook as U,writeApiSpecMarker as de,reportCodegenFindings as fe,blockingFindingsMessage as ge,STRICT_ADVISORIES_ENV as ue}from"@lunora/config";import{findWranglerFile as he,readWranglerJsonc as me,WRANGLER_FILES as pe,reconcileBindingsSafely as we,wranglerCodegenInputs as ye,reconcileWranglerExtras as Se}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as ve}from"vite";import{createHash as Ee}from"node:crypto";import Re from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as $e,r as ke}from"./server-close-DWiO4Vxb.mjs";const Ce=(e,t)=>{try{const{parsed:i,text:n}=me(e);return i===void 0?`raw:${n}`:JSON.stringify(t?t(i):i)}catch{return"unreadable"}},je=e=>{const t={...e},{triggers:i}=t;if(i!==null&&typeof i=="object"){const n={...i};delete n.crons,Object.keys(n).length>0?t.triggers=n:delete t.triggers}return t},O=e=>{const t=he(e),i=t===void 0?"absent":Ce(t,je),n=re(e);let l="absent";try{n!==void 0&&(l=Ee("sha256").update(Q(n)).digest("hex"))}catch{}return`${i}\0${l}`},be=100,J=300,V=2,De=e=>{let t,i,n=0;const l=()=>{t&&(clearTimeout(t),t=void 0)},a=(f,g)=>{i&&clearTimeout(i),i=setTimeout(()=>{if(i=void 0,e.fingerprint()!==f){if(n+=1,n>V){e.logger.warn(`${m} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(V)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${m} schema changed while \`postcodegen\` was running — regenerating`),g()}},J)},d=f=>{e.regenerate(f,g=>{a(g,()=>{d(f)})})};return{cancelPending:l,dispose:()=>{l(),i&&(clearTimeout(i),i=void 0)},onSave:f=>{l(),n=0,t=setTimeout(()=>{t=void 0,d(f)},be)}}},B=/[/\\]tsconfig\..+\.json$/u,Te=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,_e=e=>{const t=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.`,...t,"","Add to your worker entry:",...i].join(`
|
|
2
|
-
`)},Pe=(e,t,i)=>{if(t.warn(`${m} 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)}},A=(e,t,i,n)=>{const l=z(e.projectRoot,e.schemaDir,"schema.ts");if(!Y(l))return Pe(l,t,i),{};try{const a=ne({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:n,projectRoot:e.projectRoot,target:e.target,...ye(e.projectRoot)});Se(e.projectRoot,a.cronTriggers,t);let d;try{de(e.projectRoot,e.apiSpec)}catch(f){d=`${m} could not write the API spec marker: ${f instanceof Error?f.message:String(f)}`,t.error(d)}return fe(a,t),{blockingMessage:ge(a,{strictAdvisories:process.env[ue]!=="0"}),markerFailure:d,outputDirectory:p(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return t.error(`${m} codegen failed: ${d}`),i?.onError(a,d),{failure:`${m} codegen failed: ${d}`}}},Fe=(e,t,i)=>{let n;for(const[l,a]of Object.entries(e.environments)){if(l==="client"){n=a;continue}ve(a)||a.hot.send({path:"*",triggeredBy:t,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:Re,type:"custom"})},j={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Ue=e=>{const t=p(e.projectRoot,e.schemaDir),i=le(process.env[W]);let n=p(e.projectRoot,e.generatedDir),l=0,a=!1,d;const f=new Map;let g,b=!1,D=!1,y,T;return{config(o,S){y=S.command},configResolved(){y!=="build"&&i||(T=A(e,j))},async buildStart(){const o=y!=="build"&&i,{blockingMessage:S,failure:v,markerFailure:E,outputDirectory:C}=T??(o?{}:A(e,j));if(T=void 0,y==="build"&&v!==void 0&&this.error(v),y==="build"&&E!==void 0&&this.error(E),C!==void 0){n=C,a=!0;let u;try{u=await U({cwd:e.projectRoot,logger:j})}finally{a=!1}u.ran&&(l=Date.now()),y==="build"&&u.error!==void 0&&this.error(u.error)}y==="build"&&S!==void 0&&this.error(S),await we(e,j,u=>{d?.hot.send({err:{loc:void 0,message:_e(u),stack:""},type:"error"})}),d!==void 0&&(g=O(e.projectRoot),b=!0)},configureServer(o){d=o,o.watcher.add(t);const S=te(e.projectRoot).services.filter(r=>r.rpcEntrypoint!==void 0).map(r=>Z(r.wranglerPath));o.watcher.add(S),g=O(e.projectRoot),b=!1;const v={error:r=>{o.config.logger.error(r)},info:r=>{o.config.logger.info(r)},warn:r=>{o.config.logger.warn(r)}};let E=!1;const C={onError(r,c){E=!0;const s=r instanceof se?{column:r.column,file:r.file,line:r.line}:void 0,w=s===void 0?`[lunora] codegen failed: ${c}
|
|
3
|
-
(see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${c}`;d?.hot.send({err:{loc:s,message:w,stack:r instanceof Error?r.stack??"":""},type:"error"})}},u=(r,c)=>r===c||r.startsWith(c+k);let _=!1,h;const H=()=>{for(const r of Object.values(o.environments)){const c=r.moduleGraph;for(const s of c.idToModuleMap.values())s.id&&u(s.id,n)&&c.invalidateModule(s)}},K=async(r,c)=>{try{if(_)return;h===void 0?h=ce(t):ae(h,t);const{outputDirectory:s}=A(e,v,C,h);if(s===void 0){h=void 0;return}n=s;const w=L(t);a=!0;let F;try{F=await U({cwd:e.projectRoot,logger:v})}finally{a=!1}if(F.ran&&(l=Date.now(),c(w)),F.error!==void 0)return;H(),Fe(o,r,E),E=!1}catch(s){v.error(`${m} codegen watch: ${s instanceof Error?s.message:String(s)}`)}},P=De({fingerprint:()=>L(t),logger:v,regenerate:(r,c)=>{K(r,c)}}),X=r=>B.test(r)||x.includes(I(r))&&G(t).includes(r)||r.endsWith(`${k}tsconfig.json`)&&r===oe(t)?(h=void 0,!1):!(!u(r,t)||u(r,n)||!r.endsWith(".ts")||ie(ee(t,r).split(k).join("/"))),R=r=>{const c=p(r);if(!(!(Te.test(c)&&!c.includes(`${k}node_modules${k}`)&&S.some(w=>u(c,w)))&&!X(c))){if(a||Date.now()-l<J){P.cancelPending();return}P.onSave(c)}},M=r=>{const c=p(r);(c.endsWith(`${k}tsconfig.json`)||B.test(c))&&(h=void 0)};i?o.config.logger.info(`${m} codegen watch disabled (${W}) — _generated/ is written only by an explicit \`lunora codegen\``):(o.watcher.on("add",R),o.watcher.on("change",R),o.watcher.on("unlink",R),o.watcher.on("unlink",M));const N=new Set([...pe.map(r=>p(e.projectRoot,r)),...x.map(r=>p(e.projectRoot,r)),...G(t)]);for(const r of N)o.watcher.add(r);const $=r=>{if(!N.has(p(r))||D)return;const c=O(e.projectRoot);if(!b){g=c;return}if(g===void 0){g=c;return}c!==g&&(g=c,D=!0,o.config.logger.info(`${m} ${I(p(r))} changed — restarting dev server`),Promise.resolve(o.restart()).finally(()=>{D=!1}).catch(s=>{const w=s instanceof Error?s.message:String(s);o.config.logger.error(`${m} dev server restart failed: ${w} — keeping the running server; re-save your config to retry.`),o.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${w}`,stack:""},type:"error"})}))};o.watcher.on("add",$),o.watcher.on("change",$),o.watcher.on("unlink",$);const q=()=>{_||(_=!0,h=void 0,P.dispose(),o.watcher.off("add",R),o.watcher.off("change",R),o.watcher.off("unlink",R),o.watcher.off("unlink",M),o.watcher.off("add",$),o.watcher.off("change",$),o.watcher.off("unlink",$))};return()=>{ke(o,f,q)}},buildEnd(){$e(f,this.environment)},name:"lunora:codegen"}};export{Ue as default};
|