@lunora/cli 1.0.0-alpha.48 → 1.0.0-alpha.480
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 +33 -0
- package/README.md +3 -1
- package/dist/bin.mjs +3 -10
- package/dist/cli.d.mts +31 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.mjs +1 -0
- package/dist/index.d.mts +1168 -416
- package/dist/index.d.ts +1168 -416
- package/dist/index.mjs +1 -19
- package/dist/packem_chunks/cli.mjs +2 -0
- package/dist/packem_chunks/dispatch.mjs +1 -0
- package/dist/packem_chunks/handler.mjs +61 -157
- package/dist/packem_chunks/handler10.mjs +2 -16
- package/dist/packem_chunks/handler11.mjs +1 -22
- package/dist/packem_chunks/handler12.mjs +1 -192
- package/dist/packem_chunks/handler13.mjs +1 -131
- package/dist/packem_chunks/handler14.mjs +3 -65
- package/dist/packem_chunks/handler15.mjs +1 -58
- package/dist/packem_chunks/handler16.mjs +1 -80
- package/dist/packem_chunks/handler17.mjs +1 -43
- package/dist/packem_chunks/handler18.mjs +1 -105
- package/dist/packem_chunks/handler19.mjs +1 -170
- package/dist/packem_chunks/handler2.mjs +1 -114
- package/dist/packem_chunks/handler20.mjs +1 -94
- package/dist/packem_chunks/handler21.mjs +7 -94
- package/dist/packem_chunks/handler22.mjs +1 -0
- package/dist/packem_chunks/handler23.mjs +3 -0
- package/dist/packem_chunks/handler24.mjs +3 -0
- package/dist/packem_chunks/handler25.mjs +2 -0
- package/dist/packem_chunks/handler26.mjs +1 -0
- package/dist/packem_chunks/handler27.mjs +2 -0
- package/dist/packem_chunks/handler28.mjs +99 -0
- package/dist/packem_chunks/handler29.mjs +3 -0
- package/dist/packem_chunks/handler3.mjs +1 -204
- package/dist/packem_chunks/handler30.mjs +15 -0
- package/dist/packem_chunks/handler31.mjs +1 -0
- package/dist/packem_chunks/handler32.mjs +1 -0
- package/dist/packem_chunks/handler4.mjs +1 -33
- package/dist/packem_chunks/handler5.mjs +1 -49
- package/dist/packem_chunks/handler6.mjs +3 -91
- package/dist/packem_chunks/handler7.mjs +1 -42
- package/dist/packem_chunks/handler8.mjs +1 -174
- package/dist/packem_chunks/handler9.mjs +1 -315
- package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
- package/dist/packem_chunks/runDevCommand.mjs +8 -0
- package/dist/packem_chunks/runInitCommand.mjs +423 -1447
- package/dist/packem_chunks/runResetCommand.mjs +1 -41
- package/dist/packem_chunks/runRpcCommand.mjs +1 -68
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck9tABfr.mjs +1 -0
- package/dist/packem_shared/EXIT_CODE-DQVhSE-1.mjs +1 -0
- package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
- package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
- package/dist/packem_shared/api-spec-lYyq4vL6.mjs +1 -0
- package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
- package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
- package/dist/packem_shared/cap-error-body-YBKO32BF.mjs +1 -0
- package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
- package/dist/packem_shared/cli-manifest-DoQ_3bzs.mjs +1 -0
- package/dist/packem_shared/cloudflare-credentials-BVmZnDZk.mjs +1 -0
- package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
- package/dist/packem_shared/command-BpMv2n0o.mjs +1 -0
- package/dist/packem_shared/commands-CkuCMUP_.mjs +13 -0
- package/dist/packem_shared/createLogger-4TujevyB.mjs +2 -0
- package/dist/packem_shared/createRecordingSpawner-DchLi0gR.mjs +1 -0
- package/dist/packem_shared/deploy-target-resolve-BTCW1Iv4.mjs +1 -0
- package/dist/packem_shared/diffSnapshots-Y1G8am6C.mjs +7 -0
- package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
- package/dist/packem_shared/export-rows-EzdNDYpa.mjs +3 -0
- package/dist/packem_shared/free-port-DjbFhaaT.mjs +1 -0
- package/dist/packem_shared/health-probe-BLnoq_oC.mjs +13 -0
- package/dist/packem_shared/import-3Y59Ry9F.mjs +13 -0
- package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
- package/dist/packem_shared/insertSchemaExtension-CbTH3lCQ.mjs +10 -0
- package/dist/packem_shared/js-literal-FWLi94Lh.mjs +1 -0
- package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
- package/dist/packem_shared/mcp-config-file-GR1Y_CVw.mjs +2 -0
- package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
- package/dist/packem_shared/output-format-DWe_tkTR.mjs +2 -0
- package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
- package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
- package/dist/packem_shared/plan-pog5AvMk.mjs +5 -0
- package/dist/packem_shared/planDevCommand-Bl6OrwXm.mjs +1 -0
- package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
- package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
- package/dist/packem_shared/render-lunora-error-JsLelWwR.mjs +2 -0
- package/dist/packem_shared/resolve-Bdc9KEUv.mjs +5 -0
- package/dist/packem_shared/resolve-target-BRvw8Pf7.mjs +1 -0
- package/dist/packem_shared/runAddCommand-gThKW-ZB.mjs +1 -0
- package/dist/packem_shared/runDeployCommand-ByBuze9W.mjs +1 -0
- package/dist/packem_shared/runExportCommand-_PtkJJDT.mjs +5 -0
- package/dist/packem_shared/runMigrateGenerateCommand-CguLEIZp.mjs +11 -0
- package/dist/packem_shared/schemaIrToSnapshot-Ck7DSPdf.mjs +1 -0
- package/dist/packem_shared/shared-CV7ESvuj.mjs +2 -0
- package/dist/packem_shared/storage-3GOIFVZm.mjs +1 -0
- package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
- package/dist/packem_shared/variables-CPYyJtsL.mjs +1 -0
- package/dist/packem_shared/vectorize-metadata-DK61NmVx.mjs +2 -0
- package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
- package/dist/packem_shared/wrangler-secrets-C9siMBwN.mjs +1 -0
- package/package.json +45 -19
- package/skills/README.md +36 -17
- package/skills/lunora/SKILL.md +158 -65
- package/skills/lunora-cloudflare-audit/SKILL.md +164 -0
- package/skills/lunora-create-package/SKILL.md +98 -84
- package/skills/lunora-deploy/SKILL.md +212 -102
- package/skills/lunora-functions/SKILL.md +367 -60
- package/skills/lunora-migration-helper/SKILL.md +194 -149
- package/skills/lunora-performance-audit/SKILL.md +137 -95
- package/skills/lunora-quickstart/SKILL.md +136 -136
- package/skills/lunora-realtime/SKILL.md +219 -97
- package/skills/lunora-setup-auth/SKILL.md +203 -101
- package/skills/lunora-setup-hyperdrive/SKILL.md +153 -110
- package/skills/lunora-setup-hyperdrive-global/SKILL.md +152 -94
- package/skills/lunora-setup-mail/SKILL.md +87 -113
- package/skills/lunora-setup-scheduler/SKILL.md +133 -97
- package/skills/lunora-setup-storage/SKILL.md +189 -95
- package/dist/packem_chunks/planDevCommand.mjs +0 -541
- package/dist/packem_chunks/runDeployCommand.mjs +0 -594
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
- package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
- 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/codegen-error-DJG-ghs_.mjs +0 -31
- package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
- package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
- 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/prompt-cancelled-APzX1Im-.mjs +0 -9
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
- package/dist/packem_shared/runAddCommand-bnY6-HKb.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-BIsph-Vk.mjs +0 -84
- package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
|
@@ -1,315 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { DEV_VARS_FILE, DEV_VARS_KEY_PATTERN, generateSecretValue, DEV_VARS_EXAMPLE_FILE, parseDevVariableEntries, isPlaceholderValue, packageNamesFromBindings, inferLunoraBindings, requiredSecrets, isMintableSecretKey } from '@lunora/config';
|
|
4
|
-
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
5
|
-
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
6
|
-
import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
|
|
7
|
-
|
|
8
|
-
const NEWLINE_PRESENT = /[\r\n]/u;
|
|
9
|
-
const UNREPRESENTABLE_PRESENT = /["\\]/u;
|
|
10
|
-
const parseDevVariables = (content) => {
|
|
11
|
-
const map = /* @__PURE__ */ new Map();
|
|
12
|
-
for (const entry of parseDevVariableEntries(content)) {
|
|
13
|
-
map.set(entry.key, entry);
|
|
14
|
-
}
|
|
15
|
-
return map;
|
|
16
|
-
};
|
|
17
|
-
const serializeDevVariables = (map) => {
|
|
18
|
-
const lines = [];
|
|
19
|
-
for (const entry of map.values()) {
|
|
20
|
-
lines.push(`${entry.key}="${entry.value}"`);
|
|
21
|
-
}
|
|
22
|
-
return `${lines.join("\n")}
|
|
23
|
-
`;
|
|
24
|
-
};
|
|
25
|
-
const redact = (value) => {
|
|
26
|
-
if (value.length <= 4) {
|
|
27
|
-
return "****";
|
|
28
|
-
}
|
|
29
|
-
return `${value.slice(0, 4)}${"*".repeat(Math.min(8, value.length - 4))}`;
|
|
30
|
-
};
|
|
31
|
-
const loadDevVariables = (devVariablesPath) => {
|
|
32
|
-
if (!existsSync(devVariablesPath)) {
|
|
33
|
-
return /* @__PURE__ */ new Map();
|
|
34
|
-
}
|
|
35
|
-
return parseDevVariables(readFileSync(devVariablesPath, "utf8"));
|
|
36
|
-
};
|
|
37
|
-
const runEnvList = (context) => {
|
|
38
|
-
const map = loadDevVariables(context.devVariablesPath);
|
|
39
|
-
if (map.size === 0) {
|
|
40
|
-
context.logger.info(`${DEV_VARS_FILE}: (empty)`);
|
|
41
|
-
return { code: 0, descriptors: [] };
|
|
42
|
-
}
|
|
43
|
-
for (const entry of map.values()) {
|
|
44
|
-
context.logger.info(`${entry.key}=${redact(entry.value)}`);
|
|
45
|
-
}
|
|
46
|
-
return { code: 0, descriptors: [] };
|
|
47
|
-
};
|
|
48
|
-
const runEnvGet = (context) => {
|
|
49
|
-
const { devVariablesPath, logger, options } = context;
|
|
50
|
-
if (!options.key) {
|
|
51
|
-
logger.error("env get requires a key. Usage: lunora env get <KEY>");
|
|
52
|
-
return { code: 1, descriptors: [] };
|
|
53
|
-
}
|
|
54
|
-
const entry = loadDevVariables(devVariablesPath).get(options.key);
|
|
55
|
-
if (!entry) {
|
|
56
|
-
logger.error(`env: ${options.key} is not set in ${DEV_VARS_FILE}`);
|
|
57
|
-
return { code: 1, descriptors: [] };
|
|
58
|
-
}
|
|
59
|
-
process.stdout.write(`${entry.value}
|
|
60
|
-
`);
|
|
61
|
-
return { code: 0, descriptors: [] };
|
|
62
|
-
};
|
|
63
|
-
const runEnvSet = (context) => {
|
|
64
|
-
const { devVariablesPath, logger, options } = context;
|
|
65
|
-
if (!options.key) {
|
|
66
|
-
logger.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>");
|
|
67
|
-
return { code: 1, descriptors: [] };
|
|
68
|
-
}
|
|
69
|
-
if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
|
|
70
|
-
logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
|
|
71
|
-
return { code: 1, descriptors: [] };
|
|
72
|
-
}
|
|
73
|
-
if (options.value === void 0) {
|
|
74
|
-
logger.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>");
|
|
75
|
-
return { code: 1, descriptors: [] };
|
|
76
|
-
}
|
|
77
|
-
if (NEWLINE_PRESENT.test(options.value)) {
|
|
78
|
-
logger.error(`env: value for "${options.key}" contains a newline, which .dev.vars cannot represent`);
|
|
79
|
-
return { code: 1, descriptors: [] };
|
|
80
|
-
}
|
|
81
|
-
if (UNREPRESENTABLE_PRESENT.test(options.value)) {
|
|
82
|
-
logger.error(`env: value for "${options.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`);
|
|
83
|
-
return { code: 1, descriptors: [] };
|
|
84
|
-
}
|
|
85
|
-
const map = loadDevVariables(devVariablesPath);
|
|
86
|
-
map.set(options.key, { key: options.key, value: options.value });
|
|
87
|
-
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
88
|
-
logger.success(`env: set ${options.key} (${redact(options.value)}) in ${DEV_VARS_FILE}`);
|
|
89
|
-
return { code: 0, descriptors: [] };
|
|
90
|
-
};
|
|
91
|
-
const runEnvUnset = (context) => {
|
|
92
|
-
const { devVariablesPath, logger, options } = context;
|
|
93
|
-
if (!options.key) {
|
|
94
|
-
logger.error("env unset requires a key. Usage: lunora env unset <KEY>");
|
|
95
|
-
return { code: 1, descriptors: [] };
|
|
96
|
-
}
|
|
97
|
-
const map = loadDevVariables(devVariablesPath);
|
|
98
|
-
if (!map.delete(options.key)) {
|
|
99
|
-
logger.warn(`env: ${options.key} was not set in ${DEV_VARS_FILE}`);
|
|
100
|
-
return { code: 0, descriptors: [] };
|
|
101
|
-
}
|
|
102
|
-
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
103
|
-
logger.success(`env: unset ${options.key} in ${DEV_VARS_FILE}`);
|
|
104
|
-
return { code: 0, descriptors: [] };
|
|
105
|
-
};
|
|
106
|
-
const runEnvPush = async (context) => {
|
|
107
|
-
const { devVariablesPath, logger, options } = context;
|
|
108
|
-
if (!options.yes) {
|
|
109
|
-
logger.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm.");
|
|
110
|
-
return { code: 1, descriptors: [] };
|
|
111
|
-
}
|
|
112
|
-
const map = loadDevVariables(devVariablesPath);
|
|
113
|
-
if (map.size === 0) {
|
|
114
|
-
logger.warn(`${DEV_VARS_FILE}: nothing to push (empty)`);
|
|
115
|
-
return { code: 0, descriptors: [] };
|
|
116
|
-
}
|
|
117
|
-
const spawner = options.spawner ?? defaultSpawner;
|
|
118
|
-
const descriptors = [];
|
|
119
|
-
for (const entry of map.values()) {
|
|
120
|
-
const args = ["exec", "wrangler", "secret", "put", entry.key];
|
|
121
|
-
if (options.prod) {
|
|
122
|
-
args.push("--env", "production");
|
|
123
|
-
}
|
|
124
|
-
if (options.temporary) {
|
|
125
|
-
args.push("--temporary");
|
|
126
|
-
}
|
|
127
|
-
const descriptor = {
|
|
128
|
-
args,
|
|
129
|
-
command: "pnpm",
|
|
130
|
-
cwd: options.cwd ?? process.cwd(),
|
|
131
|
-
// `wrangler secret put <name>` reads the value from stdin. We
|
|
132
|
-
// pipe it through the spawner's `input` channel so the secret
|
|
133
|
-
// never lands on the command line, in env, or in shell history.
|
|
134
|
-
input: entry.value
|
|
135
|
-
};
|
|
136
|
-
descriptors.push(descriptor);
|
|
137
|
-
logger.info(`pushing ${entry.key} -> wrangler secret${options.prod ? " (production)" : ""}`);
|
|
138
|
-
const result = await spawner(descriptor);
|
|
139
|
-
if (result.code !== 0) {
|
|
140
|
-
logger.error(`env push: failed at ${entry.key} (exit ${String(result.code)})`);
|
|
141
|
-
return { code: result.code, descriptors };
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
logger.success(`env: pushed ${String(map.size)} secret(s)`);
|
|
145
|
-
return { code: 0, descriptors };
|
|
146
|
-
};
|
|
147
|
-
const fetchRemoteSecretNames = (context) => {
|
|
148
|
-
const lister = context.options.secretLister ?? listRemoteSecrets;
|
|
149
|
-
return lister({
|
|
150
|
-
cwd: context.cwd,
|
|
151
|
-
env: context.options.prod ? "production" : void 0,
|
|
152
|
-
temporary: context.options.temporary
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
const runEnvDiff = async (context) => {
|
|
156
|
-
const { devVariablesPath, logger } = context;
|
|
157
|
-
const remote = await fetchRemoteSecretNames(context);
|
|
158
|
-
if (!remote.ok) {
|
|
159
|
-
logger.error(`env diff: ${remote.error ?? "failed to list remote secrets"}`);
|
|
160
|
-
return { code: 1, descriptors: [] };
|
|
161
|
-
}
|
|
162
|
-
const localKeys = new Set(loadDevVariables(devVariablesPath).keys());
|
|
163
|
-
const remoteKeys = new Set(remote.names);
|
|
164
|
-
const localOnly = [...localKeys].filter((key) => !remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
165
|
-
const remoteOnly = remote.names.filter((name) => !localKeys.has(name));
|
|
166
|
-
const both = [...localKeys].filter((key) => remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
167
|
-
for (const key of localOnly) {
|
|
168
|
-
logger.info(`local only (run \`lunora env push\`): ${key}`);
|
|
169
|
-
}
|
|
170
|
-
for (const key of remoteOnly) {
|
|
171
|
-
logger.info(`remote only (in Cloudflare, not ${DEV_VARS_FILE}): ${key}`);
|
|
172
|
-
}
|
|
173
|
-
logger.info(`in both: ${String(both.length)} secret(s)`);
|
|
174
|
-
if (localOnly.length === 0 && remoteOnly.length === 0) {
|
|
175
|
-
logger.success("env diff: local and remote secret names match");
|
|
176
|
-
}
|
|
177
|
-
return { code: 0, descriptors: [] };
|
|
178
|
-
};
|
|
179
|
-
const runEnvDoctor = (context) => {
|
|
180
|
-
const { cwd, devVariablesPath, logger } = context;
|
|
181
|
-
const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
|
|
182
|
-
if (!existsSync(examplePath)) {
|
|
183
|
-
logger.info(`env doctor: no ${DEV_VARS_EXAMPLE_FILE} to check against — nothing to validate.`);
|
|
184
|
-
return { code: 0, descriptors: [] };
|
|
185
|
-
}
|
|
186
|
-
const exampleKeys = parseDevVariableEntries(readFileSync(examplePath, "utf8")).map((entry) => entry.key);
|
|
187
|
-
const current = loadDevVariables(devVariablesPath);
|
|
188
|
-
if (!existsSync(devVariablesPath)) {
|
|
189
|
-
logger.error(`env doctor: ${DEV_VARS_FILE} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`);
|
|
190
|
-
logger.info(`expected (from ${DEV_VARS_EXAMPLE_FILE}): ${exampleKeys.join(", ")}`);
|
|
191
|
-
return { code: 1, descriptors: [] };
|
|
192
|
-
}
|
|
193
|
-
const missing = exampleKeys.filter((key) => !current.has(key));
|
|
194
|
-
const placeholders = [...current.values()].filter((entry) => isPlaceholderValue(entry.value)).map((entry) => entry.key);
|
|
195
|
-
const exampleKeySet = new Set(exampleKeys);
|
|
196
|
-
const extra = [...current.keys()].filter((key) => !exampleKeySet.has(key));
|
|
197
|
-
for (const key of missing) {
|
|
198
|
-
logger.error(`missing: ${key} is in ${DEV_VARS_EXAMPLE_FILE} but not ${DEV_VARS_FILE}`);
|
|
199
|
-
}
|
|
200
|
-
for (const key of placeholders) {
|
|
201
|
-
logger.error(`unset: ${key} still has a placeholder value`);
|
|
202
|
-
}
|
|
203
|
-
for (const key of extra) {
|
|
204
|
-
logger.info(`extra: ${key} is set locally but not listed in ${DEV_VARS_EXAMPLE_FILE}`);
|
|
205
|
-
}
|
|
206
|
-
if (missing.length === 0 && placeholders.length === 0) {
|
|
207
|
-
logger.success(`env doctor: ${DEV_VARS_FILE} looks good (${String(current.size)} var(s)).`);
|
|
208
|
-
return { code: 0, descriptors: [] };
|
|
209
|
-
}
|
|
210
|
-
return { code: 1, descriptors: [] };
|
|
211
|
-
};
|
|
212
|
-
const resolveMintableKeys = async (context) => {
|
|
213
|
-
let packages = [];
|
|
214
|
-
try {
|
|
215
|
-
packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: context.cwd }));
|
|
216
|
-
} catch {
|
|
217
|
-
}
|
|
218
|
-
const fromPackages = requiredSecrets(packages).map((entry) => entry.key).filter((key) => isMintableSecretKey(key));
|
|
219
|
-
const fromLocal = [...loadDevVariables(context.devVariablesPath).keys()].filter((key) => isMintableSecretKey(key));
|
|
220
|
-
return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
|
|
221
|
-
};
|
|
222
|
-
const runEnvGenerate = async (context) => {
|
|
223
|
-
const { devVariablesPath, logger, options } = context;
|
|
224
|
-
let keys;
|
|
225
|
-
if (options.key === void 0) {
|
|
226
|
-
keys = await resolveMintableKeys(context);
|
|
227
|
-
if (keys.length === 0) {
|
|
228
|
-
logger.info("env generate: no locally-generatable secrets for this project. Name one explicitly: lunora env generate <KEY>");
|
|
229
|
-
return { code: 0, descriptors: [] };
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
|
|
233
|
-
logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
|
|
234
|
-
return { code: 1, descriptors: [] };
|
|
235
|
-
}
|
|
236
|
-
keys = [options.key];
|
|
237
|
-
}
|
|
238
|
-
const generated = keys.map((key) => {
|
|
239
|
-
return { key, value: generateSecretValue() };
|
|
240
|
-
});
|
|
241
|
-
if (options.set === true) {
|
|
242
|
-
const map = loadDevVariables(devVariablesPath);
|
|
243
|
-
for (const entry of generated) {
|
|
244
|
-
map.set(entry.key, entry);
|
|
245
|
-
}
|
|
246
|
-
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
247
|
-
logger.success(`env: generated ${String(generated.length)} secret(s) into ${DEV_VARS_FILE}: ${generated.map((entry) => entry.key).join(", ")}`);
|
|
248
|
-
return { code: 0, descriptors: [] };
|
|
249
|
-
}
|
|
250
|
-
for (const entry of generated) {
|
|
251
|
-
process.stdout.write(`${entry.key}=${entry.value}
|
|
252
|
-
`);
|
|
253
|
-
}
|
|
254
|
-
return { code: 0, descriptors: [] };
|
|
255
|
-
};
|
|
256
|
-
const runEnvCommand = async (options) => {
|
|
257
|
-
const cwd = options.cwd ?? process.cwd();
|
|
258
|
-
const context = {
|
|
259
|
-
cwd,
|
|
260
|
-
devVariablesPath: join(cwd, DEV_VARS_FILE),
|
|
261
|
-
logger: options.logger,
|
|
262
|
-
options
|
|
263
|
-
};
|
|
264
|
-
switch (options.subcommand) {
|
|
265
|
-
case "diff": {
|
|
266
|
-
return runEnvDiff(context);
|
|
267
|
-
}
|
|
268
|
-
case "doctor": {
|
|
269
|
-
return runEnvDoctor(context);
|
|
270
|
-
}
|
|
271
|
-
case "generate": {
|
|
272
|
-
return runEnvGenerate(context);
|
|
273
|
-
}
|
|
274
|
-
case "get": {
|
|
275
|
-
return runEnvGet(context);
|
|
276
|
-
}
|
|
277
|
-
case "list": {
|
|
278
|
-
return runEnvList(context);
|
|
279
|
-
}
|
|
280
|
-
case "push": {
|
|
281
|
-
return runEnvPush(context);
|
|
282
|
-
}
|
|
283
|
-
case "set": {
|
|
284
|
-
return runEnvSet(context);
|
|
285
|
-
}
|
|
286
|
-
case "unset": {
|
|
287
|
-
return runEnvUnset(context);
|
|
288
|
-
}
|
|
289
|
-
default: {
|
|
290
|
-
options.logger.error(`env: unknown subcommand "${options.subcommand}"`);
|
|
291
|
-
return { code: 1, descriptors: [] };
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
const isEnvSubcommand = (value) => value === "list" || value === "get" || value === "set" || value === "unset" || value === "push" || value === "diff" || value === "doctor" || value === "generate";
|
|
296
|
-
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
297
|
-
const sub = argument[0];
|
|
298
|
-
if (!isEnvSubcommand(sub)) {
|
|
299
|
-
logger.error(`env: unknown subcommand "${sub ?? ""}" — expected list | get | set | unset | push | diff | doctor | generate`);
|
|
300
|
-
return { code: 1 };
|
|
301
|
-
}
|
|
302
|
-
return runEnvCommand({
|
|
303
|
-
cwd,
|
|
304
|
-
key: argument[1],
|
|
305
|
-
logger,
|
|
306
|
-
prod: options.prod === true,
|
|
307
|
-
set: options.set === true,
|
|
308
|
-
subcommand: sub,
|
|
309
|
-
temporary: options.temporary === true,
|
|
310
|
-
value: argument[2],
|
|
311
|
-
yes: options.yes === true
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
export { execute, runEnvCommand };
|
|
1
|
+
import{readFileSync as g,existsSync as b}from"node:fs";import{join as y}from"node:path";import{discoverSchema as h}from"@lunora/codegen";import{readLinkedProject as v,readProjectManifest as $}from"@lunora/config";import{findWranglerFile as p}from"@lunora/config/cloudflare";import{parse as k}from"jsonc-parser";import{Project as w}from"ts-morph";import{w as j,d as m}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{d as S}from"../packem_shared/command-BpMv2n0o.mjs";import{EXIT_CODE as f}from"../packem_shared/EXIT_CODE-DQVhSE-1.mjs";const d=(n,e)=>{if(n===null||typeof n!="object")return;const i=n[e];return typeof i=="string"&&i.length>0?i:void 0},x=(n,e)=>{if(n===null||typeof n!="object")return[];const i=n[e];return Array.isArray(i)?i:[]},E=(n,e)=>{const{manifest:i}=m(e);return{bindings:(i?.bindings??[]).map(r=>`${r.type}:${r.binding}`),compatibilityDate:d(n,"compatibility_date"),compatibilityFlags:x(n,"compatibility_flags").filter(r=>typeof r=="string"),main:d(n,"main"),name:d(n,"name")}},F=n=>({tables:n.tables.map(e=>{let i="root";return e.shardMode==="global"?i="global":typeof e.shardMode=="object"&&(i=`shardBy(${e.shardMode.field})`),{indexes:e.indexes.length,name:e.name,shard:i}}),vectorIndexes:n.vectorIndexes.length}),P=n=>{const e=$(n);if(e===void 0)return[];const i=["dependencies","devDependencies","peerDependencies","optionalDependencies"],r=new Map;for(const s of i){const a=e[s];if(!(a===null||typeof a!="object"))for(const[t,o]of Object.entries(a))t.startsWith("@lunora/")&&typeof o=="string"&&!r.has(t)&&r.set(t,o)}return[...r.entries()].toSorted(([s],[a])=>s.localeCompare(a)).map(([s,a])=>({name:s,version:a}))},M=n=>{const e=P(n),i=p(n);let r;if(i)try{r=E(k(g(i,"utf8")),n)}catch{r=void 0}const s=y(n,"lunora","schema.ts");let a,t;if(b(s))try{const o=new w({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1});a=F(h(o,s))}catch(o){t=o instanceof Error?o.message:String(o)}return{link:v(n),lunoraPackages:e,projectRoot:n,schema:a,schemaError:t,wrangler:r,wranglerPath:i}},I=(n,e)=>{if(e.info(`project: ${n.projectRoot}`),e.info(""),e.info("@lunora/* packages:"),n.lunoraPackages.length===0)e.info(" (none found in package.json)");else for(const i of n.lunoraPackages)e.info(` ${i.name}@${i.version}`);if(e.info(""),n.wrangler?(e.info(`wrangler: ${n.wranglerPath??""}`),e.info(` name: ${n.wrangler.name??"<unset>"}`),e.info(` main: ${n.wrangler.main??"<unset>"}`),e.info(` compatibility_date: ${n.wrangler.compatibilityDate??"<unset>"}`),e.info(` compatibility_flags: ${n.wrangler.compatibilityFlags.join(", ")||"<none>"}`),e.info(` bindings: ${n.wrangler.bindings.join(", ")||"<none>"}`)):e.info("wrangler: (not found)"),e.info(""),n.link?(e.info(`link: ${n.link.workerName??"(unnamed)"} -> ${n.link.workerUrl??"<no url>"}`),n.link.env!==void 0&&e.info(` env: ${n.link.env}`)):e.info("link: (not linked — run `lunora link --url <https://your-worker>`)"),e.info(""),n.schemaError!==void 0)e.warn(`schema: parse error — ${n.schemaError}`);else if(n.schema){e.info(`schema: ${String(n.schema.tables.length)} table(s), ${String(n.schema.vectorIndexes)} vector index(es)`);for(const i of n.schema.tables)e.info(` ${i.name} [${i.shard}, ${String(i.indexes)} index(es)]`)}else e.info("schema: (no lunora/schema.ts)")},A=n=>{const{cwd:e,json:i,logger:r,out:s}=n;if(s!==void 0){const{error:o}=j({destination:s,logger:r,projectRoot:e});return o!==void 0?(r.error(o),{code:f.USAGE,error:o}):{code:0}}const{error:a,manifest:t}=m(e);if(t===void 0){const o=a??"could not derive the binding manifest";return r.error(o),{code:f.USAGE,error:o}}if(i)return{code:0,data:t};if(t.bindings.length===0)r.info("No bindings declared.");else{const o=Math.max(...t.bindings.map(c=>c.type.length));r.info(`${String(t.bindings.length)} binding(s):`);for(const c of t.bindings){const l=[c.resource,c.className,c.resourceId].filter(u=>u!==void 0).join(" ");r.info(` ${c.type.padEnd(o)} ${c.binding}${l===""?"":` ${l}`}`)}}return t.crons.length>0&&r.info(`${String(t.crons.length)} cron trigger(s): ${t.crons.join(", ")}`),t.vars.length>0&&r.info(`${String(t.vars.length)} var(s): ${t.vars.join(", ")}`),t.unknown.length>0&&r.warn(`not modelled by the manifest: ${t.unknown.join(", ")} — anything they bind must be provisioned by hand.`),{code:0,data:t}},D=n=>{const e=n.cwd??process.cwd(),i=n.format==="json",{logger:r}=n;if(n.bindings===!0)return A({cwd:e,json:i,logger:r,out:n.out});if(n.out!==void 0){const a="--out only applies with --bindings; the full info snapshot prints to stdout under --format json.";return r.error(a),{code:f.USAGE,error:a}}const s=M(e);return i||I(s,r),{code:0,data:s,snapshot:s}},H=S(({cwd:n,format:e,logger:i,options:r})=>D({bindings:r.bindings===!0,cwd:n,format:e,logger:i,out:r.out}));export{M as collectInfo,H as execute,D as runInfoCommand};
|
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const CRON_TRIGGER_LIMIT = 3;
|
|
7
|
-
const runCodegenCommand = (options) => {
|
|
8
|
-
const projectRoot = options.cwd ?? process.cwd();
|
|
9
|
-
const json = isJsonFormat(options.format);
|
|
10
|
-
const logger = loggerForFormat(options.format, options.logger);
|
|
11
|
-
const formatError = validateOutputFormat("codegen", options.format);
|
|
12
|
-
if (formatError !== void 0) {
|
|
13
|
-
options.logger.error(formatError);
|
|
14
|
-
return { advisories: [], cronTriggers: [], error: formatError, outputDirectory: "" };
|
|
15
|
-
}
|
|
16
|
-
const result = runCodegen({ apiSpec: options.apiSpec, projectRoot });
|
|
17
|
-
const commandResult = {
|
|
18
|
-
advisories: result.advisories.map((advisory) => {
|
|
19
|
-
return {
|
|
20
|
-
detail: advisory.detail,
|
|
21
|
-
level: advisory.level,
|
|
22
|
-
name: advisory.name,
|
|
23
|
-
remediation: advisory.remediation
|
|
24
|
-
};
|
|
25
|
-
}),
|
|
26
|
-
cronTriggers: result.cronTriggers,
|
|
27
|
-
outputDirectory: result.outputDirectory
|
|
28
|
-
};
|
|
29
|
-
logger.success(`codegen wrote dataModel.ts, api.ts, server.ts to ${result.outputDirectory}`);
|
|
30
|
-
if (result.advisories.length > 0) {
|
|
31
|
-
const count = result.advisories.length;
|
|
32
|
-
const lines = result.advisories.map((advisory) => ` [${advisory.level}] ${advisory.name} — ${advisory.detail}
|
|
33
|
-
↳ ${advisory.remediation}`);
|
|
34
|
-
logger.warn(`${count.toString()} schema ${count === 1 ? "advisory" : "advisories"}:
|
|
35
|
-
${lines.join("\n")}`);
|
|
36
|
-
}
|
|
37
|
-
if (result.cronTriggers.length > CRON_TRIGGER_LIMIT) {
|
|
38
|
-
logger.warn(
|
|
39
|
-
`${result.cronTriggers.length.toString()} distinct cron expressions declared — Cloudflare allows at most ${CRON_TRIGGER_LIMIT.toString()} Cron Triggers per Worker. Consolidate schedules (jobs can share one expression) or move finer-grained work to Durable Object alarms via @lunora/scheduler (runAfter/runAt).`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (json) {
|
|
43
|
-
printJson(commandResult);
|
|
44
|
-
}
|
|
45
|
-
return commandResult;
|
|
46
|
-
};
|
|
47
|
-
const execute = defineHandler(({ cwd, logger, options }) => {
|
|
48
|
-
const result = runCodegenCommand({ apiSpec: parseApiSpec(options.apiSpec), cwd, format: options.format, logger });
|
|
49
|
-
return { code: result.error === void 0 ? 0 : 1 };
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export { execute, runCodegenCommand };
|
|
1
|
+
import{runCodegen as h}from"@lunora/codegen";import{resolveLazyFunctions as m,applyLintIgnores as w,detectLintTools as y,inferLunoraBindings as $,resolveSchemaDirectory as A}from"@lunora/config";import{warnCloudflareCliConfigOnce as T,wranglerCodegenInputs as C,collectExportGaps as D}from"@lunora/config/cloudflare";import{r as S,a as x,e as k}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as E}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{d as b}from"../packem_shared/command-BpMv2n0o.mjs";import{r as I}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as L}from"../packem_shared/EXIT_CODE-DQVhSE-1.mjs";import{r as O}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";const u=3,R=r=>{const s=r.cwd??process.cwd(),{logger:i}=r,e=S(r),o=I(s,r.target);if(o.target===void 0)return r.logger.error(o.error??"unknown deploy target"),{advisories:[],code:L.USAGE,cronTriggers:[],error:o.error??"unknown deploy target",failedAdvisories:0,outputDirectory:""};const{target:a}=o,t=h({apiSpec:r.apiSpec,lazyFunctions:m(r.lazyFunctions),projectRoot:s,target:a,...C(s)}),d={advisories:t.advisories.map(n=>({detail:n.detail,level:n.level,name:n.name,remediation:n.remediation})),cronTriggers:t.cronTriggers,failedAdvisories:0,outputDirectory:t.outputDirectory};if(i.success(`codegen wrote ${t.writtenFiles.join(", ")} to ${t.outputDirectory}`),t.advisories.length>0){const n=t.advisories.length,v=t.advisories.map(c=>` [${c.level}] ${c.name} — ${c.detail}
|
|
2
|
+
↳ ${c.remediation}`);i.warn(`${n.toString()} schema ${n===1?"advisory":"advisories"}:
|
|
3
|
+
${v.join(`
|
|
4
|
+
`)}`)}const g=x(t.platformDiagnostics,i);g.errors.length>0&&(d.error=g.errors.join("; "));const{errorAdvisories:l,names:p,shouldBlock:f}=k(d.advisories,e);return f&&i.error(`${l.length.toString()} ERROR-level ${l.length===1?"advisory":"advisories"} (${p.join(", ")}). Codegen wrote its output; this exit code is the gate. Pass --no-strict-advisories to downgrade it to a warning.`),t.cronTriggers.length>u&&i.warn(`${t.cronTriggers.length.toString()} distinct cron expressions declared — Cloudflare allows at most ${u.toString()} Cron Triggers per Worker. Consolidate schedules (jobs can share one expression) or move finer-grained work to Durable Object alarms via @lunora/scheduler (runAfter/runAt).`),{...d,failedAdvisories:e?l.length:0}},F=async(r,s)=>{let i;try{i=D(await $({projectRoot:r,schemaDir:A(r)}))}catch(e){s.warn(`could not check whether declared containers/workflows/agents are re-exported by the worker entry: ${e instanceof Error?e.message:String(e)}. Run \`lunora doctor\` to check explicitly.`);return}for(const e of i)s.warn(`${e.kind} "${e.exportName}" is declared but ${e.className} is not exported by the worker entry — add \`export * from "./lunora/_generated/${e.module}"\` so wrangler can provision its binding. Until then it deploys with nothing to run.`)},G=(r,s)=>{try{O(w(r,y(r)),s)}catch{}},W=b(async({cwd:r,format:s,logger:i,options:e})=>{const o=R({apiSpec:E(e.apiSpec),cwd:r,format:s,lazyFunctions:m(e.lazyFunctions),logger:i,strictAdvisories:e.strictAdvisories,target:e.target});if(o.outputDirectory!==""){const a=i;G(r,a),await F(r,a),T(r,t=>{a.warn(t)})}return{code:o.code??(o.error===void 0&&o.failedAdvisories===0?0:1),data:{advisories:o.advisories,cronTriggers:o.cronTriggers,failedAdvisories:o.failedAdvisories,outputDirectory:o.outputDirectory},error:o.error}});export{W as execute,R as runCodegenCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{projectConfigCandidatePaths as L,readServiceBindings as ge,createCodegenProject as ve,refreshCodegenProject as me,findTsconfig as he,PROJECT_CONFIG_FILENAMES as we,runCodegen as ee}from"@lunora/codegen";import{runPostCodegenHook as ye,resolveLazyFunctions as P,detectAgentRules as te,updateDevServerState as re,readDevServerState as pe,DEV_DAEMON_ENV as ne,detectAiAgent as Se,readProjectRemotePreference as Ee,readLiveDevServerState as oe,createDiscoveryCache as be,DEV_HANDOFF_ENV as I,clearDevServerState as _e,claimDevServerState as ke,DEV_LOG_FILE_ENV as Pe,secretSourcesFromBindings as Te,inferLunoraBindings as De,resolveSchemaDirectory as Re,ensureDevVarsExample as $e,ensureDevVariables as Ce,isInteractive as Ae,DEV_VARS_FILE as H,DEV_VARS_EXAMPLE_FILE as Oe,fillDevSecrets as Fe,DEV_BINDINGS_FILE as Le,DEV_STATE_FILE as ae,writeCelldDevProjection as Ie,claimAgentRulesHint as Ne,AGENT_RULES_HINT as je}from"@lunora/config";import{wranglerCodegenInputs as ie,resolveRemoteEnabled as Me,startLocalHyperdrive as We,describeWithheld as He}from"@lunora/config/cloudflare";import{p as xe}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{w as Ue}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{createHash as Ve}from"node:crypto";import{existsSync as C,watch as N,readFileSync as se,statSync as Be}from"node:fs";import{join as k,dirname as M}from"node:path";import{STUDIO_WRITE_TEMP_SUFFIX as ze,consumeStudioWrite as x,loadStudioAssets as U,studioAssetsStamp as V,createStudioDocumentCache as Ge,renderStudioHtml as Xe,resolveAdminToken as Je,requestPathname as B,transportRejectionReason as z,SCHEMA_EDIT_ENDPOINT as Ye,POLICY_SCAFFOLD_ENDPOINT as Ke,SEED_ENDPOINT as Qe,sendStudioDocument as Ze,serveJsonHandler as qe,isStandaloneModulePath as et,readStandaloneAsset as tt,assetContentType as rt,handleSchemaEditRequest as nt,handlePolicyScaffoldRequest as ot,handleSeedRequest as at,sendStudioAsset as it}from"@lunora/config/studio-host";import{LunoraError as st}from"@lunora/errors";import{ts as G}from"ts-morph";import{a as ct}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{a as dt}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{d as lt}from"../packem_shared/command-BpMv2n0o.mjs";import{a as ut}from"../packem_shared/deploy-target-resolve-BTCW1Iv4.mjs";import{EXIT_CODE as $}from"../packem_shared/EXIT_CODE-DQVhSE-1.mjs";import{forceJsonLogging as ft}from"../packem_shared/createLogger-4TujevyB.mjs";import{createServer as gt,request as vt}from"node:http";import{connect as mt}from"node:net";import{pipeline as ht}from"node:stream";import{c as wt}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{setTimeout as yt}from"node:timers/promises";import{r as pt,d as St,P as Et,a as bt,b as j,c as _t,s as kt,n as ce,e as Pt,f as Tt,g as Dt,h as Rt,i as X,w as $t,j as Ct,k as At,t as Ot,l as Ft,m as Lt,o as It}from"../packem_shared/plan-pog5AvMk.mjs";import{b as Nt}from"./handler.mjs";const jt=100,Mt=/(?:\.[cm]?[jt]sx?|(?:^|[/\\])tsconfig(?:\..+)?\.json)$/u,F=300,J=/[/\\]/u,Y=e=>{try{return se(e,"utf8")}catch{return""}},Wt=e=>{try{const{mtimeMs:t,size:n}=Be(e);return`${String(t)}:${String(n)}`}catch{return""}},Ht=["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock","node_modules/.modules.yaml","node_modules/.package-lock.json","node_modules/.yarn-integrity"],de=e=>{const t=M(e);return t===e?[e]:[e,...de(t)]},xt=e=>{const t={...G.sys,onUnRecoverableConfigFileDiagnostic:()=>{},readDirectory:()=>[]},n=G.getParsedCommandLineOfConfigFile(e,{},t);return n===void 0?"":JSON.stringify(n.options)},Ut=(e,t)=>{const n=he(t),o=[...new Set([...L(t),...we.map(s=>k(e,s))])].map(s=>`${s}
|
|
2
|
+
${Y(s)}`),a=de(e).flatMap(s=>Ht.map(i=>`${k(s,i)}
|
|
3
|
+
${Wt(k(s,i))}`));return[n===void 0?"":`${n}
|
|
4
|
+
${Y(n)}
|
|
5
|
+
${xt(n)}`,...o,...a].join("\0")},Vt=(e,t)=>{let n,r;return{drop:()=>{n=void 0},get:()=>{const o=Ut(e,t);return n===void 0||o!==r?(r=o,n=ve(t)):me(n,t),n}}},Bt=(e,t,n,r)=>{const{apiSpec:o,lazyFunctions:a,logger:d,projectRoot:s,target:i}=e;try{const u=k(s,t,"schema.ts");if(!C(u))throw new st("INTERNAL",`schema.ts not found at ${u}`);const S=ee({apiSpec:o,lazyFunctions:P(a),lunoraDirectory:t,project:r.get(),projectRoot:s,target:i,...ie(s)});d.success(`codegen: wrote ${t}/_generated (${n})`),dt(S.platformDiagnostics,d)}catch(u){return r.drop(),d.error(ct(u,n)),!1}return!0},K=e=>{const t=Ve("sha256");for(const n of e){if(t.update(n).update("\0"),C(n)){t.update("present\0");try{t.update(se(n))}catch{t.update("unreadable")}}else t.update("absent");t.update("\0")}return t.digest("hex")},Q=e=>e instanceof Error?e.stack??e.message:String(e),zt=(e,t,n)=>{const r=[];for(const o of new Set([...e].map(a=>M(a))))if(C(o))try{const a=N(o,(d,s)=>{typeof s!="string"?t(void 0):e.has(k(o,s))&&t(s)});a.on("error",d=>{n(`codegen watch: stopped watching ${o} for lunora.config changes
|
|
6
|
+
${Q(d)}`),a.close()}),r.push(a)}catch(a){n(`codegen watch: could not watch ${o} for lunora.config changes
|
|
7
|
+
${Q(a)}`)}return r},Gt=e=>{const t=e.lunoraDirectory??"lunora",n=k(e.projectRoot,t),r=e.debounceMs??jt;let o=!1,a=!1,d=!1,s,i=0,u;const S=L(n);let m=Promise.resolve();const c=Vt(e.projectRoot,n);let l;const g=new Promise(f=>{l=f}),h=(f,v)=>{o||(s={codegen:v||s?.codegen===!0,reason:f},!a&&(a=!0,m=(async()=>{try{for(;s!==void 0;){const w=s;if(s=void 0,w.codegen&&(u=K(S)),!(w.codegen&&!Bt(e,t,w.reason,c))){d=!0;try{(await ye({cwd:e.projectRoot,logger:e.logger,spawner:e.spawner,stdoutToStderr:e.jsonLogs})).ran&&(i=Date.now())}finally{d=!1}}}}catch(w){e.logger.error(`codegen watch: ${w instanceof Error?w.message:String(w)}`)}finally{a=!1,l()}})()))};h("startup",!0);const p=f=>(e.logger.warn(`codegen watch unavailable (${f}) — schema edits will NOT auto-regenerate. Run \`lunora codegen\` manually after each edit.`),{close:()=>(o=!0,s=void 0,m),ready:g,watchAvailable:!1});let y,b;if(!C(n))return p(`no such directory: ${n}`);const _=new Set;let T=!1;const D=(f,v)=>{if(d||Date.now()-i<F){y&&(clearTimeout(y),y=void 0);let w=!1;for(const E of[..._,f])E!==void 0&&x(E)&&(w=!0);_.clear(),T=!1,w&&h(`change: ${v}`,!1);return}f===void 0?T=!0:_.add(f),y&&clearTimeout(y),y=setTimeout(()=>{const w=[..._].map(fe=>x(fe)),E=T||w.includes(!1);_.clear(),T=!1,h(`change: ${v}`,E)},r)},A=[],O=[],le=new Set(L(n));let R;const W=f=>{if(!o){if(!d&&Date.now()-i>=F){clearTimeout(R),(f===void 0||K(S)!==u)&&D(void 0,f??"?");return}clearTimeout(R),R=setTimeout(()=>{W(f)},F)}};try{b=N(n,{recursive:!0},(f,v)=>{if(typeof v!="string"){D(void 0,"?");return}v.split(J).includes("_generated")||v.endsWith(ze)||D(k(n,v),v)});for(const f of ge(e.projectRoot).services)if(f.rpcEntrypoint!==void 0){const v=N(M(f.wranglerPath),{recursive:!0},(w,E)=>{typeof E=="string"&&Mt.test(E)&&!E.split(J).includes("node_modules")&&D(void 0,E)});v.on("error",w=>{e.logger.warn(`codegen watch: stopped watching service "${f.name}" (${w.message})`),v.close()}),A.push(v)}O.push(...zt(le,f=>{W(f)},f=>{e.logger.warn(f)}))}catch(f){b?.close();for(const v of A)v.close();for(const v of O)v.close();return p(f instanceof Error?f.message:String(f))}const ue=b;return{close:()=>{o=!0,s=void 0,y&&clearTimeout(y),clearTimeout(R),ue.close();for(const f of A)f.close();for(const f of O)f.close();return m},ready:g,watchAvailable:!0}},Z="/_lunora",Xt=3e4,q=(e,t,n,r=Xt)=>{const o=vt({headers:{...e.headers,host:n.host},hostname:n.hostname,method:e.method,path:e.url,port:n.port},a=>{o.setTimeout(0),t.writeHead(a.statusCode??502,a.headers),ht(a,t,()=>{})});o.setTimeout(r,()=>{o.destroy(new Error(`no response within ${String(r)}ms`))}),o.on("error",a=>{if(t.headersSent){t.destroy();return}t.statusCode=a.message.startsWith("no response within")?504:502,t.end(`lunora dev: worker unreachable (${a.message})`)}),t.on("close",()=>{t.writableFinished||o.destroy()}),e.pipe(o)},Jt=5e3,Yt=(e,t,n,r)=>{const o=mt({host:r.hostname,port:Number(r.port)},()=>{o.setTimeout(0);const a=[`${e.method??"GET"} ${e.url??"/"} HTTP/1.1`];for(const[d,s]of Object.entries(e.headers))if(d!=="host")for(const i of Array.isArray(s)?s:[s])i!==void 0&&a.push(`${d}: ${i}`);a.push(`host: ${r.host}`,"",""),o.write(a.join(`\r
|
|
8
|
+
`)),n.length>0&&o.write(n),o.pipe(t),t.pipe(o)});o.setTimeout(Jt,()=>o.destroy()),o.on("error",()=>t.destroy()),t.on("error",()=>o.destroy())},Kt=async e=>{const t=e.host??"127.0.0.1",n=t==="127.0.0.1"||t==="localhost"||t==="::1",r=new URL(e.workerOrigin);let o=U(e.logger,import.meta.url),a=V(import.meta.url);const d=Ge(e.cwd,()=>Buffer.from(Xe({adminToken:n?Je(e.cwd):void 0,basePath:"/",dataEditable:n,rulesInstalled:te(e.cwd).installed,runAsIdentity:n,schemaEditable:n,scriptSrc:"/studio.js",styleHref:"/styles.css"}))),s=(c,l,g,h,p)=>{it(c,l,g,h,p,a)},i=(c,l,g)=>{c.statusCode=l,c.setHeader("Content-Type","text/plain"),c.end(g)},u=(c,l,g,h)=>{if(n){qe(c,l,g,e.cwd,{apiSpec:e.apiSpec,lazyFunctions:P(e.lazyFunctions)});return}i(l,403,h)},S=(c,l,g)=>{const h=c==="/styles.css",p=et(c);if(!h&&!p)return!1;const y=V(import.meta.url);if(y!==a&&(o=U(e.logger,import.meta.url),a=y),o===void 0)return i(g,501,"Lunora studio assets not found — install and build @lunora/studio."),!0;if(h)return s(l,g,o.styles,"text/css; charset=utf-8","styles.css"),!0;const b=c.slice(c.lastIndexOf("/")+1),_=tt(b,import.meta.url);return _===void 0?(i(g,404,"Not found"),!0):(s(l,g,_,rt(b),b),!0)};d();const m=gt((c,l)=>{const g=B(c.url??"/");if(n){const p=z(c,e.logger);if(p!==void 0){i(l,403,p);return}}if(g.startsWith(Z)){if(!n){i(l,403,"Lunora studio: the worker admin proxy is only available on a loopback bind.");return}q(c,l,r);return}if(g===Ye){u(c,l,nt,"Lunora schema editing is only available on loopback hosts in dev.");return}if(g===Ke){u(c,l,ot,"Lunora policy scaffolding is only available on loopback hosts in dev.");return}if(g===Qe){u(c,l,at,"Lunora data seeding is only available on loopback hosts in dev.");return}if(S(g,c,l))return;const h=c.headers["sec-fetch-mode"];if(n&&typeof h=="string"&&h!=="navigate"){q(c,l,r);return}Ze(l,d())});return m.on("upgrade",(c,l,g)=>{if(!n||z(c,e.logger)!==void 0){l.destroy();return}B(c.url??"").startsWith(Z)?Yt(c,l,g,r):l.destroy()}),await new Promise((c,l)=>{m.once("error",g=>{g.code==="EADDRINUSE"?l(new Error(`studio port ${String(e.port)} is already in use — pass a different port with --port, or stop the process using it`,{cause:g})):l(g)}),m.listen(e.port,t,()=>{c()})}),{close:()=>new Promise(c=>{m.close(()=>{c()})}),url:`http://${t==="0.0.0.0"||t==="::"?"localhost":t}:${String(e.port)}`}},Qt=async e=>{const{cwd:t,logger:n,origin:r,signal:o}=e,a=e.probe??St,d=pt(e.readyTimeoutMs),s=Date.now()+d,i=()=>o.aborted;for(;!i()&&Date.now()<s;){let u=!1;try{u=await a(r,o)}catch{}if(i()||Date.now()>=s)break;if(u)return re(t,{readyAt:new Date().toISOString()},{expectedPid:process.pid}),pe(t)?.readyAt!==void 0;try{await yt(Et,void 0,{signal:o})}catch{}}return i()||n.warn(`server did not answer on ${r} within ${String(Math.round(d/1e3))}s — .lunora/dev.json will have no readyAt, so anything polling for readiness will keep waiting. The server itself is unaffected; raise LUNORA_DEV_READY_TIMEOUT_MS if it is just slow to boot.`),!1},Zt=(e,t,n,r)=>{e.info(""),e.success("Lunora dev"),e.info(` ➜ Worker: ${t.workerOrigin}`),n!==void 0&&e.info(` ➜ Studio: ${n}`),t.runsCodegenWatch&&e.info(" ➜ Codegen: watching lunora/"),r!==void 0&&e.info(` ➜ Supervisor: ${r} (needs) · ${ae} (status)`),t.remote.enabled&&(t.remote.bindings.length>0?e.info(` ➜ Remote: ${t.remote.bindings.join(", ")} → deployed worker`):t.remote.reason!==void 0&&e.warn(` ➜ Remote: requested but inactive (${t.remote.reason}) — running fully local`));for(const o of t.remote.withheld)e.warn(` ➜ ${He(o)}`);e.info("")},qt=(e,t)=>{te(t).installed||!Ne()||(e.info(` ⓘ ${je}`),e.info(""))},er=async(e,t,n)=>{let r;try{r=Te(await De({cache:n,projectRoot:t,schemaDir:Re(t)}))}catch{}if(r!==void 0)try{const a=(e.ensureExample??$e)(t,r);if(a.length>0){const d=r.map(s=>s.includes(":")?`${s.replace(":"," (")})`:s);e.logger.info(`Updated .dev.vars.example with secrets for: ${d.join(", ")} (${a.join(", ")})`)}}catch{}(await(e.ensureEnv??Ce)({confirm:wt(),cwd:t,info:a=>{e.logger.info(a)}})).status==="declined"&&!Ae()&&e.logger.info(`hint: ${H} was not scaffolded (non-interactive run). Copy ${Oe} → ${H} and fill in secrets, or run \`lunora dev\` in an interactive terminal to scaffold automatically.`);try{(e.fillSecrets??Fe)({cwd:t,secretSources:r,info:a=>{e.logger.info(a)}})}catch{}},tr=(e,t,n,r,o)=>{if(e.flavor!=="wrangler")return;r!==void 0&&re(t,{studioUrl:r});let a;try{a=It(t,n)}catch{}return Zt(n,e,r,o),a},rr=(e,t)=>{const n=Number(process.env[I]),r=ke(t,{background:process.env[ne]==="1",logFile:process.env[Pe],mode:"cli",pid:process.pid,startedAt:new Date().toISOString(),url:e.workerOrigin},Number.isInteger(n)&&n>0?{supersedePid:n}:void 0);return r.ok?void 0:r.existing},nr=e=>{const{cwd:t,destination:n,logger:r,plan:o}=e,a=n!==void 0,d=n??Le,s=Ue({destination:d,dev:{...o.flavor==="wrangler"?{origin:o.workerOrigin}:{},statusFile:ae},logger:a?r:{...r,success:()=>{},warn:()=>{}},projectRoot:t});return s.error!==void 0?a?s:(r.debug?.(`skipped the default binding manifest: ${s.error}`),{}):{written:d}},or=async(e,t,n,r)=>{if(t.studioEnabled)try{return await(e.startStudio??Kt)({apiSpec:e.apiSpec,lazyFunctions:P(e.lazyFunctions),cwd:n,logger:{warnOnce:o=>{r.warn(o)}},port:t.studioPort,workerOrigin:t.workerOrigin})}catch(o){r.warn(`studio server failed to start (${o instanceof Error?o.message:String(o)}) — continuing without it`);return}},ar=e=>{const t=[e.runsCodegenWatch?"codegen watch":void 0,e.studioEnabled?"studio":void 0].filter(r=>r!==void 0);return`--no-worker: not starting wrangler. ${t.length>0?`${t.join(" + ")} running`:"nothing else to run"}; your task runner owns the worker on ${e.workerOrigin}.`},ir=(e,t,n,r,o)=>{if(!(e.sidecar===void 0||!Ft(t)))try{ee({apiSpec:t.apiSpec,lazyFunctions:P(t.lazyFunctions),lunoraDirectory:"lunora",projectRoot:n,target:o,...ie(n)})}catch(a){r.warn(`codegen (pre-sidecar) failed: ${a instanceof Error?a.message:String(a)} — the framework dev server will retry`)}},sr=e=>e.flavor==="vite"?"starting vite dev (worker + studio + codegen run inside Vite via @lunora/vite)":`starting ${e.wrangler.tag} dev + studio`,cr=(e,t)=>{e.ipv4LoopbackForced&&t.info("no IPv6 loopback (::1) on this host — binding the worker to 127.0.0.1 (--ip) so wrangler dev doesn't crash. Pin `dev.ip` in wrangler.jsonc to override.")},dr=async(e,t,n,r)=>{if(e.celldSession!==!0||e.workerEnabled)return!0;try{for(const o of await(t.writeCelldProjection??Ie)({projectRoot:n}))r.warn(o);return!0}catch(o){return r.error(`could not write the celld projection: ${o instanceof Error?o.message:String(o)}`),!1}},lr=async(e,t,n,r,o)=>{try{return e.celldSession===!0?await Lt({logger:o,port:e.workerPort,projectRoot:r,start:t.startCelldSession}):n(e.wrangler,o)}catch(a){o.error(`could not start the worker: ${a instanceof Error?a.message:String(a)}`);return}},ur=async(e,t,n)=>{const r=await(e.startHyperdrive??We)({onWarning:o=>{n.warn(o)},projectRoot:t});return r!==void 0&&r.bindings.length>0&&n.info(`Hyperdrive ${r.bindings.join(", ")}: embedded Postgres (PGlite), data in .wrangler/state/lunora-pglite. Set CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING> to use your own.`),r},fr=async e=>{const{logger:t}=e,n=be(),r=e.cwd??process.cwd(),o=e.flavor??Pt(r),a=ut(r,e.target);if(a.target===void 0)throw new Error(a.error??"unknown deploy target");const{target:d}=a,s=Tt(d,o,t);s==="wrangler"&&await Nt(r,t,void 0,d,void 0,n);const i=await Dt({...e,flavor:s,target:d}),u={remoteCleanup:i.remote.cleanup,serviceConfigCleanup:i.serviceConfigCleanup};try{const S=Number(process.env[I]),m=oe(r);if(m!==void 0&&m.pid!==process.pid&&m.pid!==S)return j(t,m),{code:0,plan:i};const c=rr(i,r);if(c!==void 0)return j(t,c),{code:0,plan:i};(i.flavor==="vite"||i.flavor==="framework-worker")&&(i.wrangler.env={...i.wrangler.env,[I]:String(process.pid)}),i.workerEnabled&&d==="cloudflare"&&(u.hyperdrive=await ur(e,r,t)),await er(e,r,n),t.info(sr(i)),Rt(t,r),cr(i,t),i.runsCodegenWatch&&(u.codegen=(e.startCodegen??Gt)({apiSpec:e.apiSpec,lazyFunctions:P(e.lazyFunctions),jsonLogs:e.jsonLogs,logger:t,projectRoot:r,target:d})),u.studio=await or(e,i,r,t);const l=nr({cwd:r,destination:e.emitBindings,logger:t,plan:i});if(l.error!==void 0)return t.error(l.error),{code:$.USAGE,plan:i};await u.codegen?.ready;const g=u.studio?.url;i.frameworkHint!==void 0&&t.warn(i.frameworkHint);const h=()=>{i.flavor==="wrangler"&&(u.readyProbe=new AbortController,Qt({cwd:r,logger:t,origin:i.workerOrigin,probe:e.probeReady,signal:u.readyProbe.signal}))};if(!await dr(i,e,r,t))return{code:$.FAILURE,plan:i};if(!i.workerEnabled)return h(),t.info(ar(i)),u.tunnel=X({cwd:r,logger:t,plan:i,tunnel:e.tunnel}),{code:await(e.waitForInterrupt??$t)(t),plan:i};ir(i,e,r,t,d);const p=e.startWorker??Ct,y=await lr(i,e,p,r,t);if(y===void 0)return{code:$.FAILURE,plan:i};const b=i.sidecar===void 0?void 0:p(i.sidecar,t);return h(),u.containerLogs=tr(i,r,t,g,l.written),u.tunnel=X({cwd:r,logger:t,plan:i,tunnel:e.tunnel}),qt(t,r),{code:await At(y,b,t),plan:i}}finally{u.readyProbe?.abort(),_e(r,process.pid),await Ot(u)}},gr=e=>({codegen:e.codegen===!1?!1:void 0,studio:e.studio===!1?!1:void 0,worker:e.worker===!1?!1:void 0}),vr=e=>{if(e.local===!0&&e.remote===!0)return"`--local` and `--remote` are mutually exclusive — pass at most one.";const{entries:t,invalid:n}=ce(e.allowMail);if(n.length>0)return`\`--allow-mail\` takes email addresses or '*@domain' — not ${n.map(r=>`"${r}"`).join(", ")}.`;if(t.length>0&&e.tunnel!==!0)return"`--allow-mail` only applies to a tunnel — add `--tunnel`."},mr=e=>e.tunnel===!0?{allowMail:ce(e.allowMail).entries}:void 0,Hr=lt(async({argument:e,cwd:t,logger:n,options:r})=>{const o=r.json===!0,a=bt({cwd:t,json:o,lines:r.lines,logger:n,subcommand:e[0]});if(a!==void 0)return a;const d=process.env[ne]==="1",s=d?void 0:Se(),i=o||s!==void 0;i&&ft(),s!==void 0&&r.background!==!0&&n.info(`AI agent detected (${s.name} via ${s.variable}) — starting the dev server in background mode with JSON logs. Set LUNORA_AGENT_MODE=0 to opt out.`);const u=vr(r);if(u!==void 0)return n.error(`dev: ${u}`),{code:$.USAGE};const S=mr(r),m=r.local===!0?!1:Me({configPreference:Ee(t),envValue:process.env.LUNORA_REMOTE,flag:r.remote});if(!d&&(r.background===!0||s!==void 0)){const c=oe(t);return c!==void 0?(j(n,c),{code:0}):(S?.allowMail.length===0&&_t(n),kt({cwd:t,jsonLogs:i,logger:n,options:r,remote:m}))}return fr({apiSpec:xe(r.apiSpec),cwd:t,emitBindings:r.emitBindings,inspectorPort:r.inspectorPort,lazyFunctions:P(r.lazyFunctions),jsonLogs:i,local:r.local,logger:n,port:r.port,remote:m,target:r.target,tunnel:S,workerPort:r.workerPort,...gr(r)})});export{vr as devFlagConflict,Hr as execute,gr as negatableDevFlags,fr as runDevCommand};
|