@lunora/cli 1.0.0-alpha.416 → 1.0.0-alpha.418
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/handler.mjs +25 -1
- package/dist/packem_chunks/handler10.mjs +1 -1
- package/dist/packem_chunks/handler11.mjs +1 -1
- package/dist/packem_chunks/handler12.mjs +1 -1
- package/dist/packem_chunks/handler13.mjs +1 -3
- package/dist/packem_chunks/handler14.mjs +3 -1
- package/dist/packem_chunks/handler15.mjs +1 -1
- package/dist/packem_chunks/handler16.mjs +1 -1
- package/dist/packem_chunks/handler17.mjs +1 -7
- package/dist/packem_chunks/handler18.mjs +7 -1
- package/dist/packem_chunks/handler19.mjs +2 -1
- package/dist/packem_chunks/handler2.mjs +1 -1
- package/dist/packem_chunks/handler20.mjs +1 -3
- package/dist/packem_chunks/handler21.mjs +3 -3
- package/dist/packem_chunks/handler22.mjs +3 -1
- package/dist/packem_chunks/handler23.mjs +1 -2
- package/dist/packem_chunks/handler24.mjs +2 -99
- package/dist/packem_chunks/handler25.mjs +99 -2
- package/dist/packem_chunks/handler26.mjs +2 -9
- package/dist/packem_chunks/handler27.mjs +9 -1
- package/dist/packem_chunks/handler28.mjs +1 -0
- package/dist/packem_chunks/handler3.mjs +1 -1
- package/dist/packem_chunks/handler4.mjs +1 -3
- package/dist/packem_chunks/handler5.mjs +3 -1
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/handler8.mjs +1 -2
- package/dist/packem_chunks/handler9.mjs +2 -1
- package/dist/packem_chunks/runDevCommand.mjs +1 -1
- package/dist/packem_chunks/runInitCommand.mjs +16 -16
- package/dist/packem_shared/{COMMANDS-Bl9QXbmy.mjs → COMMANDS-BCSDC-pv.mjs} +1 -1
- package/dist/packem_shared/cli-BbgDNGew.mjs +2 -0
- package/dist/packem_shared/runDeployCommand-D40F3PLQ.mjs +1 -0
- package/package.json +9 -9
- package/skills/lunora-quickstart/SKILL.md +0 -1
- package/dist/packem_chunks/runDeployCommand.mjs +0 -25
- package/dist/packem_shared/cli-DP6QFela.mjs +0 -2
package/dist/bin.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{r as e}from"./packem_shared/cli-
|
|
2
|
+
import{r as e}from"./packem_shared/cli-BbgDNGew.mjs";try{const r=await e();process.exit(r)}catch(r){process.stderr.write(`${r instanceof Error?r.message:String(r)}
|
|
3
3
|
`),process.exit(1)}
|
package/dist/index.d.mts
CHANGED
|
@@ -573,6 +573,8 @@ interface DeployCommandOptions {
|
|
|
573
573
|
allowSchemaDrift?: boolean;
|
|
574
574
|
/** Which API spec(s) codegen emits. Defaults to codegen's `"openapi"` when omitted. */
|
|
575
575
|
apiSpec?: ApiSpec;
|
|
576
|
+
/** The Vite metafile path this run's client build keeps for `lunora build`'s copy; unset, the build's metafile is discarded. */
|
|
577
|
+
bundleMetaPath?: string;
|
|
576
578
|
/**
|
|
577
579
|
* The `--env` this run's client build was given as `CLOUDFLARE_ENV`. Set only when a client build ran, so the generated config
|
|
578
580
|
* it wrote is for that environment; without it the environment's Hyperdrive id is not written into that config.
|
|
@@ -1407,7 +1409,7 @@ interface LintToolOfferDeps {
|
|
|
1407
1409
|
defaults?: ReadonlyArray<LintTool>;
|
|
1408
1410
|
}) => Promise<LintTool[]>;
|
|
1409
1411
|
}
|
|
1410
|
-
type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "
|
|
1412
|
+
type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "rspack-react" | "solid-v2" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-react-rspack" | "tanstack-start-solid" | "vinext" | "vinext-pages";
|
|
1411
1413
|
interface InitCommandOptions {
|
|
1412
1414
|
/**
|
|
1413
1415
|
* Add features non-interactively after scaffolding (the `--add` flag): a
|
package/dist/index.d.ts
CHANGED
|
@@ -573,6 +573,8 @@ interface DeployCommandOptions {
|
|
|
573
573
|
allowSchemaDrift?: boolean;
|
|
574
574
|
/** Which API spec(s) codegen emits. Defaults to codegen's `"openapi"` when omitted. */
|
|
575
575
|
apiSpec?: ApiSpec;
|
|
576
|
+
/** The Vite metafile path this run's client build keeps for `lunora build`'s copy; unset, the build's metafile is discarded. */
|
|
577
|
+
bundleMetaPath?: string;
|
|
576
578
|
/**
|
|
577
579
|
* The `--env` this run's client build was given as `CLOUDFLARE_ENV`. Set only when a client build ran, so the generated config
|
|
578
580
|
* it wrote is for that environment; without it the environment's Hyperdrive id is not written into that config.
|
|
@@ -1407,7 +1409,7 @@ interface LintToolOfferDeps {
|
|
|
1407
1409
|
defaults?: ReadonlyArray<LintTool>;
|
|
1408
1410
|
}) => Promise<LintTool[]>;
|
|
1409
1411
|
}
|
|
1410
|
-
type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "
|
|
1412
|
+
type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "rspack-react" | "solid-v2" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-react-rspack" | "tanstack-start-solid" | "vinext" | "vinext-pages";
|
|
1411
1413
|
interface InitCommandOptions {
|
|
1412
1414
|
/**
|
|
1413
1415
|
* Add features non-interactively after scaffolding (the `--add` flag): a
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as o,V as a,r as n}from"./packem_shared/cli-
|
|
1
|
+
import{C as o,V as a,r as n}from"./packem_shared/cli-BbgDNGew.mjs";import{runCodegenCommand as m}from"./packem_chunks/runCodegenCommand.mjs";import{r as p}from"./packem_chunks/handler.mjs";import{runDevCommand as f}from"./packem_chunks/runDevCommand.mjs";import{p as i}from"./packem_shared/plan-DFY3CqHD.mjs";import{runInitCommand as l}from"./packem_chunks/runInitCommand.mjs";import{runMigrateGenerateCommand as I}from"./packem_shared/runMigrateGenerateCommand-BwemPIOz.mjs";import{runResetCommand as g}from"./packem_chunks/runResetCommand.mjs";import{runRpcCommand as T}from"./packem_chunks/runRpcCommand.mjs";import{EXIT_CODE as S,exitCodeForCode as A,exitCodeForError as c,exitCodeForStatus as M}from"./packem_shared/EXIT_CODE-D_XCixv8.mjs";import{insertSchemaExtension as v}from"./packem_shared/insertSchemaExtension-DuiV6cba.mjs";import{createLogger as b,pail as O}from"./packem_shared/createLogger-4TujevyB.mjs";import{diffSnapshots as y,renderAddColumn as L,renderCreateIndex as w,renderCreateTable as B,renderDropIndex as P,renderDropTable as U,renderMigrationFile as V,validatorKindToSqlType as W}from"./packem_shared/diffSnapshots-htqNZT8Q.mjs";import{default as N}from"./packem_shared/schemaIrToSnapshot-BHuNOfgs.mjs";import{createRecordingSpawner as j,defaultSpawner as q}from"./packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{default as K}from"./packem_shared/parseManifest-CwPTKdtS.mjs";import{D as Y,r as Z}from"./packem_shared/import-BRM1hs7j.mjs";import{REQUIRED_COMPATIBILITY_DATE as z,REQUIRED_FLAG as J,validateWranglerProject as $,validateWranglerConfig as rr}from"@lunora/config/cloudflare";import{b as or}from"./packem_shared/catalog-CahzmDLV.mjs";import{r as nr,a as tr,b as mr}from"./packem_shared/commands-DvSfLvyt.mjs";import{runExportCommand as pr}from"./packem_shared/runExportCommand-slAq5BCF.mjs";export{o as COMMANDS,Y as DEFAULT_IMPORT_BATCH_SIZE,S as EXIT_CODE,z as REQUIRED_COMPATIBILITY_DATE,J as REQUIRED_FLAG,a as VERSION,or as buildRegistryIndex,b as createLogger,j as createRecordingSpawner,q as defaultSpawner,y as diffSnapshots,A as exitCodeForCode,c as exitCodeForError,M as exitCodeForStatus,v as insertSchemaExtension,O as pail,K as parseManifest,i as planDevCommand,L as renderAddColumn,w as renderCreateIndex,B as renderCreateTable,P as renderDropIndex,U as renderDropTable,V as renderMigrationFile,nr as runAddCommand,tr as runBuildIndexCommand,n as runCli,m as runCodegenCommand,p as runDeployCommand,f as runDevCommand,pr as runExportCommand,Z as runImportCommand,l as runInitCommand,I as runMigrateGenerateCommand,mr as runRegistryViewCommand,g as runResetCommand,T as runRpcCommand,N as schemaIrToSnapshot,$ as validateWrangler,rr as validateWranglerConfig,W as validatorKindToSqlType};
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import{existsSync as b}from"node:fs";import{
|
|
1
|
+
import{mkdirSync as xe,writeFileSync as C,existsSync as b,readFileSync as E,rmSync as W,mkdtempSync as wr,readdirSync as Me,realpathSync as kr,statSync as Fe}from"node:fs";import{dirname as F,join as S,resolve as j,relative as Z,extname as br,sep as se}from"node:path";import{PROJECT_CONFIG_FILENAMES as Sr,isTestPath as ae,discoverMigrations as $r,readServiceBindings as ue,runCodegen as Er}from"@lunora/codegen";import{readLinkedProject as Ue,resolveSchemaDirectory as L,startDevProcess as Ar,acceptsConnection as Tr,resolveTargetOrThrow as ie,detectFramework as Rr,DEFAULT_BUNDLE_META_PATH as Dr,STRICT_ADVISORIES_ENV as _r,LAZY_FUNCTIONS_ENV as Pr,BUNDLE_META_PATH_ENV as Nr,BUILD_TARGET_ENV as Ir,BUILD_ROOT_ENV as Or,canonicalPath as Cr,COMPOSED_WORKER_ENTRY as Se,discoverContainerInfo as Be,writeLinkedProject as jr,discoverSchemaInfo as He,DEV_VARS_FILE as N,parseDevVariableEntries as Ge,isMintableSecretKey as $e,secretSourcesFromBindings as Lr,inferLunoraBindings as qe,requiredSecrets as xr,generateSecretValue as Mr,upsertDevVariableLine as Fr,writeDevVariablesFileAtomically as Ur,resolveLazyFunctions as K,resolveDeployDriver as J,MissingBuildOutputError as Br,clearApiSpecMarker as Hr,createDiscoveryCache as Gr,planToolchainInvocation as Ve,runPostCodegenHook as qr,readApiSpecMarker as Vr}from"@lunora/config";import{bindingsNeedingDatabase as Wr,findWranglerFile as x,readWranglerJsonc as P,mergeWranglerEnvironment as Y,applyModify as We,HYPERDRIVE_PLACEHOLDER_ID as zr,warnCloudflareCliConfigOnce as Kr,validateWranglerProject as Jr,wranglerCodegenInputs as Yr,reconcileWranglerBindings as Xr,reconcileWranglerCompatibilityDate as Qr,reconcileWranglerCrons as Zr,describePreservedCrons as et}from"@lunora/config/cloudflare";import{Spinner as rt}from"@visulima/spinner";import{r as ge,a as tt,e as nt}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as ot}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{m as st,e as at,i as it,b as ct,a as dt}from"../packem_shared/secret-key-8DPOH98z.mjs";import{w as lt}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{d as ut}from"../packem_shared/command-CB4JM-Jl.mjs";import{r as fe}from"../packem_shared/wrangler-name-Dsk5K1f-.mjs";import{a as gt}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as p}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{spawn as ft}from"node:child_process";import{randomUUID as ze,createHash as mt}from"node:crypto";import{setTimeout as ht}from"node:timers/promises";import{toolchainExecArgs as U,detectPackageManager as I,execArgsFor as me}from"@lunora/config/cli";import{f as vt}from"../packem_shared/free-port-DjbFhaaT.mjs";import{containerBuildTag as pt}from"@lunora/container";import{a as yt,i as wt}from"../packem_shared/docker-DpVxvYpL.mjs";import{defaultSpawner as M}from"../packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{r as Ke}from"../packem_shared/resolve-target-C_ZloTvd.mjs";import{p as kt,H as bt,a as St,r as $t}from"../packem_shared/health-probe-Bw9JFfIy.mjs";import{runAdvisor as Et,openShardAccess as Ee}from"@lunora/advisor";import{join as k,relative as B,dirname as Je}from"@visulima/path";import{Project as Ye,SyntaxKind as v,Node as y}from"ts-morph";import{r as At,c as Tt}from"../packem_shared/cloudflare-credentials-BVmZnDZk.mjs";import{runMigrateDataCommand as Rt}from"../packem_shared/runMigrateGenerateCommand-BwemPIOz.mjs";import{c as Dt}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{l as _t}from"../packem_shared/wrangler-secrets-CTQPpalP.mjs";const Pt=Object.freeze({edges:[],nodes:[],modules:[],unresolved:[],version:1}),Nt=20,Ae=e=>`${e.from} -${e.kind}-> ${e.to}`,q=(e,r)=>{const n=new Set(e);return r.filter(t=>!n.has(t)).toSorted((t,o)=>t.localeCompare(o))},It=(e,r)=>{const n=e.modules.map(a=>a.name),t=r.modules.map(a=>a.name),o=e.edges.map(a=>Ae(a)),s=r.edges.map(a=>Ae(a));return{addedEdges:q(o,s),addedModules:q(n,t),removedEdges:q(s,o),removedModules:q(t,n)}},V=(e,r,n)=>{if(n.length===0)return[];const t=n.slice(0,Nt).map(s=>` ${e} ${s}`),o=n.length-t.length;return[`${r}:`,...t,...o>0?[` … and ${o.toString()} more`]:[]]},Ot=e=>{const r=[...V("+","modules added",e.addedModules),...V("-","modules removed",e.removedModules),...V("+","edges added",e.addedEdges),...V("-","edges removed",e.removedEdges)];return r.length===0?void 0:`architecture changes since the last deploy:
|
|
2
|
+
${r.join(`
|
|
3
|
+
`)}`},Ct=(e,r)=>S(e,".lunora",r===void 0?"architecture.json":`architecture.${r}.json`),jt=e=>{if(b(e))try{const r=JSON.parse(E(e,"utf8"));return r.version===1&&Array.isArray(r.modules)&&Array.isArray(r.edges)?r:void 0}catch{return}},Lt=e=>{const{cwd:r,environment:n,logger:t}=e,o=Ct(r,n),s=jt(o),a=e.current??(s===void 0?void 0:Pt);if(a===void 0)return;const i=s===void 0?void 0:Ot(It(s,a));return i!==void 0&&t.info(i),()=>{try{xe(F(o),{recursive:!0}),C(o,`${JSON.stringify(a,void 0,2)}
|
|
4
|
+
`,"utf8")}catch(c){t.warn(`could not record the deployed architecture at ${o}: ${c instanceof Error?c.message:String(c)}`)}}},xt=e=>{const{cwd:r,env:n,logger:t,mintedSecretsFile:o}=e;try{const s=Ue(r),a=s?.workerName??fe(r),i=e.url??s?.workerUrl;t.success("deploy complete"),t.info(` worker: ${a??"(see wrangler output above)"}`),n!==void 0&&t.info(` env: ${n}`),i===void 0?t.info(" url: run `lunora link --url <https://your-worker>` to record it"):t.info(` url: ${i}`),o!==void 0&&t.info(` secrets: generated value(s) recorded in ${o}`),e.logsAvailable&&t.info(" logs: lunora logs")}catch{}},Mt=/\/index$/u,Ft=/[^\dA-Za-z]/gu,Ut=e=>e.replace(Mt,"").split("/").map(r=>r.replaceAll(Ft,"_")),Bt=e=>Ut(e).join("_"),Ht=18787,Te=3,Xe=12e4,Gt=5e3,ee=10,qt=new Set([".js",".mjs",".mts",".ts",".tsx"]),Vt=/\(void 0\)|is not a function|before initialization|of undefined/u,Wt=e=>typeof e=="object"&&e!==null&&typeof e.functionPath=="string"&&typeof e.message=="string",zt=e=>{const r=L(e),n=new Map;let t;try{t=Me(S(e,r),{recursive:!0,encoding:"utf8"})}catch{return n}for(const o of t){const s=br(o);qt.has(s)&&!o.split(se).some(a=>a==="_generated"||a==="node_modules")&&n.set(Bt(o.slice(0,-s.length).split(se).join("/")),S(r,o))}return n},Kt=(e,r)=>{const n=zt(e),t=new Map;for(const{functionPath:o,message:s}of r){const a=o.lastIndexOf(":"),i=o.slice(0,a),c=`${i}\0${s}`,l=t.get(c)??{exports:[],message:s,namespace:i};l.exports.push(o.slice(a+1)),t.set(c,l)}return[...t.values()].map(({exports:o,message:s,namespace:a})=>{const i=Vt.test(s)?`
|
|
5
|
+
hint: if this module is part of a circular import, an import it reads is still undefined while it evaluates`:"";return` ${n.get(a)??a} (${o.join(", ")}): ${s}${i}`})};class D extends Error{skipped;constructor(r,n=!1){super(r),this.skipped=n}}const Jt=(e,r)=>{const n=x(e),t=n===void 0?void 0:P(n).parsed;if(t===void 0)return{hasContainers:!1,main:void 0};const{merged:o}=Y(t,r);return{hasContainers:(o.containers??[]).length>0,main:o.main}},Yt=({composedEntry:e,configPath:r,cwd:n,environment:t,toolchain:o})=>{if(o.devServer!=="workerd")return{skip:"this deploy target does not run on workerd"};const{hasContainers:s,main:a}=Jt(n,t),i=e??a;if(typeof i!="string"||i.startsWith("virtual:")||!b(j(n,i)))return{skip:"the Worker entry is not a file on disk"};if(s)return{skip:"the project declares containers, which `wrangler dev` would build locally before the real container build"};const c=Wr(n,process.env,t,r);return c.length===0?{main:i}:{skip:`the Hyperdrive binding ${c.join(", ")} has no local database for wrangler dev`}},Xt=async(e,r,n)=>{const t=await fetch(`http://127.0.0.1:${String(e)}/_lunora/__smoke_load`,{signal:AbortSignal.timeout(Math.max(0,n-Date.now()))}).catch(u=>{throw u instanceof Error&&u.name==="TimeoutError"?new D(`the smoke Worker booted but did not finish evaluating the lazy modules within ${String(Xe/1e3)}s — a module may be awaiting something that never settles. Pass --no-smoke-load to ship anyway.`):u});if(t.status>=500)throw new D(`the smoke Worker booted but failed while evaluating the lazy modules (HTTP ${String(t.status)}). Pass --no-smoke-load to ship anyway.`);const o=await t.text().catch(()=>"");let s;try{s=JSON.parse(o)}catch{s=void 0}const{checked:a,failures:i,run:c}=s??{};if(typeof a=="number"&&Array.isArray(i)&&i.every(u=>Wt(u)))return c===r?{checked:a,failures:i}:void 0;const l=t.headers.get("content-type")??"no content type",g=o.replaceAll(/\s+/gu," ").trim().slice(0,120);throw new D(`the smoke Worker answered with something other than the probe's result (HTTP ${String(t.status)}, ${l}${g===""?"":`: ${g}`}). A route that does not send /_lunora/* to the Worker first answers with the app's assets, so check run_worker_first. Pass --no-smoke-load to ship anyway.`)},ce=(e,r)=>{try{process.kill(-e,r)}catch{}},Re=e=>{try{return process.kill(-e,0),!0}catch{return!1}},Qt=e=>{const r=()=>{ce(e,"SIGKILL")},n=o=>{r(),process.kill(process.pid,o)},t=()=>{process.removeListener("exit",r),process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n)};return process.once("exit",r),process.once("SIGINT",n),process.once("SIGTERM",n),t},re=async e=>{if(e===void 0)return;e.dispose();const{pid:r}=e;ce(r,"SIGTERM");const n=Date.now()+Gt;for(;Re(r)&&Date.now()<n;)await ht(50);Re(r)&&ce(r,"SIGKILL")},Zt=e=>Ar(e).catch(async r=>{if(!await Tr(e.port))throw r}),en=(e,{checked:r,failures:n},t)=>{if(n.length===0){t.success(`${String(r)} lazy function(s) evaluate cleanly`);return}const o=Kt(e,n),s=o.length>ee?[` …and ${String(o.length-ee)} more module(s)`]:[];throw new D([`${String(n.length)} of ${String(r)} lazy function(s) fail to load:`,...o.slice(0,ee),...s,"Fix the module, or pass --no-smoke-load to ship anyway."].join(`
|
|
6
|
+
`))},rn=(e,r,n)=>{if(e instanceof D&&!e.skipped)return n.error(e.message),e.message;if(e instanceof D){n.warn(`smoke-load skipped: ${e.message}`);return}const t=r.slice(-5).join(`
|
|
7
|
+
`),o=`the smoke Worker did not start (${e instanceof Error?e.message:String(e)})${t===""?"":`
|
|
8
|
+
${t}`}. Either the entry fails when it loads, or local wrangler cannot run the project (a remote-only binding or a missing assets directory). Fix whichever it is, or pass --no-smoke-load to ship anyway.`;return n.error(o),o},tn=e=>{try{return xe(S(e,".lunora"),{recursive:!0}),wr(S(e,".lunora","smoke-"))}catch(r){throw new D(`could not create a directory for the check (${r instanceof Error?r.message:String(r)})`,!0)}},nn=async e=>{const{configPath:r,cwd:n,directory:t,environment:o,functionsFile:s,main:a,preferred:i,toolchain:c}=e;try{const l=S(t,"entry.ts"),g=ze();C(l,`export * from ${JSON.stringify(j(n,a))};
|
|
9
|
+
import { loadAllFunctions } from ${JSON.stringify(s)};
|
|
10
|
+
|
|
11
|
+
const runId = ${JSON.stringify(g)};
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
async fetch() {
|
|
15
|
+
return Response.json({ ...(await loadAllFunctions()), run: runId });
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
`);const u=await vt(i),{args:d,command:f}=U(I(n),c.dev({configPath:r===void 0?void 0:Z(n,r),environment:o,extraArgs:[Z(n,l),"--local","--local-protocol","http","--ip","127.0.0.1","--port",String(u),"--persist-to",Z(n,S(t,"state"))]}));return{args:d,command:f,port:u,runId:g}}catch(l){throw new D(`could not prepare the check (${l instanceof Error?l.message:String(l)})`,!0)}},on=async e=>{const{configPath:r,cwd:n,environment:t,launcher:o,logger:s,toolchain:a}=e,i=S(n,L(n),"_generated","functions.ts");if(!b(i)||!E(i,"utf8").includes("export const loadAllFunctions"))return;const c=Yt(e);if("skip"in c){s.warn(`smoke-load skipped: ${c.skip}, so lazy modules are not evaluated before deploy`);return}const{main:l}=c,g=[];let u,d;const f=Date.now()+Xe,m=process.platform!=="win32",w=(h,A,_)=>{const $=ft(h,[...A],{cwd:_.cwd,detached:m,shell:_.shell,stdio:["ignore","pipe","pipe"]});return m&&$.pid!==void 0&&(d={dispose:Qt($.pid),pid:$.pid}),$};try{u=tn(n),s.info("smoke-loading lazy function modules in workerd");let h=Ht;for(let A=0;A<Te;A+=1){const{args:_,command:$,port:O,runId:T}=await nn({configPath:r,cwd:n,directory:u,environment:t,functionsFile:i,main:l,preferred:h,toolchain:a});h=O+1;const be=await Zt({args:_,command:$,cwd:n,spawn:o??w,label:"wrangler dev (smoke-load)",notFound:"`wrangler` was not found",onLine:G=>{g.push(G)},port:O,readyTimeoutMs:Math.max(0,f-Date.now()),shell:process.platform==="win32"});if(be===void 0){await re(d),d=void 0;continue}try{const G=await Xt(O,T,f);if(G!==void 0){en(n,G,s);return}}finally{await be.stop(),await re(d),d=void 0}}throw new D(`the smoke port was answered by other runs on all ${String(Te)} attempts`,!0)}catch(h){return rn(h,g,s)}finally{if(await re(d),u!==void 0)try{W(u,{force:!0,recursive:!0})}catch{}}},sn=(e,r)=>r===void 0?e:j(e,r),an=async e=>{if(e.targets.length===0)return{builtTags:[],code:0};if(!(e.railpackAvailable??yt)()){const t="deploy blocked: a container uses `image: { build }` (Railpack), but Railpack isn't ready. Install the `railpack` CLI and start a BuildKit instance, e.g. `docker run --rm --privileged -d --name buildkit moby/buildkit` then `export BUILDKIT_HOST=docker-container://buildkit`. Alternatively switch the container's `image` to a Dockerfile path or a pre-built registry reference.";return e.logger.error(t),{builtTags:[],code:1,error:t}}const r=e.spawner??M,n=[];for(const t of e.targets){const o=pt(t.exportName),s={args:["build",t.buildDir,"--name",o],command:"railpack",cwd:e.cwd},a=me(I(e.cwd),"wrangler",["containers","push",o]),i={args:a.args,command:a.command,cwd:e.cwd};e.logger.info(`railpack: building "${t.exportName}" → ${o} from ${t.buildDir}`);const c=await r(s);if(c.code!==0){const g=`railpack build failed for container "${t.exportName}" (${t.buildDir})`;return e.logger.error(g),{builtTags:n,code:c.code,error:g}}e.logger.info(`railpack: pushing ${o} to the Cloudflare Registry`);const l=await r(i);if(l.code!==0){const g=`wrangler containers push failed for "${t.exportName}" (${o})`;return e.logger.error(g),{builtTags:n,code:l.code,error:g}}n.push(o)}return{builtTags:n,code:0}},Qe=e=>{const n=[x(e),S(e,"package.json"),S(e,"wrangler.dev.jsonc")].filter(t=>t!==void 0&&b(t)).map(t=>[t,E(t,"utf8")]);return()=>{for(const[t,o]of n)E(t,"utf8")!==o&&C(t,o,"utf8")}},cn=(e,r=ze())=>j(e,".lunora",`vite-bundle-meta-${r}.json`),Ze="LUNORA_CLIENT_BUILD",dn="virtual:lunora/worker",de=(e,r)=>["ts","mts","cts","js","mjs","cjs"].some(n=>b(S(e,`${r}.config.${n}`))),er=e=>de(e,"rsbuild")?"rsbuild":de(e,"vite")?"vite":void 0,ln=e=>de(e,"vite")?"vite":er(e),un=e=>{try{const{scripts:r}=JSON.parse(E(S(e,"package.json"),"utf8"));return typeof r?.build=="string"&&r.build!==""}catch{return!1}},X=(e,r)=>{if(process.env[Ze]==="1")return;const n=x(e),t=n===void 0?void 0:P(n).parsed,o=t?.main===dn,s=(o?ln(e):er(e))??(un(e)?"script":void 0);if(s===void 0)return;const a=r===void 0?void 0:t?.env?.[r]?.assets?.directory,i=t?.assets?.directory??a;return o||Rr(e).class!=="C"||i!==void 0?s:void 0},gn=async(e,r,n)=>{const t=n.spawner??M,o=I(e),s=r==="script"?{args:["run","build"],command:o}:me(o,r,["build"]);n.logger.info(`running ${r} build before bundling the Worker`);const a=Qe(e),i=n.bundleMetaPath??cn(e);W(S(e,Dr),{force:!0});try{const c=await t({args:s.args,command:s.command,cwd:e,env:{[Or]:Cr(e),[Ir]:n.target,[Nr]:i,...n.lazyFunctions?{[Pr]:"1"}:{},...n.environment===void 0?{}:{CLOUDFLARE_ENV:n.environment},...n.strictAdvisories===!1?{[_r]:"0"}:{},[Ze]:"1"},stdoutToStderr:n.outputJson});return c.code===0?void 0:`${r} build failed with exit code ${String(c.code)}`}finally{a(),n.bundleMetaPath===void 0&&W(i,{force:!0})}},Q=(e,r,n)=>r!==!1&&X(e,n)!==void 0,fn=(e,r,n)=>Q(e,r,n)&&X(e,n)!=="script",he=e=>{const r=e.frameworkBuild===!1?void 0:X(e.cwd,e.environment);if(r===void 0||r==="script")return;if(e.apiSpec!==void 0)return`--api-spec is read from the ${r} plugin config when the client build runs; set it there, or pass --no-framework-build`;if(e.target!==void 0)try{ie(e.cwd,e.target)}catch(t){return t instanceof Error?t.message:String(t)}let n;try{n=ie(e.cwd)}catch(t){return`the project's configured target cannot be used, and the ${r} plugin reads it: ${t instanceof Error?t.message:String(t)}`}if(e.target!==void 0&&e.target!==n)return`this run targets "${e.target}", but the project's target is "${n}", which the ${r} plugin reads; set it in the project config, or pass --no-framework-build`},rr=async e=>{const r=e.frameworkBuild===!1?void 0:X(e.cwd,e.environment);if(r===void 0)return;let n;try{n=e.target??ie(e.cwd)}catch(t){return t instanceof Error?t.message:String(t)}return gn(e.cwd,r,{bundleMetaPath:e.bundleMetaPath,environment:e.environment,strictAdvisories:e.strictAdvisories,lazyFunctions:e.lazyFunctions,logger:e.logger,outputJson:e.outputJson,spawner:e.spawner,target:n})},tr="<replace-with-d1-create-id>",De=e=>Array.isArray(e)?e.filter(r=>r!=null):void 0,ve=(e,r)=>{const n=x(e);if(!n)return;const{parsed:t}=P(n);if(t===void 0)return;const{error:o,merged:s}=Y(t,r),a=o===void 0?s:t,{containers:i,d1_databases:c,vars:l}=a;return{containers:De(i),d1_databases:De(c),vars:typeof l=="object"&&l!==null&&!Array.isArray(l)?l:void 0}},mn=/^127(?:\.\d{1,3}){3}$/,hn=e=>{try{const{hostname:r}=new URL(e);return r==="localhost"||mn.test(r)||r==="::1"||r==="[::1]"}catch{return!1}},vn=e=>e.startsWith("./")||e.startsWith("../")||e.startsWith("/")||e.includes("Dockerfile"),pn=(e,r,n,t="deploy",o)=>{const s=(ve(e,o)?.containers??[]).filter(i=>typeof i?.image=="string"&&vn(i.image));if(s.length===0||n())return;const a=`${t} blocked: wrangler.jsonc declares ${String(s.length)} container(s) built from a local Dockerfile, but no Docker-compatible engine is available. Start Docker (or Colima), or point the container's \`image\` at a pre-built registry reference. Note: container images must target linux/amd64.`;return r.error(a),a},pe=e=>b(k(e,Se))?Se:void 0,yn=(e,r,n="deploy",t)=>{for(const o of Be(e,"lunora",t).containers){const s=o.schedulingPolicy===void 0?o.image:void 0,i=[...s?.kind==="dockerfile"?[{field:"image",path:s.dockerfilePath}]:[],...Object.entries(o.schedulingPolicy==="durable_object"?o.images??{}:{}).flatMap(([c,l])=>l.kind==="dockerfile"?[{field:`images["${c}"]`,path:l.dockerfilePath}]:[])].find(c=>!b(k(e,c.path)));if(i!==void 0){const c=`${n} blocked: container "${o.exportName}" references a Dockerfile at "${i.path}" that does not exist. Create it or fix the \`${i.field}\` path in lunora/containers.ts.`;return r.error(c),c}if(s?.kind==="build"&&!b(k(e,s.buildDir))){const c=`${n} blocked: container "${o.exportName}" references a Railpack build directory "${s.buildDir}" that does not exist. Create it or fix the \`image.build\` path in lunora/containers.ts.`;return r.error(c),c}}},wn=(e,r)=>(ve(e,r)?.d1_databases??[]).find(n=>n.database_id===tr)?.binding,kn=e=>{if(!e.migrate||e.dryRun||e.preview)return;if(e.migrateUrl===void 0){const n="--migrate requires --migrate-url <https://your-worker> — the deploy target URL is only known after wrangler runs, and this gate runs before it; refusing to default to localhost";return e.logger.error(n),n}if(e.migrateYes!==!0){const n="--migrate runs production data migrations after deploy. Re-run with --migrate-yes to confirm.";return e.logger.error(n),n}const r=e.migrateToken??process.env.LUNORA_ADMIN_TOKEN;if(r===void 0||r===""){const n="admin token required for --migrate — pass --migrate-token or set LUNORA_ADMIN_TOKEN";return e.logger.error(n),n}},bn=(e,r,n="deploy",t)=>{const o=wn(e,t);if(o===void 0)return;const s=`${n} blocked: the "${o}" D1 binding has a placeholder database_id ("${tr}"). Run \`wrangler d1 create <name>\` to create the database, then replace the placeholder in wrangler.jsonc with the real id before deploying.`;return r.error(s),s},Sn=(e,r,n="deploy",t)=>{const o=ve(e,t)?.vars;if(!o)return;const s=Object.entries(o).filter(([,i])=>typeof i=="string"&&hn(i)).map(([i])=>i).toSorted((i,c)=>i.localeCompare(c));if(s.length===0)return;const a=`${n} blocked: ${s.join(", ")} in wrangler.jsonc point at localhost. A deployed Worker can't reach a loopback address, so this silently breaks scheduled-job dispatch, reverse cross-shard relations, and auth callbacks. Set each to the deployed worker's public URL (or move it to a secret with \`wrangler secret put\`) before deploying.`;return r.error(a),a},$n=["vite.config.ts","vite.config.mts","vite.config.cts","vite.config.js","vite.config.mjs","vite.config.cjs",...Sr],nr=/\.(?:[cm]?[jt]s|tsx|jsx)$/u,or=/\.(?:test|spec)\.[cm]?[jt]sx?$/u,sr="allowUnauthenticatedShardAccess",En=/[\\/]/u,ar=new Set(["_generated","build","dist","node_modules"]),ir=(e,r)=>{const n=B(e,r).split(En);return nr.test(r)&&!or.test(r)&&!ae(n.join("/"))&&n.every(t=>t===".."||!t.startsWith(".")&&!ar.has(t))},_e=(e,r,n)=>{const{parsed:t}=P(r);if(t===void 0)return[];const{error:o,merged:s}=Y(t,n),{main:a}=o===void 0?s:t,i=typeof a=="string"?k(Je(r),a):void 0;return i!==void 0&&b(i)&&ir(e,i)?[i]:[]},ye=e=>e===void 0?!1:e.getKind()===v.FalseKeyword?!0:y.isParenthesizedExpression(e)||y.isAsExpression(e)||y.isSatisfiesExpression(e)||y.isTypeAssertion(e)||y.isNonNullExpression(e)?ye(e.getExpression()):!1,An=e=>{try{return Fe(e).isFile()}catch{return!1}},Tn=new Set(["ELOOP","ENOENT","ENOTDIR"]),z=(e,r,n)=>{const t=r instanceof Error&&"code"in r&&typeof r.code=="string"?r.code:"";Tn.has(t)||n.push(e)},Rn=(e,r)=>{try{return Fe(e)}catch(n){z(e,n,r);return}},cr=(e,r)=>{try{return E(e,"utf8")}catch(n){z(e,n,r);return}},dr=(e,r,n,t=new Set)=>{let o;try{o=kr(r)}catch(a){return z(r,a,n),[]}if(t.has(o))return[];t.add(o);let s;try{s=Me(r)}catch(a){return z(r,a,n),[]}return s.flatMap(a=>{const i=k(r,a),c=Rn(i,n);if(c===void 0)return[];const l=B(e,i).split(se).join("/");return c.isDirectory()?ar.has(a)||a.startsWith(".")||ae(`${l}/`)?[]:dr(e,i,n,t):c.isFile()&&nr.test(a)&&!or.test(a)&&!ae(l)?[i]:[]})},Dn=e=>{const r=y.isComputedPropertyName(e)?e.getExpression():e;return y.isStringLiteral(r)||y.isNoSubstitutionTemplateLiteral(r)?r.getLiteralValue():e.getText()},te=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"],_n=/\.(?:[cm]?js|jsx)$/u,Pn=(e,r)=>{if(!r.startsWith("."))return;const n=j(Je(e),r),t=n.replace(_n,"");return[n,...te.map(s=>`${n}${s}`),...te.map(s=>k(n,`index${s}`)),...te.map(s=>`${t}${s}`)].find(s=>An(s))},Nn=e=>{if(e.getExpression().getText()!=="require")return;const[r]=e.getArguments();return r!==void 0&&(y.isStringLiteral(r)||y.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},In=e=>{const r=e.getModuleReference();if(!y.isExternalModuleReference(r))return;const n=r.getExpression();return y.isStringLiteral(n)?n.getLiteralValue():void 0},On=(e,r,n,t)=>{const o=new Set(e),s=[...e],a=[];for(let i=0;i<s.length;i+=1){const c=s[i]??"",l=cr(c,t);if(l===void 0)continue;const g=r.createSourceFile(B(n,c),l,{overwrite:!0}),u=[...g.getImportDeclarations().map(d=>d.getModuleSpecifierValue()),...g.getExportDeclarations().map(d=>d.getModuleSpecifierValue()),...g.getDescendantsOfKind(v.ImportEqualsDeclaration).map(d=>In(d)),...g.getDescendantsOfKind(v.CallExpression).map(d=>Nn(d))].filter(d=>d!==void 0);for(const d of u){const f=Pn(c,d);f!==void 0&&ir(n,f)&&!o.has(f)&&(o.add(f),a.push(f),s.push(f))}}return a},Cn=e=>{const r=e.getArgumentExpression();return r!==void 0&&(y.isStringLiteral(r)||y.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},jn=e=>y.isPropertyAccessExpression(e)?e.getName():y.isElementAccessExpression(e)?Cn(e):void 0,Ln=new Set([v.AmpersandAmpersandEqualsToken,v.AmpersandEqualsToken,v.AsteriskAsteriskEqualsToken,v.AsteriskEqualsToken,v.BarBarEqualsToken,v.BarEqualsToken,v.CaretEqualsToken,v.EqualsToken,v.GreaterThanGreaterThanEqualsToken,v.GreaterThanGreaterThanGreaterThanEqualsToken,v.LessThanLessThanEqualsToken,v.MinusEqualsToken,v.PercentEqualsToken,v.PlusEqualsToken,v.QuestionQuestionEqualsToken,v.SlashEqualsToken]),xn=e=>{const r=e.getOperatorToken().getKind();return!Ln.has(r)||jn(e.getLeft())!==sr?!1:r!==v.EqualsToken||!ye(e.getRight())},Mn=(e,r,n)=>{const t=[],o=[...new Set([L(e),"src"])].filter(u=>b(k(e,u))),s=x(e),a=[...$n.map(u=>k(e,u)).filter(u=>b(u)),...s===void 0?[]:_e(e,s,r),...n.flatMap(u=>_e(e,u,r))],i=new Ye({compilerOptions:{allowJs:!0},useInMemoryFileSystem:!0}),c=o.flatMap(u=>dr(k(e,u),k(e,u),t));return{sites:[...new Set([...c,...a,...On([...a,...c],i,e,t)])].flatMap(u=>{const d=cr(u,t);if(d===void 0)return[];const f=i.createSourceFile(B(e,u),d,{overwrite:!0}),m=[...f.getDescendantsOfKind(v.PropertyAssignment),...f.getDescendantsOfKind(v.ShorthandPropertyAssignment),...f.getDescendantsOfKind(v.GetAccessor),...f.getDescendantsOfKind(v.MethodDeclaration)].filter(h=>{const A=y.isPropertyAssignment(h)&&ye(h.getInitializer());return Dn(h.getNameNode())===sr&&!A}).map(h=>h.getStartLineNumber()),w=f.getDescendantsOfKind(v.BinaryExpression).filter(h=>xn(h)).map(h=>h.getStartLineNumber());return[...m,...w].map(h=>({file:B(e,u),line:h}))}),unreadable:t}},Fn=(e,r,n,t,o,s)=>{if(n!=="deploy")return;const{sites:a,unreadable:i}=Mn(e,o,s),c=Et({openShardAccess:a,schema:{tables:[]}},{lints:[Ee]});if(c.length===0&&i.length===0)return;const l=[];if(c.length>0){const u=c.map(d=>`${String(d.metadata.file)}:${String(d.metadata.line)}`).join(", ");l.push(`${u} enable the open-shard option (any value but a literal false), so any caller may target any shard.`)}if(i.length>0&&l.push(`could not read ${i.join(", ")}, so the open-shard option cannot be ruled out there.`),t){r.warn(`deploying past the open-shard gate (--allow-open-shards): ${l.join(" ")}`);return}const g=`deploy blocked (open_shard_access): ${l.join(" ")} ${Ee.remediation}`;return r.error(g),g},Un=(e,r,n,t)=>{const o=Fn(e,r.logger,n,r.allowOpenShards===!0,r.env,t);return o===void 0?void 0:{code:p.USAGE,error:o}},Bn=(e,r,n)=>{const t=bn(e,r.logger,n,r.env);if(t!==void 0)return{code:p.USAGE,error:t};const o=Sn(e,r.logger,n,r.env);if(o!==void 0)return{code:p.USAGE,error:o};const s=yn(e,r.logger,n,r.discoveryCache);if(s!==void 0)return{code:p.USAGE,error:s};const a=pn(e,r.logger,r.dockerAvailable??wt,n,r.env);return a===void 0?void 0:{code:p.MISSING_DEPENDENCY,error:a}},Pe=32,Hn=15e3,Gn=5432,qn=3306,Vn=/[^a-z0-9-]/gu,Wn=/[^A-Za-z0-9]/gu,zn=/-$/u,H=e=>`LUNORA_${e.replaceAll(Wn,"_").toUpperCase()}_URL`,Kn=e=>{const r=new Map;for(const n of e){const t=H(n),o=r.get(t);if(o!==void 0)return{bindings:[o,n],variable:t};r.set(t,n)}},Ne=7,Jn=(e,r)=>{const n=`${e}-${r}`.toLowerCase(),t=n.replaceAll(Vn,"-");if(t===n&&t.length<=Pe)return t;const o=mt("sha256").update(n).digest("hex").slice(0,Ne-1);return`${t.slice(0,Pe-Ne).replace(zn,"")}-${o}`},Ie=e=>e==="postgresql"?"postgres":e==="mariadb"?"mysql":e,Yn=e=>e==="mysql"?qn:Gn,Xn=e=>{try{const r=new URL(e),n=r.protocol.slice(0,-1),t=decodeURIComponent(r.pathname.slice(1));return!["mariadb","mysql","postgres","postgresql"].includes(n)||r.hostname===""||t===""?void 0:{database:t,host:r.hostname,password:decodeURIComponent(r.password),port:r.port===""?Yn(Ie(n)):Number(r.port),scheme:Ie(n),user:decodeURIComponent(r.username)}}catch{return}},Qn=(e,r)=>{const n=typeof r?.password=="string"?r.password:"",t=n===""?[]:[n,JSON.stringify(n).slice(1,-1),encodeURIComponent(n)];let o=e;for(const s of t)o=o.replaceAll(s,"<redacted>");return o.split(" ").map(s=>s.includes("://")?"<url>":s).join(" ")},lr=e=>(Array.isArray(e)?e:[]).flatMap((r,n)=>{const{binding:t,id:o}=typeof r=="object"&&r!==null?r:{};return typeof t=="string"&&o===zr?[{binding:t,index:n}]:[]}),le=e=>{let r="";try{const{errors:n}=JSON.parse(e.text);r=(n??[]).flatMap(t=>typeof t.message=="string"?[t.message]:[]).slice(0,2).join("; ")}catch{}return r===""?`HTTP ${String(e.status)}`:`HTTP ${String(e.status)}: ${r}`},Zn=e=>typeof e=="string"||typeof e=="number"?e.toString():void 0,eo=["scheme","host","port","database","user"],ro=e=>e==="postgresql"?"postgres":e,Oe=(e,r)=>{const n=Zn(r);return e==="scheme"?ro(n):n},Ce=50,to=async(e,r)=>{for(let n=1;n<=Ce;n+=1){const t=await e(n===1?"/hyperdrive/configs":`/hyperdrive/configs?page=${String(n)}`);if(!t.ok)throw new Error(`listing Hyperdrive configs failed (${le(t)})`);if(!Array.isArray(t.body.result))throw new TypeError("the listing of Hyperdrive configs had no result list");const o=t.body.result.find(a=>a.name===r),s=typeof t.body.result_info=="object"&&t.body.result_info!==null?t.body.result_info:{};if(o!==void 0||typeof s.total_pages!="number"||n>=s.total_pages)return o}throw new Error(`the listing of Hyperdrive configs has more than ${String(Ce)} pages, so "${r}" can't be shown to be absent`)},no=async(e,r,n)=>{const t=await to(e,r);if(typeof t?.id=="string"){const a=eo.filter(c=>Oe(c,t.origin?.[c])!==Oe(c,n[c]));if(a.length>0)throw new Error(`a Hyperdrive config named "${r}" already exists for a different origin, or one that can't be confirmed (${a.join(", ")}). Delete it, or rename the Worker, so the binding does not reach the wrong database.`);const i=await e(`/hyperdrive/configs/${encodeURIComponent(t.id)}`,{body:JSON.stringify({origin:n}),method:"PATCH"});if(!i.ok)throw new Error(`updating its credentials failed (${le(i)})`);return{id:t.id,reused:!0}}const o=await e("/hyperdrive/configs",{body:JSON.stringify({name:r,origin:n}),method:"POST"});if(!o.ok)throw new Error(`creating it failed (${le(o)})`);const{id:s}=typeof o.body.result=="object"&&o.body.result!==null?o.body.result:{};if(typeof s!="string")throw new TypeError("the response carried no id");return{id:s,reused:!1}},oo=(e,r,n,t)=>r===void 0&&t?`${H(e)} is set but is not a usable connection string for the "${e}" Hyperdrive binding: it needs a postgres://, postgresql:// or mysql:// scheme, a host and a database name, with any special characters percent-encoded.`:r===void 0?`the "${e}" Hyperdrive binding has no config yet. Set ${H(e)} to its postgres:// or mysql:// connection string and Lunora creates the config, or run \`wrangler hyperdrive create\` and put its id in wrangler.jsonc.`:n?void 0:`creating the "${e}" Hyperdrive config needs CLOUDFLARE_API_TOKEN (Hyperdrive: Edit) and CLOUDFLARE_ACCOUNT_ID, or run \`wrangler hyperdrive create\` and put its id in wrangler.jsonc.`,so=async(e,r)=>{const n=Jn(e.workerName,e.binding),{id:t,reused:o}=await no(async(s,a)=>Tt({accountId:e.accountId,apiToken:e.token,...e.fetch===void 0?{}:{fetch:e.fetch},init:{...a,signal:AbortSignal.timeout(Hn)},path:s}),n,e.origin);return e.logger.success(`${o?"reusing":"created"} Hyperdrive config "${n}" for ${e.binding} → ${e.wranglerPath}`),{id:t,text:We(r,[...e.path,e.index,"id"],t)}},ao=e=>e===void 0||e===""?void 0:e,ur=e=>{const r=S(F(e),".wrangler","deploy","config.json");try{const{configPath:n}=JSON.parse(E(r,"utf8"));return typeof n=="string"?j(F(r),n):void 0}catch{return}},io=(e,r,n,t,o)=>{const s=ur(e);if(s===void 0||s===e)return;if(t.built!==t.deployed){o.warn(`the build output ${s} was made for ${t.built===void 0?"the default environment":`"${t.built}"`}, not ${t.deployed===void 0?"the default environment":`"${t.deployed}"`}, so the "${r}" Hyperdrive id was not written there. Build with CLOUDFLARE_ENV set to the environment you deploy, then deploy again.`);return}let a;try{a=P(s)}catch{return}const i=lr(a.parsed?.hyperdrive).find(c=>c.binding===r);i!==void 0&&C(s,We(a.text,["hyperdrive",i.index,"id"],n),"utf8")},co=(e,r)=>{const n=typeof e.name=="string"&&e.name!==""?e.name:"lunora";if(r===void 0)return n;const t=e.env?.[r]?.name;return typeof t=="string"&&t!==""?t:`${n}-${r}`},we=(e,r)=>{const n=x(e),t=n===void 0?void 0:P(n).parsed;if(n===void 0||t===void 0)return;const o=r===void 0?void 0:t.env?.[r],s=lr(r===void 0?t.hyperdrive:o?.hyperdrive);return s.length===0?void 0:{accountId:o?.account_id??t.account_id,entries:s,path:r===void 0?["hyperdrive"]:["env",r,"hyperdrive"],workerName:co(t,r),wranglerPath:n}},lo=(e,r,n)=>{const t=Kn(e.map(({binding:o})=>o));if(t!==void 0){const o=`deploy blocked: the Hyperdrive bindings ${t.bindings.map(s=>`"${s}"`).join(" and ")} both read ${t.variable} and would share one config. Rename one so their names differ in letters or digits, not only in punctuation.`;return n.logger.error(o),o}for(const{binding:o,origin:s,supplied:a}of e){const i=oo(o,s,r,a);if(i!==void 0&&n.dryRun===!0)n.logger.warn(`dry run: ${i} A real deploy stops here.`);else if(i!==void 0){const c=`deploy blocked: ${i}`;return n.logger.error(c),c}}},uo=async e=>{const r=we(e.cwd,e.wranglerEnvironment);if(r===void 0)return;const{entries:n,path:t,wranglerPath:o}=r,s=e.environment??process.env,{accountId:a,token:i}=At(s,r.accountId),c=n.map(({binding:g})=>{const u=s[H(g)]??"";return{binding:g,origin:Xn(u),supplied:u!==""}}),l=lo(c,i!==void 0&&a!==void 0,e);if(l!==void 0)return l;if(!(e.dryRun===!0||e.checkOnly===!0))for(const[g,{binding:u,index:d}]of n.entries()){const f=c[g]?.origin;if(!(f===void 0||i===void 0||a===void 0))try{const{id:m,text:w}=await so({accountId:a,binding:u,fetch:e.fetch,index:d,logger:e.logger,origin:f,path:t,token:i,workerName:r.workerName,wranglerPath:o},E(o,"utf8"));C(o,w,"utf8"),io(o,u,m,{built:ao(s.CLOUDFLARE_ENV),deployed:e.wranglerEnvironment},e.logger)}catch(m){const w=m instanceof Error?m.message:String(m),h=`deploy blocked: the "${u}" Hyperdrive config could not be set up: ${Qn(w,c[g]?.origin)}`;return e.logger.error(h),h}}},go=(e,r)=>{const n=we(e,r.env)?.entries[0]?.binding;if(n===void 0)return;const t=`prepare blocked: the "${n}" Hyperdrive binding still has its placeholder id. Run \`lunora deploy\` with ${H(n)} set to create the config, or put the id from \`wrangler hyperdrive create\` in wrangler.jsonc.`;return r.logger.error(t),t},fo=(e,r)=>{const n=we(e,r.env)?.entries[0]?.binding;if(n===void 0)return;const t=`deploy blocked: the "${n}" Hyperdrive binding has no config, and a --temporary deploy cannot create one: it would be made in your account while the Worker goes to a temporary one, which a temporary account has no database for. Deploy without --temporary.`;return r.logger.error(t),t},gr=async(e,r,n,t,o="create")=>{if(t!=="cloudflare")return;if(n==="prepare")return go(e,r);if(r.temporary===!0)return fo(e,r);const s=r.clientBuildEnvironment===void 0?void 0:{...process.env,CLOUDFLARE_ENV:r.clientBuildEnvironment};return uo({checkOnly:o==="check",cwd:e,dryRun:r.dryRun,environment:s,logger:r.logger,wranglerEnvironment:r.env})},mo=/https?:\/\/[^\s"'<>]+\.workers\.dev[^\s"'<>]*/u,ho=/https:\/\/[^\s"'<>]+/u,vo=e=>{if(e===void 0)return;const r=mo.exec(e);return r?r[0]:ho.exec(e)?.[0]},je=e=>e===void 0?"":` (--env ${e})`,po=({cwd:e,env:r,logger:n,now:t,url:o})=>{if(o!==void 0)try{const s=Ue(e);if(s!==void 0){if(s.workerUrl===o&&s.env===r)return;n.warn(`link: .lunora/project.json records ${s.workerUrl??"(no url)"}${je(s.env)}, but this deploy published ${o}${je(r)}. Keeping the recorded value — run \`lunora link --url ${o}${r===void 0?"":` --env ${r}`}\` to update it.`);return}const a=(t??(()=>new Date().toISOString()))();jr(e,{env:r,linkedAt:a,workerName:fe(e),workerUrl:o}),n.success(`link: recorded ${o} in .lunora/project.json (run \`lunora link\` to change)`)}catch{}},yo=async(e,r)=>{const n=new Ye({skipAddingFilesFromTsConfig:!0}),t=k(r,"lunora");let o;try{o=$r(n,t)}catch(s){const a=s instanceof Error?s.message:String(s);return e.logger.warn(`--migrate: could not discover migrations (${a}); skipping`),0}if(o.length===0)return e.logger.info("--migrate: no data migrations declared in lunora/"),0;e.logger.info(`--migrate: running ${String(o.length)} migration(s) against deployed worker`);for(const s of o){e.logger.info(`--migrate: up "${s.id}" (table "${s.table}")`);const a={cwd:r,fetchImpl:e.fetchImpl,id:s.id,logger:e.logger,prod:!0,subcommand:"up",token:e.migrateToken,url:e.migrateUrl,yes:e.migrateYes===!0},i=await Rt(a);if(i.code!==0)return e.logger.error(`--migrate: migration "${s.id}" failed — see output above`),i.code;e.logger.success(`--migrate: "${s.id}" applied`)}return 0},wo=async(e,r)=>{const{info:n}=He(r,"lunora",e.discoveryCache),t=n?.vectorMetadata??[];if(t.length===0)return;const o=[];for(const i of t){const c=st(i.kind);if(c===void 0){e.logger.warn(`vector index "${i.index}" declares metadata "${i.property}", whose column type cannot be filtered on in Vectorize — it is stored with each vector but no filter will match it.`);continue}o.push({index:i.index,property:i.property,type:c})}if(o.length===0)return;const a=(await at({cwd:r,entries:o,exec:me(I(r),"wrangler",[]),logger:e.logger,spawner:e.spawner??M})).filter(i=>i.status!=="failed").length;a>0&&e.logger.success(`vectorize metadata indexes ready: ${String(a)}/${String(o.length)}`)},Le=5,ko=2e3,bo=async(e,r,n)=>{if(e.healthCheck!==!0)return;const t=n??Ke({cwd:r,env:e.env});if(t===void 0){const s="--health-check: the deploy succeeded, but no URL to probe could be resolved — wrangler's output carried none and this checkout has no link for this environment. Run `lunora link --url <https://your-worker>` and re-deploy, or drop --health-check.";return e.logger.error(s),{error:s,ok:!1,url:""}}const o=await kt({attempts:Le,baseUrl:t,delayMs:ko,fetchImpl:e.healthFetch,paths:[bt,St],sleep:e.healthSleep});return o.error===void 0?(e.logger.success(`health check ok (${o.url})`),{ok:!0,url:o.url}):(e.logger.error(`--health-check: the deploy succeeded, but the new version did not answer after ${String(Le)} attempt(s) — ${o.error}`),{error:o.error,ok:!1,url:o.url})},So=async(e,r,n,t,o,s)=>{await wo(e,r);const a=e.migrate?await yo(e,r):0;return a===0&&o?.(),{code:a,descriptor:n,mintedSecretsFile:s,validation:t}},$o=async({cwd:e,descriptor:r,mintedSecretsFile:n,options:t,reblessSchemaBaseline:o,recordArchitecture:s,stdout:a,validation:i})=>{const c={deployedAt:new Date().toISOString(),dryRun:t.dryRun===!0,env:t.env,preview:t.preview===!0,url:t.dryRun===!0?void 0:vo(a),workerName:fe(e)};if(t.dryRun===!0||t.preview===!0)return t.healthCheck===!0&&t.logger.warn(`--health-check skipped: ${t.dryRun===!0?"a dry run publishes nothing":"a preview version serves no live traffic"}`),{code:0,deployment:c,descriptor:r,mintedSecretsFile:n,validation:i};t.temporary!==!0&&(s?.(),po({cwd:e,env:t.env,logger:t.logger,url:c.url}));const l=await bo(t,e,c.url);return l?.error!==void 0?{code:p.UNAVAILABLE,deployment:c,descriptor:r,healthCheck:l,mintedSecretsFile:n,validation:i}:{...await So(t,e,r,i,o,n),deployment:c,healthCheck:l}},Eo=(e,r,n)=>{const t=k(e,N);if(!b(t))return;let o;try{o=Ge(E(t,"utf8")).length}catch{return}if(o===0)return;const s=n.toolchain?.secretPut!==void 0;r.warn(s?`Note: \`lunora deploy\` does not push secrets. ${N} has ${String(o)} key(s); if you changed them, run \`lunora env push --yes\` to update the deployed secrets.`:`Note: ${n.name} deploys read no secrets. ${N} has ${String(o)} key(s) that only the dev server sees; put the values the deployed worker needs in wrangler \`vars\`.`)},Ao=async(e,r)=>{let n=[];try{n=Lr(await qe({cache:r,projectRoot:e,schemaDir:L(e)}))}catch{}const t=xr(n).map(s=>s.key);let o=[];try{const s=k(e,N);b(s)&&(o=Ge(E(s,"utf8")).map(a=>a.key).filter(a=>it(a)))}catch{}return[...new Set([...t,...o])]},To=async(e,r,n,t)=>{const{logger:o}=r,s=r.spawner??M,a=I(e),i=r.env===void 0?"":` --env ${r.env}`,c=t.toolchain?.secretPut;if(c===void 0)return o.error(`deploy target "${t.id}" has no secret store; cannot push secrets`),{minted:[],ok:!1};const l=n.map(d=>({key:d,value:Mr()})),g=t.toolchain?.secretBulk;if(g!==void 0&&l.length>=2){const d=U(a,g({environment:r.env,temporary:r.temporary})),f=await s({args:d.args,command:d.command,cwd:e,input:JSON.stringify(Object.fromEntries(l.map(m=>[m.key,m.value])))});if(f.code===0){for(const{key:m}of l)o.success(`generated + pushed ${m}`);return{minted:l,ok:!0}}o.warn(`bulk secret push failed (exit ${String(f.code)}); retrying one key at a time`)}const u=[];for(const{key:d,value:f}of l){const m=c({environment:r.env,key:d,temporary:r.temporary}),w=U(a,m),h=await s({args:w.args,command:w.command,cwd:e,input:f});if(h.code!==0)return o.error(`failed to push secret ${d} (exit ${String(h.code)}); set it manually with \`wrangler secret put ${d}${i}\`.`),{minted:u,ok:!1};u.push({key:d,value:f}),o.success(`generated + pushed ${d}`)}return{minted:u,ok:!0}},Ro=/^[\w-]+$/u,ne=[".dev.vars",".dev.vars.*","!.dev.vars.example"],Do=/\r?\n/u,_o=(e,r)=>{const n=k(e,".gitignore");try{const t=b(n)?E(n,"utf8"):"",o=new Set(t.split(Do).map(c=>c.trim())),s=ne.filter(c=>!o.has(c));if(s.length===0)return;const a=s.some(c=>!c.startsWith("!"))?[...s.filter(c=>!c.startsWith("!")),...ne.filter(c=>c.startsWith("!"))]:s,i=t.length>0&&!t.endsWith(`
|
|
19
|
+
`)?`
|
|
20
|
+
`:"";C(n,`${t}${i}
|
|
21
|
+
# Lunora — never commit a minted secret
|
|
22
|
+
${a.join(`
|
|
23
|
+
`)}
|
|
24
|
+
`,"utf8"),r.info(`.gitignore: added ${s.join(", ")} so the recorded secret cannot be committed`)}catch(t){r.warn(`could not update .gitignore (${t instanceof Error?t.message:String(t)}) — add \`${ne.join("` and `")}\` by hand before committing.`)}},Po=(e,r,n)=>{if(n.length===0)return;const t=n.map(i=>i.key).join(", ");if(r.env!==void 0&&!Ro.test(r.env)){r.logger.warn(`${t}: minted and pushed for --env ${r.env}, but "${r.env}" isn't a safe filename fragment — the value could not be recorded. Capture it manually if you need it again.`);return}const o=r.env===void 0?N:`${N}.${r.env}`;_o(e,r.logger);const s=k(e,o);let a=b(s)?E(s,"utf8"):"";for(const i of n)a=Fr(a,i.key,i.value);return Ur(s,a),r.logger.success(r.env===void 0?`${t}: value(s) recorded in ${o}`:`${t}: value(s) recorded in ${o} (kept separate from ${N} so \`lunora dev\` and a plain \`lunora env push\` don't inherit the --env ${r.env} value)`),o},No=async(e,r,n,t)=>{if(r.dryRun===!0||r.preview===!0)return{};const{logger:o}=r,s=r.env===void 0?"":` --env ${r.env}`;let a;try{a=await(r.secretLister??_t)({cwd:e,env:r.env,temporary:r.temporary})}catch{return{}}if(!a.ok)return{};const i=new Set(a.names),l=(await Ao(e,r.discoveryCache)).filter(d=>!i.has(d));if(l.length===0)return{};if(!n)return{error:`missing required secret(s) on the deploy target: ${l.join(", ")}. Set them with \`wrangler secret put <KEY>${s}\` (or \`lunora env generate --set\` then \`lunora env push --yes${s}\`), then re-deploy.`};for(const d of l.filter(f=>!$e(f)))o.warn(`required secret ${d} is not set on the target — set it with: wrangler secret put ${d}${s}`);const g=l.filter(d=>$e(d));if(g.length===0)return{};if(await(r.secretConfirm??Dt())(`${String(g.length)} required secret(s) not set on the target (${g.join(", ")}). Generate strong values and push them now?`)){const{minted:d,ok:f}=await To(e,r,g,t),m=Po(e,r,d);return f?{mintedSecretsFile:m}:{error:"failed to push required secret(s) — set them manually and re-deploy",mintedSecretsFile:m}}return o.warn(`${String(g.length)} required secret(s) not set on the target: ${g.join(", ")}. Generate + push with \`lunora env generate --set\` then \`lunora env push --yes${s}\`.`),{}},fr=e=>e.format==="json"?!1:e.interactive!==void 0?e.interactive:process.stdout.isTTY&&!process.env.CI,Io=async(e,r)=>{if(r.dryRun===!0)return;const n=Be(e,"lunora",r.discoveryCache).containers.flatMap(o=>o.schedulingPolicy===void 0&&o.image.kind==="build"?[{buildDir:o.image.buildDir,exportName:o.exportName}]:[]);if(n.length===0)return;const t=await an({cwd:e,logger:r.logger,railpackAvailable:r.railpackAvailable,spawner:r.spawner,targets:n});return t.code===0?void 0:t.error??"railpack build failed"},Oo=(e,r,n)=>{if(n!==void 0)try{const t=Zr(e,n);t.changed&&r.success(`synced ${String(n.length)} cron trigger(s) → ${t.wranglerPath??"wrangler.jsonc"}`);for(const s of t.warnings)r.warn(s);const o=et(t.preserved);o!==void 0&&r.info(o)}catch(t){const o=t instanceof Error?t.message:String(t);r.warn(`cron trigger sync skipped: ${o}`)}},Co=async(e,r,n,t,o,s)=>{try{J(t);const a=await qe({cache:s,projectRoot:e,schemaDir:L(e)}),i=Xr(e,a,{environment:o,target:t}),c=i.wranglerPath??"wrangler.jsonc";if(i.added.length>0&&r.success(`provisioned bindings: ${i.added.join(", ")} → ${c}`),i.updated.length>0&&r.success(`updated bindings: ${i.updated.join(", ")} → ${c}`),i.devConfig!==void 0){const{added:l,path:g,updated:u}=i.devConfig;r.success(`dev sidecar bindings: ${[...l,...u].join(", ")} → ${g}`)}for(const l of i.warnings)r.warn(l)}catch(a){const i=a instanceof Error?a.message:String(a);r.warn(`binding inference skipped: ${i}`)}try{const a=Qr(e);a.changed&&r.success(`bumped compatibility_date to ${a.date??"unknown"} (Workers Cache enabled) → ${a.wranglerPath??"wrangler.jsonc"}`)}catch(a){const i=a instanceof Error?a.message:String(a);r.warn(`compatibility date sync skipped: ${i}`)}Oo(e,r,n)},jo=async(e,r,n,t,o,s,a,i,c,l)=>{let g;r?(g=new rt({name:"dots"}),g.start("running codegen")):n.info("running codegen");try{const u=Er({apiSpec:t,dryRun:!l,lazyFunctions:o,projectRoot:e,target:s,...Yr(e)});g?.succeed("codegen complete"),g||n.success("codegen complete");const d=tt(u.platformDiagnostics,n);if(d.errors.length>0)return{error:d.errors.join("; ")};const{errorAdvisories:f,names:m,shouldBlock:w}=nt(u.advisories,c);if(w){const A=`${f.length.toString()} ERROR-level ${f.length===1?"advisory":"advisories"} (${m.join(", ")}). Pass --no-strict-advisories to downgrade this to a warning and continue.`;return n.error(A),{error:A}}const h=l?await qr({cwd:e,logger:n,spawner:a,stdoutToStderr:i}):void 0;return h?.error!==void 0?{error:h.error}:{result:u}}catch(u){g?.failed("codegen failed");const d=u instanceof Error?u.message:String(u);return n.error(`codegen failed: ${d}`),{error:`codegen failed: ${d}`}}},Lo=(e,r)=>({dryRun:r.dryRun,entry:pe(e),environment:r.env,outDir:r.outDir,preview:r.preview,temporary:r.temporary}),mr=(e,r,n)=>{const{toolchain:t}=n;if(t===void 0)throw new Error(`deploy target "${n.id}" has no command-line toolchain`);const o=Lo(e,r);return Ve(n,e,"deploy",s=>t.deploy({...o,configPath:s}))},xo=(e,r,n)=>{const t=mr(e,r,n),o=pe(e);return o!==void 0&&r.logger.info(`class-B composition: deploying ${o} (overrides wrangler main)`),r.temporary&&r.logger.info("temporary account: deploying to a short-lived Cloudflare account (~60min); wrangler will print a claim URL"),r.dryRun&&r.logger.info("dry run: validating + bundling without publishing"),r.outDir!==void 0&&r.logger.info(`build artifact: emitting bundle to ${r.outDir}`),t.commit(),t.projection!==void 0&&t.projection.dropped.length>0&&r.logger.warn(`${n.name} ignores these wrangler keys, so they were left out of ${t.projection.configPath}: ${t.projection.dropped.join(", ")}`),t.command},R={problems:[],wranglerPath:void 0},oe=(e,r)=>({code:p.USAGE,descriptor:void 0,error:e,validation:R,...r}),Mo=(e,r)=>{for(const n of e.report?.warnings??[])r.warn(`wrangler.jsonc: ${n}`);if(e.problems.length===0)return!1;r.error("wrangler.jsonc validation failed:");for(const n of e.problems)r.error(` - ${n}`);return!0},Fo=(e,r,n)=>{const t=r.format==="json",o=r.dryRun!==!0,s=xo(e,r,n),a=U(I(e),s);return{args:a.args,captureStdout:o&&!t,captureStdoutSilently:o&&t,command:a.command,cwd:e,stdoutToStderr:t&&!o}},ke=e=>{if(e.skipServices===!0)return"--skip-services";if(e.preview===!0)return"--preview uploads the app version only";if(e.temporary===!0)return"--temporary deploys the app to a throwaway account"},Uo=(e,r)=>ke(r)===void 0?ue(e).services.map(n=>n.wranglerPath):[],hr=(e,r,n,t,o)=>({cwd:e,environment:r.env,frameworkBuild:t,lazyFunctions:K(r.lazyFunctions),logger:r.logger,outputJson:r.format==="json"||r.clientBuildOutputJson===!0,spawner:o,strictAdvisories:ge(r),target:n.id}),Bo=(e,r,n)=>{const{toolchain:t}=n,o=t===void 0?`target "${n.id}" has no deploy command`:ke(r);if(o!==void 0||t===void 0){const s=e.map(a=>a.worker).join(", ");r.logger.warn(`services not deployed (${o??""}): ${s} — deploy them yourself if the app calls anything new`);return}return t},vr=(e,r)=>{for(const n of e){const t=he(r(F(n.wranglerPath)));if(t!==void 0)return`service ${n.name} (${n.worker}): ${t}`}},Ho=(e,r,n)=>{const{error:t,services:o}=ue(e);if(t!==void 0||o.length===0)return;const s=J(n);if(s.toolchain===void 0||ke(r)!==void 0)return;const a=r.skipCodegen===!0?!1:r.frameworkBuild,i=[...new Map(o.map(c=>[c.wranglerPath,c])).values()];return vr(i,c=>hr(c,r,s,a,M))},pr=(e,r,n)=>{const t=e.cwd??process.cwd(),o=gt(t,e.target);if(o.target===void 0){const i=o.error??"unknown deploy target";return e.logger.error(i),{kind:"refused",error:i,validation:R}}try{mr(t,e,J(o.target))}catch(i){if(!(n&&i instanceof Br&&Q(t,e.skipCodegen===!0?!1:e.frameworkBuild,e.env))){const c=i instanceof Error?i.message:String(i);return e.logger.error(c),{kind:"refused",error:c,validation:R}}}const s=e.openShardGatePassed===!0?void 0:Un(t,e,r,Uo(t,e));if(s!==void 0)return{kind:"refused",code:s.code,error:s.error,validation:R};const a=Ho(t,e,o.target);return a!==void 0?(e.logger.error(a),{kind:"refused",code:p.USAGE,error:a,validation:R}):{kind:"ok",target:o.target}},Go=(e,r)=>e.apiSpec??(e.clientBuildRan===!0?Vr(r):void 0),qo=async(e,r)=>{const n=e.cwd??process.cwd(),t=fr(e),o=ge(e),s={problems:[],wranglerPath:void 0},a=pr(e,r,!1);if(a.kind==="refused")return{code:a.code,error:a.error,validation:a.validation};const{target:i}=a;let c;if(!e.skipCodegen){const m=await jo(n,t,e.logger,Go(e,n),K(e.lazyFunctions),i,e.spawner,e.format==="json",o,e.clientBuildRan!==!0);if(m.error!==void 0)return{error:m.error,target:i,validation:R};c=m.result,e.discoveryCache?.clear()}let l;if(c!==void 0){const m=$t({allowDrift:e.allowSchemaDrift===!0,codegen:c,command:r,logger:e.logger,updateBaseline:e.updateSchemaBaseline===!0});if(m.blocked)return{error:`schema drift gate blocked ${r}`,schemaDrift:{blocked:!0,reason:m.reason},target:i,validation:s};l=m.rebless}const g=c&&Lt({current:c.architecture,cwd:n,environment:e.env,logger:e.logger});await Co(n,e.logger,c?.cronTriggers,i,e.env,e.discoveryCache);const u=await gr(n,e,r,i,"check");if(u!==void 0)return{error:u,target:i,validation:R};const d=Bn(n,e,r);if(d!==void 0)return{code:d.code,error:d.error,target:i,validation:R};const f=Jr({environment:e.env,projectRoot:n});return Mo(f,e.logger)?{error:"wrangler validation failed",target:i,validation:f}:{codegen:c,reblessSchemaBaseline:l,recordArchitecture:g,target:i,validation:f}},Vo=e=>{W(S(e,".wrangler","deploy","config.json"),{force:!0})},Wo=async(e,r,n)=>{const t=he(e);if(t!==void 0)return{built:!1,error:t};const o=Q(e.cwd,r,n);return o&&Vo(e.cwd),{built:o,error:await rr(e)}},zo=(e,r,n)=>r||n===!1?ur(e):void 0,Ko=async(e,r,n,t)=>{const{error:o,services:s}=ue(e);if(o!==void 0)return{code:p.FAILURE,error:o};if(s.length===0)return;const a=Bo(s,r,n);if(a===void 0)return;const i=I(e),c=[...new Map(s.map(d=>[d.wranglerPath,d])).values()],l=r.skipCodegen===!0?!1:r.frameworkBuild,g=d=>hr(d,r,n,l,t),u=vr(c,g);if(u!==void 0)return r.logger.error(u),{code:p.USAGE,error:u};for(const d of c){const f=F(d.wranglerPath),m=g(f),{built:w,error:h}=await Wo(m,l,r.env);if(h!==void 0){const T=`service ${d.name} (${d.worker}): ${h}`;return r.logger.error(T),{code:p.FAILURE,error:T}}const A=zo(d.wranglerPath,w,l);let _;try{_=Ve(n,f,"deploy",T=>a.deploy({configPath:T??A??d.wranglerPath,dryRun:r.dryRun===!0,environment:r.env}))}catch(T){return{code:p.FAILURE,error:`service ${d.name} (${d.worker}): ${T instanceof Error?T.message:String(T)}`}}_.commit();const $=U(i,_.command);r.logger.info(`deploying service ${d.name} (${d.worker}) via ${$.command} ${$.args.join(" ")}`);const O=await t({args:$.args,command:$.command,cwd:f,stdoutToStderr:r.format==="json"});if(O.code!==0)return{code:p.FAILURE,error:`service ${d.name} (${d.worker}): ${$.command} ${$.args.join(" ")} exited ${String(O.code)} — stopping before the app`}}},Jo=async(e,r,n,t)=>{if(r!=="cloudflare")return;const o=e===void 0?void 0:P(e).parsed,s=(n===void 0?void 0:o?.env?.[n]?.account_id)??o?.account_id,a=await dt({accountId:s});(a.verdict==="near"||a.verdict==="full")&&t.warn(a.fix===void 0?a.message:`${a.message} ${a.fix}`)},Yo=e=>e.dryRun!==!0&&e.temporary!==!0,Xo=e=>e.temporary===!0?"temporary":e.dryRun===!0?"preview":"defer",Qo=e=>{const r=e.fix===void 0?e.message:`${e.message} ${e.fix}`;return e.verdict==="unchecked"?`${r} The deploy stops until it can be checked, as a namespace made by the first repo is unrestricted.`:r},Zo=(e,r,n)=>{const t=[];for(const o of e)if(o.verdict==="ok")o.changesAccount===!0&&r.info(o.message);else if(o.verdict==="unchecked"&&n==="preview")r.warn(`dry run: ${o.message}${o.fix===void 0?"":` ${o.fix}`} A real deploy stops here.`);else{const s=Qo(o);r.error(s),t.push(s)}return t},yr=async(e,r,n,t,o,s,a)=>{const i=n==="cloudflare"&&r!==void 0?P(r).parsed:void 0;if(i===void 0)return;const c=(Y(i,t).merged.artifacts??[]).flatMap(m=>typeof m?.binding=="string"&&typeof m.namespace=="string"?[{binding:m.binding,namespace:m.namespace}]:[]),l=c.length===0?void 0:He(e,L(e),s).info?.jurisdiction;if(l===void 0)return;const g=[...new Map(c.map(m=>[m.namespace,m])).values()];if(a==="temporary"){o.warn(`--temporary deploys to a throwaway account, so the jurisdiction ("${l}") of Artifacts namespace ${g.map(m=>`"${m.namespace}"`).join(", ")} was not checked: it is created there on first use, in no jurisdiction.`);return}const u=(t===void 0?void 0:i.env?.[t]?.account_id)??i.account_id,d=await Promise.all(g.map(async m=>ct({...m,accountId:u,create:a==="create",jurisdiction:l,missingOk:a==="defer"||a==="preview"}))),f=Zo(d,o,a);return f.length===0?void 0:f.join(`
|
|
25
|
+
`)},es=async(e,r,n,t,o,s)=>{const a=Yo(r)?await yr(e,s,o,r.env,r.logger,r.discoveryCache,"create"):void 0;if(a!==void 0)return{code:p.FAILURE,error:a};const i=await gr(e,r,"deploy",o);return i!==void 0?{code:p.FAILURE,error:i}:Ko(e,r,n,t)},rs=async(e,r,n,t)=>{if(!(r.smokeLoad===!1||n.toolchain===void 0))return on({composedEntry:pe(e),configPath:t,cwd:e,environment:r.env,launcher:r.smokeLauncher,logger:r.logger,toolchain:n.toolchain})},ts=async e=>{const r={...e,discoveryCache:e.discoveryCache??Gr()},n=r.cwd??process.cwd(),t=fr(r),o=await qo(r,r.commandName??"deploy");if(o.error!==void 0){if(o.validation.problems.length>0)return{code:p.USAGE,descriptor:void 0,error:o.error,validation:o.validation};const h=o.schemaDrift===void 0?void 0:{schemaDrift:o.schemaDrift};return oe(o.error,{...h,...o.code===void 0?{}:{code:o.code}})}const{validation:s}=o,a=J(o.target),i=kn(r)??await yr(n,s.wranglerPath,o.target,r.env,r.logger,r.discoveryCache,Xo(r))??await rs(n,r,a,s.wranglerPath);if(i!==void 0)return oe(i);const c=a.toolchain?.prebuildsContainerImages===!0?await Io(n,r):void 0;if(c!==void 0)return oe(c);Eo(n,r.logger,a),Kr(n,h=>{r.logger.warn(h)}),await Jo(s.wranglerPath,o.target,r.env,r.logger);const{error:l,mintedSecretsFile:g}=await No(n,r,t,a);if(l!==void 0)return r.logger.error(l),{code:p.USAGE,descriptor:void 0,error:l,mintedSecretsFile:g,validation:s};const u=r.spawner??M,d=await es(n,r,a,u,o.target,s.wranglerPath);if(d!==void 0)return{code:d.code,descriptor:void 0,error:d.error,mintedSecretsFile:g,validation:s};const f=Fo(n,r,a);r.logger.info(`deploying via ${f.command} ${f.args.join(" ")}`);const m=await u(f);return f.captureStdoutSilently===!0&&m.stdout!==void 0&&m.stdout!==""&&process.stderr.write(m.stdout),m.code!==0?{code:m.code,descriptor:f,mintedSecretsFile:g,validation:s}:{...await $o({...o,cwd:n,descriptor:f,mintedSecretsFile:g,options:r,stdout:m.stdout}),logsAvailable:a.toolchain?.tail!==void 0}},ns=async e=>{const{logger:r}=e,n=e.cwd??process.cwd(),t={apiSpec:e.apiSpec,cwd:n,environment:e.env,bundleMetaPath:e.bundleMetaPath,frameworkBuild:e.skipCodegen===!0?!1:e.frameworkBuild,strictAdvisories:ge(e),lazyFunctions:K(e.lazyFunctions),logger:r,outputJson:e.format==="json"||e.clientBuildOutputJson===!0,spawner:e.spawner,target:e.target},o=he(t);if(o!==void 0)return r.error(o),{code:p.USAGE,descriptor:void 0,error:o,validation:R};Hr(n);const s=await rr(t);if(s!==void 0)return r.error(s),{code:p.FAILURE,descriptor:void 0,error:s,validation:R}},os=(e,r)=>{const n=r.skipCodegen===!0?!1:r.frameworkBuild;return Q(e,n,r.env)?r.env:void 0},ss=async e=>{const{logger:r}=e,n=e.cwd??process.cwd(),t=pr(e,e.commandName??"deploy",!0);if(t.kind==="refused")return{code:t.code??p.USAGE,descriptor:void 0,error:t.error,validation:t.validation};const o=await ns(e);if(o!==void 0)return o;const s=e.dryRun===!0?Qe(n):void 0;let a;try{if(a=await ts({...e,clientBuildEnvironment:os(n,e),clientBuildRan:fn(n,e.skipCodegen===!0?!1:e.frameworkBuild,e.env),logger:r,openShardGatePassed:!0}),a.code===0&&e.emitBindings!==void 0){const{error:i}=lt({destination:e.emitBindings,logger:r,projectRoot:e.cwd??process.cwd()});i!==void 0&&(r.error(i),a={...a,code:p.USAGE})}}finally{s?.()}if(e.format==="json")return a;if(a.code===0&&e.dryRun!==!0&&e.preview!==!0)xt({cwd:e.cwd??process.cwd(),env:e.env,logger:e.logger,logsAvailable:a.logsAvailable===!0,mintedSecretsFile:a.mintedSecretsFile,url:a.deployment?.url});else if(a.code===0&&e.preview===!0){const i=a.deployment?.url;e.logger.success(i===void 0?"preview version uploaded":`preview version uploaded — ${i}`)}return a},xs=ut(async({cwd:e,format:r,logger:n,options:t})=>{const o=sn(e,t.root),s=await ss({allowOpenShards:t.allowOpenShards===!0,allowSchemaDrift:t.allowSchemaDrift===!0,apiSpec:ot(t.apiSpec),frameworkBuild:t.prebuilt===!0?!1:t.frameworkBuild,lazyFunctions:K(t.lazyFunctions),cwd:o,dryRun:t.dryRun===!0,env:t.env,format:r,healthCheck:t.healthCheck===!0,logger:n,migrate:t.migrate===!0,migrateToken:t.migrateToken,migrateUrl:Ke({cwd:o,env:t.env,url:t.migrateUrl}),migrateYes:t.migrateYes===!0,preview:t.preview===!0,skipCodegen:t.prebuilt===!0,skipServices:t.skipServices===!0,smokeLoad:t.smokeLoad,strictAdvisories:t.strictAdvisories,target:t.target,temporary:t.temporary===!0,updateSchemaBaseline:t.updateSchemaBaseline===!0});return{code:s.code,data:{deployment:s.deployment,healthCheck:s.healthCheck,mintedSecretsFile:s.mintedSecretsFile,schemaDrift:s.schemaDrift,validation:s.validation},error:s.error}});export{qo as a,Co as b,xs as e,sn as p,ss as r,rs as s,cn as v};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{existsSync as u,rmSync as a}from"node:fs";import{join as i}from"node:path";import{writeLinkedProject as d,LINKED_PROJECT_FILE as o}from"@lunora/config";import{d as k}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as c}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as s}from"../packem_shared/wrangler-name-Dsk5K1f-.mjs";const v=r=>{try{const{protocol:n}=new URL(r);return n==="http:"||n==="https:"}catch{return!1}},f=(r,n)=>{const e=i(r,o);return u(e)?(a(e),n.success(`link: removed ${o}`),{code:0}):(n.warn(`link: no ${o} to remove`),{code:0})},w=r=>{const n=r.cwd??process.cwd(),{logger:e}=r;if(r.remove)return f(n,e);if(r.url===void 0||r.url==="")return e.error("link requires a deployed Worker URL. Usage: lunora link --url <https://your-worker>"),{code:c.USAGE};if(!v(r.url))return e.error(`link: invalid --url "${r.url}" — expected an http(s) URL`),{code:c.USAGE};const l=r.now??(()=>new Date().toISOString()),t={env:r.env,linkedAt:l(),workerName:r.name??s(n),workerUrl:r.url},m=d(n,t);return e.success(`link: ${t.workerName??"(unnamed worker)"} -> ${r.url}`),e.info(`link: wrote ${m}`),t.env!==void 0&&e.info(`link: environment "${t.env}"`),{code:0,link:t}},y=k(({cwd:r,logger:n,options:e})=>w({cwd:r,env:e.env,logger:n,name:e.name,remove:e.remove===!0,url:e.url}));export{y as execute,w as runLinkCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{resolveLazyFunctions as t,resolveDeployDriver as o}from"@lunora/config";import{p as l}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{d as s}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as c}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{a as d,s as m}from"./handler.mjs";const n=async r=>{const a=r.cwd??process.cwd(),e=await d({allowSchemaDrift:r.allowSchemaDrift,apiSpec:r.apiSpec,lazyFunctions:t(r.lazyFunctions),cwd:a,logger:r.logger,spawner:r.spawner,strictAdvisories:r.strictAdvisories,target:r.target,updateSchemaBaseline:r.updateSchemaBaseline},"prepare");if(e.error!==void 0)return{code:e.code??c.USAGE,error:e.error,...e.schemaDrift===void 0?{}:{schemaDrift:e.schemaDrift},validation:e.validation};const i=await m(a,{env:void 0,logger:r.logger,smokeLauncher:r.smokeLauncher,smokeLoad:r.smokeLoad},o(e.target),e.validation.wranglerPath);return i!==void 0?{code:c.FAILURE,error:i,validation:e.validation}:(e.reblessSchemaBaseline?.(),r.logger.success("project is ready to deploy"),{code:0,validation:e.validation})},h=s(({cwd:r,logger:a,options:e})=>n({allowSchemaDrift:e.allowSchemaDrift===!0,apiSpec:l(e.apiSpec),lazyFunctions:t(e.lazyFunctions),cwd:r,logger:a,smokeLoad:e.smokeLoad,strictAdvisories:e.strictAdvisories,target:e.target,updateSchemaBaseline:e.updateSchemaBaseline===!0}));export{h as execute,n as runPrepareCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as l}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as n}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as s,b as t,a as o}from"../packem_shared/commands-DvSfLvyt.mjs";const y=l(({argument:a,cwd:u,format:m,logger:e,options:r})=>{const f=a[0],c=a.slice(1);if(f==="add")return s({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,diff:r.diff===!0,dryRun:r.dryRun===!0,format:m,from:r.from,logger:e,names:c,overwrite:r.overwrite===!0,ref:r.ref,source:r.source,yes:r.yes===!0});if(f==="list")return s({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,format:m,from:r.from,list:!0,logger:e,names:[],ref:r.ref,source:r.source});if(f==="view")return t({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,from:r.from,logger:e,names:c,ref:r.ref,source:r.source});if(f==="build")return o({check:r.check===!0,cwd:u,from:r.from,logger:e,names:[],out:r.out});const d="registry: unknown subcommand. Usage: lunora registry <add|list|view|build> [names…]";return e.error(d),{code:n.USAGE,error:d}});export{y as execute};
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
`)}
|
|
3
|
-
`:""}},P=async e=>{const r=e.cwd??process.cwd(),o=e.format==="json",t=w(r,"lunora","schema.ts"),n=x(e,t);if(n!==void 0)return n;const s=new A({skipAddingFilesFromTsConfig:!0}),d=C(s,t),a=D(e,d);if(a!==void 0)return a;const i=T(d),l=$(i,{defaultCount:e.count??10,now:e.now,only:e.table===void 0?void 0:[e.table],seed:e.seed??0}),{lines:h,ndjson:c}=G(l),m=h.length;if(e.dryRun===!0)return!o&&c.length>0&&process.stdout.write(c),e.logger.info(`generated ${String(m)} row(s) across ${String(l.length)} table(s) — dry run, nothing inserted`),{code:0,data:{conflicts:0,generated:m,inserted:0,rows:o?h.map(g=>JSON.parse(g)):void 0,tables:l.length},ndjson:c};if(m===0)return e.logger.warn("no rows generated — nothing to insert"),{code:0,data:{conflicts:0,generated:0,inserted:0,tables:l.length},ndjson:c};if(e.reset===!0){const g=await U({confirm:e.confirm,cwd:r,logger:e.logger,yes:e.yes});if(g.code!==0)return{code:g.code,error:"seed: --reset could not clear local state",ndjson:c}}const b=await _(e,m);return b!==void 0?b:z(c,m,l.length,r,e)},ee=E(async({cwd:e,format:r,logger:o,options:t})=>{const n=await P({batchSize:t.batchSize,count:t.count,cwd:e,dryRun:t.dryRun===!0,format:r,logger:o,prod:t.prod===!0,reset:t.reset===!0,now:t.now,seed:t.seed,table:t.table,token:t.token,url:F({cwd:e,prod:t.prod===!0,url:t.url}),yes:t.yes===!0});return{code:n.code,data:n.data,error:n.error}});export{ee as execute,P as runSeedCommand};
|
|
1
|
+
import{existsSync as u,readdirSync as d,statSync as g,mkdirSync as h,writeFileSync as w,readFileSync as y}from"node:fs";import{fileURLToPath as v}from"node:url";import{AGENT_RULES_DIR as a,detectAgentRules as R,LUNORA_SKILL_NAMES as L}from"@lunora/config";import{join as i,relative as A,resolve as E,dirname as m}from"@visulima/path";import{f as I}from"../packem_shared/cli-manifest-DoQ_3bzs.mjs";import{d as $}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as _}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";const b=(e=m(v(import.meta.url)))=>{const r=I(e),t=r===void 0?void 0:i(r,"skills");return t!==void 0&&u(t)?t:void 0},j=e=>d(e).filter(r=>{const t=i(e,r);return g(t).isDirectory()&&u(i(t,"SKILL.md"))}),f=(e,r,t)=>{h(r,{recursive:!0});let n=!1;for(const o of d(e)){const l=i(e,o),s=i(r,o);if(g(l).isDirectory()){n=f(l,s,t)||n;continue}u(s)&&!t||(w(s,y(l)),n=!0)}return n},D=["pnpm-workspace.yaml","pnpm-lock.yaml","yarn.lock","package-lock.json","bun.lock","bun.lockb",".git"],O=e=>{let r=e;for(;;){if(D.some(n=>u(i(r,n))))return r;const t=m(r);if(t===r)return e;r=t}},k=(e,r)=>r===void 0?O(e):E(e,r),U=e=>{const r=e.cwd??process.cwd(),t=k(r,e.dir),n=e.overwrite===!0,o=b();if(o===void 0)return e.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?)."),{code:1,installed:[],skipped:[]};const l=[],s=[];for(const c of j(o)){const S=i(t,a,c);f(i(o,c),S,n)?l.push(c):s.push(c)}const p=A(r,i(t,a))||a;return l.length>0&&e.logger.success(`Installed ${String(l.length)} Lunora skill(s) into ${p}/: ${l.join(", ")}.`),s.length>0&&e.logger.info(`Skipped ${String(s.length)} existing skill(s) (re-run with --overwrite to replace): ${s.join(", ")}.`),e.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill."),{code:0,installed:l,skipped:s}},x=e=>{const r=e.cwd??process.cwd(),t=k(r,e.dir),n=R(t);return n.installed?(e.logger.success(`Lunora agent rules are installed (${String(n.present.length)}/${String(L.length)} skills).`),n.missing.length>0&&e.logger.info(`Missing: ${n.missing.join(", ")}. Run \`lunora rules install\` to add them.`),{code:0,installed:n.present,skipped:[]}):(e.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora."),{code:e.strict===!0?1:0,installed:n.present,skipped:[]})},G=$(({argument:e,cwd:r,logger:t,options:n})=>{const o=e[0]??"check";return o==="install"?U({cwd:r,dir:n.dir,logger:t,overwrite:n.overwrite===!0}):o==="check"?x({cwd:r,dir:n.dir,logger:t,strict:n.strict===!0}):(t.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:_.USAGE})});export{G as execute,j as listBundledSkills,b as resolveBundledSkillsDirectory,x as runRulesCheck,U as runRulesInstall};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{existsSync as S}from"node:fs";import{mkdtemp as v,writeFile as k,rm as j}from"node:fs/promises";import{tmpdir as R}from"node:os";import{discoverSchema as C,schemaFromIr as T}from"@lunora/codegen";import{seedPlan as $}from"@lunora/seed";import{join as w}from"@visulima/path";import{Project as A}from"ts-morph";import{t as y}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{d as E}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as u}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{a as F}from"../packem_shared/resolve-target-C_ZloTvd.mjs";import{b as N}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{runResetCommand as U}from"./runResetCommand.mjs";import{r as I}from"../packem_shared/import-BRM1hs7j.mjs";const O=(e,r)=>typeof r=="bigint"?Number(r):r instanceof ArrayBuffer?[...new Uint8Array(r)]:r,f=(e,r)=>({code:e,error:r,ndjson:""}),x=(e,r)=>{if(!S(r)){const o=`schema not found: ${r} — run \`vis generate lunora-table --name=<name>\` to create one`;return e.logger.error(o),f(u.NOT_FOUND,o)}if(e.reset===!0&&y({prod:e.prod,url:e.url})){const o="--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url";return e.logger.error(o),f(u.USAGE,o)}},z=async(e,r,o,t,n)=>{const s=await v(w(R(),"lunora-seed-")),d=w(s,"rows.ndjson");await k(d,e,"utf8");try{const a=await I({batchSize:n.batchSize,cwd:t,fetchImpl:n.fetchImpl,file:d,logger:n.logger,prod:n.prod,token:n.token,url:n.url,yes:!0}),i=a.body?.conflicts??0;return i>0&&n.logger.warn(`${String(i)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`),{code:a.code,data:{conflicts:i,generated:r,inserted:a.inserted,tables:o},ndjson:e,...a.error===void 0?{}:{error:a.error}}}finally{await j(s,{force:!0,recursive:!0}).catch(()=>{})}},D=(e,r)=>{if(e.table===void 0||r.tables.some(n=>n.name===e.table))return;const o=r.tables.map(n=>n.name).join(", "),t=`unknown table "${e.table}" — schema defines: ${o||"(no tables)"}`;return e.logger.error(t),f(u.USAGE,t)},_=async(e,r)=>{if(!y({prod:e.prod,url:e.url})||e.yes===!0)return;if(!process.stdin.isTTY&&e.confirm===void 0){const s="seed: refusing to insert into a non-local target without confirmation — re-run with --yes";return e.logger.error(s),f(u.USAGE,s)}if(!await(e.confirm??N)(`This will insert ${String(r)} generated row(s) into ${e.url??"the production worker"}. Continue?`))return e.logger.info("seed: aborted"),f(u.CANCELLED,"seed: aborted at the confirmation prompt")},G=e=>{const r=[];for(const{rows:o,table:t}of e)for(const n of o)r.push(JSON.stringify({doc:n,table:t},O));return{lines:r,ndjson:r.length>0?`${r.join(`
|
|
2
|
+
`)}
|
|
3
|
+
`:""}},P=async e=>{const r=e.cwd??process.cwd(),o=e.format==="json",t=w(r,"lunora","schema.ts"),n=x(e,t);if(n!==void 0)return n;const s=new A({skipAddingFilesFromTsConfig:!0}),d=C(s,t),a=D(e,d);if(a!==void 0)return a;const i=T(d),l=$(i,{defaultCount:e.count??10,now:e.now,only:e.table===void 0?void 0:[e.table],seed:e.seed??0}),{lines:h,ndjson:c}=G(l),m=h.length;if(e.dryRun===!0)return!o&&c.length>0&&process.stdout.write(c),e.logger.info(`generated ${String(m)} row(s) across ${String(l.length)} table(s) — dry run, nothing inserted`),{code:0,data:{conflicts:0,generated:m,inserted:0,rows:o?h.map(g=>JSON.parse(g)):void 0,tables:l.length},ndjson:c};if(m===0)return e.logger.warn("no rows generated — nothing to insert"),{code:0,data:{conflicts:0,generated:0,inserted:0,tables:l.length},ndjson:c};if(e.reset===!0){const g=await U({confirm:e.confirm,cwd:r,logger:e.logger,yes:e.yes});if(g.code!==0)return{code:g.code,error:"seed: --reset could not clear local state",ndjson:c}}const b=await _(e,m);return b!==void 0?b:z(c,m,l.length,r,e)},ee=E(async({cwd:e,format:r,logger:o,options:t})=>{const n=await P({batchSize:t.batchSize,count:t.count,cwd:e,dryRun:t.dryRun===!0,format:r,logger:o,prod:t.prod===!0,reset:t.reset===!0,now:t.now,seed:t.seed,table:t.table,token:t.token,url:F({cwd:e,prod:t.prod===!0,url:t.url}),yes:t.yes===!0});return{code:n.code,data:n.data,error:n.error}});export{ee as execute,P as runSeedCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as $}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{r as S,a as p}from"../packem_shared/admin-url-DJB8P6Jh.mjs";import{d as k}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as u,exitCodeForStatus as b}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{a as y}from"../packem_shared/resolve-target-C_ZloTvd.mjs";const w="/_lunora/admin/shard-registry/prune",f=["prune"],d=(e,r,a)=>(e.error(r),{code:a,error:r}),g=(e,r,a)=>{for(const{shardKey:t,table:n}of r.released)e.info(`${a?"would release":"released"} ${t} (${n})`);for(const{message:t,shardKey:n,tables:l}of r.failed)e.error(`could not check ${n} (${l.join(", ")}) — kept: ${t}`);const s=`${String(r.released.length)} ${a?"would be released":"released"}, ${String(r.kept.length)} kept (still hold rows), ${String(r.failed.length)} unreachable`;r.failed.length>0?e.warn(`${s} — re-run to retry the unreachable shards`):e.success(s)},A=async e=>{const{logger:r}=e;if(!f.includes(e.subcommand))return d(r,`shards: unknown subcommand "${e.subcommand??""}" — expected ${f.join(" | ")}`,u.USAGE);if(e.prod&&e.url===void 0)return d(r,"--prod requires an explicit --url (refusing to prune the implicit localhost worker)",u.USAGE);const a=S(e.url,r,e.cwd);if(a===void 0)return{code:u.USAGE,error:"could not resolve a usable worker URL"};const{token:s}=$({cwd:e.cwd??process.cwd(),token:e.token,url:a});if(!s)return d(r,"admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)",u.AUTH);const t=`${a}${w}`,n=e.fetchImpl??p,l=e.tables?.split(",").map(h=>h.trim()).filter(h=>h!==""),i=e.dryRun===!0;r.info(`POST ${t} -> shards prune${i?" (dry run)":""}`);const c=await n(t,{body:JSON.stringify({dryRun:i,...l===void 0?{}:{tables:l}}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST"}),m=await c.text();if(!c.ok)return d(r,`shards prune failed: HTTP ${String(c.status)}: ${m}`,b(c.status));let o;try{o=JSON.parse(m)}catch{return d(r,`shards prune failed: worker returned non-JSON: ${m}`,1)}return e.format!=="json"&&g(r,o,i),o.failed.length>0?{code:1,error:`shards prune: ${String(o.failed.length)} shard(s) could not be checked`,result:o}:{code:0,result:o}},E=k(async({argument:e,cwd:r,format:a,logger:s,options:t})=>{const n=await A({cwd:r,dryRun:t.dryRun===!0,format:a,logger:s,prod:t.prod,subcommand:e[0],tables:t.tables,token:t.token,url:y({cwd:r,prod:t.prod===!0,url:t.url})});return{code:n.code,data:n.result,error:n.error}});export{E as execute,A as runShardsCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{existsSync as h}from"node:fs";import{join as p}from"node:path";import{runCodegen as g}from"@lunora/codegen";import{resolveLazyFunctions as u}from"@lunora/config";import{validateWranglerProject as v,wranglerCodegenInputs as y}from"@lunora/config/cloudflare";import{a as w,e as S,r as k}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as j}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{r as E}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{d as A}from"../packem_shared/command-CB4JM-Jl.mjs";import{r as D}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as R}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as $,p as b}from"../packem_shared/health-probe-Bw9JFfIy.mjs";import{defaultSpawner as F}from"../packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{execArgsFor as U,detectPackageManager as x}from"@lunora/config/cli";const P=async(r,a,t)=>{if(!h(p(r,"tsconfig.json")))return{warning:"no tsconfig.json found — skipping TypeScript type-check"};const o=U(x(r),"tsc",["--noEmit","-p","tsconfig.json"]),e=await a({args:o.args,command:o.command,cwd:r,stdoutToStderr:t==="json"});return e.code===0?{}:{error:`type errors: tsc --noEmit exited ${String(e.code)}`}},T=async(r,a)=>{if(r.healthUrl===void 0||r.healthUrl==="")return;const t=await b({baseUrl:r.healthUrl,fetchImpl:r.healthFetch});if(t.error===void 0){a.success(`verify: health probe ok (${t.url})`);return}return t.error},z=(r,a)=>{const{errorAdvisories:t,names:o,shouldBlock:e}=S(r,k(a));if(e)return`${t.length.toString()} ERROR-level ${t.length===1?"advisory":"advisories"} (${o.join(", ")}). Pass --no-strict-advisories to downgrade this to a warning and continue.`},C=(r,a,t,o)=>{if(a.length===0&&t.length===0)return r.success("verify: project is valid"),{code:0,errors:[],warnings:[],wranglerPath:o};if(t.length>0){r.warn("verify: warnings:");for(const e of t)r.warn(` - ${e}`)}if(a.length>0){r.error("verify: errors:");for(const e of a){r.error(` - ${e}`);const s=E(e);s!==void 0&&r.error(s)}return{code:1,error:a[0],errors:a,warnings:t,wranglerPath:o}}return r.success("verify: project is valid (with warnings)"),{code:0,errors:[],warnings:t,wranglerPath:o}},H=async r=>{const a=r.cwd??process.cwd(),{logger:t}=r,o=v({environment:r.env,projectRoot:a}),e=[...o.report.errors],s=[...o.report.warnings];try{const n=D(a,r.target);if(n.target===void 0){const c=n.error??"unknown deploy target";return t.error(c),{code:R.USAGE,error:c,errors:[c],warnings:[],wranglerPath:void 0}}const i=g({apiSpec:r.apiSpec,lazyFunctions:u(r.lazyFunctions),dryRun:!0,projectRoot:a,target:n.target,...y(a)}),l=w(i.platformDiagnostics,t);e.push(...l.errors),s.push(...l.warnings);const f=z(i.advisories,r);f!==void 0&&e.push(f);const m=$({allowDrift:r.allowSchemaDrift===!0,codegen:i,command:"verify",logger:t,readOnly:!0});m.blocked&&e.push(m.reason)}catch(n){const i=n instanceof Error?n.message:String(n);e.push(`codegen failed: ${i}`)}if(r.typecheck!==!1){const n=await P(a,r.spawner??F,r.format??"pretty");n.error!==void 0&&e.push(n.error),n.warning!==void 0&&s.push(n.warning)}const d=await T(r,t);return d!==void 0&&e.push(d),C(t,e,s,o.wranglerPath)},Q=A(async({cwd:r,format:a,logger:t,options:o})=>{const e=await H({allowSchemaDrift:o.allowSchemaDrift===!0,apiSpec:j(o.apiSpec),lazyFunctions:u(o.lazyFunctions),cwd:r,env:o.env,format:a,healthUrl:o.healthUrl,logger:t,strictAdvisories:o.strictAdvisories,target:o.target,typecheck:o.typecheck===!1?!1:void 0});return{code:e.code,data:{errors:e.errors,warnings:e.warnings,wranglerPath:e.wranglerPath},error:e.error}});export{Q as execute,H as runVerifyCommand};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)},T=e=>e.coverage==="exempt"?[` exempt: ${e.exemptReason===void 0||e.exemptReason===""?"no reason given":e.exemptReason}`]:e.checks.map(r=>{const n=r.occurrences>1?`, ×${String(r.occurrences)}`:"";return` ${r.name} (−${String(r.weight)}${n})`}),B=e=>{const r=new Map;for(const n of e){const t=r.get(n.file);t===void 0?r.set(n.file,[n]):t.push(n)}return[...r].toSorted(([n],[t])=>b(n,t))},I=e=>{const r=f(e.procedures),n=[`advisor health ${String(e.score)}/100 — ${e.grade}`,"",` legend: ${l.clean} clean ${l.warned} warned ${l.failing} failing ${l.exempt} exempt`];for(const[t,o]of B(e.procedures)){n.push("",` ${t}`);for(const i of o)n.push(g(i,r),...T(i))}return n.join(`
|
|
3
|
-
`)},L=(e,r)=>{const n=e.procedures.find(o=>o.id===r);if(n===void 0){const o=e.procedures.slice(0,10).map(i=>` ${i.id}`);return[`no procedure ${r} in the map. Known ids:`,...o,e.procedures.length>10?" …":""].filter(Boolean).join(`
|
|
4
|
-
`)}const t=[`${R(n)} — ${String(n.score)}/100, ${n.coverage}`,` weight in the global mean: ${String(n.weight)}`];if(n.checks.length===0)return t.push(""," no rule fired"),t.join(`
|
|
5
|
-
`);t.push(""," rules fired:");for(const o of n.checks)t.push(` [${o.level}] ${o.name} −${String(o.weight)}${o.occurrences>1?` (×${String(o.occurrences)})`:""}`);return t.join(`
|
|
6
|
-
`)},N=new Date(0).toISOString(),m=(e,r)=>v(r)?r:w(e,r),P=e=>{if(e===void 0)return{value:void 0};if(e===null||e==="")return{error:"--min-score needs a value between 0 and 100"};const r=Number(e);return Number.isFinite(r)&&r>=0&&r<=100?{value:r}:{error:"--min-score must be a number between 0 and 100"}},_=(e,r,n)=>{const t=m(r,n===null||n===""?u:n);if(!S(t))return{error:`baseline not found at ${t} — generate one with \`lunora advisor\` and commit it`};const o=x(JSON.parse(p(t,"utf8")));return o===void 0?{error:`baseline at ${t} is malformed — regenerate it with \`lunora advisor\``}:{comparison:j(e,o)}},z=e=>`baseline is not comparable (${e}) — regenerate it; this run verified nothing`,G=(e,r,n)=>r.entry!==void 0?L(e,r.entry):r.all===!0?I(e):C(e,n),H=e=>{const r=e.cwd??process.cwd(),n=e.format==="json",{logger:t}=e,o=P(e.minScore);if("error"in o)return e.logger.error(o.error),{code:E.USAGE,error:o.error};const{advisorContext:i,advisories:$}=A({dryRun:!0,lazyFunctions:M(),projectRoot:r,...F(r)}),a=y(i?.procedureProtections??[],$,{generatedAt:e.generatedAt??N}),s={map:a};if(e.baseline!==void 0){const c=_(a,r,e.baseline);if("error"in c)return e.logger.error(c.error),{...s,error:c.error};s.comparison=c.comparison,c.comparison.comparable||e.logger.error(z(c.comparison.reason))}if(e.write!==!1){const c=m(r,e.out??u);h(c,`${JSON.stringify(a,void 0,4)}
|
|
7
|
-
`,"utf8"),s.written=c}return s.belowMinScore=o.value!==void 0&&a.score<o.value,s.belowMinScore&&t.error(`advisor score ${String(a.score)} is below the required ${String(o.value)}`),n||(t.info(G(a,e,s.comparison)),s.written!==void 0&&t.success(`wrote ${s.written}`)),s},J=e=>e.error!==void 0||e.belowMinScore===!0?!0:e.comparison!==void 0&&(!e.comparison.comparable||e.comparison.regressed),Z=D(({cwd:e,format:r,logger:n,options:t})=>{const o=H({all:t.all,baseline:t.baseline,cwd:e,entry:t.entry,format:r,logger:n,minScore:t.minScore,out:t.out,write:t.write});return{code:o.code??(J(o)?1:0),data:{belowMinScore:o.belowMinScore,comparison:o.comparison,map:o.map,written:o.written},error:o.error}});export{Z as execute,H as runAdvisorCommand};
|
|
1
|
+
import{readLiveDevServerState as c}from"@lunora/config";import{d as i}from"../packem_shared/command-CB4JM-Jl.mjs";import{o as a}from"../packem_shared/open-url-EnKy--w-.mjs";const n="http://127.0.0.1:6173",d="/__lunora",u=/\/$/u,l=r=>{const e=c(r);return e===void 0?n:e.studioUrl!==void 0?e.studioUrl:e.mode==="vite"?`${e.url.replace(u,"")}${d}`:n},m=async r=>{const e=l(r.cwd??process.cwd()),{logger:t}=r;t.info(`opening ${e}`);try{await a(e,{opener:r.opener})}catch(o){const s=o instanceof Error?o.message:String(o);return t.error(`view: failed to open URL: ${s}`),{code:1,url:e}}return{code:0,url:e}},v=i(({cwd:r,logger:e})=>m({cwd:r,logger:e}));export{v as execute,m as runViewCommand};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{writeFileSync as h,existsSync as S,readFileSync as p}from"node:fs";import{isAbsolute as v,join as w}from"node:path";import{byCodepoint as b,scoreAdvisor as y,parseAdvisorMap as x,compareToBaseline as j}from"@lunora/advisor";import{runCodegen as A}from"@lunora/codegen";import{resolveLazyFunctions as M}from"@lunora/config";import{wranglerCodegenInputs as F}from"@lunora/config/cloudflare";import{d as D}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as E}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{D as u}from"../packem_shared/cli-BbgDNGew.mjs";const l={clean:"·",exempt:"–",failing:"✗",warned:"!"},d=(e,r)=>e.length>=r?e:e+" ".repeat(r-e.length),R=e=>`${e.id} (${e.visibility} ${e.kind})`,f=e=>{let r=0;for(const n of e)r=Math.max(r,n.id.length);return r},g=(e,r)=>` ${d(String(e.score),3)} ${l[e.coverage]} ${d(e.id,r)} ${e.visibility} ${e.kind}`,k=e=>{if(!e.comparable)return[` baseline not comparable (${e.reason}) — regenerate it; this run cannot verify anything`];if(!e.regressed)return[` no regression against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];const r=[` REGRESSED against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];for(const n of e.dropped)r.push(` ${n.id}: ${String(n.before)} → ${String(n.after)}`);for(const n of e.newFailing)r.push(` ${n}: now failing`);for(const n of e.worsened)r.push(` ${n}: more findings than the baseline`);return e.projectRegressed&&r.push(" project: new schema/config rules fired"),r},C=(e,r)=>{const n=e.procedures.filter(i=>i.coverage!=="clean"&&i.coverage!=="exempt"),t=f(n),o=[`advisor health ${String(e.score)}/100 — ${e.grade}`,` ${String(e.summary.clean)} clean · ${String(e.summary.warned)} warned · ${String(e.summary.failing)} failing · ${String(e.summary.exempt)} exempt (${String(e.summary.procedures)} procedures, ${String(e.summary.rulesFired)} rules fired)`];return e.project.checks.length>0&&o.push("",` project ${String(e.project.score)}/100 — ${e.project.checks.map(i=>i.name).join(", ")}`),n.length>0&&o.push("",...n.map(i=>g(i,t)),""," run with --all for every procedure, or --entry <file#export> for one"),r!==void 0&&o.push("",...k(r)),o.join(`
|
|
2
|
+
`)},T=e=>e.coverage==="exempt"?[` exempt: ${e.exemptReason===void 0||e.exemptReason===""?"no reason given":e.exemptReason}`]:e.checks.map(r=>{const n=r.occurrences>1?`, ×${String(r.occurrences)}`:"";return` ${r.name} (−${String(r.weight)}${n})`}),B=e=>{const r=new Map;for(const n of e){const t=r.get(n.file);t===void 0?r.set(n.file,[n]):t.push(n)}return[...r].toSorted(([n],[t])=>b(n,t))},I=e=>{const r=f(e.procedures),n=[`advisor health ${String(e.score)}/100 — ${e.grade}`,"",` legend: ${l.clean} clean ${l.warned} warned ${l.failing} failing ${l.exempt} exempt`];for(const[t,o]of B(e.procedures)){n.push("",` ${t}`);for(const i of o)n.push(g(i,r),...T(i))}return n.join(`
|
|
3
|
+
`)},L=(e,r)=>{const n=e.procedures.find(o=>o.id===r);if(n===void 0){const o=e.procedures.slice(0,10).map(i=>` ${i.id}`);return[`no procedure ${r} in the map. Known ids:`,...o,e.procedures.length>10?" …":""].filter(Boolean).join(`
|
|
4
|
+
`)}const t=[`${R(n)} — ${String(n.score)}/100, ${n.coverage}`,` weight in the global mean: ${String(n.weight)}`];if(n.checks.length===0)return t.push(""," no rule fired"),t.join(`
|
|
5
|
+
`);t.push(""," rules fired:");for(const o of n.checks)t.push(` [${o.level}] ${o.name} −${String(o.weight)}${o.occurrences>1?` (×${String(o.occurrences)})`:""}`);return t.join(`
|
|
6
|
+
`)},N=new Date(0).toISOString(),m=(e,r)=>v(r)?r:w(e,r),P=e=>{if(e===void 0)return{value:void 0};if(e===null||e==="")return{error:"--min-score needs a value between 0 and 100"};const r=Number(e);return Number.isFinite(r)&&r>=0&&r<=100?{value:r}:{error:"--min-score must be a number between 0 and 100"}},_=(e,r,n)=>{const t=m(r,n===null||n===""?u:n);if(!S(t))return{error:`baseline not found at ${t} — generate one with \`lunora advisor\` and commit it`};const o=x(JSON.parse(p(t,"utf8")));return o===void 0?{error:`baseline at ${t} is malformed — regenerate it with \`lunora advisor\``}:{comparison:j(e,o)}},z=e=>`baseline is not comparable (${e}) — regenerate it; this run verified nothing`,G=(e,r,n)=>r.entry!==void 0?L(e,r.entry):r.all===!0?I(e):C(e,n),H=e=>{const r=e.cwd??process.cwd(),n=e.format==="json",{logger:t}=e,o=P(e.minScore);if("error"in o)return e.logger.error(o.error),{code:E.USAGE,error:o.error};const{advisorContext:i,advisories:$}=A({dryRun:!0,lazyFunctions:M(),projectRoot:r,...F(r)}),a=y(i?.procedureProtections??[],$,{generatedAt:e.generatedAt??N}),s={map:a};if(e.baseline!==void 0){const c=_(a,r,e.baseline);if("error"in c)return e.logger.error(c.error),{...s,error:c.error};s.comparison=c.comparison,c.comparison.comparable||e.logger.error(z(c.comparison.reason))}if(e.write!==!1){const c=m(r,e.out??u);h(c,`${JSON.stringify(a,void 0,4)}
|
|
7
|
+
`,"utf8"),s.written=c}return s.belowMinScore=o.value!==void 0&&a.score<o.value,s.belowMinScore&&t.error(`advisor score ${String(a.score)} is below the required ${String(o.value)}`),n||(t.info(G(a,e,s.comparison)),s.written!==void 0&&t.success(`wrote ${s.written}`)),s},J=e=>e.error!==void 0||e.belowMinScore===!0?!0:e.comparison!==void 0&&(!e.comparison.comparable||e.comparison.regressed),Z=D(({cwd:e,format:r,logger:n,options:t})=>{const o=H({all:t.all,baseline:t.baseline,cwd:e,entry:t.entry,format:r,logger:n,minScore:t.minScore,out:t.out,write:t.write});return{code:o.code??(J(o)?1:0),data:{belowMinScore:o.belowMinScore,comparison:o.comparison,map:o.map,written:o.written},error:o.error}});export{Z as execute,H as runAdvisorCommand};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{randomUUID as $}from"node:crypto";import{readdirSync as D,readFileSync as b,existsSync as d,rmSync as l,mkdirSync as S,copyFileSync as z,writeFileSync as A,lstatSync as j}from"node:fs";import{join as f,resolve as m,dirname as v}from"node:path";import{resolveLazyFunctions as F,DEFAULT_BUNDLE_META_PATH as E}from"@lunora/config";import{p as M}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{d as T}from"../packem_shared/command-CB4JM-Jl.mjs";import{p as _,v as R,r as U}from"./handler.mjs";import{defaultSpawner as x}from"../packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{gzipSync as I}from"node:zlib";const g=64*1024*1024,P=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",C=e=>{let i;try{i=D(e,{recursive:!0,withFileTypes:!0})}catch{return}let o=0,r=0,n=0;for(const t of i){if(!t.isFile()||!P(t.name))continue;const c=b(f(t.parentPath,t.name));o+=1,n+=c.byteLength,r+=I(c).byteLength}return o===0?void 0:{files:o,gzipBytes:r,rawBytes:n}},k=".lunora/build",O=async e=>x({...e,stdoutToStderr:!0}),B=e=>`${(e/1024).toFixed(1)} KiB`,h=e=>d(e)?D(e,{encoding:"utf8",recursive:!0}).map(i=>{try{const o=j(f(e,i));return`${i}:${String(o.size)}:${String(o.mtimeMs)}`}catch{return`${i}:gone`}}).join(`
|
|
2
|
+
`):"",W=async e=>{const i=e.outDir??k,o=e.format==="json",{logger:r}=e,n=e.cwd??process.cwd(),t=m(n,i,"bundle-meta.json"),c=R(n,$()),y=d(t)?b(t):void 0;l(t,{force:!0}),l(c,{force:!0});const w=m(n,i),L=h(w);let s;try{s=await U({allowSchemaDrift:e.allowSchemaDrift,apiSpec:e.apiSpec,bundleMetaPath:c,frameworkBuild:e.frameworkBuild,lazyFunctions:F(e.lazyFunctions),commandName:"build",clientBuildOutputJson:o,cwd:e.cwd,dryRun:!0,emitBindings:e.emitBindings,format:void 0,interactive:o?!1:void 0,logger:r,outDir:i,smokeLauncher:e.smokeLauncher,smokeLoad:e.smokeLoad,spawner:e.spawner??(o?O:void 0),strictAdvisories:e.strictAdvisories,target:e.target});const u=e.frameworkBuild===!1?f(n,E):c;s.code===0&&!d(t)&&d(u)&&(S(v(t),{recursive:!0}),z(u,t))}finally{l(c,{force:!0}),y!==void 0&&!d(t)&&h(w)===L&&s?.code!==0&&(S(v(t),{recursive:!0}),A(t,y))}if(s.code!==0)return s;r.success(`build complete — bundle written to ${i}`);const a=C(m(e.cwd??process.cwd(),i));if(a===void 0)r.warn(`could not weigh the bundle — nothing uploadable was found in ${i}`);else{const u=(a.rawBytes/g*100).toFixed(1),p=`bundle: ${B(a.rawBytes)} raw across ${String(a.files)} file(s) — ${u}% of Cloudflare's 64 MiB uncompressed Worker size limit (${B(a.gzipBytes)} gzipped, for reference; there is no compressed limit)`;a.rawBytes>g?r.warn(`${p} — Cloudflare will reject this upload`):r.info(p)}return{...s,bundle:a}},V=T(async({cwd:e,format:i,logger:o,options:r})=>{const n=_(e,r.root),t=await W({allowSchemaDrift:r.allowSchemaDrift===!0,apiSpec:M(r.apiSpec),lazyFunctions:F(r.lazyFunctions),cwd:n,emitBindings:r.emitBindings,format:i,frameworkBuild:r.frameworkBuild,logger:o,outDir:r.outDir,smokeLoad:r.smokeLoad,strictAdvisories:r.strictAdvisories,target:r.target});return{code:t.code,data:{bundle:t.bundle,deployment:t.deployment,outDir:r.outDir??k,validation:t.validation},error:t.error}});export{V as execute,W as runBuildCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{existsSync as b}from"node:fs";import{readProjectDependencies as w,applyLintIgnores as A,detectLintTools as k}from"@lunora/config";import{findWranglerFile as I}from"@lunora/config/cloudflare";import{join as U,basename as h}from"@visulima/path";import{d as N}from"../packem_shared/command-CB4JM-Jl.mjs";import{EXIT_CODE as o}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as S}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import{t as y,a as E}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{i as _}from"../packem_shared/resolve-Bdc9KEUv.mjs";import{r as D}from"../packem_shared/commands-DvSfLvyt.mjs";import{n as L,i as M,A as P,E as R,s as O,d as f,p as $,r as v,M as j,a as C,b as g,c as F,D as m,e as x,f as H,g as d,h as z,j as B,w as G,k as W,l as V}from"../packem_shared/storage-DNzYhXR-.mjs";const p=e=>{const r=e.trim().toLowerCase();return B.find(a=>a.value===r||a.label.toLowerCase()===r||r==="auth0"&&a.value==="auth-auth0"||r==="clerk"&&a.value==="auth-clerk")?.value},q=async e=>{const r=e.cwd??process.cwd(),t=H(w(r));return t!==void 0?t:e.yes===!0?(e.logger.warn(`add: couldn't detect your framework — using "${d}". Pass a specific item (e.g. \`lunora add auth-ui-vue\`) to override.`),d):await(e.promptSelect??((c,n,i)=>y(c,n,i)))("Which framework is your app?",z,{default:d})??d},X=async e=>{if(e.provider!==void 0&&e.provider!==""){const t=p(e.provider);return t===void 0?(e.logger.warn(`add: unknown --provider "${e.provider}" — using "${m}" (email & password).`),m):t}if(e.yes===!0)return m;const r=e.promptSelect??((t,a,c)=>y(t,a,c));return x(r)},l=e=>e.promptText??((r,t)=>E(r,t)),J=async e=>{const r=h(e.cwd??process.cwd());if(e.bucket!==void 0&&e.bucket!==""){const t=O(e.bucket);if(t!==void 0)return t;const a=f(r);return e.logger.warn(`add: "${e.bucket}" isn't a valid R2 bucket name (lowercase alphanumeric + hyphens, 3–63 chars) — using "${a}".`),a}return e.yes===!0?f(r):$(l(e),r)},K=async e=>{const r=t=>{e.logger.warn(`add: ${t}`)};if(e.mailTo!==void 0&&e.mailTo!=="")return v(e.mailTo,r);if(e.yes!==!0)return v(await l(e)(j,{placeholder:"you@yourdomain.com"}),r)},Q=async e=>{const r=h(e.cwd??process.cwd());if(e.db!==void 0&&e.db!==""){const t=C(e.db);if(t!==void 0)return t;const a=g(r);return e.logger.warn(`add: "${e.db}" isn't a usable D1 database name — using "${a}".`),a}return e.yes===!0?g(r):F(l(e),r)},Y=async(e,r)=>e.kind==="auth"?[await X(r)]:e.kind==="auth-ui"?[await q(r)]:e.kind==="email"?[R]:[e.item],Z=(e,r)=>{S(A(e,k(e)),r)},ee=e=>!_(e)||e.yes===!0,re=async e=>{const r=e.cwd??process.cwd(),t=e.feature===void 0?void 0:L(e.feature);if(t===void 0)return e.logger.error("add requires a feature or registry item. Usage: lunora add <auth|email|storage|crons|presence|…>"),{code:o.USAGE,items:[]};if(!b(U(r,"lunora"))||I(r)===void 0)return e.logger.error("add: not a Lunora project here (need a lunora/ directory and a wrangler.jsonc). Run `lunora init` first."),{code:o.USAGE,items:[]};if(t.kind==="auth-ui"&&M(w(r)))return e.logger.error(`add: ${P}`),{code:o.USAGE,items:[]};const a=await Y(t,e),c=[];if(a.includes("storage")){const s=await J(e);c.push(u=>G(u,s))}if(a.includes("mail")){const s=await K(e);s!==void 0&&c.push(u=>W(u,s))}if(a.some(s=>s==="auth"||s.startsWith("auth-"))){const s=await Q(e);c.push(u=>V(u,s))}const n=c.length>0?s=>{let u=s;for(const T of c)u=T(u);return u}:void 0,i=await D({allowUnsafeSource:e.allowUnsafeSource,confirm:e.confirm,cwd:r,from:e.from,logger:e.logger,names:[...a],ref:e.ref,source:e.source,transformManifest:n,yes:ee(e)});return i.code===0&&Z(r,e.logger),{code:i.code,items:a}},fe=N(async({argument:e,cwd:r,logger:t,options:a})=>{const c=await re({allowUnsafeSource:a.allowUnsafeSource===!0,bucket:a.bucket,cwd:r,db:a.db,feature:e[0],from:a.from,logger:t,mailTo:a.mailTo,provider:a.provider,ref:a.ref,source:a.source,yes:a.yes===!0});return{code:c.code,data:{items:c.items},...c.error===void 0?{}:{error:c.error}}});export{fe as execute,re as runAddFeature};
|