@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,52 +1,21 @@
1
- import { B as isRecord, b as loadAllEnv, c as createNetlifyApiClient, f as resolveHostCredentials, l as createVercelProvisionClient, m as cliErrorDiagnostics, o as createCloudflareApiClient, p as runHostCli, s as createCloudflareProvisionClient, u as isProvisionRequestError, x as withViteStageEnvironment, z as internalErrorDiagnostics } from "./provision-DXl97xG0.js";
2
- import { i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-B4mPbSbj.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { $ as isRecord, B as formatInstallArgument, H as installSpecifier, I as featureIds, L as featurePackages, Q as internalErrorDiagnostics, R as featureSupport, V as impliedFeatures, W as invariant, b as loadAllEnv, c as createNetlifyApiClient, f as resolveHostCredentials, l as createVercelProvisionClient, m as cliErrorDiagnostics, o as createCloudflareApiClient, p as runHostCli, s as createCloudflareProvisionClient, u as isProvisionRequestError, x as withViteStageEnvironment, z as features } from "./provision-DgT_lpyn.js";
3
+ import { i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-C7e408hm.js";
3
4
  import { createRequire } from "node:module";
4
5
  import { spawn } from "node:child_process";
5
6
  import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
6
7
  import process$1 from "node:process";
7
8
  import { basename, dirname, join, relative, resolve } from "pathe";
8
- import { defineDiagnostics } from "nostics";
9
- import { mkdir, mkdtemp, open, readFile, realpath, rm, stat, unlink, writeFile } from "node:fs/promises";
9
+ import { mkdir, mkdtemp, open, readFile, readdir, realpath, rm, stat, unlink, writeFile } from "node:fs/promises";
10
10
  import { basename as basename$1, delimiter, sep } from "node:path";
11
11
  import { createInterface } from "node:readline/promises";
12
- import { constants, tmpdir } from "node:os";
12
+ import { constants, homedir, tmpdir } from "node:os";
13
13
  import { parse as parse$1 } from "@babel/parser";
14
+ import { parse as parse$2 } from "rc9";
14
15
  import { parseArgs, parseEnv } from "node:util";
15
16
  import { createPublicKey, diffieHellman, generateKeyPairSync, randomBytes } from "node:crypto";
16
17
  import { hsalsa, xsalsa20poly1305 } from "@noble/ciphers/salsa.js";
17
18
  import { blake2b } from "@noble/hashes/blake2.js";
18
- //#region \0rolldown/runtime.js
19
- var __defProp = Object.defineProperty;
20
- var __exportAll = (all, no_symbols) => {
21
- let target = {};
22
- for (var name in all) __defProp(target, name, {
23
- get: all[name],
24
- enumerable: true
25
- });
26
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
27
- return target;
28
- };
29
- //#endregion
30
- //#region ../internal/dist/invariant.js
31
- const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
32
- docsBase: "https://vitehub.dev/docs/development/diagnostics",
33
- codes: { INTERNAL_INVARIANT_FAILED: {
34
- why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
35
- fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
36
- } }
37
- });
38
- /**
39
- * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
40
- * Use a code from the package catalog when a developer can cause the error or fix it.
41
- */
42
- function invariantError(what) {
43
- return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
44
- }
45
- /** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
46
- function invariant(condition, what) {
47
- if (!condition) throw invariantError(what);
48
- }
49
- //#endregion
50
19
  //#region ../internal/dist/ast.js
51
20
  /** Parses JavaScript or TypeScript. `jsx` adds JSX syntax. */
52
21
  function parseProgram(code, options = {}) {
@@ -1427,7 +1396,7 @@ function locateNuxtOptions(code, program, root, names, namespaces) {
1427
1396
  }
1428
1397
  };
1429
1398
  }
1430
- function parse$2(code) {
1399
+ function parse$3(code) {
1431
1400
  try {
1432
1401
  return parseProgram(code);
1433
1402
  } catch (error) {
@@ -1435,7 +1404,7 @@ function parse$2(code) {
1435
1404
  }
1436
1405
  }
1437
1406
  function locate(file, code) {
1438
- const program = parse$2(code);
1407
+ const program = parse$3(code);
1439
1408
  if ("ok" in program) return program;
1440
1409
  let commonjs;
1441
1410
  walk(program, (node) => {
@@ -1633,7 +1602,7 @@ function insertViteHubConfig(file, code, options) {
1633
1602
  code
1634
1603
  };
1635
1604
  if (located.reason !== "no-vitehub") return located;
1636
- const program = parse$2(code);
1605
+ const program = parse$3(code);
1637
1606
  if ("ok" in program) return program;
1638
1607
  const exported = defaultExport(program);
1639
1608
  if (!exported) return fail("no-vitehub");
@@ -1679,603 +1648,6 @@ function insertViteHubConfig(file, code, options) {
1679
1648
  };
1680
1649
  }
1681
1650
  //#endregion
1682
- //#region ../internal/dist/features.js
1683
- /**
1684
- * The feature keys of `vitehub({...})`. `vitehub add <feature>` and `vitehub status` read this list before the owner
1685
- * package of a feature is installed, so the catalog is plain data with no owner imports.
1686
- */
1687
- const featureIds = [
1688
- "agent",
1689
- "auth",
1690
- "blob",
1691
- "browser",
1692
- "cache",
1693
- "channels",
1694
- "comments",
1695
- "connections",
1696
- "console",
1697
- "database",
1698
- "email",
1699
- "env",
1700
- "i18n",
1701
- "kv",
1702
- "mcp",
1703
- "observability",
1704
- "queue",
1705
- "rateLimit",
1706
- "realtime",
1707
- "sandboxTask",
1708
- "schedule",
1709
- "workflow",
1710
- "workspace"
1711
- ];
1712
- /** `dev` stores default Node development support. Use `featureSupport()` with the configured host for development lookups. */
1713
- const featureHosts = [
1714
- "dev",
1715
- "cloudflare",
1716
- "vercel",
1717
- "netlify",
1718
- "deno",
1719
- "node"
1720
- ];
1721
- const noHostLimit = "No host limit in ViteHub.";
1722
- function native(driver, display, detail, guarantee = "native") {
1723
- return {
1724
- detail,
1725
- display,
1726
- driver,
1727
- guarantee,
1728
- level: "native"
1729
- };
1730
- }
1731
- function explicit(option, display, detail) {
1732
- return {
1733
- detail,
1734
- display,
1735
- level: "explicit",
1736
- option
1737
- };
1738
- }
1739
- function unsupported$1(detail) {
1740
- return {
1741
- detail,
1742
- level: "unsupported"
1743
- };
1744
- }
1745
- function everywhere(driver, display, detail = noHostLimit) {
1746
- const support = native(driver, display, detail);
1747
- return {
1748
- cloudflare: support,
1749
- deno: support,
1750
- dev: support,
1751
- netlify: support,
1752
- node: support,
1753
- vercel: support
1754
- };
1755
- }
1756
- function feature(definition) {
1757
- return {
1758
- devPackages: [],
1759
- enabledByDefault: false,
1760
- implies: [],
1761
- packages: [],
1762
- ...definition
1763
- };
1764
- }
1765
- const sourceExtensions = [
1766
- "ts",
1767
- "mts",
1768
- "js",
1769
- "mjs",
1770
- "cts",
1771
- "cjs"
1772
- ];
1773
- /** `<base>.<ext>` for each source extension. */
1774
- function sourceFiles(base) {
1775
- return sourceExtensions.map((extension) => `${base}.${extension}`);
1776
- }
1777
- /**
1778
- * A starter for Definitions in `dir`, one `<name>.ts` file each. With `suffix`, the owner also discovers the Vite
1779
- * form `src/<name>.<suffix>.ts`, and a Definition folder `<dir>/<name>/` when `folder` names its entry file.
1780
- */
1781
- function starter(dir, template, options = {}) {
1782
- return {
1783
- conflicts: (name) => [
1784
- ...sourceFiles(`${dir}/${name}`).slice(1),
1785
- ...options.folder ? sourceFiles(`${dir}/${name}/${options.folder}`) : [],
1786
- ...options.suffix ? [...sourceFiles(`src/${name}.${options.suffix}`), ...sourceFiles(`${name}.${options.suffix}`)] : []
1787
- ],
1788
- dir,
1789
- file: (name) => `${dir}/${name}.ts`,
1790
- template
1791
- };
1792
- }
1793
- const features = {
1794
- agent: feature({
1795
- definition: starter("server/agents", (name) => `import { defineAgent } from "vite-hub/agent"
1796
-
1797
- export default defineAgent({
1798
- driver: { run: () => ({ text: "Hello from ${name}." }) },
1799
- })
1800
- `, {
1801
- folder: "agent",
1802
- suffix: "agent"
1803
- }),
1804
- docs: "/docs/agents",
1805
- enabledByDiscovery: ["agents"],
1806
- hosts: {
1807
- ...everywhere("nitro", "Nitro"),
1808
- deno: native("nitro", "Nitro", "Agent routes run in the Nitro output. The Agent Deno runtime is not supported on this host."),
1809
- netlify: native("nitro", "Nitro", "Agent HTTP routes run in generated functions. `agent.invocations` is not supported.")
1810
- },
1811
- id: "agent",
1812
- packages: ["@vite-hub/agent"],
1813
- summary: "Agents in `server/agents/` with tools, Capabilities, channels, and invocations.",
1814
- title: "Agent"
1815
- }),
1816
- auth: feature({
1817
- docs: "/docs/auth",
1818
- enabledByDiscovery: sourceFiles("auth"),
1819
- hosts: everywhere("better-auth", "Better Auth"),
1820
- id: "auth",
1821
- packages: ["@vite-hub/auth", "better-auth"],
1822
- summary: "Better Auth sign-in, sessions, and organizations, with tables that ViteHub owns.",
1823
- title: "Auth"
1824
- }),
1825
- blob: feature({
1826
- docs: "/docs/blob",
1827
- hosts: {
1828
- cloudflare: native("cloudflare", "R2", "Cloudflare R2 binding or S3-compatible HTTP access."),
1829
- deno: explicit("blob.driver", "S3", "Use a remote S3-compatible store. No Deno-native Blob driver is provided."),
1830
- dev: native("fs", "fs", "Local filesystem storage for development.", "single-host"),
1831
- netlify: native("netlify-blobs", "Netlify Blobs", "Netlify Blobs selected from the detected host."),
1832
- node: native("fs", "fs / S3", "Filesystem, S3-compatible, MinIO, or files-sdk drivers.", "single-host"),
1833
- vercel: native("vercel", "Vercel Blob", "Vercel Blob through the vercel driver.")
1834
- },
1835
- id: "blob",
1836
- packages: ["@vite-hub/blob"],
1837
- providerPackages: { driver: { s3: [
1838
- "@aws-sdk/client-s3",
1839
- "@aws-sdk/lib-storage",
1840
- "@aws-sdk/s3-presigned-post",
1841
- "@aws-sdk/s3-request-presigner"
1842
- ] } },
1843
- service: "blob",
1844
- summary: "Object storage for files and uploads, with one API on every host.",
1845
- title: "Blob"
1846
- }),
1847
- browser: feature({
1848
- docs: "/docs/browser",
1849
- enabledByDiscovery: ["browsers"],
1850
- hosts: {
1851
- cloudflare: native("cloudflare", "Browser Run", "Cloudflare Browser Run binding and provider output."),
1852
- deno: unsupported$1("Browser Definitions do not have a Deno provider."),
1853
- dev: unsupported$1("Browser Definitions need the Cloudflare host. Use createBrowser({ driver: localBrowser({ executablePath }) }) from code for a trusted local process."),
1854
- netlify: unsupported$1("Browser Definitions do not have a Netlify provider."),
1855
- node: unsupported$1("The Node host has no built-in Browser Provider. Use localBrowser() from code for a trusted process."),
1856
- vercel: unsupported$1("Browser Definitions do not have a Vercel provider.")
1857
- },
1858
- id: "browser",
1859
- packages: ["@vite-hub/browser"],
1860
- service: "browser",
1861
- summary: "Headless browser sessions for Agents and server code.",
1862
- title: "Browser"
1863
- }),
1864
- cache: feature({
1865
- developmentOverrides: [
1866
- "cloudflare",
1867
- "deno",
1868
- "vercel"
1869
- ],
1870
- docs: "/docs/reference/config-options",
1871
- hosts: {
1872
- cloudflare: native("cloudflare", "Workers KV", "Workers KV binding `CACHE`."),
1873
- deno: native("deno-kv", "Deno KV", "Native Deno KV."),
1874
- dev: native("fs-lite", "fs-lite", "`.vitehub/data/cache` during development.", "single-host"),
1875
- netlify: explicit("cache.driver", "KV", "`cache: true` has no default store on Netlify. Set `cache: { driver: \"kv\" }` and enable `kv`."),
1876
- node: native("fs-lite", "fs-lite", "`.vitehub/data/cache` on the server disk.", "single-host"),
1877
- vercel: native("vercel", "Runtime Cache", "Vercel Runtime Cache.")
1878
- },
1879
- id: "cache",
1880
- summary: "Storage for Nitro's cache mount, used by defineCachedFunction() and defineCachedEventHandler().",
1881
- title: "Cache"
1882
- }),
1883
- channels: feature({
1884
- docs: "/docs/channels",
1885
- enabledByDiscovery: ["channels"],
1886
- hosts: everywhere("nitro", "Nitro"),
1887
- id: "channels",
1888
- packages: ["@vite-hub/channels"],
1889
- summary: "Chat channels such as Slack, Discord, and GitHub that deliver messages to Agents.",
1890
- title: "Channels"
1891
- }),
1892
- comments: feature({
1893
- docs: "/docs/comments",
1894
- enabledByDiscovery: [
1895
- "comments.ts",
1896
- "comments.mts",
1897
- "comments.js",
1898
- "comments.mjs"
1899
- ],
1900
- hosts: everywhere("database", "Database"),
1901
- id: "comments",
1902
- implies: [{ feature: "database" }],
1903
- packages: ["@vite-hub/comments"],
1904
- summary: "Comments on the app's pages, stored in a ViteHub Database.",
1905
- title: "Comments"
1906
- }),
1907
- connections: feature({
1908
- docs: "/docs/connections",
1909
- enabledByDiscovery: ["connections"],
1910
- hosts: everywhere("database", "Database"),
1911
- id: "connections",
1912
- implies: [{ feature: "database" }],
1913
- packages: [
1914
- "@vite-hub/connections",
1915
- "@vite-hub/database",
1916
- "drizzle-orm"
1917
- ],
1918
- summary: "OAuth and API key Connections in `server/connections/`, with grants stored in a Database.",
1919
- title: "Connections"
1920
- }),
1921
- console: feature({
1922
- docs: "/docs/console",
1923
- hosts: everywhere("nitro", "Nitro"),
1924
- id: "console",
1925
- packages: [],
1926
- summary: "The Operations endpoint and MCP at `/_vitehub`, which the hosted Console at console.vitehub.dev and the CLI call.",
1927
- title: "Console"
1928
- }),
1929
- database: feature({
1930
- definition: {
1931
- conflicts: (name) => [
1932
- ...sourceFiles(`server/databases/${name}`).slice(1),
1933
- ...sourceFiles(`server/databases/${name}/index`),
1934
- ...name === "default" ? ["src/database.ts"] : [...sourceFiles(`src/${name}.database`), "src/database.ts"]
1935
- ],
1936
- dir: "server/databases",
1937
- file: (name) => `server/databases/${name}.ts`,
1938
- template: (name) => `import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
1939
- import { defineDatabase } from "vite-hub/database"
1940
-
1941
- export default defineDatabase({
1942
- ${name === "default" ? "" : ` name: ${JSON.stringify(name)},\n`} schema: {
1943
- notes: sqliteTable("notes", {
1944
- id: integer("id").primaryKey(),
1945
- title: text("title").notNull(),
1946
- }),
1947
- },
1948
- })
1949
- `
1950
- },
1951
- developmentOverrides: [
1952
- "deno",
1953
- "netlify",
1954
- "vercel"
1955
- ],
1956
- devPackages: ["drizzle-kit"],
1957
- docs: "/docs/database",
1958
- hosts: {
1959
- cloudflare: native("cloudflare", "D1", "Cloudflare D1 binding, with authenticated HTTP available for development. A PostgreSQL Database Definition connects through Hyperdrive or `connection.url`."),
1960
- deno: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Deno-native database driver is provided."),
1961
- dev: native("sqlite", "SQLite", "Local SQLite through libSQL and Drizzle.", "single-host"),
1962
- netlify: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Netlify-native database driver is provided."),
1963
- node: native("sqlite", "SQLite / libSQL / Postgres", "SQLite or hosted libSQL through the selected Database connection, or a PostgreSQL Database Definition.", "single-host"),
1964
- vercel: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. The default local SQLite file is not supported in Vercel functions.")
1965
- },
1966
- id: "database",
1967
- packages: ["@vite-hub/database", "drizzle-orm"],
1968
- summary: "Drizzle Databases in `server/databases/` with migrations and a local SQLite in development.",
1969
- title: "Database"
1970
- }),
1971
- email: feature({
1972
- docs: "/docs/email",
1973
- hosts: {
1974
- cloudflare: native("cloudflare", "Cloudflare Email", "The Cloudflare Email driver is the default. Resend is also supported."),
1975
- deno: explicit("email.driver", "Resend", "Configure the built-in fetch-based Resend driver."),
1976
- dev: native("log", "Log", "`email: true` keeps each message in the development outbox and sends nothing. Set `email.driver` for a production build.", "process-local"),
1977
- netlify: explicit("email.driver", "Resend", "Configure the built-in Resend driver."),
1978
- node: explicit("email.driver", "Resend / custom", "Configure Resend or provide a custom ViteHub Email driver."),
1979
- vercel: explicit("email.driver", "Resend", "Configure the built-in Resend driver.")
1980
- },
1981
- developmentOverrides: [
1982
- "deno",
1983
- "netlify",
1984
- "vercel"
1985
- ],
1986
- id: "email",
1987
- packages: ["@vite-hub/email"],
1988
- summary: "Send email from server code and Agents, with a development outbox.",
1989
- title: "Email"
1990
- }),
1991
- env: feature({
1992
- docs: "/docs/env",
1993
- enabledByDefault: true,
1994
- hosts: everywhere("nitro", "Nitro"),
1995
- id: "env",
1996
- summary: "Typed environment variables and secrets, validated at build and at runtime.",
1997
- title: "Env"
1998
- }),
1999
- i18n: feature({
2000
- docs: "/docs/i18n",
2001
- hosts: everywhere("nitro", "Nitro 3", "Requires Nitro 3 with request async context, or Nuxt 5. Nuxt 4 and Nitro 2 are unsupported."),
2002
- id: "i18n",
2003
- packages: ["@vite-hub/i18n"],
2004
- summary: "Messages with translation records for each locale and a locale for each request.",
2005
- title: "I18n"
2006
- }),
2007
- kv: feature({
2008
- developmentOverrides: ["netlify"],
2009
- docs: "/docs/kv",
2010
- hosts: {
2011
- cloudflare: native("cloudflare", "Workers KV", "Cloudflare Workers KV binding."),
2012
- deno: native("deno-kv", "Deno KV", "Native Deno KV through Deno.openKv()."),
2013
- dev: native("fs-lite", "fs-lite", "Local filesystem-backed KV for development.", "single-host"),
2014
- netlify: explicit("kv.driver", "Upstash / Redis", "Set `kv.driver` to `upstash`, `redis`, or `database`, or set Upstash REST credentials at build time. No Netlify-native KV output is provided. Without them, KV uses a Postgres Default Database, else `fs-lite` files that other function instances cannot read."),
2015
- node: native("fs-lite", "Redis / Postgres / fs-lite", "A table in a Postgres Default Database, else local files. Redis requires kv: { driver: 'redis' }; REDIS_URL supplies its URL on every server. Upstash with REST credentials at build time.", "single-host"),
2016
- vercel: native("upstash", "Upstash", "Upstash Redis with KV REST credentials.")
2017
- },
2018
- id: "kv",
2019
- packages: ["@vite-hub/kv"],
2020
- summary: "Key-value storage with one API on every host.",
2021
- title: "KV"
2022
- }),
2023
- mcp: feature({
2024
- docs: "/docs/mcp",
2025
- hosts: everywhere("nitro", "Nitro"),
2026
- id: "mcp",
2027
- packages: ["@vite-hub/mcp"],
2028
- summary: "The app's own MCP server, with one tool per file in `server/mcp/tools/`.",
2029
- title: "MCP server"
2030
- }),
2031
- observability: feature({
2032
- docs: "/docs/agents/observability",
2033
- hosts: everywhere("evlog", "Evlog"),
2034
- id: "observability",
2035
- packages: ["evlog"],
2036
- summary: "Request logs through Evlog, the logs that the Console reads, and Agent telemetry with a service name.",
2037
- title: "Observability"
2038
- }),
2039
- queue: feature({
2040
- definition: starter("server/queues", (name) => `import { defineQueue } from "vite-hub/queue"
2041
-
2042
- export default defineQueue<{ id: string }>({
2043
- handler: async ({ payload }) => {
2044
- console.log("${name}", payload.id)
2045
- },
2046
- })
2047
- `, { suffix: "queue" }),
2048
- docs: "/docs/queue",
2049
- enabledByDiscovery: ["queues"],
2050
- hosts: {
2051
- cloudflare: native("cloudflare", "Queues", "Cloudflare Queues bindings and consumers."),
2052
- deno: unsupported$1("No Deno Queue driver is provided."),
2053
- dev: native("local", "Local driver", "The local driver stores jobs in .vitehub/data/queue and runs them in the dev server process.", "single-host"),
2054
- netlify: unsupported$1("Netlify has no Queue driver, so `vitehub({ queue })` fails on Netlify."),
2055
- node: native("local", "Postgres / local driver", "With a Postgres Default Database, the postgres driver keeps jobs in Postgres and every instance runs them. Else the local driver keeps jobs on the disk of one host.", "single-host"),
2056
- vercel: native("vercel", "Vercel Queues", "Vercel Queues callbacks and runtime client.")
2057
- },
2058
- id: "queue",
2059
- packages: ["@vite-hub/queue"],
2060
- providerPackages: { driver: { postgres: ["postgres"] } },
2061
- service: "queue",
2062
- summary: "Background jobs in `server/queues/` with retries and delivery on every supported host.",
2063
- title: "Queue"
2064
- }),
2065
- rateLimit: feature({
2066
- developmentOverrides: ["cloudflare"],
2067
- docs: "/docs/rate-limit",
2068
- hosts: {
2069
- cloudflare: native("cloudflare", "Cloudflare", "Native Cloudflare Rate Limiting binding."),
2070
- deno: unsupported$1("ViteHub has no native Deno Rate Limit driver."),
2071
- dev: native("memory", "memory", "Process-local memory driver for development and tests.", "process-local"),
2072
- netlify: unsupported$1("ViteHub has no native Netlify Rate Limit driver."),
2073
- node: native("memory", "memory, or KV", "Without KV, each process counts alone. With KV on, ViteHub selects the kv provider, which shares the counts when KV uses Redis or a Postgres Database.", "process-local"),
2074
- vercel: unsupported$1("ViteHub has no native Vercel Rate Limit driver.")
2075
- },
2076
- id: "rateLimit",
2077
- packages: ["@vite-hub/rate-limit"],
2078
- service: "rateLimit",
2079
- summary: "Rate limits in `server/rate-limits/` that protect routes and Agent tools.",
2080
- title: "Rate Limit"
2081
- }),
2082
- realtime: feature({
2083
- definition: starter("server/realtime", (name) => `import { defineRealtime } from "vite-hub/realtime"
2084
-
2085
- export default defineRealtime({
2086
- authorize: true,
2087
- document: { workspace: "${name}" },
2088
- })
2089
- `),
2090
- developmentOverrides: [
2091
- "cloudflare",
2092
- "deno",
2093
- "netlify",
2094
- "vercel"
2095
- ],
2096
- docs: "/docs/realtime",
2097
- enabledByDiscovery: ["realtime"],
2098
- hosts: {
2099
- cloudflare: native("cloudflare", "Durable Objects", "Cloudflare Durable Objects run the production rooms."),
2100
- deno: unsupported$1("Realtime has no distributed Deno driver, and process memory is rejected for the Deno host."),
2101
- dev: native("memory", "memory", "Process-memory driver for local development.", "process-local"),
2102
- netlify: unsupported$1("Realtime has no distributed Netlify driver, and process memory is rejected for the Netlify host."),
2103
- node: native("node", "Postgres or Redis", "Each instance keeps its rooms in memory and shares them through Redis with REDIS_URL, else Postgres on a Postgres Default Database. Without either, rooms stay in one process."),
2104
- vercel: unsupported$1("Realtime has no distributed Vercel driver, and process memory is rejected for the Vercel host.")
2105
- },
2106
- id: "realtime",
2107
- packages: ["@vite-hub/realtime"],
2108
- service: "realtime",
2109
- summary: "Shared rooms with presence and Yjs documents.",
2110
- title: "Realtime"
2111
- }),
2112
- sandboxTask: feature({
2113
- docs: "/docs/sandbox",
2114
- hosts: {
2115
- cloudflare: native("cloudflare", "CF Sandbox", "Cloudflare Sandbox execution provider."),
2116
- deno: unsupported$1("No Deno Sandbox driver is provided."),
2117
- dev: unsupported$1("The default Node host has no Sandbox Provider. With the Cloudflare or Vercel host, `vite dev` runs each Sandbox Task as a process on this machine, with no isolation and no provider account. `sandboxTask: { remote: true }` uses the host's Sandbox instead."),
2118
- netlify: explicit("sandboxTask.driver", "Vercel Sandbox", "The Netlify host has no Sandbox, so `sandboxTask: true` fails. Set `sandboxTask: { driver: \"vercel\" }` and Vercel credentials to use Vercel Sandbox."),
2119
- node: explicit("sandboxTask.driver", "Vercel Sandbox", "The Node host has no Sandbox, so `sandboxTask: true` fails. Set `sandboxTask: { driver: \"vercel\" }` and Vercel credentials to use Vercel Sandbox."),
2120
- vercel: native("vercel", "Vercel Sandbox", "Vercel Sandbox execution provider.")
2121
- },
2122
- id: "sandboxTask",
2123
- packages: ["@vite-hub/sandbox"],
2124
- service: "sandbox",
2125
- summary: "Sandbox Tasks in `server/sandbox-tasks/`. Each run starts an isolated Cloudflare or Vercel Sandbox.",
2126
- title: "Sandbox"
2127
- }),
2128
- schedule: feature({
2129
- definition: starter("server/schedules", (name) => `import { defineSchedule } from "vite-hub/schedule"
2130
-
2131
- export default defineSchedule({
2132
- cron: "0 * * * *",
2133
- handler: () => {
2134
- console.log("${name}")
2135
- },
2136
- })
2137
- `, { suffix: "schedule" }),
2138
- developmentOverrides: [
2139
- "cloudflare",
2140
- "netlify",
2141
- "vercel"
2142
- ],
2143
- docs: "/docs/schedule",
2144
- enabledByDiscovery: ["schedules"],
2145
- hosts: {
2146
- cloudflare: native("cloudflare", "Cron triggers", "Cloudflare scheduled events and Nitro Provider Wake."),
2147
- deno: native("deno", "Deno.cron", "`Deno.cron` output that the generated `.output/main.ts` loads before the Nitro server."),
2148
- dev: native("local", "Local / process", "Local development runner and the explicit process runtime.", "single-host"),
2149
- netlify: native("netlify", "Scheduled fn", "One generated Netlify scheduled function per static Schedule."),
2150
- node: native("process", "process", "Process runtime for one long-lived process or replica. `schedule: true` uses it. Set `providerOutput: false` to wake Schedules yourself.", "single-host"),
2151
- vercel: native("vercel", "Vercel Cron", "Vercel Cron Jobs provider output.")
2152
- },
2153
- id: "schedule",
2154
- packages: ["@vite-hub/schedule"],
2155
- summary: "Cron Schedules in `server/schedules/` that run on the host's scheduler.",
2156
- title: "Schedule"
2157
- }),
2158
- workflow: feature({
2159
- definition: starter("server/workflows", () => `import { defineWorkflow } from "vite-hub/workflow"
2160
-
2161
- export default defineWorkflow<{ id: string }>({
2162
- handler: async ({ payload }) => {
2163
- return { id: payload.id }
2164
- },
2165
- })
2166
- `, {
2167
- folder: "index",
2168
- suffix: "workflow"
2169
- }),
2170
- docs: "/docs/workflows",
2171
- enabledByDiscovery: ["workflows"],
2172
- hosts: {
2173
- cloudflare: native("cloudflare", "CF Workflows", "Cloudflare Workflows provider."),
2174
- deno: explicit("workflow.driver", "OpenWorkflow", "Set `workflow.driver` to \"openworkflow\" with `workflow.postgres.url`, and start its worker. A build without a driver fails."),
2175
- dev: native("openworkflow", "OpenWorkflow", "The Node host runs OpenWorkflow and its worker in the dev server, on .vitehub/data/openworkflow.sqlite.db. workflow.remote lets it use the Postgres Default Database or OPENWORKFLOW_POSTGRES_URL."),
2176
- netlify: explicit("workflow.driver", "OpenWorkflow", "Use OpenWorkflow explicitly. No Netlify-native Workflow driver is provided."),
2177
- node: {
2178
- ...native("openworkflow", "OpenWorkflow", "OpenWorkflow is the default, and each server runs its worker. It uses OPENWORKFLOW_POSTGRES_URL or the Postgres Default Database. Without them, runs use a SQLite file on one host.", "single-host"),
2179
- envOverrides: ["OPENWORKFLOW_POSTGRES_URL"].map((env) => ({
2180
- env,
2181
- support: native("openworkflow", "OpenWorkflow (Postgres)", `${env} selects Postgres. Several servers can run the worker on the same database, and each run executes once.`)
2182
- }))
2183
- },
2184
- vercel: native("vercel", "Vercel Workflow", "Vercel Workflow provider and Workflow DevKit output.")
2185
- },
2186
- id: "workflow",
2187
- packages: ["@vite-hub/workflow"],
2188
- summary: "Durable Workflows in `server/workflows/` with steps and driver retries.",
2189
- title: "Workflow"
2190
- }),
2191
- workspace: feature({
2192
- developmentOverrides: [
2193
- "cloudflare",
2194
- "deno",
2195
- "netlify",
2196
- "vercel"
2197
- ],
2198
- docs: "/docs/workspace",
2199
- enabledByDiscovery: ["workspaces"],
2200
- hosts: {
2201
- cloudflare: native("memory", "Artifacts / GitHub", "Memory by default, or Cloudflare Artifacts beta and GitHub for durable state.", "process-local"),
2202
- deno: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
2203
- dev: native("local", "local / memory", "Local filesystem or in-memory Workspace Store.", "single-host"),
2204
- netlify: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
2205
- node: native("local", "local / GitHub", "Local filesystem, memory, or GitHub Workspace Store.", "single-host"),
2206
- vercel: {
2207
- ...native("memory", "memory / Blob / GitHub", "Process-local memory by default. BLOB_READ_WRITE_TOKEN selects Vercel Blob; GitHub can be selected explicitly for durable state.", "process-local"),
2208
- envOverrides: [{
2209
- env: "BLOB_READ_WRITE_TOKEN",
2210
- support: native("vercel", "Blob / GitHub", "BLOB_READ_WRITE_TOKEN selects durable Vercel Blob storage by default.")
2211
- }]
2212
- }
2213
- },
2214
- id: "workspace",
2215
- packages: ["@vite-hub/workspace"],
2216
- summary: "File workspaces that Agents read and edit, backed by local, Blob, or GitHub stores.",
2217
- title: "Workspace"
2218
- })
2219
- };
2220
- /** Packages needed by a feature, its provider, and its enabled feature integrations. */
2221
- function featurePackages(id, value, host, enabled = []) {
2222
- const definition = features[id];
2223
- const options = value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
2224
- const stores = options?.stores;
2225
- const selected = (id === "blob" && stores && typeof stores === "object" && !Array.isArray(stores) ? [value, ...Object.values(stores)] : [value]).flatMap((value) => Object.entries(definition.providerPackages ?? {}).flatMap(([key, choices]) => {
2226
- const choice = value && typeof value === "object" && !Array.isArray(value) ? Reflect.get(value, key) : void 0;
2227
- return typeof choice === "string" ? choices[choice] ?? [] : [];
2228
- }));
2229
- if (id === "observability" && typeof options?.service === "string") selected.push("@vite-hub/agent");
2230
- if (id === "observability" && options?.posthog) selected.push("posthog-node");
2231
- const sandboxDriver = typeof options?.driver === "string" ? options.driver : host;
2232
- if (id === "sandboxTask" && (sandboxDriver === "vercel" || sandboxDriver === "cloudflare")) selected.push(sandboxDriverPackages[sandboxDriver]);
2233
- if ((id === "queue" || id === "workflow") && host === "vercel" && (options?.driver ?? "vercel") === "vercel") selected.push(...vercelProviderPackages[id]);
2234
- if (id === "console" && enabled.includes("agent")) selected.push(...consoleFeaturePackages.agents);
2235
- return [.../* @__PURE__ */ new Set([...definition.packages, ...selected])];
2236
- }
2237
- const sandboxDriverPackages = {
2238
- cloudflare: "@cloudflare/sandbox",
2239
- vercel: "@vercel/sandbox"
2240
- };
2241
- /**
2242
- * The SDKs of the Vercel provider. Native Vercel Workflows also need `workflow` and `@workflow/builders`, but only
2243
- * `@vite-hub/workflow` knows when a Workflow is native, so it checks those two itself.
2244
- */
2245
- const vercelProviderPackages = {
2246
- queue: ["@vercel/queue", "@vercel/functions"],
2247
- workflow: ["@vercel/functions"]
2248
- };
2249
- /** Additional Console owners selected by its enabled Agent integration. */
2250
- const consoleFeaturePackages = { agents: ["@libsql/client", "drizzle-orm"] };
2251
- function featureSupport(id, host, appHost) {
2252
- const definition = features[id];
2253
- if (host !== "dev") return definition.hosts[host];
2254
- invariant(appHost, "every caller of featureSupport() for the dev host passes the configured ViteHub host");
2255
- if (id === "workflow" && appHost === "deno") return native("vercel", "Inline", "Development runs each Workflow inline unless OpenWorkflow storage or a provider is configured.", "process-local");
2256
- return definition.hosts[appHost === "node" || definition.developmentOverrides?.includes(appHost) ? "dev" : appHost];
2257
- }
2258
- /**
2259
- * The features that `enabled` turn on through implications, without the ones already in `enabled`.
2260
- * This follows implications transitively.
2261
- * `disabled` lists features that the app sets to `false`; an implication never turns them on.
2262
- */
2263
- function impliedFeatures(enabled, disabled = []) {
2264
- const on = new Set(enabled);
2265
- const implied = [];
2266
- const pending = [...enabled];
2267
- while (pending.length) {
2268
- const id = pending.shift();
2269
- for (const implication of features[id].implies) {
2270
- if (on.has(implication.feature) || disabled.includes(implication.feature)) continue;
2271
- on.add(implication.feature);
2272
- implied.push(implication.feature);
2273
- pending.push(implication.feature);
2274
- }
2275
- }
2276
- return implied;
2277
- }
2278
- //#endregion
2279
1651
  //#region src/setup/project.ts
2280
1652
  const nuxtConfigFiles = [
2281
1653
  "nuxt.config.ts",
@@ -2341,21 +1713,57 @@ function detectPackageManager(root, manifest, env) {
2341
1713
  packageManagerSource: "default"
2342
1714
  };
2343
1715
  }
2344
- function nuxtServerDirs(root, config) {
1716
+ const nuxtLayerKeys = [
1717
+ "extends",
1718
+ "_extends",
1719
+ "theme",
1720
+ "_layers"
1721
+ ];
1722
+ function nuxtDirectoryOverride(value) {
1723
+ return value !== null && typeof value === "object" && [
1724
+ "rootDir",
1725
+ "serverDir",
1726
+ ...nuxtLayerKeys
1727
+ ].some((key) => Object.hasOwn(value, key));
1728
+ }
1729
+ async function nuxtRcAllowsStaticDiscovery(folder) {
1730
+ const file = join(folder, ".nuxtrc");
1731
+ try {
1732
+ if (!(await stat(file)).isFile()) return false;
1733
+ return !nuxtDirectoryOverride(parse$2(await readFile(file, "utf8")));
1734
+ } catch (error) {
1735
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
1736
+ }
1737
+ }
1738
+ async function nuxtServerDirs(root, config, env) {
2345
1739
  const nuxt = config?.ok ? config.site.nuxt : void 0;
2346
1740
  if (!nuxt || nuxt.spread) return;
2347
- const extended = nuxt.keys.extends;
2348
- if (extended && !(extended.kind === "literal" && Array.isArray(extended.value) && extended.value.length === 0)) return;
2349
- if (nuxt.keys._layers || nuxt.keys.srcDir || existsSync(join(root, "layers"))) return;
1741
+ for (const key of nuxtLayerKeys) {
1742
+ const layer = nuxt.keys[key];
1743
+ if (layer && !(layer.kind === "literal" && Array.isArray(layer.value) && layer.value.length === 0)) return;
1744
+ }
1745
+ for (const [key, override] of Object.entries(nuxt.keys)) {
1746
+ if (!key.startsWith("$") || key === "$meta") continue;
1747
+ if (override.kind === "expression") return;
1748
+ if (key === "$env") {
1749
+ if (override.value !== null && typeof override.value === "object" && Object.values(override.value).some(nuxtDirectoryOverride)) return;
1750
+ } else if (nuxtDirectoryOverride(override.value)) return;
1751
+ }
1752
+ if (existsSync(join(root, "layers"))) return;
2350
1753
  const rootDir = nuxt.keys.rootDir;
2351
1754
  const serverDir = nuxt.keys.serverDir;
2352
1755
  if (rootDir && (rootDir.kind !== "literal" || typeof rootDir.value !== "string")) return;
2353
1756
  if (serverDir && (serverDir.kind !== "literal" || typeof serverDir.value !== "string")) return;
2354
1757
  const appRoot = rootDir?.kind === "literal" && typeof rootDir.value === "string" ? resolve(root, rootDir.value) : root;
2355
1758
  if (existsSync(join(appRoot, "layers"))) return;
1759
+ const home = homedir();
1760
+ for (const folder of /* @__PURE__ */ new Set([
1761
+ ...parentFolders(root),
1762
+ home,
1763
+ env.XDG_CONFIG_HOME || join(home, ".config")
1764
+ ])) if (!await nuxtRcAllowsStaticDiscovery(folder)) return;
2356
1765
  return [resolve(appRoot, serverDir?.kind === "literal" && typeof serverDir.value === "string" ? serverDir.value || "server" : "server")];
2357
1766
  }
2358
- /** The real folders of `name` in NODE_PATH, which Node's resolver reads after every node_modules folder. */
2359
1767
  function globalPackageDirs(name) {
2360
1768
  return (process$1.env.NODE_PATH ?? "").split(delimiter).filter(Boolean).flatMap((dir) => {
2361
1769
  try {
@@ -2408,7 +1816,7 @@ async function readSetupProject(root, env) {
2408
1816
  },
2409
1817
  ...detectPackageManager(root, manifest, env),
2410
1818
  root,
2411
- serverDirs: framework === "nuxt" ? nuxtServerDirs(root, config) : [join(root, "server")]
1819
+ serverDirs: framework === "nuxt" ? await nuxtServerDirs(root, config, env) : [join(root, "server")]
2412
1820
  };
2413
1821
  }
2414
1822
  //#endregion
@@ -2540,7 +1948,7 @@ const plans = {
2540
1948
  nitroPreset: "netlify",
2541
1949
  output: {
2542
1950
  directory: ".netlify",
2543
- entry: "functions-internal/server/server.mjs",
1951
+ entry: "v1/functions/server/server.mjs",
2544
1952
  packaging: "none"
2545
1953
  },
2546
1954
  runtime: "node",
@@ -2683,6 +2091,10 @@ const addArgs = {
2683
2091
  prod: ["add"]
2684
2092
  }
2685
2093
  };
2094
+ /** Quotes `value` for a POSIX shell when it needs quotes. */
2095
+ function shellQuote(value) {
2096
+ return /^[\w@%+=:,./-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
2097
+ }
2686
2098
  /** The arguments of the `packageManager` command that installs `packages`, such as `["add", "-D", "drizzle-kit"]`. */
2687
2099
  function installArgs(packageManager, packages, dev) {
2688
2100
  return [...addArgs[packageManager][dev ? "dev" : "prod"], ...packages];
@@ -2697,9 +2109,11 @@ const removeArgs = {
2697
2109
  function uninstallArgs(packageManager, packages) {
2698
2110
  return [...removeArgs[packageManager], ...packages];
2699
2111
  }
2700
- /** The shell command that installs `prod` and then `dev`, such as `pnpm add kv && pnpm add -D drizzle-kit`. */
2112
+ function formatInstallCommand(command, args) {
2113
+ return [command, ...args].map(formatInstallArgument).join(" ");
2114
+ }
2701
2115
  function installCommand(packageManager, prod, dev) {
2702
- const commands = [...prod.length ? [[packageManager, ...installArgs(packageManager, prod, false)].join(" ")] : [], ...dev.length ? [[packageManager, ...installArgs(packageManager, dev, true)].join(" ")] : []];
2116
+ const commands = [...prod.length ? [formatInstallCommand(packageManager, installArgs(packageManager, prod, false))] : [], ...dev.length ? [formatInstallCommand(packageManager, installArgs(packageManager, dev, true))] : []];
2703
2117
  return commands.length ? commands.join(" && ") : void 0;
2704
2118
  }
2705
2119
  function readHost(project, env) {
@@ -2770,21 +2184,32 @@ function readEnabled(project, id, withoutDefinitions) {
2770
2184
  reason: "default"
2771
2185
  };
2772
2186
  }
2773
- /** True when the config sets `option`, such as `blob.driver`, as a literal key of the feature object. */
2774
- function setsOption(project, option) {
2775
- const config = project.config;
2776
- if (!config?.ok) return false;
2187
+ const kvDefaultStoreOption = "kv.stores.default.driver";
2188
+ function kvStores(value) {
2189
+ return isRecord(value) && isRecord(value.stores) ? value.stores : void 0;
2190
+ }
2191
+ function missingProviderOption(project, option, value) {
2777
2192
  const [id, key] = option.split(".");
2778
- const value = config.site.keys[id];
2779
- if (value?.kind === "expression") return true;
2780
- const options = value?.value;
2781
- return !!options && typeof options === "object" && !Array.isArray(options) && key in options;
2193
+ const configured = project.config?.ok ? project.config.site.keys[id] : void 0;
2194
+ if (configured?.kind === "expression") return;
2195
+ const options = value ?? configured?.value;
2196
+ const stores = option === "kv.driver" ? kvStores(options) : void 0;
2197
+ if (stores) {
2198
+ const store = stores.default;
2199
+ const driver = isRecord(store) ? store.driver : void 0;
2200
+ if (driver !== "upstash" && driver !== "redis" && driver !== "database") return kvDefaultStoreOption;
2201
+ return;
2202
+ }
2203
+ if (!isRecord(options) || !(key in options)) return option;
2782
2204
  }
2783
2205
  function featureFix(project, id, support, host, missing, providerChosen) {
2784
- const install = installCommand(project.packageManager, missing.prod, missing.dev);
2206
+ const install = installCommand(project.packageManager, missing.prod.map(installSpecifier), missing.dev.map(installSpecifier));
2785
2207
  if (install) return install;
2786
2208
  if (support.level === "unsupported") return `Set \`${id}: false\`, or build for another host than ${host}.`;
2787
- if (support.level === "explicit" && !providerChosen && !setsOption(project, support.option)) return `Set \`${support.option}\` in vitehub() to choose a provider on ${host}.`;
2209
+ if (support.level === "explicit" && !providerChosen) {
2210
+ const option = missingProviderOption(project, support.option);
2211
+ if (option) return `Set \`${option}\` in vitehub() to choose a provider on ${host}.`;
2212
+ }
2788
2213
  }
2789
2214
  /** What the project enables, on which host, and what each enabled feature still needs. Reads the config without running it. */
2790
2215
  function setupStatus(project, env, withoutDefinitions) {
@@ -2819,7 +2244,8 @@ function setupStatus(project, env, withoutDefinitions) {
2819
2244
  } : featureSupport(id, host.name);
2820
2245
  const definition = features[id];
2821
2246
  const value = project.config?.ok ? project.config.site.keys[id] : void 0;
2822
- const packages = featurePackages(id, value?.kind === "literal" ? value.value : void 0, host.name, featureIds.filter((feature) => enabled.get(feature)?.enabled === "on"));
2247
+ const literal = value?.kind === "literal" ? value.value : void 0;
2248
+ const packages = featurePackages(id, literal, host.name, featureIds.filter((feature) => enabled.get(feature)?.enabled === "on"));
2823
2249
  const missing = state.enabled === "on" ? {
2824
2250
  dev: definition.devPackages.filter((name) => !project.installed(name)),
2825
2251
  prod: packages.filter((name) => !project.installed(name))
@@ -2829,11 +2255,15 @@ function setupStatus(project, env, withoutDefinitions) {
2829
2255
  };
2830
2256
  const providerChosen = id === "workflow" && host.name !== "netlify" && packages.includes("openworkflow");
2831
2257
  const fix = state.enabled === "on" ? featureFix(project, id, support, host.name, missing, providerChosen) : void 0;
2258
+ const resolvedSupport = support.level === "explicit" && support.option === "kv.driver" && kvStores(literal) ? {
2259
+ ...support,
2260
+ option: kvDefaultStoreOption
2261
+ } : support;
2832
2262
  return {
2833
2263
  id,
2834
2264
  ...state,
2835
2265
  missingPackages: [...missing.prod, ...missing.dev],
2836
- support,
2266
+ support: resolvedSupport,
2837
2267
  ...fix ? { fix } : {}
2838
2268
  };
2839
2269
  }),
@@ -3033,13 +2463,14 @@ function createDeployRun(stderr, secrets) {
3033
2463
  options.signal?.addEventListener("abort", abort, { once: true });
3034
2464
  if (options.timeoutMs) timeout = setTimeout(stop, options.timeoutMs);
3035
2465
  if (options.signal?.aborted) abort();
3036
- child.stdin?.on("error", () => {});
2466
+ child.stdin?.on("error", (error) => {
2467
+ if (!(error.code === "EPIPE" || stopping && error.code === "ERR_STREAM_DESTROYED")) failure ??= error;
2468
+ });
3037
2469
  child.stdin?.end(options.stdin ?? "");
3038
2470
  });
3039
2471
  }
3040
2472
  };
3041
2473
  }
3042
- /** Resolve npm/pnpm Windows shims to Node entrypoints without evaluating any batch or shell syntax. */
3043
2474
  function windowsNodeEntry(file) {
3044
2475
  if (/\.(?:exe|cmd|bat)$/iu.test(file)) return;
3045
2476
  if (!existsSync(file)) return;
@@ -3223,7 +2654,6 @@ async function build(project, host, context) {
3223
2654
  function stringList(value) {
3224
2655
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
3225
2656
  }
3226
- /** One entry of `env` in `deployment.json`. Only names: the build never writes a value there. */
3227
2657
  function readEnvEntry(value) {
3228
2658
  if (!isRecord(value)) return [];
3229
2659
  const names = stringList(value.names);
@@ -3241,7 +2671,6 @@ function readEnvEntry(value) {
3241
2671
  ...owners.length ? { owners } : {}
3242
2672
  }];
3243
2673
  }
3244
- /** `deploy` of `deployment.json`. Only paths that start with one `/` and a key that IndexNow accepts. */
3245
2674
  function readDeploy(value) {
3246
2675
  if (!isRecord(value)) return { check: [] };
3247
2676
  const check = stringList(value.check).filter((path) => path.startsWith("/") && !path.startsWith("//"));
@@ -3285,15 +2714,8 @@ async function readBuildOutput(root, host) {
3285
2714
  }
3286
2715
  //#endregion
3287
2716
  //#region src/setup/deploy/cloudflare.ts
3288
- /** The flags that ViteHub's own build writes into `commands.deploy` (`packages/vite-hub/src/plugins.ts`). */
3289
2717
  const valueFlags = /* @__PURE__ */ new Set(["--config"]);
3290
2718
  const plainFlags = /* @__PURE__ */ new Set(["--containers-rollout=gradual"]);
3291
- /**
3292
- * Reads `commands.deploy` from `<output>/nitro.json` and checks that it is the Wrangler deploy that the build writes:
3293
- * `npx wrangler deploy --config <file> [--containers-rollout=gradual]`. With
3294
- * `database.migrateOnDeploy`, `npx wrangler d1 migrations apply <binding> --remote --config <file> && ` comes before it
3295
- * once for each D1 binding (`packages/database/src/internal/migrate-on-deploy.ts`).
3296
- */
3297
2719
  async function readWranglerCommand(outputDir) {
3298
2720
  let manifest;
3299
2721
  try {
@@ -3335,6 +2757,11 @@ async function readWranglerCommand(outputDir) {
3335
2757
  */
3336
2758
  async function wranglerVarNames(outputDir) {
3337
2759
  const { config } = await readWranglerCommand(outputDir);
2760
+ const wrangler = await readWranglerConfig(outputDir, config);
2761
+ return isRecord(wrangler.vars) ? Object.keys(wrangler.vars) : [];
2762
+ }
2763
+ /** The Wrangler config that the `--config` flag of `commands.deploy` names. */
2764
+ async function readWranglerConfig(outputDir, config) {
3338
2765
  const file = join(outputDir, config);
3339
2766
  let value;
3340
2767
  try {
@@ -3342,9 +2769,40 @@ async function wranglerVarNames(outputDir) {
3342
2769
  } catch {
3343
2770
  throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_OUTPUT_MISSING({ file }), setupExitCodes.error);
3344
2771
  }
3345
- return isRecord(value) && isRecord(value.vars) ? Object.keys(value.vars) : [];
2772
+ return isRecord(value) ? value : {};
2773
+ }
2774
+ /**
2775
+ * The D1 bindings of the Wrangler config whose `migrations_dir` holds `.sql` files, except the bindings that the deploy
2776
+ * command migrates. Wrangler reads `migrations_dir` relative to the config file, and its default pattern is `*.sql`
2777
+ * without dot files. A binding with `migrations_pattern` selects other files, and ViteHub's build never writes one.
2778
+ */
2779
+ async function unmigratedD1Bindings(outputDir, config, wrangler, migrated) {
2780
+ const found = [];
2781
+ for (const entry of Array.isArray(wrangler.d1_databases) ? wrangler.d1_databases : []) {
2782
+ if (!isRecord(entry)) continue;
2783
+ const binding = optionalString$1(entry.binding);
2784
+ const dir = optionalString$1(entry.migrations_dir);
2785
+ if (!binding || !dir || entry.migrations_pattern !== void 0 || migrated.includes(binding)) continue;
2786
+ const files = (await readdir(join(outputDir, dirname(config), dir), { withFileTypes: true }).catch(() => [])).filter((item) => item.isFile() && item.name.endsWith(".sql") && !item.name.startsWith(".")).map((item) => item.name).toSorted();
2787
+ if (files.length) found.push({
2788
+ binding,
2789
+ files,
2790
+ table: optionalString$1(entry.migrations_table) ?? "d1_migrations"
2791
+ });
2792
+ }
2793
+ return found;
2794
+ }
2795
+ /** The `results` rows of `wrangler d1 execute --json`, which prints one `{ results, success, meta }` per statement. */
2796
+ function d1ResultNames(result) {
2797
+ let value;
2798
+ try {
2799
+ value = JSON.parse(result.stdout.slice(Math.max(result.stdout.indexOf("["), 0)));
2800
+ } catch {
2801
+ return;
2802
+ }
2803
+ if (!Array.isArray(value)) return void 0;
2804
+ return value.flatMap((item) => isRecord(item) && Array.isArray(item.results) ? item.results : []).flatMap((row) => isRecord(row) && typeof row.name === "string" ? [row.name] : []);
3346
2805
  }
3347
- /** Wrangler writes one JSON object per line to `WRANGLER_OUTPUT_FILE_PATH`. */
3348
2806
  async function readWranglerOutput(file) {
3349
2807
  return (await readFile(file, "utf8").catch(() => "")).split("\n").flatMap((line) => {
3350
2808
  try {
@@ -3361,7 +2819,6 @@ const durationUnits = {
3361
2819
  hour: 36e5,
3362
2820
  day: 864e5
3363
2821
  };
3364
- /** `Claim within: 59 minutes` as an ISO time, from now. */
3365
2822
  function claimExpiry(text) {
3366
2823
  const match = /Claim within:\s*(\d+)\s*(second|minute|hour|day)s?/u.exec(text);
3367
2824
  return match ? new Date(Date.now() + Number(match[1]) * durationUnits[match[2]]).toISOString() : void 0;
@@ -3381,18 +2838,60 @@ async function cloudflareAdapter(context) {
3381
2838
  env: options.env ?? env,
3382
2839
  ...options
3383
2840
  });
3384
- return { async deploy() {
3385
- if (!context.preview && !context.temporary) for (const binding of command.migrations) {
2841
+ /** The migrations of `target` that its migrations table does not list. A database without the table has none applied. */
2842
+ const pendingD1Migrations = async (target) => {
2843
+ const query = async (sql) => {
2844
+ const step = `wrangler d1 execute ${target.binding}`;
3386
2845
  const result = await run([
3387
2846
  "d1",
3388
- "migrations",
3389
- "apply",
3390
- binding,
2847
+ "execute",
2848
+ target.binding,
3391
2849
  "--remote",
3392
2850
  "--config",
3393
- command.config
3394
- ], { show: true });
3395
- if (result.exitCode !== 0) throw hostCliFailed(`wrangler d1 migrations apply ${binding}`, result, context.secrets);
2851
+ command.config,
2852
+ "--json",
2853
+ "--command",
2854
+ sql
2855
+ ], { env: {
2856
+ ...env,
2857
+ WRANGLER_LOG: "log"
2858
+ } });
2859
+ if (result.exitCode !== 0) throw hostCliFailed(step, result, context.secrets);
2860
+ const names = d1ResultNames(result);
2861
+ if (!names) throw hostCliFailed(`${step} printed no JSON`, result, context.secrets);
2862
+ return names;
2863
+ };
2864
+ const tables = await query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = '${target.table.replaceAll("'", "''")}'`);
2865
+ const applied = new Set(tables.length ? await query(`SELECT name FROM "${target.table.replaceAll("\"", "\"\"")}"`) : []);
2866
+ return target.files.filter((file) => !applied.has(file));
2867
+ };
2868
+ return { async deploy() {
2869
+ if (!context.preview && !context.temporary) {
2870
+ const wranglerConfig = await readWranglerConfig(context.outputDir, command.config);
2871
+ const environment = env.CLOUDFLARE_ENV;
2872
+ const named = environment && isRecord(wranglerConfig.env) && Object.hasOwn(wranglerConfig.env, environment) ? wranglerConfig.env[environment] : void 0;
2873
+ const config = isRecord(named) ? named : wranglerConfig;
2874
+ for (const target of await unmigratedD1Bindings(context.outputDir, command.config, config, command.migrations)) {
2875
+ const pending = await pendingD1Migrations(target);
2876
+ if (!pending.length) continue;
2877
+ throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_D1_MIGRATIONS_PENDING({
2878
+ apply: `npx wrangler d1 migrations apply ${shellQuote(target.binding)} --remote --config ${shellQuote(command.config)}${environment ? ` --env ${shellQuote(environment)}` : ""}`,
2879
+ binding: target.binding,
2880
+ migrations: pending.join(", ")
2881
+ }), setupExitCodes.error);
2882
+ }
2883
+ for (const binding of command.migrations) {
2884
+ const result = await run([
2885
+ "d1",
2886
+ "migrations",
2887
+ "apply",
2888
+ binding,
2889
+ "--remote",
2890
+ "--config",
2891
+ command.config
2892
+ ], { show: true });
2893
+ if (result.exitCode !== 0) throw hostCliFailed(`wrangler d1 migrations apply ${binding}`, result, context.secrets);
2894
+ }
3396
2895
  }
3397
2896
  return await untilInterrupted(async (signal) => {
3398
2897
  const folder = await mkdtemp(join(tmpdir(), "vitehub-deploy-"));
@@ -3453,7 +2952,6 @@ async function cloudflareAdapter(context) {
3453
2952
  });
3454
2953
  } };
3455
2954
  }
3456
- /** Version and deployment `source` values: https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/versions/methods/list/ */
3457
2955
  /**
3458
2956
  * The secrets of the linked Worker. Wrangler 4.158 (`wrangler secret put --help`, `wrangler secret list --help`, in
3459
2957
  * test/fixtures/host-cli-help/). `secret put` reads the value from stdin when stdin is not a terminal, and creates a
@@ -3547,7 +3045,6 @@ function parseDeployments(value) {
3547
3045
  }];
3548
3046
  });
3549
3047
  }
3550
- /** A Workers API request that answers undefined on any error, for data that only adds to a listing. */
3551
3048
  async function optional(request) {
3552
3049
  try {
3553
3050
  return await request;
@@ -3642,7 +3139,6 @@ const listCloudflareDeployments = async (context, { limit, includeLive }) => {
3642
3139
  };
3643
3140
  //#endregion
3644
3141
  //#region src/setup/deploy/deno.ts
3645
- /** The first line of the `deploy.mjs` that ViteHub's Deno build writes (`packages/internal/src/build/deno-runtime-packages.ts`). */
3646
3142
  const runnerFirstLine = "import { spawn } from \"node:child_process\"";
3647
3143
  async function denoAdapter(context, organization) {
3648
3144
  const runner = join(context.outputDir, "deploy.mjs");
@@ -3678,10 +3174,6 @@ function denoOrganization(link, env) {
3678
3174
  if (!organization) throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_ORG_REQUIRED(), setupExitCodes.inputNeeded, { missing: [{ field: "DENO_DEPLOY_ORG" }] });
3679
3175
  return organization;
3680
3176
  }
3681
- /**
3682
- * One `KEY='value'` line for `deno deploy env load`, which parses the file with `@std/dotenv`. A single-quoted value
3683
- * is taken as it is. A value with a quote or a line break has no safe dotenv form, so it is refused.
3684
- */
3685
3177
  function dotenvLine(name, value) {
3686
3178
  if (/['\r\n]/u.test(value)) throw setupFailure(cliErrorDiagnostics.SETUP_ENV_VALUE_UNSUPPORTED({
3687
3179
  host: "deno",
@@ -3859,7 +3351,6 @@ function abortReason(signal, message) {
3859
3351
  }
3860
3352
  //#endregion
3861
3353
  //#region src/setup/deploy/netlify.ts
3862
- /** Nitro's Netlify preset writes static files to `dist` (`output.publicDir`). */
3863
3354
  const publishDir = "dist";
3864
3355
  function netlifyAdapter(context) {
3865
3356
  const netlify = hostCli("netlify", "netlify-cli", context.root, context.env);
@@ -3877,7 +3368,6 @@ function netlifyAdapter(context) {
3877
3368
  "--json",
3878
3369
  ...context.preview ? ["--context", "deploy-preview"] : ["--prod"]
3879
3370
  ];
3880
- if (existsSync(join(context.outputDir, "functions", "server.mjs"))) args.push("--functions", join(context.outputDir, "functions"));
3881
3371
  args.push(...site ? ["--site", site.id] : ["--site-name", context.projectName]);
3882
3372
  if (context.commit) args.push("--message", commitMessage(context.commit));
3883
3373
  const result = await context.run(netlify[0], [...netlify.slice(1), ...args], {
@@ -3904,12 +3394,10 @@ function netlifyAdapter(context) {
3904
3394
  };
3905
3395
  } };
3906
3396
  }
3907
- /** The Netlify deploy context of a host env target. */
3908
3397
  const netlifyContexts = {
3909
3398
  preview: "deploy-preview",
3910
3399
  production: "production"
3911
3400
  };
3912
- /** The contexts that one `all` value stands for, as the Netlify UI lists them for "different value for each context". */
3913
3401
  const allContexts = [
3914
3402
  "production",
3915
3403
  "deploy-preview",
@@ -3930,13 +3418,6 @@ function netlifyValues(value) {
3930
3418
  }
3931
3419
  return values;
3932
3420
  }
3933
- /**
3934
- * The `updateEnvVar` body that gives an existing variable Functions scope and, for a secret, secret storage. Undefined
3935
- * when the variable already has both, so PATCH can set the one value. PUT replaces every value, so the body keeps the
3936
- * values of the other contexts. Netlify masks secret values of every context except `dev`, so a secret with values
3937
- * in other contexts cannot be rewritten without losing them: that is refused before any write.
3938
- * https://docs.netlify.com/build/environment-variables/secrets-controller/
3939
- */
3940
3421
  function netlifyUpdate(existing, name, context, value, secret) {
3941
3422
  const refuse = (reason) => setupFailure(cliErrorDiagnostics.SETUP_ENV_VALUE_UNSUPPORTED({
3942
3423
  host: "netlify",
@@ -4149,7 +3630,6 @@ async function hasVercelLogin(root, context) {
4149
3630
  return false;
4150
3631
  }
4151
3632
  }
4152
- /** Reads `claimUrl` and `expiresAt` that `vercel deploy --temporary` keeps in `.vercel/anonymous.json`. Its token stays there. */
4153
3633
  async function readClaim(root) {
4154
3634
  let value;
4155
3635
  try {
@@ -4270,7 +3750,6 @@ const gitSources = /* @__PURE__ */ new Set([
4270
3750
  "import/repo",
4271
3751
  "clone/repo"
4272
3752
  ]);
4273
- /** `source` of a deployment: https://vercel.com/docs/rest-api/reference/endpoints/deployments/list-deployments */
4274
3753
  function vercelSource(value, commit) {
4275
3754
  if (value === "cli") return "cli";
4276
3755
  if (typeof value === "string" && gitSources.has(value)) return "git";
@@ -4284,7 +3763,6 @@ function vercelState(value) {
4284
3763
  if (value === "BUILDING" || value === "INITIALIZING" || value === "QUEUED" || value === "BLOCKED") return "building";
4285
3764
  return "unknown";
4286
3765
  }
4287
- /** `vitehubCommit` and `vitehubDirty` from `vercel deploy --meta`, else the commit of a Git integration build. */
4288
3766
  function vercelCommit(meta) {
4289
3767
  if (!isRecord(meta)) return;
4290
3768
  const marked = optionalString$1(meta.vitehubCommit);
@@ -4365,7 +3843,6 @@ function optionalString(value) {
4365
3843
  function invalidResponse(host) {
4366
3844
  return cliErrorDiagnostics.CLI_HOST_RESPONSE_INVALID({ host });
4367
3845
  }
4368
- /** The same normalization as the deployment identity of `vitehub({ name })`. */
4369
3846
  function normalizeName(value) {
4370
3847
  return value?.trim().toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "") || void 0;
4371
3848
  }
@@ -4386,7 +3863,6 @@ function nameRequired() {
4386
3863
  rerun: "vitehub link --project <name>"
4387
3864
  });
4388
3865
  }
4389
- /** `--project`, else the literal `name` of vitehub(), else the package.json name, normalized as the build does. */
4390
3866
  async function projectName(project, option) {
4391
3867
  if (option?.trim()) return option.trim();
4392
3868
  const config = project.config;
@@ -4425,6 +3901,11 @@ function rerunCommand(host, name, options, extra) {
4425
3901
  ].join(" ");
4426
3902
  }
4427
3903
  function notFound(host, name, options, account) {
3904
+ if (host === "deno") return setupFailure(cliErrorDiagnostics.SETUP_LINK_PROJECT_NOT_FOUND({
3905
+ account,
3906
+ host,
3907
+ project: name
3908
+ }), setupExitCodes.conflict);
4428
3909
  const rerun = rerunCommand(host, name, options, "--create");
4429
3910
  return setupFailure(cliErrorDiagnostics.SETUP_LINK_PROJECT_NOT_FOUND({
4430
3911
  account,
@@ -4433,7 +3914,6 @@ function notFound(host, name, options, account) {
4433
3914
  rerun
4434
3915
  }), setupExitCodes.conflict, { rerun });
4435
3916
  }
4436
- /** Returns undefined when the host API answers 404. */
4437
3917
  async function unlessNotFound(request) {
4438
3918
  try {
4439
3919
  return await request;
@@ -4604,6 +4084,55 @@ async function linkNetlify(name, options, token, fetchImpl) {
4604
4084
  verified: true
4605
4085
  };
4606
4086
  }
4087
+ async function linkDeno(name, options, token, root, context) {
4088
+ const linked = {
4089
+ ...options.account ? { account: { id: options.account } } : {},
4090
+ created: false,
4091
+ project: { name }
4092
+ };
4093
+ const organization = options.account ?? context.env.DENO_DEPLOY_ORG?.trim();
4094
+ if (!token || !organization) return {
4095
+ ...linked,
4096
+ verified: false
4097
+ };
4098
+ const deno = hostCli("deno", "deno", root, context.env);
4099
+ const step = "deno deploy apps get";
4100
+ const secrets = [token];
4101
+ const run = context.runHostCli ?? createDeployRun(context.stderr, secrets);
4102
+ const runOptions = {
4103
+ cwd: root,
4104
+ env: context.env,
4105
+ timeoutMs: 3e4
4106
+ };
4107
+ const result = await run(deno[0], [
4108
+ ...deno.slice(1),
4109
+ "deploy",
4110
+ "apps",
4111
+ "get",
4112
+ "--json",
4113
+ "--non-interactive",
4114
+ "--org",
4115
+ organization,
4116
+ "--app",
4117
+ name
4118
+ ], runOptions).catch((error) => {
4119
+ throw hostCliFailed(step, {
4120
+ exitCode: null,
4121
+ stderr: error instanceof Error ? error.message : String(error),
4122
+ stdout: ""
4123
+ }, secrets);
4124
+ });
4125
+ if (result.exitCode === 4) throw notFound("deno", name, options, organization);
4126
+ if (result.exitCode !== 0) throw hostCliFailed(step, {
4127
+ ...result,
4128
+ stderr: result.stderr ?? ""
4129
+ }, secrets);
4130
+ return {
4131
+ ...linked,
4132
+ account: { id: organization },
4133
+ verified: true
4134
+ };
4135
+ }
4607
4136
  /** `content` of a `.gitignore` with a `.vitehub` line, or undefined when it already ignores `.vitehub`. */
4608
4137
  function gitignoreWithViteHub(content) {
4609
4138
  if (content.split(/\r?\n/u).some((line) => /^\/?(?:\*\*\/)?\.vitehub\/?$/u.test(line.trim()))) return;
@@ -4630,12 +4159,7 @@ async function linkSetupProject(project, options, context) {
4630
4159
  const credentials = await resolveHostCredentials(host, credentialsContext);
4631
4160
  const fetchImpl = context.fetch ?? globalThis.fetch;
4632
4161
  let linked;
4633
- if (host === "deno") linked = {
4634
- ...options.account ? { account: { id: options.account } } : {},
4635
- created: false,
4636
- project: { name },
4637
- verified: false
4638
- };
4162
+ if (host === "deno") linked = await linkDeno(name, options, credentials.ok ? credentials.token : void 0, project.root, context);
4639
4163
  else if (!credentials.ok) throw setupFailure(cliErrorDiagnostics.SETUP_LINK_CREDENTIALS_MISSING({
4640
4164
  fix: credentials.fix,
4641
4165
  host
@@ -4877,7 +4401,6 @@ async function readSetupLinkStatus(project, host, context) {
4877
4401
  }
4878
4402
  //#endregion
4879
4403
  //#region src/setup/env-encrypted.ts
4880
- /** dotenvx marks an encrypted value with this prefix. */
4881
4404
  const prefix = "encrypted:";
4882
4405
  /** The file where dotenvx writes private keys. It must never be in git. */
4883
4406
  const envKeysFile = ".env.keys";
@@ -5024,7 +4547,6 @@ function concat(...parts) {
5024
4547
  }
5025
4548
  return out;
5026
4549
  }
5027
- /** "expand 32-byte k" as little-endian words. */
5028
4550
  const sigma = new Uint32Array([
5029
4551
  1634760805,
5030
4552
  857760878,
@@ -5041,7 +4563,6 @@ function wordBytes(input) {
5041
4563
  input.forEach((word, index) => view.setUint32(index * 4, word, true));
5042
4564
  return out;
5043
4565
  }
5044
- /** `crypto_box_beforenm`: HSalsa20 of the X25519 shared secret with a zero input. */
5045
4566
  function boxKey(shared) {
5046
4567
  const out = /* @__PURE__ */ new Uint32Array(8);
5047
4568
  hsalsa(sigma, words(shared), /* @__PURE__ */ new Uint32Array(4), out);
@@ -5130,9 +4651,7 @@ var env_exports = /* @__PURE__ */ __exportAll({
5130
4651
  readLocalEnvValues: () => readLocalEnvValues,
5131
4652
  runEnvCommand: () => runEnvCommand
5132
4653
  });
5133
- /** The stage that a deploy without `--preview` reads. */
5134
4654
  const defaultStage = "production";
5135
- /** The host CLI tokens. They are never values to push, and no output may show them. */
5136
4655
  const tokenNames = [
5137
4656
  "CLOUDFLARE_API_TOKEN",
5138
4657
  "VERCEL_TOKEN",
@@ -5145,7 +4664,6 @@ const hostEnvs = {
5145
4664
  netlify: netlifyEnv,
5146
4665
  vercel: vercelEnv
5147
4666
  };
5148
- /** Hosts without a preview environment: a Worker has one set of secrets, and ViteHub deploys Deno to production only. */
5149
4667
  const noPreview = /* @__PURE__ */ new Set(["cloudflare", "deno"]);
5150
4668
  function readEnvArgs(args, push, usage) {
5151
4669
  try {
@@ -5222,7 +4740,6 @@ function linkedTarget(links, host, command) {
5222
4740
  });
5223
4741
  return selected.link;
5224
4742
  }
5225
- /** The names and the env folder of the last build for `host`. Builds first when there is no build output for `host`. */
5226
4743
  async function readNames(project, host, context) {
5227
4744
  try {
5228
4745
  return await readBuildOutput(project.root, host);
@@ -5234,7 +4751,6 @@ async function readNames(project, host, context) {
5234
4751
  await build(project, host, context);
5235
4752
  return await readBuildOutput(project.root, host);
5236
4753
  }
5237
- /** Plain vars set by the build rather than uploaded as secrets. */
5238
4754
  async function configVarNames(host, outputDir) {
5239
4755
  return new Set(host === "cloudflare" ? await wranglerVarNames(outputDir) : []);
5240
4756
  }
@@ -5276,10 +4792,6 @@ async function openTarget(args, command, context) {
5276
4792
  target
5277
4793
  };
5278
4794
  }
5279
- /**
5280
- * GitHub is a destination, not a host: the names come from the build of the linked host (or `--host`), and the stage
5281
- * only picks the local `.env.<stage>` file. Names that GitHub reserves (`GITHUB_*`) drop out of each entry.
5282
- */
5283
4795
  async function openGitHubTarget(args, options, project, command, context) {
5284
4796
  const selected = selectSetupLink(await readSetupLinks(project.root), args.host);
5285
4797
  if ("ambiguous" in selected) throw hostRequired(selected.ambiguous, `${command} --to github`);
@@ -5350,7 +4862,6 @@ function isRequired(entry) {
5350
4862
  function matchesPrefix(entry, name) {
5351
4863
  return !!entry.prefix && name.startsWith(entry.prefix) && name.length > entry.prefix.length;
5352
4864
  }
5353
- /** True when one of `names` sets the entry: one of its names, or a name with its prefix. */
5354
4865
  function isSet(entry, names) {
5355
4866
  return entry.names.some((name) => names.has(name)) || [...names].some((name) => matchesPrefix(entry, name));
5356
4867
  }
@@ -5390,7 +4901,6 @@ function targetLabel(output) {
5390
4901
  if (output.github) return `the GitHub Actions secrets of ${output.github.repository}${output.github.environment ? `, environment ${output.github.environment}` : ""}, stage ${output.stage}`;
5391
4902
  return `${output.project} on ${output.host}, stage ${output.stage}${output.target === output.stage ? "" : ` (${output.target})`}`;
5392
4903
  }
5393
- /** The flags that name the destination again, for a hint or a rerun. */
5394
4904
  function destinationFlags(output) {
5395
4905
  return [...output.github ? [
5396
4906
  "--to github",
@@ -5433,12 +4943,10 @@ function destination(target) {
5433
4943
  ...target.github ? { github: target.github } : {}
5434
4944
  };
5435
4945
  }
5436
- /** An env file as output names it: relative to the project root, such as `config/.env.production`. */
5437
4946
  function fileSource(root, path) {
5438
4947
  const folder = relative(root, dirname(path));
5439
4948
  return `${folder ? `${folder}/` : ""}.env${basename(path).slice(4)}`;
5440
4949
  }
5441
- /** Trace the same replacements and iteration order as Vite's patched dotenv-expand. */
5442
4950
  function expandedFiles(raw, env) {
5443
4951
  const parsed = Object.fromEntries([...raw].map(([name, file]) => [name, file.value]));
5444
4952
  const files = new Map([...raw].map(([name, file]) => [name, /* @__PURE__ */ new Set([file.path])]));
@@ -5526,11 +5034,6 @@ async function readLocalEnvValues(root, envDir, stage, env) {
5526
5034
  }
5527
5035
  return values;
5528
5036
  }
5529
- /**
5530
- * The value of each entry: the first name in read order that has a local value, and every local name of a prefix.
5531
- * `onHost` keeps what the host has: an entry with one of its names on the host keeps that alias, and a prefix entry
5532
- * skips only the members that the host has.
5533
- */
5534
5037
  function planPush(entries, values, only, onHost = /* @__PURE__ */ new Set()) {
5535
5038
  const wanted = only.length ? new Set(only) : void 0;
5536
5039
  const unknown = only.filter((name) => !entries.some((entry) => entry.names.includes(name) || matchesPrefix(entry, name)));
@@ -5569,11 +5072,6 @@ function planPush(entries, values, only, onHost = /* @__PURE__ */ new Set()) {
5569
5072
  skipped
5570
5073
  };
5571
5074
  }
5572
- /**
5573
- * True when `directory` or a parent folder looks like a git repository, or `GIT_DIR` names one: a `.git` file, as in a
5574
- * worktree, or a `.git` folder with `HEAD`. It does not ask git, because git reports a broken repository the same way
5575
- * as no repository, and a broken one must refuse.
5576
- */
5577
5075
  function inGitRepository(directory, env) {
5578
5076
  if (env.GIT_DIR) return true;
5579
5077
  for (let current = directory;; current = dirname(current)) {
@@ -5582,7 +5080,6 @@ function inGitRepository(directory, env) {
5582
5080
  if (dirname(current) === current) return false;
5583
5081
  }
5584
5082
  }
5585
- /** What git says about one env file, by its real path. Throws when git cannot answer. */
5586
5083
  async function gitFileState(file, label, run, env) {
5587
5084
  const failed = (reason) => setupFailure(cliErrorDiagnostics.SETUP_ENV_GIT_FAILED({
5588
5085
  file: label,
@@ -5616,12 +5113,6 @@ async function gitFileState(file, label, run, env) {
5616
5113
  if (ignored.exitCode === 1) return "unignored";
5617
5114
  throw failed(ignored.stderr.trim() || `git check-ignore exited with ${ignored.exitCode}`);
5618
5115
  }
5619
- /**
5620
- * Refuses a secret whose value reads an env file that git tracks, or that git does not ignore: pushing it would hide
5621
- * that the secret is in git, or that the next commit can add it. It checks every file that the value reads, through
5622
- * `$NAME` expansion too, by its real path, so a symlink to a tracked file does not pass. When git cannot answer inside a
5623
- * repository, it refuses. A file outside any git repository passes with a warning, since git cannot commit it.
5624
- */
5625
5116
  async function assertUntracked(planned, root, run, env, stderr) {
5626
5117
  const byFile = /* @__PURE__ */ new Map();
5627
5118
  for (const item of planned) {
@@ -5652,7 +5143,6 @@ async function assertUntracked(planned, root, run, env, stderr) {
5652
5143
  const realKeys = await realpath(keysPath).catch(() => void 0);
5653
5144
  if (planned.some((item) => item.encrypted) && realKeys && inGitRepository(dirname(realKeys), env) && await gitFileState(realKeys, ".env.keys", run, env) === "tracked") throw setupFailure(cliErrorDiagnostics.SETUP_ENV_KEYS_TRACKED({ file: envKeysFile }), setupExitCodes.conflict);
5654
5145
  }
5655
- /** Replaces each encrypted value with its plaintext. The private keys and the plaintext join the values that output redacts. */
5656
5146
  async function decryptPlanned(planned, root, env, secrets) {
5657
5147
  const { keys, values } = await decryptEnvValues(root, planned.filter((item) => item.encrypted).map((item) => ({
5658
5148
  file: item.source,
@@ -5697,7 +5187,6 @@ function pushRerun(args) {
5697
5187
  ...args.json ? ["--json"] : []
5698
5188
  ].join(" ");
5699
5189
  }
5700
- /** Short plain values, such as "1", would hide host output that has nothing to do with them. */
5701
5190
  function addRedactions(planned, secrets) {
5702
5191
  for (const item of planned) if (item.secret || item.value.length >= 4) secrets.push(item.value);
5703
5192
  }
@@ -5746,7 +5235,6 @@ async function runPush(args, context) {
5746
5235
  else writePush(output, context);
5747
5236
  return setupExitCodes.done;
5748
5237
  }
5749
- /** The name that ViteHub derives its own keys from. A deploy can generate it, because no one else has to know it. */
5750
5238
  const appSecretName = "VITEHUB_SECRET";
5751
5239
  async function confirmGenerate(label) {
5752
5240
  const terminal = createInterface({
@@ -5851,7 +5339,7 @@ async function checkDeployEnv(options) {
5851
5339
  if (stored.length && !hostEnv && host !== "cloudflare") throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_ENV_NOT_LINKED({
5852
5340
  host,
5853
5341
  names: stored.map((item) => item.name).join(", ")
5854
- }), setupExitCodes.inputNeeded, { rerun: `vitehub link --host ${host} --create` });
5342
+ }), setupExitCodes.inputNeeded, { rerun: host === "deno" ? "vitehub link --host deno" : `vitehub link --host ${host} --create` });
5855
5343
  await assertUntracked(stored, options.root, options.run, context.env, context.stderr);
5856
5344
  const planned = await decryptPlanned(stored, options.root, context.env, options.secrets);
5857
5345
  output.missing = missing.map(diffEntry);
@@ -5887,4 +5375,4 @@ async function runEnvCommand(feature, args, context) {
5887
5375
  }
5888
5376
  }
5889
5377
  //#endregion
5890
- export { readDeployCommit as A, readSetupProject as B, denoOrganization as C, build as D, listCloudflareDeployments as E, uninstallArgs as F, featureSupport as G, featureHosts as H, hostFromNitroPreset as I, editViteHubConfig as J, features as K, hasDefinitionFiles as L, installCommand as M, setsOption as N, readBuildOutput as O, setupStatus as P, listMatchingFiles as R, denoAdapter as S, cloudflareAdapter as T, featureIds as U, setupLockfiles as V, featurePackages as W, locateViteHubConfig as X, insertViteHubConfig as Y, __exportAll as Z, listVercelDeployments as _, ensureViteHubGitignore as a, netlifyAdapter as b, linkSetupProject as c, readSetupLinkStatus as d, readSetupLinks as f, hasVercelLogin as g, writeSeparateResourcesNote as h, addSetupLink as i, installArgs as j, createDeployRun as k, readLinkHostOption as l, unlinkSetupProject as m, env_exports as n, gitignoreWithViteHub as o, selectSetupLink as p, impliedFeatures as q, SETUP_LINK_FILE as r, hostRequired as s, checkDeployEnv as t, readSetupLinkState as u, vercelAdapter as v, listDenoDeployments as w, abortable as x, listNetlifyDeployments as y, detectPackageManager as z };
5378
+ export { readDeployCommit as A, listMatchingFiles as B, denoOrganization as C, build as D, listCloudflareDeployments as E, setupStatus as F, insertViteHubConfig as G, readSetupProject as H, shellQuote as I, locateViteHubConfig as K, uninstallArgs as L, installArgs as M, installCommand as N, readBuildOutput as O, missingProviderOption as P, hostFromNitroPreset as R, denoAdapter as S, cloudflareAdapter as T, setupLockfiles as U, detectPackageManager as V, editViteHubConfig as W, listVercelDeployments as _, ensureViteHubGitignore as a, netlifyAdapter as b, linkSetupProject as c, readSetupLinkStatus as d, readSetupLinks as f, hasVercelLogin as g, writeSeparateResourcesNote as h, addSetupLink as i, formatInstallCommand as j, createDeployRun as k, readLinkHostOption as l, unlinkSetupProject as m, env_exports as n, gitignoreWithViteHub as o, selectSetupLink as p, SETUP_LINK_FILE as r, hostRequired as s, checkDeployEnv as t, readSetupLinkState as u, vercelAdapter as v, listDenoDeployments as w, abortable as x, listNetlifyDeployments as y, hasDefinitionFiles as z };