@lunora/vite 1.0.0-alpha.43 → 1.0.0-alpha.430
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 +207 -104
- package/README.md +15 -5
- package/dist/index.d.mts +455 -345
- package/dist/index.d.ts +455 -345
- package/dist/index.mjs +4 -164
- package/dist/packem_shared/CLASS_A_WIRING-CDSSmDqw.mjs +29 -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/build-session-D75JzvIT.mjs +1 -0
- package/dist/packem_shared/buildStudioUrl-Num2hyVU.mjs +1 -0
- package/dist/packem_shared/checkLunoraProxy-BNPgNWtV.mjs +1 -0
- package/dist/packem_shared/codegenPlugin-CzkFjxTv.mjs +3 -0
- package/dist/packem_shared/containerLogsPlugin-CWF3LHN3.mjs +1 -0
- package/dist/packem_shared/devStatePlugin-CF4GDvBn.mjs +1 -0
- package/dist/packem_shared/devVariablesPlugin-BZc49ZPO.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-CxfLf0vb.mjs +1 -0
- package/dist/packem_shared/server-close-DWiO4Vxb.mjs +1 -0
- package/dist/packem_shared/wranglerValidatorPlugin-CPPKubFC.mjs +1 -0
- package/package.json +9 -10
- package/dist/packem_shared/CLASS_A_WIRING-DWYL4g1x.mjs +0 -118
- 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,164 +1,4 @@
|
|
|
1
|
-
import { cloudflare }
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
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-DWYL4g1x.mjs';
|
|
12
|
-
export { CLASS_A_WIRING, LUNORA_WORKER_VIRTUAL_ID, buildWorkerEntrySource, isAutoComposable } from './packem_shared/CLASS_A_WIRING-DWYL4g1x.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
|
-
allowUnauthenticatedShardAccess: input.allowUnauthenticatedShardAccess ?? false,
|
|
113
|
-
apiSpec: input.apiSpec ?? "openapi",
|
|
114
|
-
cloudflare: cloudflareOption,
|
|
115
|
-
studio: input.studio ?? true,
|
|
116
|
-
generatedDir: input.generatedDir ?? `${schemaDirectory}/_generated`,
|
|
117
|
-
overlay: resolveOverlayOption(input.overlay),
|
|
118
|
-
projectRoot: input.projectRoot ?? process.cwd(),
|
|
119
|
-
schemaDir: schemaDirectory,
|
|
120
|
-
validateWrangler: input.validateWrangler ?? true
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
const lunora = (options) => {
|
|
124
|
-
const resolved = resolveOptions(options);
|
|
125
|
-
const context = createPluginContext();
|
|
126
|
-
const { isServe, plugin: commandProbe } = createCommandProbe();
|
|
127
|
-
const plugins = [
|
|
128
|
-
commandProbe,
|
|
129
|
-
frameworkDetectPlugin(resolved, context),
|
|
130
|
-
// Reads the detected framework off `context` and, for a class-A
|
|
131
|
-
// framework (and only when the CF integration is on), resolves the
|
|
132
|
-
// `virtual:lunora/worker` entry to a `composeWorker`-based worker that
|
|
133
|
-
// routes `/_lunora/*` to Lunora and falls through to the framework SSR
|
|
134
|
-
// handler — so the template never hand-wires `createWorker({ httpRouter })`.
|
|
135
|
-
// A strict no-op for class-C and the `cloudflare: false` BYO path.
|
|
136
|
-
frameworkComposePlugin(resolved, context),
|
|
137
|
-
devVariablesPlugin(resolved),
|
|
138
|
-
codegenPlugin(resolved),
|
|
139
|
-
logStreamPlugin(),
|
|
140
|
-
agentRulesHintPlugin(resolved)
|
|
141
|
-
];
|
|
142
|
-
if (resolved.studio) {
|
|
143
|
-
plugins.push(studioPlugin());
|
|
144
|
-
}
|
|
145
|
-
if (resolved.validateWrangler) {
|
|
146
|
-
plugins.push(wranglerValidatorPlugin(resolved));
|
|
147
|
-
}
|
|
148
|
-
if (resolved.overlay !== false) {
|
|
149
|
-
plugins.push(errorOverlayPlugin(resolved.overlay));
|
|
150
|
-
}
|
|
151
|
-
if (resolved.cloudflare !== false) {
|
|
152
|
-
plugins.push(containerLogsPlugin(resolved));
|
|
153
|
-
const remotePlan = planViteRemoteBindings({ projectRoot: resolved.projectRoot });
|
|
154
|
-
if (remotePlan.enabled && remotePlan.configPath !== void 0) {
|
|
155
|
-
plugins.push(remoteBindingsCleanupPlugin(remotePlan.cleanup));
|
|
156
|
-
}
|
|
157
|
-
const cloudflareOptions = withRemoteBindings(withDevWorkerEnv(resolved.cloudflare, isServe), isServe, remotePlan);
|
|
158
|
-
plugins.push(...withWorkerStartupHint(cloudflare(cloudflareOptions)));
|
|
159
|
-
}
|
|
160
|
-
return plugins;
|
|
161
|
-
};
|
|
162
|
-
const VERSION = "0.0.0";
|
|
163
|
-
|
|
164
|
-
export { VERSION, codegenPlugin, containerLogsPlugin, createCommandProbe, devVariablesPlugin, frameworkComposePlugin, logStreamPlugin, lunora, lunoraSolutionFinders, planViteRemoteBindings, remoteBindingsCleanupPlugin, resolveOverlayOption, studioPlugin, withDevWorkerEnv, withRemoteBindings, withWorkerStartupHint, wranglerValidatorPlugin };
|
|
1
|
+
import{createRequire as I}from"node:module";import{resolve as h,sep as L,dirname as M,isAbsolute as U,relative as j}from"node:path";import{cloudflare as H}from"@cloudflare/vite-plugin";import{lunoraLine as A,BUNDLE_META_PATH_ENV as V,canonicalPath as k,DEFAULT_BUNDLE_META_PATH as z,resolveDeployDriver as G,startCelldDevSession as K,formatLunoraEvent as q,detectFramework as J,resolveSchemaDirectory as Q,createDiscoveryCache as Y,targetRunsOwnDevServer as X,resolveLazyFunctions as Z,resolveTargetOrThrow as ee,isRunnableTarget as re,runnableTargetIds as te,assertBuildTargetMatches as oe}from"@lunora/config";import{GENERATED_CLASS_MODULES as Nr,detectFramework as Fr}from"@lunora/config";import ne from"@visulima/vite-overlay";import{detectAgentRules as ie,claimAgentRulesHint as se,lunoraLine as g,AGENT_RULES_HINT as ae}from"@lunora/config/cli";import{reconcileBindingsSafely as le,findWranglerFile as ce,readWranglerJsonc as ue,warnCloudflareCliConfigOnce as de,hasCloudflareCredentials as fe,withheldBindings as pe,describeWithheld as me,startLocalHyperdrive as ge}from"@lunora/config/cloudflare";import{reconcileWranglerCrons as Ir}from"@lunora/config/cloudflare";import{o as ve}from"./packem_shared/build-session-D75JzvIT.mjs";import{mkdirSync as he,writeFileSync as we,statSync as ye,rmSync as Se}from"node:fs";import{r as W,a as $}from"./packem_shared/server-close-DWiO4Vxb.mjs";import Pe from"./packem_shared/codegenPlugin-CzkFjxTv.mjs";import be from"./packem_shared/containerLogsPlugin-CWF3LHN3.mjs";import Ae from"./packem_shared/devStatePlugin-CF4GDvBn.mjs";import Re from"./packem_shared/devVariablesPlugin-BZc49ZPO.mjs";import{frameworkComposePlugin as ke}from"./packem_shared/CLASS_A_WIRING-CDSSmDqw.mjs";import{CLASS_A_WIRING as Ur,LUNORA_WORKER_VIRTUAL_ID as jr,buildWorkerEntrySource as Hr,isAutoComposable as Vr}from"./packem_shared/CLASS_A_WIRING-CDSSmDqw.mjs";import Ee from"./packem_shared/logStreamPlugin-EMXiy6pI.mjs";import{proxyCheckPlugin as De}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{checkLunoraProxy as Gr}from"./packem_shared/checkLunoraProxy-BNPgNWtV.mjs";import{remoteBindingsPlugin as _e}from"./packem_shared/planViteRemoteBindings-CxfLf0vb.mjs";import{planViteRemoteBindings as qr,withRemoteBindings as Jr}from"./packem_shared/planViteRemoteBindings-CxfLf0vb.mjs";import{readDevServiceBindings as Te}from"@lunora/codegen";import{lunoraSolutionFinders as Ce}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{lunoraSolutionFinder as Yr}from"./packem_shared/lunoraSolutionFinder--J0x2mAM.mjs";import{studioPlugin as xe}from"./packem_shared/buildStudioUrl-Num2hyVU.mjs";import{buildStudioUrl as Zr}from"./packem_shared/buildStudioUrl-Num2hyVU.mjs";import{withWorkerStartupHint as Oe}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{WORKER_STARTUP_HINT as rt,augmentWorkerStartupError as tt,isWorkerEntryEvalError as ot}from"./packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs";import{wranglerValidatorPlugin as Le}from"./packem_shared/wranglerValidatorPlugin-CPPKubFC.mjs";import{default as it}from"./packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{STUDIO_PATH as at}from"@lunora/config/studio-host";const We=r=>({apply:"serve",configureServer(e){return()=>{ie(r.projectRoot).installed||!se()||e.config.logger.warn(`
|
|
2
|
+
${g(ae)}
|
|
3
|
+
`)}},name:"lunora:agent-rules-hint"}),$e="vite-plugin-cloudflare",N=["assetFileNames","chunkFileNames","entryFileNames"],F=r=>{const{output:e}=r.rolldownOptions??r.rollupOptions;return e===void 0?[]:[e].flat()},Ne=r=>F(r).every(e=>N.every(t=>e[t]===void 0||typeof e[t]=="string"&&e[t].includes("[hash]"))),Fe=r=>[...F(r).flatMap(e=>N.map(t=>e[t]).filter(t=>typeof t=="string")),`${r.assetsDir}/[name]-[hash][extname]`,`${r.assetsDir}/[name]-[hash].js`],Be=(r,e)=>{let t=!1;return{apply:"build",applyToEnvironment:o=>o.name==="client",configResolved(o){t=o.plugins.some(s=>s.name===$e)},name:"lunora:asset-headers",async writeBundle(){if(!t)return;const{config:o}=this.environment,{emitProjectAssetHeaders:s}=await import("@lunora/config/cloudflare");s({hashedDirectory:Ne(o.build)?o.build.assetsDir:void 0,hashedNamePatterns:Fe(o.build),outputDirectory:h(o.root,o.build.outDir),projectRoot:r.projectRoot,publicDirectory:o.publicDir===""?void 0:o.publicDir,requireAssetsDirectory:!1,schemaDir:r.schemaDir,target:r.target,wranglerPath:e},{info:n=>{o.logger.info(A(n))},warn:n=>{o.logger.warn(A(n))}})}}},Ie=(r,e)=>({async config(t,o){if(e?.clear(),o.isPreview===!0)return;const s=async()=>le({...r,cache:e},{info:n=>{console.info(n)},warn:n=>{console.warn(n)}});await(o.command==="build"?ve(r,"provision",s):s())},enforce:"pre",name:"lunora:bindings-provision"}),Me=(r,e=L)=>r.split(e).join("/"),R=(r,e)=>U(e)?Me(j(r,e)):e,y=(r,e,t)=>e.map(o=>({kind:t,path:R(r,o)})),Ue=/[?#]/,E=r=>{try{return ye(r).size}catch{return}},je=(r,e)=>E(r)??E(r.split(Ue)[0]??r)??Buffer.byteLength(e??""),He=r=>{let e;return{apply:"build",applyToEnvironment:t=>t.config.consumer==="server",name:"lunora:bundle-meta",sharedDuringBuild:!0,generateBundle(t,o){const s={},n={};for(const[u,d]of Object.entries(o)){if(d.type!=="chunk")continue;const f={bytes:Buffer.byteLength(d.code),imports:[...y(r,d.imports,"import-statement"),...y(r,d.dynamicImports,"dynamic-import")],inputs:{}};d.facadeModuleId&&(f.entryPoint=R(r,d.facadeModuleId));for(const[m,S]of Object.entries(d.modules)){const v=R(r,m);if(f.inputs[v]={bytesInOutput:Buffer.byteLength(S.code??"")},!s[v]){const p=this.getModuleInfo(m);s[v]={bytes:je(m,p?.code),imports:[...y(r,p?.importedIds??[],"import-statement"),...y(r,p?.dynamicallyImportedIds??[],"dynamic-import")]}}}n[u]=f}const i=process.env[V],a=i===void 0||i===""?void 0:h(r,i),l=`${k(h(r,".lunora"))}${L}`,c=a!==void 0&&k(a).startsWith(l)?a:h(r,z);if(e!==void 0&&e!==this.environment.name){Se(c,{force:!0}),this.warn(`bundle-meta: environment "${this.environment.name}" built a server bundle after "${e}" wrote one; no bundle-meta.json is written, because the app's own graph cannot be told apart from a service's`);return}e=this.environment.name,he(M(c),{recursive:!0}),we(c,`${JSON.stringify({inputs:s,outputs:n},void 0,2)}
|
|
4
|
+
`,"utf8")}}},D="/_lunora",Ve=8787,w=new Map,B=r=>r.command==="serve"&&r.isPreview!==!0,ze=(r,e)=>{let t;return()=>{if(t===void 0)try{G(e).projectConfig?.(r,"dev"),t={runs:!0}}catch(o){t={reason:o instanceof Error?o.message:String(o),runs:!1}}return t}},Ge=r=>{const e=ce(r),t=e===void 0?void 0:ue(e).parsed?.dev?.port;return typeof t=="number"?t:Ve},Ke=(r,e)=>r.map(t=>{const o=t.apply;return{...t,apply:(s,n)=>B(n)&&e()?!1:typeof o=="function"?o(s,n):o===void 0||o===n.command}}),qe=(r,e,{stream:t,tag:o})=>{const s=q(e);s!==void 0?r[s.level](`[lunora] ${s.text}`):t==="stderr"?r.warn(`[${o}] ${e}`):r.info(`[${o}] ${e}`)},Je=(r,e)=>{const t=Ge(r),o=new Map;return{apply:(s,n)=>B(n)&&e(),buildEnd(){$(o,this.environment)},config:s=>{if(s.server?.proxy?.[D]===void 0)return{server:{proxy:{[D]:{changeOrigin:!0,target:`http://127.0.0.1:${String(t)}`,ws:!0}}}}},async configureServer(s){const{logger:n}=s.config;await w.get(r)?.stop(),w.delete(r),n.info(`[lunora] starting the worker on celld at http://127.0.0.1:${String(t)} …`);const i=await K({log:(l,c)=>{qe(n,l,c)},port:t,projectRoot:r});w.set(r,i);const a=l=>{n.error(`[lunora] the worker on celld exited (code ${String(l)}) — restart vite dev to bring it back`)};i.exited.then(a).catch(()=>{}),W(s,o,()=>{w.get(r)===i&&w.delete(r),i.stop().catch(l=>{n.error(`[lunora] stopping celld failed: ${l instanceof Error?l.message:String(l)}`)})})},name:"lunora:celld-dev"}},Qe=r=>({configResolved(e){de(r.projectRoot,t=>{e.logger.warn(A(t))})},name:"lunora:cf-config-warning"}),Ye=()=>({}),Xe={astro:"Astro",none:"standalone (SPA / SSR-less)",nuxt:"Nuxt","react-router":"React Router","solid-start":"SolidStart",sveltekit:"SvelteKit","tanstack-start":"TanStack Start","tanstack-start-solid":"TanStack Start (Solid)",vinext:"Next.js on Vite (vinext)"},Ze=r=>{const e=Xe[r.framework];return r.framework==="none"?g("no meta-framework detected — running standalone."):r.class==="B"?g(`detected ${e} — composition is handled by the framework adapter.`):g(`detected ${e} — composing the Lunora worker into one Cloudflare Worker.`)},er=(r,e)=>{let t=!1;const o=()=>{e.framework??=J(r.projectRoot)};return{config(){o()},configResolved(){o()},configureServer(){o(),!t&&e.framework!==void 0&&(t=!0,console.info(Ze(e.framework)))},name:"lunora:framework-detect"}},_=r=>Array.isArray(r)?r:[],P=new WeakSet,rr=(r,e={})=>{let t=!1;const o=r.experimental?.newConfig,s=o!==void 0&&o!==!1,n=e.hasCredentials??(()=>fe({projectRoot:e.projectRoot})),i=(a,l)=>{const c=(u,...d)=>{const f=typeof a=="function"?a(u,...d):a,m=f===void 0?void 0:{...f},S=t?[..._(u.artifacts),..._(m?.artifacts)]:[],v=t?pe({ai:u.ai??m?.ai,artifacts:S},n):[];for(const p of v)Reflect.deleteProperty(u,p.kind),Reflect.deleteProperty(m??{},p.kind),console.warn(g(me(p)));return l?.(v.map(p=>p.binding)),m};return P.add(c),c};return{config(a,l){if(t=l.command==="serve"&&l.isPreview!==!0,s)return;const c=r;P.has(c.config)||(c.config=i(c.config,e.onWithheld)),Array.isArray(c.auxiliaryWorkers)&&(c.auxiliaryWorkers=c.auxiliaryWorkers.map(u=>P.has(u.config)?u:{...u,config:i(u.config)}))},enforce:"pre",name:"lunora:local-ai-binding"}},tr=5e3,or=3e4,T=new Map,C=r=>{const e=T.get(r);if(e!==void 0)return e;const t={databases:[],pending:Promise.resolve(),servers:0,stopping:Promise.resolve()};return T.set(r,t),t},nr=async r=>{const e=r.databases.splice(0);await Promise.allSettled(e.map(async t=>t.stop()))},x=(r,e)=>{const t=setTimeout(()=>{r.pending.then(async()=>{r.servers===0&&(r.stopping=nr(r),await r.stopping)}).catch(()=>{})},e);return t.unref(),t},O=({projectRoot:r,start:e=ge,wranglerConfigPath:t})=>{const o=new Map,s=n=>{const i=C(r);let a=!1;i.servers+=1,clearTimeout(i.stopTimer),n(()=>{a||(a=!0,i.servers-=1,i.servers===0&&(i.stopTimer=x(i,tr)))})};return{async config(n,i){if(i.command!=="serve")return;const a=C(r);clearTimeout(a.stopTimer);const l=a.pending,c=(async()=>{await l,await a.stopping;const u=await e({onWarning:d=>{console.warn(g(d))},projectRoot:r,wranglerConfigPath:t});u!==void 0&&a.databases.push(u),u!==void 0&&u.bindings.length>0&&console.info(g(`Hyperdrive ${u.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite.`))})();a.pending=c.catch(()=>{});try{await c}finally{a.servers===0&&(clearTimeout(a.stopTimer),a.stopTimer=x(a,or))}},buildEnd(){$(o,this.environment)},configureServer(n){s(i=>{W(n,o,i)})},configurePreviewServer(n){s(i=>{n.httpServer.once("close",i)})},enforce:"pre",name:"lunora:local-hyperdrive"}},ir=(r,e)=>({config(t,o){if(o.command!=="serve")return;const{services:s}=Te(e,Q(e)),n=Array.isArray(r.auxiliaryWorkers)?r.auxiliaryWorkers:[],i=new Set(n.map(l=>l.configPath===void 0?"":h(e,l.configPath))),a=[...new Set(s.map(l=>l.wranglerPath))].filter(l=>!i.has(l)).map(l=>({configPath:l}));a.length>0&&(r.auxiliaryWorkers=[...n,...a])},enforce:"pre",name:"lunora:service-workers"}),sr=r=>{if(r===!1)return!1;const e=r===!0||r===void 0?{}:r;return{...e,forwardedConsoleMethods:e.forwardedConsoleMethods??["error","warn"],solutionFinders:[...Ce,...e.solutionFinders??[]]}},ar=(r,e)=>{const t=ee(r,e);if(!re(t)){const o=te();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 oe(t,r),t},lr=r=>{const e=r??{};if(e.lazyFunctions!==void 0)throw new Error("lunora(): the `lazyFunctions` option was removed. Set `codegen: { lazyFunctions: true }` in lunora.config (or pass --lazy-functions for one run).");const t=e.schemaDir??"lunora";let o;e.cloudflare===!1?o=!1:e.cloudflare===!0||e.cloudflare===void 0?o={}:o=e.cloudflare;const s=e.projectRoot??process.cwd(),n=ar(s,e.target);return{allowUnauthenticatedShardAccess:e.allowUnauthenticatedShardAccess??!1,apiSpec:e.apiSpec??"openapi",lazyFunctions:Z(),cloudflare:o,studio:e.studio??!0,generatedDir:`${t}/_generated`,overlay:sr(e.overlay),projectRoot:s,schemaDir:t,shard:e.shard??{},target:n,validateWrangler:e.validateWrangler??!0}},b=(r,e)=>{const{configPath:t}=r;return typeof t=="string"&&t!==""?h(e,t):void 0},Or=r=>{const e=lr(r),t=Ye(),o=Y();let s=[],n=[];const i=[er(e,t),ke(e,t),Re(e,{configPath:e.cloudflare===!1?void 0:b(e.cloudflare,e.projectRoot),withheld:()=>[...new Set([...s,...n])]}),Ie(e,o),Pe(e,o),He(e.projectRoot),Be(e,e.cloudflare===!1?void 0:b(e.cloudflare,e.projectRoot)),Ee(),Ae(e),We(e),Qe(e),De()];e.studio&&i.push(xe(e)),e.validateWrangler&&i.push(Le(e,o)),e.overlay!==!1&&i.push(ne(e.overlay)),i.push(be(e,o));const a=e.cloudflare===!1?void 0:{...e.cloudflare};if(i.push(_e(a,{projectRoot:e.projectRoot},l=>{s=l.withheld.map(c=>c.binding)})),a===void 0&&i.push(O({projectRoot:e.projectRoot})),a!==void 0){i.push(ir(a,e.projectRoot));const l=X(e.target),c=ze(e.projectRoot,e.target),u=()=>l&&c().runs;i.push(...Ke([O({projectRoot:e.projectRoot,wranglerConfigPath:b(a,e.projectRoot)}),rr(a,{onWithheld:d=>{n=d},projectRoot:e.projectRoot}),...Oe(H(a))],u)),l&&i.push(Je(e.projectRoot,u),{apply:(d,f)=>f.command==="serve"&&f.isPreview!==!0&&!u(),configureServer(d){d.config.logger.warn(`[lunora] target "${e.target}": vite dev serves the worker in workerd, not on ${e.target} — ${c().reason??"it cannot run this project"}. \`vite build\` then \`lunora deploy\` ships it to ${e.target}.`)},name:"lunora:target-runtime-notice"})}return i},Lr=I(import.meta.url)("../package.json").version;export{Ur as CLASS_A_WIRING,Nr as GENERATED_CLASS_MODULES,it as LUNORA_API_UPDATED_EVENT,jr as LUNORA_WORKER_VIRTUAL_ID,at as STUDIO_PATH,Lr as VERSION,rt as WORKER_STARTUP_HINT,tt as augmentWorkerStartupError,Zr as buildStudioUrl,Hr as buildWorkerEntrySource,Gr as checkLunoraProxy,Pe as codegenPlugin,be as containerLogsPlugin,Fr as detectFramework,Ae as devStatePlugin,Re as devVariablesPlugin,ke as frameworkComposePlugin,Vr as isAutoComposable,ot as isWorkerEntryEvalError,Ee as logStreamPlugin,Or as lunora,Yr as lunoraSolutionFinder,Ce as lunoraSolutionFinders,qr as planViteRemoteBindings,De as proxyCheckPlugin,Ir as reconcileWranglerCrons,_e as remoteBindingsPlugin,sr as resolveOverlayOption,xe as studioPlugin,Jr as withRemoteBindings,Oe as withWorkerStartupHint,Le as wranglerValidatorPlugin};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{existsSync as L}from"node:fs";import{resolve as y,join as M}from"node:path";import{loadProjectConfig as C,findProjectConfigFile as k}from"@lunora/codegen";import{DURABLE_OBJECT_BINDINGS as m,GENERATED_CLASS_MODULES as I,isMergedProject as b,GENERATED_MODULE_DURABLE_OBJECTS as N,isMergedRoleModule as U,MERGED_DURABLE_OBJECTS_MODULE as j}from"@lunora/config";import{LunoraError as x}from"@lunora/errors";const R="virtual:lunora/worker",T="\0",f=`${T}${R}`,B=/^virtual:lunora\/worker$/u,W=/^\0virtual:lunora\/worker$/u,G=`// @lunora/vite — the composed worker entry is worker-only and unavailable in the client environment.
|
|
2
|
+
export default {};
|
|
3
|
+
`,P=/\/$/,v={"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 t=r.framework;return t?.class==="A"&&v[t.framework]!==void 0},V={adminRevocations:m.AdminRevocationDO,scheduler:m.SchedulerDO,shardRegistry:m.ShardRegistryDO},H=(r,t,a)=>{if(!a)return{classExport:"export const ShardDO = app.ShardDO;",imports:"",namespace:e=>`env.${V[e]}`,reexported:()=>!0};const s=t.flatMap(e=>{const o=N[e];return o===void 0?[]:[{className:o,module:e}]});return{classExport:`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO${s.map(({className:e,module:o})=>`, ${o}: ${e}`).join("")} });`,imports:[`
|
|
4
|
+
import { mergeDurableObjects, roleNamespace } from "${r}/${j}";`,...s.map(({className:e,module:o})=>`
|
|
5
|
+
import { ${e} } from "${r}/${o}";`)].join(""),namespace:e=>`roleNamespace(env.SHARD, "${e}")`,reexported:e=>!U(e)}},K=(r,t,a={})=>{const{allowUnauthenticatedShardAccess:s=!1,appConfigModule:e,classModules:o=[],mergeDurableObjects:l=!1,shard:p={}}=a,c=v[r];if(c===void 0)throw new x("INTERNAL",`[lunora] no class-A worker wiring for framework "${r}"`);const d=t.replaceAll("\\","/"),i=H(d,o,l),E=l&&o.includes("shardRegistry")?`
|
|
6
|
+
export { ShardRegistryEntrypoint } from "${d}/shardRegistry";
|
|
7
|
+
`:"",$=o.filter(n=>i.reexported(n)).map(n=>`
|
|
8
|
+
export * from "${d}/${n}";
|
|
9
|
+
`).join("")+E,g=o.includes("scheduler")?`
|
|
10
|
+
.scheduler({ namespace: (env) => ${i.namespace("scheduler")} })`:"",O=o.includes("shardRegistry")?`
|
|
11
|
+
.shardRegistry((env) => ${i.namespace("shardRegistry")})`:"",D=o.includes("adminRevocations")?`
|
|
12
|
+
.adminRevocations((env) => ${i.namespace("adminRevocations")})`:"",A=e===void 0?"":`
|
|
13
|
+
import lunoraConfig from "${e}";`,[_,S]=e===void 0?["",""]:["lunoraConfig.app(",")"],w=Object.entries(p).filter(([,n])=>n!==void 0).toSorted(([n],[u])=>n.localeCompare(u)).map(([n,u])=>`
|
|
14
|
+
.${n}(${JSON.stringify(u)})`).join("");return`// Generated by @lunora/vite — class-A worker composition (PLAN4 M2).
|
|
15
|
+
// Do not edit: emitted from the detected framework (${r}). Point your
|
|
16
|
+
// wrangler \`main\` here (or re-export it) instead of hand-wiring createWorker.
|
|
17
|
+
${c.imports}
|
|
18
|
+
import { defineApp } from "${d}/app";${i.imports}${A}
|
|
19
|
+
|
|
20
|
+
const app = ${_}defineApp()
|
|
21
|
+
.shard((env) => env.SHARD)${g}${O}${D}${S}
|
|
22
|
+
.httpRouter(${c.handler})${w}${s?`
|
|
23
|
+
.extend(() => ({ allowUnauthenticatedShardAccess: true }))`:""}
|
|
24
|
+
.build();
|
|
25
|
+
|
|
26
|
+
${i.classExport}
|
|
27
|
+
${$}
|
|
28
|
+
export default app;
|
|
29
|
+
`},q=async r=>{const{config:t,error:a}=await C(r);return a!==void 0?{error:a}:typeof t?.app!="function"?{}:{specifier:k(r)?.replaceAll("\\","/")}},Q=(r,t)=>{const a=y(r.projectRoot,r.generatedDir.replace(P,""));return{load:{filter:{id:W},async handler(s){if(s===f&&h(t)&&t.framework!==void 0){if(this.environment.name==="client")return G;const e=I.filter(c=>L(M(a,`${c}.ts`))),o=b(a),{error:l,specifier:p}=await q(r.projectRoot);return l!==void 0&&this.warn(`[lunora] lunora.config could not be loaded, so its \`app\` hook was not composed: ${l}`),K(t.framework.framework,a,{allowUnauthenticatedShardAccess:r.allowUnauthenticatedShardAccess,appConfigModule:p,classModules:e,mergeDurableObjects:o,shard:r.shard})}}},name:"lunora:framework-compose",resolveId:{filter:{id:B},handler(s){if(s===R&&h(t))return f}}}};export{v as CLASS_A_WIRING,R as LUNORA_WORKER_VIRTUAL_ID,f as RESOLVED_LUNORA_WORKER_ID,K as buildWorkerEntrySource,Q 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{join as a}from"node:path";import{findProjectConfigFile as f,fingerprintSchemaSources as u}from"@lunora/codegen";import{createHash as l}from"node:crypto";import{readFileSync as m}from"node:fs";import{findWranglerFile as h,readWranglerJsonc as y}from"@lunora/config/cloudflare";const p=(n,e)=>{try{const{parsed:r,text:t}=y(n);return r===void 0?`raw:${t}`:JSON.stringify(e?e(r):r)}catch{return"unreadable"}},w=n=>{const e={...n},{triggers:r}=e;if(r!==null&&typeof r=="object"){const t={...r};delete t.crons,Object.keys(t).length>0?e.triggers=t:delete e.triggers}return e},c=n=>{const e=h(n),r=e===void 0?"absent":p(e,w),t=f(n);let o="absent";try{t!==void 0&&(o=l("sha256").update(m(t)).digest("hex"))}catch{}return`${r}\0${o}`},i=new Map,g=n=>JSON.stringify([a(n.projectRoot,n.schemaDir),n.apiSpec,n.lazyFunctions,n.target]),S=n=>u(a(n.projectRoot,n.schemaDir)),d=n=>{const e=g(n),r=S(n),t=c(n.projectRoot);let o=i.get(e);return(o===void 0||o.started||o.sources!==r||o.config!==t&&o.running===0)&&(o={config:t,done:new Map,running:0,sources:r,started:!1},i.set(e,o)),o},C=async(n,e,r)=>{const t=d(n);let o=t.done.get(e);return o===void 0&&(t.running+=1,o=(async()=>r())().then(s=>(t.running-=1,t.config=c(n.projectRoot),s),s=>{throw t.running-=1,t.done.delete(e),s}),t.done.set(e,o)),o},k=(n,e,r)=>{const t=d(n);t.done.has(e)||(r(),t.done.set(e,Promise.resolve()),t.config=c(n.projectRoot))},J=n=>{const e=i.get(g(n));e!==void 0&&(e.started=!0)};export{k as a,c,J as m,C as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{formatDevBannerRow as n,targetRunsOwnDevServer as l,devTriggerHints as i}from"@lunora/config";import{STUDIO_PATH as g,studioMountPath as f,isNonLoopbackHost as u,createStudioMiddleware as m}from"@lunora/config/studio-host";import{STUDIO_PATH as D}from"@lunora/config/studio-host";const h=/\/$/,S=e=>{if(e.resolvedLocal!==void 0&&e.resolvedLocal!=="")return`${e.resolvedLocal.replace(h,"")}${g}`;const o=f(e.base);if(e.address===void 0||typeof e.address=="string")return`http://localhost:5173${o}`;const r=e.address.address==="::"||e.address.address==="0.0.0.0"?"localhost":e.address.address;return`http://${r.includes(":")?`[${r}]`:r}:${String(e.address.port)}${o}`},d={arrow:e=>`\x1B[32m${e}\x1B[39m`,label:e=>`\x1B[1m${e}\x1B[22m`},a=9,p=(e,o)=>{const t=e.cloudflare!==!1&&!l(e.target)?`${new URL(o).origin}/cdn-cgi/local/scheduled`:void 0;return i({projectRoot:e.projectRoot,scheduledUrl:t,schemaDirectory:e.schemaDir,studioUrl:o}).map(({label:s,text:c})=>n(s,c,a,d))},$=e=>({apply:"serve",configureServer(o){const r=u(o.config.server?.host);return o.middlewares.use(m({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,base:o.config.base,isNonLoopbackBind:r,logger:o.config.logger,projectRoot:e.projectRoot,schemaDirectory:e.schemaDir})),()=>{const t=()=>{const s=S({address:o.httpServer?.address()??void 0,base:o.config.base,resolvedLocal:o.resolvedUrls?.local[0]});o.config.logger.info(n("Lunora",`\x1B[36m${s}\x1B[39m`,a,d));for(const c of p(e,s))o.config.logger.info(c)};if(typeof o.printUrls=="function"){const s=o.printUrls.bind(o);o.printUrls=()=>{s(),t()}}else o.httpServer?.listening===!0?t():o.httpServer?.once("listening",t)}},name:"lunora:studio"});export{D as STUDIO_PATH,S as buildStudioUrl,$ 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{existsSync as we}from"node:fs";import{resolve as h,dirname as Se,sep as $,basename as q,join as Q,relative as ye}from"node:path";import{PROJECT_CONFIG_FILENAMES as U,readServiceBindings as Re,readProjectLazyFunctions as Y,projectConfigCandidatePaths as Z,createCodegenProject as ae,runCodegen as ve,findTsconfig as Ee,isTestPath as ke,fingerprintSchemaSources as z,refreshCodegenProject as je,CodegenDiagnosticError as Ce}from"@lunora/codegen";import{LUNORA_TAG as y,isCodegenDisabled as $e,CODEGEN_ENV as ee,createDiscoveryCache as De,writeApiSpecMarker as be,reportCodegenFindings as Te,blockingFindingsMessage as _e,STRICT_ADVISORIES_ENV as Pe,runPostCodegenHook as te}from"@lunora/config";import{pendingBindingChanges as Ne,WRANGLER_FILES as ne,wranglerCodegenInputs as Fe,reconcileWranglerExtras as Ie,reconcileBindingsSafely as Me}from"@lunora/config/cloudflare";import{consumeStudioWrite as Ae}from"@lunora/config/studio-host";import{isRunnableDevEnvironment as Oe}from"vite";import{c as L,m as We,o as xe}from"./build-session-D75JzvIT.mjs";import Be from"./LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs";import{a as Ge,r as Le}from"./server-close-DWiO4Vxb.mjs";const Ue=2e3,Ve=(e,i)=>{const c=setTimeout(e,i);return()=>{clearTimeout(c)}},He=e=>{const i=e.pending??Ne,c=e.schedule??Ve;let o=new Set,f,a=0;const s=async()=>{if(f=void 0,e.isSuppressed())return;const u=a,d=await i({...e.project,cache:e.cache});if(a!==u||e.isSuppressed())return;const R=d.filter(g=>!o.has(g));o=new Set(d),R.length!==0&&e.warn(`${y} ${d.join(", ")} — not in the running worker yet. Restart the dev server to write ${d.length===1?"it":"them"} to the wrangler config.`)},m=()=>{a+=1,e.cache.clear(),f?.(),f=void 0};return{check:s,dispose:()=>{a+=1,f?.(),f=void 0},invalidate:m,noteSave:()=>{m(),f=c(s,Ue)}}},Je=e=>{const i=U.some(c=>h(e.projectRoot,c)===e.file);return e.flipped&&(!i||!e.baselineSettled)},Ke=100,se=300,re=2,Xe=e=>{let i,c=!1,o,f=0;const a=()=>{i&&(clearTimeout(i),i=void 0)},s=(d,R)=>{o&&clearTimeout(o),o=setTimeout(()=>{if(o=void 0,e.fingerprint()!==d){if(f+=1,f>re){e.logger.warn(`${y} \`postcodegen\` keeps rewriting the schema sources — stopping after ${String(re)} reruns. Make the hook idempotent or move it off the schema directory.`);return}e.logger.info(`${y} schema changed while \`postcodegen\` was running — regenerating`),R()}},se)},m=(d,R)=>{e.regenerate(d,g=>{s(g,()=>{m(d,!0)})},R)},u=(d,R)=>{const g=R||i!==void 0&&c;a(),f=0,c=g,i=setTimeout(()=>{i=void 0,m(d,g)},Ke)};return{cancelPending:a,dispose:()=>{a(),o&&(clearTimeout(o),o=void 0)},onSave:d=>{u(d,!0)},onStudioWrite:d=>{u(d,!1)}}},oe=/[/\\]tsconfig\..+\.json$/u,qe=/\.[cm]?[jt]sx?$/u,Qe=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,Ye=e=>{const i=e.map(o=>` • ${o.kind} "${o.exportName}" — class ${o.className} is not exported by your worker entry.`),c=[...new Set(e.map(o=>o.module))].map(o=>` export * from "./lunora/_generated/${o}";`);return[`[lunora] ${String(e.length)} declared ${e.length===1?"binding is":"bindings are"} not exported by your worker entry — \`wrangler deploy\` will fail.`,...i,"","Add to your worker entry:",...c].join(`
|
|
2
|
+
`)},Ze=(e,i,c)=>{if(i.warn(`${y} schema.ts not found at ${e} — codegen skipped`),c!==void 0){const o=`schema.ts not found at ${e} — generated output is now stale`;c.onError(new Error(o),o)}},O=(e,i,c,o)=>{const f=Q(e.projectRoot,e.schemaDir,"schema.ts");if(!we(f))return Ze(f,i,c),{};try{const a=o??ae(Q(e.projectRoot,e.schemaDir)),s=ve({apiSpec:e.apiSpec,lazyFunctions:e.lazyFunctions,lunoraDirectory:e.schemaDir,project:a,projectRoot:e.projectRoot,target:e.target,...Fe(e.projectRoot)});Ie(e.projectRoot,s.cronTriggers,i);let m;try{be(e.projectRoot,e.apiSpec)}catch(u){m=`${y} could not write the API spec marker: ${u instanceof Error?u.message:String(u)}`,i.error(m)}return Te(s,i),{blockingMessage:_e(s,{strictAdvisories:process.env[Pe]!=="0"}),markerFailure:m,outputDirectory:h(s.outputDirectory),project:a}}catch(a){const s=a instanceof Error?a.message:String(a);return i.error(`${y} codegen failed: ${s}`),c?.onError(a,s),{failure:`${y} codegen failed: ${s}`}}},ze=(e,i,c)=>{let o;for(const[f,a]of Object.entries(e.environments)){if(f==="client"){o=a;continue}Oe(a)||a.hot.send({path:"*",triggeredBy:i,type:"full-reload"})}if(o===void 0){e.hot.send({type:"full-reload"});return}if(c){o.hot.send({type:"full-reload"});return}o.hot.send({event:Be,type:"custom"})},F={error:e=>{console.error(e)},info:e=>{console.info(e)},warn:e=>{console.warn(e)}},ce=new WeakMap,ie=async(e,i,c)=>{const o=ce.get(e)??new Map;return ce.set(e,o),o.has(i)||o.set(i,c()),o.get(i)},lt=(e,i)=>{const c=h(e.projectRoot,e.schemaDir),o=e.cloudflare===!1?void 0:e.cloudflare.configPath,f=typeof o=="string"&&o!==""&&!ne.some(n=>h(e.projectRoot,n)===h(e.projectRoot,o)),a=$e(process.env[ee]);let s=h(e.projectRoot,e.generatedDir),m=0,u=!1,d;const R=new Map;let g,I=!1,_=!1,W=!1,V,v,P;const x=new Set,de=n=>{const p=x.has(n)?void 0:P;return x.add(n),v!=="build"&&(P=void 0),p},le=async()=>{u=!0;let n;try{n=await te({cwd:e.projectRoot,logger:F})}finally{u=!1}return n.ran&&(m=Date.now(),i?.clear()),n.error},fe=async()=>{P=await xe(e,"codegen",()=>{const{blockingMessage:n,failure:p,markerFailure:E,outputDirectory:k}=O(e,F);return{blockingMessage:n,failure:p,markerFailure:E,outputDirectory:k}})};return{config(n,p){v=p.command},configResolved(){if(x.clear(),v==="build")return fe();a||(P=O(e,F))},async buildStart(){const n=v!=="build"&&a,p=de(v==="build"?this.environment.name:"")??(n?{}:O(e,F)),{blockingMessage:E,failure:k,markerFailure:M,outputDirectory:j}=p;v==="build"&&We(e),v==="build"&&k!==void 0&&this.error(k),v==="build"&&M!==void 0&&this.error(M),s=j??s;const C=j===void 0?void 0:await ie(p,"postcodegen",le);v==="build"&&C!==void 0&&this.error(C),v==="build"&&E!==void 0&&this.error(E),await ie(p,"reconcile",async()=>Me({...e,cache:i},F,w=>{d?.hot.send({err:{loc:void 0,message:Ye(w),stack:""},type:"error"})})),i?.clear(),d!==void 0&&(g=L(e.projectRoot),I=!0)},configureServer(n){d=n,n.watcher.add(c);const p=Re(e.projectRoot).services.filter(t=>t.rpcEntrypoint!==void 0).map(t=>Se(t.wranglerPath));n.watcher.add(p),g=L(e.projectRoot),I=!1;const E={error:t=>{n.config.logger.error(t)},info:t=>{n.config.logger.info(t)},warn:t=>{n.config.logger.warn(t)}};let k=!1;const M={onError(t,r){k=!0;const l=t instanceof Ce?{column:t.column,file:t.file,line:t.line}:void 0,S=l===void 0?`[lunora] codegen failed: ${r}
|
|
3
|
+
(see terminal for full stack trace and file location)`:`[lunora] codegen failed: ${r}`;d?.hot.send({err:{loc:l,message:S,stack:t instanceof Error?t.stack??"":""},type:"error"})}},j=(t,r)=>t===r||t.startsWith(r+$);let C=!1,w=P?.project;const ue=()=>{for(const t of Object.values(n.environments)){const r=t.moduleGraph;for(const l of r.idToModuleMap.values())l.id&&j(l.id,s)&&r.invalidateModule(l)}},ge=()=>{w===void 0?w=ae(c):je(w,c);const{outputDirectory:t}=O(e,E,M,w);return t===void 0?(w=void 0,!1):(s=t,!0)},N=He({cache:i??De(),isSuppressed:()=>(_&&(W=!0),_||C||f),project:e,warn:E.warn});V=N.noteSave;const he=async(t,r,l)=>{try{if(C||l&&!ge())return;const S=z(c);u=!0;let G;try{G=await te({cwd:e.projectRoot,logger:E})}finally{u=!1}if(G.ran&&(m=Date.now(),r(S)),G.error!==void 0)return;ue(),ze(n,t,k),k=!1,N.noteSave()}catch(S){E.error(`${y} codegen watch: ${S instanceof Error?S.message:String(S)}`)}};let H=Y(c);const A=Xe({fingerprint:()=>z(c),logger:E,regenerate:(t,r,l)=>{he(t,r,l)}}),me=t=>{if(oe.test(t))return w=void 0,!1;if(U.includes(q(t))&&Z(c).includes(t)){w=void 0;const r=Y(c),l=r!==H;return H=r,Je({baselineSettled:I,file:t,flipped:l,projectRoot:e.projectRoot})}return t.endsWith(`${$}tsconfig.json`)&&t===Ee(c)?(w=void 0,!1):!(!j(t,c)||j(t,s)||!t.endsWith(".ts")||ke(ye(c,t).split($).join("/")))},D=t=>{const r=h(t);if(!(!(Qe.test(r)&&!r.includes(`${$}node_modules${$}`)&&p.some(S=>j(r,S)))&&!me(r))){if(u||Date.now()-m<se){A.cancelPending();return}if(Ae(r)){A.onStudioWrite(r);return}N.invalidate(),A.onSave(r)}},J=h(e.projectRoot,"src"),B=(t,r)=>t.startsWith(`${r}${$}`),b=t=>{const r=h(t);if(!qe.test(r)||B(r,s))return;const l=!a&&r.endsWith(".ts");(B(r,J)||!l&&B(r,c))&&N.noteSave()},K=t=>{const r=h(t);(r.endsWith(`${$}tsconfig.json`)||oe.test(r))&&(w=void 0)};a?n.config.logger.info(`${y} codegen watch disabled (${ee}) — _generated/ is written only by an explicit \`lunora codegen\``):(n.watcher.on("add",D),n.watcher.on("change",D),n.watcher.on("unlink",D),n.watcher.on("unlink",K)),n.watcher.add(J),n.watcher.on("add",b),n.watcher.on("change",b),n.watcher.on("unlink",b);const X=new Set([...ne.map(t=>h(e.projectRoot,t)),...U.map(t=>h(e.projectRoot,t)),...Z(c)]);for(const t of X)n.watcher.add(t);const T=t=>{if(!X.has(h(t))||_)return;const r=L(e.projectRoot);if(!I){g=r;return}if(g===void 0){g=r;return}r!==g&&(g=r,_=!0,n.config.logger.info(`${y} ${q(h(t))} changed — restarting dev server`),Promise.resolve(n.restart()).finally(()=>{_=!1,W&&(W=!1,V?.())}).catch(l=>{const S=l instanceof Error?l.message:String(l);n.config.logger.error(`${y} dev server restart failed: ${S} — keeping the running server; re-save your config to retry.`),n.hot.send({err:{loc:void 0,message:`[lunora] dev server restart failed: ${S}`,stack:""},type:"error"})}))};n.watcher.on("add",T),n.watcher.on("change",T),n.watcher.on("unlink",T);const pe=()=>{C||(C=!0,w=void 0,A.dispose(),N.dispose(),a||(n.watcher.off("add",D),n.watcher.off("change",D),n.watcher.off("unlink",D),n.watcher.off("unlink",K)),n.watcher.off("add",b),n.watcher.off("change",b),n.watcher.off("unlink",b),n.watcher.off("add",T),n.watcher.off("change",T),n.watcher.off("unlink",T))};return()=>{Le(n,R,pe)}},buildEnd(){Ge(R,this.environment)},name:"lunora:codegen"}};export{lt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{discoverContainerInfo as m,streamContainerLogs as u}from"@lunora/config";import{lunoraLine as s}from"@lunora/config/cli";const p=(r,i)=>{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=m(r.projectRoot,r.schemaDir,i).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 l=s(`container:${e.name} ${e.text}`);e.level==="error"?o.warn(l):o.info(l)},onUnavailable:e=>{o.warn(s(`container: Docker engine unreachable — container logs unavailable (${e})`))}}),t.httpServer?.once("close",a)},name:"lunora:container-logs"}};export{p 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{existsSync as h}from"node:fs";import{resolve as l}from"node:path";import{ENV_FILENAME as g,ensureDevVariables as m,createConfirm as w,fillDevSecrets as R,ensureDevWorkerEnv as E,lunoraLine as f,secretSourcesFromBindings as D,inferLunoraBindings as j,checkDevEnv as p,detectFramework as S,describeDevEnvCheck as k}from"@lunora/config";const C=async(e,n,o)=>{try{return D(await j({projectRoot:e,schemaDir:n}))}catch(r){o(`could not read the project's bindings, so every dev secret is generated: ${r instanceof Error?r.message:String(r)}`);return}},y="wrangler.dev.jsonc",b=new Set(["nuxt","sveltekit"]),P=(e,n)=>{const o=l(e.projectRoot,y),r={projectRoot:e.projectRoot,schemaDirectory:e.schemaDir};return b.has(S(e.projectRoot).framework)&&h(o)?{...r,configPath:o,vars:{WORKER_ENV:"development"}}:{...r,configPath:n.configPath,withheld:n.withheld}},u=new Map,_=(e,n,o,r)=>{const a=k(e,n,{wasInvalid:r});return a!==void 0&&o[a.level](f(a.message)),e.kind==="invalid"||e.kind==="unloadable"&&r},V=(e,{configPath:n,withheld:o=()=>[]}={})=>{let r=!1,a=u.get(e.projectRoot)??!1,d=0;const v=async t=>{d+=1;const c=d,i=await p(P(e,{configPath:n,withheld:o()}));c===d&&(a=_(i,e.schemaDir,t,a),u.set(e.projectRoot,a))};return{apply:"serve",config(t,c){r=c.isPreview===!0},async configResolved(){if(r)return;const t=s=>{console.info(f(s))},c=s=>{console.warn(f(s))};if((await m({confirm:w("[lunora] "),cwd:e.projectRoot,info:t,warn:c})).status!=="unreadable"){const s=await C(e.projectRoot,e.schemaDir,t);R({cwd:e.projectRoot,info:t,secretSources:s}),E(e.projectRoot,t)}await v(console)},configureServer(t){if(r)return;const c=l(e.projectRoot,e.schemaDir,g),i=s=>{l(s)===c&&v(t.config.logger)};t.watcher.add(c),t.watcher.on("add",i),t.watcher.on("change",i),t.watcher.on("unlink",i)},enforce:"pre",name:"lunora:dev-vars"}};export{V 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 m,lunoraLine as o}from"@lunora/config";import{resolveRemoteEnabled as b,materializeDevWranglerConfig as P,toRemotePlan as v,describeWithheld as p}from"@lunora/config/cloudflare";const g=()=>{},R=e=>{const i=e.readPreference??m;if(!b({configPreference:i(e.projectRoot),envValue:e.remoteEnv??process.env.LUNORA_REMOTE}))return{bindings:[],cleanup:g,enabled:!1,withheld:[]};const n=e.materialize??P;return v(n({projectRoot:e.projectRoot,remote:!0}),!0)},j=(e,i)=>!i.enabled||i.configPath===void 0||typeof e.configPath=="string"?e:{...e,configPath:i.configPath},w=e=>{if(!e.enabled||e.configPath===void 0)return;const i=e.bindings.length>0?` (${e.bindings.join(", ")})`:"";console.info(o(`remote bindings${i} are materialized at ${e.configPath} — this project adds @cloudflare/vite-plugin itself (\`cloudflare: false\`), so pass that path as its \`configPath\` to use them.`))},B=(e,i,r)=>{let n={bindings:[],cleanup:g,enabled:!1,withheld:[]},c;const d=()=>{n.cleanup()};return{buildEnd:d,closeBundle:d,config(E,h){if(h.command!=="serve")return;n.cleanup(),n=R(i);const s=f=>{r?.(f?n:{...n,withheld:[]});for(const u of f?n.withheld:[])console.warn(o(p(u)))};if(e===void 0){s(!0),w(n);return}const t=e;c!==void 0&&t.configPath===c&&delete t.configPath;const a=j(e,n),l=a.configPath!==void 0&&t.configPath===void 0;s(l),l?(t.configPath=a.configPath,c=a.configPath,n.bindings.length>0&&console.info(o(`remote bindings: ${n.bindings.join(", ")} → deployed resources`))):n.enabled&&n.configPath===void 0&&n.reason!==void 0&&console.info(o(`remote bindings requested but not applied: ${n.reason}`))},enforce:"pre",name:"lunora:remote-bindings"}};export{R as planViteRemoteBindings,B as remoteBindingsPlugin,j 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 s}from"node:child_process";import{lunoraLine as c}from"@lunora/config";import{readWranglerJsonc as l,assertWranglerSatisfiesSchema as f,findWranglerFile as d}from"@lunora/config/cloudflare";import{a as u}from"./build-session-D75JzvIT.mjs";const g=r=>r.startsWith("./")||r.startsWith("../")||r.startsWith("/")||r.includes("Dockerfile"),m=()=>{try{return s("docker",["info"],{stdio:"ignore"}).status===0}catch{return!1}},w=(r,t=m)=>{const{parsed:n}=l(r);!(n?.containers??[]).some(e=>typeof e?.image=="string"&&g(e.image))||t()||console.warn(c("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."))},D=(r,t)=>{let n=!1,a=!1;const e=()=>{f({...r,cache:t},o=>{console.warn(o)},"Update your wrangler.jsonc and restart the dev server.");const i=d(r.projectRoot);i!==void 0&&w(i)};return{config(i,o){n=o.isPreview===!0,a=o.command==="build"},configResolved(){if(!n){if(a){u(r,"validate-wrangler",e);return}e()}},enforce:"pre",name:"lunora:wrangler-validator"}};export{w as warnWhenDockerMissing,D 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.430",
|
|
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",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://lunora.sh",
|
|
16
16
|
"bugs": "https://github.com/anolilab/lunora/issues",
|
|
17
|
-
"license": "
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "Daniel Bannert",
|
|
20
20
|
"email": "d.bannert@anolilab.de"
|
|
@@ -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.63.1",
|
|
49
|
+
"@lunora/codegen": "^1.0.0-alpha.404",
|
|
50
|
+
"@lunora/config": "^1.0.0-alpha.470",
|
|
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,118 +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, allowUnauthenticatedShardAccess = 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({${allowUnauthenticatedShardAccess ? "\n allowUnauthenticatedShardAccess: true," : ""}
|
|
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(
|
|
99
|
-
context.framework.framework,
|
|
100
|
-
generatedImportBase,
|
|
101
|
-
hasContainers,
|
|
102
|
-
useUmbrella,
|
|
103
|
-
options.allowUnauthenticatedShardAccess
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
return void 0;
|
|
107
|
-
},
|
|
108
|
-
name: "lunora:framework-compose",
|
|
109
|
-
resolveId(id) {
|
|
110
|
-
if (id === LUNORA_WORKER_VIRTUAL_ID && isWorkerVirtualActive(context)) {
|
|
111
|
-
return RESOLVED_LUNORA_WORKER_ID;
|
|
112
|
-
}
|
|
113
|
-
return void 0;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
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 };
|