@lunora/cli 1.0.0-alpha.12 → 1.0.0-alpha.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/bin.mjs +2 -10
- package/dist/index.d.mts +357 -321
- package/dist/index.d.ts +357 -321
- package/dist/index.mjs +1 -19
- package/dist/packem_chunks/handler.mjs +1 -150
- package/dist/packem_chunks/handler10.mjs +1 -22
- package/dist/packem_chunks/handler11.mjs +1 -192
- package/dist/packem_chunks/handler12.mjs +2 -131
- package/dist/packem_chunks/handler13.mjs +2 -65
- package/dist/packem_chunks/handler14.mjs +1 -58
- package/dist/packem_chunks/handler15.mjs +1 -79
- package/dist/packem_chunks/handler16.mjs +1 -43
- package/dist/packem_chunks/handler17.mjs +1 -105
- package/dist/packem_chunks/handler18.mjs +3 -170
- package/dist/packem_chunks/handler19.mjs +1 -89
- package/dist/packem_chunks/handler2.mjs +2 -114
- package/dist/packem_chunks/handler20.mjs +1 -94
- package/dist/packem_chunks/handler21.mjs +2 -311
- package/dist/packem_chunks/handler22.mjs +99 -0
- package/dist/packem_chunks/handler23.mjs +11 -0
- package/dist/packem_chunks/handler3.mjs +2 -204
- package/dist/packem_chunks/handler4.mjs +1 -33
- package/dist/packem_chunks/handler5.mjs +1 -49
- package/dist/packem_chunks/handler6.mjs +1 -91
- package/dist/packem_chunks/handler7.mjs +1 -42
- package/dist/packem_chunks/handler8.mjs +1 -174
- package/dist/packem_chunks/handler9.mjs +8 -16
- package/dist/packem_chunks/planDevCommand.mjs +7 -500
- package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
- package/dist/packem_chunks/runDeployCommand.mjs +1 -504
- package/dist/packem_chunks/runInitCommand.mjs +996 -1265
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +9 -395
- package/dist/packem_chunks/runResetCommand.mjs +1 -41
- package/dist/packem_chunks/runRpcCommand.mjs +1 -68
- package/dist/packem_shared/COMMANDS-P8RHe9Zp.mjs +3 -0
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-DL87PIEl.mjs +8 -0
- package/dist/packem_shared/admin-url-DfVehV3e.mjs +1 -0
- package/dist/packem_shared/api-spec-BENwiyUa.mjs +1 -0
- package/dist/packem_shared/buildRegistryIndex-DwySASBu.mjs +1 -0
- package/dist/packem_shared/codegen-error-DJN6pTH5.mjs +3 -0
- package/dist/packem_shared/command-Bjv4VmYA.mjs +1 -0
- package/dist/packem_shared/commands-BhX2Bo9B.mjs +19 -0
- package/dist/packem_shared/createLogger--C3x1FNE.mjs +2 -0
- package/dist/packem_shared/createRecordingSpawner-ByIqBepG.mjs +1 -0
- package/dist/packem_shared/detect-package-manager-B2eIuAiP.mjs +1 -0
- package/dist/packem_shared/diffSnapshots-9bDd9nOK.mjs +5 -0
- package/dist/packem_shared/docker-CKvYE9YF.mjs +1 -0
- package/dist/packem_shared/insertSchemaExtension-DZReBZ4_.mjs +8 -0
- package/dist/packem_shared/open-url-CTU_g9gr.mjs +1 -0
- package/dist/packem_shared/output-format-D7cKB-O5.mjs +2 -0
- package/dist/packem_shared/parseManifest-x3WsxKHz.mjs +1 -0
- package/dist/packem_shared/prompt-cancelled-C8Sj7OqI.mjs +1 -0
- package/dist/packem_shared/resolve-target-vxaXHmvg.mjs +1 -0
- package/dist/packem_shared/runAddCommand--TBYJQYi.mjs +1 -0
- package/dist/packem_shared/schema-drift-gate-CpqG-xP4.mjs +1 -0
- package/dist/packem_shared/schemaIrToSnapshot-Clwd2A8e.mjs +1 -0
- package/dist/packem_shared/storage-DOvAKGi4.mjs +1 -0
- package/dist/packem_shared/tui-prompts-CCt3jm1k.mjs +4 -0
- package/dist/packem_shared/vectorize-metadata-BvZbbqUD.mjs +1 -0
- package/dist/packem_shared/wrangler-name-HIl0Z6yx.mjs +1 -0
- package/dist/packem_shared/wrangler-secrets-BMRJwKQU.mjs +1 -0
- package/package.json +35 -16
- package/skills/README.md +28 -14
- package/skills/lunora/SKILL.md +48 -9
- package/skills/lunora-functions/SKILL.md +38 -3
- package/skills/lunora-migration-helper/SKILL.md +36 -17
- package/skills/lunora-performance-audit/SKILL.md +36 -6
- package/skills/lunora-quickstart/SKILL.md +86 -24
- package/skills/lunora-realtime/SKILL.md +43 -30
- package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +0 -944
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
- package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
- package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
- package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
- package/dist/packem_shared/command-BC30oSBW.mjs +0 -14
- package/dist/packem_shared/commands-DVr4lduS.mjs +0 -812
- package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
- package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
- package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
- package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
- package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
- package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
- package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
- package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
- package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
- package/dist/packem_shared/runAddCommand-C-NOz8NJ.mjs +0 -4
- package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
- package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
- package/dist/packem_shared/storage-DL9OE4oE.mjs +0 -84
- package/dist/packem_shared/tui-prompts-M6OWsuyw.mjs +0 -663
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
|
@@ -1,174 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { findWranglerFile, readWranglerJsonc, validateWranglerConfig, isPlaceholderValue, DEV_VARS_FILE, parseDevVariableEntries, inferLunoraBindings } from '@lunora/config';
|
|
4
|
-
import { d as defineHandler } from '../packem_shared/command-BC30oSBW.mjs';
|
|
5
|
-
|
|
6
|
-
const SECRET_KEY_PATTERN = /(?:KEY|PASSWORD|SECRET|TOKEN)$/u;
|
|
7
|
-
const isD1PlaceholderId = (databaseId) => {
|
|
8
|
-
const value = databaseId.trim();
|
|
9
|
-
if (value === "") {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
const lower = value.toLowerCase();
|
|
13
|
-
return lower.includes("replace") || lower.startsWith("<") && lower.endsWith(">");
|
|
14
|
-
};
|
|
15
|
-
const readWrangler = (cwd) => {
|
|
16
|
-
const path = findWranglerFile(cwd);
|
|
17
|
-
if (path === void 0) {
|
|
18
|
-
return { parsed: void 0, path: void 0 };
|
|
19
|
-
}
|
|
20
|
-
const { parsed } = readWranglerJsonc(path);
|
|
21
|
-
return { parsed, path };
|
|
22
|
-
};
|
|
23
|
-
const checkWrangler = (parsed, path, findings) => {
|
|
24
|
-
if (path === void 0) {
|
|
25
|
-
findings.push({
|
|
26
|
-
fix: "Run `lunora init` (or `lunora dev`) to scaffold and reconcile wrangler.jsonc.",
|
|
27
|
-
level: "fail",
|
|
28
|
-
message: "wrangler.jsonc not found."
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (parsed === void 0) {
|
|
33
|
-
findings.push({ fix: `Check ${path} is valid JSONC.`, level: "fail", message: `Could not parse ${path}.` });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const report = validateWranglerConfig(parsed);
|
|
37
|
-
const shardError = report.errors.find((error) => error.includes("SHARD"));
|
|
38
|
-
if (shardError === void 0) {
|
|
39
|
-
findings.push({ level: "pass", message: "wrangler.jsonc present with a SHARD durable-object binding." });
|
|
40
|
-
} else {
|
|
41
|
-
findings.push({ fix: "Run `lunora dev` to auto-reconcile, or add the binding manually.", level: "fail", message: shardError });
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const checkD1Placeholders = (parsed, findings) => {
|
|
45
|
-
if (parsed === void 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const databases = (parsed.d1_databases ?? []).filter(Boolean);
|
|
49
|
-
for (const database of databases) {
|
|
50
|
-
const databaseId = typeof database.database_id === "string" ? database.database_id : "";
|
|
51
|
-
if (isD1PlaceholderId(databaseId)) {
|
|
52
|
-
const label = typeof database.binding === "string" && database.binding.length > 0 ? database.binding : "<unnamed>";
|
|
53
|
-
findings.push({
|
|
54
|
-
fix: "Run `wrangler d1 create <name>` and paste the returned database_id into wrangler.jsonc.",
|
|
55
|
-
level: "fail",
|
|
56
|
-
message: `D1 binding "${label}" has a placeholder database_id ("${databaseId || "<empty>"}").`
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const checkEmailDestination = (parsed, findings) => {
|
|
62
|
-
if (parsed === void 0) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const bindings = (parsed.send_email ?? []).filter(Boolean);
|
|
66
|
-
for (const binding of bindings) {
|
|
67
|
-
const destination = typeof binding.destination_address === "string" ? binding.destination_address : "";
|
|
68
|
-
if (destination !== "" && isPlaceholderValue(destination)) {
|
|
69
|
-
const label = typeof binding.name === "string" && binding.name.length > 0 ? binding.name : "send_email";
|
|
70
|
-
findings.push({
|
|
71
|
-
fix: "Set destination_address to a verified Cloudflare Email Routing address.",
|
|
72
|
-
level: "warn",
|
|
73
|
-
message: `send_email binding "${label}" has a placeholder destination_address ("${destination}").`
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const checkDevVariables = (cwd, findings) => {
|
|
79
|
-
const devVariablesPath = join(cwd, DEV_VARS_FILE);
|
|
80
|
-
if (!existsSync(devVariablesPath)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
let content;
|
|
84
|
-
try {
|
|
85
|
-
content = readFileSync(devVariablesPath, "utf8");
|
|
86
|
-
} catch {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const unfilled = parseDevVariableEntries(content).filter((entry) => SECRET_KEY_PATTERN.test(entry.key) && isPlaceholderValue(entry.value)).map((entry) => entry.key);
|
|
90
|
-
if (unfilled.length > 0) {
|
|
91
|
-
findings.push({
|
|
92
|
-
fix: "Run `lunora dev` to auto-generate secrets, or fill them in by hand.",
|
|
93
|
-
level: "warn",
|
|
94
|
-
message: `${DEV_VARS_FILE} has unfilled secret value(s): ${unfilled.join(", ")}.`
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const checkAdminToken = (findings) => {
|
|
99
|
-
const token = process.env.LUNORA_ADMIN_TOKEN;
|
|
100
|
-
if (token === void 0 || token.trim() === "") {
|
|
101
|
-
findings.push({
|
|
102
|
-
fix: "Set LUNORA_ADMIN_TOKEN (env or `.dev.vars`) to enable admin RPCs / studio.",
|
|
103
|
-
level: "info",
|
|
104
|
-
message: "LUNORA_ADMIN_TOKEN is not set."
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
findings.push({ level: "pass", message: "LUNORA_ADMIN_TOKEN is set." });
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const checkContainers = async (cwd, findings) => {
|
|
111
|
-
let containers;
|
|
112
|
-
try {
|
|
113
|
-
({ containers } = await inferLunoraBindings({ projectRoot: cwd }));
|
|
114
|
-
} catch {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
for (const container of containers) {
|
|
118
|
-
if (container.exported) {
|
|
119
|
-
findings.push({ level: "pass", message: `container "${container.exportName}" is exported by the worker entry.` });
|
|
120
|
-
} else {
|
|
121
|
-
findings.push({
|
|
122
|
-
fix: 'Add `export * from "./lunora/_generated/containers"` to your worker entry (or re-run `vis generate lunora-container`).',
|
|
123
|
-
level: "fail",
|
|
124
|
-
message: `container "${container.exportName}" is declared but ${container.className} is not exported by the worker entry.`
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
const runDoctor = async (options) => {
|
|
130
|
-
const cwd = options.cwd ?? process.cwd();
|
|
131
|
-
const findings = [];
|
|
132
|
-
const { parsed, path } = readWrangler(cwd);
|
|
133
|
-
checkWrangler(parsed, path, findings);
|
|
134
|
-
checkD1Placeholders(parsed, findings);
|
|
135
|
-
checkEmailDestination(parsed, findings);
|
|
136
|
-
checkDevVariables(cwd, findings);
|
|
137
|
-
checkAdminToken(findings);
|
|
138
|
-
await checkContainers(cwd, findings);
|
|
139
|
-
const code = findings.some((finding) => finding.level === "fail") ? 1 : 0;
|
|
140
|
-
return { code, findings };
|
|
141
|
-
};
|
|
142
|
-
const LEVEL_LABEL = { fail: "FAIL", info: "INFO", pass: "PASS", warn: "WARN" };
|
|
143
|
-
const renderReport = (result, logger) => {
|
|
144
|
-
logger.info("lunora doctor — project preflight");
|
|
145
|
-
for (const finding of result.findings) {
|
|
146
|
-
const line = `[${LEVEL_LABEL[finding.level]}] ${finding.message}`;
|
|
147
|
-
if (finding.level === "fail") {
|
|
148
|
-
logger.error(line);
|
|
149
|
-
} else if (finding.level === "warn") {
|
|
150
|
-
logger.warn(line);
|
|
151
|
-
} else {
|
|
152
|
-
logger.info(line);
|
|
153
|
-
}
|
|
154
|
-
if (finding.fix !== void 0 && finding.level !== "pass") {
|
|
155
|
-
logger.info(` fix: ${finding.fix}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const fails = result.findings.filter((finding) => finding.level === "fail").length;
|
|
159
|
-
const warns = result.findings.filter((finding) => finding.level === "warn").length;
|
|
160
|
-
if (fails > 0) {
|
|
161
|
-
logger.error(`${String(fails)} failure(s), ${String(warns)} warning(s).`);
|
|
162
|
-
} else if (warns > 0) {
|
|
163
|
-
logger.warn(`0 failures, ${String(warns)} warning(s).`);
|
|
164
|
-
} else {
|
|
165
|
-
logger.success("all checks passed.");
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const execute = defineHandler(async ({ cwd, logger }) => {
|
|
169
|
-
const result = await runDoctor({ cwd});
|
|
170
|
-
renderReport(result, logger);
|
|
171
|
-
return { code: result.code };
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
export { execute, runDoctor };
|
|
1
|
+
import{existsSync as g,readFileSync as m}from"node:fs";import{join as h}from"node:path";import{findWranglerFile as w,readWranglerJsonc as $,validateWranglerConfig as x,isPlaceholderValue as v,DEV_VARS_FILE as p,parseDevVariableEntries as y,discoverSchemaInfo as b,inferLunoraBindings as S}from"@lunora/config";import{i as _}from"../packem_shared/command-Bjv4VmYA.mjs";import{o as N,p as R}from"../packem_shared/vectorize-metadata-BvZbbqUD.mjs";const k=/(?:KEY|PASSWORD|SECRET|TOKEN)$/u,A=a=>{const e=a.trim();if(e==="")return!0;const n=e.toLowerCase();return n.includes("replace")||n.startsWith("<")&&n.endsWith(">")},j=a=>{const e=w(a);if(e===void 0)return{parsed:void 0,path:void 0};const{parsed:n}=$(e);return{parsed:n,path:e}},O=(a,e,n)=>{if(e===void 0){n.push({fix:"Run `lunora init` (or `lunora dev`) to scaffold and reconcile wrangler.jsonc.",level:"fail",message:"wrangler.jsonc not found."});return}if(a===void 0){n.push({fix:`Check ${e} is valid JSONC.`,level:"fail",message:`Could not parse ${e}.`});return}const r=x(a).errors.find(t=>t.includes("SHARD"));r===void 0?n.push({level:"pass",message:"wrangler.jsonc present with a SHARD durable-object binding."}):n.push({fix:"Run `lunora dev` to auto-reconcile, or add the binding manually.",level:"fail",message:r})},D=(a,e)=>{const{info:n}=b(a,"lunora");for(const r of n?.vectorMetadata??[]){const t=R(r.kind);if(t===void 0){e.push({fix:"Filter on a string, number or boolean column, or drop it from `metadata`.",level:"warn",message:`vector index "${r.index}" declares metadata "${r.property}", whose type Vectorize cannot filter on.`});continue}e.push({fix:`wrangler ${N({index:r.index,property:r.property,type:t}).join(" ")}`,level:"info",message:`vector index "${r.index}" filters on metadata "${r.property}" — that needs a Vectorize metadata index (\`lunora deploy\` creates it).`})}},E=(a,e)=>{if(a===void 0)return;const n=(a.d1_databases??[]).filter(Boolean);for(const r of n){const t=typeof r.database_id=="string"?r.database_id:"";if(A(t)){const o=typeof r.binding=="string"&&r.binding.length>0?r.binding:"<unnamed>";e.push({fix:"Run `wrangler d1 create <name>` and paste the returned database_id into wrangler.jsonc.",level:"fail",message:`D1 binding "${o}" has a placeholder database_id ("${t||"<empty>"}").`})}}},L=(a,e)=>{if(a===void 0)return;const n=(a.send_email??[]).filter(Boolean);for(const r of n){const t=typeof r.destination_address=="string"?r.destination_address:"";if(t!==""&&v(t)){const o=typeof r.name=="string"&&r.name.length>0?r.name:"send_email";e.push({fix:"Set destination_address to a verified Cloudflare Email Routing address.",level:"warn",message:`send_email binding "${o}" has a placeholder destination_address ("${t}").`})}}},I=(a,e)=>{const n=h(a,p);if(!g(n))return;let r;try{r=m(n,"utf8")}catch{return}const t=y(r).filter(o=>k.test(o.key)&&v(o.value)).map(o=>o.key);t.length>0&&e.push({fix:"Run `lunora dev` to auto-generate secrets, or fill them in by hand.",level:"warn",message:`${p} has unfilled secret value(s): ${t.join(", ")}.`})},C=a=>{const e=process.env.LUNORA_ADMIN_TOKEN;e===void 0||e.trim()===""?a.push({fix:"Set LUNORA_ADMIN_TOKEN (env or `.dev.vars`) to enable admin RPCs / studio.",level:"info",message:"LUNORA_ADMIN_TOKEN is not set."}):a.push({level:"pass",message:"LUNORA_ADMIN_TOKEN is set."})},W=async(a,e)=>{let n;try{({containers:n}=await S({projectRoot:a}))}catch{return}for(const r of n)r.exported?e.push({level:"pass",message:`container "${r.exportName}" is exported by the worker entry.`}):e.push({fix:'Add `export * from "./lunora/_generated/containers"` to your worker entry (or re-run `vis generate lunora-container`).',level:"fail",message:`container "${r.exportName}" is declared but ${r.className} is not exported by the worker entry.`})},M=/^[\^~><= ]+/u,z=/^(?<core>\d+\.\d+\.\d+)(?:-(?<channel>[a-z]+)\.(?<counter>\d+))?$/u,F=a=>{const e=a.replace(M,"").trim(),n=z.exec(e);if(!n?.groups)return;const{channel:r,core:t,counter:o}=n.groups;return{channel:r??"",core:t??"",counter:o===void 0?void 0:Number.parseInt(o,10),raw:e}},K=(a,e)=>{const n=h(a,"package.json");if(!g(n))return;let r;try{r=JSON.parse(m(n,"utf8"))}catch{return}const t={...r.devDependencies,...r.dependencies},o=[];for(const[s,i]of Object.entries(t)){if(s!=="lunorash"&&!s.startsWith("@lunora/"))continue;const f=F(i);f&&o.push({name:s,version:f})}if(o.length<2)return;const d=s=>s.map(i=>`${i.name}@${i.version.raw}`).join(", "),u=new Set(o.map(s=>s.version.core)),c=new Set(o.map(s=>s.version.channel));if(u.size>1){e.push({fix:'Run `pnpm update "@lunora/*" lunorash` (or `npm`/`yarn` equivalent) so every Lunora package moves to the same release.',level:"warn",message:`Lunora packages span ${String(u.size)} different versions: ${d(o)}.`});return}if(c.size>1){e.push({fix:"Pick one channel (all stable, or all alpha/beta) and update the odd package out.",level:"warn",message:`Lunora packages mix release channels (${[...c].map(s=>s===""?"stable":s).join(" + ")}): ${d(o)}.`});return}const l=o.map(s=>s.version.counter).filter(s=>s!==void 0);if(l.length>1){const s=Math.min(...l),i=Math.max(...l);e.push({level:"info",message:l.length===o.length&&s===i?`Lunora packages are all at ${[...c][0]??""}.${String(i)}.`:`Lunora pre-release counters span ${String(s)}–${String(i)}: ${d(o)}.`})}},T=async a=>{const e=a.cwd??process.cwd(),n=[],{parsed:r,path:t}=j(e);return O(r,t,n),E(r,n),L(r,n),I(e,n),C(n),K(e,n),D(e,n),await W(e,n),{code:n.some(o=>o.level==="fail")?1:0,findings:n}},V={fail:"FAIL",info:"INFO",pass:"PASS",warn:"WARN"},P=(a,e)=>{e.info("lunora doctor — project preflight");for(const t of a.findings){const o=`[${V[t.level]}] ${t.message}`;t.level==="fail"?e.error(o):t.level==="warn"?e.warn(o):e.info(o),t.fix!==void 0&&t.level!=="pass"&&e.info(` fix: ${t.fix}`)}const n=a.findings.filter(t=>t.level==="fail").length,r=a.findings.filter(t=>t.level==="warn").length;n>0?e.error(`${String(n)} failure(s), ${String(r)} warning(s).`):r>0?e.warn(`0 failures, ${String(r)} warning(s).`):e.success("all checks passed.")},Y=_(async({cwd:a,logger:e})=>{const n=await T({cwd:a});return P(n,e),{code:n.code}});export{Y as execute,T as runDoctor};
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
prod: options.prod === true,
|
|
10
|
-
tables: options.tables,
|
|
11
|
-
token: options.token,
|
|
12
|
-
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url })
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
export { execute };
|
|
1
|
+
import{existsSync as f,readFileSync as m,writeFileSync as $}from"node:fs";import{join as S}from"node:path";import{DEV_VARS_FILE as d,DEV_VARS_KEY_PATTERN as b,generateSecretValue as _,DEV_VARS_EXAMPLE_FILE as v,parseDevVariableEntries as E,isPlaceholderValue as x,packageNamesFromBindings as R,inferLunoraBindings as z,requiredSecrets as L,isMintableSecretKey as k}from"@lunora/config";import{i as K}from"../packem_shared/command-Bjv4VmYA.mjs";import{P as Y,M as q}from"../packem_shared/detect-package-manager-B2eIuAiP.mjs";import{defaultSpawner as U}from"../packem_shared/createRecordingSpawner-ByIqBepG.mjs";import{f as j}from"../packem_shared/wrangler-secrets-BMRJwKQU.mjs";const C=/[\r\n]/u,F=/["\\]/u,V=e=>{const o=new Map;for(const t of E(e))o.set(t.key,t);return o},M=e=>e.replaceAll(/[.*+?^${}()|[\]\\]/gu,String.raw`\$&`),w=(e,o)=>new RegExp(String.raw`^[ \t]*${M(e)}[ \t]*=.*(\r?\n|$)`,o?"gmu":"mu"),P=(e,o,t)=>{const r=`${o}="${t}"`;if(!w(o,!1).test(e))return e===""?`${r}
|
|
2
|
+
`:e.endsWith(`
|
|
3
|
+
`)?`${e}${r}
|
|
4
|
+
`:`${e}
|
|
5
|
+
${r}
|
|
6
|
+
`;let s=!1;return e.replace(w(o,!0),(i,n)=>s?"":(s=!0,`${r}${n}`))},Z=(e,o)=>e.replaceAll(new RegExp(String.raw`^[ \t]*${o}[ \t]*=.*(?:\r?\n|$)`,"gmu"),""),A=e=>e.length<=4?"****":`${e.slice(0,4)}${"*".repeat(Math.min(8,e.length-4))}`,g=e=>f(e)?V(m(e,"utf8")):new Map,D=e=>{const o=g(e.devVariablesPath);if(o.size===0)return e.logger.info(`${d}: (empty)`),{code:0,descriptors:[]};for(const t of o.values())e.logger.info(`${t.key}=${A(t.value)}`);return{code:0,descriptors:[]}},B=e=>{const{devVariablesPath:o,logger:t,options:r}=e;if(!r.key)return t.error("env get requires a key. Usage: lunora env get <KEY>"),{code:1,descriptors:[]};const s=g(o).get(r.key);return s?(process.stdout.write(`${s.value}
|
|
7
|
+
`),{code:0,descriptors:[]}):(t.error(`env: ${r.key} is not set in ${d}`),{code:1,descriptors:[]})},I=e=>{const{devVariablesPath:o,logger:t,options:r}=e;if(!r.key)return t.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>"),{code:1,descriptors:[]};if(!b.test(r.key))return t.error(`env: invalid key "${r.key}" — must match [A-Za-z_][A-Za-z0-9_]*`),{code:1,descriptors:[]};if(r.value===void 0)return t.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>"),{code:1,descriptors:[]};if(C.test(r.value))return t.error(`env: value for "${r.key}" contains a newline, which .dev.vars cannot represent`),{code:1,descriptors:[]};if(F.test(r.value))return t.error(`env: value for "${r.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`),{code:1,descriptors:[]};const s=f(o)?m(o,"utf8"):"";return $(o,P(s,r.key,r.value),"utf8"),t.success(`env: set ${r.key} (${A(r.value)}) in ${d}`),{code:0,descriptors:[]}},N=e=>{const{devVariablesPath:o,logger:t,options:r}=e;if(!r.key)return t.error("env unset requires a key. Usage: lunora env unset <KEY>"),{code:1,descriptors:[]};const s=f(o)?m(o,"utf8"):"";return V(s).has(r.key)?($(o,Z(s,r.key),"utf8"),t.success(`env: unset ${r.key} in ${d}`),{code:0,descriptors:[]}):(t.warn(`env: ${r.key} was not set in ${d}`),{code:0,descriptors:[]})},T=async e=>{const{devVariablesPath:o,logger:t,options:r}=e;if(!r.yes)return t.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm."),{code:1,descriptors:[]};const s=g(o);if(s.size===0)return t.warn(`${d}: nothing to push (empty)`),{code:0,descriptors:[]};const i=r.spawner??U,n=r.cwd??process.cwd(),u=Y(n),p=[];for(const a of s.values()){const l=["secret","put",a.key];r.prod&&l.push("--env","production"),r.temporary&&l.push("--temporary");const c=q(u,"wrangler",l),h={args:c.args,command:c.command,cwd:n,input:a.value};p.push(h),t.info(`pushing ${a.key} -> wrangler secret${r.prod?" (production)":""}`);const y=await i(h);if(y.code!==0)return t.error(`env push: failed at ${a.key} (exit ${String(y.code)})`),{code:y.code,descriptors:p}}return t.success(`env: pushed ${String(s.size)} secret(s)`),{code:0,descriptors:p}},W=e=>(e.options.secretLister??j)({cwd:e.cwd,env:e.options.prod?"production":void 0,temporary:e.options.temporary}),X=async e=>{const{devVariablesPath:o,logger:t}=e,r=await W(e);if(!r.ok)return t.error(`env diff: ${r.error??"failed to list remote secrets"}`),{code:1,descriptors:[]};const s=new Set(g(o).keys()),i=new Set(r.names),n=[...s].filter(a=>!i.has(a)).toSorted((a,l)=>a.localeCompare(l)),u=r.names.filter(a=>!s.has(a)),p=[...s].filter(a=>i.has(a)).toSorted((a,l)=>a.localeCompare(l));for(const a of n)t.info(`local only (run \`lunora env push\`): ${a}`);for(const a of u)t.info(`remote only (in Cloudflare, not ${d}): ${a}`);return t.info(`in both: ${String(p.length)} secret(s)`),n.length===0&&u.length===0&&t.success("env diff: local and remote secret names match"),{code:0,descriptors:[]}},G=e=>{const{cwd:o,devVariablesPath:t,logger:r}=e,s=S(o,v);if(!f(s))return r.info(`env doctor: no ${v} to check against — nothing to validate.`),{code:0,descriptors:[]};const i=E(m(s,"utf8")).map(c=>c.key),n=g(t);if(!f(t))return r.error(`env doctor: ${d} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`),r.info(`expected (from ${v}): ${i.join(", ")}`),{code:1,descriptors:[]};const u=i.filter(c=>!n.has(c)),p=[...n.values()].filter(c=>x(c.value)).map(c=>c.key),a=new Set(i),l=[...n.keys()].filter(c=>!a.has(c));for(const c of u)r.error(`missing: ${c} is in ${v} but not ${d}`);for(const c of p)r.error(`unset: ${c} still has a placeholder value`);for(const c of l)r.info(`extra: ${c} is set locally but not listed in ${v}`);return u.length===0&&p.length===0?(r.success(`env doctor: ${d} looks good (${String(n.size)} var(s)).`),{code:0,descriptors:[]}):{code:1,descriptors:[]}},H=async e=>{let o=[];try{o=R(await z({projectRoot:e.cwd}))}catch{}const t=L(o).map(s=>s.key).filter(s=>k(s)),r=[...g(e.devVariablesPath).keys()].filter(s=>k(s));return[...new Set([...t,...r])]},J=async e=>{const{devVariablesPath:o,logger:t,options:r}=e;let s;if(r.key===void 0){if(s=await H(e),s.length===0)return t.info("env generate: no locally-generatable secrets for this project. Name one explicitly: lunora env generate <KEY>"),{code:0,descriptors:[]}}else{if(!b.test(r.key))return t.error(`env: invalid key "${r.key}" — must match [A-Za-z_][A-Za-z0-9_]*`),{code:1,descriptors:[]};s=[r.key]}const i=s.map(n=>({key:n,value:_()}));if(r.set===!0){let n=f(o)?m(o,"utf8"):"";for(const u of i)n=P(n,u.key,u.value);return $(o,n,"utf8"),t.success(`env: generated ${String(i.length)} secret(s) into ${d}: ${i.map(u=>u.key).join(", ")}`),{code:0,descriptors:[]}}for(const n of i)process.stdout.write(`${n.key}=${n.value}
|
|
8
|
+
`);return{code:0,descriptors:[]}},Q=async e=>{const o=e.cwd??process.cwd(),t={cwd:o,devVariablesPath:S(o,d),logger:e.logger,options:e};switch(e.subcommand){case"diff":return X(t);case"doctor":return G(t);case"generate":return J(t);case"get":return B(t);case"list":return D(t);case"push":return T(t);case"set":return I(t);case"unset":return N(t);default:return e.logger.error(`env: unknown subcommand "${e.subcommand}"`),{code:1,descriptors:[]}}},O=e=>e==="list"||e==="get"||e==="set"||e==="unset"||e==="push"||e==="diff"||e==="doctor"||e==="generate",ce=K(({argument:e,cwd:o,logger:t,options:r})=>{const s=e[0];return O(s)?Q({cwd:o,key:e[1],logger:t,prod:r.prod===!0,set:r.set===!0,subcommand:s,temporary:r.temporary===!0,value:e[2],yes:r.yes===!0}):(t.error(`env: unknown subcommand "${s??""}" — expected list | get | set | unset | push | diff | doctor | generate`),{code:1})});export{ce as execute,Q as runEnvCommand};
|