@vite-hub/cli 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
- import { F as featureHosts, H as installSpecifier, I as featureIds, L as featurePackages, R as featureSupport, V as impliedFeatures, m as cliErrorDiagnostics, z as features } from "./provision-DlknnTAt.js";
3
- import { B as listMatchingFiles, F as setupStatus, G as insertViteHubConfig, H as readSetupProject, I as shellQuote, K as locateViteHubConfig, L as uninstallArgs, M as installArgs, N as installCommand, P as missingProviderOption, U as setupLockfiles, V as detectPackageManager, W as editViteHubConfig, c as linkSetupProject, j as formatInstallCommand, l as readLinkHostOption, m as unlinkSetupProject, o as gitignoreWithViteHub, r as SETUP_LINK_FILE, u as readSetupLinkState, z as hasDefinitionFiles } from "./env-DRI0QH4-.js";
4
- import { a as table, i as setupFailure, n as readSetupArgs, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-DbplCDko.js";
5
- import { l as whoamiCommand, o as loginCommand, s as logoutCommand } from "./console-auth-CpOpbA7U.js";
6
- import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-BZ2iQjZL.js";
2
+ import { C as installArgs, D as shellQuote, E as setupStatus, G as setupFailure, H as isSetupFailure, J as writeSetupJson, K as table, M as listMatchingFiles, O as uninstallArgs, R as loginCommand, S as formatInstallCommand, St as installSpecifier, T as missingProviderOption, U as readSetupArgs, V as whoamiCommand, W as setupExitCodes, Y as cliErrorDiagnostics, _t as featureIds, bt as features, gt as featureHosts, j as hasDefinitionFiles, m as appsCommand, q as writeSetupError, vt as featurePackages, w as installCommand, xt as impliedFeatures, yt as featureSupport, z as logoutCommand } from "./provision-akHsvf-B.js";
3
+ import { B as insertViteHubConfig, I as detectPackageManager, L as readSetupProject, R as setupLockfiles, V as locateViteHubConfig, d as readSetupLinkState, h as unlinkSetupProject, i as SETUP_LINK_FILE, l as linkSetupProject, s as gitignoreWithViteHub, u as readLinkHostOption, z as editViteHubConfig } from "./env-BiVwma4a.js";
4
+ import { a as deploymentsCommand, i as STATUS_HOST_TIMEOUT_MS, o as liveLabel, s as readSetupLive, t as deployCommand } from "./deploy-DwNjKrHq.js";
7
5
  import { createRequire } from "node:module";
8
6
  import { existsSync, readFileSync } from "node:fs";
9
7
  import process from "node:process";
@@ -12,8 +10,8 @@ import { glob, mkdir, readFile, readdir, rm, rmdir, writeFile } from "node:fs/pr
12
10
  import { join as join$1 } from "node:path";
13
11
  import { createInterface } from "node:readline/promises";
14
12
  import { pathToFileURL } from "node:url";
15
- import { createTwoFilesPatch } from "diff";
16
13
  import { isDeepStrictEqual, parseArgs } from "node:util";
14
+ import { createTwoFilesPatch } from "diff";
17
15
  import semver, { Range, minVersion, satisfies, subset, validRange } from "semver";
18
16
  // ../internal/dist/feature-inputs.js
19
17
  function isLocaleTag(value) {
@@ -2628,6 +2626,7 @@ const setupCommands = [
2628
2626
  deploymentsCommand,
2629
2627
  loginCommand,
2630
2628
  logoutCommand,
2631
- whoamiCommand
2629
+ whoamiCommand,
2630
+ appsCommand
2632
2631
  ];
2633
2632
  export { applySetupAdd as _, updateCommand as a, planSetupRemove as c, initCommandDefinition as d, initPackages as f, addCommand as g, setupCatalog as h, readUpdateArgs as i, readRemoveArgs as l, readInitArgs as m, setupCommands as n, updateInstallArgs as o, nuxiPackage as p, planSetupUpdate as r, applySetupRemove as s, commands_exports as t, removeCommand as u, planSetupAdd as v, readAddArgs as y };
@@ -1,6 +1,4 @@
1
- import { m as cliErrorDiagnostics } from "./provision-DlknnTAt.js";
2
- import { c as readConsoleCredential, n as consoleOrigin } from "./console-auth-CpOpbA7U.js";
3
- import { o as writeSetupError, s as writeSetupJson } from "./envelope-DbplCDko.js";
1
+ import { B as readConsoleCredential, J as writeSetupJson, P as consoleOrigin, Y as cliErrorDiagnostics, q as writeSetupError } from "./provision-akHsvf-B.js";
4
2
  import { execFile } from "node:child_process";
5
3
  import { mkdtemp, open, rename, rm } from "node:fs/promises";
6
4
  import { join } from "node:path";
@@ -1,7 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
- import { A as readDeployCommit, C as denoOrganization, D as build, E as listCloudflareDeployments, F as setupStatus, H as readSetupProject, O as readBuildOutput, R as hostFromNitroPreset, S as denoAdapter, T as cloudflareAdapter, _ as listVercelDeployments, a as ensureViteHubGitignore, b as netlifyAdapter, f as readSetupLinks, g as hasVercelLogin, h as writeSeparateResourcesNote, i as addSetupLink, k as createDeployRun, l as readLinkHostOption, p as selectSetupLink, s as hostRequired, t as checkDeployEnv, v as vercelAdapter, w as listDenoDeployments, x as abortable, y as listNetlifyDeployments } from "./env-DRI0QH4-.js";
3
- import { C as callOperationFromCli, _ as readProvisionState, a as writeProvisionActions, d as planProvisionSteps, f as resolveHostCredentials, g as mergeProvisionState, h as PROVISION_STATE_FILE, i as provisionEnv, m as cliErrorDiagnostics, n as isProvisionHost, r as provisionActionStatus, y as writeProvisionState } from "./provision-DlknnTAt.js";
4
- import { a as table, i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-DbplCDko.js";
2
+ import { E as setupStatus, G as setupFailure, H as isSetupFailure, J as writeSetupJson, K as table, Q as readProvisionState, W as setupExitCodes, X as PROVISION_STATE_FILE, Y as cliErrorDiagnostics, Z as mergeProvisionState, a as writeProvisionActions, d as planProvisionSteps, et as writeProvisionState, f as resolveHostCredentials, i as provisionEnv, it as callOperationFromCli, k as hostFromNitroPreset, n as isProvisionHost, q as writeSetupError, r as provisionActionStatus } from "./provision-akHsvf-B.js";
3
+ import { A as openDeployConsole, C as denoAdapter, D as listCloudflareDeployments, E as cloudflareAdapter, F as readDeployCommit, L as readSetupProject, M as build, N as readBuildOutput, O as formatDeployConsole, P as createDeployRun, S as abortable, T as listDenoDeployments, _ as hasVercelLogin, a as addSetupLink, b as listNetlifyDeployments, c as hostRequired, g as writeSeparateResourcesNote, j as readsConsoleKey, k as linkDeployedApp, m as selectSetupLink, o as ensureViteHubGitignore, p as readSetupLinks, r as hostEnvs, t as checkDeployEnv, u as readLinkHostOption, v as listVercelDeployments, w as denoOrganization, x as netlifyAdapter, y as vercelAdapter } from "./env-BiVwma4a.js";
5
4
  import { createRequire } from "node:module";
6
5
  import { existsSync } from "node:fs";
7
6
  import process from "node:process";
@@ -724,7 +723,7 @@ const deployHosts = [
724
723
  "deno"
725
724
  ];
726
725
  const temporaryHosts = ["cloudflare", "vercel"];
727
- const usage = "vitehub deploy [--host <host>] [--preview] [--push-env] [--no-build] [--no-provision] [--no-push] [--no-check] [--no-index-now] [--temporary] [--yes] [--json]";
726
+ const usage = "vitehub deploy [--host <host>] [--preview] [--push-env] [--no-build] [--no-provision] [--no-push] [--no-check] [--no-index-now] [--no-console] [--temporary] [--yes] [--json]";
728
727
  const help = `--host picks a host target of .vitehub/link.json. Without it, deploy uses the default target. The build runs
729
728
  with VITEHUB_HOST set to that host, which wins over \`host\` in vitehub(). Each host has its own resources, such as D1,
730
729
  KV, R2, and libSQL.
@@ -746,8 +745,16 @@ omitted secret cannot inherit from another stage. With --yes, a missing VITEHUB_
746
745
 
747
746
  After the upload, deploy requests the paths of \`deploy.check\` in vitehub(), and the health route with \`health\`, on
748
747
  the deployed URL. When one does not answer with a 2xx status, deploy exits with 1 and prints the command that rolls
749
- production back to the deployment it replaced. --no-check skips the checks. With \`deploy.indexNow\`, a production
748
+ production back to the deployment it replaced. --no-check skips the checks. When the host reports no URL, such as a
749
+ Worker whose routes have a wildcard host or a narrower path, deploy skips the checks and IndexNow with a warning. With \`deploy.indexNow\`, a production
750
750
  deploy that passed its checks then sends the URLs of /sitemap.xml to IndexNow. --no-index-now skips it.
751
+
752
+ With \`console: true\` in vitehub() and a \`vitehub login\`, a production deploy links the app in that Console. It
753
+ links the deployed URL, sets the \`VITEHUB_CONSOLE_KEY_<NAME>\` key of the link on the host when the host lacks it,
754
+ checks that the app answers a signed request of the Console, and prints the Console page of the app. A second deploy
755
+ keeps the same link. On Cloudflare, it also re-supplies the key of the Console with each version. Other hosts read a
756
+ new variable on the next deploy, so the first deploy there deploys a second time. Without a login, deploy needs the
757
+ key on the host or in a local value, as for any other env name. --no-console skips the Console.
751
758
  `;
752
759
  function readDeployArgs(args) {
753
760
  try {
@@ -772,6 +779,10 @@ function readDeployArgs(args) {
772
779
  type: "boolean",
773
780
  default: false
774
781
  },
782
+ "no-console": {
783
+ type: "boolean",
784
+ default: false
785
+ },
775
786
  "no-index-now": {
776
787
  type: "boolean",
777
788
  default: false
@@ -807,6 +818,7 @@ function readDeployArgs(args) {
807
818
  return {
808
819
  build: !values["no-build"],
809
820
  check: !values["no-check"],
821
+ console: !values["no-console"],
810
822
  help: values.help,
811
823
  indexNow: !values["no-index-now"],
812
824
  ...values.host === void 0 ? {} : { host: values.host },
@@ -833,6 +845,7 @@ function rerunCommand(args, extra = {}) {
833
845
  ...args.push ? [] : ["--no-push"],
834
846
  ...args.check ? [] : ["--no-check"],
835
847
  ...args.indexNow ? [] : ["--no-index-now"],
848
+ ...args.console ? [] : ["--no-console"],
836
849
  ...args.temporary || extra.temporary ? ["--temporary"] : [],
837
850
  "--yes",
838
851
  ...args.json ? ["--json"] : []
@@ -934,11 +947,12 @@ async function recordLink(root, host, result, fallbackName) {
934
947
  await ensureViteHubGitignore(root);
935
948
  }
936
949
  function writeDeployed(output, name, context) {
937
- context.stdout.write(`Deployed ${name} to ${output.host}: ${output.url}\n`);
950
+ context.stdout.write(`Deployed ${name} to ${output.host}${output.url ? `: ${output.url}` : "."}\n`);
938
951
  if (output.deploymentId) context.stdout.write(`Deployment: ${output.deploymentId}\n`);
939
952
  if (output.version) context.stdout.write(`Version: ${output.version}\n`);
940
953
  if (output.commit) context.stdout.write(`Commit: ${output.commit.sha}${output.commit.dirty ? " (with uncommitted changes)" : ""}\n`);
941
954
  for (const check of output.checks ?? []) context.stdout.write(`Checked ${check.path}: ${check.status ?? check.error}\n`);
955
+ if (output.console) context.stdout.write(formatDeployConsole(output.console));
942
956
  if (output.temporary) {
943
957
  const window = output.host === "cloudflare" ? "within 60 minutes" : output.temporary.expiresAt ? `before ${output.temporary.expiresAt}` : "soon";
944
958
  context.stdout.write(`This is a temporary deploy. Claim it ${window}, or the host deletes it. Do not share the claim link:\n${output.temporary.claimUrl}\n`);
@@ -1006,8 +1020,12 @@ async function runDeploy(args, context) {
1006
1020
  });
1007
1021
  const secrets = credentials.ok ? [credentials.token] : [];
1008
1022
  const run = createDeployRun(context.stderr, secrets);
1023
+ const consoleStep = args.console && !args.temporary && readsConsoleKey(output.env) ? await openDeployConsole(context) : void 0;
1024
+ const availableConsole = consoleStep === "unavailable" ? void 0 : consoleStep;
1009
1025
  const env = await checkDeployEnv({
1010
1026
  context,
1027
+ ...availableConsole ? { consoleKeys: availableConsole.keys } : {},
1028
+ deferConsoleKey: !!consoleStep && !args.preview,
1011
1029
  entries: output.env,
1012
1030
  envDir: output.envDir,
1013
1031
  host,
@@ -1040,12 +1058,22 @@ async function runDeploy(args, context) {
1040
1058
  await env.apply();
1041
1059
  const checkPaths = args.check ? output.deploy.check : [];
1042
1060
  const previous = checkPaths.length && !args.preview && !args.temporary ? await previousDeployment(project.root, link, credentials, context, run) : void 0;
1043
- const result = await adapter.deploy();
1061
+ let result = await adapter.deploy();
1044
1062
  if (!link && !args.temporary) await recordLink(project.root, host, result, projectName);
1045
- const checks = checkPaths.length ? await runDeployChecks(result.url, checkPaths, deployContext.fetch) : void 0;
1063
+ const consoleDeploy = availableConsole && !args.preview ? await deployConsole(availableConsole, result, {
1064
+ context,
1065
+ deployContext,
1066
+ host,
1067
+ onHost: env.onHost,
1068
+ projectName
1069
+ }) : void 0;
1070
+ if (consoleDeploy) result = consoleDeploy.result;
1071
+ const linkedConsole = consoleDeploy?.output;
1072
+ if (checkPaths.length && !result.url) context.stderr.write(`Deploy checks skipped: ${host} reported no URL to request, such as a workers.dev URL, a custom domain, or a \`<host>/*\` route. The deploy is done.\n`);
1073
+ const checks = checkPaths.length && result.url ? await runDeployChecks(result.url, checkPaths, deployContext.fetch) : void 0;
1046
1074
  const deployed = {
1047
1075
  host,
1048
- url: result.url,
1076
+ ...result.url ? { url: result.url } : {},
1049
1077
  ...result.deploymentId ? { deploymentId: result.deploymentId } : {},
1050
1078
  ...result.version ? { version: result.version } : {},
1051
1079
  ...result.claim ? { temporary: {
@@ -1055,12 +1083,15 @@ async function runDeploy(args, context) {
1055
1083
  ...deployContext.commit ? { commit: deployContext.commit } : {},
1056
1084
  env: env.output,
1057
1085
  ...provisioned ? { provision: provisioned } : {},
1058
- ...checks ? { checks } : {}
1086
+ ...checks ? { checks } : {},
1087
+ ...linkedConsole ? { console: linkedConsole } : {}
1059
1088
  };
1060
1089
  if (checks?.some((check) => !check.ok)) throw checkFailed(deployed, host, previous, projectName, link, result, args.preview);
1061
1090
  if (!args.json) writeDeployed(deployed, projectName, context);
1062
1091
  const pushed = checkouts ? await pushCheckouts(checkouts, deployed, args, context) : deployed;
1063
- const indexNow = output.deploy.indexNow && args.indexNow && !args.preview && !args.temporary ? await submitIndexNow(output.deploy.indexNow, deployContext.fetch) : void 0;
1092
+ const indexNowConfig = args.indexNow && !args.preview && !args.temporary ? output.deploy.indexNow : void 0;
1093
+ if (indexNowConfig && !result.url) context.stderr.write(`IndexNow: nothing was sent, because ${host} reported no URL for this deploy.\n`);
1094
+ const indexNow = indexNowConfig && result.url ? await submitIndexNow(indexNowConfig, deployContext.fetch) : void 0;
1064
1095
  if (indexNow && !args.json) context.stderr.write("submitted" in indexNow ? `IndexNow: sent ${indexNow.submitted} URLs (${indexNow.status}).\n` : `IndexNow: nothing was sent. ${indexNow.error} The deploy is done.\n`);
1065
1096
  const final = indexNow ? {
1066
1097
  ...pushed,
@@ -1069,6 +1100,55 @@ async function runDeploy(args, context) {
1069
1100
  if (args.json) writeSetupJson(context, final);
1070
1101
  return setupExitCodes.done;
1071
1102
  }
1103
+ async function deployConsole(step, initial, options) {
1104
+ const { context, deployContext, host } = options;
1105
+ const productionUrl = (result) => host === "vercel" ? result.productionUrl : result.url;
1106
+ const url = productionUrl(initial);
1107
+ if (!url) {
1108
+ context.stderr.write(`The app was not linked in the Console, because ${host} reported no production URL. Run \`vitehub apps link <url>\` with the production URL of the app.\n`);
1109
+ return;
1110
+ }
1111
+ let result = initial;
1112
+ return {
1113
+ output: await linkDeployedApp({
1114
+ console: step,
1115
+ context,
1116
+ label: options.projectName,
1117
+ onHost: options.onHost,
1118
+ async setKey(name, value) {
1119
+ const link = deployContext.link ?? (await readSetupLinks(deployContext.root)).targets.find((target) => target.host === host);
1120
+ if (!link) throw cliErrorDiagnostics.SETUP_ENV_VALUE_UNSUPPORTED({
1121
+ host,
1122
+ name,
1123
+ reason: "The project has no host target in .vitehub/link.json."
1124
+ });
1125
+ await hostEnvs[host]({
1126
+ env: context.env,
1127
+ fetch: deployContext.fetch,
1128
+ link,
1129
+ root: deployContext.root,
1130
+ run: deployContext.run,
1131
+ secrets: deployContext.secrets,
1132
+ target: "production"
1133
+ }).setSecret(name, value, { secret: host === "cloudflare" });
1134
+ if (host === "cloudflare") {
1135
+ const { version: _version, ...live } = result;
1136
+ result = live;
1137
+ } else {
1138
+ context.stderr.write(`Deploying again, so ${host} reads ${name}.\n`);
1139
+ result = await (await hostAdapter(host, {
1140
+ ...deployContext,
1141
+ link,
1142
+ upload: {}
1143
+ })).deploy();
1144
+ }
1145
+ return productionUrl(result);
1146
+ },
1147
+ url
1148
+ }),
1149
+ result
1150
+ };
1151
+ }
1072
1152
  async function previousDeployment(root, link, credentials, context, run) {
1073
1153
  if (!link) return { failed: "the project was not linked before this deploy." };
1074
1154
  if (!credentials.ok) return { failed: `deploy used the saved ${link.host} CLI login, which gives no API token.` };