@vite-hub/cli 0.7.0 → 0.9.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 +2 -1
- package/dist/{commands-o_CHzNS9.js → commands-CzNBAR-E.js} +308 -74
- package/dist/console-apps-Cvzc6tY4.js +271 -0
- package/dist/console-auth-BunROd7u.js +2813 -0
- package/dist/{console-env-MPzeOLqu.js → console-env-BCw039oZ.js} +4 -14
- package/dist/{deploy-CGRf9Pq-.js → deploy-DxOKht-B.js} +9 -4
- package/dist/{env-DSPUdOVC.js → env-BvSnsKMg.js} +8 -9
- package/dist/envelope-DXB-0EcA.js +99 -0
- package/dist/help-cache-BI6y5pN8.js +195 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +64 -174
- package/dist/link-B3NuFAyj.js +663 -0
- package/dist/provision-D0ct9RDq.js +1743 -0
- package/dist/provision-DVuxa-yY.js +1389 -0
- package/dist/setup/index.d.ts +5 -0
- package/dist/setup/index.js +8 -7
- package/dist/status-HXNfm9mB.js +599 -0
- package/dist/vercel-ClYz5iI7.js +701 -0
- package/package.json +4 -4
- package/dist/provision-DWEZYLWJ.js +0 -8091
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
1
|
+
import { C as invariant, _ 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-D0ct9RDq.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-BunROd7u.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-DXB-0EcA.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-HXNfm9mB.js";
|
|
5
|
+
import { t as appsCommand } from "./console-apps-Cvzc6tY4.js";
|
|
6
|
+
import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-DxOKht-B.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-B3NuFAyj.js";
|
|
4
8
|
import { createRequire } from "node:module";
|
|
5
9
|
import { existsSync, readFileSync } from "node:fs";
|
|
6
10
|
import process from "node:process";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
7
12
|
import { basename, dirname, join, relative, resolve } from "pathe";
|
|
8
|
-
import { glob, mkdir, readFile, readdir, rm, rmdir, writeFile } from "node:fs/promises";
|
|
13
|
+
import { cp, glob, mkdir, mkdtemp, readFile, readdir, rm, rmdir, writeFile } from "node:fs/promises";
|
|
9
14
|
import { join as join$1, matchesGlob } from "node:path";
|
|
10
15
|
import { createInterface } from "node:readline/promises";
|
|
11
|
-
import {
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { createTwoFilesPatch } from "diff";
|
|
12
18
|
import { isDeepStrictEqual, parseArgs, stripVTControlCharacters } from "node:util";
|
|
13
|
-
import semver, { minVersion, satisfies, subset, validRange } from "semver";
|
|
14
19
|
import { isMap, parseDocument } from "yaml";
|
|
15
|
-
import {
|
|
20
|
+
import semver, { minVersion, satisfies, subset, validRange } from "semver";
|
|
16
21
|
// ../internal/dist/feature-inputs.js
|
|
17
22
|
function isLocaleTag(value) {
|
|
18
23
|
try {
|
|
@@ -51,10 +56,10 @@ function declinedBuilds(project, host, features) {
|
|
|
51
56
|
];
|
|
52
57
|
}
|
|
53
58
|
function named(policy, name) {
|
|
54
|
-
if (!isRecord
|
|
59
|
+
if (!isRecord(policy)) return false;
|
|
55
60
|
if (policy.dangerouslyAllowAllBuilds === true) return true;
|
|
56
61
|
const matches = (key) => typeof key === "string" && (key === name || key.startsWith(`${name}@`));
|
|
57
|
-
if (isRecord
|
|
62
|
+
if (isRecord(policy.allowBuilds) && Object.keys(policy.allowBuilds).some(matches)) return true;
|
|
58
63
|
return [
|
|
59
64
|
"onlyBuiltDependencies",
|
|
60
65
|
"ignoredBuiltDependencies",
|
|
@@ -71,7 +76,7 @@ function pnpmBuildPolicyFile(root) {
|
|
|
71
76
|
const document = parseDocument(readFileSync(workspace, "utf8"));
|
|
72
77
|
if (document.errors.length) return workspace;
|
|
73
78
|
const policy = document.toJS();
|
|
74
|
-
if (!isRecord
|
|
79
|
+
if (!isRecord(policy) || !Array.isArray(policy.packages)) return workspace;
|
|
75
80
|
const path = relative(dirname(workspace), root);
|
|
76
81
|
const patterns = policy.packages.filter((pattern) => typeof pattern === "string");
|
|
77
82
|
const includes = (pattern) => matchesGlob(path, pattern.replace(/^\.\//u, "").replace(/\/$/u, ""));
|
|
@@ -176,9 +181,9 @@ const optionExamples = {
|
|
|
176
181
|
};
|
|
177
182
|
const providerKeys = ["driver", "store"];
|
|
178
183
|
function selectsProvider(id, value, host) {
|
|
179
|
-
if (!isRecord
|
|
184
|
+
if (!isRecord(value)) return false;
|
|
180
185
|
if (id === "workflow" && host !== "netlify") {
|
|
181
|
-
const configured = (storage, key) => isRecord
|
|
186
|
+
const configured = (storage, key) => isRecord(storage) && (typeof storage[key] === "string" ? !!storage[key].trim() : isRecord(storage[key]));
|
|
182
187
|
if (configured(value.postgres, "url") || configured(value.sqlite, "path")) return true;
|
|
183
188
|
}
|
|
184
189
|
return providerKeys.some((key) => value[key] !== void 0);
|
|
@@ -191,7 +196,7 @@ function hostSupport(id, host, env) {
|
|
|
191
196
|
const enabledValues = { env: {} };
|
|
192
197
|
function installSpecifiers(packages) {
|
|
193
198
|
const manifest = JSON.parse(readFileSync(new URL(import.meta.resolve("@vite-hub/cli/package.json")), "utf8"));
|
|
194
|
-
const dependencies = isRecord
|
|
199
|
+
const dependencies = isRecord(manifest) && isRecord(manifest.dependencies) ? manifest.dependencies : {};
|
|
195
200
|
const preview = Object.entries(dependencies).flatMap(([name, specifier]) => {
|
|
196
201
|
if (!name.startsWith("@vite-hub/") || typeof specifier !== "string" || !specifier.startsWith("https://pkg.pr.new/")) return [];
|
|
197
202
|
const [base, ref] = specifier.split(`/${name}@`);
|
|
@@ -228,13 +233,10 @@ function setPath(target, path, value) {
|
|
|
228
233
|
return;
|
|
229
234
|
}
|
|
230
235
|
const child = target[key];
|
|
231
|
-
const next = isRecord
|
|
236
|
+
const next = isRecord(child) ? { ...child } : {};
|
|
232
237
|
setPath(next, rest, value);
|
|
233
238
|
target[key] = next;
|
|
234
239
|
}
|
|
235
|
-
function isRecord$1(value) {
|
|
236
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
237
|
-
}
|
|
238
240
|
/** Reads the arguments. Throws `CLI_R0003` for an unknown flag, feature, or option. */
|
|
239
241
|
function readAddArgs(args) {
|
|
240
242
|
const parsed = {
|
|
@@ -280,7 +282,7 @@ function readAddArgs(args) {
|
|
|
280
282
|
}
|
|
281
283
|
/** `value` as `--option` values under `prefix`, such as `["email.driver=resend"]`. */
|
|
282
284
|
function flattenOptions(prefix, value, out = []) {
|
|
283
|
-
if (isRecord
|
|
285
|
+
if (isRecord(value)) for (const [key, child] of Object.entries(value)) flattenOptions(`${prefix}.${key}`, child, out);
|
|
284
286
|
else out.push(`${prefix}=${value === null || typeof value !== "object" ? String(value) : JSON.stringify(value)}`);
|
|
285
287
|
return out;
|
|
286
288
|
}
|
|
@@ -292,7 +294,7 @@ function rerunCommand$1(args, extra = {}, extraFeatures = []) {
|
|
|
292
294
|
...Object.keys(extra)
|
|
293
295
|
])].flatMap((id) => {
|
|
294
296
|
const merged = mergeValue(args.options[id], extra[id]);
|
|
295
|
-
return isRecord
|
|
297
|
+
return isRecord(merged) ? flattenOptions(id, merged) : [];
|
|
296
298
|
});
|
|
297
299
|
return [
|
|
298
300
|
"vitehub add",
|
|
@@ -307,18 +309,18 @@ function rerunCommand$1(args, extra = {}, extraFeatures = []) {
|
|
|
307
309
|
/** Merges `patch` into `base`, object key by object key. */
|
|
308
310
|
function mergeValue(base, patch) {
|
|
309
311
|
if (patch === void 0) return base;
|
|
310
|
-
if (!isRecord
|
|
312
|
+
if (!isRecord(base) || !isRecord(patch)) return patch;
|
|
311
313
|
const merged = { ...base };
|
|
312
314
|
for (const [key, value] of Object.entries(patch)) merged[key] = mergeValue(base[key], value);
|
|
313
315
|
return merged;
|
|
314
316
|
}
|
|
315
317
|
function sameValue(left, right) {
|
|
316
|
-
if (isRecord
|
|
318
|
+
if (isRecord(left) && isRecord(right)) return [.../* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])].every((key) => sameValue(left[key], right[key]));
|
|
317
319
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
318
320
|
}
|
|
319
321
|
function toSource(value) {
|
|
320
322
|
if (Array.isArray(value)) return `[${value.map(toSource).join(", ")}]`;
|
|
321
|
-
if (isRecord
|
|
323
|
+
if (isRecord(value)) {
|
|
322
324
|
const entries = Object.entries(value).map(([key, child]) => `${/^[A-Z_$][\w$]*$/iu.test(key) ? key : JSON.stringify(key)}: ${toSource(child)}`);
|
|
323
325
|
return entries.length ? `{ ${entries.join(", ")} }` : "{}";
|
|
324
326
|
}
|
|
@@ -333,7 +335,7 @@ function nextValue(id, status, project, options) {
|
|
|
333
335
|
if (current?.kind === "expression") return "expression";
|
|
334
336
|
const literal = current?.value;
|
|
335
337
|
if (!options) return status.features.find((item) => item.id === id).enabled === "on" ? void 0 : { value: enabledValues[id] ?? true };
|
|
336
|
-
const merged = mergeValue(isRecord
|
|
338
|
+
const merged = mergeValue(isRecord(literal) ? literal : {}, options);
|
|
337
339
|
return sameValue(literal, merged) ? void 0 : { value: merged };
|
|
338
340
|
}
|
|
339
341
|
/** Plans `vitehub add` without writing anything. Throws `SetupFailure` when the change needs input or is not possible. */
|
|
@@ -354,7 +356,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
354
356
|
for (const id of args.features) {
|
|
355
357
|
const support = featureSupport(id, host);
|
|
356
358
|
const current = project.config?.ok ? project.config.site.keys[id] : void 0;
|
|
357
|
-
const driver = args.options[id]?.driver ?? (current?.kind === "literal" && isRecord
|
|
359
|
+
const driver = args.options[id]?.driver ?? (current?.kind === "literal" && isRecord(current.value) ? current.value.driver : void 0);
|
|
358
360
|
if (id === "email" && driver === "cloudflare" && host !== "cloudflare") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
359
361
|
detail: "The cloudflare driver requires Cloudflare. Choose email.driver=resend, or email.driver=log to print each message and send nothing.",
|
|
360
362
|
feature: id,
|
|
@@ -393,9 +395,9 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
393
395
|
const support = featureSupport(id, host);
|
|
394
396
|
const current = project.config?.ok ? project.config.site.keys[id] : void 0;
|
|
395
397
|
const value = valueFor(id);
|
|
396
|
-
if (id === "observability" && isRecord
|
|
398
|
+
if (id === "observability" && isRecord(value) && value.papercuts) {
|
|
397
399
|
const agent = valueFor("agent");
|
|
398
|
-
if (host === "netlify" || isRecord
|
|
400
|
+
if (host === "netlify" || isRecord(agent) && agent.runtime === "deno") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
399
401
|
detail: "observability.papercuts requires Nitro-hosted Agents. Netlify and the Agent Deno runtime are not supported.",
|
|
400
402
|
feature: id,
|
|
401
403
|
host
|
|
@@ -403,14 +405,14 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
403
405
|
requireFeature("agent");
|
|
404
406
|
requireFeature("console");
|
|
405
407
|
}
|
|
406
|
-
if (id === "observability" && isRecord
|
|
408
|
+
if (id === "observability" && isRecord(value) && value.posthog) requireFeature("env");
|
|
407
409
|
if (id === "realtime" && args.name !== void 0) requireFeature("workspace");
|
|
408
|
-
if (id === "agent" && host === "deno" && isRecord
|
|
410
|
+
if (id === "agent" && host === "deno" && isRecord(value) && value.runtime === "deno") throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
409
411
|
detail: "The Deno host cannot deploy the Agent Deno runtime outside its Nitro entrypoint. Use the host's Nitro runtime instead.",
|
|
410
412
|
feature: id,
|
|
411
413
|
host
|
|
412
414
|
}), setupExitCodes.conflict);
|
|
413
|
-
if (id === "realtime" && isRecord
|
|
415
|
+
if (id === "realtime" && isRecord(value) && value.driver !== void 0) {
|
|
414
416
|
const choices = host === "cloudflare" ? ["cloudflare", "auto"] : host === "node" ? [
|
|
415
417
|
"auto",
|
|
416
418
|
"postgres",
|
|
@@ -423,7 +425,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
423
425
|
host
|
|
424
426
|
}), setupExitCodes.conflict);
|
|
425
427
|
}
|
|
426
|
-
if (id === "cache" && isRecord
|
|
428
|
+
if (id === "cache" && isRecord(value) && value.driver !== void 0) {
|
|
427
429
|
const nativeDriver = {
|
|
428
430
|
cloudflare: "cloudflare",
|
|
429
431
|
deno: "deno-kv",
|
|
@@ -437,13 +439,13 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
437
439
|
host
|
|
438
440
|
}), setupExitCodes.conflict);
|
|
439
441
|
}
|
|
440
|
-
const invocations = id === "agent" && isRecord
|
|
442
|
+
const invocations = id === "agent" && isRecord(value) ? value.invocations : void 0;
|
|
441
443
|
if (host === "netlify" && invocations !== void 0 && invocations !== false) throw setupFailure(cliErrorDiagnostics.SETUP_FEATURE_UNSUPPORTED({
|
|
442
444
|
detail: "agent.invocations requires Nitro-hosted Agents. Set invocations on each Agent Definition instead, or use agent.invocations=false.",
|
|
443
445
|
feature: id,
|
|
444
446
|
host
|
|
445
447
|
}), setupExitCodes.conflict);
|
|
446
|
-
if (invocations === "database" || isRecord
|
|
448
|
+
if (invocations === "database" || isRecord(invocations) && invocations.store === "database") requireFeature("database");
|
|
447
449
|
const storageSelected = id === "workflow" && host !== "netlify" && selectsProvider(id, value, host);
|
|
448
450
|
if (support.level === "explicit" && !storageSelected) {
|
|
449
451
|
const field = missingProviderOption(project, support.option, value);
|
|
@@ -464,19 +466,19 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
464
466
|
for (const [field, choice] of Object.entries(optionChoices)) {
|
|
465
467
|
if (!choice?.requires || !field.startsWith(`${id}.`)) continue;
|
|
466
468
|
const key = field.slice(id.length + 1);
|
|
467
|
-
const selected = (isRecord
|
|
469
|
+
const selected = (isRecord(value) ? value[key] : void 0) ?? defaults[id]?.[key];
|
|
468
470
|
if (typeof selected !== "string" || !choice.values.includes(selected)) continue;
|
|
469
471
|
requireFeature(choice.requires);
|
|
470
472
|
}
|
|
471
|
-
if (id === "schedule" && host === "node" && current?.kind !== "expression" && !(isRecord
|
|
472
|
-
if (isRecord
|
|
473
|
+
if (id === "schedule" && host === "node" && current?.kind !== "expression" && !(isRecord(value) && value.providerOutput === false)) {
|
|
474
|
+
if (isRecord(value) && (value.providerOutput === "nitro" || value.providerOutput === "standalone")) {
|
|
473
475
|
missing.push({
|
|
474
476
|
choices: ["auto"],
|
|
475
477
|
field: "schedule.providerOutput"
|
|
476
478
|
});
|
|
477
479
|
setPath(defaults.schedule ??= {}, ["providerOutput"], "auto");
|
|
478
480
|
}
|
|
479
|
-
if (isRecord
|
|
481
|
+
if (isRecord(value) && value.runtime !== void 0 && (!isRecord(value.runtime) || value.runtime.driver !== "process")) {
|
|
480
482
|
missing.push({
|
|
481
483
|
choices: ["process"],
|
|
482
484
|
field: "schedule.runtime.driver"
|
|
@@ -488,8 +490,8 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
488
490
|
const enabledAfter = (id) => inputFeatures.includes(id) || status.features.find((item) => item.id === id)?.enabled === "on";
|
|
489
491
|
const agent = valueFor("agent");
|
|
490
492
|
const observabilityValue = valueFor("observability");
|
|
491
|
-
const telemetry = isRecord
|
|
492
|
-
if (inputFeatures.some((id) => id === "agent" || id === "observability") && enabledAfter("observability") && telemetry && enabledAfter("agent") && (host === "netlify" || isRecord
|
|
493
|
+
const telemetry = isRecord(observabilityValue) && typeof observabilityValue.service === "string";
|
|
494
|
+
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({
|
|
493
495
|
detail: "Observability requires Nitro-hosted Agents. Netlify and the Agent Deno runtime are not supported.",
|
|
494
496
|
feature: "observability",
|
|
495
497
|
host
|
|
@@ -498,7 +500,7 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
498
500
|
const site = project.config?.ok ? project.config.site : void 0;
|
|
499
501
|
if (inputFeatures.includes("i18n") && site?.keys.i18n?.kind !== "expression") {
|
|
500
502
|
const i18n = valueFor("i18n");
|
|
501
|
-
const problem = i18nLocaleListProblem(isRecord
|
|
503
|
+
const problem = i18nLocaleListProblem(isRecord(i18n) ? i18n.locales : void 0);
|
|
502
504
|
if (problem) {
|
|
503
505
|
missing.push({ field: "i18n.locales" });
|
|
504
506
|
inputFixes.push(`${problem} Pass a nonempty JSON array, such as \`--option 'i18n.locales=["en","es"]'\`.`);
|
|
@@ -514,15 +516,15 @@ async function planSetupAdd(project, args, env, rerun = rerunCommand$1) {
|
|
|
514
516
|
const selectedAuth = args.features.includes("auth") && (!configuredAuth || configuredAuth.kind === "expression" || configuredAuth.value === false);
|
|
515
517
|
const authEnabled = !args.options.auth && (selectedAuth || configuredAuth?.kind === "literal" && configuredAuth.value === true || discoveredAuth);
|
|
516
518
|
const mcp = valueFor("mcp");
|
|
517
|
-
const mode = isRecord
|
|
518
|
-
const publicRoute = isRecord
|
|
519
|
+
const mode = isRecord(mcp) && Object.hasOwn(mcp, "auth") ? mcp.auth : void 0;
|
|
520
|
+
const publicRoute = isRecord(mcp) && typeof mcp.publicRoute === "string" ? mcp.publicRoute : void 0;
|
|
519
521
|
if ((typeof mode === "boolean" || mode === "optional") && mcpPublicRouteNeedsSignedAuth(publicRoute, mode)) {
|
|
520
522
|
missing.push({ field: "mcp.publicRoute" });
|
|
521
523
|
inputFixes.push("Remove `mcp.publicRoute`, or enable Auth, set `mcp.auth=true`, and add `mcpOAuth()` to the Auth Definition.");
|
|
522
524
|
rerunnable = false;
|
|
523
525
|
} else if (!authEnabled && authStatus?.enabled === "unknown" && (mode === void 0 || mode === true || mode === "optional")) {
|
|
524
526
|
const file = project.configFile ?? "vite.config.ts";
|
|
525
|
-
const snippet = `mcp: ${toSource(isRecord
|
|
527
|
+
const snippet = `mcp: ${toSource(isRecord(mcp) ? mcp : true)},`;
|
|
526
528
|
const fix = `Confirm Auth is enabled in the app. ${mcpOAuthSetup}. Add this key to the vitehub() options by hand:\n${snippet}`;
|
|
527
529
|
throw setupFailure(cliErrorDiagnostics.SETUP_CONFIG_MANUAL({
|
|
528
530
|
file,
|
|
@@ -844,6 +846,61 @@ function setupCatalog() {
|
|
|
844
846
|
schemaVersion: 1
|
|
845
847
|
};
|
|
846
848
|
}
|
|
849
|
+
// ../../templates/nuxt/agent/template.json
|
|
850
|
+
var title$2 = "Agent";
|
|
851
|
+
var description$2 = "A chat assistant with tools, memory, and channels. It reads web pages with Browser, which runs on Cloudflare only.";
|
|
852
|
+
// ../../templates/nuxt/dashboard/template.json
|
|
853
|
+
var title$1 = "Dashboard";
|
|
854
|
+
var description$1 = "A SaaS app with a public landing page, a blog, and a signed-in dashboard.";
|
|
855
|
+
// ../../templates/nuxt/jobs/template.json
|
|
856
|
+
var title = "Jobs";
|
|
857
|
+
var description = "A nightly repository reviewer that runs on a schedule.";
|
|
858
|
+
// src/setup/init-template.ts
|
|
859
|
+
/** The templates in `templates/nuxt/` that `vitehub init --template` starts from. */
|
|
860
|
+
const initTemplates = [
|
|
861
|
+
"dashboard",
|
|
862
|
+
"agent",
|
|
863
|
+
"jobs"
|
|
864
|
+
];
|
|
865
|
+
/** The title and description of each template, as its `template.json` gives them. A test keeps both in sync. */
|
|
866
|
+
const initTemplateInfo = {
|
|
867
|
+
agent: {
|
|
868
|
+
description: description$2,
|
|
869
|
+
title: title$2
|
|
870
|
+
},
|
|
871
|
+
dashboard: {
|
|
872
|
+
description: description$1,
|
|
873
|
+
title: title$1
|
|
874
|
+
},
|
|
875
|
+
jobs: {
|
|
876
|
+
description,
|
|
877
|
+
title
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
const templatePnpmWorkspace = {
|
|
881
|
+
agent: "allowBuilds:\n esbuild: false\n \"@mongodb-js/zstd\": false\n node-liblzma: false\n",
|
|
882
|
+
dashboard: "allowBuilds:\n esbuild: false\n",
|
|
883
|
+
jobs: "allowBuilds:\n esbuild: false\n \"@swc/core\": false\n cbor-extract: false\n"
|
|
884
|
+
};
|
|
885
|
+
/** The pinned giget that downloads a template folder from GitHub. */
|
|
886
|
+
const gigetPackage = "giget@3.3.1";
|
|
887
|
+
/** The files that every complete template has. A release that has only the skeleton of a template has no README.md. */
|
|
888
|
+
const templateRequiredFiles = ["README.md", "package.json"];
|
|
889
|
+
/** The version of this CLI. A template comes from the release tag of the same version, so the app matches the CLI. */
|
|
890
|
+
function templateVersion() {
|
|
891
|
+
const manifest = JSON.parse(readFileSync(new URL(import.meta.resolve("@vite-hub/cli/package.json")), "utf8"));
|
|
892
|
+
const version = manifest && typeof manifest === "object" ? Reflect.get(manifest, "version") : void 0;
|
|
893
|
+
invariant(typeof version === "string", "the installed @vite-hub/cli package manifest has a version");
|
|
894
|
+
return version;
|
|
895
|
+
}
|
|
896
|
+
/** The giget source of a template at a release tag. */
|
|
897
|
+
function templateSource(template, version) {
|
|
898
|
+
return `gh:vite-hub/vitehub/templates/nuxt/${template}#v${version}`;
|
|
899
|
+
}
|
|
900
|
+
/** Whether a downloaded template folder is complete. */
|
|
901
|
+
function isCompleteTemplate(dir) {
|
|
902
|
+
return templateRequiredFiles.every((file) => existsSync(`${dir}/${file}`));
|
|
903
|
+
}
|
|
847
904
|
// src/setup/init-wizard.ts
|
|
848
905
|
function cancelled() {
|
|
849
906
|
return setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] The setup was cancelled. Nothing was written." }), setupExitCodes.error);
|
|
@@ -945,7 +1002,7 @@ function containsCredentials(value) {
|
|
|
945
1002
|
return !!(url && (url.username || url.password || url.search || url.hash));
|
|
946
1003
|
}
|
|
947
1004
|
if (Array.isArray(value)) return value.some(containsCredentials);
|
|
948
|
-
return isRecord
|
|
1005
|
+
return isRecord(value) && Object.entries(value).some(([key, child]) => credentialKey(key) || containsCredentials(child));
|
|
949
1006
|
}
|
|
950
1007
|
function setupStackLabels(stack) {
|
|
951
1008
|
return {
|
|
@@ -967,7 +1024,7 @@ async function deriveSetupStack(project, status, validate) {
|
|
|
967
1024
|
});
|
|
968
1025
|
return;
|
|
969
1026
|
}
|
|
970
|
-
if (isRecord
|
|
1027
|
+
if (isRecord(value) && Object.keys(value).length) {
|
|
971
1028
|
for (const [key, child] of Object.entries(value)) collect(id, [...keys, key], child);
|
|
972
1029
|
return;
|
|
973
1030
|
}
|
|
@@ -1019,7 +1076,7 @@ async function deriveSetupStack(project, status, validate) {
|
|
|
1019
1076
|
continue;
|
|
1020
1077
|
}
|
|
1021
1078
|
const value = setting?.value;
|
|
1022
|
-
if (features[id].enabledByDefault && (value === void 0 || value === true || isRecord
|
|
1079
|
+
if (features[id].enabledByDefault && (value === void 0 || value === true || isRecord(value) && !Object.keys(value).length)) continue;
|
|
1023
1080
|
selected.push(id);
|
|
1024
1081
|
if (value !== void 0 && value !== true) collect(id, [], value);
|
|
1025
1082
|
}
|
|
@@ -1081,7 +1138,8 @@ async function deriveSetupStack(project, status, validate) {
|
|
|
1081
1138
|
};
|
|
1082
1139
|
}
|
|
1083
1140
|
// src/setup/init.ts
|
|
1084
|
-
const usage$2 =
|
|
1141
|
+
const usage$2 = `vitehub init <dir> --host <host> --features <id,id,...> [--option <feature.key=value>]... [--framework vite|nuxt] [--nuxt-nightly] [--pm pnpm|npm|yarn|bun] [--no-install] [--dry-run] --yes [--json]
|
|
1142
|
+
vitehub init <dir> --template ${initTemplates.join("|")} [--pm pnpm|npm|yarn|bun] [--no-install] [--dry-run] --yes [--json]`;
|
|
1085
1143
|
const initCommandPrefix = "pnpm dlx vite-hub init";
|
|
1086
1144
|
const initHosts = [
|
|
1087
1145
|
"cloudflare",
|
|
@@ -1131,9 +1189,6 @@ const nuxt47ViteHub = "vite-hub@>=0.5.1 <1";
|
|
|
1131
1189
|
/** The pinned Nuxt CLI that creates a new Nuxt app. */
|
|
1132
1190
|
const nuxiPackage = "nuxi@3.37.0";
|
|
1133
1191
|
const nuxtTemplate = "gh:nuxt/starter#d4367031fe43d93d4e2a339f73b519ec35e78b38";
|
|
1134
|
-
function isRecord(value) {
|
|
1135
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1136
|
-
}
|
|
1137
1192
|
function invalid$2(message) {
|
|
1138
1193
|
return cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] ${message} Usage: ${usage$2}` });
|
|
1139
1194
|
}
|
|
@@ -1173,10 +1228,12 @@ function readInitArgs(args) {
|
|
|
1173
1228
|
else if (flag === "--option") parsed.options.push(value());
|
|
1174
1229
|
else if (flag === "--framework") parsed.framework = oneOf("--framework", value(), frameworks);
|
|
1175
1230
|
else if (flag === "--pm") parsed.pm = oneOf("--pm", value(), packageManagers);
|
|
1231
|
+
else if (flag === "--template") parsed.template = oneOf("--template", value(), initTemplates);
|
|
1176
1232
|
else if (arg.startsWith("-")) throw invalid$2(`Unknown argument ${JSON.stringify(arg)}.`);
|
|
1177
1233
|
else if (parsed.dir === void 0) parsed.dir = arg;
|
|
1178
1234
|
else throw invalid$2(`Pass one folder, not ${JSON.stringify(parsed.dir)} and ${JSON.stringify(arg)}.`);
|
|
1179
1235
|
}
|
|
1236
|
+
if (parsed.template && (parsed.framework || parsed.host || features !== void 0 || parsed.options.length || parsed.nuxtNightly)) throw invalid$2("--template cannot be used with --framework, --host, --features, --option, or --nuxt-nightly. The template sets them.");
|
|
1180
1237
|
if (features !== void 0) parsed.features = readAddArgs(features.split(",").map((item) => item.trim()).filter(Boolean)).features;
|
|
1181
1238
|
if (parsed.nuxtNightly && parsed.framework === "vite") throw invalid$2("--nuxt-nightly needs --framework nuxt.");
|
|
1182
1239
|
if (parsed.nuxtNightly) parsed.framework = "nuxt";
|
|
@@ -1237,7 +1294,7 @@ function viteAppFiles(name, host) {
|
|
|
1237
1294
|
start: "node .output/server/index.mjs"
|
|
1238
1295
|
}
|
|
1239
1296
|
}, null, 2)}\n`,
|
|
1240
|
-
"server/api/health.get.ts": "import { defineEventHandler } from \"h3\"\n\nexport default defineEventHandler(() => ({ ok: true }))\n",
|
|
1297
|
+
"server/api/health.get.ts": "import { defineEventHandler } from \"nitro/h3\"\n\nexport default defineEventHandler(() => ({ ok: true }))\n",
|
|
1241
1298
|
"tsconfig.json": `{
|
|
1242
1299
|
"extends": ["vite-hub/tsconfig"],
|
|
1243
1300
|
"compilerOptions": {
|
|
@@ -1312,6 +1369,9 @@ function lockedHost(project, env) {
|
|
|
1312
1369
|
const status = setupStatus(project, env);
|
|
1313
1370
|
if (status.features.some((feature) => feature.id !== "env" && feature.enabled !== "off")) return status.host.name;
|
|
1314
1371
|
}
|
|
1372
|
+
function isTemplateInputs(inputs) {
|
|
1373
|
+
return inputs.template !== void 0;
|
|
1374
|
+
}
|
|
1315
1375
|
function changeOf(path, before, after) {
|
|
1316
1376
|
return before === void 0 ? {
|
|
1317
1377
|
after,
|
|
@@ -1530,6 +1590,7 @@ async function planInit(args, root, state, context) {
|
|
|
1530
1590
|
function setupStack(project, status) {
|
|
1531
1591
|
return deriveSetupStack(project, status, async (args) => {
|
|
1532
1592
|
const inputs = await readInputs(readInitArgs(args));
|
|
1593
|
+
if (isTemplateInputs(inputs)) return;
|
|
1533
1594
|
const rootDir = dirname(project.root);
|
|
1534
1595
|
await planInit(inputs, resolve(rootDir, inputs.dir), {
|
|
1535
1596
|
exists: false,
|
|
@@ -1669,18 +1730,40 @@ function askFeatures(prompts, host) {
|
|
|
1669
1730
|
}
|
|
1670
1731
|
async function askInputs(args, prompts, context) {
|
|
1671
1732
|
const { dir, state } = await askDir(args, prompts, context);
|
|
1733
|
+
if (args.template) return {
|
|
1734
|
+
...args,
|
|
1735
|
+
dir,
|
|
1736
|
+
template: args.template
|
|
1737
|
+
};
|
|
1672
1738
|
const found = state.kind === "adopt" && state.project.framework !== "none" ? state.project.framework : void 0;
|
|
1673
|
-
const
|
|
1739
|
+
const offerTemplates = state.kind === "create" && args.host === void 0 && args.features === void 0 && !args.options.length && !args.nuxtNightly;
|
|
1740
|
+
const start = args.framework ?? (found === "nuxt" || found === "vite" ? found : await prompts.select({
|
|
1674
1741
|
initialValue: "vite",
|
|
1675
|
-
message: "
|
|
1676
|
-
options: [
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1742
|
+
message: "Start from",
|
|
1743
|
+
options: [
|
|
1744
|
+
{
|
|
1745
|
+
hint: "an empty app",
|
|
1746
|
+
label: "Vite",
|
|
1747
|
+
value: "vite"
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
hint: "an empty app",
|
|
1751
|
+
label: "Nuxt",
|
|
1752
|
+
value: "nuxt"
|
|
1753
|
+
},
|
|
1754
|
+
...offerTemplates ? initTemplates.map((value) => ({
|
|
1755
|
+
hint: initTemplateInfo[value].description,
|
|
1756
|
+
label: `${initTemplateInfo[value].title} (Nuxt)`,
|
|
1757
|
+
value
|
|
1758
|
+
})) : []
|
|
1759
|
+
]
|
|
1683
1760
|
}));
|
|
1761
|
+
if (start !== "vite" && start !== "nuxt") return {
|
|
1762
|
+
...args,
|
|
1763
|
+
dir,
|
|
1764
|
+
template: start
|
|
1765
|
+
};
|
|
1766
|
+
const framework = start;
|
|
1684
1767
|
const currentHost = state.kind === "adopt" ? lockedHost(state.project, context.env) : void 0;
|
|
1685
1768
|
const host = args.host ?? currentHost ?? await prompts.select({
|
|
1686
1769
|
message: "Host",
|
|
@@ -1707,6 +1790,21 @@ async function readInputs(args, prompts, context = {
|
|
|
1707
1790
|
rootDir: process.cwd()
|
|
1708
1791
|
}) {
|
|
1709
1792
|
if (prompts) return askInputs(args, prompts, context);
|
|
1793
|
+
if (args.template) {
|
|
1794
|
+
if (args.dir !== void 0) return {
|
|
1795
|
+
...args,
|
|
1796
|
+
dir: args.dir,
|
|
1797
|
+
template: args.template
|
|
1798
|
+
};
|
|
1799
|
+
throw setupFailure(cliErrorDiagnostics.SETUP_INPUT_NEEDED({ message: `[vitehub] Pass the app folder, such as \`vitehub init my-app --template ${args.template}\`, when running without an interactive terminal.${npmCreateHint(context.env)}` }), setupExitCodes.inputNeeded, {
|
|
1800
|
+
missing: [{ field: "dir" }],
|
|
1801
|
+
rerun: templateCommand({
|
|
1802
|
+
...args,
|
|
1803
|
+
dir: "<dir>",
|
|
1804
|
+
template: args.template
|
|
1805
|
+
})
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1710
1808
|
const missing = [];
|
|
1711
1809
|
if (args.dir === void 0) missing.push({
|
|
1712
1810
|
field: "dir",
|
|
@@ -1764,6 +1862,144 @@ function writeResult$1(plan, context) {
|
|
|
1764
1862
|
context.stdout.write(`${stackLines(plan.stack).join("\n")}\n`);
|
|
1765
1863
|
context.stdout.write(`\nNext steps:\n${plan.nextSteps.map((step) => `- ${step}`).join("\n")}\n`);
|
|
1766
1864
|
}
|
|
1865
|
+
function templateCommand(args) {
|
|
1866
|
+
return [
|
|
1867
|
+
initCommandPrefix,
|
|
1868
|
+
shellQuote(args.dir),
|
|
1869
|
+
"--template",
|
|
1870
|
+
args.template,
|
|
1871
|
+
...args.pm && args.pm !== "pnpm" ? ["--pm", args.pm] : [],
|
|
1872
|
+
...args.install ? [] : ["--no-install"],
|
|
1873
|
+
"--yes",
|
|
1874
|
+
...args.json ? ["--json"] : []
|
|
1875
|
+
].join(" ");
|
|
1876
|
+
}
|
|
1877
|
+
async function checkTemplateDir(root) {
|
|
1878
|
+
if (!existsSync(root)) return;
|
|
1879
|
+
if ((await readdir(root)).filter((entry) => entry !== ".git").length) throw setupFailure(cliErrorDiagnostics.SETUP_INIT_TEMPLATE_DIR({ dir: root }), setupExitCodes.conflict);
|
|
1880
|
+
}
|
|
1881
|
+
function planTemplate(args, root, context, version) {
|
|
1882
|
+
const detected = detectPackageManager(root, void 0, context.env);
|
|
1883
|
+
const packageManager = args.pm ?? (detected.packageManagerSource === "default" ? "pnpm" : detected.packageManager);
|
|
1884
|
+
const source = templateSource(args.template, version);
|
|
1885
|
+
const [command, commandArgs] = dlx(packageManager, gigetPackage, [source, args.dir]);
|
|
1886
|
+
const install = `${packageManager} install`;
|
|
1887
|
+
return {
|
|
1888
|
+
download: { command: [command, ...commandArgs.map(shellQuote)].join(" ") },
|
|
1889
|
+
framework: "nuxt",
|
|
1890
|
+
install: { command: install },
|
|
1891
|
+
mode: "create",
|
|
1892
|
+
nextSteps: [
|
|
1893
|
+
...root === resolve(context.rootDir) ? [] : [`cd ${shellQuote(args.dir)}`],
|
|
1894
|
+
...args.install ? [] : [`Install the packages: ${install}`],
|
|
1895
|
+
"Read README.md for the rest of the setup, such as database migrations and the owner claim.",
|
|
1896
|
+
`Start the dev server: ${runScript(packageManager, "dev")}`
|
|
1897
|
+
],
|
|
1898
|
+
packageManager,
|
|
1899
|
+
root,
|
|
1900
|
+
source,
|
|
1901
|
+
status: "planned",
|
|
1902
|
+
template: args.template
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
async function applyTemplate(plan, version, install, context) {
|
|
1906
|
+
const work = await mkdtemp(join(tmpdir(), "vitehub-template-"));
|
|
1907
|
+
try {
|
|
1908
|
+
const target = join(work, "app");
|
|
1909
|
+
const [command, commandArgs] = dlx(plan.packageManager, gigetPackage, [plan.source, target]);
|
|
1910
|
+
const result = await context.spawn(command, commandArgs, {
|
|
1911
|
+
cwd: work,
|
|
1912
|
+
env: context.env,
|
|
1913
|
+
stdout: "stderr"
|
|
1914
|
+
});
|
|
1915
|
+
if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INIT_TEMPLATE_DOWNLOAD_FAILED({
|
|
1916
|
+
command: plan.download.command,
|
|
1917
|
+
exitCode: result.exitCode ?? result.signal
|
|
1918
|
+
}), setupExitCodes.error);
|
|
1919
|
+
if (!isCompleteTemplate(target)) throw setupFailure(cliErrorDiagnostics.SETUP_INIT_TEMPLATE_MISSING({
|
|
1920
|
+
source: plan.source,
|
|
1921
|
+
template: plan.template,
|
|
1922
|
+
version
|
|
1923
|
+
}), setupExitCodes.error);
|
|
1924
|
+
const manifestFile = join(target, "package.json");
|
|
1925
|
+
const manifest = JSON.parse(await readFile(manifestFile, "utf8"));
|
|
1926
|
+
if (isRecord(manifest)) {
|
|
1927
|
+
const updated = {
|
|
1928
|
+
...manifest,
|
|
1929
|
+
name: packageNameOf(plan.root)
|
|
1930
|
+
};
|
|
1931
|
+
for (const field of [
|
|
1932
|
+
"dependencies",
|
|
1933
|
+
"devDependencies",
|
|
1934
|
+
"optionalDependencies"
|
|
1935
|
+
]) {
|
|
1936
|
+
const dependencies = manifest[field];
|
|
1937
|
+
if (!isRecord(dependencies)) continue;
|
|
1938
|
+
updated[field] = Object.fromEntries(Object.entries(dependencies).map(([name, range]) => [name, name === "vite-hub" || name.startsWith("@vite-hub/") ? version : range]));
|
|
1939
|
+
}
|
|
1940
|
+
await writeFile(manifestFile, `${JSON.stringify(updated, null, 2)}\n`);
|
|
1941
|
+
}
|
|
1942
|
+
if (plan.packageManager === "pnpm" && !pnpmWorkspaceFile(target)) await writeFile(join(target, "pnpm-workspace.yaml"), templatePnpmWorkspace[plan.template]);
|
|
1943
|
+
await mkdir(plan.root, { recursive: true });
|
|
1944
|
+
for (const entry of await readdir(target)) await cp(join(target, entry), join(plan.root, entry), {
|
|
1945
|
+
errorOnExist: true,
|
|
1946
|
+
force: false,
|
|
1947
|
+
recursive: true
|
|
1948
|
+
});
|
|
1949
|
+
} finally {
|
|
1950
|
+
await rm(work, {
|
|
1951
|
+
force: true,
|
|
1952
|
+
recursive: true
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
if (!install) return;
|
|
1956
|
+
const result = await context.spawn(plan.packageManager, ["install"], {
|
|
1957
|
+
cwd: plan.root,
|
|
1958
|
+
env: context.env,
|
|
1959
|
+
stdout: "stderr"
|
|
1960
|
+
});
|
|
1961
|
+
if (result.exitCode !== 0) throw setupFailure(cliErrorDiagnostics.SETUP_INSTALL_FAILED({
|
|
1962
|
+
command: plan.install.command,
|
|
1963
|
+
exitCode: result.exitCode ?? result.signal,
|
|
1964
|
+
filesWritten: true
|
|
1965
|
+
}), setupExitCodes.error);
|
|
1966
|
+
}
|
|
1967
|
+
function writeTemplatePlan(plan, install, context) {
|
|
1968
|
+
context.stdout.write(`Download: ${plan.download.command}\n${install ? `Install: ${plan.install.command}\n` : ""}`);
|
|
1969
|
+
}
|
|
1970
|
+
async function runTemplate(args, prompts, context) {
|
|
1971
|
+
const root = resolve(context.rootDir, args.dir);
|
|
1972
|
+
await checkTemplateDir(root);
|
|
1973
|
+
const version = templateVersion();
|
|
1974
|
+
const plan = planTemplate(args, root, context, version);
|
|
1975
|
+
if (args.dryRun) {
|
|
1976
|
+
if (args.json) writeSetupJson(context, plan);
|
|
1977
|
+
else writeTemplatePlan(plan, args.install, context);
|
|
1978
|
+
return setupExitCodes.done;
|
|
1979
|
+
}
|
|
1980
|
+
if (!args.yes) {
|
|
1981
|
+
if (!prompts) {
|
|
1982
|
+
if (!args.json) writeTemplatePlan(plan, args.install, context);
|
|
1983
|
+
throw setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] `vitehub init` writes files and was not confirmed. Without a terminal, pass --yes." }), setupExitCodes.inputNeeded, {
|
|
1984
|
+
data: plan,
|
|
1985
|
+
rerun: templateCommand(args)
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
writeTemplatePlan(plan, args.install, context);
|
|
1989
|
+
if (!await prompts.confirm({
|
|
1990
|
+
initialValue: true,
|
|
1991
|
+
message: "Create the app?"
|
|
1992
|
+
})) throw setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] The change was not confirmed. Nothing was written." }), setupExitCodes.error);
|
|
1993
|
+
}
|
|
1994
|
+
await applyTemplate(plan, version, args.install, context);
|
|
1995
|
+
const applied = {
|
|
1996
|
+
...plan,
|
|
1997
|
+
status: "applied"
|
|
1998
|
+
};
|
|
1999
|
+
if (args.json) writeSetupJson(context, applied);
|
|
2000
|
+
else context.stdout.write(`Created ${root} from the ${initTemplateInfo[args.template].title} template of ViteHub v${version}.\n\nNext steps:\n${applied.nextSteps.map((step) => `- ${step}`).join("\n")}\n`);
|
|
2001
|
+
return setupExitCodes.done;
|
|
2002
|
+
}
|
|
1767
2003
|
/** Runs `vitehub init`. `wizard` gives the prompts for a person at a terminal; tests pass fake prompts. */
|
|
1768
2004
|
async function runInit(rawArgs, context, wizard = terminalWizard) {
|
|
1769
2005
|
let json = rawArgs.includes("--json");
|
|
@@ -1776,6 +2012,7 @@ async function runInit(rawArgs, context, wizard = terminalWizard) {
|
|
|
1776
2012
|
}
|
|
1777
2013
|
const prompts = parsed.json ? void 0 : await wizard();
|
|
1778
2014
|
const args = await readInputs(parsed, prompts, context);
|
|
2015
|
+
if (isTemplateInputs(args)) return await runTemplate(args, prompts, context);
|
|
1779
2016
|
const root = resolve(context.rootDir, args.dir);
|
|
1780
2017
|
let planned = await planWithAnswers(args, root, await readDir(root, context.env), context, prompts, parsed.features === void 0);
|
|
1781
2018
|
const plan = {
|
|
@@ -1829,7 +2066,7 @@ async function runInit(rawArgs, context, wizard = terminalWizard) {
|
|
|
1829
2066
|
}
|
|
1830
2067
|
}
|
|
1831
2068
|
const initCommandDefinition = {
|
|
1832
|
-
description: "Create a ViteHub app in a folder, or set up an existing Vite or Nuxt app, with a host and features.",
|
|
2069
|
+
description: "Create a ViteHub app in a folder, or set up an existing Vite or Nuxt app, with a host and features. --template starts a new app from a ViteHub template.",
|
|
1833
2070
|
name: "init",
|
|
1834
2071
|
run: (args, context) => runInit(args, context),
|
|
1835
2072
|
usage: usage$2
|
|
@@ -1903,11 +2140,11 @@ function isStarter(starter, path, content) {
|
|
|
1903
2140
|
return name !== void 0 && [starter.template, ...starter.previousTemplates ?? []].some((template) => template(name) === content);
|
|
1904
2141
|
}
|
|
1905
2142
|
function optionPrerequisites(id, value, unknown) {
|
|
1906
|
-
const options = isRecord
|
|
2143
|
+
const options = isRecord(value) ? value : void 0;
|
|
1907
2144
|
if (id === "cache" && (unknown || options?.driver === "kv")) return ["kv"];
|
|
1908
2145
|
if (id === "observability") return [...unknown || options?.posthog ? ["env"] : [], ...unknown || options?.papercuts ? ["agent", "console"] : []];
|
|
1909
2146
|
const invocations = options?.invocations;
|
|
1910
|
-
if (id === "agent" && (unknown || invocations === "database" || isRecord
|
|
2147
|
+
if (id === "agent" && (unknown || invocations === "database" || isRecord(invocations) && invocations.store === "database")) return ["database"];
|
|
1911
2148
|
return [];
|
|
1912
2149
|
}
|
|
1913
2150
|
/** Plans `vitehub remove` without writing anything. Throws `SetupFailure` when the change is not safe or not possible. */
|
|
@@ -2284,12 +2521,9 @@ function nextSpecifier(name, current, place, target) {
|
|
|
2284
2521
|
if (place === "override") return version;
|
|
2285
2522
|
return `${/^[\^~]/u.exec(current)?.[0] ?? (semver.valid(current) ? "" : "^")}${version}`;
|
|
2286
2523
|
}
|
|
2287
|
-
function isObject(value) {
|
|
2288
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2289
|
-
}
|
|
2290
2524
|
function visitManifest(manifest, visit) {
|
|
2291
2525
|
const entries = (holder, place, nameOf) => {
|
|
2292
|
-
if (!
|
|
2526
|
+
if (!isRecord(holder)) return;
|
|
2293
2527
|
for (const [key, value] of Object.entries(holder)) {
|
|
2294
2528
|
const name = nameOf(key);
|
|
2295
2529
|
if (typeof value === "string") {
|
|
@@ -2297,7 +2531,7 @@ function visitManifest(manifest, visit) {
|
|
|
2297
2531
|
name,
|
|
2298
2532
|
place
|
|
2299
2533
|
});
|
|
2300
|
-
} else if (place === "override" &&
|
|
2534
|
+
} else if (place === "override" && isRecord(value)) {
|
|
2301
2535
|
if (name && typeof value["."] === "string" && isReplaceable(value["."])) visit(value, ".", {
|
|
2302
2536
|
name,
|
|
2303
2537
|
place
|
|
@@ -2310,10 +2544,10 @@ function visitManifest(manifest, visit) {
|
|
|
2310
2544
|
for (const field of dependencyFields) entries(manifest[field], "dependency", plainName);
|
|
2311
2545
|
entries(manifest.overrides, "override", overrideTarget);
|
|
2312
2546
|
entries(manifest.resolutions, "override", overrideTarget);
|
|
2313
|
-
if (
|
|
2314
|
-
if (
|
|
2547
|
+
if (isRecord(manifest.pnpm)) entries(manifest.pnpm.overrides, "override", overrideTarget);
|
|
2548
|
+
if (isRecord(manifest.workspaces)) {
|
|
2315
2549
|
entries(manifest.workspaces.catalog, "dependency", plainName);
|
|
2316
|
-
if (
|
|
2550
|
+
if (isRecord(manifest.workspaces.catalogs)) for (const catalog of Object.values(manifest.workspaces.catalogs)) entries(catalog, "dependency", plainName);
|
|
2317
2551
|
}
|
|
2318
2552
|
}
|
|
2319
2553
|
function unquote(text) {
|
|
@@ -2445,7 +2679,7 @@ function workspacePatterns(yaml, manifest) {
|
|
|
2445
2679
|
return yamlList(lines, yamlBlocks(lines).get("packages")).map((item) => item.value);
|
|
2446
2680
|
}
|
|
2447
2681
|
const workspaces = manifest.workspaces;
|
|
2448
|
-
return (Array.isArray(workspaces) ? workspaces :
|
|
2682
|
+
return (Array.isArray(workspaces) ? workspaces : isRecord(workspaces) && Array.isArray(workspaces.packages) ? workspaces.packages : []).filter((item) => typeof item === "string");
|
|
2449
2683
|
}
|
|
2450
2684
|
async function workspaceRoot(start) {
|
|
2451
2685
|
if (setupLockfiles.some(([file]) => existsSync(join(start, file)))) return start;
|
|
@@ -2460,7 +2694,7 @@ async function workspaceRoot(start) {
|
|
|
2460
2694
|
}
|
|
2461
2695
|
async function readJson(file) {
|
|
2462
2696
|
const value = JSON.parse(await readFile(file, "utf8"));
|
|
2463
|
-
return
|
|
2697
|
+
return isRecord(value) ? value : {};
|
|
2464
2698
|
}
|
|
2465
2699
|
function stringifyLike(before, value) {
|
|
2466
2700
|
const indent = /^[ \t]+(?=")/mu.exec(before)?.[0] ?? " ";
|
|
@@ -2528,7 +2762,7 @@ async function resolvePackages(names, preview, context) {
|
|
|
2528
2762
|
});
|
|
2529
2763
|
if (preview) return;
|
|
2530
2764
|
const body = await response.json();
|
|
2531
|
-
const version =
|
|
2765
|
+
const version = isRecord(body) && typeof body.version === "string" ? body.version : void 0;
|
|
2532
2766
|
if (!version) throw cliErrorDiagnostics.CLI_UPDATE_REQUEST_FAILED({
|
|
2533
2767
|
status: "a response without a version",
|
|
2534
2768
|
url: target
|
|
@@ -2587,7 +2821,7 @@ async function planSetupUpdate(rootDir, args, context) {
|
|
|
2587
2821
|
const direct = /* @__PURE__ */ new Map();
|
|
2588
2822
|
for (const field of dependencyFields) {
|
|
2589
2823
|
const dependencies = manifest.value[field];
|
|
2590
|
-
if (!
|
|
2824
|
+
if (!isRecord(dependencies)) continue;
|
|
2591
2825
|
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));
|
|
2592
2826
|
}
|
|
2593
2827
|
let edited = false;
|