@vite-hub/cli 0.1.0 → 0.3.1

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.
@@ -0,0 +1,919 @@
1
+ import { l as HostCredentials, o as CredentialHost, r as ViteHubCliContext, s as CredentialSource, t as ViteHubCliCommand, u as HostCredentialsDescription } from "../provision-C9p1wSzq.js";
2
+ //#region ../internal/dist/config-edit.d.ts
3
+ //#region src/config-edit.d.ts
4
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
5
+ readonly [key: string]: JsonValue;
6
+ };
7
+ type ConfigForm = "vite-call" | "nuxt-module-tuple" | "nuxt-config-key";
8
+ type ManualReason = "parse-error" | "no-vitehub" | "multiple-vitehub" | "dynamic-options" | "spread" | "computed-key";
9
+ type ConfigValue = {
10
+ kind: "literal";
11
+ value: JsonValue;
12
+ } | {
13
+ kind: "expression";
14
+ source: string;
15
+ line: number;
16
+ };
17
+ interface ViteHubConfigSite {
18
+ form: ConfigForm;
19
+ /** Byte range of the options object. Absent when the call or tuple has no options. */
20
+ options?: {
21
+ start: number;
22
+ end: number;
23
+ };
24
+ keys: Readonly<Record<string, ConfigValue>>;
25
+ /** True when a spread can supply keys that are not in `keys`. */
26
+ spread: boolean;
27
+ /** Top-level Nuxt options used to locate server discovery directories. */
28
+ nuxt?: {
29
+ keys: Readonly<Record<string, ConfigValue>>;
30
+ spread: boolean;
31
+ };
32
+ }
33
+ type LocateResult = {
34
+ ok: true;
35
+ site: ViteHubConfigSite;
36
+ } | {
37
+ ok: false;
38
+ reason: ManualReason;
39
+ line?: number;
40
+ };
41
+ //#endregion
42
+ //#region ../internal/dist/deployment.d.ts
43
+ //#region src/deployment.d.ts
44
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
45
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
46
+ type DeploymentService = "blob" | "browser" | "queue" | "rateLimit" | "realtime" | "sandbox";
47
+ //#endregion
48
+ //#region ../internal/dist/features.d.ts
49
+ //#region src/features.d.ts
50
+ /**
51
+ * The feature keys of `vitehub({...})`. `vitehub add <feature>` and `vitehub status` read this list before the owner
52
+ * package of a feature is installed, so the catalog is plain data with no owner imports.
53
+ */
54
+ declare const featureIds: readonly ["agent", "auth", "blob", "browser", "cache", "channels", "comments", "connections", "console", "database", "email", "env", "i18n", "kv", "mcp", "observability", "queue", "rateLimit", "realtime", "sandboxTask", "schedule", "workflow", "workspace"];
55
+ type FeatureId = (typeof featureIds)[number];
56
+ /** `dev` stores default Node development support. Use `featureSupport()` with the configured host for development lookups. */
57
+ declare const featureHosts: readonly ["dev", "cloudflare", "vercel", "netlify", "deno", "node"];
58
+ type FeatureHost = (typeof featureHosts)[number];
59
+ interface NativeHostSupport {
60
+ level: "native";
61
+ /** The default driver that ViteHub selects, such as `cloudflare`. */
62
+ driver: string;
63
+ /** Short name for tables, such as `R2`. */
64
+ display: string;
65
+ guarantee: "native" | "single-host" | "process-local";
66
+ detail: string;
67
+ /** The first override whose environment variable has a non-empty, trimmed value replaces the default. */
68
+ envOverrides?: readonly {
69
+ env: string;
70
+ support: Omit<NativeHostSupport, "envOverrides">;
71
+ }[];
72
+ }
73
+ /**
74
+ * How a host supports a feature when the app enables it in `vitehub({...})`.
75
+ * - `native`: ViteHub selects a driver for the host. Credentials can still be needed.
76
+ * - `explicit`: the app must set `option` to choose a driver.
77
+ * - `unsupported`: `vitehub({...})` cannot provide the feature on this host.
78
+ */
79
+ type HostSupport = NativeHostSupport | {
80
+ level: "explicit";
81
+ display: string;
82
+ /** The option path that selects a driver, such as `blob.driver`. */
83
+ option: `${FeatureId}.${string}`;
84
+ detail: string;
85
+ } | {
86
+ level: "unsupported";
87
+ detail: string;
88
+ };
89
+ /** A feature that this feature turns on, unless the app sets the other feature to `false`. */
90
+ interface FeatureImplication {
91
+ feature: FeatureId;
92
+ /** Hosts where the implication does not apply. */
93
+ except?: readonly ViteHubHost[];
94
+ /**
95
+ * Hosts where the implied feature needs no provider option, because it runs inline in the request process. A
96
+ * restart loses its work. The feature still needs its option when the app turns it on itself.
97
+ */
98
+ inline?: readonly ViteHubHost[];
99
+ }
100
+ /** The starter Definition file that `vitehub add <feature> --name <name>` creates. */
101
+ interface FeatureStarter {
102
+ /** The folder of the Definitions, relative to the project root, such as `server/queues`. */
103
+ dir: string;
104
+ /** The path of the Definition `name`, relative to the project root. */
105
+ file: (name: string) => string;
106
+ /** The source of a minimal Definition named `name`. */
107
+ template: (name: string) => string;
108
+ /**
109
+ * Earlier versions of `template`. `vitehub remove` deletes a file only when it equals the current or an earlier
110
+ * starter, so keep the old template here when you change one.
111
+ */
112
+ previousTemplates?: readonly ((name: string) => string)[];
113
+ /**
114
+ * Other files, relative to the project root, that already define the Definition `name` or that the owner rejects
115
+ * next to it. The starter is not written when one exists.
116
+ */
117
+ conflicts: (name: string) => readonly string[];
118
+ }
119
+ interface FeatureDefinition<TId extends FeatureId = FeatureId> {
120
+ id: TId;
121
+ title: string;
122
+ /** One sentence for pickers and docs. */
123
+ summary: string;
124
+ docs: `/docs/${string}`;
125
+ /** Whether the feature is unconditionally on when the app does not set its key. */
126
+ enabledByDefault: boolean;
127
+ /** File names in the configured server directories (default `server/`) that enable an unset feature. `false` disables discovery. */
128
+ enabledByDiscovery?: readonly string[];
129
+ /** Packages that the app installs for this feature, in `pnpm add` order. */
130
+ packages: readonly string[];
131
+ /** Additional packages selected by literal provider options. */
132
+ providerPackages?: Readonly<Record<string, Readonly<Record<string, readonly string[]>>>>;
133
+ /** Development dependencies that the app installs for this feature. */
134
+ devPackages: readonly string[];
135
+ implies: readonly FeatureImplication[];
136
+ /** The Deployment Plan service that this feature reads, when it has one. */
137
+ service?: DeploymentService;
138
+ hosts: Readonly<Record<FeatureHost, HostSupport>>;
139
+ /** The starter Definition, for features with Definition files. */
140
+ definition?: FeatureStarter;
141
+ /** Hosts that use `hosts.dev` during development instead of their deployment entry. Node always uses `hosts.dev`. */
142
+ developmentOverrides?: readonly ViteHubHost[];
143
+ }
144
+ //#endregion
145
+ //#region src/setup/project.d.ts
146
+ type SetupFramework = "vite" | "nuxt" | "none";
147
+ type SetupPackageManager = "pnpm" | "npm" | "yarn" | "bun";
148
+ interface SetupProject {
149
+ root: string;
150
+ framework: SetupFramework;
151
+ packageManager: SetupPackageManager;
152
+ /** Where `packageManager` comes from. `default` means npm, because nothing named one. */
153
+ packageManagerSource: "manifest" | "lockfile" | "user-agent" | "default";
154
+ /** The config file name in `root`, such as `vite.config.ts`. */
155
+ configFile?: string;
156
+ /** Where `vitehub()` options are in `configFile`. `undefined` when there is no config file. */
157
+ config: LocateResult | undefined;
158
+ /** The text of `configFile` that `config` was read from. */
159
+ configSource?: string;
160
+ /** True when the target manifest declares `name` for production, or for development when `dev` is true. */
161
+ declared: (name: string, dev: boolean) => boolean;
162
+ /** Static discovery directories; undefined when Nuxt directories or layers need evaluation. */
163
+ serverDirs?: readonly string[];
164
+ /** True when `name` is resolvable from the project or present in an ancestor's node_modules. */
165
+ installed: (name: string) => boolean;
166
+ }
167
+ /**
168
+ * Reads the project in `root` without loading its config: the config file is parsed, never run.
169
+ * Throws `SETUP_NOT_A_PROJECT` when `root` has no package.json and no Vite or Nuxt config.
170
+ */
171
+ export declare function readSetupProject(root: string, env: NodeJS.ProcessEnv): Promise<SetupProject>;
172
+ //#endregion
173
+ //#region src/setup/status.d.ts
174
+ interface SetupFeatureStatus {
175
+ id: FeatureId;
176
+ enabled: "on" | "off" | "unknown";
177
+ /** `config` when the config sets the key, `default` when it does not, `implied` when another feature turns it on. */
178
+ reason: "config" | "default" | "implied";
179
+ support: HostSupport | {
180
+ level: "unknown";
181
+ detail: string;
182
+ };
183
+ /** Packages and development packages of an enabled feature that are not installed. */
184
+ missingPackages: readonly string[];
185
+ /** The next step, such as the install command of `missingPackages`. */
186
+ fix?: string;
187
+ }
188
+ interface SetupStatus {
189
+ schemaVersion: 1;
190
+ root: string;
191
+ framework: SetupProject["framework"];
192
+ config: {
193
+ file: string;
194
+ form: ConfigForm;
195
+ } | {
196
+ file?: string;
197
+ manual: ManualReason;
198
+ line?: number;
199
+ };
200
+ host: {
201
+ name: ViteHubHost | "unknown";
202
+ source: "config" | "env" | "default";
203
+ };
204
+ packageManager: SetupPackageManager;
205
+ features: readonly SetupFeatureStatus[];
206
+ }
207
+ /** What the project enables, on which host, and what each enabled feature still needs. Reads the config without running it. */
208
+ export declare function setupStatus(project: SetupProject, env: NodeJS.ProcessEnv): SetupStatus;
209
+ //#endregion
210
+ //#region src/setup/add.d.ts
211
+ interface SetupAddArgs {
212
+ features: FeatureId[];
213
+ json: boolean;
214
+ dryRun: boolean;
215
+ yes: boolean;
216
+ install: boolean;
217
+ name?: string;
218
+ /** `--option` values, by feature. */
219
+ options: Partial<Record<FeatureId, Record<string, JsonValue>>>;
220
+ help: boolean;
221
+ }
222
+ interface SetupChange {
223
+ /** Relative to the project root. */
224
+ path: string;
225
+ /** `delete` is a file that `vitehub remove` deletes; its `after` is empty. */
226
+ kind: "create" | "patch" | "delete";
227
+ before?: string;
228
+ after: string;
229
+ /** A unified diff from `before` to `after`. */
230
+ diff: string;
231
+ }
232
+ interface SetupAddPlan {
233
+ /** `planned` for a dry run or a plan that waits for `--yes`, `applied` when done, `unchanged` when there is nothing to do. */
234
+ status: "planned" | "applied" | "unchanged";
235
+ root: string;
236
+ host: SetupStatus["host"];
237
+ features: readonly FeatureId[];
238
+ changes: readonly SetupChange[];
239
+ install: {
240
+ packages: readonly string[];
241
+ devPackages: readonly string[];
242
+ command?: string;
243
+ };
244
+ /** Features that the added features turn on. Only supplied provider options need an explicit config key. */
245
+ implied: readonly FeatureId[];
246
+ nextSteps: readonly string[];
247
+ }
248
+ /** Reads the arguments. Throws `CLI_R0003` for an unknown flag, feature, or option. */
249
+ export declare function readAddArgs(args: readonly string[]): SetupAddArgs;
250
+ /** `--option` values by feature. */
251
+ type SetupOptions = Partial<Record<FeatureId, Record<string, JsonValue>>>;
252
+ /** Builds the command that `rerun` reports: the request with `extra` options and `extraFeatures` added. */
253
+ type SetupRerun = (args: SetupAddArgs, extra?: SetupOptions, extraFeatures?: readonly FeatureId[]) => string;
254
+ /** A `vitehub add` plan with the file contents that applying it writes. */
255
+ interface SetupAddPlanned {
256
+ plan: SetupAddPlan;
257
+ configFile?: {
258
+ path: string;
259
+ before: string;
260
+ after: string;
261
+ };
262
+ files: {
263
+ path: string;
264
+ content: string;
265
+ }[];
266
+ install: {
267
+ prod: string[];
268
+ dev: string[];
269
+ };
270
+ }
271
+ /** Plans `vitehub add` without writing anything. Throws `SetupFailure` when the change needs input or is not possible. */
272
+ export declare function planSetupAdd(project: SetupProject, args: SetupAddArgs, env: NodeJS.ProcessEnv, rerun?: SetupRerun): Promise<SetupAddPlanned>;
273
+ /** Applies a `vitehub add` plan: installs the packages, writes the starter Definitions, and writes the config last. */
274
+ export declare function applySetupAdd(project: SetupProject, planned: SetupAddPlanned, args: Pick<SetupAddArgs, "install">, context: Pick<ViteHubCliContext, "env" | "spawn">): Promise<void>;
275
+ export declare const addCommand: ViteHubCliCommand;
276
+ //#endregion
277
+ //#region src/setup/catalog.d.ts
278
+ interface SetupCatalog {
279
+ schemaVersion: 1;
280
+ hosts: readonly FeatureHost[];
281
+ features: readonly FeatureDefinition[];
282
+ }
283
+ /** Every feature of `vitehub({...})` and how each host supports it. Needs no project. */
284
+ export declare function setupCatalog(): SetupCatalog;
285
+ //#endregion
286
+ //#region src/setup/commands.d.ts
287
+ /** The setup commands. They run before the CLI loads the project config. */
288
+ export declare const setupCommands: readonly ViteHubCliCommand[];
289
+ //#endregion
290
+ //#region src/setup/console-auth.d.ts
291
+ /** The hosted Console. `--console` and `VITEHUB_CONSOLE_URL` name a self-hosted one. */
292
+ export declare const defaultConsoleUrl = "https://console.vitehub.dev";
293
+ /** An API key for CI. It wins over the saved key, and `vitehub logout` does not remove it. */
294
+ export declare const consoleTokenVariable = "VITEHUB_CONSOLE_TOKEN";
295
+ export declare const consoleUrlVariable = "VITEHUB_CONSOLE_URL";
296
+ /** What `vitehub login` keeps for one Console. The file is readable only by its owner. */
297
+ interface ConsoleCredential {
298
+ token: string;
299
+ keyId: string;
300
+ user: {
301
+ id: string;
302
+ name: string;
303
+ email: string;
304
+ };
305
+ team: {
306
+ id: string;
307
+ name: string;
308
+ };
309
+ /** Milliseconds since 1970. */
310
+ expiresAt: number;
311
+ }
312
+ /** `$XDG_CONFIG_HOME/vitehub/credentials.json`, else `~/.config/vitehub/credentials.json`. */
313
+ export declare function consoleCredentialsFile(env: NodeJS.ProcessEnv): string;
314
+ /** The origin of a Console URL. Plain `http` is accepted only for a Console on this machine. */
315
+ export declare function consoleOrigin(value: string): string;
316
+ /**
317
+ * The key that a command sends to a Console, and where it came from: `VITEHUB_CONSOLE_TOKEN`, else the key that
318
+ * `vitehub login` saved for the Console. Without `console`, the Console is `VITEHUB_CONSOLE_URL`, else the only saved
319
+ * Console, else console.vitehub.dev. `undefined` when there is no key.
320
+ */
321
+ export declare function readConsoleCredential(env: NodeJS.ProcessEnv, console?: string): Promise<{
322
+ origin: string;
323
+ token: string;
324
+ source: "env" | "file";
325
+ saved?: ConsoleCredential;
326
+ } | undefined>;
327
+ export declare const loginCommand: ViteHubCliCommand;
328
+ export declare const whoamiCommand: ViteHubCliCommand;
329
+ export declare const logoutCommand: ViteHubCliCommand;
330
+ //#endregion
331
+ //#region src/setup/envelope.d.ts
332
+ /** Exit codes of the setup commands. */
333
+ export declare const setupExitCodes: {
334
+ readonly done: 0;
335
+ readonly error: 1;
336
+ readonly inputNeeded: 2;
337
+ readonly conflict: 3;
338
+ readonly stalePlan: 4;
339
+ };
340
+ interface SetupError {
341
+ code: string;
342
+ message: string;
343
+ why: string;
344
+ fix?: string;
345
+ docs?: string;
346
+ }
347
+ /** One accepted value of a missing input. Accounts carry an id and a name; plain values are strings. */
348
+ type SetupChoice = string | {
349
+ id: string;
350
+ name?: string;
351
+ };
352
+ /** An input that a setup command needs, such as an account id, with the values it accepts when there are few. */
353
+ interface SetupMissing {
354
+ field: string;
355
+ choices?: readonly SetupChoice[];
356
+ }
357
+ interface SetupFailureDetails {
358
+ missing?: readonly SetupMissing[];
359
+ /** A command that would succeed, with `<placeholders>` for values that the caller must choose. */
360
+ rerun?: string;
361
+ /** More fields of the JSON document, such as the plan. */
362
+ data?: object;
363
+ }
364
+ /** A setup diagnostic with its exit code and the input that is missing. `writeSetupError` reports it. */
365
+ type SetupFailure = Error & {
366
+ readonly details: SetupFailureDetails;
367
+ readonly exitCode: number;
368
+ };
369
+ //#endregion
370
+ //#region src/setup/link.d.ts
371
+ /** The link file, relative to the project root. It is gitignored and never holds a secret. */
372
+ export declare const SETUP_LINK_FILE = ".vitehub/link.json";
373
+ type SetupLinkHost = CredentialHost;
374
+ interface SetupLinkAccount {
375
+ id: string;
376
+ name?: string;
377
+ }
378
+ /** One host target of `.vitehub/link.json`. */
379
+ interface SetupLinkTarget {
380
+ /** Absent only for a Deno link without `--account`. */
381
+ account?: SetupLinkAccount;
382
+ project: {
383
+ id?: string;
384
+ name: string;
385
+ };
386
+ /** True when the host API confirmed that the project exists. */
387
+ verified: boolean;
388
+ linkedAt: string;
389
+ }
390
+ /** A host target with its host, as deploy and the other commands use it. */
391
+ interface SetupLink extends SetupLinkTarget {
392
+ host: SetupLinkHost;
393
+ }
394
+ /** The content of `.vitehub/link.json`: one target for each linked host, and the host that deploys without `--host`. */
395
+ interface SetupLinkFile {
396
+ schemaVersion: 2;
397
+ default?: SetupLinkHost;
398
+ targets: Partial<Record<SetupLinkHost, SetupLinkTarget>>;
399
+ }
400
+ /** The parsed link file. `targets` is empty when the project has no link. */
401
+ interface SetupLinks {
402
+ default?: SetupLinkHost;
403
+ targets: SetupLink[];
404
+ }
405
+ /** The link fields that `vitehub status` reports. */
406
+ type SetupLinkSummary = Pick<SetupLink, "host" | "account" | "project" | "verified">;
407
+ interface SetupLinkOptions {
408
+ host?: string;
409
+ project?: string;
410
+ account?: string;
411
+ create: boolean;
412
+ /** Make this host the default target. The first linked host is always the default. */
413
+ default?: boolean;
414
+ }
415
+ interface SetupLinkResult {
416
+ file: string;
417
+ link: SetupLink;
418
+ /** The host that `vitehub deploy` uses without `--host`. `null` with several hosts and no default. */
419
+ default: SetupLinkHost | null;
420
+ /** Every linked host, this one included. */
421
+ hosts: SetupLinkHost[];
422
+ /** True when `--create` created the project on the host. */
423
+ created: boolean;
424
+ /** Where the credentials came from. `null` when the host needs none for a link (Deno). */
425
+ credentials: {
426
+ source: CredentialSource;
427
+ } | null;
428
+ /** `added` when the command appended `.vitehub` to `.gitignore`. `no-gitignore` when the project has no `.gitignore`. */
429
+ gitignore: "added" | "present" | "no-gitignore";
430
+ }
431
+ /** Looks up the project on the host, creates it with `create`, and writes `.vitehub/link.json`. */
432
+ export declare function linkSetupProject(project: SetupProject, options: SetupLinkOptions, context: ViteHubCliContext): Promise<SetupLinkResult>;
433
+ /**
434
+ * Removes the target of `host`, or the whole link file without `host`. When the default target goes and one target
435
+ * stays, that one becomes the default. Returns false when there was nothing to remove.
436
+ */
437
+ export declare function unlinkSetupProject(root: string, host?: SetupLinkHost): Promise<boolean>;
438
+ /**
439
+ * Reads the targets of `.vitehub/link.json`. A missing or unreadable file has no target. A file of schema version 1
440
+ * holds one host link, so it reads as one target that is also the default. The next write saves it as version 2.
441
+ */
442
+ export declare function readSetupLinks(root: string): Promise<SetupLinks>;
443
+ /** The result of picking a target: the target, none, or several without a default. */
444
+ type SetupLinkSelection = {
445
+ link: SetupLink | undefined;
446
+ } | {
447
+ ambiguous: SetupLinkHost[];
448
+ };
449
+ /** Picks the target of `host`. Without `host`: the default target, else the only target. */
450
+ export declare function selectSetupLink(links: SetupLinks, host?: SetupLinkHost): SetupLinkSelection;
451
+ /** What `vitehub status` adds to the feature status. */
452
+ interface SetupLinkStatus {
453
+ /** The target that `vitehub deploy` uses without `--host`. With several targets and no default, the target of the config host, else `null`. */
454
+ link: SetupLinkSummary | null;
455
+ /** Every linked host target. */
456
+ targets: SetupLinkSummary[];
457
+ /** The host that `vitehub deploy` uses without `--host`. */
458
+ default: SetupLinkHost | null;
459
+ /** For the `link` host, else the config host. Never includes the token. `null` on a host without credentials (Node). */
460
+ credentials: HostCredentialsDescription | null;
461
+ }
462
+ /** The link file and the credentials that `vitehub status` reads. `credentials` holds the token and never goes in output. */
463
+ interface SetupLinkState {
464
+ status: SetupLinkStatus;
465
+ link: SetupLink | undefined;
466
+ credentials: HostCredentials | undefined;
467
+ }
468
+ /** Reads the link and credentials, skipping CLI discovery offline and sharing the online host deadline. */
469
+ export declare function readSetupLinkState(project: SetupProject, host: string, context: ViteHubCliContext, options?: {
470
+ offline?: boolean;
471
+ signal?: AbortSignal;
472
+ }): Promise<SetupLinkState>;
473
+ /** The link and the credential status for `vitehub status`. The credentials never include the token. */
474
+ export declare function readSetupLinkStatus(project: SetupProject, host: string, context: ViteHubCliContext): Promise<SetupLinkStatus>;
475
+ //#endregion
476
+ //#region src/setup/deploy/host.d.ts
477
+ /** The hosts that `vitehub deploy` deploys to. */
478
+ type DeployHost = "cloudflare" | "vercel" | "netlify" | "deno";
479
+ /** The git commit of the deployed source. A folder without git has none. */
480
+ interface DeployCommit {
481
+ sha: string;
482
+ dirty: boolean;
483
+ }
484
+ /** Where a deployment came from, when the host says. */
485
+ type HostDeploymentSource = "cli" | "git" | "dashboard" | "api" | "unknown";
486
+ /** One deployment as the host lists it. */
487
+ interface HostDeployment {
488
+ id: string;
489
+ /** The URL of this deployment. Absent when the host gives it no own URL. */
490
+ url?: string;
491
+ createdAt: string;
492
+ state: "ready" | "building" | "error" | "canceled" | "unknown";
493
+ target: "production" | "preview";
494
+ /** True for the deployment that receives production traffic. */
495
+ live: boolean;
496
+ /** The Worker version of a Cloudflare deployment. */
497
+ version?: string;
498
+ /**
499
+ * The deployed commit. `from: "vitehub"` is the marker of `vitehub deploy`. `from: "host"` is the commit of a Git
500
+ * integration build, which builds a clean checkout.
501
+ */
502
+ commit?: DeployCommit & {
503
+ from: "vitehub" | "host";
504
+ };
505
+ source: HostDeploymentSource;
506
+ }
507
+ //#endregion
508
+ //#region src/setup/deploy/after.d.ts
509
+ /** One path of `deploy.check`, as the deployed app answered it. */
510
+ interface DeployCheckResult {
511
+ path: string;
512
+ url: string;
513
+ ok: boolean;
514
+ /** The last HTTP status. Missing when no request got an answer. */
515
+ status?: number;
516
+ /** Why the last request got no answer, such as a timeout. */
517
+ error?: string;
518
+ }
519
+ /** How to put the previous production deployment back, when a check fails. */
520
+ interface DeployRollback {
521
+ /** The deployment that received production traffic before this deploy. Missing on a first deploy or when it is not known. */
522
+ previous?: {
523
+ deploymentId: string;
524
+ version?: string;
525
+ };
526
+ /** The command that rolls production back to `previous`. Missing when the host has no rollback command. */
527
+ command?: string;
528
+ /** What to do when there is no command, or why `previous` is not known. */
529
+ note?: string;
530
+ }
531
+ /** What `vitehub deploy --json` prints for the IndexNow submission. */
532
+ type DeployIndexNowOutput = {
533
+ submitted: number;
534
+ status: number;
535
+ } | {
536
+ error: string;
537
+ status?: number;
538
+ };
539
+ //#endregion
540
+ //#region src/setup/deploy/checkouts.d.ts
541
+ /** What `pushWorkspaces()` returns for one checkout folder, the same as `vitehub push --json`. */
542
+ interface CheckoutPushResult {
543
+ workspace: string;
544
+ ref: string;
545
+ /** The new head. Undefined when nothing changed locally. */
546
+ revision?: string;
547
+ pushed: string[];
548
+ /** The pulls before the build and the push, in order. */
549
+ pull: {
550
+ workspace: string;
551
+ ref: string;
552
+ from: string | null;
553
+ head: string | null;
554
+ files: Array<{
555
+ path: string;
556
+ action: string;
557
+ note?: string;
558
+ }>;
559
+ };
560
+ /** The pull after the first push to a new ref that inherits files from another ref. */
561
+ after?: CheckoutPushResult["pull"];
562
+ }
563
+ interface CheckoutPushError {
564
+ code: string;
565
+ message: string;
566
+ fix?: string;
567
+ }
568
+ /** `checkouts` of `vitehub deploy --json`: the push results and the files to commit, or the error of the push. */
569
+ type DeployCheckoutsOutput = {
570
+ results: CheckoutPushResult[];
571
+ changed: string[];
572
+ } | {
573
+ error: CheckoutPushError;
574
+ };
575
+ //#endregion
576
+ //#region src/setup/env.d.ts
577
+ /** One set of names that the app reads, without its values. */
578
+ interface EnvDiffEntry {
579
+ names: readonly string[];
580
+ prefix?: string;
581
+ path?: string;
582
+ owners?: readonly string[];
583
+ secret: boolean;
584
+ }
585
+ /** What `vitehub deploy --json` prints in `env`. Names only, never a value. */
586
+ interface DeployEnvOutput {
587
+ /** `production`, or `preview` with `--preview`. It picks the `.env.<stage>` files. */
588
+ stage: string;
589
+ /** Every name and prefix that the build lists. */
590
+ checked: string[];
591
+ /** Optional entries that neither the host nor a local value sets. Required ones stop the deploy. */
592
+ missing: EnvDiffEntry[];
593
+ /** Names that the deploy set on the host, or uploaded with the Cloudflare version. */
594
+ pushed: string[];
595
+ /** Names that the deploy generated, such as `VITEHUB_SECRET`. They are in `pushed` too. */
596
+ generated?: string[];
597
+ }
598
+ //#endregion
599
+ //#region src/provision.d.ts
600
+ type ProvisionActionStatus = "create" | "update" | "pending" | "exists";
601
+ //#endregion
602
+ //#region src/setup/deploy/provision.d.ts
603
+ /** What `vitehub deploy --json` reports in `provision`. */
604
+ interface DeployProvisionOutput {
605
+ /** The resources that this deploy created or changed. Empty when everything existed. */
606
+ changed: Array<{
607
+ status: Exclude<ProvisionActionStatus, "exists">;
608
+ kind: string;
609
+ name: string;
610
+ step: string;
611
+ }>;
612
+ /** The ids of the host resources, by category and key, as `.vitehub/provision.json` records them. */
613
+ ids: Record<string, Record<string, string>>;
614
+ }
615
+ //#endregion
616
+ //#region src/setup/deploy.d.ts
617
+ interface SetupDeployArgs {
618
+ /** The host of --host, as the user wrote it. */
619
+ host?: string;
620
+ preview: boolean;
621
+ /** `--push-env`: set every local value on the host, also the names that the host has. */
622
+ pushEnv: boolean;
623
+ build: boolean;
624
+ /** False with --no-provision. */
625
+ provision: boolean;
626
+ /** False with --no-push. A preview deploy never pushes. */
627
+ push: boolean;
628
+ /** False with --no-check: do not request the `deploy.check` paths after the upload. */
629
+ check: boolean;
630
+ /** False with --no-index-now: do not send the sitemap URLs to IndexNow. */
631
+ indexNow: boolean;
632
+ temporary: boolean;
633
+ yes: boolean;
634
+ json: boolean;
635
+ help: boolean;
636
+ }
637
+ /** What `vitehub deploy --json` prints, after `schemaVersion: 1`. */
638
+ interface SetupDeployOutput {
639
+ host: DeployHost;
640
+ url: string;
641
+ deploymentId?: string;
642
+ version?: string;
643
+ temporary?: {
644
+ claimUrl: string;
645
+ expiresAt?: string;
646
+ };
647
+ commit?: DeployCommit;
648
+ /** The host resources that the deploy provisioned. Missing when the host has none, or with --no-provision. */
649
+ provision?: DeployProvisionOutput;
650
+ /** The Workspace push of the checkout folders of `vitehub.lock`. Missing when the deploy did not push. */
651
+ checkouts?: DeployCheckoutsOutput;
652
+ /** The env names that the deploy checked and set. Never a value. */
653
+ env: DeployEnvOutput;
654
+ /** The `deploy.check` paths and how the deployed app answered. Missing when the build has none, or with --no-check. */
655
+ checks?: DeployCheckResult[];
656
+ /** How to roll production back. Only when a check failed. */
657
+ rollback?: DeployRollback;
658
+ /** The IndexNow submission. Missing when the build has no `deploy.indexNow`, for a preview, and with --no-index-now. */
659
+ indexNow?: DeployIndexNowOutput;
660
+ }
661
+ export declare function readDeployArgs(args: readonly string[]): SetupDeployArgs;
662
+ export declare const deployCommand: ViteHubCliCommand;
663
+ //#endregion
664
+ //#region src/setup/deployments.d.ts
665
+ /** How long `vitehub status` waits for the host before it reports `liveReason: "timeout"`. */
666
+ export declare const STATUS_HOST_TIMEOUT_MS = 5000;
667
+ /** What `vitehub deployments --json` prints, after `schemaVersion: 1`. */
668
+ interface SetupDeploymentsOutput {
669
+ host: SetupLinkHost;
670
+ project: SetupLink["project"];
671
+ deployments: HostDeployment[];
672
+ }
673
+ /** The deployment that receives production traffic, as `vitehub status` reports it. */
674
+ interface SetupLive {
675
+ deploymentId: string;
676
+ url?: string;
677
+ commit?: DeployCommit;
678
+ /** Commits on HEAD that the live deployment does not have. */
679
+ behind?: number;
680
+ /** Commits in the live deployment that HEAD does not have. */
681
+ ahead?: number;
682
+ /** Why `behind` and `ahead` are not known. */
683
+ unknownReason?: "commit-not-local" | "no-marker" | "no-git";
684
+ }
685
+ /** Why `live` is `null`. */
686
+ type SetupLiveReason = "offline" | "not-linked" | "no-credentials" | "no-live-deployment" | "timeout" | "host-error";
687
+ interface SetupLiveStatus {
688
+ live: SetupLive | null;
689
+ liveReason: SetupLiveReason | null;
690
+ }
691
+ export declare const deploymentsCommand: ViteHubCliCommand;
692
+ /**
693
+ * The deployment that receives production traffic, for `vitehub status`. It asks the host only when the project is
694
+ * linked and the credentials resolved. The signal shares status's deadline with credential discovery; standalone
695
+ * callers get `STATUS_HOST_TIMEOUT_MS`. It never throws: a failure is a `liveReason`.
696
+ */
697
+ export declare function readSetupLive(root: string, link: SetupLink | undefined, credentials: HostCredentials | undefined, context: ViteHubCliContext, options: {
698
+ offline: boolean;
699
+ signal?: AbortSignal;
700
+ }): Promise<SetupLiveStatus>;
701
+ //#endregion
702
+ //#region src/setup/init.d.ts
703
+ declare const initHosts: readonly ["cloudflare", "vercel", "netlify", "deno", "node"];
704
+ type InitHost = typeof initHosts[number];
705
+ type InitFramework = "vite" | "nuxt";
706
+ /**
707
+ * The packages of a new app, as `getting-started/installation.md` installs them. The Nitro and H3 versions match the
708
+ * server integration of ViteHub. Nuxt 5 supplies Nitro 3, and its tutorials import H3 2. Valibot validates request
709
+ * bodies in the docs' route examples.
710
+ */
711
+ export declare const initPackages: Readonly<Record<InitFramework, {
712
+ prod: readonly string[];
713
+ dev: readonly string[];
714
+ }>>;
715
+ /** The pinned Nuxt CLI that creates a new Nuxt app. */
716
+ export declare const nuxiPackage = "nuxi@3.37.0";
717
+ interface SetupInitArgs {
718
+ dir?: string;
719
+ host?: InitHost;
720
+ /** `undefined` when `--features` is absent. */
721
+ features?: FeatureId[];
722
+ /** Raw `--option` values, such as `email.driver=resend`. */
723
+ options: string[];
724
+ framework?: InitFramework;
725
+ pm?: SetupPackageManager;
726
+ install: boolean;
727
+ dryRun: boolean;
728
+ yes: boolean;
729
+ json: boolean;
730
+ help: boolean;
731
+ }
732
+ interface SetupInitPlan {
733
+ /** `planned` for a dry run or a plan that waits for `--yes`, `applied` when done, `unchanged` when there is nothing to do. */
734
+ status: "planned" | "applied" | "unchanged";
735
+ root: string;
736
+ /** `create` for a new app, `adopt` for an existing Vite or Nuxt app. */
737
+ mode: "create" | "adopt";
738
+ framework: InitFramework;
739
+ host: InitHost;
740
+ packageManager: SetupPackageManager;
741
+ features: readonly FeatureId[];
742
+ implied: readonly FeatureId[];
743
+ /** The Nuxt CLI command that creates a new Nuxt app before ViteHub adopts it. */
744
+ scaffold?: {
745
+ command: string;
746
+ };
747
+ changes: readonly SetupChange[];
748
+ install: {
749
+ packages: readonly string[];
750
+ devPackages: readonly string[];
751
+ command?: string;
752
+ };
753
+ /** The command that creates the same stack. README.md keeps it. */
754
+ stack: {
755
+ command: string;
756
+ };
757
+ nextSteps: readonly string[];
758
+ }
759
+ /** Reads the arguments. Throws `CLI_R0003` for an unknown flag or value. */
760
+ export declare function readInitArgs(args: readonly string[]): SetupInitArgs;
761
+ /** The stack command in the README.md block of `root`, for `vitehub status`. `null` when there is no block. */
762
+ export declare function readSetupStack(root: string): Promise<{
763
+ command: string;
764
+ } | null>;
765
+ export declare const initCommandDefinition: ViteHubCliCommand;
766
+ //#endregion
767
+ //#region src/setup/remove.d.ts
768
+ interface SetupRemoveArgs {
769
+ features: FeatureId[];
770
+ json: boolean;
771
+ dryRun: boolean;
772
+ yes: boolean;
773
+ /** `--keep-files`: keep the starter Definitions. */
774
+ keepFiles: boolean;
775
+ /** `--force`: turn the features off while the app still uses them, and write `false` for an implied feature. */
776
+ force: boolean;
777
+ /** False with `--no-uninstall`. */
778
+ uninstall: boolean;
779
+ help: boolean;
780
+ }
781
+ /** A place where the app still uses a feature that `vitehub remove` turns off. */
782
+ interface SetupReference {
783
+ feature: FeatureId;
784
+ /** Relative to the project root. */
785
+ file: string;
786
+ line?: number;
787
+ /** The import, such as `vite-hub/queue`. Undefined for a Definition file or a discovered file. */
788
+ module?: string;
789
+ }
790
+ interface SetupRemovePlan {
791
+ /** `planned` for a dry run or a plan that waits for `--yes`, `applied` when done, `unchanged` when there is nothing to do. */
792
+ status: "planned" | "applied" | "unchanged";
793
+ root: string;
794
+ host: SetupStatus["host"];
795
+ features: readonly FeatureId[];
796
+ /** Every feature that goes off, with the ones that only the removed features turned on, such as Workflow for Agent. */
797
+ turnedOff: readonly FeatureId[];
798
+ /** The config patch first, then the starter Definitions to delete. */
799
+ changes: readonly SetupChange[];
800
+ /** Files that stay: edited Definitions with `--force`, and starter Definitions with `--keep-files`. */
801
+ kept: readonly {
802
+ path: string;
803
+ reason: "edited" | "keep-files";
804
+ }[];
805
+ /** Uses of the features that `--force` ignored. */
806
+ references: readonly SetupReference[];
807
+ uninstall: {
808
+ packages: readonly string[];
809
+ devPackages: readonly string[];
810
+ command?: string;
811
+ };
812
+ nextSteps: readonly string[];
813
+ }
814
+ /** Reads the arguments. Throws `CLI_R0003` for an unknown flag or feature. */
815
+ export declare function readRemoveArgs(args: readonly string[]): SetupRemoveArgs;
816
+ /** A `vitehub remove` plan with the file contents that applying it checks and writes. */
817
+ interface PlannedRemove {
818
+ plan: SetupRemovePlan;
819
+ configFile?: {
820
+ path: string;
821
+ before: string;
822
+ after: string;
823
+ };
824
+ /** Starter Definitions to delete. */
825
+ deletes: {
826
+ path: string;
827
+ content: string;
828
+ }[];
829
+ uninstall: string[];
830
+ }
831
+ /** Plans `vitehub remove` without writing anything. Throws `SetupFailure` when the change is not safe or not possible. */
832
+ export declare function planSetupRemove(project: SetupProject, args: SetupRemoveArgs, env: NodeJS.ProcessEnv): Promise<PlannedRemove>;
833
+ /** Applies a removal. In-server sessions defer the restart-triggering config until cleanup finishes. */
834
+ export declare function applySetupRemove(project: SetupProject, planned: PlannedRemove, args: Pick<SetupRemoveArgs, "uninstall">, context: Pick<ViteHubCliContext, "env" | "spawn">, options?: {
835
+ configLast?: boolean;
836
+ }): Promise<void>;
837
+ export declare const removeCommand: ViteHubCliCommand;
838
+ //#endregion
839
+ //#region src/setup/session.d.ts
840
+ /**
841
+ * Runs the package manager with an argument array and no shell. `onOutput` gets its stdout and stderr as they arrive.
842
+ * Tests pass a fake runner.
843
+ */
844
+ type SetupCommandRunner = (command: string, args: readonly string[], options: {
845
+ cwd: string;
846
+ env: NodeJS.ProcessEnv;
847
+ onOutput: (text: string, stream: "stdout" | "stderr") => void;
848
+ }) => Promise<{
849
+ exitCode: number | null;
850
+ signal?: NodeJS.Signals | null;
851
+ }>;
852
+ /**
853
+ * A change that the dev Setup page asks for. It names features and options only: never a path or a command. The
854
+ * session turns it into the same arguments as `vitehub add` or `vitehub remove`.
855
+ */
856
+ interface SetupPlanRequest {
857
+ action: "add" | "remove";
858
+ features: readonly string[];
859
+ /** `add`: `--option` values, such as `kv.driver=upstash`. */
860
+ options?: readonly string[];
861
+ /** `add`: `--name` of the starter Definitions. */
862
+ name?: string;
863
+ /** `add`: false for `--no-install`. */
864
+ install?: boolean;
865
+ /** `remove`: `--force`. */
866
+ force?: boolean;
867
+ /** `remove`: `--keep-files`. */
868
+ keepFiles?: boolean;
869
+ /** `remove`: false for `--no-uninstall`. */
870
+ uninstall?: boolean;
871
+ }
872
+ /** A JSON document of a setup command, the same as its `--json` output, and the exit code of the command. */
873
+ interface SetupSessionResult {
874
+ exitCode: number;
875
+ body: {
876
+ schemaVersion: 1;
877
+ [key: string]: unknown;
878
+ };
879
+ }
880
+ /** Fields that the session adds to a plan document. */
881
+ interface SetupSessionPlanFields {
882
+ /** Applies this plan once with `apply()`. Absent when there is nothing to change. */
883
+ planId?: string;
884
+ /** The CLI command that makes the same change. */
885
+ command: string;
886
+ /** True when applying writes the config file, so the dev server restarts. */
887
+ restart: boolean;
888
+ }
889
+ interface SetupSession {
890
+ catalog: () => SetupSessionResult;
891
+ status: () => Promise<SetupSessionResult>;
892
+ /** Plans a change without writing anything. The document equals `vitehub add|remove ... --dry-run --json`, with {@link SetupSessionPlanFields}. */
893
+ plan: (request: unknown) => Promise<SetupSessionResult>;
894
+ /**
895
+ * Applies exactly the stored plan, once. It fails with exit code 4 when a file that the plan read changed, or when
896
+ * planning again would give another plan. Applies run one at a time.
897
+ */
898
+ apply: (planId: unknown, onOutput?: (text: string, stream: "stdout" | "stderr") => void) => Promise<SetupSessionResult>;
899
+ }
900
+ interface SetupSessionOptions {
901
+ /** The project root. The session never takes a path from a request. */
902
+ root: string;
903
+ env: NodeJS.ProcessEnv;
904
+ run: SetupCommandRunner;
905
+ /** The most plans that the session keeps. The oldest goes first. Defaults to 20. */
906
+ maxPlans?: number;
907
+ }
908
+ /** The CLI arguments of a request. Every value goes inline after `=`, so no value can become another flag. */
909
+ export declare function setupRequestArgs(request: unknown): {
910
+ action: "add" | "remove";
911
+ argv: string[];
912
+ };
913
+ /**
914
+ * The setup engine for a long-running process, such as the dev Setup page. It does what `vitehub status`, `catalog`,
915
+ * `add`, and `remove` do, with the same documents, and keeps each plan until one `apply()` uses it.
916
+ */
917
+ export declare function createSetupSession(options: SetupSessionOptions): SetupSession;
918
+ //#endregion
919
+ export type { ConsoleCredential, DeployCommit, HostDeployment, HostDeploymentSource, PlannedRemove, SetupAddArgs, SetupAddPlan, SetupAddPlanned, SetupCatalog, SetupChange, SetupChoice, SetupCommandRunner, SetupDeployArgs, SetupDeployOutput, SetupDeploymentsOutput, SetupError, SetupFailure, SetupFailureDetails, SetupFeatureStatus, SetupFramework, SetupInitArgs, SetupInitPlan, SetupLink, SetupLinkAccount, SetupLinkFile, SetupLinkHost, SetupLinkOptions, SetupLinkResult, SetupLinkSelection, SetupLinkState, SetupLinkStatus, SetupLinkSummary, SetupLinkTarget, SetupLinks, SetupLive, SetupLiveReason, SetupLiveStatus, SetupMissing, SetupOptions, SetupPackageManager, SetupPlanRequest, SetupProject, SetupReference, SetupRemoveArgs, SetupRemovePlan, SetupRerun, SetupSession, SetupSessionOptions, SetupSessionPlanFields, SetupSessionResult, SetupStatus };