@vite-hub/cli 0.6.1 → 0.8.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.
- package/README.md +6 -3
- package/dist/{commands-FOmqEZUi.js → commands-w7tEEJph.js} +469 -160
- package/dist/console-apps-BQX-Np9Q.js +271 -0
- package/dist/console-auth-cCodgT_T.js +2813 -0
- package/dist/{console-env-lQ3_eMOy.js → console-env-eXdVI6kw.js} +7 -4
- package/dist/{deploy-DDen0JC0.js → deploy-CqR6pJa-.js} +49 -17
- package/dist/dist-CEIUyD15.js +2495 -0
- package/dist/env-D_CN5DyX.js +2169 -0
- package/dist/envelope-BJQ7xPyX.js +99 -0
- package/dist/help-cache-BI6y5pN8.js +195 -0
- package/dist/index.d.ts +13 -14
- package/dist/index.js +217 -66
- package/dist/link-BRNWNqT9.js +663 -0
- package/dist/provision-9QsGgeiq.js +1741 -0
- package/dist/{provision-kiD8Emd7.d.ts → provision-ByxmUa19.d.ts} +16 -1
- package/dist/provision-Fiosv3Un.js +1391 -0
- package/dist/setup/index.d.ts +37 -15
- package/dist/setup/index.js +12 -9
- package/dist/status-gjvZVutV.js +599 -0
- package/dist/vercel-B5CJLsT0.js +701 -0
- package/package.json +5 -4
- package/dist/env-DzYHxq9A.js +0 -5657
- package/dist/provision-YzxNsbhs.js +0 -4139
- package/dist/rolldown-runtime-BJohB4LM.js +0 -13
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { _ as featureSupport, b as impliedFeatures, d as cliErrorDiagnostics, h as featureIds, m as featureHosts, v as features, w as isRecord, x as installSpecifier } from "./provision-9QsGgeiq.js";
|
|
2
|
+
import { _ as setupLockfiles, b as locateViteHubConfig, c as logoutCommand, d as whoamiCommand, f as declaresNuxt5, g as readSetupProject, h as pnpmWorkspaceFile, m as nuxtReleases, p as detectPackageManager, s as loginCommand, v as editViteHubConfig, y as insertViteHubConfig } from "./console-auth-cCodgT_T.js";
|
|
3
|
+
import { a as table, c as __exportAll, i as setupFailure, n as readSetupArgs, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-BJQ7xPyX.js";
|
|
4
|
+
import { a as rateLimitUsesVercelKV, c as shellQuote, f as hasDefinitionFiles, i as missingProviderOption, l as uninstallArgs, n as installArgs, o as setupFeaturePackages, p as listMatchingFiles, r as installCommand, s as setupStatus, t as formatInstallCommand } from "./status-gjvZVutV.js";
|
|
5
|
+
import { t as appsCommand } from "./console-apps-BQX-Np9Q.js";
|
|
6
|
+
import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-CqR6pJa-.js";
|
|
7
|
+
import { i as gitignoreWith, l as readLinkHostOption, m as unlinkSetupProject, o as ignoredFolders, s as linkSetupProject, t as SETUP_LINK_FILE, u as readSetupLinkState } from "./link-BRNWNqT9.js";
|
|
5
8
|
import { createRequire } from "node:module";
|
|
6
9
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
10
|
import process from "node:process";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
8
12
|
import { basename, dirname, join, relative, resolve } from "pathe";
|
|
9
13
|
import { glob, mkdir, readFile, readdir, rm, rmdir, writeFile } from "node:fs/promises";
|
|
10
|
-
import { join as join$1 } from "node:path";
|
|
14
|
+
import { join as join$1, matchesGlob } from "node:path";
|
|
11
15
|
import { createInterface } from "node:readline/promises";
|
|
12
|
-
import { pathToFileURL } from "node:url";
|
|
13
|
-
import { isDeepStrictEqual, parseArgs } from "node:util";
|
|
14
16
|
import { createTwoFilesPatch } from "diff";
|
|
17
|
+
import { isDeepStrictEqual, parseArgs, stripVTControlCharacters } from "node:util";
|
|
18
|
+
import { isMap, parseDocument } from "yaml";
|
|
15
19
|
import semver, { minVersion, satisfies, subset, validRange } from "semver";
|
|
16
20
|
// ../internal/dist/feature-inputs.js
|
|
17
21
|
function isLocaleTag(value) {
|
|
@@ -33,6 +37,129 @@ function i18nLocaleListProblem(locales) {
|
|
|
33
37
|
function mcpPublicRouteNeedsSignedAuth(publicRoute, auth) {
|
|
34
38
|
return !!publicRoute && auth !== true;
|
|
35
39
|
}
|
|
40
|
+
// src/setup/install.ts
|
|
41
|
+
/**
|
|
42
|
+
* The packages with build scripts that a ViteHub app installs: Nuxt 4 and Workflow install esbuild, Workflow installs
|
|
43
|
+
* `@swc/core` and cbor-extract, and Wrangler on Cloudflare installs esbuild and workerd. pnpm 11 and later stop the
|
|
44
|
+
* install while a build script waits for approval. Each of these packages runs without its build script: esbuild,
|
|
45
|
+
* workerd, and `@swc/core` load the binary of their platform package, and cbor-extract loads its prebuilt addon, so the
|
|
46
|
+
* app declines every one of them.
|
|
47
|
+
*/
|
|
48
|
+
function declinedBuilds(project, host, features) {
|
|
49
|
+
const workflow = features.includes("workflow");
|
|
50
|
+
const cloudflare = host === "cloudflare";
|
|
51
|
+
return [
|
|
52
|
+
...project.framework === "nuxt" && !declaresNuxt5(project.nuxt) || workflow || cloudflare ? ["esbuild"] : [],
|
|
53
|
+
...cloudflare ? ["workerd"] : [],
|
|
54
|
+
...workflow ? ["@swc/core", "cbor-extract"] : []
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
function named(policy, name) {
|
|
58
|
+
if (!isRecord(policy)) return false;
|
|
59
|
+
if (policy.dangerouslyAllowAllBuilds === true) return true;
|
|
60
|
+
const matches = (key) => typeof key === "string" && (key === name || key.startsWith(`${name}@`));
|
|
61
|
+
if (isRecord(policy.allowBuilds) && Object.keys(policy.allowBuilds).some(matches)) return true;
|
|
62
|
+
return [
|
|
63
|
+
"onlyBuiltDependencies",
|
|
64
|
+
"ignoredBuiltDependencies",
|
|
65
|
+
"neverBuiltDependencies"
|
|
66
|
+
].some((key) => {
|
|
67
|
+
const list = policy[key];
|
|
68
|
+
return Array.isArray(list) && list.some(matches);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function pnpmBuildPolicyFile(root) {
|
|
72
|
+
const local = join(root, "pnpm-workspace.yaml");
|
|
73
|
+
const workspace = pnpmWorkspaceFile(root);
|
|
74
|
+
if (!workspace || workspace === local) return local;
|
|
75
|
+
const document = parseDocument(readFileSync(workspace, "utf8"));
|
|
76
|
+
if (document.errors.length) return workspace;
|
|
77
|
+
const policy = document.toJS();
|
|
78
|
+
if (!isRecord(policy) || !Array.isArray(policy.packages)) return workspace;
|
|
79
|
+
const path = relative(dirname(workspace), root);
|
|
80
|
+
const patterns = policy.packages.filter((pattern) => typeof pattern === "string");
|
|
81
|
+
const includes = (pattern) => matchesGlob(path, pattern.replace(/^\.\//u, "").replace(/\/$/u, ""));
|
|
82
|
+
return patterns.some((pattern) => !pattern.startsWith("!") && includes(pattern)) && !patterns.some((pattern) => pattern.startsWith("!") && includes(pattern.slice(1))) ? workspace : local;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adds `allowBuilds: { <name>: false }` for each of `names` that the pnpm build policy does not name yet. It edits the
|
|
86
|
+
* `pnpm-workspace.yaml` of the project or of its pnpm workspace, or creates one in the project. Undefined when the
|
|
87
|
+
* package manager is not pnpm, or when the policy already names every package.
|
|
88
|
+
*/
|
|
89
|
+
function planPnpmBuilds(project, names) {
|
|
90
|
+
if (project.packageManager !== "pnpm" || !names.length) return;
|
|
91
|
+
const file = pnpmBuildPolicyFile(project.root);
|
|
92
|
+
const before = existsSync(file) ? readFileSync(file, "utf8") : void 0;
|
|
93
|
+
const document = parseDocument(before ?? "");
|
|
94
|
+
if (document.errors.length || document.contents !== null && !isMap(document.contents)) return;
|
|
95
|
+
const policy = document.toJS();
|
|
96
|
+
const missing = names.filter((name) => !named(policy, name));
|
|
97
|
+
if (!missing.length) return;
|
|
98
|
+
if (document.has("allowBuilds") && !isMap(document.get("allowBuilds", true))) return;
|
|
99
|
+
for (const name of missing) document.setIn(["allowBuilds", name], false);
|
|
100
|
+
return {
|
|
101
|
+
after: document.toString(),
|
|
102
|
+
file,
|
|
103
|
+
path: relative(project.root, file),
|
|
104
|
+
...before === void 0 ? {} : { before }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Writes a planned build policy change. Throws when the file changed after the plan. */
|
|
108
|
+
async function writePnpmBuilds(change) {
|
|
109
|
+
if (change.before === void 0) {
|
|
110
|
+
await mkdir(dirname(change.file), { recursive: true });
|
|
111
|
+
try {
|
|
112
|
+
await writeFile(change.file, change.after, { flag: "wx" });
|
|
113
|
+
} catch {
|
|
114
|
+
throw setupFailure(cliErrorDiagnostics.SETUP_FILE_EXISTS({ file: change.path }), setupExitCodes.conflict);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (await readFile(change.file, "utf8") !== change.before) throw setupFailure(cliErrorDiagnostics.SETUP_STALE_PLAN({ file: change.path }), setupExitCodes.stalePlan);
|
|
119
|
+
await writeFile(change.file, change.after);
|
|
120
|
+
}
|
|
121
|
+
function ignoredBuilds(output) {
|
|
122
|
+
const list = output.match(/Ignored build scripts:\s*((?:@[^\s/,]+\/)?[\w.-]+(?:@[^\s,]+)?(?:,\s*(?:@[^\s/,]+\/)?[\w.-]+(?:@[^\s,]+)?)*)/u)?.[1];
|
|
123
|
+
return list ? list.split(",").map((spec) => spec.trim().replace(/(?<=.)@[^@]*$/u, "")) : [];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Installs `packages` with the package manager. The package manager's error output still reaches the terminal, and a
|
|
127
|
+
* failure throws `SETUP_INSTALL_FAILED` with that output, so `--json` shows the real error too.
|
|
128
|
+
*/
|
|
129
|
+
async function installPackages(context, packageManager, packages, dev, failure) {
|
|
130
|
+
const commandArgs = installArgs(packageManager, packages, dev);
|
|
131
|
+
const tails = {
|
|
132
|
+
stderr: "",
|
|
133
|
+
stdout: ""
|
|
134
|
+
};
|
|
135
|
+
const onOutput = (text, stream) => {
|
|
136
|
+
context.stderr?.write(text);
|
|
137
|
+
tails[stream] = (tails[stream] + text).slice(-16384);
|
|
138
|
+
};
|
|
139
|
+
const result = await context.spawn(packageManager, commandArgs, {
|
|
140
|
+
cwd: failure.root,
|
|
141
|
+
env: context.env,
|
|
142
|
+
onOutput,
|
|
143
|
+
stderr: "pipe",
|
|
144
|
+
stdout: "pipe"
|
|
145
|
+
});
|
|
146
|
+
if (result.stdout && !tails.stdout) onOutput(result.stdout, "stdout");
|
|
147
|
+
if (result.stderr && !tails.stderr) onOutput(result.stderr, "stderr");
|
|
148
|
+
if (result.exitCode === 0) return;
|
|
149
|
+
const streams = [tails.stdout, tails.stderr].map(stripVTControlCharacters);
|
|
150
|
+
const output = streams.map((text) => text.trim().split("\n").map((line) => line.trimEnd()).filter(Boolean).slice(-20).join("\n")).filter(Boolean).join("\n");
|
|
151
|
+
const ignored = packageManager === "pnpm" ? [...new Set(streams.flatMap(ignoredBuilds))] : [];
|
|
152
|
+
throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
|
|
153
|
+
command: formatInstallCommand(packageManager, commandArgs),
|
|
154
|
+
exitCode: result.exitCode ?? result.signal,
|
|
155
|
+
filesWritten: failure.filesWritten,
|
|
156
|
+
...output ? { output } : {},
|
|
157
|
+
...ignored.length ? {
|
|
158
|
+
ignored,
|
|
159
|
+
workspaceFile: pnpmBuildPolicyFile(failure.root)
|
|
160
|
+
} : {}
|
|
161
|
+
}), setupExitCodes.error);
|
|
162
|
+
}
|
|
36
163
|
// src/setup/add.ts
|
|
37
164
|
const usage$3 = "vitehub add <feature...> [--name <definition>] [--option <key=value>]... [--dry-run] [--yes] [--no-install] [--json]";
|
|
38
165
|
const optionChoices = {
|
|
@@ -46,11 +173,16 @@ const optionChoices = {
|
|
|
46
173
|
"sandboxTask.driver": { values: ["vercel"] },
|
|
47
174
|
"workflow.driver": { values: ["openworkflow"] }
|
|
48
175
|
};
|
|
176
|
+
const optionExamples = {
|
|
177
|
+
"blob.driver": ["blob.driver=s3", "blob.bucket=<bucket>"],
|
|
178
|
+
"database.connection": ["database.connection.url=libsql://<host>"],
|
|
179
|
+
"workspace.store": ["workspace.store.driver=github", "workspace.store.repo=<owner>/<repo>"]
|
|
180
|
+
};
|
|
49
181
|
const providerKeys = ["driver", "store"];
|
|
50
182
|
function selectsProvider(id, value, host) {
|
|
51
|
-
if (!isRecord
|
|
183
|
+
if (!isRecord(value)) return false;
|
|
52
184
|
if (id === "workflow" && host !== "netlify") {
|
|
53
|
-
const configured = (storage, key) => isRecord
|
|
185
|
+
const configured = (storage, key) => isRecord(storage) && (typeof storage[key] === "string" ? !!storage[key].trim() : isRecord(storage[key]));
|
|
54
186
|
if (configured(value.postgres, "url") || configured(value.sqlite, "path")) return true;
|
|
55
187
|
}
|
|
56
188
|
return providerKeys.some((key) => value[key] !== void 0);
|
|
@@ -63,7 +195,7 @@ function hostSupport(id, host, env) {
|
|
|
63
195
|
const enabledValues = { env: {} };
|
|
64
196
|
function installSpecifiers(packages) {
|
|
65
197
|
const manifest = JSON.parse(readFileSync(new URL(import.meta.resolve("@vite-hub/cli/package.json")), "utf8"));
|
|
66
|
-
const dependencies = isRecord
|
|
198
|
+
const dependencies = isRecord(manifest) && isRecord(manifest.dependencies) ? manifest.dependencies : {};
|
|
67
199
|
const preview = Object.entries(dependencies).flatMap(([name, specifier]) => {
|
|
68
200
|
if (!name.startsWith("@vite-hub/") || typeof specifier !== "string" || !specifier.startsWith("https://pkg.pr.new/")) return [];
|
|
69
201
|
const [base, ref] = specifier.split(`/${name}@`);
|
|
@@ -100,13 +232,10 @@ function setPath(target, path, value) {
|
|
|
100
232
|
return;
|
|
101
233
|
}
|
|
102
234
|
const child = target[key];
|
|
103
|
-
const next = isRecord
|
|
235
|
+
const next = isRecord(child) ? { ...child } : {};
|
|
104
236
|
setPath(next, rest, value);
|
|
105
237
|
target[key] = next;
|
|
106
238
|
}
|
|
107
|
-
function isRecord$1(value) {
|
|
108
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
109
|
-
}
|
|
110
239
|
/** Reads the arguments. Throws `CLI_R0003` for an unknown flag, feature, or option. */
|
|
111
240
|
function readAddArgs(args) {
|
|
112
241
|
const parsed = {
|
|
@@ -152,7 +281,7 @@ function readAddArgs(args) {
|
|
|
152
281
|
}
|
|
153
282
|
/** `value` as `--option` values under `prefix`, such as `["email.driver=resend"]`. */
|
|
154
283
|
function flattenOptions(prefix, value, out = []) {
|
|
155
|
-
if (isRecord
|
|
284
|
+
if (isRecord(value)) for (const [key, child] of Object.entries(value)) flattenOptions(`${prefix}.${key}`, child, out);
|
|
156
285
|
else out.push(`${prefix}=${value === null || typeof value !== "object" ? String(value) : JSON.stringify(value)}`);
|
|
157
286
|
return out;
|
|
158
287
|
}
|
|
@@ -164,7 +293,7 @@ function rerunCommand$1(args, extra = {}, extraFeatures = []) {
|
|
|
164
293
|
...Object.keys(extra)
|
|
165
294
|
])].flatMap((id) => {
|
|
166
295
|
const merged = mergeValue(args.options[id], extra[id]);
|
|
167
|
-
return isRecord
|
|
296
|
+
return isRecord(merged) ? flattenOptions(id, merged) : [];
|
|
168
297
|
});
|
|
169
298
|
return [
|
|
170
299
|
"vitehub add",
|
|
@@ -179,18 +308,18 @@ function rerunCommand$1(args, extra = {}, extraFeatures = []) {
|
|
|
179
308
|
/** Merges `patch` into `base`, object key by object key. */
|
|
180
309
|
function mergeValue(base, patch) {
|
|
181
310
|
if (patch === void 0) return base;
|
|
182
|
-
if (!isRecord
|
|
311
|
+
if (!isRecord(base) || !isRecord(patch)) return patch;
|
|
183
312
|
const merged = { ...base };
|
|
184
313
|
for (const [key, value] of Object.entries(patch)) merged[key] = mergeValue(base[key], value);
|
|
185
314
|
return merged;
|
|
186
315
|
}
|
|
187
316
|
function sameValue(left, right) {
|
|
188
|
-
if (isRecord
|
|
317
|
+
if (isRecord(left) && isRecord(right)) return [.../* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])].every((key) => sameValue(left[key], right[key]));
|
|
189
318
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
190
319
|
}
|
|
191
320
|
function toSource(value) {
|
|
192
321
|
if (Array.isArray(value)) return `[${value.map(toSource).join(", ")}]`;
|
|
193
|
-
if (isRecord
|
|
322
|
+
if (isRecord(value)) {
|
|
194
323
|
const entries = Object.entries(value).map(([key, child]) => `${/^[A-Z_$][\w$]*$/iu.test(key) ? key : JSON.stringify(key)}: ${toSource(child)}`);
|
|
195
324
|
return entries.length ? `{ ${entries.join(", ")} }` : "{}";
|
|
196
325
|
}
|
|
@@ -205,7 +334,7 @@ function nextValue(id, status, project, options) {
|
|
|
205
334
|
if (current?.kind === "expression") return "expression";
|
|
206
335
|
const literal = current?.value;
|
|
207
336
|
if (!options) return status.features.find((item) => item.id === id).enabled === "on" ? void 0 : { value: enabledValues[id] ?? true };
|
|
208
|
-
const merged = mergeValue(isRecord
|
|
337
|
+
const merged = mergeValue(isRecord(literal) ? literal : {}, options);
|
|
209
338
|
return sameValue(literal, merged) ? void 0 : { value: merged };
|
|
210
339
|
}
|
|
211
340
|
/** Plans `vitehub add` without writing anything. Throws `SetupFailure` when the change needs input or is not possible. */
|
|
@@ -226,7 +355,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
226
355
|
for (const id of args.features) {
|
|
227
356
|
const support = featureSupport(id, host);
|
|
228
357
|
const current = project.config?.ok ? project.config.site.keys[id] : void 0;
|
|
229
|
-
const driver = args.options[id]?.driver ?? (current?.kind === "literal" && isRecord
|
|
358
|
+
const driver = args.options[id]?.driver ?? (current?.kind === "literal" && isRecord(current.value) ? current.value.driver : void 0);
|
|
230
359
|
if (id === "email" && driver === "cloudflare" && host !== "cloudflare") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
231
360
|
detail: "The cloudflare driver requires Cloudflare. Choose email.driver=resend, or email.driver=log to print each message and send nothing.",
|
|
232
361
|
feature: id,
|
|
@@ -265,9 +394,9 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
265
394
|
const support = featureSupport(id, host);
|
|
266
395
|
const current = project.config?.ok ? project.config.site.keys[id] : void 0;
|
|
267
396
|
const value = valueFor(id);
|
|
268
|
-
if (id === "observability" && isRecord
|
|
397
|
+
if (id === "observability" && isRecord(value) && value.papercuts) {
|
|
269
398
|
const agent = valueFor("agent");
|
|
270
|
-
if (host === "netlify" || isRecord
|
|
399
|
+
if (host === "netlify" || isRecord(agent) && agent.runtime === "deno") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
271
400
|
detail: "observability.papercuts requires Nitro-hosted Agents. Netlify and the Agent Deno runtime are not supported.",
|
|
272
401
|
feature: id,
|
|
273
402
|
host
|
|
@@ -275,14 +404,14 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
275
404
|
requireFeature("agent");
|
|
276
405
|
requireFeature("console");
|
|
277
406
|
}
|
|
278
|
-
if (id === "observability" && isRecord
|
|
407
|
+
if (id === "observability" && isRecord(value) && value.posthog) requireFeature("env");
|
|
279
408
|
if (id === "realtime" && args.name !== void 0) requireFeature("workspace");
|
|
280
|
-
if (id === "agent" && host === "deno" && isRecord
|
|
409
|
+
if (id === "agent" && host === "deno" && isRecord(value) && value.runtime === "deno") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
281
410
|
detail: "The Deno host cannot deploy the Agent Deno runtime outside its Nitro entrypoint. Use the host's Nitro runtime instead.",
|
|
282
411
|
feature: id,
|
|
283
412
|
host
|
|
284
413
|
}), setupExitCodes.conflict);
|
|
285
|
-
if (id === "realtime" && isRecord
|
|
414
|
+
if (id === "realtime" && isRecord(value) && value.driver !== void 0) {
|
|
286
415
|
const choices = host === "cloudflare" ? ["cloudflare", "auto"] : host === "node" ? [
|
|
287
416
|
"auto",
|
|
288
417
|
"postgres",
|
|
@@ -295,7 +424,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
295
424
|
host
|
|
296
425
|
}), setupExitCodes.conflict);
|
|
297
426
|
}
|
|
298
|
-
if (id === "cache" && isRecord
|
|
427
|
+
if (id === "cache" && isRecord(value) && value.driver !== void 0) {
|
|
299
428
|
const nativeDriver = {
|
|
300
429
|
cloudflare: "cloudflare",
|
|
301
430
|
deno: "deno-kv",
|
|
@@ -309,13 +438,13 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
309
438
|
host
|
|
310
439
|
}), setupExitCodes.conflict);
|
|
311
440
|
}
|
|
312
|
-
const invocations = id === "agent" && isRecord
|
|
441
|
+
const invocations = id === "agent" && isRecord(value) ? value.invocations : void 0;
|
|
313
442
|
if (host === "netlify" && invocations !== void 0 && invocations !== false) throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
314
443
|
detail: "agent.invocations requires Nitro-hosted Agents. Set invocations on each Agent Definition instead, or use agent.invocations=false.",
|
|
315
444
|
feature: id,
|
|
316
445
|
host
|
|
317
446
|
}), setupExitCodes.conflict);
|
|
318
|
-
if (invocations === "database" || isRecord
|
|
447
|
+
if (invocations === "database" || isRecord(invocations) && invocations.store === "database") requireFeature("database");
|
|
319
448
|
const storageSelected = id === "workflow" && host !== "netlify" && selectsProvider(id, value, host);
|
|
320
449
|
if (support.level === "explicit" && !storageSelected) {
|
|
321
450
|
const field = missingProviderOption(project, support.option, value);
|
|
@@ -326,25 +455,29 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
326
455
|
...choices ? { choices: choices.values } : {}
|
|
327
456
|
});
|
|
328
457
|
if (choices) setPath(defaults[id] ??= {}, field.split(".").slice(1), choices.values[0]);
|
|
329
|
-
else
|
|
458
|
+
else {
|
|
459
|
+
const example = optionExamples[field];
|
|
460
|
+
inputFixes.push(`${example ? `Pass ${example.map((option) => `\`--option ${option}\``).join(" ")}, or set \`${field}\` in the config.` : `Set \`${field}\` with --option or in the config.`} ${support.detail}`);
|
|
461
|
+
rerunnable = false;
|
|
462
|
+
}
|
|
330
463
|
}
|
|
331
464
|
}
|
|
332
465
|
for (const [field, choice] of Object.entries(optionChoices)) {
|
|
333
466
|
if (!choice?.requires || !field.startsWith(`${id}.`)) continue;
|
|
334
467
|
const key = field.slice(id.length + 1);
|
|
335
|
-
const selected = (isRecord
|
|
468
|
+
const selected = (isRecord(value) ? value[key] : void 0) ?? defaults[id]?.[key];
|
|
336
469
|
if (typeof selected !== "string" || !choice.values.includes(selected)) continue;
|
|
337
470
|
requireFeature(choice.requires);
|
|
338
471
|
}
|
|
339
|
-
if (id === "schedule" && host === "node" && current?.kind !== "expression" && !(isRecord
|
|
340
|
-
if (isRecord
|
|
472
|
+
if (id === "schedule" && host === "node" && current?.kind !== "expression" && !(isRecord(value) && value.providerOutput === false)) {
|
|
473
|
+
if (isRecord(value) && (value.providerOutput === "nitro" || value.providerOutput === "standalone")) {
|
|
341
474
|
missing.push({
|
|
342
475
|
choices: ["auto"],
|
|
343
476
|
field: "schedule.providerOutput"
|
|
344
477
|
});
|
|
345
478
|
setPath(defaults.schedule ??= {}, ["providerOutput"], "auto");
|
|
346
479
|
}
|
|
347
|
-
if (isRecord
|
|
480
|
+
if (isRecord(value) && value.runtime !== void 0 && (!isRecord(value.runtime) || value.runtime.driver !== "process")) {
|
|
348
481
|
missing.push({
|
|
349
482
|
choices: ["process"],
|
|
350
483
|
field: "schedule.runtime.driver"
|
|
@@ -356,8 +489,8 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
356
489
|
const enabledAfter = (id) => inputFeatures.includes(id) || status.features.find((item) => item.id === id)?.enabled === "on";
|
|
357
490
|
const agent = valueFor("agent");
|
|
358
491
|
const observabilityValue = valueFor("observability");
|
|
359
|
-
const telemetry = isRecord
|
|
360
|
-
if (inputFeatures.some((id) => id === "agent" || id === "observability") && enabledAfter("observability") && telemetry && enabledAfter("agent") && (host === "netlify" || isRecord
|
|
492
|
+
const telemetry = isRecord(observabilityValue) && typeof observabilityValue.service === "string";
|
|
493
|
+
if (inputFeatures.some((id) => id === "agent" || id === "observability") && enabledAfter("observability") && telemetry && enabledAfter("agent") && (host === "netlify" || isRecord(agent) && agent.runtime === "deno")) throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
361
494
|
detail: "Observability requires Nitro-hosted Agents. Netlify and the Agent Deno runtime are not supported.",
|
|
362
495
|
feature: "observability",
|
|
363
496
|
host
|
|
@@ -366,7 +499,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
366
499
|
const site = project.config?.ok ? project.config.site : void 0;
|
|
367
500
|
if (inputFeatures.includes("i18n") && site?.keys.i18n?.kind !== "expression") {
|
|
368
501
|
const i18n = valueFor("i18n");
|
|
369
|
-
const problem = i18nLocaleListProblem(isRecord
|
|
502
|
+
const problem = i18nLocaleListProblem(isRecord(i18n) ? i18n.locales : void 0);
|
|
370
503
|
if (problem) {
|
|
371
504
|
missing.push({ field: "i18n.locales" });
|
|
372
505
|
inputFixes.push(`${problem} Pass a nonempty JSON array, such as \`--option 'i18n.locales=["en","es"]'\`.`);
|
|
@@ -382,15 +515,15 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
382
515
|
const selectedAuth = args.features.includes("auth") && (!configuredAuth || configuredAuth.kind === "expression" || configuredAuth.value === false);
|
|
383
516
|
const authEnabled = !args.options.auth && (selectedAuth || configuredAuth?.kind === "literal" && configuredAuth.value === true || discoveredAuth);
|
|
384
517
|
const mcp = valueFor("mcp");
|
|
385
|
-
const mode = isRecord
|
|
386
|
-
const publicRoute = isRecord
|
|
518
|
+
const mode = isRecord(mcp) && Object.hasOwn(mcp, "auth") ? mcp.auth : void 0;
|
|
519
|
+
const publicRoute = isRecord(mcp) && typeof mcp.publicRoute === "string" ? mcp.publicRoute : void 0;
|
|
387
520
|
if ((typeof mode === "boolean" || mode === "optional") && mcpPublicRouteNeedsSignedAuth(publicRoute, mode)) {
|
|
388
521
|
missing.push({ field: "mcp.publicRoute" });
|
|
389
522
|
inputFixes.push("Remove `mcp.publicRoute`, or enable Auth, set `mcp.auth=true`, and add `mcpOAuth()` to the Auth Definition.");
|
|
390
523
|
rerunnable = false;
|
|
391
524
|
} else if (!authEnabled && authStatus?.enabled === "unknown" && (mode === void 0 || mode === true || mode === "optional")) {
|
|
392
525
|
const file = project.configFile ?? "vite.config.ts";
|
|
393
|
-
const snippet = `mcp: ${toSource(isRecord
|
|
526
|
+
const snippet = `mcp: ${toSource(isRecord(mcp) ? mcp : true)},`;
|
|
394
527
|
const fix = `Confirm Auth is enabled in the app. ${mcpOAuthSetup}. Add this key to the vitehub() options by hand:\n${snippet}`;
|
|
395
528
|
throw setupFailure(cliErrorDiagnostics.SETUP_CONFIG_MANUAL({
|
|
396
529
|
file,
|
|
@@ -417,15 +550,22 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
417
550
|
rerunnable = false;
|
|
418
551
|
}
|
|
419
552
|
}
|
|
553
|
+
if (inputFeatures.includes("rateLimit") && keep.includes("kv") && !requires.includes("kv") && site?.keys.rateLimit?.kind !== "expression" && rateLimitUsesVercelKV(host, valueFor("rateLimit"))) {
|
|
554
|
+
missing.push({ field: "kv" });
|
|
555
|
+
inputFixes.push("Add `kv` to the command for shared counts, or pass `--option rateLimit.driver=memory` for counts in one function instance.");
|
|
556
|
+
rerunnable = false;
|
|
557
|
+
}
|
|
420
558
|
if (missing.length) {
|
|
421
559
|
const fields = missing.map((item) => `\`${item.field}\``).join(", ");
|
|
422
560
|
const fix = inputFixes.length ? inputFixes.join(" ") : void 0;
|
|
561
|
+
const command = rerunnable ? rerun(args, defaults, requires) : void 0;
|
|
423
562
|
throw setupFailure(cliErrorDiagnostics.SETUP_INPUT_NEEDED({
|
|
424
563
|
fix,
|
|
425
|
-
message: `[vitehub] Set ${fields} to add ${args.features.join(", ")} on the ${host} host
|
|
564
|
+
message: `[vitehub] Set ${fields} to add ${args.features.join(", ")} on the ${host} host.`,
|
|
565
|
+
rerun: command
|
|
426
566
|
}), setupExitCodes.inputNeeded, {
|
|
427
567
|
missing,
|
|
428
|
-
...
|
|
568
|
+
...command ? { rerun: command } : {}
|
|
429
569
|
});
|
|
430
570
|
}
|
|
431
571
|
const edits = [];
|
|
@@ -520,7 +660,9 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
520
660
|
...inputFeatures,
|
|
521
661
|
...enabled.has("console") ? ["console"] : []
|
|
522
662
|
])];
|
|
523
|
-
const
|
|
663
|
+
const plannedKV = edits.find((edit) => edit.key === "kv");
|
|
664
|
+
const packageValue = (id) => id === "kv" && plannedKV?.op === "set" ? plannedKV.value : valueFor(id);
|
|
665
|
+
const packages = packageFeatures.flatMap((id) => setupFeaturePackages(id, packageValue, host, [...enabled]));
|
|
524
666
|
const install = {
|
|
525
667
|
dev: [...new Set(packageFeatures.flatMap((id) => features[id].devPackages))].filter((name) => !project.declared(name, true)),
|
|
526
668
|
prod: [...new Set(packages)].filter((name) => !project.declared(name, false))
|
|
@@ -528,6 +670,14 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
528
670
|
install.prod = installSpecifiers(install.prod);
|
|
529
671
|
install.dev = installSpecifiers(install.dev);
|
|
530
672
|
const command = installCommand(project.packageManager, install.prod, install.dev);
|
|
673
|
+
const workspace = command ? planPnpmBuilds(project, declinedBuilds(project, host, [...enabled])) : void 0;
|
|
674
|
+
if (workspace) changes.unshift({
|
|
675
|
+
after: workspace.after,
|
|
676
|
+
diff: setupDiff(workspace.path, workspace.before ?? "", workspace.after),
|
|
677
|
+
kind: workspace.before === void 0 ? "create" : "patch",
|
|
678
|
+
path: workspace.path,
|
|
679
|
+
...workspace.before === void 0 ? {} : { before: workspace.before }
|
|
680
|
+
});
|
|
531
681
|
const restartRequired = addsDiscovery && !configFile;
|
|
532
682
|
const nextSteps = restartRequired ? ["Restart the dev server to load the new feature configuration."] : [];
|
|
533
683
|
if (needsMcpOAuth) {
|
|
@@ -561,42 +711,42 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
561
711
|
if (args.name !== void 0 && args.features.includes("realtime")) nextSteps.push(`${join(serverDir, "realtime", `${args.name}.ts`)} stores documents in the Workspace "${args.name}". Add a Workspace Definition in ${join(serverDir, "workspaces", `${args.name}.ts`)}.`);
|
|
562
712
|
for (const id of args.features) nextSteps.push(`${features[id].title}: https://vitehub.dev${features[id].docs}`);
|
|
563
713
|
nextSteps.push("Run `vitehub status` to check the result.");
|
|
714
|
+
const plan = {
|
|
715
|
+
changes,
|
|
716
|
+
features: addedFeatures,
|
|
717
|
+
host: status.host,
|
|
718
|
+
implied,
|
|
719
|
+
install: {
|
|
720
|
+
devPackages: install.dev,
|
|
721
|
+
packages: install.prod,
|
|
722
|
+
...command ? { command } : {}
|
|
723
|
+
},
|
|
724
|
+
nextSteps,
|
|
725
|
+
root: project.root,
|
|
726
|
+
status: changes.length || command && args.install ? "planned" : "unchanged"
|
|
727
|
+
};
|
|
564
728
|
return {
|
|
729
|
+
enabled: [...enabled],
|
|
565
730
|
files,
|
|
566
731
|
install,
|
|
567
|
-
plan
|
|
568
|
-
changes,
|
|
569
|
-
features: addedFeatures,
|
|
570
|
-
host: status.host,
|
|
571
|
-
implied,
|
|
572
|
-
install: {
|
|
573
|
-
devPackages: install.dev,
|
|
574
|
-
packages: install.prod,
|
|
575
|
-
...command ? { command } : {}
|
|
576
|
-
},
|
|
577
|
-
nextSteps,
|
|
578
|
-
root: project.root,
|
|
579
|
-
status: changes.length || command && args.install ? "planned" : "unchanged"
|
|
580
|
-
},
|
|
732
|
+
plan,
|
|
581
733
|
restartRequired,
|
|
582
|
-
...configFile ? { configFile } : {}
|
|
734
|
+
...configFile ? { configFile } : {},
|
|
735
|
+
...workspace ? { workspace } : {}
|
|
583
736
|
};
|
|
584
737
|
}
|
|
585
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Applies a `vitehub add` plan: writes the pnpm build policy, installs the packages, writes the starter Definitions,
|
|
740
|
+
* and writes the config last.
|
|
741
|
+
*/
|
|
586
742
|
async function applySetupAdd(project, planned, args, context) {
|
|
587
743
|
const { dev, prod } = planned.install;
|
|
588
|
-
if (
|
|
589
|
-
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
env: context.env,
|
|
594
|
-
stdout: "stderr"
|
|
744
|
+
if (planned.workspace) await writePnpmBuilds(planned.workspace);
|
|
745
|
+
if (args.install) {
|
|
746
|
+
for (const [packages, isDev] of [[prod, false], [dev, true]]) if (packages.length) await installPackages(context, project.packageManager, packages, isDev, {
|
|
747
|
+
filesWritten: false,
|
|
748
|
+
root: project.root
|
|
595
749
|
});
|
|
596
|
-
if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
|
|
597
|
-
command: formatInstallCommand(project.packageManager, commandArgs),
|
|
598
|
-
exitCode: result.exitCode ?? result.signal
|
|
599
|
-
}), setupExitCodes.error);
|
|
600
750
|
}
|
|
601
751
|
if (planned.configFile && await readFile(join(project.root, planned.configFile.path), "utf8") !== planned.configFile.before) throw setupFailure(cliErrorDiagnostics.SETUP_STALE_PLAN({ file: planned.configFile.path }), setupExitCodes.stalePlan);
|
|
602
752
|
for (const file of planned.files) {
|
|
@@ -695,6 +845,76 @@ function setupCatalog() {
|
|
|
695
845
|
schemaVersion: 1
|
|
696
846
|
};
|
|
697
847
|
}
|
|
848
|
+
// src/setup/init-wizard.ts
|
|
849
|
+
function cancelled() {
|
|
850
|
+
return setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] The setup was cancelled. Nothing was written." }), setupExitCodes.error);
|
|
851
|
+
}
|
|
852
|
+
/** The wizard on the terminal, with `@clack/prompts`. It loads only when `vitehub init` runs interactively. */
|
|
853
|
+
async function terminalPrompts() {
|
|
854
|
+
const clack = await import("./dist-CEIUyD15.js");
|
|
855
|
+
const output = process.stderr;
|
|
856
|
+
const answer = (value) => {
|
|
857
|
+
if (clack.isCancel(value) || typeof value === "symbol") throw cancelled();
|
|
858
|
+
return value;
|
|
859
|
+
};
|
|
860
|
+
const pick = (options, value) => {
|
|
861
|
+
const found = options.find((option) => option.value === value);
|
|
862
|
+
if (!found) throw cancelled();
|
|
863
|
+
return found.value;
|
|
864
|
+
};
|
|
865
|
+
return {
|
|
866
|
+
confirm: async (options) => answer(await clack.confirm({
|
|
867
|
+
...options,
|
|
868
|
+
output
|
|
869
|
+
})),
|
|
870
|
+
error: (message) => clack.log.error(message, { output }),
|
|
871
|
+
multiselect: async ({ message, options }) => answer(await clack.multiselect({
|
|
872
|
+
message,
|
|
873
|
+
options: [...options],
|
|
874
|
+
output,
|
|
875
|
+
required: false
|
|
876
|
+
})).map((value) => pick(options, value)),
|
|
877
|
+
select: async ({ initialValue, message, options }) => pick(options, answer(await clack.select({
|
|
878
|
+
message,
|
|
879
|
+
options: [...options],
|
|
880
|
+
output,
|
|
881
|
+
...initialValue ? { initialValue } : {}
|
|
882
|
+
}))),
|
|
883
|
+
text: async ({ defaultValue, message }) => answer(await clack.text({
|
|
884
|
+
defaultValue,
|
|
885
|
+
message,
|
|
886
|
+
output,
|
|
887
|
+
placeholder: defaultValue
|
|
888
|
+
})) || defaultValue
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
/** The features that a picker offers on `host`: every feature that the host supports and that is not always on. */
|
|
892
|
+
function pickableFeatures(host) {
|
|
893
|
+
return featureIds.filter((id) => !features[id].enabledByDefault && featureSupport(id, host).level !== "unsupported").map((id) => ({
|
|
894
|
+
hint: features[id].summary.replaceAll("`", ""),
|
|
895
|
+
label: features[id].title,
|
|
896
|
+
value: id
|
|
897
|
+
}));
|
|
898
|
+
}
|
|
899
|
+
async function askOption(prompts, item) {
|
|
900
|
+
if (item.choices?.length) {
|
|
901
|
+
const options = item.choices.map((choice) => typeof choice === "string" ? {
|
|
902
|
+
label: choice,
|
|
903
|
+
value: choice
|
|
904
|
+
} : {
|
|
905
|
+
label: choice.name ?? choice.id,
|
|
906
|
+
value: choice.id
|
|
907
|
+
});
|
|
908
|
+
return await prompts.select({
|
|
909
|
+
message: `Choose ${item.field}`,
|
|
910
|
+
options
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
if (item.field === "i18n.locales") return await prompts.text({
|
|
914
|
+
defaultValue: "",
|
|
915
|
+
message: "Enter i18n.locales as a JSON array, such as [\"en\",\"es\"]"
|
|
916
|
+
});
|
|
917
|
+
}
|
|
698
918
|
// src/setup/stack.ts
|
|
699
919
|
function replayOption(id, keys, value) {
|
|
700
920
|
if (keys.some((key) => !key || /[.=\0]/u.test(key) || [
|
|
@@ -726,7 +946,7 @@ function containsCredentials(value) {
|
|
|
726
946
|
return !!(url && (url.username || url.password || url.search || url.hash));
|
|
727
947
|
}
|
|
728
948
|
if (Array.isArray(value)) return value.some(containsCredentials);
|
|
729
|
-
return isRecord
|
|
949
|
+
return isRecord(value) && Object.entries(value).some(([key, child]) => credentialKey(key) || containsCredentials(child));
|
|
730
950
|
}
|
|
731
951
|
function setupStackLabels(stack) {
|
|
732
952
|
return {
|
|
@@ -748,7 +968,7 @@ async function deriveSetupStack(project, status, validate) {
|
|
|
748
968
|
});
|
|
749
969
|
return;
|
|
750
970
|
}
|
|
751
|
-
if (isRecord
|
|
971
|
+
if (isRecord(value) && Object.keys(value).length) {
|
|
752
972
|
for (const [key, child] of Object.entries(value)) collect(id, [...keys, key], child);
|
|
753
973
|
return;
|
|
754
974
|
}
|
|
@@ -800,7 +1020,7 @@ async function deriveSetupStack(project, status, validate) {
|
|
|
800
1020
|
continue;
|
|
801
1021
|
}
|
|
802
1022
|
const value = setting?.value;
|
|
803
|
-
if (features[id].enabledByDefault && (value === void 0 || value === true || isRecord
|
|
1023
|
+
if (features[id].enabledByDefault && (value === void 0 || value === true || isRecord(value) && !Object.keys(value).length)) continue;
|
|
804
1024
|
selected.push(id);
|
|
805
1025
|
if (value !== void 0 && value !== true) collect(id, [], value);
|
|
806
1026
|
}
|
|
@@ -909,17 +1129,9 @@ const initPackages = {
|
|
|
909
1129
|
const nuxtNitroRange = "^3.0.261103-rc";
|
|
910
1130
|
const nuxtNitroPackage = `nitro@${nuxtNitroRange}`;
|
|
911
1131
|
const nuxt47ViteHub = "vite-hub@>=0.5.1 <1";
|
|
912
|
-
/**
|
|
913
|
-
* Nuxt 4 installs esbuild, and pnpm 11 and later fail the install while the esbuild build script waits for
|
|
914
|
-
* approval. esbuild runs without that script, so a new Nuxt 4.7 app declines it.
|
|
915
|
-
*/
|
|
916
|
-
const nuxtPnpmWorkspace = "allowBuilds:\n esbuild: false\n";
|
|
917
1132
|
/** The pinned Nuxt CLI that creates a new Nuxt app. */
|
|
918
1133
|
const nuxiPackage = "nuxi@3.37.0";
|
|
919
1134
|
const nuxtTemplate = "gh:nuxt/starter#d4367031fe43d93d4e2a339f73b519ec35e78b38";
|
|
920
|
-
function isRecord(value) {
|
|
921
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
922
|
-
}
|
|
923
1135
|
function invalid$2(message) {
|
|
924
1136
|
return cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] ${message} Usage: ${usage$2}` });
|
|
925
1137
|
}
|
|
@@ -1001,9 +1213,18 @@ function rerunInit(args, parts) {
|
|
|
1001
1213
|
function packageNameOf(root) {
|
|
1002
1214
|
return basename(root).trim().toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "") || "vitehub-app";
|
|
1003
1215
|
}
|
|
1216
|
+
function appGitignore(host) {
|
|
1217
|
+
return [
|
|
1218
|
+
"node_modules",
|
|
1219
|
+
".output",
|
|
1220
|
+
...ignoredFolders(host),
|
|
1221
|
+
".env*",
|
|
1222
|
+
"!.env.example"
|
|
1223
|
+
];
|
|
1224
|
+
}
|
|
1004
1225
|
function viteAppFiles(name, host) {
|
|
1005
1226
|
return {
|
|
1006
|
-
".gitignore": "
|
|
1227
|
+
".gitignore": [...appGitignore(host), ""].join("\n"),
|
|
1007
1228
|
"package.json": `${JSON.stringify({
|
|
1008
1229
|
name,
|
|
1009
1230
|
private: true,
|
|
@@ -1014,7 +1235,7 @@ function viteAppFiles(name, host) {
|
|
|
1014
1235
|
start: "node .output/server/index.mjs"
|
|
1015
1236
|
}
|
|
1016
1237
|
}, null, 2)}\n`,
|
|
1017
|
-
"server/api/health.get.ts": "import { defineEventHandler } from \"h3\"\n\nexport default defineEventHandler(() => ({ ok: true }))\n",
|
|
1238
|
+
"server/api/health.get.ts": "import { defineEventHandler } from \"nitro/h3\"\n\nexport default defineEventHandler(() => ({ ok: true }))\n",
|
|
1018
1239
|
"tsconfig.json": `{
|
|
1019
1240
|
"extends": ["vite-hub/tsconfig"],
|
|
1020
1241
|
"compilerOptions": {
|
|
@@ -1062,12 +1283,18 @@ function dlx(packageManager, spec, args) {
|
|
|
1062
1283
|
function runScript(packageManager, script) {
|
|
1063
1284
|
return packageManager === "npm" || packageManager === "bun" ? `${packageManager} run ${script}` : `${packageManager} ${script}`;
|
|
1064
1285
|
}
|
|
1286
|
+
function hasErrorCode(error, code) {
|
|
1287
|
+
return error instanceof Error && "code" in error && error.code === code;
|
|
1288
|
+
}
|
|
1065
1289
|
async function readDir(root, env) {
|
|
1066
|
-
|
|
1290
|
+
const entries = await readdir(root).catch((error) => {
|
|
1291
|
+
if (!hasErrorCode(error, "ENOENT")) throw error;
|
|
1292
|
+
});
|
|
1293
|
+
if (!entries) return {
|
|
1067
1294
|
exists: false,
|
|
1068
1295
|
kind: "create"
|
|
1069
1296
|
};
|
|
1070
|
-
if (
|
|
1297
|
+
if (entries.every((entry) => entry === ".git")) return {
|
|
1071
1298
|
exists: true,
|
|
1072
1299
|
kind: "create"
|
|
1073
1300
|
};
|
|
@@ -1078,6 +1305,11 @@ async function readDir(root, env) {
|
|
|
1078
1305
|
project
|
|
1079
1306
|
};
|
|
1080
1307
|
}
|
|
1308
|
+
function lockedHost(project, env) {
|
|
1309
|
+
if (!project.config?.ok) return;
|
|
1310
|
+
const status = setupStatus(project, env);
|
|
1311
|
+
if (status.features.some((feature) => feature.id !== "env" && feature.enabled !== "off")) return status.host.name;
|
|
1312
|
+
}
|
|
1081
1313
|
function changeOf(path, before, after) {
|
|
1082
1314
|
return before === void 0 ? {
|
|
1083
1315
|
after,
|
|
@@ -1165,8 +1397,8 @@ async function planInit(args, root, state, context) {
|
|
|
1165
1397
|
for (const [path, after] of Object.entries(files)) base.set(path, { after });
|
|
1166
1398
|
configFile = framework === "vite" ? "vite.config.ts" : "nuxt.config.ts";
|
|
1167
1399
|
} else {
|
|
1168
|
-
const
|
|
1169
|
-
if (
|
|
1400
|
+
const currentHost = lockedHost(state.project, context.env);
|
|
1401
|
+
if (currentHost && currentHost !== args.host) throw setupFailure(cliErrorDiagnostics.SETUP_INIT_HOST_MIGRATION({ host: args.host }), setupExitCodes.conflict);
|
|
1170
1402
|
const config = adoptConfig(state.project, args.host, framework);
|
|
1171
1403
|
base.set(config.file, config);
|
|
1172
1404
|
configFile = config.file;
|
|
@@ -1230,17 +1462,16 @@ async function planInit(args, root, state, context) {
|
|
|
1230
1462
|
const gitignore = await readOptional(join(root, ".gitignore"));
|
|
1231
1463
|
base.set(".gitignore", {
|
|
1232
1464
|
...gitignore === void 0 ? {} : { before: gitignore },
|
|
1233
|
-
after: gitignore
|
|
1465
|
+
after: gitignoreWith(gitignore ?? "", appGitignore(args.host)) ?? gitignore ?? ""
|
|
1234
1466
|
});
|
|
1235
1467
|
}
|
|
1236
|
-
const workspaceFile = allowsNuxt4 && packageManager === "pnpm" ? pnpmWorkspaceFile(root) : void 0;
|
|
1237
|
-
if (state.kind === "create" && allowsNuxt4 && packageManager === "pnpm" && !workspaceFile) base.set("pnpm-workspace.yaml", { after: nuxtPnpmWorkspace });
|
|
1238
1468
|
const scaffolded = state.kind === "create" && framework === "nuxt";
|
|
1239
1469
|
const writes = [...base.entries()].filter(([path]) => !scaffolded || !Object.hasOwn(nuxtAppFiles(name, args.host), path)).sort(([left], [right]) => Number(left === configFile) - Number(right === configFile)).filter(([, file]) => file.before !== file.after).map(([path, file]) => ({
|
|
1240
1470
|
path,
|
|
1241
1471
|
...file
|
|
1242
1472
|
}));
|
|
1243
1473
|
const command = installCommand(packageManager, install.prod, install.dev);
|
|
1474
|
+
const workspace = command ? planPnpmBuilds(planned, declinedBuilds(planned, args.host, added.enabled)) : void 0;
|
|
1244
1475
|
const scaffold = scaffolded ? dlx(packageManager, nuxiPackage, [
|
|
1245
1476
|
"init",
|
|
1246
1477
|
basename(root),
|
|
@@ -1270,7 +1501,7 @@ async function planInit(args, root, state, context) {
|
|
|
1270
1501
|
return {
|
|
1271
1502
|
install,
|
|
1272
1503
|
plan: {
|
|
1273
|
-
changes: writes.map((write) => changeOf(write.path, write.before, write.after)),
|
|
1504
|
+
changes: [...workspace ? [changeOf(workspace.path, workspace.before, workspace.after)] : [], ...writes.map((write) => changeOf(write.path, write.before, write.after))],
|
|
1274
1505
|
features: added.plan.features,
|
|
1275
1506
|
framework,
|
|
1276
1507
|
host: args.host,
|
|
@@ -1285,13 +1516,13 @@ async function planInit(args, root, state, context) {
|
|
|
1285
1516
|
packageManager,
|
|
1286
1517
|
root,
|
|
1287
1518
|
...scaffold ? { scaffold: { command: [scaffold[0], ...scaffold[1]].join(" ") } } : {},
|
|
1288
|
-
status: writes.length || scaffold || command && args.install ? "planned" : "unchanged"
|
|
1519
|
+
status: writes.length || workspace || scaffold || command && args.install ? "planned" : "unchanged"
|
|
1289
1520
|
},
|
|
1290
1521
|
rerun: rerunInit(args, parts()),
|
|
1291
1522
|
stackProject,
|
|
1292
1523
|
writes,
|
|
1293
1524
|
...scaffold ? { scaffold } : {},
|
|
1294
|
-
...
|
|
1525
|
+
...workspace ? { workspace } : {}
|
|
1295
1526
|
};
|
|
1296
1527
|
}
|
|
1297
1528
|
function setupStack(project, status) {
|
|
@@ -1311,22 +1542,12 @@ async function applyInit(planned, install, context, scaffolded = false) {
|
|
|
1311
1542
|
const { plan } = planned;
|
|
1312
1543
|
const runInstall = async () => {
|
|
1313
1544
|
if (!install) return;
|
|
1314
|
-
for (const [packages, dev] of [[planned.install.prod, false], [planned.install.dev, true]]) {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
cwd: plan.root,
|
|
1319
|
-
env: context.env,
|
|
1320
|
-
stdout: "stderr"
|
|
1321
|
-
});
|
|
1322
|
-
if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
|
|
1323
|
-
command: formatInstallCommand(plan.packageManager, commandArgs),
|
|
1324
|
-
exitCode: result.exitCode ?? result.signal,
|
|
1325
|
-
filesWritten: scaffolded || plan.mode === "create",
|
|
1326
|
-
workspaceFile: planned.workspaceFile
|
|
1327
|
-
}), setupExitCodes.error);
|
|
1328
|
-
}
|
|
1545
|
+
for (const [packages, dev] of [[planned.install.prod, false], [planned.install.dev, true]]) if (packages.length) await installPackages(context, plan.packageManager, packages, dev, {
|
|
1546
|
+
filesWritten: scaffolded || plan.mode === "create",
|
|
1547
|
+
root: plan.root
|
|
1548
|
+
});
|
|
1329
1549
|
};
|
|
1550
|
+
if (planned.workspace) await writePnpmBuilds(planned.workspace);
|
|
1330
1551
|
if (plan.mode === "adopt") await runInstall();
|
|
1331
1552
|
for (const write of planned.writes) {
|
|
1332
1553
|
const file = join(plan.root, write.path);
|
|
@@ -1380,32 +1601,110 @@ async function checkNuxtVersion(root, scaffolded = false) {
|
|
|
1380
1601
|
}
|
|
1381
1602
|
return { needsNitro: nitroDeclarations.length === 0 };
|
|
1382
1603
|
}
|
|
1383
|
-
function
|
|
1384
|
-
|
|
1604
|
+
async function planWithAnswers(args, root, state, context, prompts, canReviseFeatures) {
|
|
1605
|
+
const initialOptions = [...args.options];
|
|
1606
|
+
const asked = /* @__PURE__ */ new Set();
|
|
1607
|
+
for (;;) try {
|
|
1608
|
+
return await planInit(args, root, state, context);
|
|
1609
|
+
} catch (error) {
|
|
1610
|
+
if (!prompts || !isSetupFailure(error) || error.exitCode !== setupExitCodes.inputNeeded) throw error;
|
|
1611
|
+
const missing = error.details.missing ?? [];
|
|
1612
|
+
let answered = false;
|
|
1613
|
+
for (const item of missing) {
|
|
1614
|
+
if (asked.has(item.field)) continue;
|
|
1615
|
+
asked.add(item.field);
|
|
1616
|
+
if (item.field === "auth") {
|
|
1617
|
+
if (await prompts.confirm({
|
|
1618
|
+
initialValue: true,
|
|
1619
|
+
message: "Enable Auth for signed MCP requests?"
|
|
1620
|
+
})) {
|
|
1621
|
+
args.features = [...args.features, "auth"];
|
|
1622
|
+
answered = true;
|
|
1623
|
+
}
|
|
1624
|
+
continue;
|
|
1625
|
+
}
|
|
1626
|
+
const value = await askOption(prompts, item);
|
|
1627
|
+
if (value === void 0) continue;
|
|
1628
|
+
args.options.push(`${item.field}=${value}`);
|
|
1629
|
+
answered = true;
|
|
1630
|
+
}
|
|
1631
|
+
if (answered) continue;
|
|
1632
|
+
if (!canReviseFeatures || !missing.length) throw error;
|
|
1633
|
+
prompts.error(error.message.replace(/^\[vitehub\] /u, ""));
|
|
1634
|
+
args.features = await askFeatures(prompts, args.host);
|
|
1635
|
+
const selected = /* @__PURE__ */ new Set([...args.features, ...initialOptions.map((option) => option.split(".", 1)[0])]);
|
|
1636
|
+
args.options = args.options.filter((option) => selected.has(option.split(".", 1)[0]));
|
|
1637
|
+
asked.clear();
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
async function terminalWizard() {
|
|
1641
|
+
return process.stdin.isTTY && process.stderr.isTTY ? await terminalPrompts() : void 0;
|
|
1642
|
+
}
|
|
1643
|
+
async function askDir(args, prompts, context) {
|
|
1644
|
+
for (;;) {
|
|
1645
|
+
const dir = args.dir ?? await prompts.text({
|
|
1646
|
+
defaultValue: "vitehub-app",
|
|
1647
|
+
message: "Folder of the app"
|
|
1648
|
+
});
|
|
1649
|
+
try {
|
|
1650
|
+
return {
|
|
1651
|
+
dir,
|
|
1652
|
+
state: await readDir(resolve(context.rootDir, dir), context.env)
|
|
1653
|
+
};
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
if (args.dir !== void 0) throw error;
|
|
1656
|
+
if (hasErrorCode(error, "ENOTDIR")) prompts.error(`${dir} is not a folder. Choose a folder.`);
|
|
1657
|
+
else if (isSetupFailure(error)) prompts.error(error.message.replace(/^\[vitehub\] /u, ""));
|
|
1658
|
+
else throw error;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function askFeatures(prompts, host) {
|
|
1663
|
+
return prompts.multiselect({
|
|
1664
|
+
message: "Features (space to select, enter for none)",
|
|
1665
|
+
options: pickableFeatures(host)
|
|
1666
|
+
});
|
|
1385
1667
|
}
|
|
1386
|
-
async function
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
|
|
1668
|
+
async function askInputs(args, prompts, context) {
|
|
1669
|
+
const { dir, state } = await askDir(args, prompts, context);
|
|
1670
|
+
const found = state.kind === "adopt" && state.project.framework !== "none" ? state.project.framework : void 0;
|
|
1671
|
+
const framework = args.framework ?? (found === "nuxt" || found === "vite" ? found : await prompts.select({
|
|
1672
|
+
initialValue: "vite",
|
|
1673
|
+
message: "Framework",
|
|
1674
|
+
options: [{
|
|
1675
|
+
label: "Vite",
|
|
1676
|
+
value: "vite"
|
|
1677
|
+
}, {
|
|
1678
|
+
label: "Nuxt",
|
|
1679
|
+
value: "nuxt"
|
|
1680
|
+
}]
|
|
1681
|
+
}));
|
|
1682
|
+
const currentHost = state.kind === "adopt" ? lockedHost(state.project, context.env) : void 0;
|
|
1683
|
+
const host = args.host ?? currentHost ?? await prompts.select({
|
|
1684
|
+
message: "Host",
|
|
1685
|
+
options: initHosts.map((value) => ({
|
|
1686
|
+
label: value,
|
|
1687
|
+
value
|
|
1688
|
+
}))
|
|
1390
1689
|
});
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1690
|
+
if (host === "unknown") throw setupFailure(cliErrorDiagnostics.SETUP_INIT_HOST_MIGRATION({ host }), setupExitCodes.conflict);
|
|
1691
|
+
const features = args.features ?? await askFeatures(prompts, host);
|
|
1692
|
+
return {
|
|
1693
|
+
...args,
|
|
1694
|
+
dir,
|
|
1695
|
+
features,
|
|
1696
|
+
framework,
|
|
1697
|
+
host
|
|
1698
|
+
};
|
|
1396
1699
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
features,
|
|
1406
|
-
host
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1700
|
+
function npmCreateHint(env) {
|
|
1701
|
+
return env.npm_command === "init" || env.npm_command === "create" ? " With `npm create`, put `--` before the flags: `npm create vitehub@latest -- my-app --host node --features kv --yes`." : "";
|
|
1702
|
+
}
|
|
1703
|
+
async function readInputs(args, prompts, context = {
|
|
1704
|
+
env: {},
|
|
1705
|
+
rootDir: process.cwd()
|
|
1706
|
+
}) {
|
|
1707
|
+
if (prompts) return askInputs(args, prompts, context);
|
|
1409
1708
|
const missing = [];
|
|
1410
1709
|
if (args.dir === void 0) missing.push({
|
|
1411
1710
|
field: "dir",
|
|
@@ -1427,7 +1726,7 @@ async function readInputs(args) {
|
|
|
1427
1726
|
features: args.features,
|
|
1428
1727
|
host: args.host
|
|
1429
1728
|
};
|
|
1430
|
-
const message = missing.map((item) => `${item.sentence} when running without an interactive terminal.`).join(" ")
|
|
1729
|
+
const message = `${missing.map((item) => `${item.sentence} when running without an interactive terminal.`).join(" ")}${npmCreateHint(context.env)}`;
|
|
1431
1730
|
throw setupFailure(cliErrorDiagnostics.SETUP_INPUT_NEEDED({ message: `[vitehub] ${message}` }), setupExitCodes.inputNeeded, {
|
|
1432
1731
|
missing: missing.map(({ sentence: _sentence, ...item }) => item),
|
|
1433
1732
|
rerun: rerunInit(args, {
|
|
@@ -1463,7 +1762,8 @@ function writeResult$1(plan, context) {
|
|
|
1463
1762
|
context.stdout.write(`${stackLines(plan.stack).join("\n")}\n`);
|
|
1464
1763
|
context.stdout.write(`\nNext steps:\n${plan.nextSteps.map((step) => `- ${step}`).join("\n")}\n`);
|
|
1465
1764
|
}
|
|
1466
|
-
|
|
1765
|
+
/** Runs `vitehub init`. `wizard` gives the prompts for a person at a terminal; tests pass fake prompts. */
|
|
1766
|
+
async function runInit(rawArgs, context, wizard = terminalWizard) {
|
|
1467
1767
|
let json = rawArgs.includes("--json");
|
|
1468
1768
|
try {
|
|
1469
1769
|
const parsed = readInitArgs(rawArgs);
|
|
@@ -1472,9 +1772,10 @@ async function runInit(rawArgs, context) {
|
|
|
1472
1772
|
context.stdout.write(`Usage: ${usage$2}\n\n${initCommandDefinition.description}\n`);
|
|
1473
1773
|
return setupExitCodes.done;
|
|
1474
1774
|
}
|
|
1475
|
-
const
|
|
1775
|
+
const prompts = parsed.json ? void 0 : await wizard();
|
|
1776
|
+
const args = await readInputs(parsed, prompts, context);
|
|
1476
1777
|
const root = resolve(context.rootDir, args.dir);
|
|
1477
|
-
let planned = await
|
|
1778
|
+
let planned = await planWithAnswers(args, root, await readDir(root, context.env), context, prompts, parsed.features === void 0);
|
|
1478
1779
|
const plan = {
|
|
1479
1780
|
...planned.plan,
|
|
1480
1781
|
stack: await setupStack(planned.stackProject, setupStatus(planned.stackProject, context.env))
|
|
@@ -1486,19 +1787,24 @@ async function runInit(rawArgs, context) {
|
|
|
1486
1787
|
return setupExitCodes.done;
|
|
1487
1788
|
}
|
|
1488
1789
|
if (!args.yes) {
|
|
1489
|
-
if (!
|
|
1790
|
+
if (!prompts) {
|
|
1490
1791
|
if (!args.json) writePlan$1(plan, context);
|
|
1491
1792
|
throw setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] `vitehub init` writes files and was not confirmed. Without a terminal, pass --yes." }), setupExitCodes.inputNeeded, {
|
|
1492
1793
|
data: plan,
|
|
1493
1794
|
rerun: planned.rerun
|
|
1494
1795
|
});
|
|
1495
1796
|
}
|
|
1496
|
-
writePlan$1(plan,
|
|
1497
|
-
|
|
1797
|
+
writePlan$1(plan, {
|
|
1798
|
+
...context,
|
|
1799
|
+
stdout: context.stderr
|
|
1800
|
+
});
|
|
1801
|
+
if (!await prompts.confirm({
|
|
1802
|
+
initialValue: plan.mode === "create",
|
|
1803
|
+
message: plan.mode === "create" ? "Create the app?" : "Apply these changes?"
|
|
1804
|
+
})) throw setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] The change was not confirmed. Nothing was written." }), setupExitCodes.error);
|
|
1498
1805
|
}
|
|
1499
1806
|
if (planned.scaffold) {
|
|
1500
1807
|
await scaffoldNuxt(planned, context);
|
|
1501
|
-
for (const write of planned.writes.filter((write) => write.path === "pnpm-workspace.yaml")) await writeFile(join(root, write.path), write.after);
|
|
1502
1808
|
planned = await planInit({
|
|
1503
1809
|
...args,
|
|
1504
1810
|
pm: plan.packageManager
|
|
@@ -1523,7 +1829,7 @@ async function runInit(rawArgs, context) {
|
|
|
1523
1829
|
const initCommandDefinition = {
|
|
1524
1830
|
description: "Create a ViteHub app in a folder, or set up an existing Vite or Nuxt app, with a host and features.",
|
|
1525
1831
|
name: "init",
|
|
1526
|
-
run: runInit,
|
|
1832
|
+
run: (args, context) => runInit(args, context),
|
|
1527
1833
|
usage: usage$2
|
|
1528
1834
|
};
|
|
1529
1835
|
// src/setup/remove.ts
|
|
@@ -1595,11 +1901,11 @@ function isStarter(starter, path, content) {
|
|
|
1595
1901
|
return name !== void 0 && [starter.template, ...starter.previousTemplates ?? []].some((template) => template(name) === content);
|
|
1596
1902
|
}
|
|
1597
1903
|
function optionPrerequisites(id, value, unknown) {
|
|
1598
|
-
const options = isRecord
|
|
1904
|
+
const options = isRecord(value) ? value : void 0;
|
|
1599
1905
|
if (id === "cache" && (unknown || options?.driver === "kv")) return ["kv"];
|
|
1600
1906
|
if (id === "observability") return [...unknown || options?.posthog ? ["env"] : [], ...unknown || options?.papercuts ? ["agent", "console"] : []];
|
|
1601
1907
|
const invocations = options?.invocations;
|
|
1602
|
-
if (id === "agent" && (unknown || invocations === "database" || isRecord
|
|
1908
|
+
if (id === "agent" && (unknown || invocations === "database" || isRecord(invocations) && invocations.store === "database")) return ["database"];
|
|
1603
1909
|
return [];
|
|
1604
1910
|
}
|
|
1605
1911
|
/** Plans `vitehub remove` without writing anything. Throws `SetupFailure` when the change is not safe or not possible. */
|
|
@@ -1681,6 +1987,10 @@ async function planSetupRemove(project, args, env) {
|
|
|
1681
1987
|
const key = source?.ok ? source.site.keys[id] : void 0;
|
|
1682
1988
|
return key?.kind === "literal" ? key.value : void 0;
|
|
1683
1989
|
};
|
|
1990
|
+
if (args.features.includes("kv") && remaining.includes("rateLimit") && valueOf(project.config, "kv") !== false && rateLimitUsesVercelKV(host, valueOf(afterKeys, "rateLimit"))) throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_REQUIRED({
|
|
1991
|
+
by: "rateLimit",
|
|
1992
|
+
feature: "kv"
|
|
1993
|
+
}), setupExitCodes.conflict, { data: { impliedBy: ["rateLimit"] } });
|
|
1684
1994
|
for (const id of turnedOff) {
|
|
1685
1995
|
const by = remaining.filter((dependent) => optionPrerequisites(dependent, valueOf(afterKeys, dependent), enabled(after.status, dependent).enabled === "unknown" && enabled(after.status, dependent).reason === "config").includes(id));
|
|
1686
1996
|
if (by.length) throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_REQUIRED({
|
|
@@ -1688,10 +1998,10 @@ async function planSetupRemove(project, args, env) {
|
|
|
1688
1998
|
feature: id
|
|
1689
1999
|
}), setupExitCodes.conflict, { data: { impliedBy: by } });
|
|
1690
2000
|
}
|
|
1691
|
-
const packagesOf = (id,
|
|
1692
|
-
return [...
|
|
2001
|
+
const packagesOf = (id, source, active = wasEnabled) => {
|
|
2002
|
+
return [...setupFeaturePackages(id, (feature) => valueOf(source, feature), host, active), ...features[id].devPackages];
|
|
1693
2003
|
};
|
|
1694
|
-
const stillNeeded = new Set(remaining.flatMap((id) => packagesOf(id,
|
|
2004
|
+
const stillNeeded = new Set(remaining.flatMap((id) => packagesOf(id, afterKeys, remaining)));
|
|
1695
2005
|
const starters = /* @__PURE__ */ new Map();
|
|
1696
2006
|
const edited = [];
|
|
1697
2007
|
for (const id of turnedOff) {
|
|
@@ -1717,7 +2027,7 @@ async function planSetupRemove(project, args, env) {
|
|
|
1717
2027
|
const modules = /* @__PURE__ */ new Map();
|
|
1718
2028
|
for (const id of turnedOff) {
|
|
1719
2029
|
modules.set(runtimeModule(id), id);
|
|
1720
|
-
for (const name of packagesOf(id,
|
|
2030
|
+
for (const name of packagesOf(id, project.config)) if (!stillNeeded.has(name) && !modules.has(name)) modules.set(name, id);
|
|
1721
2031
|
}
|
|
1722
2032
|
const imported = /* @__PURE__ */ new Set();
|
|
1723
2033
|
for (const file of listMatchingFiles(project.root, (name) => sourceFile.test(name))) {
|
|
@@ -1765,7 +2075,7 @@ async function planSetupRemove(project, args, env) {
|
|
|
1765
2075
|
const dev = [];
|
|
1766
2076
|
for (const id of wasEnabled) {
|
|
1767
2077
|
if (enabled(status, id).enabled !== "on") continue;
|
|
1768
|
-
const packages =
|
|
2078
|
+
const packages = setupFeaturePackages(id, (feature) => valueOf(project.config, feature), host, wasEnabled);
|
|
1769
2079
|
const removable = (name) => !stillNeeded.has(name) && !imported.has(name) && !prod.includes(name) && !dev.includes(name);
|
|
1770
2080
|
for (const name of packages) if (removable(name) && project.declared(name, true)) prod.push(name);
|
|
1771
2081
|
for (const name of features[id].devPackages) if (removable(name) && project.declared(name, true)) dev.push(name);
|
|
@@ -1972,12 +2282,9 @@ function nextSpecifier(name, current, place, target) {
|
|
|
1972
2282
|
if (place === "override") return version;
|
|
1973
2283
|
return `${/^[\^~]/u.exec(current)?.[0] ?? (semver.valid(current) ? "" : "^")}${version}`;
|
|
1974
2284
|
}
|
|
1975
|
-
function isObject(value) {
|
|
1976
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1977
|
-
}
|
|
1978
2285
|
function visitManifest(manifest, visit) {
|
|
1979
2286
|
const entries = (holder, place, nameOf) => {
|
|
1980
|
-
if (!
|
|
2287
|
+
if (!isRecord(holder)) return;
|
|
1981
2288
|
for (const [key, value] of Object.entries(holder)) {
|
|
1982
2289
|
const name = nameOf(key);
|
|
1983
2290
|
if (typeof value === "string") {
|
|
@@ -1985,7 +2292,7 @@ function visitManifest(manifest, visit) {
|
|
|
1985
2292
|
name,
|
|
1986
2293
|
place
|
|
1987
2294
|
});
|
|
1988
|
-
} else if (place === "override" &&
|
|
2295
|
+
} else if (place === "override" && isRecord(value)) {
|
|
1989
2296
|
if (name && typeof value["."] === "string" && isReplaceable(value["."])) visit(value, ".", {
|
|
1990
2297
|
name,
|
|
1991
2298
|
place
|
|
@@ -1998,10 +2305,10 @@ function visitManifest(manifest, visit) {
|
|
|
1998
2305
|
for (const field of dependencyFields) entries(manifest[field], "dependency", plainName);
|
|
1999
2306
|
entries(manifest.overrides, "override", overrideTarget);
|
|
2000
2307
|
entries(manifest.resolutions, "override", overrideTarget);
|
|
2001
|
-
if (
|
|
2002
|
-
if (
|
|
2308
|
+
if (isRecord(manifest.pnpm)) entries(manifest.pnpm.overrides, "override", overrideTarget);
|
|
2309
|
+
if (isRecord(manifest.workspaces)) {
|
|
2003
2310
|
entries(manifest.workspaces.catalog, "dependency", plainName);
|
|
2004
|
-
if (
|
|
2311
|
+
if (isRecord(manifest.workspaces.catalogs)) for (const catalog of Object.values(manifest.workspaces.catalogs)) entries(catalog, "dependency", plainName);
|
|
2005
2312
|
}
|
|
2006
2313
|
}
|
|
2007
2314
|
function unquote(text) {
|
|
@@ -2133,7 +2440,7 @@ function workspacePatterns(yaml, manifest) {
|
|
|
2133
2440
|
return yamlList(lines, yamlBlocks(lines).get("packages")).map((item) => item.value);
|
|
2134
2441
|
}
|
|
2135
2442
|
const workspaces = manifest.workspaces;
|
|
2136
|
-
return (Array.isArray(workspaces) ? workspaces :
|
|
2443
|
+
return (Array.isArray(workspaces) ? workspaces : isRecord(workspaces) && Array.isArray(workspaces.packages) ? workspaces.packages : []).filter((item) => typeof item === "string");
|
|
2137
2444
|
}
|
|
2138
2445
|
async function workspaceRoot(start) {
|
|
2139
2446
|
if (setupLockfiles.some(([file]) => existsSync(join(start, file)))) return start;
|
|
@@ -2148,7 +2455,7 @@ async function workspaceRoot(start) {
|
|
|
2148
2455
|
}
|
|
2149
2456
|
async function readJson(file) {
|
|
2150
2457
|
const value = JSON.parse(await readFile(file, "utf8"));
|
|
2151
|
-
return
|
|
2458
|
+
return isRecord(value) ? value : {};
|
|
2152
2459
|
}
|
|
2153
2460
|
function stringifyLike(before, value) {
|
|
2154
2461
|
const indent = /^[ \t]+(?=")/mu.exec(before)?.[0] ?? " ";
|
|
@@ -2216,7 +2523,7 @@ async function resolvePackages(names, preview, context) {
|
|
|
2216
2523
|
});
|
|
2217
2524
|
if (preview) return;
|
|
2218
2525
|
const body = await response.json();
|
|
2219
|
-
const version =
|
|
2526
|
+
const version = isRecord(body) && typeof body.version === "string" ? body.version : void 0;
|
|
2220
2527
|
if (!version) throw cliErrorDiagnostics.CLI_UPDATE_REQUEST_FAILED({
|
|
2221
2528
|
status: "a response without a version",
|
|
2222
2529
|
url: target
|
|
@@ -2275,7 +2582,7 @@ async function planSetupUpdate(rootDir, args, context) {
|
|
|
2275
2582
|
const direct = /* @__PURE__ */ new Map();
|
|
2276
2583
|
for (const field of dependencyFields) {
|
|
2277
2584
|
const dependencies = manifest.value[field];
|
|
2278
|
-
if (!
|
|
2585
|
+
if (!isRecord(dependencies)) continue;
|
|
2279
2586
|
for (const [name, value] of Object.entries(dependencies)) if (isViteHubPackage(name) && typeof value === "string" && isReplaceable(value) && !missing.includes(name)) direct.set(name, nextSpecifier(name, value, "dependency", resolved));
|
|
2280
2587
|
}
|
|
2281
2588
|
let edited = false;
|
|
@@ -2427,7 +2734,9 @@ function linkLabel(status) {
|
|
|
2427
2734
|
}
|
|
2428
2735
|
function credentialsLabel(credentials) {
|
|
2429
2736
|
if (!credentials) return "not needed";
|
|
2430
|
-
|
|
2737
|
+
if (credentials.ok && credentials.host === "vercel" && credentials.source === "host-cli") return "vercel (vercel login; deploy uses it. Set VERCEL_TOKEN for link checks, provision, and live status)";
|
|
2738
|
+
if (credentials.ok) return `${credentials.host} (${credentials.source})`;
|
|
2739
|
+
return "unknown" in credentials ? `unknown: ${credentials.fix}` : `missing: ${credentials.fix}`;
|
|
2431
2740
|
}
|
|
2432
2741
|
function writeStatus(status, context) {
|
|
2433
2742
|
const shown = status.features.filter((feature) => feature.enabled !== "off");
|