@vite-hub/cli 0.4.1 → 0.5.0

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.
@@ -1,8 +1,9 @@
1
- import { B as readSetupProject, F as uninstallArgs, G as featureSupport, H as featureHosts, J as editViteHubConfig, K as features, L as hasDefinitionFiles, M as installCommand, N as setsOption, P as setupStatus, R as listMatchingFiles, U as featureIds, V as setupLockfiles, W as featurePackages, X as locateViteHubConfig, Y as insertViteHubConfig, Z as __exportAll, c as linkSetupProject, j as installArgs, l as readLinkHostOption, m as unlinkSetupProject, o as gitignoreWithViteHub, q as impliedFeatures, r as SETUP_LINK_FILE, u as readSetupLinkState, z as detectPackageManager } from "./env-B1Gg-WnA.js";
2
- import { m as cliErrorDiagnostics } from "./provision-DXl97xG0.js";
3
- import { a as table, i as setupFailure, n as readSetupArgs, o as writeSetupError, r as setupExitCodes, s as writeSetupJson } from "./envelope-B4mPbSbj.js";
4
- import { l as whoamiCommand, o as loginCommand, s as logoutCommand } from "./console-auth-B0HxFFiX.js";
5
- import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-C0RdI5OK.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { F as featureHosts, H as installSpecifier, I as featureIds, L as featurePackages, R as featureSupport, V as impliedFeatures, m as cliErrorDiagnostics, z as features } from "./provision-DgT_lpyn.js";
3
+ import { B as listMatchingFiles, F as setupStatus, G as insertViteHubConfig, H as readSetupProject, I as shellQuote, K as locateViteHubConfig, L as uninstallArgs, M as installArgs, N as installCommand, P as missingProviderOption, U as setupLockfiles, V as detectPackageManager, W as editViteHubConfig, c as linkSetupProject, j as formatInstallCommand, l as readLinkHostOption, m as unlinkSetupProject, o as gitignoreWithViteHub, r as SETUP_LINK_FILE, u as readSetupLinkState, z as hasDefinitionFiles } from "./env-MtXhP7A7.js";
4
+ import { a as table, i as setupFailure, n as readSetupArgs, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-C7e408hm.js";
5
+ import { l as whoamiCommand, o as loginCommand, s as logoutCommand } from "./console-auth-Dz9HHP2G.js";
6
+ import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-CHW75le_.js";
6
7
  import { createRequire } from "node:module";
7
8
  import { existsSync, readFileSync } from "node:fs";
8
9
  import process from "node:process";
@@ -12,14 +13,31 @@ import { join as join$1 } from "node:path";
12
13
  import { createInterface } from "node:readline/promises";
13
14
  import { pathToFileURL } from "node:url";
14
15
  import { createTwoFilesPatch } from "diff";
15
- import { parseArgs } from "node:util";
16
+ import { isDeepStrictEqual, parseArgs } from "node:util";
16
17
  import semver, { Range, minVersion, subset, validRange } from "semver";
18
+ //#region ../internal/dist/feature-inputs.js
19
+ function isLocaleTag(value) {
20
+ try {
21
+ return Intl.getCanonicalLocales(value).length === 1;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ function i18nLocaleListProblem(locales) {
27
+ if (!Array.isArray(locales) || locales.length === 0) return "`i18n.locales` is empty.";
28
+ const seen = /* @__PURE__ */ new Set();
29
+ for (const locale of locales) {
30
+ if (typeof locale !== "string" || !isLocaleTag(locale)) return `\`${String(locale)}\` is not a BCP 47 language tag.`;
31
+ if (seen.has(locale.toLowerCase())) return `\`${locale}\` is listed twice.`;
32
+ seen.add(locale.toLowerCase());
33
+ }
34
+ }
35
+ function mcpPublicRouteNeedsSignedAuth(publicRoute, auth) {
36
+ return !!publicRoute && auth !== true;
37
+ }
38
+ //#endregion
17
39
  //#region src/setup/add.ts
18
40
  const usage$3 = "vitehub add <feature...> [--name <definition>] [--option <key=value>]... [--dry-run] [--yes] [--no-install] [--json]";
19
- /**
20
- * Values that `--option` can choose for an `explicit` host, first the one that `rerun` uses, and the feature that the
21
- * value needs. Options without an entry, such as `database.connection`, need a value that only the developer knows.
22
- */
23
41
  const optionChoices = {
24
42
  "cache.driver": {
25
43
  requires: "kv",
@@ -31,7 +49,6 @@ const optionChoices = {
31
49
  "sandboxTask.driver": { values: ["vercel"] },
32
50
  "workflow.driver": { values: ["openworkflow"] }
33
51
  };
34
- /** Option keys that select a provider or a store. A feature that sets one does not use the host default. */
35
52
  const providerKeys = ["driver", "store"];
36
53
  function selectsProvider(id, value, host) {
37
54
  if (!isRecord$1(value)) return false;
@@ -41,15 +58,12 @@ function selectsProvider(id, value, host) {
41
58
  }
42
59
  return providerKeys.some((key) => value[key] !== void 0);
43
60
  }
44
- /** How `host` supports `id`, with the override that `env` selects, such as BLOB_READ_WRITE_TOKEN for the Vercel Workspace. */
45
61
  function hostSupport(id, host, env) {
46
62
  const support = featureSupport(id, host);
47
63
  if (support.level !== "native") return support;
48
64
  return support.envOverrides?.find((override) => env[override.env]?.trim())?.support ?? support;
49
65
  }
50
- /** The value that turns a feature on, when `true` is not valid for its key. */
51
66
  const enabledValues = { env: {} };
52
- /** Keep owner packages on the running CLI's pkg.pr.new preview. */
53
67
  function installSpecifiers(packages) {
54
68
  const manifest = JSON.parse(readFileSync(new URL(import.meta.resolve("@vite-hub/cli/package.json")), "utf8"));
55
69
  const dependencies = isRecord$1(manifest) && isRecord$1(manifest.dependencies) ? manifest.dependencies : {};
@@ -61,7 +75,7 @@ function installSpecifiers(packages) {
61
75
  ref
62
76
  }] : [];
63
77
  })[0];
64
- return packages.map((name) => preview && name.startsWith("@vite-hub/") ? `${preview.base}/${name}@${preview.ref}` : name);
78
+ return packages.map((name) => preview && name.startsWith("@vite-hub/") ? `${preview.base}/${name}@${preview.ref}` : installSpecifier(name));
65
79
  }
66
80
  function invalid$3(message, commandUsage = usage$3) {
67
81
  return cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] ${message} Usage: ${commandUsage}` });
@@ -73,7 +87,12 @@ function readFeatureId(value, commandUsage = usage$3) {
73
87
  if (!id) throw invalid$3(`Unknown feature ${JSON.stringify(value)}. Run \`vitehub catalog\` to list the features.`, commandUsage);
74
88
  return id;
75
89
  }
76
- function optionValue(value) {
90
+ function optionValue(value, key) {
91
+ if (key === "i18n.locales" && value.trimStart().startsWith("[")) try {
92
+ return JSON.parse(value);
93
+ } catch {
94
+ throw invalid$3(`--option ${key} must contain a valid JSON array.`);
95
+ }
77
96
  if (value === "true" || value === "false" || value === "null" || /^-?\d+(?:\.\d+)?$/u.test(value)) return JSON.parse(value);
78
97
  return value;
79
98
  }
@@ -130,21 +149,16 @@ function readAddArgs(args) {
130
149
  const id = head ?? (parsed.features.length === 1 ? parsed.features[0] : void 0);
131
150
  const keys = head ? path.slice(1) : path;
132
151
  if (!id || !keys.length || keys.some((key) => !key)) throw invalid$3(`--option ${JSON.stringify(option)} must start with one of the features, such as \`${parsed.features[0] ?? "email"}.driver=resend\`.`);
133
- setPath(parsed.options[id] ??= {}, keys, optionValue(option.slice(separator + 1)));
152
+ setPath(parsed.options[id] ??= {}, keys, optionValue(option.slice(separator + 1), `${id}.${keys.join(".")}`));
134
153
  }
135
154
  return parsed;
136
155
  }
137
- /** Quotes `value` for a POSIX shell when it needs quotes. */
138
- function shellQuote(value) {
139
- return /^[\w@%+=:,./-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
140
- }
141
156
  /** `value` as `--option` values under `prefix`, such as `["email.driver=resend"]`. */
142
157
  function flattenOptions(prefix, value, out = []) {
143
158
  if (isRecord$1(value)) for (const [key, child] of Object.entries(value)) flattenOptions(`${prefix}.${key}`, child, out);
144
159
  else out.push(`${prefix}=${value === null || typeof value !== "object" ? String(value) : JSON.stringify(value)}`);
145
160
  return out;
146
161
  }
147
- /** The `vitehub add` command for `args`, with `extra` options and `--yes` unless it is a dry run. */
148
162
  function rerunCommand$1(args, extra = {}, extraFeatures = []) {
149
163
  const ids = [...args.features, ...extraFeatures.filter((id) => !args.features.includes(id))];
150
164
  const options = [.../* @__PURE__ */ new Set([
@@ -189,10 +203,6 @@ function toSource(value) {
189
203
  function setupDiff(path, before, after) {
190
204
  return createTwoFilesPatch(before ? `a/${path}` : "/dev/null", after ? `b/${path}` : "/dev/null", before, after, void 0, void 0, { context: 3 }).replace(/^=+\n/u, "");
191
205
  }
192
- /**
193
- * The config value that `add` writes for `id`, `undefined` when the config already turns it on, or `expression` when
194
- * the key is an expression that only a person can edit.
195
- */
196
206
  function nextValue(id, status, project, options) {
197
207
  const current = project.config?.ok ? project.config.site.keys[id] : void 0;
198
208
  if (current?.kind === "expression") return "expression";
@@ -225,6 +235,11 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
225
235
  feature: id,
226
236
  host
227
237
  }), setupExitCodes.conflict);
238
+ if (id === "email" && driver === "smtp" && host === "cloudflare") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
239
+ detail: "The \"smtp\" driver opens TCP connections with nodemailer, and Cloudflare Workers cannot run it. On Cloudflare, use the \"cloudflare\" or \"resend\" driver, or a driver module that sends over HTTP.",
240
+ feature: id,
241
+ host
242
+ }), setupExitCodes.conflict);
228
243
  if (support.level === "unsupported") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
229
244
  detail: support.detail,
230
245
  feature: id,
@@ -232,6 +247,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
232
247
  }), setupExitCodes.conflict);
233
248
  }
234
249
  const missing = [];
250
+ const inputFixes = [];
235
251
  const defaults = {};
236
252
  const requires = [];
237
253
  let rerunnable = true;
@@ -250,7 +266,6 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
250
266
  };
251
267
  for (const id of inputFeatures) {
252
268
  const support = featureSupport(id, host);
253
- const options = args.options[id];
254
269
  const current = project.config?.ok ? project.config.site.keys[id] : void 0;
255
270
  const value = valueFor(id);
256
271
  if (id === "observability" && isRecord$1(value) && value.papercuts) {
@@ -306,14 +321,14 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
306
321
  if (invocations === "database" || isRecord$1(invocations) && invocations.store === "database") requireFeature("database");
307
322
  const storageSelected = id === "workflow" && host !== "netlify" && selectsProvider(id, value, host);
308
323
  if (support.level === "explicit" && !storageSelected) {
309
- const key = support.option.slice(id.length + 1);
310
- if (!(options && key in options) && !setsOption(project, support.option)) {
324
+ const field = missingProviderOption(project, support.option, value);
325
+ if (field) {
311
326
  const choices = optionChoices[support.option];
312
327
  missing.push({
313
- field: support.option,
328
+ field,
314
329
  ...choices ? { choices: choices.values } : {}
315
330
  });
316
- if (choices) setPath(defaults[id] ??= {}, [key], choices.values[0]);
331
+ if (choices) setPath(defaults[id] ??= {}, field.split(".").slice(1), choices.values[0]);
317
332
  else rerunnable = false;
318
333
  }
319
334
  }
@@ -351,16 +366,73 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
351
366
  host
352
367
  }), setupExitCodes.conflict);
353
368
  for (const id of Object.keys(args.options)) if (!inputFeatures.includes(id)) throw invalid$3(`${id} is not requested or required by ${args.features.join(", ")}.`);
369
+ const site = project.config?.ok ? project.config.site : void 0;
370
+ if (inputFeatures.includes("i18n") && site?.keys.i18n?.kind !== "expression") {
371
+ const i18n = valueFor("i18n");
372
+ const problem = i18nLocaleListProblem(isRecord$1(i18n) ? i18n.locales : void 0);
373
+ if (problem) {
374
+ missing.push({ field: "i18n.locales" });
375
+ inputFixes.push(`${problem} Pass a nonempty JSON array, such as \`--option 'i18n.locales=["en","es"]'\`.`);
376
+ rerunnable = false;
377
+ }
378
+ }
379
+ const mcpOAuthSetup = "Include `mcpOAuth()` from `vite-hub/auth/mcp` in the `plugins` of `defineAuth()` in the Auth Definition";
380
+ let needsMcpOAuth = false;
381
+ if (inputFeatures.includes("mcp") && site?.keys.mcp?.kind !== "expression") {
382
+ const configuredAuth = site?.keys.auth;
383
+ const authStatus = status.features.find((item) => item.id === "auth");
384
+ const discoveredAuth = authStatus?.enabled === "on" && authStatus.reason === "default";
385
+ const selectedAuth = args.features.includes("auth") && (!configuredAuth || configuredAuth.kind === "expression" || configuredAuth.value === false);
386
+ const authEnabled = !args.options.auth && (selectedAuth || configuredAuth?.kind === "literal" && configuredAuth.value === true || discoveredAuth);
387
+ const mcp = valueFor("mcp");
388
+ const mode = isRecord$1(mcp) && Object.hasOwn(mcp, "auth") ? mcp.auth : void 0;
389
+ const publicRoute = isRecord$1(mcp) && typeof mcp.publicRoute === "string" ? mcp.publicRoute : void 0;
390
+ if ((typeof mode === "boolean" || mode === "optional") && mcpPublicRouteNeedsSignedAuth(publicRoute, mode)) {
391
+ missing.push({ field: "mcp.publicRoute" });
392
+ inputFixes.push("Remove `mcp.publicRoute`, or enable Auth, set `mcp.auth=true`, and add `mcpOAuth()` to the Auth Definition.");
393
+ rerunnable = false;
394
+ } else if (!authEnabled && authStatus?.enabled === "unknown" && (mode === void 0 || mode === true || mode === "optional")) {
395
+ const file = project.configFile ?? "vite.config.ts";
396
+ const snippet = `mcp: ${toSource(isRecord$1(mcp) ? mcp : true)},`;
397
+ const fix = `Confirm Auth is enabled in the app. ${mcpOAuthSetup}. Add this key to the vitehub() options by hand:\n${snippet}`;
398
+ throw setupFailure(cliErrorDiagnostics.SETUP_CONFIG_MANUAL({
399
+ file,
400
+ fix,
401
+ reason: "Auth cannot be determined statically"
402
+ }), setupExitCodes.conflict, { data: { snippet } });
403
+ } else if (mode === true || mode === "optional" || mode === void 0 && authEnabled) {
404
+ if (authEnabled) needsMcpOAuth = true;
405
+ else {
406
+ missing.push({ field: "auth" });
407
+ inputFixes.push(`Select the \`auth\` feature or enable Auth in the app config. ${mcpOAuthSetup}.`);
408
+ rerunnable = false;
409
+ }
410
+ } else if (mode !== false) {
411
+ missing.push({
412
+ choices: [
413
+ "true",
414
+ "optional",
415
+ "false"
416
+ ],
417
+ field: "mcp.auth"
418
+ });
419
+ inputFixes.push("Enable Auth for signed requests and use `mcp.auth=true` or `mcp.auth=optional`, or omit `mcp.auth` to require sign-in by default. Pass `--option mcp.auth=false` only when anyone may call every tool.");
420
+ rerunnable = false;
421
+ }
422
+ }
354
423
  if (missing.length) {
355
424
  const fields = missing.map((item) => `\`${item.field}\``).join(", ");
356
- throw setupFailure(cliErrorDiagnostics.SETUP_INPUT_NEEDED({ message: `[vitehub] Set ${fields} to add ${args.features.join(", ")} on the ${host} host.` }), setupExitCodes.inputNeeded, {
425
+ const fix = inputFixes.length ? inputFixes.join(" ") : void 0;
426
+ throw setupFailure(cliErrorDiagnostics.SETUP_INPUT_NEEDED({
427
+ fix,
428
+ message: `[vitehub] Set ${fields} to add ${args.features.join(", ")} on the ${host} host.`
429
+ }), setupExitCodes.inputNeeded, {
357
430
  missing,
358
431
  ...rerunnable ? { rerun: rerun(args, defaults, requires) } : {}
359
432
  });
360
433
  }
361
434
  const edits = [];
362
435
  let expression = false;
363
- const site = project.config?.ok ? project.config.site : void 0;
364
436
  const addedFeatures = [...args.features, ...requires];
365
437
  for (const id of /* @__PURE__ */ new Set([...addedFeatures, ...inputFeatures.filter((id) => args.options[id])])) {
366
438
  const next = nextValue(id, status, project, args.options[id]);
@@ -461,11 +533,27 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
461
533
  const command = installCommand(project.packageManager, install.prod, install.dev);
462
534
  const restartRequired = addsDiscovery && !configFile;
463
535
  const nextSteps = restartRequired ? ["Restart the dev server to load the new feature configuration."] : [];
536
+ if (needsMcpOAuth) {
537
+ const [appServerDir, ...layers] = project.serverDirs ?? [];
538
+ const authFiles = features.auth.enabledByDiscovery ?? [];
539
+ const appFiles = appServerDir ? authFiles.map((name) => join(appServerDir, name)) : [];
540
+ const definition = appServerDir && [
541
+ ...appFiles,
542
+ ...authFiles.map((name) => join(definitionRoot, `server.${name}`)),
543
+ ...layers.flatMap((dir) => authFiles.map((name) => join(dir, name)))
544
+ ].find(existsSync);
545
+ const target = definition ? ` in \`${relative(project.root, definition)}\`` : "";
546
+ if (!definition && appServerDir) nextSteps.push(`Create an Auth Definition at \`${join(serverDir, "auth.ts")}\` if the app has none.`);
547
+ nextSteps.push(`${mcpOAuthSetup}${target}. https://vitehub.dev/docs/mcp/configure#sign-in-with-mcp-oauth`);
548
+ }
464
549
  if (command && !args.install) nextSteps.push(`Install the packages: ${command}`);
465
550
  for (const id of implied) {
466
551
  const support = featureSupport(id, host);
467
552
  if (support.level === "unsupported") nextSteps.push(`${id} is turned on by ${args.features.join(", ")} but is not supported on ${host}: ${support.detail} Set \`${id}: false\` to turn it off.`);
468
- else if (support.level === "explicit" && !setsOption(project, support.option) && !(args.options[id] && support.option.slice(id.length + 1) in args.options[id])) nextSteps.push(`${id} is turned on by ${args.features.join(", ")}. Set \`${support.option}\` on ${host}, or set \`${id}: false\`. ${support.detail}`);
553
+ else if (support.level === "explicit") {
554
+ const option = missingProviderOption(project, support.option, valueFor(id));
555
+ if (option) nextSteps.push(`${id} is turned on by ${args.features.join(", ")}. Set \`${option}\` on ${host}, or set \`${id}: false\`. ${support.detail}`);
556
+ }
469
557
  }
470
558
  for (const id of [...addedFeatures, ...implied]) {
471
559
  if (selectsProvider(id, valueFor(id))) continue;
@@ -509,7 +597,7 @@ async function applySetupAdd(project, planned, args, context) {
509
597
  stdout: "stderr"
510
598
  });
511
599
  if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
512
- command: [project.packageManager, ...commandArgs].join(" "),
600
+ command: formatInstallCommand(project.packageManager, commandArgs),
513
601
  exitCode: result.exitCode ?? result.signal
514
602
  }), setupExitCodes.error);
515
603
  }
@@ -612,9 +700,166 @@ function setupCatalog() {
612
700
  };
613
701
  }
614
702
  //#endregion
703
+ //#region src/setup/stack.ts
704
+ function replayOption(id, keys, value) {
705
+ if (keys.some((key) => !key || /[.=\0]/u.test(key) || [
706
+ "__proto__",
707
+ "constructor",
708
+ "prototype"
709
+ ].includes(key))) return;
710
+ const raw = typeof value === "object" ? JSON.stringify(value) : String(value);
711
+ if (raw.includes("\0")) return;
712
+ const flag = `${id}.${keys.join(".")}=${raw}`;
713
+ try {
714
+ const parsed = readAddArgs([
715
+ id,
716
+ "--option",
717
+ flag
718
+ ]).options[id];
719
+ const expected = keys.reduceRight((child, key) => ({ [key]: child }), value);
720
+ if (isDeepStrictEqual(parsed, expected)) return flag;
721
+ } catch {
722
+ return;
723
+ }
724
+ }
725
+ function credentialKey(key) {
726
+ return /(?:token|secret|password|passphrase|apikey|privatekey|accesskey(?:id)?|connectionstring|credentials?|authorization|cookie|dsn)$/iu.test(key.replaceAll(/[-_]/gu, "")) || /^(?:pass|auth|headers)$/iu.test(key);
727
+ }
728
+ function containsCredentials(value) {
729
+ if (typeof value === "string") {
730
+ const url = URL.parse(value.startsWith("//") ? `https:${value}` : value);
731
+ return !!(url && (url.username || url.password || url.search || url.hash));
732
+ }
733
+ if (Array.isArray(value)) return value.some(containsCredentials);
734
+ return isRecord$1(value) && Object.entries(value).some(([key, child]) => credentialKey(key) || containsCredentials(child));
735
+ }
736
+ function setupStackLabels(stack) {
737
+ return {
738
+ command: stack.command ?? "Unavailable",
739
+ omissions: stack.omits.map(({ path, reason }) => `${path} (${reason})`).join(", ")
740
+ };
741
+ }
742
+ async function deriveSetupStack(project, status, validate) {
743
+ const site = project.config?.ok ? project.config.site : void 0;
744
+ const omits = [];
745
+ const options = [];
746
+ const selected = [];
747
+ const collect = (id, keys, value) => {
748
+ const path = [id, ...keys].join(".");
749
+ if (!(path === "mcp.auth" && keys.length === 1 && (typeof value === "boolean" || value === "optional")) && keys.some(credentialKey)) {
750
+ omits.push({
751
+ path,
752
+ reason: "credential-option"
753
+ });
754
+ return;
755
+ }
756
+ if (isRecord$1(value) && Object.keys(value).length) {
757
+ for (const [key, child] of Object.entries(value)) collect(id, [...keys, key], child);
758
+ return;
759
+ }
760
+ if (containsCredentials(value)) {
761
+ omits.push({
762
+ path,
763
+ reason: "credential-option"
764
+ });
765
+ return;
766
+ }
767
+ const flag = keys.length ? replayOption(id, keys, value) : void 0;
768
+ if (flag === void 0) omits.push({
769
+ path,
770
+ reason: "non-replayable-option"
771
+ });
772
+ else options.push(flag);
773
+ };
774
+ if (!site) omits.push({
775
+ path: "config",
776
+ reason: "opaque-config"
777
+ });
778
+ if (site?.spread) omits.push({
779
+ path: "config",
780
+ reason: "spread"
781
+ });
782
+ if (status.host.name === "unknown") omits.push({
783
+ path: "host",
784
+ reason: "unresolved-host"
785
+ });
786
+ for (const { id, enabled, support } of status.features) {
787
+ const setting = site?.keys[id];
788
+ if (setting?.kind === "expression") {
789
+ omits.push({
790
+ path: id,
791
+ reason: "expression"
792
+ });
793
+ continue;
794
+ }
795
+ if (enabled === "unknown" && site && !site.spread) omits.push({
796
+ path: id,
797
+ reason: "unresolved-feature"
798
+ });
799
+ if (enabled !== "on") continue;
800
+ if (support.level === "unsupported") {
801
+ omits.push({
802
+ path: id,
803
+ reason: "unsupported-feature"
804
+ });
805
+ continue;
806
+ }
807
+ const value = setting?.value;
808
+ if (features[id].enabledByDefault && (value === void 0 || value === true || isRecord$1(value) && !Object.keys(value).length)) continue;
809
+ selected.push(id);
810
+ if (value !== void 0 && value !== true) collect(id, [], value);
811
+ }
812
+ const implied = impliedFeatures(selected);
813
+ for (const { id, enabled, reason } of status.features) if (enabled === "off" && reason === "config" && (features[id].enabledByDefault || implied.includes(id))) omits.push({
814
+ path: id,
815
+ reason: "disabled-feature"
816
+ });
817
+ const name = basename(project.root);
818
+ const args = [
819
+ name.startsWith("-") ? `./${name}` : name || "vitehub-app",
820
+ "--host",
821
+ status.host.name === "unknown" ? "<host>" : status.host.name,
822
+ "--features",
823
+ selected.join(","),
824
+ ...options.flatMap((option) => ["--option", option]),
825
+ "--framework",
826
+ status.framework === "nuxt" ? "nuxt" : "vite",
827
+ "--pm",
828
+ status.packageManager,
829
+ "--yes"
830
+ ];
831
+ if (status.host.name !== "unknown") try {
832
+ await validate(args);
833
+ } catch (error) {
834
+ if (!isSetupFailure(error)) throw error;
835
+ const missing = error.details.missing;
836
+ if (missing?.length) omits.push(...missing.map(({ field }) => ({
837
+ path: field,
838
+ reason: "required-option"
839
+ })));
840
+ else omits.push({
841
+ path: "features",
842
+ reason: "unplannable-stack"
843
+ });
844
+ return {
845
+ command: null,
846
+ omits
847
+ };
848
+ }
849
+ return {
850
+ command: [
851
+ "pnpm",
852
+ "dlx",
853
+ "vite-hub",
854
+ "init",
855
+ ...args.map(shellQuote)
856
+ ].join(" "),
857
+ omits
858
+ };
859
+ }
860
+ //#endregion
615
861
  //#region src/setup/init.ts
616
862
  const usage$2 = "vitehub init <dir> --host <host> --features <id,id,...> [--option <feature.key=value>]... [--framework vite|nuxt] [--pm pnpm|npm|yarn|bun] [--no-install] [--dry-run] --yes [--json]";
617
- /** The command that starts a project. It runs from the `vite-hub` package, so it needs no install. */
618
863
  const initCommandPrefix = "pnpm dlx vite-hub init";
619
864
  const initHosts = [
620
865
  "cloudflare",
@@ -652,7 +897,7 @@ const initPackages = {
652
897
  ],
653
898
  prod: [
654
899
  "vite-hub",
655
- "nitro@3.0.261102-rc",
900
+ "nitro@3.0.261103-rc",
656
901
  "h3@2.0.8",
657
902
  "valibot"
658
903
  ]
@@ -660,11 +905,7 @@ const initPackages = {
660
905
  };
661
906
  /** The pinned Nuxt CLI that creates a new Nuxt app. */
662
907
  const nuxiPackage = "nuxi@3.37.0";
663
- /** Pin the starter files and select Nuxt 5 explicitly instead of the live minimal registry entry. */
664
908
  const nuxtTemplate = "gh:nuxt/starter#db01806fcb37f2e369fb09443c72cac696b31548";
665
- /** Where the reproducing command lives in README.md. */
666
- const stackStart = "<!-- vitehub:stack -->";
667
- const stackEnd = "<!-- /vitehub:stack -->";
668
909
  function isRecord(value) {
669
910
  return !!value && typeof value === "object" && !Array.isArray(value);
670
911
  }
@@ -712,7 +953,6 @@ function readInitArgs(args) {
712
953
  if (features !== void 0) parsed.features = readAddArgs(features.split(",").map((item) => item.trim()).filter(Boolean)).features;
713
954
  return parsed;
714
955
  }
715
- /** The `vitehub add` arguments for the features and options of `init`. */
716
956
  function addArgsOf(args) {
717
957
  return {
718
958
  ...readAddArgs([...args.features, ...args.options.flatMap((option) => ["--option", option])]),
@@ -726,20 +966,15 @@ function initCommand(parts, extra) {
726
966
  initCommandPrefix,
727
967
  shellQuote(parts.dir),
728
968
  "--host",
729
- parts.host ?? "<host>",
969
+ shellQuote(parts.host ?? "<host>"),
730
970
  "--features",
731
- parts.features ? parts.features.join(",") || "''" : "<id,id,...>",
971
+ shellQuote(parts.features?.join(",") ?? "<id,id,...>"),
732
972
  ...options.flatMap((option) => ["--option", shellQuote(option)]),
733
973
  ...parts.framework === "nuxt" ? ["--framework", "nuxt"] : [],
734
974
  ...parts.pm && parts.pm !== "pnpm" ? ["--pm", parts.pm] : [],
735
975
  ...extra
736
976
  ].join(" ");
737
977
  }
738
- /** The command that creates the same stack, for README.md and `vitehub status`. */
739
- function stackCommand(parts) {
740
- return initCommand(parts, ["--yes"]);
741
- }
742
- /** The `rerun` command: the same request with `--yes`. */
743
978
  function rerunInit(args, parts) {
744
979
  return initCommand(parts, [
745
980
  ...args.install ? [] : ["--no-install"],
@@ -747,37 +982,9 @@ function rerunInit(args, parts) {
747
982
  ...args.json ? ["--json"] : []
748
983
  ]);
749
984
  }
750
- function stackBlock(command) {
751
- return `${stackStart}\nCreate the same stack with:\n\n\`\`\`sh\n${command}\n\`\`\`\n${stackEnd}\n`;
752
- }
753
- /** README.md with the stack block, or undefined when it already holds the same block. */
754
- function readmeWithStack(readme, name, command) {
755
- const block = stackBlock(command);
756
- if (readme === void 0) return `# ${name}\n\n${block}`;
757
- const from = readme.indexOf(stackStart);
758
- const to = readme.indexOf(stackEnd, from);
759
- if (from !== -1 && to !== -1) {
760
- const after = readme.slice(to + 23).replace(/^\r?\n/u, "");
761
- return `${readme.slice(0, from)}${block}${after}`;
762
- }
763
- return `${readme}${readme === "" || readme.endsWith("\n") ? "" : "\n"}\n${block}`;
764
- }
765
- /** The stack command in the README.md block of `root`, for `vitehub status`. `null` when there is no block. */
766
- async function readSetupStack(root) {
767
- const file = join(root, "README.md");
768
- if (!existsSync(file)) return null;
769
- const readme = await readFile(file, "utf8");
770
- const from = readme.indexOf(stackStart);
771
- const to = readme.indexOf(stackEnd, from);
772
- if (from === -1 || to === -1) return null;
773
- const command = readme.slice(from, to).split(/\r?\n/u).map((line) => line.trim()).find((line) => line.startsWith(initCommandPrefix));
774
- return command ? { command } : null;
775
- }
776
- /** The deployment name rules of `vitehub({ name })`, for the package.json name of a new app. */
777
985
  function packageNameOf(root) {
778
986
  return basename(root).trim().toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "") || "vitehub-app";
779
987
  }
780
- /** The files of a new Vite app, as `fixtures/docs-hosts/installation` has them. */
781
988
  function viteAppFiles(name, host) {
782
989
  return {
783
990
  ".gitignore": "node_modules\n.output\n.vitehub\n.env*\n!.env.example\n",
@@ -809,7 +1016,6 @@ function viteAppFiles(name, host) {
809
1016
  "vite.config.ts": `import { defineConfig } from "vite"\nimport { vitehub } from "vite-hub"\n\nexport default defineConfig({\n plugins: [vitehub({ host: "${host}" })],\n})\n`
810
1017
  };
811
1018
  }
812
- /** The config that `nuxi init` and the adoption would give, to plan a new Nuxt app before `nuxi init` runs. */
813
1019
  function nuxtAppFiles(name, host) {
814
1020
  return {
815
1021
  "nuxt.config.ts": `import viteHubNuxt from "vite-hub/nuxt"\n\nexport default defineNuxtConfig({\n modules: [\n [viteHubNuxt, { host: "${host}" }],\n ],\n})\n`,
@@ -881,7 +1087,6 @@ function manualConfig(file, reason, host, framework) {
881
1087
  snippet
882
1088
  }), setupExitCodes.conflict, { data: { snippet } });
883
1089
  }
884
- /** The config of an existing app with ViteHub registered on `host`. */
885
1090
  function adoptConfig(project, host, framework) {
886
1091
  const file = project.configFile ?? (framework === "nuxt" ? "nuxt.config.ts" : "vite.config.ts");
887
1092
  const config = project.config;
@@ -923,7 +1128,6 @@ function adoptConfig(project, host, framework) {
923
1128
  file
924
1129
  };
925
1130
  }
926
- /** Plans `vitehub init` without writing anything. Throws `SetupFailure` when the change needs input or is not possible. */
927
1131
  async function planInit(args, root, state, context) {
928
1132
  const name = packageNameOf(root);
929
1133
  const found = state.kind === "adopt" ? state.project.framework : void 0;
@@ -973,7 +1177,7 @@ async function planInit(args, root, state, context) {
973
1177
  packageManager,
974
1178
  packageManagerSource: args.pm ? "manifest" : detected.packageManagerSource,
975
1179
  root,
976
- serverDirs: state.kind === "adopt" ? state.project.serverDirs : [join(root, "server")]
1180
+ serverDirs: state.kind === "adopt" ? state.project.serverDirs : []
977
1181
  };
978
1182
  const addArgs = addArgsOf(args);
979
1183
  const parts = (extra = {}, extraFeatures = []) => {
@@ -1001,12 +1205,6 @@ async function planInit(args, root, state, context) {
1001
1205
  ...base.get(configFile),
1002
1206
  after: added.configFile.after
1003
1207
  });
1004
- const stack = stackCommand(parts());
1005
- const readme = state.kind === "create" ? void 0 : await readOptional(join(root, "README.md"));
1006
- base.set("README.md", {
1007
- ...readme === void 0 ? {} : { before: readme },
1008
- after: readmeWithStack(readme, name, stack)
1009
- });
1010
1208
  if (state.kind === "adopt") {
1011
1209
  const gitignore = await readOptional(join(root, ".gitignore"));
1012
1210
  base.set(".gitignore", {
@@ -1040,6 +1238,13 @@ async function planInit(args, root, state, context) {
1040
1238
  `Start the dev server: ${runScript(packageManager, "dev")}`,
1041
1239
  ...added.plan.nextSteps
1042
1240
  ];
1241
+ const finalConfig = base.get(configFile).after;
1242
+ const stackProject = {
1243
+ ...planned,
1244
+ config: locateViteHubConfig(configFile, finalConfig),
1245
+ configSource: finalConfig,
1246
+ packageManager: args.install && (command || scaffold) ? packageManager : detected.packageManager
1247
+ };
1043
1248
  return {
1044
1249
  install,
1045
1250
  plan: {
@@ -1058,14 +1263,27 @@ async function planInit(args, root, state, context) {
1058
1263
  packageManager,
1059
1264
  root,
1060
1265
  ...scaffold ? { scaffold: { command: [scaffold[0], ...scaffold[1]].join(" ") } } : {},
1061
- stack: { command: stack },
1062
1266
  status: writes.length || scaffold || command && args.install ? "planned" : "unchanged"
1063
1267
  },
1064
1268
  rerun: rerunInit(args, parts()),
1269
+ stackProject,
1065
1270
  writes,
1066
1271
  ...scaffold ? { scaffold } : {}
1067
1272
  };
1068
1273
  }
1274
+ function setupStack(project, status) {
1275
+ return deriveSetupStack(project, status, async (args) => {
1276
+ const inputs = await readInputs(readInitArgs(args));
1277
+ const rootDir = dirname(project.root);
1278
+ await planInit(inputs, resolve(rootDir, inputs.dir), {
1279
+ exists: false,
1280
+ kind: "create"
1281
+ }, {
1282
+ env: {},
1283
+ rootDir
1284
+ });
1285
+ });
1286
+ }
1069
1287
  async function applyInit(planned, install, context, scaffolded = false) {
1070
1288
  const { plan } = planned;
1071
1289
  const runInstall = async () => {
@@ -1079,7 +1297,7 @@ async function applyInit(planned, install, context, scaffolded = false) {
1079
1297
  stdout: "stderr"
1080
1298
  });
1081
1299
  if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
1082
- command: [plan.packageManager, ...commandArgs].join(" "),
1300
+ command: formatInstallCommand(plan.packageManager, commandArgs),
1083
1301
  exitCode: result.exitCode ?? result.signal,
1084
1302
  filesWritten: scaffolded || plan.mode === "create"
1085
1303
  }), setupExitCodes.error);
@@ -1102,7 +1320,6 @@ async function applyInit(planned, install, context, scaffolded = false) {
1102
1320
  }
1103
1321
  if (plan.mode === "create") await runInstall();
1104
1322
  }
1105
- /** Runs `nuxi init` for a new Nuxt app. ViteHub then adopts the app that it created. */
1106
1323
  async function scaffoldNuxt(planned, context) {
1107
1324
  const [command, commandArgs] = planned.scaffold;
1108
1325
  await mkdir(dirname(planned.plan.root), { recursive: true });
@@ -1118,7 +1335,6 @@ async function scaffoldNuxt(planned, context) {
1118
1335
  }), setupExitCodes.error);
1119
1336
  await validateNuxtVersion(planned.plan.root, true);
1120
1337
  }
1121
- /** Accept nonempty ranges confined to Nuxt 5, including its prereleases and nightly aliases. */
1122
1338
  function supportsNuxt5(nuxt) {
1123
1339
  if (typeof nuxt !== "string") return false;
1124
1340
  const range = validRange(nuxt.replace(/^npm:nuxt(?:-nightly)?@/u, ""));
@@ -1126,7 +1342,6 @@ function supportsNuxt5(nuxt) {
1126
1342
  const releases = new Range(range).set.map((comparators) => comparators.map(({ operator, semver, value }) => typeof semver !== "symbol" && semver.major === 5 && semver.prerelease.length > 0 ? `${operator}5.${semver.minor}.${semver.patch}` : value).join(" ")).join(" || ");
1127
1343
  return subset(releases, ">=5.0.0 <6.0.0");
1128
1344
  }
1129
- /** Validate both existing apps and scaffold output before planning adoption or installing packages. */
1130
1345
  async function validateNuxtVersion(root, scaffolded = false) {
1131
1346
  const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
1132
1347
  const dependencies = isRecord(manifest) && isRecord(manifest.dependencies) ? manifest.dependencies : {};
@@ -1150,7 +1365,6 @@ async function ask(question) {
1150
1365
  terminal.close();
1151
1366
  }
1152
1367
  }
1153
- /** Asks for missing inputs in a terminal. Without one, fails with the flag and its choices. */
1154
1368
  async function readInputs(args) {
1155
1369
  if (interactive(args)) {
1156
1370
  const dir = args.dir ?? (await ask("Folder of the app: ") || ".");
@@ -1201,13 +1415,22 @@ function writePlan$1(plan, context) {
1201
1415
  if (plan.scaffold) context.stdout.write(`Run: ${plan.scaffold.command}\n`);
1202
1416
  for (const change of plan.changes) if (change.kind === "create") context.stdout.write(`create ${change.path}\n`);
1203
1417
  else context.stdout.write(change.diff.endsWith("\n") ? change.diff : `${change.diff}\n`);
1204
- const lines = [...plan.install.command ? [`Install: ${plan.install.command}`] : [], ...plan.implied.length ? [`Also turns on: ${plan.implied.join(", ")}`] : []];
1205
- if (lines.length) context.stdout.write(`${lines.join("\n")}\n`);
1418
+ const lines = [
1419
+ ...plan.install.command ? [`Install: ${plan.install.command}`] : [],
1420
+ ...plan.implied.length ? [`Also turns on: ${plan.implied.join(", ")}`] : [],
1421
+ ...stackLines(plan.stack)
1422
+ ];
1423
+ context.stdout.write(`${lines.join("\n")}\n`);
1424
+ }
1425
+ function stackLines(stack) {
1426
+ const { command, omissions } = setupStackLabels(stack);
1427
+ return [`Stack: ${command}`, ...omissions ? [`Stack omissions: ${omissions}`] : []];
1206
1428
  }
1207
1429
  function writeResult$1(plan, context) {
1208
1430
  const features = plan.features.length ? ` with ${plan.features.join(", ")}` : "";
1209
1431
  if (plan.status === "unchanged") context.stdout.write(`${plan.root} already has this stack. Nothing to change.\n`);
1210
1432
  else context.stdout.write(`${plan.mode === "create" ? "Created" : "Set up"} ${plan.root} for ${plan.host}${features}.\n`);
1433
+ context.stdout.write(`${stackLines(plan.stack).join("\n")}\n`);
1211
1434
  context.stdout.write(`\nNext steps:\n${plan.nextSteps.map((step) => `- ${step}`).join("\n")}\n`);
1212
1435
  }
1213
1436
  async function runInit(rawArgs, context) {
@@ -1222,7 +1445,10 @@ async function runInit(rawArgs, context) {
1222
1445
  const args = await readInputs(parsed);
1223
1446
  const root = resolve(context.rootDir, args.dir);
1224
1447
  let planned = await planInit(args, root, await readDir(root, context.env), context);
1225
- const { plan } = planned;
1448
+ const plan = {
1449
+ ...planned.plan,
1450
+ stack: await setupStack(planned.stackProject, setupStatus(planned.stackProject, context.env))
1451
+ };
1226
1452
  if (plan.status === "unchanged" || args.dryRun) {
1227
1453
  if (args.json) writeSetupJson(context, plan);
1228
1454
  else if (plan.status === "unchanged") writeResult$1(plan, context);
@@ -1248,9 +1474,11 @@ async function runInit(rawArgs, context) {
1248
1474
  }, root, await readDir(root, context.env), context);
1249
1475
  }
1250
1476
  await applyInit(planned, args.install, context, !!plan.scaffold);
1477
+ const project = await readSetupProject(root, context.env);
1251
1478
  const applied = {
1252
1479
  ...planned.plan,
1253
1480
  mode: plan.mode,
1481
+ stack: await setupStack(project, setupStatus(project, context.env)),
1254
1482
  status: "applied",
1255
1483
  ...plan.scaffold ? { scaffold: plan.scaffold } : {}
1256
1484
  };
@@ -1310,11 +1538,9 @@ function rerunCommand(args) {
1310
1538
  ...args.json ? ["--json"] : []
1311
1539
  ].join(" ");
1312
1540
  }
1313
- /** The `vite-hub` subpath of a feature, such as `vite-hub/rate-limit`. */
1314
1541
  function runtimeModule(id) {
1315
1542
  return `vite-hub/${id === "sandboxTask" ? "sandbox/task" : id.replace(/[A-Z]/gu, (char) => `-${char.toLowerCase()}`)}`;
1316
1543
  }
1317
- /** The package of an import, such as `@vite-hub/schedule` for `@vite-hub/schedule/vite`. */
1318
1544
  function packageName(specifier) {
1319
1545
  const parts = specifier.split("/");
1320
1546
  return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
@@ -1322,7 +1548,6 @@ function packageName(specifier) {
1322
1548
  function importsModule(specifier, module) {
1323
1549
  return specifier === module || specifier.startsWith(`${module}/`);
1324
1550
  }
1325
- /** Imports (including static template literals), re-exports, module augmentations, and triple-slash type references. Comments can match, which only makes `remove` stricter. */
1326
1551
  const specifierPattern = /(?:\b(?:from|import|require|declare\s+module)(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)*(?:\((?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)*)?|\/\/\/\s*<reference\s+types\s*=\s*)(?:(["'])([^"'\r\n]+)\1|`((?:[^`$\r\n]|\$(?!\{))+)`)/gu;
1327
1552
  const sourceFile = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|mdx?|html?)$/iu;
1328
1553
  function lineAt(content, index) {
@@ -1330,7 +1555,6 @@ function lineAt(content, index) {
1330
1555
  for (let cursor = content.indexOf("\n"); cursor !== -1 && cursor < index; cursor = content.indexOf("\n", cursor + 1)) line++;
1331
1556
  return line;
1332
1557
  }
1333
- /** True when `content` equals the current or an earlier starter template for the Definition at `path`. */
1334
1558
  function isStarter(starter, path, content) {
1335
1559
  const parts = path.replace(/\.[^./]+$/u, "").split("/");
1336
1560
  const name = [
@@ -1340,7 +1564,6 @@ function isStarter(starter, path, content) {
1340
1564
  ].find((candidate) => candidate && starter.file(candidate) === path);
1341
1565
  return name !== void 0 && [starter.template, ...starter.previousTemplates ?? []].some((template) => template(name) === content);
1342
1566
  }
1343
- /** Features required by selected options. Unknown options can select any supported prerequisite. */
1344
1567
  function optionPrerequisites(id, value, unknown) {
1345
1568
  const options = isRecord$1(value) ? value : void 0;
1346
1569
  if (id === "cache" && (unknown || options?.driver === "kv")) return ["kv"];
@@ -1593,7 +1816,6 @@ async function planSetupRemove(project, args, env) {
1593
1816
  ...configPatch ? { configFile: configPatch } : {}
1594
1817
  };
1595
1818
  }
1596
- /** Deletes `path` and then each folder that is empty after it, such as the `server/queues` that `add` created. */
1597
1819
  async function deleteStarter(root, path) {
1598
1820
  await rm(join(root, path));
1599
1821
  for (let folder = dirname(join(root, path)); folder !== root && folder.startsWith(`${root}/`); folder = dirname(folder)) {
@@ -1701,14 +1923,9 @@ const dependencyFields = [
1701
1923
  "devDependencies",
1702
1924
  "optionalDependencies"
1703
1925
  ];
1704
- /** `vite-hub` and every `@vite-hub/*` package. */
1705
1926
  function isViteHubPackage(name) {
1706
1927
  return name === "vite-hub" || /^@vite-hub\/[a-z0-9][\w.-]*$/u.test(name);
1707
1928
  }
1708
- /**
1709
- * The package that an override or resolution key targets, such as `@vite-hub/env` for `foo>@vite-hub/env@0.1.0` or
1710
- * `**\/@vite-hub/env`. Undefined when it is not a ViteHub package.
1711
- */
1712
1929
  function overrideTarget(key) {
1713
1930
  let part = key.split(">").at(-1).replace(/^\*\*\//u, "");
1714
1931
  const scoped = part.lastIndexOf("/@");
@@ -1717,11 +1934,9 @@ function overrideTarget(key) {
1717
1934
  const name = part.replace(/(?<=.)@.*$/u, "");
1718
1935
  return isViteHubPackage(name) ? name : void 0;
1719
1936
  }
1720
- /** True for a specifier that names a release or a pkg.pr.new build, not `workspace:`, `catalog:`, a link, or git. */
1721
1937
  function isReplaceable(specifier) {
1722
1938
  return specifier.startsWith(`${previewBase}/`) || specifier === "latest" || specifier === "next" || semver.validRange(specifier) !== null;
1723
1939
  }
1724
- /** The new specifier for `name`, from the resolved npm version or preview URL. */
1725
1940
  function nextSpecifier(name, current, place, target) {
1726
1941
  if ("preview" in target) return target.url(name);
1727
1942
  const version = target.versions.get(name);
@@ -1731,7 +1946,6 @@ function nextSpecifier(name, current, place, target) {
1731
1946
  function isObject(value) {
1732
1947
  return !!value && typeof value === "object" && !Array.isArray(value);
1733
1948
  }
1734
- /** Calls `visit` for every ViteHub specifier in the update fields of a package.json. */
1735
1949
  function visitManifest(manifest, visit) {
1736
1950
  const entries = (holder, place, nameOf) => {
1737
1951
  if (!isObject(holder)) return;
@@ -1771,7 +1985,6 @@ function unquote(text) {
1771
1985
  value: text
1772
1986
  };
1773
1987
  }
1774
- /** A `key: value` line inside a block, such as ` "@vite-hub/env": 0.1.0 # pinned`. Undefined for other lines. */
1775
1988
  function readYamlEntry(line) {
1776
1989
  const match = /^(\s+)("[^"]+"|'[^']+'|[^\s#'"][^:#]*?):\s+(.+?)(\s+#.*)?$/u.exec(line);
1777
1990
  if (!match) return;
@@ -1785,12 +1998,10 @@ function readYamlEntry(line) {
1785
1998
  value
1786
1999
  };
1787
2000
  }
1788
- /** The top-level key of a line without indentation, such as `overrides` for `overrides:`. */
1789
2001
  function topLevelKey(line) {
1790
2002
  if (!line || /^\s/u.test(line) || line.startsWith("#") || line.startsWith("-")) return;
1791
2003
  return /^("[^"]+"|'[^']+'|[^:#\s]+):/u.exec(line)?.[1]?.replace(/^["']|["']$/gu, "");
1792
2004
  }
1793
- /** The line ranges of each top-level block of a YAML file. */
1794
2005
  function yamlBlocks(lines) {
1795
2006
  const blocks = /* @__PURE__ */ new Map();
1796
2007
  let current;
@@ -1806,7 +2017,6 @@ function yamlBlocks(lines) {
1806
2017
  }
1807
2018
  return blocks;
1808
2019
  }
1809
- /** The items of a top-level YAML list, such as `packages`, with their line numbers. */
1810
2020
  function yamlList(lines, range) {
1811
2021
  if (!range) return [];
1812
2022
  const inline = /^[^:]+:\s*\[(.*)\]\s*(#.*)?$/u.exec(lines[range.start]);
@@ -1822,14 +2032,11 @@ function yamlList(lines, range) {
1822
2032
  }] : [];
1823
2033
  });
1824
2034
  }
1825
- /** The name of a `minimumReleaseAgeExclude` entry that pins versions, such as `@vite-hub/env` for `@vite-hub/env@0.1.0`. */
1826
2035
  function pinnedName(entry) {
1827
2036
  const at = entry.indexOf("@", entry.startsWith("@") ? 1 : 0);
1828
2037
  return at > 0 ? entry.slice(0, at) : void 0;
1829
2038
  }
1830
- /** The patterns that let a fresh ViteHub release through pnpm's `minimumReleaseAge`. */
1831
2039
  const releaseAgePatterns = ["vite-hub", "@vite-hub/*"];
1832
- /** Calls `edit` for each ViteHub entry of the `overrides`, `catalog`, and `catalogs` blocks, and returns the removed lines. */
1833
2040
  function editYamlEntries(lines, edit) {
1834
2041
  const blocks = yamlBlocks(lines);
1835
2042
  const removed = /* @__PURE__ */ new Set();
@@ -1851,7 +2058,6 @@ function editYamlEntries(lines, edit) {
1851
2058
  }
1852
2059
  return removed;
1853
2060
  }
1854
- /** Rewrites the ViteHub entries of pnpm-workspace.yaml, and the settings that the target needs. */
1855
2061
  function updateWorkspaceYaml(text, edit, options) {
1856
2062
  const lines = text.split("\n");
1857
2063
  const removed = editYamlEntries(lines, edit);
@@ -1877,7 +2083,6 @@ function updateWorkspaceYaml(text, edit, options) {
1877
2083
  const after = lines.filter((_, index) => !removed.has(index)).join("\n");
1878
2084
  return after.endsWith("\n") || !after ? after : `${after}\n`;
1879
2085
  }
1880
- /** The workspace package folders that `patterns` select, relative to `root`. */
1881
2086
  async function workspaceFolders(root, patterns) {
1882
2087
  const find = async (selected) => {
1883
2088
  if (!selected.length) return /* @__PURE__ */ new Set();
@@ -1893,7 +2098,6 @@ async function workspaceFolders(root, patterns) {
1893
2098
  const excluded = await find(patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1)));
1894
2099
  return [...included].filter((folder) => !excluded.has(folder)).sort();
1895
2100
  }
1896
- /** The workspace patterns of a root: `packages` of pnpm-workspace.yaml, else `workspaces` of package.json. */
1897
2101
  function workspacePatterns(yaml, manifest) {
1898
2102
  if (yaml !== void 0) {
1899
2103
  const lines = yaml.split("\n");
@@ -1902,11 +2106,6 @@ function workspacePatterns(yaml, manifest) {
1902
2106
  const workspaces = manifest.workspaces;
1903
2107
  return (Array.isArray(workspaces) ? workspaces : isObject(workspaces) && Array.isArray(workspaces.packages) ? workspaces.packages : []).filter((item) => typeof item === "string");
1904
2108
  }
1905
- /**
1906
- * The root of the workspace that `start` belongs to: the nearest pnpm-workspace.yaml above, like pnpm finds it, or the
1907
- * nearest package.json whose `workspaces` list `start`, like npm, Yarn, and Bun. `start` itself when it has a lockfile
1908
- * or no workspace lists it.
1909
- */
1910
2109
  async function workspaceRoot(start) {
1911
2110
  if (setupLockfiles.some(([file]) => existsSync(join(start, file)))) return start;
1912
2111
  for (let folder = dirname(start), last = start; folder !== last; last = folder, folder = dirname(folder)) {
@@ -1961,7 +2160,6 @@ function readUpdateArgs(args) {
1961
2160
  }
1962
2161
  return parsed;
1963
2162
  }
1964
- /** Asks npm for the `latest` version of each package, or pkg.pr.new whether the build has it. Undefined when it has not. */
1965
2163
  async function resolvePackages(names, preview, context) {
1966
2164
  const request = context.fetch ?? fetch;
1967
2165
  const registry = (context.env.npm_config_registry || defaultRegistry).replace(/\/?$/u, "/");
@@ -2163,7 +2361,6 @@ function writeHelp(command, context) {
2163
2361
  context.stdout.write(`Usage: ${command.usage}\n\n${command.description}\n`);
2164
2362
  return setupExitCodes.done;
2165
2363
  }
2166
- /** Runs `body` and reports any error in the setup envelope. */
2167
2364
  async function runSetupCommand(command, args, context, body) {
2168
2365
  const json = args.includes("--json");
2169
2366
  try {
@@ -2207,6 +2404,7 @@ function credentialsLabel(credentials) {
2207
2404
  function writeStatus(status, context) {
2208
2405
  const shown = status.features.filter((feature) => feature.enabled !== "off");
2209
2406
  const off = status.features.length - shown.length;
2407
+ const stack = status.stack ? setupStackLabels(status.stack) : void 0;
2210
2408
  context.stdout.write(`${table([
2211
2409
  ["root", status.root],
2212
2410
  ["framework", status.framework],
@@ -2216,7 +2414,8 @@ function writeStatus(status, context) {
2216
2414
  ["link", linkLabel(status)],
2217
2415
  ["credentials", credentialsLabel(status.credentials)],
2218
2416
  ["live", liveLabel(status)],
2219
- ...status.stack ? [["stack", status.stack.command]] : []
2417
+ ...stack ? [["stack", stack.command]] : [],
2418
+ ...stack?.omissions ? [["stack omissions", stack.omissions]] : []
2220
2419
  ])}\n\n`);
2221
2420
  if (shown.length) context.stdout.write(`${table([[
2222
2421
  "feature",
@@ -2234,10 +2433,6 @@ function writeStatus(status, context) {
2234
2433
  function isCheckoutStatusModule(value) {
2235
2434
  return Object(value) === value && typeof Reflect.get(Object(value), "formatWorkspaceStatus") === "function" && typeof Reflect.get(Object(value), "localCheckoutStatus") === "function";
2236
2435
  }
2237
- /**
2238
- * The checkout folders of `vitehub.lock`, read by the Workspace package that the project installs. Undefined without a
2239
- * lock file. The Workspace package reads only local files here; it never calls the app.
2240
- */
2241
2436
  async function readCheckouts(root) {
2242
2437
  if (!existsSync(join$1(root, "vitehub.lock"))) return void 0;
2243
2438
  const require = createRequire(join$1(root, "package.json"));
@@ -2281,7 +2476,7 @@ const statusCommand = {
2281
2476
  offline,
2282
2477
  signal
2283
2478
  }),
2284
- stack: await readSetupStack(project.root)
2479
+ stack: "manual" in features.config && features.config.manual === "no-vitehub" ? null : await setupStack(project, features)
2285
2480
  };
2286
2481
  const checkouts = await readCheckouts(status.root);
2287
2482
  if (json) {
@@ -2429,4 +2624,4 @@ const setupCommands = [
2429
2624
  whoamiCommand
2430
2625
  ];
2431
2626
  //#endregion
2432
- export { addCommand as _, updateCommand as a, readAddArgs as b, planSetupRemove as c, initCommandDefinition as d, initPackages as f, setupCatalog as g, readSetupStack as h, readUpdateArgs as i, readRemoveArgs as l, readInitArgs as m, setupCommands as n, updateInstallArgs as o, nuxiPackage as p, planSetupUpdate as r, applySetupRemove as s, commands_exports as t, removeCommand as u, applySetupAdd as v, shellQuote as x, planSetupAdd as y };
2627
+ export { applySetupAdd as _, updateCommand as a, planSetupRemove as c, initCommandDefinition as d, initPackages as f, addCommand as g, setupCatalog as h, readUpdateArgs as i, readRemoveArgs as l, readInitArgs as m, setupCommands as n, updateInstallArgs as o, nuxiPackage as p, planSetupUpdate as r, applySetupRemove as s, commands_exports as t, removeCommand as u, planSetupAdd as v, readAddArgs as y };