@lunora/vite 1.0.0-alpha.32 → 1.0.0-alpha.321
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/LICENSE.md +6 -0
- package/README.md +4 -2
- package/dist/index.d.mts +445 -320
- package/dist/index.d.ts +445 -320
- package/dist/index.mjs +3 -163
- package/dist/packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs +26 -0
- package/dist/packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs +1 -0
- package/dist/packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs +5 -0
- package/dist/packem_shared/buildStudioUrl-DMMWpguZ.mjs +1 -0
- package/dist/packem_shared/checkLunoraProxy-BNPgNWtV.mjs +1 -0
- package/dist/packem_shared/codegenPlugin-BIAGgCkK.mjs +3 -0
- package/dist/packem_shared/containerLogsPlugin-67PZ8zmb.mjs +1 -0
- package/dist/packem_shared/devStatePlugin-CF4GDvBn.mjs +1 -0
- package/dist/packem_shared/devVariablesPlugin-DbD6cSF0.mjs +1 -0
- package/dist/packem_shared/logStreamPlugin-EMXiy6pI.mjs +3 -0
- package/dist/packem_shared/lunoraSolutionFinder--J0x2mAM.mjs +1 -0
- package/dist/packem_shared/planViteRemoteBindings-ByOliZuE.mjs +1 -0
- package/dist/packem_shared/server-close-DWiO4Vxb.mjs +1 -0
- package/dist/packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs +1 -0
- package/package.json +8 -9
- package/dist/packem_shared/CLASS_A_WIRING-DpX_WcOK.mjs +0 -112
- package/dist/packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs +0 -36
- package/dist/packem_shared/STUDIO_PATH-yREc3Bbm.mjs +0 -221
- package/dist/packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs +0 -81
- package/dist/packem_shared/codegenPlugin-B_ayaObq.mjs +0 -207
- package/dist/packem_shared/containerLogsPlugin-DMssU3wb.mjs +0 -50
- package/dist/packem_shared/devVariablesPlugin-CDNSnvOP.mjs +0 -19
- package/dist/packem_shared/log-BjO9EWah.mjs +0 -8
- package/dist/packem_shared/logStreamPlugin-CqvZ17kd.mjs +0 -61
- package/dist/packem_shared/lunoraSolutionFinder-BKEAiUJP.mjs +0 -17
- package/dist/packem_shared/planViteRemoteBindings-QN5ncUS1.mjs +0 -50
- package/dist/packem_shared/reconcileWranglerCrons-PxGwfCp_.mjs +0 -29
- package/dist/packem_shared/wranglerValidatorPlugin-CEoJEghS.mjs +0 -66
package/dist/index.mjs
CHANGED
|
@@ -1,163 +1,3 @@
|
|
|
1
|
-
import { cloudflare } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { detectFramework } from '@lunora/config';
|
|
5
|
-
import { l as lunoraLine } from './packem_shared/log-BjO9EWah.mjs';
|
|
6
|
-
import codegenPlugin from './packem_shared/codegenPlugin-B_ayaObq.mjs';
|
|
7
|
-
import containerLogsPlugin from './packem_shared/containerLogsPlugin-DMssU3wb.mjs';
|
|
8
|
-
import devVariablesPlugin from './packem_shared/devVariablesPlugin-CDNSnvOP.mjs';
|
|
9
|
-
import { createCommandProbe, withDevWorkerEnv } from './packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs';
|
|
10
|
-
export { DEV_WORKER_ENV_VALUE, DEV_WORKER_ENV_VAR } from './packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs';
|
|
11
|
-
import { frameworkComposePlugin } from './packem_shared/CLASS_A_WIRING-DpX_WcOK.mjs';
|
|
12
|
-
export { CLASS_A_WIRING, LUNORA_WORKER_VIRTUAL_ID, buildWorkerEntrySource, isAutoComposable } from './packem_shared/CLASS_A_WIRING-DpX_WcOK.mjs';
|
|
13
|
-
import logStreamPlugin from './packem_shared/logStreamPlugin-CqvZ17kd.mjs';
|
|
14
|
-
import { planViteRemoteBindings, remoteBindingsCleanupPlugin, withRemoteBindings } from './packem_shared/planViteRemoteBindings-QN5ncUS1.mjs';
|
|
15
|
-
import { lunoraSolutionFinders } from './packem_shared/lunoraSolutionFinder-BKEAiUJP.mjs';
|
|
16
|
-
export { lunoraSolutionFinder } from './packem_shared/lunoraSolutionFinder-BKEAiUJP.mjs';
|
|
17
|
-
import { studioPlugin } from './packem_shared/STUDIO_PATH-yREc3Bbm.mjs';
|
|
18
|
-
export { STUDIO_PATH, buildStudioUrl } from './packem_shared/STUDIO_PATH-yREc3Bbm.mjs';
|
|
19
|
-
import { withWorkerStartupHint } from './packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs';
|
|
20
|
-
export { WORKER_STARTUP_HINT, augmentWorkerStartupError, isWorkerEntryEvalError } from './packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs';
|
|
21
|
-
import { wranglerValidatorPlugin } from './packem_shared/wranglerValidatorPlugin-CEoJEghS.mjs';
|
|
22
|
-
export { reconcileWranglerCrons } from './packem_shared/reconcileWranglerCrons-PxGwfCp_.mjs';
|
|
23
|
-
|
|
24
|
-
const agentRulesHintPlugin = (options) => {
|
|
25
|
-
return {
|
|
26
|
-
apply: "serve",
|
|
27
|
-
configureServer(server) {
|
|
28
|
-
return () => {
|
|
29
|
-
if (detectAgentRules(options.projectRoot).installed || !claimAgentRulesHint()) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
server.config.logger.warn(`
|
|
33
|
-
${lunoraLine(AGENT_RULES_HINT)}
|
|
34
|
-
`);
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
name: "lunora:agent-rules-hint"
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const createPluginContext = () => {
|
|
42
|
-
return {};
|
|
43
|
-
};
|
|
44
|
-
const FRAMEWORK_LABELS = {
|
|
45
|
-
astro: "Astro",
|
|
46
|
-
none: "standalone (SPA / SSR-less)",
|
|
47
|
-
nuxt: "Nuxt",
|
|
48
|
-
"react-router": "React Router",
|
|
49
|
-
"solid-start": "SolidStart",
|
|
50
|
-
sveltekit: "SvelteKit",
|
|
51
|
-
"tanstack-start": "TanStack Start",
|
|
52
|
-
"tanstack-start-solid": "TanStack Start (Solid)"
|
|
53
|
-
};
|
|
54
|
-
const formatFrameworkDetection = (detection) => {
|
|
55
|
-
const label = FRAMEWORK_LABELS[detection.framework];
|
|
56
|
-
if (detection.framework === "none") {
|
|
57
|
-
return lunoraLine("no meta-framework detected — running standalone.");
|
|
58
|
-
}
|
|
59
|
-
if (detection.class === "B") {
|
|
60
|
-
return lunoraLine(`detected ${label} — composition is handled by the framework adapter.`);
|
|
61
|
-
}
|
|
62
|
-
return lunoraLine(`detected ${label} — composing the Lunora worker into one Cloudflare Worker.`);
|
|
63
|
-
};
|
|
64
|
-
const frameworkDetectPlugin = (options, context) => {
|
|
65
|
-
let logged = false;
|
|
66
|
-
const detect = () => {
|
|
67
|
-
context.framework ??= detectFramework(options.projectRoot);
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
config() {
|
|
71
|
-
detect();
|
|
72
|
-
},
|
|
73
|
-
configResolved() {
|
|
74
|
-
detect();
|
|
75
|
-
},
|
|
76
|
-
configureServer() {
|
|
77
|
-
detect();
|
|
78
|
-
if (!logged && context.framework !== void 0) {
|
|
79
|
-
logged = true;
|
|
80
|
-
console.info(formatFrameworkDetection(context.framework));
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
name: "lunora:framework-detect"
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const resolveOverlayOption = (overlay) => {
|
|
88
|
-
if (overlay === false) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
const userOverlay = overlay === true || overlay === void 0 ? {} : overlay;
|
|
92
|
-
return {
|
|
93
|
-
...userOverlay,
|
|
94
|
-
// After the spread + nullish-coalesce so an explicit `undefined` from the
|
|
95
|
-
// user doesn't erase Lunora's default (the spread would otherwise win).
|
|
96
|
-
forwardedConsoleMethods: userOverlay.forwardedConsoleMethods ?? ["error", "warn"],
|
|
97
|
-
solutionFinders: [...lunoraSolutionFinders, ...userOverlay.solutionFinders ?? []]
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
const resolveOptions = (options) => {
|
|
101
|
-
const input = options ?? {};
|
|
102
|
-
const schemaDirectory = input.schemaDir ?? "lunora";
|
|
103
|
-
let cloudflareOption;
|
|
104
|
-
if (input.cloudflare === false) {
|
|
105
|
-
cloudflareOption = false;
|
|
106
|
-
} else if (input.cloudflare === true || input.cloudflare === void 0) {
|
|
107
|
-
cloudflareOption = {};
|
|
108
|
-
} else {
|
|
109
|
-
cloudflareOption = input.cloudflare;
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
apiSpec: input.apiSpec ?? "openapi",
|
|
113
|
-
cloudflare: cloudflareOption,
|
|
114
|
-
studio: input.studio ?? true,
|
|
115
|
-
generatedDir: input.generatedDir ?? `${schemaDirectory}/_generated`,
|
|
116
|
-
overlay: resolveOverlayOption(input.overlay),
|
|
117
|
-
projectRoot: input.projectRoot ?? process.cwd(),
|
|
118
|
-
schemaDir: schemaDirectory,
|
|
119
|
-
validateWrangler: input.validateWrangler ?? true
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
const lunora = (options) => {
|
|
123
|
-
const resolved = resolveOptions(options);
|
|
124
|
-
const context = createPluginContext();
|
|
125
|
-
const { isServe, plugin: commandProbe } = createCommandProbe();
|
|
126
|
-
const plugins = [
|
|
127
|
-
commandProbe,
|
|
128
|
-
frameworkDetectPlugin(resolved, context),
|
|
129
|
-
// Reads the detected framework off `context` and, for a class-A
|
|
130
|
-
// framework (and only when the CF integration is on), resolves the
|
|
131
|
-
// `virtual:lunora/worker` entry to a `composeWorker`-based worker that
|
|
132
|
-
// routes `/_lunora/*` to Lunora and falls through to the framework SSR
|
|
133
|
-
// handler — so the template never hand-wires `createWorker({ httpRouter })`.
|
|
134
|
-
// A strict no-op for class-C and the `cloudflare: false` BYO path.
|
|
135
|
-
frameworkComposePlugin(resolved, context),
|
|
136
|
-
devVariablesPlugin(resolved),
|
|
137
|
-
codegenPlugin(resolved),
|
|
138
|
-
logStreamPlugin(),
|
|
139
|
-
agentRulesHintPlugin(resolved)
|
|
140
|
-
];
|
|
141
|
-
if (resolved.studio) {
|
|
142
|
-
plugins.push(studioPlugin());
|
|
143
|
-
}
|
|
144
|
-
if (resolved.validateWrangler) {
|
|
145
|
-
plugins.push(wranglerValidatorPlugin(resolved));
|
|
146
|
-
}
|
|
147
|
-
if (resolved.overlay !== false) {
|
|
148
|
-
plugins.push(errorOverlayPlugin(resolved.overlay));
|
|
149
|
-
}
|
|
150
|
-
if (resolved.cloudflare !== false) {
|
|
151
|
-
plugins.push(containerLogsPlugin(resolved));
|
|
152
|
-
const remotePlan = planViteRemoteBindings({ projectRoot: resolved.projectRoot });
|
|
153
|
-
if (remotePlan.enabled && remotePlan.configPath !== void 0) {
|
|
154
|
-
plugins.push(remoteBindingsCleanupPlugin(remotePlan.cleanup));
|
|
155
|
-
}
|
|
156
|
-
const cloudflareOptions = withRemoteBindings(withDevWorkerEnv(resolved.cloudflare, isServe), isServe, remotePlan);
|
|
157
|
-
plugins.push(...withWorkerStartupHint(cloudflare(cloudflareOptions)));
|
|
158
|
-
}
|
|
159
|
-
return plugins;
|
|
160
|
-
};
|
|
161
|
-
const VERSION = "0.0.0";
|
|
162
|
-
|
|
163
|
-
export { VERSION, codegenPlugin, containerLogsPlugin, createCommandProbe, devVariablesPlugin, frameworkComposePlugin, logStreamPlugin, lunora, lunoraSolutionFinders, planViteRemoteBindings, remoteBindingsCleanupPlugin, resolveOverlayOption, 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 u,AGENT_RULES_HINT as w,resolveDeployDriver as S,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 Lr,detectFramework as Ur}from"@lunora/config";import _ from"@visulima/vite-overlay";import{reconcileBindingsSafely as O,findWranglerFile as C,readWranglerJsonc as D,warnCloudflareCliConfigOnce as T}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Fr}from"@lunora/config/cloudflare";import{r as W,a as $}from"./packem_shared/server-close-DWiO4Vxb.mjs";import b from"./packem_shared/codegenPlugin-BIAGgCkK.mjs";import L from"./packem_shared/containerLogsPlugin-67PZ8zmb.mjs";import U from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import N from"./packem_shared/devVariablesPlugin-DbD6cSF0.mjs";import{frameworkComposePlugin as F}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import{CLASS_A_WIRING as jr,LUNORA_WORKER_VIRTUAL_ID as Br,buildWorkerEntrySource as Vr,isAutoComposable as Hr}from"./packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs";import I from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as j}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as Kr}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as B}from"./packem_shared/planViteRemoteBindings-ByOliZuE.mjs";import{planViteRemoteBindings as qr,withRemoteBindings as Jr}from"./packem_shared/planViteRemoteBindings-ByOliZuE.mjs";import{resolve as V}from"node:path";import{readServiceBindings as H}from"@lunora/codegen";import{lunoraSolutionFinders as M}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as Qr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as K}from"./packem_shared/buildStudioUrl-DMMWpguZ.mjs";import{buildStudioUrl as Yr}from"./packem_shared/buildStudioUrl-DMMWpguZ.mjs";import{withWorkerStartupHint as G}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as re,augmentWorkerStartupError as ee,isWorkerEntryEvalError as oe}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as q}from"./packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs";import{default as ne}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as ae}from"@lunora/config/studio-host";const J=e=>({apply:"serve",configureServer(r){return()=>{v(e.projectRoot).installed||!h()||r.config.logger.warn(`
|
|
2
|
+
${u(w)}
|
|
3
|
+
`)}},name:"lunora:agent-rules-hint"}),z=e=>({async config(r,t){t.isPreview!==!0&&await O(e,{info:o=>{console.info(o)},warn:o=>{console.warn(o)}})},enforce:"pre",name:"lunora:bindings-provision"}),f="/_lunora",Q=8787,c=new Map,g=e=>e.command==="serve"&&e.isPreview!==!0,X=(e,r)=>{let t;return()=>{if(t===void 0)try{S(r).projectConfig?.(e,"dev"),t={runs:!0}}catch(o){t={reason:o instanceof Error?o.message:String(o),runs:!1}}return t}},Y=e=>{const r=C(e),t=r===void 0?void 0:D(r).parsed?.dev?.port;return typeof t=="number"?t:Q},Z=(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}}),rr=(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}`)},er=(e,r)=>{const t=Y(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,d)=>{rr(a,i,d)},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"}},or=e=>({configResolved(r){T(e.projectRoot,t=>{r.logger.warn(u(t))})},name:"lunora:cf-config-warning"}),tr=()=>({}),nr={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)"},ir=e=>{const r=nr[e.framework];return e.framework==="none"?u("no meta-framework detected — running standalone."):e.class==="B"?u(`detected ${r} — composition is handled by the framework adapter.`):u(`detected ${r} — composing the Lunora worker into one Cloudflare Worker.`)},ar=(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(ir(r.framework)))},name:"lunora:framework-detect"}},sr=(e,r)=>({config(t,o){if(o.command!=="serve")return;const{services:n}=H(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"}),lr=e=>{if(e===!1)return!1;const r=e===!0||e===void 0?{}:e;return{...r,forwardedConsoleMethods:r.forwardedConsoleMethods??["error","warn"],solutionFinders:[...M,...r.solutionFinders??[]]}},cr=(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},ur=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=cr(n,r.target);return{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess??!1,apiSpec:r.apiSpec??"openapi",cloudflare:o,studio:r.studio??!0,generatedDir:`${t}/_generated`,overlay:lr(r.overlay),projectRoot:n,schemaDir:t,shard:r.shard??{},target:a,validateWrangler:r.validateWrangler??!0}},Tr=e=>{const r=ur(e),t=tr(),o=[ar(r,t),F(r,t),N(r),z(r),b(r),I(),U(r),J(r),or(r),j()];r.studio&&o.push(K(r)),r.validateWrangler&&o.push(q(r)),r.overlay!==!1&&o.push(_(r.overlay)),o.push(L(r));const n=r.cloudflare===!1?void 0:{...r.cloudflare};if(o.push(B(n,{projectRoot:r.projectRoot})),n!==void 0){o.push(sr(n,r.projectRoot));const a=y(r.target),s=X(r.projectRoot,r.target),l=()=>a&&s().runs;o.push(...Z(G(m(n)),l)),a&&o.push(er(r.projectRoot,l),{apply:(i,d)=>d.command==="serve"&&d.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},Wr=p(import.meta.url)("../package.json").version;export{jr as CLASS_A_WIRING,Lr as GENERATED_CLASS_MODULES,ne as LUNORA_API_UPDATED_EVENT,Br as LUNORA_WORKER_VIRTUAL_ID,ae as STUDIO_PATH,Wr as VERSION,re as WORKER_STARTUP_HINT,ee as augmentWorkerStartupError,Yr as buildStudioUrl,Vr as buildWorkerEntrySource,Kr as checkLunoraProxy,b as codegenPlugin,L as containerLogsPlugin,Ur as detectFramework,U as devStatePlugin,N as devVariablesPlugin,F as frameworkComposePlugin,Hr as isAutoComposable,oe as isWorkerEntryEvalError,I as logStreamPlugin,Tr as lunora,Qr as lunoraSolutionFinder,M as lunoraSolutionFinders,qr as planViteRemoteBindings,j as proxyCheckPlugin,Fr as reconcileWranglerCrons,B as remoteBindingsPlugin,lr as resolveOverlayOption,K as studioPlugin,Jr as withRemoteBindings,G as withWorkerStartupHint,q as wranglerValidatorPlugin};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{existsSync as w}from"node:fs";import{resolve as _,join as M}from"node:path";import{loadProjectConfig as C,findProjectConfigFile as L}from"@lunora/codegen";import{GENERATED_CLASS_MODULES as b,isMergedProject as k,DURABLE_OBJECT_BINDINGS as m,GENERATED_MODULE_DURABLE_OBJECTS as j,isMergedRoleModule as y,MERGED_DURABLE_OBJECTS_MODULE as I}from"@lunora/config";import{LunoraError as N}from"@lunora/errors";const $="virtual:lunora/worker",x="\0",f=`${x}${$}`,U=`// @lunora/vite — the composed worker entry is worker-only and unavailable in the client environment.
|
|
2
|
+
export default {};
|
|
3
|
+
`,T=/\/$/,R={"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";'}},h=r=>{const o=r.framework;return o?.class==="A"&&R[o.framework]!==void 0},B=(r,o,s)=>{if(!s)return{classExport:"export const ShardDO = app.ShardDO;",imports:"",namespace:e=>`env.${e==="scheduler"?m.SchedulerDO:m.ShardRegistryDO}`,reexported:()=>!0};const a=o.flatMap(e=>{const t=j[e];return t===void 0?[]:[{className:t,module:e}]});return{classExport:`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO${a.map(({className:e,module:t})=>`, ${t}: ${e}`).join("")} });`,imports:[`
|
|
4
|
+
import { mergeDurableObjects, roleNamespace } from "${r}/${I}";`,...a.map(({className:e,module:t})=>`
|
|
5
|
+
import { ${e} } from "${r}/${t}";`)].join(""),namespace:e=>`roleNamespace(env.SHARD, "${e}")`,reexported:e=>!y(e)}},G=(r,o,s={})=>{const{allowUnauthenticatedShardAccess:a=!1,appConfigModule:e,classModules:t=[],mergeDurableObjects:c=!1,shard:d={}}=s,i=R[r];if(i===void 0)throw new N("INTERNAL",`[lunora] no class-A worker wiring for framework "${r}"`);const p=o.replaceAll("\\","/"),l=B(p,t,c),v=t.filter(n=>l.reexported(n)).map(n=>`
|
|
6
|
+
export * from "${p}/${n}";
|
|
7
|
+
`).join(""),E=t.includes("scheduler")?`
|
|
8
|
+
.scheduler({ namespace: (env) => ${l.namespace("scheduler")} })`:"",g=t.includes("shardRegistry")?`
|
|
9
|
+
.shardRegistry((env) => ${l.namespace("shardRegistry")})`:"",A=e===void 0?"":`
|
|
10
|
+
import lunoraConfig from "${e}";`,[D,O]=e===void 0?["",""]:["lunoraConfig.app(",")"],S=Object.entries(d).filter(([,n])=>n!==void 0).toSorted(([n],[u])=>n.localeCompare(u)).map(([n,u])=>`
|
|
11
|
+
.${n}(${JSON.stringify(u)})`).join("");return`// Generated by @lunora/vite — class-A worker composition (PLAN4 M2).
|
|
12
|
+
// Do not edit: emitted from the detected framework (${r}). Point your
|
|
13
|
+
// wrangler \`main\` here (or re-export it) instead of hand-wiring createWorker.
|
|
14
|
+
${i.imports}
|
|
15
|
+
import { defineApp } from "${p}/app";${l.imports}${A}
|
|
16
|
+
|
|
17
|
+
const app = ${D}defineApp()
|
|
18
|
+
.shard((env) => env.SHARD)${E}${g}${O}
|
|
19
|
+
.httpRouter(${i.handler})${S}${a?`
|
|
20
|
+
.extend(() => ({ allowUnauthenticatedShardAccess: true }))`:""}
|
|
21
|
+
.build();
|
|
22
|
+
|
|
23
|
+
${l.classExport}
|
|
24
|
+
${v}
|
|
25
|
+
export default app;
|
|
26
|
+
`},P=async r=>{const{config:o,error:s}=await C(r);return s!==void 0?{error:s}:typeof o?.app!="function"?{}:{specifier:L(r)?.replaceAll("\\","/")}},K=(r,o)=>{const s=_(r.projectRoot,r.generatedDir.replace(T,""));return{async load(a){if(a===f&&h(o)&&o.framework!==void 0){if(this.environment.name==="client")return U;const e=b.filter(i=>w(M(s,`${i}.ts`))),t=k(s),{error:c,specifier:d}=await P(r.projectRoot);return c!==void 0&&this.warn(`[lunora] lunora.config could not be loaded, so its \`app\` hook was not composed: ${c}`),G(o.framework.framework,s,{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess,appConfigModule:d,classModules:e,mergeDurableObjects:t,shard:r.shard})}},name:"lunora:framework-compose",resolveId(a){if(a===$&&h(o))return f}}};export{R as CLASS_A_WIRING,$ as LUNORA_WORKER_VIRTUAL_ID,f as RESOLVED_LUNORA_WORKER_ID,G as buildWorkerEntrySource,K as frameworkComposePlugin,h 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 K,existsSync as X}from"node:fs";import{resolve as h,dirname as q,sep as b,basename as Q,join as Y,relative as Z}from"node:path";import{findProjectConfigFile as z,readServiceBindings as ee,PROJECT_CONFIG_FILENAMES as te,runCodegen as re,findTsconfig as ne,isTestPath as oe,fingerprintSchemaSources as A,createCodegenProject as ie,refreshCodegenProject as ce,CodegenDiagnosticError as ae}from"@lunora/codegen";import{LUNORA_TAG as m,isCodegenDisabled as se,CODEGEN_ENV as I,runPostCodegenHook as W,reportCodegenFindings as le,blockingFindingsMessage as de}from"@lunora/config";import{findWranglerFile as fe,readWranglerJsonc as ge,WRANGLER_FILES as ue,reconcileBindingsSafely as he,collectWranglerSecretVariables as me,reconcileWranglerExtras as pe}from"@lunora/config/cloudflare";import{isRunnableDevEnvironment as we}from"vite";import{createHash as ye}from"node:crypto";import ve from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as Se,r as Ee}from"./server-close-DWiO4Vxb.mjs";const Re=(e,r)=>{try{const{parsed:i,text:n}=ge(e);return i===void 0?`raw:${n}`:JSON.stringify(r?r(i):i)}catch{return"unreadable"}},$e=e=>{const r={...e},{triggers:i}=r;if(i!==null&&typeof i=="object"){const n={...i};delete n.crons,Object.keys(n).length>0?r.triggers=n:delete r.triggers}return r},M=e=>{const r=fe(e),i=r===void 0?"absent":Re(r,$e),n=z(e);let l="absent";try{n!==void 0&&(l=ye("sha256").update(K(n)).digest("hex"))}catch{}return`${i}\0${l}`},be=100,U=300,G=2,ke=e=>{let r,i,n=0;const l=()=>{r&&(clearTimeout(r),r=void 0)},a=(g,f)=>{i&&clearTimeout(i),i=setTimeout(()=>{if(i=void 0,e.fingerprint()!==g){if(n+=1,n>G){e.logger.warn(`${m} \`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(`${m} schema changed while \`postcodegen\` was running — regenerating`),f()}},U)},d=g=>{e.regenerate(g,f=>{a(f,()=>{d(g)})})};return{cancelPending:l,dispose:()=>{l(),i&&(clearTimeout(i),i=void 0)},onSave:g=>{l(),n=0,r=setTimeout(()=>{r=void 0,d(g)},be)}}},L=/[/\\]tsconfig\..+\.json$/u,Ce=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,je=e=>{const r=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.`,...r,"","Add to your worker entry:",...i].join(`
|
|
2
|
+
`)},De=(e,r,i)=>{if(r.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)}},N=(e,r,i,n)=>{const l=Y(e.projectRoot,e.schemaDir,"schema.ts");if(!X(l))return De(l,r,i),{};try{const a=re({apiSpec:e.apiSpec,lunoraDirectory:e.schemaDir,project:n,projectRoot:e.projectRoot,target:e.target,wranglerVariables:me(e.projectRoot)});return pe(e.projectRoot,a.cronTriggers,r),le(a,r),{blockingMessage:de(a),outputDirectory:h(a.outputDirectory)}}catch(a){const d=a instanceof Error?a.message:String(a);return r.error(`${m} codegen failed: ${d}`),i?.onError(a,d),{failure:`${m} codegen failed: ${d}`}}},Te=(e,r,i)=>{let n;for(const[l,a]of Object.entries(e.environments)){if(l==="client"){n=a;continue}we(a)||a.hot.send({path:"*",triggeredBy:r,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:ve,type:"custom"})},C={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},We=e=>{const r=h(e.projectRoot,e.schemaDir),i=se(process.env[I]);let n=h(e.projectRoot,e.generatedDir),l=0,a=!1,d;const g=new Map;let f,j=!1,D=!1,S,T;return{config(o,y){S=y.command},configResolved(){S!=="build"&&i||(T=N(e,C))},async buildStart(){const o=S!=="build"&&i,{blockingMessage:y,failure:v,outputDirectory:E}=T??(o?{}:N(e,C));if(T=void 0,S==="build"&&v!==void 0&&this.error(v),E!==void 0){n=E,a=!0;let p;try{p=await W({cwd:e.projectRoot,logger:C})}finally{a=!1}p.ran&&(l=Date.now()),S==="build"&&p.error!==void 0&&this.error(p.error)}S==="build"&&y!==void 0&&this.error(y),await he(e,C,p=>{d?.hot.send({err:{loc:void 0,message:je(p),stack:""},type:"error"})}),d!==void 0&&(f=M(e.projectRoot),j=!0)},configureServer(o){d=o,o.watcher.add(r);const y=ee(e.projectRoot).services.filter(t=>t.rpcEntrypoint!==void 0).map(t=>q(t.wranglerPath));o.watcher.add(y),f=M(e.projectRoot),j=!1;const v={error:t=>{o.config.logger.error(t)},info:t=>{o.config.logger.info(t)},warn:t=>{o.config.logger.warn(t)}};let E=!1;const p={onError(t,c){E=!0;const s=t instanceof ae?{column:t.column,file:t.file,line:t.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:t instanceof Error?t.stack??"":""},type:"error"})}},k=(t,c)=>t===c||t.startsWith(c+b);let _=!1,u;const V=()=>{for(const t of Object.values(o.environments)){const c=t.moduleGraph;for(const s of c.idToModuleMap.values())s.id&&k(s.id,n)&&c.invalidateModule(s)}},B=async(t,c)=>{try{if(_)return;u===void 0?u=ie(r):ce(u,r);const{outputDirectory:s}=N(e,v,p,u);if(s===void 0){u=void 0;return}n=s;const w=A(r);a=!0;let O;try{O=await W({cwd:e.projectRoot,logger:v})}finally{a=!1}if(O.ran&&(l=Date.now(),c(w)),O.error!==void 0)return;V(),Te(o,t,E),E=!1}catch(s){v.error(`${m} codegen watch: ${s instanceof Error?s.message:String(s)}`)}},P=ke({fingerprint:()=>A(r),logger:v,regenerate:(t,c)=>{B(t,c)}}),J=t=>L.test(t)||t.endsWith(`${b}tsconfig.json`)&&t===ne(r)?(u=void 0,!1):!(!k(t,r)||k(t,n)||!t.endsWith(".ts")||oe(Z(r,t).split(b).join("/"))),R=t=>{const c=h(t);if(!(!(Ce.test(c)&&!c.includes(`${b}node_modules${b}`)&&y.some(w=>k(c,w)))&&!J(c))){if(a||Date.now()-l<U){P.cancelPending();return}P.onSave(c)}},F=t=>{const c=h(t);(c.endsWith(`${b}tsconfig.json`)||L.test(c))&&(u=void 0)};i?o.config.logger.info(`${m} codegen watch disabled (${I}) — _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",F));const x=new Set([...ue.map(t=>h(e.projectRoot,t)),...te.map(t=>h(e.projectRoot,t))]);for(const t of x)o.watcher.add(t);const $=t=>{if(!x.has(h(t))||D)return;const c=M(e.projectRoot);if(!j){f=c;return}if(f===void 0){f=c;return}c!==f&&(f=c,D=!0,o.config.logger.info(`${m} ${Q(h(t))} 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 H=()=>{_||(_=!0,u=void 0,P.dispose(),o.watcher.off("add",R),o.watcher.off("change",R),o.watcher.off("unlink",R),o.watcher.off("unlink",F),o.watcher.off("add",$),o.watcher.off("change",$),o.watcher.off("unlink",$))};return()=>{Ee(o,g,H)}},buildEnd(){Se(g,this.environment)},name:"lunora:codegen"}};export{We 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
|
+
"version": "1.0.0-alpha.321",
|
|
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",
|
|
@@ -45,16 +45,15 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@cloudflare/vite-plugin": "1.
|
|
49
|
-
"@lunora/codegen": "1.0.0-alpha.
|
|
50
|
-
"@lunora/config": "1.0.0-alpha.
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"ts-morph": "^28.0.0"
|
|
48
|
+
"@cloudflare/vite-plugin": "1.62.5",
|
|
49
|
+
"@lunora/codegen": "1.0.0-alpha.278",
|
|
50
|
+
"@lunora/config": "1.0.0-alpha.323",
|
|
51
|
+
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
52
|
+
"@visulima/vite-overlay": "2.0.41"
|
|
54
53
|
},
|
|
55
54
|
"peerDependencies": {
|
|
56
|
-
"@lunora/studio": "1.0.0-alpha.
|
|
57
|
-
"vite": "^
|
|
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,112 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } 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 CLIENT_WORKER_STUB = `// @lunora/vite — the composed worker entry is worker-only and unavailable in the client environment.
|
|
8
|
-
export default {};
|
|
9
|
-
`;
|
|
10
|
-
const TRAILING_SLASH = /\/$/;
|
|
11
|
-
const CLASS_A_WIRING = {
|
|
12
|
-
"react-router": {
|
|
13
|
-
// `@react-router/dev` provides `virtual:react-router/server-build`; the
|
|
14
|
-
// runtime helper turns it into a `(request) => Promise<Response>`, which
|
|
15
|
-
// is exactly the `httpRouter.fetch` contract. Needs a named import.
|
|
16
|
-
handler: '{ fetch: (request) => createRequestHandler(() => import("virtual:react-router/server-build"), import.meta.env.MODE)(request) }',
|
|
17
|
-
imports: 'import { createRequestHandler } from "react-router";'
|
|
18
|
-
},
|
|
19
|
-
"solid-start": {
|
|
20
|
-
// SolidStart's `cloudflare-module` preset default-exports a fetch
|
|
21
|
-
// handler — structurally an `HttpRouterLike` already.
|
|
22
|
-
handler: "ssrModule.default",
|
|
23
|
-
imports: 'import * as ssrModule from "@solidjs/start/server-handler";'
|
|
24
|
-
},
|
|
25
|
-
"tanstack-start": {
|
|
26
|
-
// TanStack Start's server entry default-exports a `{ fetch }` handler.
|
|
27
|
-
handler: "ssrModule.default",
|
|
28
|
-
imports: 'import * as ssrModule from "@tanstack/react-start/server-entry";'
|
|
29
|
-
},
|
|
30
|
-
"tanstack-start-solid": {
|
|
31
|
-
// TanStack Start (Solid)'s server entry default-exports a `{ fetch }`
|
|
32
|
-
// handler — same shape as the React variant, different package.
|
|
33
|
-
handler: "ssrModule.default",
|
|
34
|
-
imports: 'import * as ssrModule from "@tanstack/solid-start/server-entry";'
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const isAutoComposable = (context) => {
|
|
38
|
-
const detected = context.framework;
|
|
39
|
-
return detected?.class === "A" && CLASS_A_WIRING[detected.framework] !== void 0;
|
|
40
|
-
};
|
|
41
|
-
const isWorkerVirtualActive = (context) => isAutoComposable(context);
|
|
42
|
-
const projectUsesUmbrella = (projectRoot) => {
|
|
43
|
-
try {
|
|
44
|
-
const pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
|
|
45
|
-
return ["dependencies", "devDependencies", "peerDependencies"].some((field) => pkg[field]?.["lunorash"] !== void 0);
|
|
46
|
-
} catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const buildWorkerEntrySource = (framework, generatedImportBase, hasContainers = false, useUmbrella = false) => {
|
|
51
|
-
const wiring = CLASS_A_WIRING[framework];
|
|
52
|
-
if (wiring === void 0) {
|
|
53
|
-
throw new Error(`[lunora] no class-A worker wiring for framework "${framework}"`);
|
|
54
|
-
}
|
|
55
|
-
const runtimeModule = useUmbrella ? "lunorash/runtime" : "@lunora/runtime";
|
|
56
|
-
const containersReexport = hasContainers ? `
|
|
57
|
-
export * from "${generatedImportBase}/containers";
|
|
58
|
-
` : "";
|
|
59
|
-
return `// Generated by @lunora/vite — class-A worker composition (PLAN4 M2).
|
|
60
|
-
// Do not edit: emitted from the detected framework (${framework}). Point your
|
|
61
|
-
// wrangler \`main\` here (or re-export it) instead of hand-wiring createWorker.
|
|
62
|
-
import { composeWorker } from "${runtimeModule}";
|
|
63
|
-
${wiring.imports}
|
|
64
|
-
import { LUNORA_FUNCTIONS } from "${generatedImportBase}/functions";
|
|
65
|
-
import { openApiSpec } from "${generatedImportBase}/openapi";
|
|
66
|
-
import { createShardDO } from "${generatedImportBase}/shard";
|
|
67
|
-
|
|
68
|
-
export const ShardDO = createShardDO();
|
|
69
|
-
${containersReexport}
|
|
70
|
-
|
|
71
|
-
let worker;
|
|
72
|
-
|
|
73
|
-
export default {
|
|
74
|
-
async fetch(request, env, context) {
|
|
75
|
-
worker ??= composeWorker({
|
|
76
|
-
functions: LUNORA_FUNCTIONS,
|
|
77
|
-
httpRouter: ${wiring.handler},
|
|
78
|
-
openApiSpec,
|
|
79
|
-
routes: {},
|
|
80
|
-
shardDO: env.SHARD,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return worker.fetch(request, env, context);
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
`;
|
|
87
|
-
};
|
|
88
|
-
const frameworkComposePlugin = (options, context) => {
|
|
89
|
-
const generatedImportBase = resolve(options.projectRoot, options.generatedDir.replace(TRAILING_SLASH, ""));
|
|
90
|
-
const useUmbrella = projectUsesUmbrella(options.projectRoot);
|
|
91
|
-
return {
|
|
92
|
-
load(id) {
|
|
93
|
-
if (id === RESOLVED_LUNORA_WORKER_ID && isWorkerVirtualActive(context) && context.framework !== void 0) {
|
|
94
|
-
if (this.environment.name === "client") {
|
|
95
|
-
return CLIENT_WORKER_STUB;
|
|
96
|
-
}
|
|
97
|
-
const hasContainers = existsSync(join(generatedImportBase, "containers.ts"));
|
|
98
|
-
return buildWorkerEntrySource(context.framework.framework, generatedImportBase, hasContainers, useUmbrella);
|
|
99
|
-
}
|
|
100
|
-
return void 0;
|
|
101
|
-
},
|
|
102
|
-
name: "lunora:framework-compose",
|
|
103
|
-
resolveId(id) {
|
|
104
|
-
if (id === LUNORA_WORKER_VIRTUAL_ID && isWorkerVirtualActive(context)) {
|
|
105
|
-
return RESOLVED_LUNORA_WORKER_ID;
|
|
106
|
-
}
|
|
107
|
-
return void 0;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
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 };
|