@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.
@@ -1,9 +1,12 @@
1
- import { B as readConsoleCredential, J as writeSetupJson, P as consoleOrigin, Y as cliErrorDiagnostics, q as writeSetupError } from "./provision-YzxNsbhs.js";
1
+ import { d as cliErrorDiagnostics } from "./provision-9QsGgeiq.js";
2
+ import { u as selectConsole } from "./console-auth-cCodgT_T.js";
3
+ import { c as __exportAll, o as writeSetupError, s as writeSetupJson } from "./envelope-BJQ7xPyX.js";
2
4
  import { execFile } from "node:child_process";
3
5
  import { mkdtemp, open, rename, rm } from "node:fs/promises";
4
6
  import { join } from "node:path";
5
7
  import { parseArgs } from "node:util";
6
8
  // src/setup/console-env.ts
9
+ var console_env_exports = /* @__PURE__ */ __exportAll({ envPullFeature: () => envPullFeature });
7
10
  const pullUsage = "vitehub env pull --from console [--stage <name>] [--project <id>] [--console <url>] [--yes] [--json]";
8
11
  const stagePattern = /^[a-z0-9][a-z0-9_-]{0,62}$/;
9
12
  /** One line of a `.env` file. A value that a parser could read in two ways goes in quotes. */
@@ -121,8 +124,8 @@ const envPullFeature = {
121
124
  const file = `.env.${values.stage}`;
122
125
  const target = join(context.cwd, file);
123
126
  await checkIgnored(context.cwd, file);
124
- const credential = await readConsoleCredential(context.env, values.console);
125
- if (!credential) throw cliErrorDiagnostics.CLI_CONSOLE_SIGNED_OUT({ console: consoleOrigin(values.console ?? context.env["VITEHUB_CONSOLE_URL"] ?? "https://console.vitehub.dev") });
127
+ const { origin, credential } = await selectConsole(context, values.console);
128
+ if (!credential) throw cliErrorDiagnostics.CLI_CONSOLE_SIGNED_OUT({ console: origin });
126
129
  const request = async (path, init = {}) => {
127
130
  const response = await (context.fetch ?? fetch)(`${credential.origin}${path}`, {
128
131
  ...init,
@@ -187,4 +190,4 @@ const envPullFeature = {
187
190
  }
188
191
  }
189
192
  };
190
- export { envPullFeature };
193
+ export { dotenvLine as n, console_env_exports as t };
@@ -1,13 +1,18 @@
1
- import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.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-YzxNsbhs.js";
3
- import { A as openDeployConsole, B as readSetupProject, C as denoAdapter, D as listCloudflareDeployments, E as cloudflareAdapter, F as readDeployCommit, 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-DzYHxq9A.js";
1
+ import { c as shellQuote, s as setupStatus, u as hostFromNitroPreset } from "./status-gjvZVutV.js";
2
+ import { d as cliErrorDiagnostics, l as resolveHostCredentials, o as planProvisionSteps } from "./provision-9QsGgeiq.js";
3
+ import { a as netlifyAdapter, c as listDenoDeployments, d as formatDeployConsole, f as linkDeployedApp, g as readBuildOutput, h as build, i as listNetlifyDeployments, l as cloudflareAdapter, m as readsConsoleKey, o as denoAdapter, p as openDeployConsole, r as hostEnvs, s as denoOrganization, t as checkDeployEnv, u as listCloudflareDeployments } from "./env-D_CN5DyX.js";
4
+ import { a as provisionStateFile, c as mergeProvisionState, d as writeProvisionState, i as provisionHostEnv, l as readProvisionState, n as isProvisionHost, o as writeProvisionActions, p as callOperationFromCli, r as provisionActionStatus } from "./provision-Fiosv3Un.js";
5
+ import { a as table, c as __exportAll, i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-BJQ7xPyX.js";
6
+ import { a as vercelDeployLink, f as createDeployRun, i as vercelAdapter, l as abortable, n as listVercelDeployments, r as resolveVercelTarget, t as hasVercelLogin, x as readDeployCommit } from "./vercel-B5CJLsT0.js";
7
+ import { a as hostRequired, f as readSetupLinks, h as writeSeparateResourcesNote, l as readLinkHostOption, n as addSetupLink, p as selectSetupLink, r as ensureViteHubGitignore } from "./link-BRNWNqT9.js";
8
+ import { g as readSetupProject } from "./console-auth-cCodgT_T.js";
4
9
  import { createRequire } from "node:module";
5
10
  import { existsSync } from "node:fs";
6
11
  import process from "node:process";
12
+ import { pathToFileURL } from "node:url";
7
13
  import { basename, join } from "pathe";
8
14
  import { readFile } from "node:fs/promises";
9
15
  import { createInterface } from "node:readline/promises";
10
- import { pathToFileURL } from "node:url";
11
16
  import { parseArgs } from "node:util";
12
17
  // src/setup/deploy/after.ts
13
18
  /** Waits between the attempts of one path: a new version can take a few seconds to reach every edge location. */
@@ -626,13 +631,17 @@ function liveLabel(status) {
626
631
  }
627
632
  // src/setup/deploy/provision.ts
628
633
  function declaresResources(step, env) {
634
+ if (step.hasResources) return step.hasResources({ env });
629
635
  const described = step.recordedState?.({ env });
630
636
  return described === void 0 || described.some((category) => category.declared.length > 0);
631
637
  }
632
- function missingCredential(host, env) {
638
+ function missingCredential(host, env, link) {
633
639
  if (host === "cloudflare" && !env.CLOUDFLARE_ACCOUNT_ID?.trim()) return "Set CLOUDFLARE_ACCOUNT_ID, or run `vitehub link --host cloudflare --account <id>`. A `wrangler login` with several accounts does not say which one to use.";
634
640
  if (host === "vercel" && !env.VERCEL_TOKEN?.trim()) return "A saved `vercel login` cannot create Vercel resources. Set VERCEL_TOKEN to a token from https://vercel.com/account/tokens.";
635
- if (host === "vercel" && !env.VERCEL_PROJECT_ID?.trim()) return "Run `vitehub link --host vercel` to store the project id, or set VERCEL_PROJECT_ID.";
641
+ if (host === "vercel" && !env.VERCEL_PROJECT_ID?.trim()) {
642
+ if (link) return "Run `vitehub link --host vercel` with VERCEL_TOKEN to verify the project and store its id.";
643
+ return "Run `vitehub link --host vercel` or `vercel link` to store the project id, or set VERCEL_PROJECT_ID.";
644
+ }
636
645
  return "Fix the cause of the warnings.";
637
646
  }
638
647
  async function confirmProvision(count, host) {
@@ -654,11 +663,12 @@ async function confirmProvision(count, host) {
654
663
  async function provisionForDeploy(input, context) {
655
664
  const { host } = input;
656
665
  if (!isProvisionHost(host) || !context.loadProvision) return;
657
- const env = provisionEnv(context.env, input.credentials, {
658
- ...input.link?.account?.id ? { accountId: input.link.account.id } : {},
659
- ...input.link?.project.id ? { projectId: input.link.project.id } : {}
660
- });
661
666
  const loaded = await context.loadProvision(host);
667
+ const credentialEnv = provisionHostEnv(context.env, input.credentials, input.link);
668
+ const env = {
669
+ ...loaded.env,
670
+ ...credentialEnv
671
+ };
662
672
  const steps = loaded.steps.filter((step) => step.provider === host && declaresResources(step, env));
663
673
  if (!steps.length) return;
664
674
  const root = loaded.rootDir;
@@ -673,7 +683,7 @@ async function provisionForDeploy(input, context) {
673
683
  });
674
684
  if (!plan.checked) throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_PROVISION_UNCHECKED({
675
685
  host,
676
- missing: missingCredential(host, env),
686
+ missing: missingCredential(host, env, input.link),
677
687
  warnings: plan.warnings.join(" ")
678
688
  }), setupExitCodes.inputNeeded, { rerun: input.rerun });
679
689
  const changes = plan.actions.flatMap((planned) => {
@@ -703,7 +713,7 @@ async function provisionForDeploy(input, context) {
703
713
  } finally {
704
714
  if (Object.keys(state).length) await writeProvisionState(root, state);
705
715
  }
706
- if (changes.length && !input.json) context.stdout.write(`Provisioned ${changes.length} ${changes.length === 1 ? "resource" : "resources"} on ${host}. Ids are in ${PROVISION_STATE_FILE}.\n`);
716
+ if (changes.length && !input.json) context.stdout.write(`Provisioned ${changes.length} ${changes.length === 1 ? "resource" : "resources"} on ${host}. Ids are in ${provisionStateFile(root, context.cwd)}.\n`);
707
717
  return {
708
718
  changed: changes.map(({ planned, status }) => ({
709
719
  kind: planned.action.kind,
@@ -941,10 +951,10 @@ async function recordLink(root, host, result, fallbackName) {
941
951
  ...project.id ? { id: project.id } : {},
942
952
  name: project.name
943
953
  },
954
+ ...host === "cloudflare" ? { resourceScope: fallbackName } : {},
944
955
  verified: false,
945
956
  linkedAt: (/* @__PURE__ */ new Date()).toISOString()
946
957
  });
947
- await ensureViteHubGitignore(root);
948
958
  }
949
959
  function writeDeployed(output, name, context) {
950
960
  context.stdout.write(`Deployed ${name} to ${output.host}${output.url ? `: ${output.url}` : "."}\n`);
@@ -984,7 +994,7 @@ async function pushCheckouts(checkouts, deployed, args, context) {
984
994
  async function runDeploy(args, context) {
985
995
  const project = await readSetupProject(context.rootDir, context.env);
986
996
  const links = await readSetupLinks(project.root);
987
- const { host, link } = deployTarget(project, links, args.host, context.env);
997
+ const { host, link: savedLink } = deployTarget(project, links, args.host, context.env);
988
998
  if (args.preview && host === "deno") throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_PREVIEW_UNSUPPORTED({ host }), setupExitCodes.conflict);
989
999
  const credentials = await resolveHostCredentials(host, {
990
1000
  cwd: project.root,
@@ -995,6 +1005,7 @@ async function runDeploy(args, context) {
995
1005
  if (args.temporary && vercelLogin) throw temporaryUnsupported("It is for a machine without a vercel login, and a saved CLI login was found.");
996
1006
  if (args.temporary) assertTemporary(host, args, credentials, project, context.env);
997
1007
  else if (!credentials.ok && !vercelLogin) throw credentialsMissing(host, credentials, args);
1008
+ const link = host === "vercel" && !args.temporary ? await resolveVercelTarget(project.root, context.env, savedLink) : savedLink;
998
1009
  const interactive = !args.json && !!process.stdin.isTTY && !!process.stderr.isTTY;
999
1010
  if (!args.yes) {
1000
1011
  if (!interactive) throw setupFailure(cliErrorDiagnostics.CLI_R0004({ message: "[vitehub] `vitehub deploy` publishes the app and was not confirmed. Without a terminal, pass --yes." }), setupExitCodes.inputNeeded, { rerun: rerunCommand(args) });
@@ -1014,10 +1025,12 @@ async function runDeploy(args, context) {
1014
1025
  if (args.build) await build(project, host, context);
1015
1026
  const output = await readBuildOutput(project.root, host);
1016
1027
  const projectName = link?.project.name ?? output.identityName;
1028
+ if (!args.temporary && savedLink && link && output.identityName && output.identityName !== link.project.name) writeLinkedNameNote(context, host, link, output.identityName);
1017
1029
  if (!projectName) throw setupFailure(cliErrorDiagnostics.SETUP_LINK_NAME_REQUIRED(), setupExitCodes.inputNeeded, {
1018
1030
  missing: [{ field: "project" }],
1019
1031
  rerun: "vitehub link --project <name>"
1020
1032
  });
1033
+ const deployLink = host === "vercel" && !args.temporary ? link ?? vercelDeployLink(projectName, context.env) : link;
1021
1034
  const secrets = credentials.ok ? [credentials.token] : [];
1022
1035
  const run = createDeployRun(context.stderr, secrets);
1023
1036
  const consoleStep = args.console && !args.temporary && readsConsoleKey(output.env) ? await openDeployConsole(context) : void 0;
@@ -1030,7 +1043,7 @@ async function runDeploy(args, context) {
1030
1043
  envDir: output.envDir,
1031
1044
  host,
1032
1045
  interactive,
1033
- link: args.temporary ? void 0 : link,
1046
+ link: args.temporary ? void 0 : deployLink,
1034
1047
  outputDir: output.outputDir,
1035
1048
  preview: args.preview,
1036
1049
  pushEnv: args.pushEnv,
@@ -1044,7 +1057,7 @@ async function runDeploy(args, context) {
1044
1057
  credentials,
1045
1058
  env: context.env,
1046
1059
  fetch: context.fetch ?? globalThis.fetch,
1047
- link,
1060
+ link: deployLink,
1048
1061
  outputDir: output.outputDir,
1049
1062
  preview: args.preview,
1050
1063
  projectName,
@@ -1059,7 +1072,10 @@ async function runDeploy(args, context) {
1059
1072
  const checkPaths = args.check ? output.deploy.check : [];
1060
1073
  const previous = checkPaths.length && !args.preview && !args.temporary ? await previousDeployment(project.root, link, credentials, context, run) : void 0;
1061
1074
  let result = await adapter.deploy();
1062
- if (!link && !args.temporary) await recordLink(project.root, host, result, projectName);
1075
+ if (!args.temporary) {
1076
+ if (!savedLink) await recordLink(project.root, host, result, projectName);
1077
+ await ensureViteHubGitignore(project.root, host);
1078
+ }
1063
1079
  const consoleDeploy = availableConsole && !args.preview ? await deployConsole(availableConsole, result, {
1064
1080
  context,
1065
1081
  deployContext,
@@ -1100,6 +1116,22 @@ async function runDeploy(args, context) {
1100
1116
  if (args.json) writeSetupJson(context, final);
1101
1117
  return setupExitCodes.done;
1102
1118
  }
1119
+ function writeLinkedNameNote(context, host, link, built) {
1120
+ const linked = JSON.stringify(link.project.name);
1121
+ const buildName = JSON.stringify(built);
1122
+ const selector = {
1123
+ cloudflare: "account-id",
1124
+ deno: "organization",
1125
+ netlify: "team-slug",
1126
+ vercel: "team-id"
1127
+ }[host];
1128
+ const account = host === "netlify" ? void 0 : link.account?.id;
1129
+ const placeholder = `<${selector}>`;
1130
+ const command = `vitehub link --host ${host} --project ${shellQuote(built)} --account ${account ? shellQuote(account) : placeholder}${host === "deno" ? "" : " --create"}`;
1131
+ const chooseAccount = account ? "" : ` Replace ${placeholder} with the ${host} ${selector.replaceAll("-", " ")} you want to use.`;
1132
+ const createFirst = host === "deno" ? "create the app in Deno Deploy first, then " : "";
1133
+ context.stderr.write(`[vitehub] Deploying to the ${host} project ${linked} of .vitehub/link.json. The build names the app ${buildName}, but the link wins. To deploy to ${buildName}, ${createFirst}run \`${command}\` and deploy again.${chooseAccount} To keep ${linked}, set \`name: ${linked}\` in the ViteHub options.\n`);
1134
+ }
1103
1135
  async function deployConsole(step, initial, options) {
1104
1136
  const { context, deployContext, host } = options;
1105
1137
  const productionUrl = (result) => host === "vercel" ? result.productionUrl : result.url;