@lunora/vite 1.0.0-alpha.3 → 1.0.0-alpha.300

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.
Files changed (31) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +19 -2
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/index.d.mts +454 -267
  5. package/dist/index.d.ts +454 -267
  6. package/dist/index.mjs +3 -153
  7. package/dist/packem_shared/CLASS_A_WIRING-BAnDZbel.mjs +24 -0
  8. package/dist/packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs +1 -0
  9. package/dist/packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs +5 -0
  10. package/dist/packem_shared/buildStudioUrl-DMMWpguZ.mjs +1 -0
  11. package/dist/packem_shared/checkLunoraProxy-BNPgNWtV.mjs +1 -0
  12. package/dist/packem_shared/codegenPlugin-eWUCZzQt.mjs +3 -0
  13. package/dist/packem_shared/containerLogsPlugin-67PZ8zmb.mjs +1 -0
  14. package/dist/packem_shared/devStatePlugin-CF4GDvBn.mjs +1 -0
  15. package/dist/packem_shared/devVariablesPlugin-DbD6cSF0.mjs +1 -0
  16. package/dist/packem_shared/logStreamPlugin-EMXiy6pI.mjs +3 -0
  17. package/dist/packem_shared/lunoraSolutionFinder--J0x2mAM.mjs +1 -0
  18. package/dist/packem_shared/planViteRemoteBindings-ByOliZuE.mjs +1 -0
  19. package/dist/packem_shared/server-close-DWiO4Vxb.mjs +1 -0
  20. package/dist/packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs +1 -0
  21. package/package.json +9 -10
  22. package/dist/packem_shared/CLASS_A_WIRING-Cja0SF6x.mjs +0 -96
  23. package/dist/packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs +0 -36
  24. package/dist/packem_shared/STUDIO_PATH-5ppCdBHa.mjs +0 -210
  25. package/dist/packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs +0 -81
  26. package/dist/packem_shared/codegenPlugin-BAyt6iWS.mjs +0 -210
  27. package/dist/packem_shared/devVariablesPlugin-BRWbWHhq.mjs +0 -20
  28. package/dist/packem_shared/logStreamPlugin-CqvZ17kd.mjs +0 -61
  29. package/dist/packem_shared/planViteRemoteBindings-QN5ncUS1.mjs +0 -50
  30. package/dist/packem_shared/reconcileWranglerCrons-PxGwfCp_.mjs +0 -29
  31. package/dist/packem_shared/wranglerValidatorPlugin-Cf0nLP7-.mjs +0 -63
package/dist/index.mjs CHANGED
@@ -1,153 +1,3 @@
1
- import { cloudflare } from '@cloudflare/vite-plugin';
2
- import errorOverlayPlugin from '@visulima/vite-overlay';
3
- import { detectAgentRules, claimAgentRulesHint, AGENT_RULES_HINT, detectFramework } from '@lunora/config';
4
- export { detectFramework } from '@lunora/config';
5
- import codegenPlugin from './packem_shared/codegenPlugin-BAyt6iWS.mjs';
6
- import devVariablesPlugin from './packem_shared/devVariablesPlugin-BRWbWHhq.mjs';
7
- import { createCommandProbe, withDevWorkerEnv } from './packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs';
8
- export { DEV_WORKER_ENV_VALUE, DEV_WORKER_ENV_VAR } from './packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs';
9
- import { frameworkComposePlugin } from './packem_shared/CLASS_A_WIRING-Cja0SF6x.mjs';
10
- export { CLASS_A_WIRING, LUNORA_WORKER_VIRTUAL_ID, buildWorkerEntrySource, isAutoComposable } from './packem_shared/CLASS_A_WIRING-Cja0SF6x.mjs';
11
- import logStreamPlugin from './packem_shared/logStreamPlugin-CqvZ17kd.mjs';
12
- import { planViteRemoteBindings, remoteBindingsCleanupPlugin, withRemoteBindings } from './packem_shared/planViteRemoteBindings-QN5ncUS1.mjs';
13
- import { studioPlugin } from './packem_shared/STUDIO_PATH-5ppCdBHa.mjs';
14
- export { STUDIO_PATH, buildStudioUrl } from './packem_shared/STUDIO_PATH-5ppCdBHa.mjs';
15
- import { withWorkerStartupHint } from './packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs';
16
- export { WORKER_STARTUP_HINT, augmentWorkerStartupError, isWorkerEntryEvalError } from './packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs';
17
- import { wranglerValidatorPlugin } from './packem_shared/wranglerValidatorPlugin-Cf0nLP7-.mjs';
18
- export { reconcileWranglerCrons } from './packem_shared/reconcileWranglerCrons-PxGwfCp_.mjs';
19
-
20
- const agentRulesHintPlugin = (options) => {
21
- return {
22
- apply: "serve",
23
- configureServer(server) {
24
- return () => {
25
- if (detectAgentRules(options.projectRoot).installed || !claimAgentRulesHint()) {
26
- return;
27
- }
28
- server.config.logger.warn(`
29
- [lunora] ${AGENT_RULES_HINT}
30
- `);
31
- };
32
- },
33
- name: "lunora:agent-rules-hint"
34
- };
35
- };
36
-
37
- const createPluginContext = () => {
38
- return {};
39
- };
40
- const FRAMEWORK_LABELS = {
41
- astro: "Astro",
42
- none: "standalone (SPA / SSR-less)",
43
- nuxt: "Nuxt",
44
- "react-router": "React Router",
45
- "solid-start": "SolidStart",
46
- sveltekit: "SvelteKit",
47
- "tanstack-start": "TanStack Start",
48
- "tanstack-start-solid": "TanStack Start (Solid)"
49
- };
50
- const formatFrameworkDetection = (detection) => {
51
- const label = FRAMEWORK_LABELS[detection.framework];
52
- if (detection.framework === "none") {
53
- return "[lunora] no meta-framework detected — running standalone (class C).";
54
- }
55
- if (detection.class === "B") {
56
- return `[lunora] detected ${label} (class B) — hook-injection composition is handled by the framework adapter (not yet wired here).`;
57
- }
58
- return `[lunora] detected ${label} (class ${detection.class}) — composing the Lunora worker into one Cloudflare Worker.`;
59
- };
60
- const frameworkDetectPlugin = (options, context) => {
61
- let logged = false;
62
- const detect = () => {
63
- context.framework ??= detectFramework(options.projectRoot);
64
- };
65
- return {
66
- config() {
67
- detect();
68
- },
69
- configResolved() {
70
- detect();
71
- },
72
- configureServer() {
73
- detect();
74
- if (!logged && context.framework !== void 0) {
75
- logged = true;
76
- console.info(formatFrameworkDetection(context.framework));
77
- }
78
- },
79
- name: "lunora:framework-detect"
80
- };
81
- };
82
-
83
- const resolveOptions = (options) => {
84
- const input = options ?? {};
85
- const schemaDirectory = input.schemaDir ?? "lunora";
86
- let cloudflareOption;
87
- if (input.cloudflare === false) {
88
- cloudflareOption = false;
89
- } else if (input.cloudflare === true || input.cloudflare === void 0) {
90
- cloudflareOption = {};
91
- } else {
92
- cloudflareOption = input.cloudflare;
93
- }
94
- let overlayOption;
95
- if (input.overlay === false) {
96
- overlayOption = false;
97
- } else if (input.overlay === true || input.overlay === void 0) {
98
- overlayOption = {};
99
- } else {
100
- overlayOption = input.overlay;
101
- }
102
- return {
103
- apiSpec: input.apiSpec ?? "openapi",
104
- cloudflare: cloudflareOption,
105
- studio: input.studio ?? true,
106
- generatedDir: input.generatedDir ?? `${schemaDirectory}/_generated`,
107
- overlay: overlayOption,
108
- projectRoot: input.projectRoot ?? process.cwd(),
109
- schemaDir: schemaDirectory,
110
- validateWrangler: input.validateWrangler ?? true
111
- };
112
- };
113
- const lunora = (options) => {
114
- const resolved = resolveOptions(options);
115
- const context = createPluginContext();
116
- const { isServe, plugin: commandProbe } = createCommandProbe();
117
- const plugins = [
118
- commandProbe,
119
- frameworkDetectPlugin(resolved, context),
120
- // Reads the detected framework off `context` and, for a class-A
121
- // framework (and only when the CF integration is on), resolves the
122
- // `virtual:lunora/worker` entry to a `composeWorker`-based worker that
123
- // routes `/_lunora/*` to Lunora and falls through to the framework SSR
124
- // handler — so the template never hand-wires `createWorker({ httpRouter })`.
125
- // A strict no-op for class-C and the `cloudflare: false` BYO path.
126
- frameworkComposePlugin(resolved, context),
127
- devVariablesPlugin(resolved),
128
- codegenPlugin(resolved),
129
- logStreamPlugin(),
130
- agentRulesHintPlugin(resolved)
131
- ];
132
- if (resolved.studio) {
133
- plugins.push(studioPlugin());
134
- }
135
- if (resolved.validateWrangler) {
136
- plugins.push(wranglerValidatorPlugin(resolved));
137
- }
138
- if (resolved.overlay !== false) {
139
- plugins.push(errorOverlayPlugin(resolved.overlay));
140
- }
141
- if (resolved.cloudflare !== false) {
142
- const remotePlan = planViteRemoteBindings({ projectRoot: resolved.projectRoot });
143
- if (remotePlan.enabled && remotePlan.configPath !== void 0) {
144
- plugins.push(remoteBindingsCleanupPlugin(remotePlan.cleanup));
145
- }
146
- const cloudflareOptions = withRemoteBindings(withDevWorkerEnv(resolved.cloudflare, isServe), isServe, remotePlan);
147
- plugins.push(...withWorkerStartupHint(cloudflare(cloudflareOptions)));
148
- }
149
- return plugins;
150
- };
151
- const VERSION = "0.0.0";
152
-
153
- export { VERSION, codegenPlugin, createCommandProbe, devVariablesPlugin, frameworkComposePlugin, logStreamPlugin, lunora, planViteRemoteBindings, remoteBindingsCleanupPlugin, studioPlugin, withDevWorkerEnv, withRemoteBindings, withWorkerStartupHint, wranglerValidatorPlugin };
1
+ import{createRequire as p}from"node:module";import{cloudflare as m}from"@cloudflare/vite-plugin";import{detectAgentRules as v,claimAgentRulesHint as h,lunoraLine as d,AGENT_RULES_HINT as S,resolveDeployDriver as w,startCelldDevSession as k,formatLunoraEvent as P,detectFramework as R,targetRunsOwnDevServer as y,resolveTargetOrThrow as x,isRunnableTarget as E,runnableTargetIds as A}from"@lunora/config";import{GENERATED_CLASS_MODULES as br,detectFramework as Cr}from"@lunora/config";import _ from"@visulima/vite-overlay";import{reconcileBindingsSafely as D,findWranglerFile as O,readWranglerJsonc as T}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Ur}from"@lunora/config/cloudflare";import{r as W,a as $}from"./packem_shared/server-close-DWiO4Vxb.mjs";import b from"./packem_shared/codegenPlugin-eWUCZzQt.mjs";import C from"./packem_shared/containerLogsPlugin-67PZ8zmb.mjs";import L from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import U from"./packem_shared/devVariablesPlugin-DbD6cSF0.mjs";import{frameworkComposePlugin as N}from"./packem_shared/CLASS_A_WIRING-BAnDZbel.mjs";import{CLASS_A_WIRING as Fr,LUNORA_WORKER_VIRTUAL_ID as Ir,buildWorkerEntrySource as Br,isAutoComposable as Vr}from"./packem_shared/CLASS_A_WIRING-BAnDZbel.mjs";import F from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as I}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as Hr}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as B}from"./packem_shared/planViteRemoteBindings-ByOliZuE.mjs";import{planViteRemoteBindings as Kr,withRemoteBindings as Gr}from"./packem_shared/planViteRemoteBindings-ByOliZuE.mjs";import{resolve as V}from"node:path";import{readServiceBindings as j}from"@lunora/codegen";import{lunoraSolutionFinders as H}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as Jr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as M}from"./packem_shared/buildStudioUrl-DMMWpguZ.mjs";import{buildStudioUrl as Qr}from"./packem_shared/buildStudioUrl-DMMWpguZ.mjs";import{withWorkerStartupHint as K}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as Yr,augmentWorkerStartupError as Zr,isWorkerEntryEvalError as re}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as G}from"./packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs";import{default as oe}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as ne}from"@lunora/config/studio-host";const q=e=>({apply:"serve",configureServer(r){return()=>{v(e.projectRoot).installed||!h()||r.config.logger.warn(`
2
+ ${d(S)}
3
+ `)}},name:"lunora:agent-rules-hint"}),J=e=>({async config(r,t){t.isPreview!==!0&&await D(e,{info:o=>{console.info(o)},warn:o=>{console.warn(o)}})},enforce:"pre",name:"lunora:bindings-provision"}),f="/_lunora",z=8787,c=new Map,g=e=>e.command==="serve"&&e.isPreview!==!0,Q=(e,r)=>{let t;return()=>{if(t===void 0)try{w(r).projectConfig?.(e,"dev"),t={runs:!0}}catch(o){t={reason:o instanceof Error?o.message:String(o),runs:!1}}return t}},X=e=>{const r=O(e),t=r===void 0?void 0:T(r).parsed?.dev?.port;return typeof t=="number"?t:z},Y=(e,r)=>e.map(t=>{const o=t.apply;return{...t,apply:(n,a)=>g(a)&&r()?!1:typeof o=="function"?o(n,a):o===void 0||o===a.command}}),Z=(e,r,{stream:t,tag:o})=>{const n=P(r);n!==void 0?e[n.level](`[lunora] ${n.text}`):t==="stderr"?e.warn(`[${o}] ${r}`):e.info(`[${o}] ${r}`)},rr=(e,r)=>{const t=X(e),o=new Map;return{apply:(n,a)=>g(a)&&r(),buildEnd(){$(o,this.environment)},config:n=>{if(n.server?.proxy?.[f]===void 0)return{server:{proxy:{[f]:{changeOrigin:!0,target:`http://127.0.0.1:${String(t)}`,ws:!0}}}}},async configureServer(n){const{logger:a}=n.config;await c.get(e)?.stop(),c.delete(e),a.info(`[lunora] starting the worker on celld at http://127.0.0.1:${String(t)} …`);const s=await k({log:(i,u)=>{Z(a,i,u)},port:t,projectRoot:e});c.set(e,s);const l=i=>{a.error(`[lunora] the worker on celld exited (code ${String(i)}) — restart vite dev to bring it back`)};s.exited.then(l).catch(()=>{}),W(n,o,()=>{c.get(e)===s&&c.delete(e),s.stop().catch(i=>{a.error(`[lunora] stopping celld failed: ${i instanceof Error?i.message:String(i)}`)})})},name:"lunora:celld-dev"}},er=()=>({}),or={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)"},tr=e=>{const r=or[e.framework];return e.framework==="none"?d("no meta-framework detected — running standalone."):e.class==="B"?d(`detected ${r} — composition is handled by the framework adapter.`):d(`detected ${r} — composing the Lunora worker into one Cloudflare Worker.`)},nr=(e,r)=>{let t=!1;const o=()=>{r.framework??=R(e.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&r.framework!==void 0&&(t=!0,console.info(tr(r.framework)))},name:"lunora:framework-detect"}},ir=(e,r)=>({config(t,o){if(o.command!=="serve")return;const{services:n}=j(r),a=Array.isArray(e.auxiliaryWorkers)?e.auxiliaryWorkers:[],s=new Set(a.map(i=>i.configPath===void 0?"":V(r,i.configPath))),l=[...new Set(n.map(i=>i.wranglerPath))].filter(i=>!s.has(i)).map(i=>({configPath:i}));l.length>0&&(e.auxiliaryWorkers=[...a,...l])},enforce:"pre",name:"lunora:service-workers"}),ar=e=>{if(e===!1)return!1;const r=e===!0||e===void 0?{}:e;return{...r,forwardedConsoleMethods:r.forwardedConsoleMethods??["error","warn"],solutionFinders:[...H,...r.solutionFinders??[]]}},sr=(e,r)=>{const t=x(e,r);if(!E(t)){const o=A();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 t},lr=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(),a=sr(n,r.target);return{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess??!1,apiSpec:r.apiSpec??"openapi",cloudflare:o,studio:r.studio??!0,generatedDir:`${t}/_generated`,overlay:ar(r.overlay),projectRoot:n,schemaDir:t,shard:r.shard??{},target:a,validateWrangler:r.validateWrangler??!0}},Or=e=>{const r=lr(e),t=er(),o=[nr(r,t),N(r,t),U(r),J(r),b(r),F(),L(r),q(r),I()];r.studio&&o.push(M(r)),r.validateWrangler&&o.push(G(r)),r.overlay!==!1&&o.push(_(r.overlay)),o.push(C(r));const n=r.cloudflare===!1?void 0:{...r.cloudflare};if(o.push(B(n,{projectRoot:r.projectRoot})),n!==void 0){o.push(ir(n,r.projectRoot));const a=y(r.target),s=Q(r.projectRoot,r.target),l=()=>a&&s().runs;o.push(...Y(K(m(n)),l)),a&&o.push(rr(r.projectRoot,l),{apply:(i,u)=>u.command==="serve"&&u.isPreview!==!0&&!l(),configureServer(i){i.config.logger.warn(`[lunora] target "${r.target}": vite dev serves the worker in workerd, not on ${r.target} — ${s().reason??"it cannot run this project"}. \`vite build\` then \`lunora deploy\` ships it to ${r.target}.`)},name:"lunora:target-runtime-notice"})}return o},Tr=p(import.meta.url)("../package.json").version;export{Fr as CLASS_A_WIRING,br as GENERATED_CLASS_MODULES,oe as LUNORA_API_UPDATED_EVENT,Ir as LUNORA_WORKER_VIRTUAL_ID,ne as STUDIO_PATH,Tr as VERSION,Yr as WORKER_STARTUP_HINT,Zr as augmentWorkerStartupError,Qr as buildStudioUrl,Br as buildWorkerEntrySource,Hr as checkLunoraProxy,b as codegenPlugin,C as containerLogsPlugin,Cr as detectFramework,L as devStatePlugin,U as devVariablesPlugin,N as frameworkComposePlugin,Vr as isAutoComposable,re as isWorkerEntryEvalError,F as logStreamPlugin,Or as lunora,Jr as lunoraSolutionFinder,H as lunoraSolutionFinders,Kr as planViteRemoteBindings,I as proxyCheckPlugin,Ur as reconcileWranglerCrons,B as remoteBindingsPlugin,ar as resolveOverlayOption,M as studioPlugin,Gr as withRemoteBindings,K as withWorkerStartupHint,G as wranglerValidatorPlugin};
@@ -0,0 +1,24 @@
1
+ import{existsSync as $}from"node:fs";import{resolve as E,join as k}from"node:path";import{loadProjectConfig as C,findProjectConfigFile as L}from"@lunora/codegen";import{GENERATED_CLASS_MODULES as _}from"@lunora/config";import{LunoraError as y}from"@lunora/errors";const f="virtual:lunora/worker",I="\0",p=`${I}${f}`,M=`// @lunora/vite — the composed worker entry is worker-only and unavailable in the client environment.
2
+ export default {};
3
+ `,D=/\/$/,m={"react-router":{handler:'{ fetch: (request) => createRequestHandler(() => import("virtual:react-router/server-build"), import.meta.env.MODE)(request) }',imports:'import { createRequestHandler } from "react-router";'},"solid-start":{handler:"ssrModule.default",imports:'import * as ssrModule from "@solidjs/start/server-handler";'},"tanstack-start":{handler:"ssrModule.default",imports:'import * as ssrModule from "@tanstack/react-start/server-entry";'},"tanstack-start-solid":{handler:"ssrModule.default",imports:'import * as ssrModule from "@tanstack/solid-start/server-entry";'},vinext:{handler:"ssrModule.default",imports:'import * as ssrModule from "vinext/server/fetch-handler";'}},u=r=>{const e=r.framework;return e?.class==="A"&&m[e.framework]!==void 0},O=(r,e,o={})=>{const{allowUnauthenticatedShardAccess:a=!1,appConfigModule:n,classModules:s=[],shard:l={}}=o,i=m[r];if(i===void 0)throw new y("INTERNAL",`[lunora] no class-A worker wiring for framework "${r}"`);const c=e.replaceAll("\\","/"),h=s.map(t=>`
4
+ export * from "${c}/${t}";
5
+ `).join(""),v=s.includes("scheduler")?`
6
+ .scheduler({ namespace: (env) => env.SCHEDULER })`:"",R=s.includes("shardRegistry")?`
7
+ .shardRegistry((env) => env.SHARD_REGISTRY)`:"",w=n===void 0?"":`
8
+ import lunoraConfig from "${n}";`,[A,S]=n===void 0?["",""]:["lunoraConfig.app(",")"],g=Object.entries(l).filter(([,t])=>t!==void 0).toSorted(([t],[d])=>t.localeCompare(d)).map(([t,d])=>`
9
+ .${t}(${JSON.stringify(d)})`).join("");return`// Generated by @lunora/vite — class-A worker composition (PLAN4 M2).
10
+ // Do not edit: emitted from the detected framework (${r}). Point your
11
+ // wrangler \`main\` here (or re-export it) instead of hand-wiring createWorker.
12
+ ${i.imports}
13
+ import { defineApp } from "${c}/app";${w}
14
+
15
+ const app = ${A}defineApp()
16
+ .shard((env) => env.SHARD)${v}${R}${S}
17
+ .httpRouter(${i.handler})${g}${a?`
18
+ .extend(() => ({ allowUnauthenticatedShardAccess: true }))`:""}
19
+ .build();
20
+
21
+ export const ShardDO = app.ShardDO;
22
+ ${h}
23
+ export default app;
24
+ `},U=async r=>{const{config:e,error:o}=await C(r);return o!==void 0?{error:o}:typeof e?.app!="function"?{}:{specifier:L(r)?.replaceAll("\\","/")}},H=(r,e)=>{const o=E(r.projectRoot,r.generatedDir.replace(D,""));return{async load(a){if(a===p&&u(e)&&e.framework!==void 0){if(this.environment.name==="client")return M;const n=_.filter(i=>$(k(o,`${i}.ts`))),{error:s,specifier:l}=await U(r.projectRoot);return s!==void 0&&this.warn(`[lunora] lunora.config could not be loaded, so its \`app\` hook was not composed: ${s}`),O(e.framework.framework,o,{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess,appConfigModule:l,classModules:n,shard:r.shard})}},name:"lunora:framework-compose",resolveId(a){if(a===f&&u(e))return p}}};export{m as CLASS_A_WIRING,f as LUNORA_WORKER_VIRTUAL_ID,p as RESOLVED_LUNORA_WORKER_ID,O as buildWorkerEntrySource,H as frameworkComposePlugin,u as isAutoComposable};
@@ -0,0 +1 @@
1
+ const a="lunora:api-updated";export{a as default};
@@ -0,0 +1,5 @@
1
+ const a=[""," ┌─ Lunora ──────────────────────────────────────────────────────────────"," │ Your Worker entry threw while loading, so the dev server couldn't read"," │ its exports. The TypeError above comes from inside the Cloudflare"," │ runtime and hides the file that actually failed. It is almost always:"," │"," │ • A circular import in lunora/. A query/mutation/action module ran at"," │ the top level before `v`/`query`/`mutation` finished initializing,"," │ so they were `undefined` (hence `reading 'string'`/`'id'`/…)."," │ → Import `v`/`query`/`mutation` only from `lunora/_generated/server`,"," │ and don't import one lunora/ function module from another at the"," │ top level."," │"," │ • Stale or missing generated files."," │ → Re-run `lunora codegen`, then restart the dev server."," │"," │ Tip: check the lunora/ files you edited most recently — the throw is at"," │ their module top level."," └───────────────────────────────────────────────────────────────────────"].join(`
2
+ `),u=/runner-worker[/\\]index\.js/u,l=/getWorkerEntryExportTypes/u,c=e=>{if(!(e instanceof Error))return!1;const t=`${e.stack??""}
3
+ ${e.message}`;return u.test(t)||l.test(t)},i=Symbol.for("lunora.workerStartupHintApplied"),d=e=>{if(!c(e))return e;const t=e;return t[i]||Object.isFrozen(t)||Object.isSealed(t)||(t[i]=!0,t.message=`${t.message}
4
+ ${a}`,typeof t.stack=="string"&&(t.stack=`${t.stack}
5
+ ${a}`)),e},s=e=>async(...t)=>{try{return await e(...t)}catch(r){throw d(r)}},f=e=>typeof e=="function"?s(e):e!==null&&typeof e=="object"&&"handler"in e&&typeof e.handler=="function"?{...e,handler:s(e.handler)}:e,m=["configureServer","buildStart"],h=e=>e.map(t=>{let r=t;for(const n of m){const o=t[n];o!==void 0&&(r={...r,[n]:f(o)})}return r});export{a as WORKER_STARTUP_HINT,d as augmentWorkerStartupError,c as isWorkerEntryEvalError,h as withWorkerStartupHint};
@@ -0,0 +1 @@
1
+ import{STUDIO_PATH as d,studioMountPath as a,isNonLoopbackHost as c,createStudioMiddleware as n}from"@lunora/config/studio-host";import{STUDIO_PATH as u}from"@lunora/config/studio-host";const l=/\/$/,i=e=>{if(e.resolvedLocal!==void 0&&e.resolvedLocal!=="")return`${e.resolvedLocal.replace(l,"")}${d}`;const o=a(e.base);if(e.address===void 0||typeof e.address=="string")return`http://localhost:5173${o}`;const s=e.address.address==="::"||e.address.address==="0.0.0.0"?"localhost":e.address.address;return`http://${s.includes(":")?`[${s}]`:s}:${String(e.address.port)}${o}`},f=e=>({apply:"serve",configureServer(o){const s=c(o.config.server?.host);return o.middlewares.use(n({apiSpec:e.apiSpec,base:o.config.base,isNonLoopbackBind:s,logger:o.config.logger,projectRoot:e.projectRoot,schemaDirectory:e.schemaDir})),()=>{const t=()=>{const r=i({address:o.httpServer?.address()??void 0,base:o.config.base,resolvedLocal:o.resolvedUrls?.local[0]});o.config.logger.info(` \x1B[32m➜\x1B[39m \x1B[1mLunora\x1B[22m: \x1B[36m${r}\x1B[39m`)};if(typeof o.printUrls=="function"){const r=o.printUrls.bind(o);o.printUrls=()=>{r(),t()}}else o.httpServer?.listening===!0?t():o.httpServer?.once("listening",t)}},name:"lunora:studio"});export{u as STUDIO_PATH,i as buildStudioUrl,f as studioPlugin};
@@ -0,0 +1 @@
1
+ import{lunoraLine as a}from"@lunora/config";const c=["/_lunora"],u="/_lunora/ws",h=e=>{if(e.startsWith("^"))try{return new RegExp(e,"u").test(u)}catch{return!1}return c.some(r=>e.startsWith(r)||r.startsWith(e))},i=(e,r)=>{if(!e)return[];const t=[];for(const[s,o]of Object.entries(e)){if(!h(s))continue;if(typeof o=="string"){t.push(`${r}.proxy["${s}"] uses the string shorthand, which does not proxy WebSocket upgrades. Live queries and shapes will never connect (the app hangs on its loading state) while HTTP RPC appears to work. Use the object form: { target: "${o}", ws: true }.`);continue}if(typeof o!="object"||o===null)continue;const n=o;n.ws!==!0&&t.push(`${r}.proxy["${s}"] is missing \`ws: true\`, so WebSocket upgrades are not proxied. Live queries and shapes will never connect (the app hangs on its loading state) while HTTP RPC appears to work.`),n.changeOrigin===!0&&t.push(`${r}.proxy["${s}"] sets \`changeOrigin: true\`, so the worker sees a different origin than the browser sends. Loopback-to-loopback is trusted by default; for any other dev host add the dev-server origin to the worker's \`security.csrf.trustedOrigins\` or the cookie-bearing WebSocket upgrade is rejected with FORBIDDEN_ORIGIN.`)}return t},g=()=>({apply:"serve",configResolved(e){const r=[...i(e.server.proxy,"server"),...i(e.preview.proxy,"preview")];for(const t of r)e.logger.warn(a(t))},name:"lunora:proxy-check"});export{i as checkLunoraProxy,g as proxyCheckPlugin};
@@ -0,0 +1,3 @@
1
+ import{readFileSync as J,existsSync as H}from"node:fs";import{resolve as p,sep as b,basename as z,join as K}from"node:path";import{findProjectConfigFile as X,PROJECT_CONFIG_FILENAMES as q,findTsconfig as Q,runCodegen as Y,fingerprintSchemaSources as A,createCodegenProject as Z,refreshCodegenProject as ee,CodegenDiagnosticError as ne}from"@lunora/codegen";import{LUNORA_TAG as w,isCodegenDisabled as te,CODEGEN_ENV as x,runPostCodegenHook as W,reportCodegenFindings as re,blockingFindingsMessage as oe}from"@lunora/config";import{findWranglerFile as ie,readWranglerJsonc as ce,WRANGLER_FILES as ae,reconcileBindingsSafely as se,collectWranglerSecretVariables as le,reconcileWranglerExtras as de}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as fe}from"vite";import{createHash as ge}from"node:crypto";import ue from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as he,r as me}from"./server-close-DWiO4Vxb.mjs";const pe=(e,n)=>{try{const{parsed:o,text:t}=ce(e);return o===void 0?`raw:${t}`:JSON.stringify(n?n(o):o)}catch{return"unreadable"}},we=e=>{const n={...e},{triggers:o}=n;if(o!==null&&typeof o=="object"){const t={...o};delete t.crons,Object.keys(t).length>0?n.triggers=t:delete n.triggers}return n},O=e=>{const n=ie(e),o=n===void 0?"absent":pe(n,we),t=X(e);let l="absent";try{t!==void 0&&(l=ge("sha256").update(J(t)).digest("hex"))}catch{}return`${o}\0${l}`},ye=100,I=300,G=2,ve=e=>{let n,o,t=0;const l=()=>{n&&(clearTimeout(n),n=void 0)},a=(u,f)=>{o&&clearTimeout(o),o=setTimeout(()=>{if(o=void 0,e.fingerprint()!==u){if(t+=1,t>G){e.logger.warn(`${w} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(G)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${w} schema changed while \`postcodegen\` was running — regenerating`),f()}},I)},d=u=>{e.regenerate(u,f=>{a(f,()=>{d(u)})})};return{cancelPending:l,dispose:()=>{l(),o&&(clearTimeout(o),o=void 0)},onSave:u=>{l(),t=0,n=setTimeout(()=>{n=void 0,d(u)},ye)}}},L=/[/\\]tsconfig\..+\.json$/u,Se=e=>{const n=e.map(t=>` • ${t.kind} "${t.exportName}" — class ${t.className} is not exported by your worker entry.`),o=[...new Set(e.map(t=>t.module))].map(t=>` export * from "./lunora/_generated/${t}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...n,"","Add to your worker entry:",...o].join(`
2
+ `)},Ee=(e,n,o)=>{if(n.warn(`${w} schema.ts not found at ${e} — codegen skipped`),o!==void 0){const t=`schema.ts not found at ${e} — generated output is now stale`;o.onError(new Error(t),t)}},M=(e,n,o,t)=>{const l=K(e.projectRoot,e.schemaDir,"schema.ts");if(!H(l))return Ee(l,n,o),{};try{const a=Y({apiSpec:e.apiSpec,lunoraDirectory:e.schemaDir,project:t,projectRoot:e.projectRoot,target:e.target,wranglerVariables:le(e.projectRoot)});return de(e.projectRoot,a.cronTriggers,n),re(a,n),{blockingMessage:oe(a),outputDirectory:p(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return n.error(`${w} codegen failed: ${d}`),o?.onError(a,d),{failure:`${w} codegen failed: ${d}`}}},$e=(e,n,o)=>{let t;for(const[l,a]of Object.entries(e.environments)){if(l==="client"){t=a;continue}fe(a)||a.hot.send({path:"*",triggeredBy:n,type:"full-reload"})}if(t===void 0){e.hot.send({type:"full-reload"});return}if(o){t.hot.send({type:"full-reload"});return}t.hot.send({event:ue,type:"custom"})},R={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},Oe=e=>{const n=p(e.projectRoot,e.schemaDir),o=te(process.env[x]);let t=p(e.projectRoot,e.generatedDir),l=0,a=!1,d;const u=new Map;let f,C=!1,j=!1,y,D;return{config(i,h){y=h.command},configResolved(){y!=="build"&&o||(D=M(e,R))},async buildStart(){const i=y!=="build"&&o,{blockingMessage:h,failure:v,outputDirectory:k}=D??(i?{}:M(e,R));if(D=void 0,y==="build"&&v!==void 0&&this.error(v),k!==void 0){t=k,a=!0;let g;try{g=await W({cwd:e.projectRoot,logger:R})}finally{a=!1}g.ran&&(l=Date.now()),y==="build"&&g.error!==void 0&&this.error(g.error)}y==="build"&&h!==void 0&&this.error(h),await se(e,R,g=>{d?.hot.send({err:{loc:void 0,message:Se(g),stack:""},type:"error"})}),d!==void 0&&(f=O(e.projectRoot),C=!0)},configureServer(i){d=i,i.watcher.add(n),f=O(e.projectRoot),C=!1;const h={error:r=>{i.config.logger.error(r)},info:r=>{i.config.logger.info(r)},warn:r=>{i.config.logger.warn(r)}};let v=!1;const k={onError(r,c){v=!0;const s=r instanceof ne?{column:r.column,file:r.file,line:r.line}:void 0,$=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:$,stack:r instanceof Error?r.stack??"":""},type:"error"})}},g=(r,c)=>r===c||r.startsWith(c+b);let T=!1,m;const U=()=>{for(const r of Object.values(i.environments)){const c=r.moduleGraph;for(const s of c.idToModuleMap.values())s.id&&g(s.id,t)&&c.invalidateModule(s)}},V=async(r,c)=>{try{if(T)return;m===void 0?m=Z(n):ee(m,n);const{outputDirectory:s}=M(e,h,k,m);if(s===void 0){m=void 0;return}t=s;const $=A(n);a=!0;let P;try{P=await W({cwd:e.projectRoot,logger:h})}finally{a=!1}if(P.ran&&(l=Date.now(),c($)),P.error!==void 0)return;U(),$e(i,r,v),v=!1}catch(s){h.error(`${w} codegen watch: ${s instanceof Error?s.message:String(s)}`)}},_=ve({fingerprint:()=>A(n),logger:h,regenerate:(r,c)=>{V(r,c)}}),S=r=>{const c=p(r);if(L.test(c)){m=void 0;return}if(c.endsWith(`${b}tsconfig.json`)&&c===Q(n)){m=void 0;return}if(g(c,n)&&!g(c,t)&&c.endsWith(".ts")&&!(c.includes(`${b}__tests__${b}`)||c.endsWith(".test.ts")||c.endsWith(".spec.ts"))){if(a||Date.now()-l<I){_.cancelPending();return}_.onSave(c)}},N=r=>{const c=p(r);(c.endsWith(`${b}tsconfig.json`)||L.test(c))&&(m=void 0)};o?i.config.logger.info(`${w} codegen watch disabled (${x}) — _generated/ is written only by an explicit \`lunora codegen\``):(i.watcher.on("add",S),i.watcher.on("change",S),i.watcher.on("unlink",S),i.watcher.on("unlink",N));const F=new Set([...ae.map(r=>p(e.projectRoot,r)),...q.map(r=>p(e.projectRoot,r))]);for(const r of F)i.watcher.add(r);const E=r=>{if(!F.has(p(r))||j)return;const c=O(e.projectRoot);if(!C){f=c;return}if(f===void 0){f=c;return}c!==f&&(f=c,j=!0,i.config.logger.info(`${w} ${z(p(r))} changed — restarting dev server`),Promise.resolve(i.restart()).finally(()=>{j=!1}).catch(s=>{const $=s instanceof Error?s.message:String(s);i.config.logger.error(`${w} dev server restart failed: ${$} — keeping the running server; re-save your config to retry.`),i.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${$}`,stack:""},type:"error"})}))};i.watcher.on("add",E),i.watcher.on("change",E),i.watcher.on("unlink",E);const B=()=>{T||(T=!0,m=void 0,_.dispose(),i.watcher.off("add",S),i.watcher.off("change",S),i.watcher.off("unlink",S),i.watcher.off("unlink",N),i.watcher.off("add",E),i.watcher.off("change",E),i.watcher.off("unlink",E))};return()=>{me(i,u,B)}},buildEnd(){he(u,this.environment)},name:"lunora:codegen"}};export{Oe as default};
@@ -0,0 +1 @@
1
+ import{discoverContainerInfo as l,streamContainerLogs as u,lunoraLine as i}from"@lunora/config";const v=r=>{let n;const a=()=>{n?.close(),n=void 0};return{apply:"serve",buildEnd(){a()},configureServer(t){if(n||process.env.LUNORA_CONTAINER_LOGS==="0")return;const c=l(r.projectRoot,r.schemaDir).containers.map(e=>({className:e.className,exportName:e.exportName}));if(c.length===0)return;const{logger:o}=t.config;n=u({containers:c,onLine:e=>{const s=i(`container:${e.name} ${e.text}`);e.level==="error"?o.warn(s):o.info(s)},onUnavailable:e=>{o.warn(i(`container: Docker engine unreachable — container logs unavailable (${e})`))}}),t.httpServer?.once("close",a)},name:"lunora:container-logs"}};export{v as default};
@@ -0,0 +1 @@
1
+ import{DEV_HANDOFF_ENV as c,claimDevServerState as p,DEV_LOG_FILE_ENV as u,DEV_DAEMON_ENV as v,lunoraLine as f,readDevServerState as g,clearDevServerState as S}from"@lunora/config";import{a as m,r as D}from"./server-close-DWiO4Vxb.mjs";const E=/\/$/,U=o=>{const r=o.resolvedUrls?.local[0];if(r!==void 0)return r.replace(E,"");const n=o.httpServer?.address();if(n!==null&&typeof n=="object")return`http://localhost:${String(n.port)}`};let s;const O=o=>{let r=!1;const n=new Map;return{apply:"serve",configureServer(e){const l=o.projectRoot,a=()=>{if(r)return;const t=U(e);if(t===void 0)return;const d=Number(process.env[c]),i=p(l,{background:process.env[v]==="1",logFile:process.env[u],mode:"vite",pid:process.pid,readyAt:new Date().toISOString(),startedAt:new Date().toISOString(),...s===void 0?{}:{tunnelUrl:s},url:t},Number.isInteger(d)&&d>0?{supersedePid:d}:void 0);if(!i.ok){i.existing!==void 0&&e.config.logger.warn(f(`another dev server is already recorded at ${i.existing.url} (pid ${String(i.existing.pid)}) — leaving .lunora/dev.json untouched`));return}r=!0,s=void 0};return D(e,n,()=>{if(r){const t=g(l);s=t?.pid===process.pid?t.tunnelUrl:void 0,S(l,process.pid),r=!1}}),()=>{if(typeof e.printUrls=="function"){const t=e.printUrls.bind(e);e.printUrls=()=>{t(),a()}}e.httpServer?.once("listening",()=>{setTimeout(a,0)})}},buildEnd(){m(n,this.environment)},name:"lunora:dev-state"}};export{O as default};
@@ -0,0 +1 @@
1
+ import{ensureDevVariables as a,createConfirm as i,fillDevSecrets as t,ensureDevWorkerEnv as c,lunoraLine as s}from"@lunora/config";const f=r=>{let n=!1;return{apply:"serve",config(e,o){n=o.isPreview===!0},async configResolved(){if(n)return;const e=o=>{console.info(s(o))};await a({confirm:i("[lunora] "),cwd:r.projectRoot,info:e}),t({cwd:r.projectRoot,info:e}),c(r.projectRoot,e)},enforce:"pre",name:"lunora:dev-vars"}};export{f as default};
@@ -0,0 +1,3 @@
1
+ import{detectAiAgent as u,LUNORA_EVENT_SOURCE as a,formatLunoraEvent as f}from"@lunora/config";import{r as l,a as d}from"./server-close-DWiO4Vxb.mjs";const p=`"source":"${a}"`,i={error:"\x1B[31m",info:"\x1B[36m",reset:"\x1B[0m",warn:"\x1B[33m"},w=(r,t,e)=>e?`${i[t]}[lunora]${i.reset} ${r}`:`[lunora] ${r}`,v=r=>typeof r=="string"?r:Buffer.isBuffer(r)?r.toString("utf8"):void 0,m=(r,t)=>r.split(`
2
+ `).map(e=>{const n=f(e);return n?w(n.text,n.level,t):e}).join(`
3
+ `),S=(r,t)=>(...e)=>{try{const n=v(e[0]);if(n?.includes(p))return r(m(n,t),...e.slice(1))}catch{}return r(...e)},c=r=>{const t=r.write.bind(r),e=S(t,r.isTTY===!0);return r.write=e,()=>{r.write===e&&(r.write=t)}},g=()=>{const r=process.env.LUNORA_LOG_JSON;return r==="1"||r==="true"?!0:r==="0"||r==="false"?!1:u()!==void 0};let o;const A=()=>{const r=new Map;return{apply:"serve",buildEnd(){d(r,this.environment)},configureServer(t){if(g())return;o?.();const e=c(process.stdout),n=c(process.stderr),s=()=>{e(),n(),o===s&&(o=void 0)};o=s,l(t,r,s)},name:"lunora:log-stream"}};export{A as default};
@@ -0,0 +1 @@
1
+ import{findLunoraSolution as r}from"@lunora/codegen";const s={handle:e=>{const n=typeof e.message=="string"?e.message:"",o=r(n);return Promise.resolve(o?{body:o.body,header:o.header}:void 0)},name:"lunora",priority:100},i=[s];export{s as lunoraSolutionFinder,i as lunoraSolutionFinders};
@@ -0,0 +1 @@
1
+ import{readProjectRemotePreference as d,lunoraLine as c}from"@lunora/config";import{resolveRemoteEnabled as s,materializeRemoteWranglerConfig as g}from"@lunora/config/cloudflare";const l=()=>{},u=e=>{const t=e.readPreference??d;if(!s({configPreference:t(e.projectRoot),envValue:e.remoteEnv??process.env.LUNORA_REMOTE}))return{cleanup:l,enabled:!1};const o=(e.materialize??g)({enabled:!0,projectRoot:e.projectRoot});return{cleanup:o.cleanup,configPath:o.configPath,enabled:!0,reason:o.reason}},m=(e,t)=>!t.enabled||t.configPath===void 0||typeof e.configPath=="string"?e:{...e,configPath:t.configPath},p=(e,t)=>{let n={cleanup:l,enabled:!1},i;const o=()=>{n.cleanup()};return{buildEnd:o,closeBundle:o,config(P,f){if(f.command!=="serve")return;if(n.cleanup(),n=u(t),e===void 0){n.enabled&&n.configPath!==void 0&&console.info(c(`remote bindings are materialized at ${n.configPath} — this project adds @cloudflare/vite-plugin itself (\`cloudflare: false\`), so pass that path as its \`configPath\` to use them.`));return}const a=e;i!==void 0&&a.configPath===i&&delete a.configPath;const r=m(e,n);r.configPath!==void 0&&a.configPath===void 0?(a.configPath=r.configPath,i=r.configPath):n.enabled&&n.configPath===void 0&&n.reason!==void 0&&console.info(c(`remote bindings requested but not applied: ${n.reason}`))},enforce:"pre",name:"lunora:remote-bindings"}};export{u as planViteRemoteBindings,p as remoteBindingsPlugin,m as withRemoteBindings};
@@ -0,0 +1 @@
1
+ const o=(e,s,t)=>{e.httpServer?e.httpServer.once("close",t):s.set(e.environments.client,t)},r=(e,s)=>{const t=e.get(s);t!==void 0&&(e.delete(s),t())};export{r as a,o as r};
@@ -0,0 +1 @@
1
+ import{spawnSync as a}from"node:child_process";import{lunoraLine as s}from"@lunora/config";import{assertWranglerSatisfiesSchema as i,findWranglerFile as c,readWranglerJsonc as l}from"@lunora/config/cloudflare";const f=r=>r.startsWith("./")||r.startsWith("../")||r.startsWith("/")||r.includes("Dockerfile"),d=()=>{try{return a("docker",["info"],{stdio:"ignore"}).status===0}catch{return!1}},g=(r,n=d)=>{const{parsed:e}=l(r);!(e?.containers??[]).some(t=>typeof t?.image=="string"&&f(t.image))||n()||console.warn(s("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."))},p=r=>{let n=!1;return{config(e,o){n=o.isPreview===!0},configResolved(){if(n)return;i(r,o=>{console.warn(o)},"Update your wrangler.jsonc and restart the dev server.");const e=c(r.projectRoot);e!==void 0&&g(e)},enforce:"pre",name:"lunora:wrangler-validator"}};export{g 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.3",
3
+ "version": "1.0.0-alpha.300",
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",
@@ -25,7 +25,7 @@
25
25
  "directory": "packages/vite"
26
26
  },
27
27
  "files": [
28
- "dist",
28
+ "./dist",
29
29
  "__assets__",
30
30
  "README.md",
31
31
  "LICENSE.md"
@@ -45,16 +45,15 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@cloudflare/vite-plugin": "1.42.0",
49
- "@lunora/codegen": "1.0.0-alpha.3",
50
- "@lunora/config": "1.0.0-alpha.4",
51
- "@visulima/vite-overlay": "2.0.0-alpha.35",
52
- "jsonc-parser": "^3.3.1",
53
- "ts-morph": "^28.0.0"
48
+ "@cloudflare/vite-plugin": "1.62.4",
49
+ "@lunora/codegen": "1.0.0-alpha.259",
50
+ "@lunora/config": "1.0.0-alpha.302",
51
+ "@lunora/errors": "1.0.0-alpha.50",
52
+ "@visulima/vite-overlay": "2.0.20"
54
53
  },
55
54
  "peerDependencies": {
56
- "@lunora/studio": "1.0.0-alpha.3",
57
- "vite": "^8.0.16"
55
+ "@lunora/studio": ">=1.0.0-alpha.50 <2.0.0-0",
56
+ "vite": "^6.1.0 || ^7.0.0 || ^8.0.0"
58
57
  },
59
58
  "peerDependenciesMeta": {
60
59
  "@lunora/studio": {
@@ -1,96 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { resolve, join } from 'node:path';
3
-
4
- const LUNORA_WORKER_VIRTUAL_ID = "virtual:lunora/worker";
5
- const RESOLVED_VIRTUAL_PREFIX = "\0";
6
- const RESOLVED_LUNORA_WORKER_ID = `${RESOLVED_VIRTUAL_PREFIX}${LUNORA_WORKER_VIRTUAL_ID}`;
7
- const TRAILING_SLASH = /\/$/;
8
- const CLASS_A_WIRING = {
9
- "react-router": {
10
- // `@react-router/dev` provides `virtual:react-router/server-build`; the
11
- // runtime helper turns it into a `(request) => Promise<Response>`, which
12
- // is exactly the `httpRouter.fetch` contract. Needs a named import.
13
- handler: '{ fetch: (request) => createRequestHandler(() => import("virtual:react-router/server-build"), import.meta.env.MODE)(request) }',
14
- imports: 'import { createRequestHandler } from "react-router";'
15
- },
16
- "solid-start": {
17
- // SolidStart's `cloudflare-module` preset default-exports a fetch
18
- // handler — structurally an `HttpRouterLike` already.
19
- handler: "ssrModule.default",
20
- imports: 'import * as ssrModule from "@solidjs/start/server-handler";'
21
- },
22
- "tanstack-start": {
23
- // TanStack Start's server entry default-exports a `{ fetch }` handler.
24
- handler: "ssrModule.default",
25
- imports: 'import * as ssrModule from "@tanstack/react-start/server-entry";'
26
- },
27
- "tanstack-start-solid": {
28
- // TanStack Start (Solid)'s server entry default-exports a `{ fetch }`
29
- // handler — same shape as the React variant, different package.
30
- handler: "ssrModule.default",
31
- imports: 'import * as ssrModule from "@tanstack/solid-start/server-entry";'
32
- }
33
- };
34
- const isAutoComposable = (context) => {
35
- const detected = context.framework;
36
- return detected?.class === "A" && CLASS_A_WIRING[detected.framework] !== void 0;
37
- };
38
- const isWorkerVirtualActive = (context) => isAutoComposable(context);
39
- const buildWorkerEntrySource = (framework, generatedImportBase, hasContainers = false) => {
40
- const wiring = CLASS_A_WIRING[framework];
41
- if (wiring === void 0) {
42
- throw new Error(`[lunora] no class-A worker wiring for framework "${framework}"`);
43
- }
44
- const containersReexport = hasContainers ? `
45
- export * from "${generatedImportBase}/containers";
46
- ` : "";
47
- return `// Generated by @lunora/vite — class-A worker composition (PLAN4 M2).
48
- // Do not edit: emitted from the detected framework (${framework}). Point your
49
- // wrangler \`main\` here (or re-export it) instead of hand-wiring createWorker.
50
- import { composeWorker } from "@lunora/runtime";
51
- ${wiring.imports}
52
- import { LUNORA_FUNCTIONS } from "${generatedImportBase}/functions";
53
- import { openApiSpec } from "${generatedImportBase}/openapi";
54
- import { createShardDO } from "${generatedImportBase}/shard";
55
-
56
- export const ShardDO = createShardDO();
57
- ${containersReexport}
58
-
59
- let worker;
60
-
61
- export default {
62
- async fetch(request, env, context) {
63
- worker ??= composeWorker({
64
- functions: LUNORA_FUNCTIONS,
65
- httpRouter: ${wiring.handler},
66
- openApiSpec,
67
- routes: {},
68
- shardDO: env.SHARD,
69
- });
70
-
71
- return worker.fetch(request, env, context);
72
- },
73
- };
74
- `;
75
- };
76
- const frameworkComposePlugin = (options, context) => {
77
- const generatedImportBase = resolve(options.projectRoot, options.generatedDir.replace(TRAILING_SLASH, ""));
78
- return {
79
- load(id) {
80
- if (id === RESOLVED_LUNORA_WORKER_ID && isWorkerVirtualActive(context) && context.framework !== void 0) {
81
- const hasContainers = existsSync(join(generatedImportBase, "containers.ts"));
82
- return buildWorkerEntrySource(context.framework.framework, generatedImportBase, hasContainers);
83
- }
84
- return void 0;
85
- },
86
- name: "lunora:framework-compose",
87
- resolveId(id) {
88
- if (id === LUNORA_WORKER_VIRTUAL_ID && isWorkerVirtualActive(context)) {
89
- return RESOLVED_LUNORA_WORKER_ID;
90
- }
91
- return void 0;
92
- }
93
- };
94
- };
95
-
96
- export { CLASS_A_WIRING, LUNORA_WORKER_VIRTUAL_ID, RESOLVED_LUNORA_WORKER_ID, buildWorkerEntrySource, frameworkComposePlugin, isAutoComposable };
@@ -1,36 +0,0 @@
1
- const DEV_WORKER_ENV_VAR = "WORKER_ENV";
2
- const DEV_WORKER_ENV_VALUE = "development";
3
- const withDevWorkerEnv = (options, isServe) => {
4
- const userConfig = options.config;
5
- return {
6
- ...options,
7
- config: (workerConfig) => {
8
- if (typeof userConfig === "function") {
9
- const partial = userConfig(workerConfig);
10
- if (partial) {
11
- Object.assign(workerConfig, partial);
12
- }
13
- } else if (userConfig) {
14
- Object.assign(workerConfig, userConfig);
15
- }
16
- if (isServe()) {
17
- workerConfig.vars = { [DEV_WORKER_ENV_VAR]: DEV_WORKER_ENV_VALUE, ...workerConfig.vars };
18
- }
19
- }
20
- };
21
- };
22
- const createCommandProbe = () => {
23
- let command;
24
- return {
25
- isServe: () => command === "serve",
26
- plugin: {
27
- config(_userConfig, env) {
28
- command = env.command;
29
- },
30
- enforce: "pre",
31
- name: "lunora:command-probe"
32
- }
33
- };
34
- };
35
-
36
- export { DEV_WORKER_ENV_VALUE, DEV_WORKER_ENV_VAR, createCommandProbe, withDevWorkerEnv };