@vite-hub/cli 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/{commands-BQucvYlq.js → commands-W0ijB5R6.js} +329 -134
- package/dist/{console-auth-B0HxFFiX.js → console-auth-Dz9HHP2G.js} +2 -5
- package/dist/{console-env-DSAuhgRZ.js → console-env--3nqqpCV.js} +3 -8
- package/dist/{deploy-C0RdI5OK.js → deploy-CHW75le_.js} +4 -32
- package/dist/{env-B1Gg-WnA.js → env-MtXhP7A7.js} +236 -748
- package/dist/{envelope-B4mPbSbj.js → envelope-C7e408hm.js} +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +235 -69
- package/dist/{provision-DXl97xG0.js → provision-DgT_lpyn.js} +742 -20
- package/dist/{provision-C9p1wSzq.d.ts → provision-bhi-xnCG.d.ts} +2 -2
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/setup/index.d.ts +16 -10
- package/dist/setup/index.js +7 -8
- package/package.json +5 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as cliErrorDiagnostics } from "./provision-
|
|
2
|
-
import { o as writeSetupError, r as setupExitCodes, s as writeSetupJson } from "./envelope-
|
|
1
|
+
import { m as cliErrorDiagnostics } from "./provision-DgT_lpyn.js";
|
|
2
|
+
import { o as writeSetupError, r as setupExitCodes, s as writeSetupJson } from "./envelope-C7e408hm.js";
|
|
3
3
|
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { homedir, hostname } from "node:os";
|
|
@@ -32,7 +32,6 @@ async function readCredentials(file) {
|
|
|
32
32
|
consoles: consoles instanceof Object ? consoles : {}
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
/** Writes the file with mode 600 in a folder with mode 700. A temporary file and a rename keep it whole. */
|
|
36
35
|
async function writeCredentials(file, value) {
|
|
37
36
|
await mkdir(dirname(file), {
|
|
38
37
|
mode: 448,
|
|
@@ -130,11 +129,9 @@ const dateFormat = new Intl.DateTimeFormat("en-GB", {
|
|
|
130
129
|
year: "numeric",
|
|
131
130
|
timeZone: "UTC"
|
|
132
131
|
});
|
|
133
|
-
/** The user code in two groups, such as `WDJB-MJHT`, as RFC 8628 suggests. The Console accepts it with or without the dash. */
|
|
134
132
|
function groupCode(code) {
|
|
135
133
|
return code.length === 8 ? `${code.slice(0, 4)}-${code.slice(4)}` : code;
|
|
136
134
|
}
|
|
137
|
-
/** Runs the device flow against `origin` and returns the API key. The key is never written to a stream. */
|
|
138
135
|
async function deviceLogin(origin, context, prompt) {
|
|
139
136
|
const started = await postJson(context, `${origin}/api/auth/device/code`, {
|
|
140
137
|
client_id: clientId,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as cliErrorDiagnostics } from "./provision-
|
|
2
|
-
import { o as writeSetupError, s as writeSetupJson } from "./envelope-
|
|
3
|
-
import { c as readConsoleCredential, n as consoleOrigin } from "./console-auth-
|
|
1
|
+
import { m as cliErrorDiagnostics } from "./provision-DgT_lpyn.js";
|
|
2
|
+
import { o as writeSetupError, s as writeSetupJson } from "./envelope-C7e408hm.js";
|
|
3
|
+
import { c as readConsoleCredential, n as consoleOrigin } from "./console-auth-Dz9HHP2G.js";
|
|
4
4
|
import { execFile } from "node:child_process";
|
|
5
5
|
import { mkdtemp, open, rename, rm } from "node:fs/promises";
|
|
6
6
|
import { join } from "node:path";
|
|
@@ -20,7 +20,6 @@ function dotenvLine(name, value) {
|
|
|
20
20
|
if (!quote || value.includes("\r")) throw cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] Cannot represent ${name} faithfully in a dotenv file. Use a value without carriage returns and with an available dotenv quote delimiter.` });
|
|
21
21
|
return `${name}=${quote}${escaped}${quote}`;
|
|
22
22
|
}
|
|
23
|
-
/** Run git in `cwd`. `undefined` when git is missing. */
|
|
24
23
|
function git(cwd, args) {
|
|
25
24
|
return new Promise((resolve) => {
|
|
26
25
|
execFile("git", args, {
|
|
@@ -36,10 +35,6 @@ function git(cwd, args) {
|
|
|
36
35
|
});
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Git must not commit the file. In a repository, the file must be ignored and not tracked. Outside a repository, there is
|
|
41
|
-
* nothing to commit it to.
|
|
42
|
-
*/
|
|
43
38
|
async function checkIgnored(cwd, file) {
|
|
44
39
|
if (await git(cwd, ["rev-parse", "--is-inside-work-tree"]) !== 0) return;
|
|
45
40
|
if (await git(cwd, [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
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-
|
|
3
|
-
import { a as
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
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-DgT_lpyn.js";
|
|
3
|
+
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-MtXhP7A7.js";
|
|
4
|
+
import { a as table, i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-C7e408hm.js";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import process from "node:process";
|
|
@@ -121,7 +122,6 @@ const xmlEntities = {
|
|
|
121
122
|
lt: "<",
|
|
122
123
|
quot: "\""
|
|
123
124
|
};
|
|
124
|
-
/** Text of an XML element: CDATA kept as it is, named and numeric character references decoded. */
|
|
125
125
|
function decodeXml(text) {
|
|
126
126
|
return text.split(/(<!\[CDATA\[[\s\S]*?\]\]>)/u).map((part) => part.startsWith("<![CDATA[") ? part.slice(9, -3) : part.replace(/&(?:#x([\da-f]+)|#(\d+)|(amp|lt|gt|quot|apos));/giu, (match, hex, decimal, name) => {
|
|
127
127
|
if (name) return xmlEntities[name];
|
|
@@ -132,9 +132,7 @@ function decodeXml(text) {
|
|
|
132
132
|
function locations(xml) {
|
|
133
133
|
return [...xml.matchAll(/<loc>([\s\S]*?)<\/loc>/gu)].map((match) => decodeXml(match[1])).filter(Boolean);
|
|
134
134
|
}
|
|
135
|
-
/** IndexNow takes at most 10,000 URLs in one request. */
|
|
136
135
|
const indexNowBatch = 1e4;
|
|
137
|
-
/** A sitemap index may list sitemaps on other paths. Read at most this many. */
|
|
138
136
|
const nestedSitemapLimit = 50;
|
|
139
137
|
/**
|
|
140
138
|
* Reads `<url>/sitemap.xml`, one level of a sitemap index included, and sends every URL of the site to IndexNow.
|
|
@@ -196,23 +194,16 @@ async function submitIndexNow(indexNow, fetchImpl) {
|
|
|
196
194
|
}
|
|
197
195
|
//#endregion
|
|
198
196
|
//#region src/setup/deploy/checkouts.ts
|
|
199
|
-
/** The lock file of `vitehub pull` and `vitehub push`, at the project root. */
|
|
200
197
|
const lockFile = "vitehub.lock";
|
|
201
198
|
function isCheckoutModule(value) {
|
|
202
199
|
return Object(value) === value && typeof Reflect.get(Object(value), "localCheckoutStatus") === "function" && typeof Reflect.get(Object(value), "pullWorkspaces") === "function" && typeof Reflect.get(Object(value), "pushWorkspaces") === "function";
|
|
203
200
|
}
|
|
204
|
-
/** The checkout module of the Workspace package. */
|
|
205
201
|
const checkoutSpecifiers = ["@vite-hub/workspace/checkout", "vite-hub/workspace/checkout"];
|
|
206
|
-
/** True when `specifier` itself does not resolve: the package is not installed, or it has no `./checkout` export. */
|
|
207
202
|
function isNotInstalled(error, specifier) {
|
|
208
203
|
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
209
204
|
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return true;
|
|
210
205
|
return code === "MODULE_NOT_FOUND" && error instanceof Error && error.message.includes(`'${specifier}'`);
|
|
211
206
|
}
|
|
212
|
-
/**
|
|
213
|
-
* The checkout module of the Workspace package that the project installs. Undefined only when no specifier resolves.
|
|
214
|
-
* A module that resolves but does not load stops the deploy, because a silent skip would deploy without the push.
|
|
215
|
-
*/
|
|
216
207
|
async function importCheckoutModule(root) {
|
|
217
208
|
const require = createRequire(join(root, "package.json"));
|
|
218
209
|
for (const specifier of checkoutSpecifiers) {
|
|
@@ -241,10 +232,6 @@ function moduleFailure(specifier, file, error) {
|
|
|
241
232
|
specifier
|
|
242
233
|
}), setupExitCodes.error);
|
|
243
234
|
}
|
|
244
|
-
/**
|
|
245
|
-
* True when `vitehub.lock` lists at least one checkout folder. False without a lock. A lock that is not JSON, such as
|
|
246
|
-
* one with a Git conflict, counts, so the checkout module reports it.
|
|
247
|
-
*/
|
|
248
235
|
async function lockHasCheckouts(root) {
|
|
249
236
|
let source;
|
|
250
237
|
try {
|
|
@@ -367,11 +354,9 @@ const listers = {
|
|
|
367
354
|
netlify: listNetlifyDeployments,
|
|
368
355
|
vercel: listVercelDeployments
|
|
369
356
|
};
|
|
370
|
-
/** How long `vitehub deployments` waits for the host. */
|
|
371
357
|
const DEPLOYMENTS_TIMEOUT_MS = 3e4;
|
|
372
358
|
/** How long `vitehub status` waits for the host before it reports `liveReason: "timeout"`. */
|
|
373
359
|
const STATUS_HOST_TIMEOUT_MS = 5e3;
|
|
374
|
-
/** A fetch that gives up after `ms`, so a slow host cannot hold the command. */
|
|
375
360
|
function fetchWithTimeout(fetchImpl, ms, signal) {
|
|
376
361
|
return async (input, init) => {
|
|
377
362
|
signal?.throwIfAborted();
|
|
@@ -503,10 +488,6 @@ const deploymentsCommand = {
|
|
|
503
488
|
},
|
|
504
489
|
usage: usage$1
|
|
505
490
|
};
|
|
506
|
-
/**
|
|
507
|
-
* Compares the live commit with HEAD: `git rev-list --left-right --count <sha>...HEAD` prints the commits that only
|
|
508
|
-
* the deployment has, then the commits that only HEAD has.
|
|
509
|
-
*/
|
|
510
491
|
async function compareWithHead(run, root, env, sha) {
|
|
511
492
|
const git = async (args) => {
|
|
512
493
|
try {
|
|
@@ -606,7 +587,6 @@ async function readSetupLive(root, link, credentials, context, options) {
|
|
|
606
587
|
};
|
|
607
588
|
}
|
|
608
589
|
}
|
|
609
|
-
/** How long `vitehub deploy` waits for the host when it reads the deployment that a failed check rolls back to. */
|
|
610
590
|
const DEPLOY_PREVIOUS_TIMEOUT_MS = 1e4;
|
|
611
591
|
/**
|
|
612
592
|
* The deployment that receives production traffic now, read before `vitehub deploy` replaces it. It throws when the
|
|
@@ -649,12 +629,10 @@ function liveLabel(status) {
|
|
|
649
629
|
}
|
|
650
630
|
//#endregion
|
|
651
631
|
//#region src/setup/deploy/provision.ts
|
|
652
|
-
/** A step whose recorded state declares nothing has no resource to create, so deploy does not ask the host. */
|
|
653
632
|
function declaresResources(step, env) {
|
|
654
633
|
const described = step.recordedState?.({ env });
|
|
655
634
|
return described === void 0 || described.some((category) => category.declared.length > 0);
|
|
656
635
|
}
|
|
657
|
-
/** Says which credential the steps miss, for the reason of SETUP_DEPLOY_PROVISION_UNCHECKED. */
|
|
658
636
|
function missingCredential(host, env) {
|
|
659
637
|
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.";
|
|
660
638
|
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.";
|
|
@@ -886,7 +864,6 @@ async function resolveDefaultDeployTarget(root, env, command) {
|
|
|
886
864
|
link: selected.link
|
|
887
865
|
};
|
|
888
866
|
}
|
|
889
|
-
/** `--host`, else the default target, else the only target, else the config host. The CLI host wins over the config. */
|
|
890
867
|
function deployTarget(project, links, option, env) {
|
|
891
868
|
if (option !== void 0) {
|
|
892
869
|
const named = hostFromNitroPreset(option);
|
|
@@ -911,7 +888,6 @@ function deployTarget(project, links, option, env) {
|
|
|
911
888
|
function temporaryUnsupported(reason) {
|
|
912
889
|
return setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_TEMPORARY_UNSUPPORTED({ reason }), setupExitCodes.conflict);
|
|
913
890
|
}
|
|
914
|
-
/** Cloudflare: Wrangler refuses `--temporary` with a login. Vercel: the CLI refuses it in CI and in a linked folder. */
|
|
915
891
|
function assertTemporary(host, args, credentials, project, env) {
|
|
916
892
|
if (!temporaryHosts.includes(host)) throw temporaryUnsupported(`${host} has no temporary deploy. Only cloudflare and vercel have one.`);
|
|
917
893
|
if (args.preview) throw temporaryUnsupported("A temporary deploy always goes to production, so --preview does not apply.");
|
|
@@ -951,7 +927,6 @@ async function hostAdapter(host, context) {
|
|
|
951
927
|
case "deno": return await denoAdapter(context, denoOrganization(context.link, context.env));
|
|
952
928
|
}
|
|
953
929
|
}
|
|
954
|
-
/** Records the host project after a first deploy, so `status` finds it. It stays unverified until `vitehub link`. */
|
|
955
930
|
async function recordLink(root, host, result, fallbackName) {
|
|
956
931
|
const project = result.project ?? { name: fallbackName };
|
|
957
932
|
await addSetupLink(root, {
|
|
@@ -977,7 +952,6 @@ function writeDeployed(output, name, context) {
|
|
|
977
952
|
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`);
|
|
978
953
|
}
|
|
979
954
|
}
|
|
980
|
-
/** Pushes the checkout folders after the deploy. A failed push does not undo the deploy, so it exits with 1 and says so. */
|
|
981
955
|
async function pushCheckouts(checkouts, deployed, args, context) {
|
|
982
956
|
try {
|
|
983
957
|
const pushed = await pushDeployCheckouts(checkouts, context);
|
|
@@ -1103,7 +1077,6 @@ async function runDeploy(args, context) {
|
|
|
1103
1077
|
if (args.json) writeSetupJson(context, final);
|
|
1104
1078
|
return setupExitCodes.done;
|
|
1105
1079
|
}
|
|
1106
|
-
/** The deployment that serves production before this deploy. Without a link or a token there is nothing to read. */
|
|
1107
1080
|
async function previousDeployment(root, link, credentials, context, run) {
|
|
1108
1081
|
if (!link) return { failed: "the project was not linked before this deploy." };
|
|
1109
1082
|
if (!credentials.ok) return { failed: `deploy used the saved ${link.host} CLI login, which gives no API token.` };
|
|
@@ -1113,7 +1086,6 @@ async function previousDeployment(root, link, credentials, context, run) {
|
|
|
1113
1086
|
return { failed: error instanceof Error ? error.message : String(error) };
|
|
1114
1087
|
}
|
|
1115
1088
|
}
|
|
1116
|
-
/** A deployed app that failed a check. Production now serves it, so the error says how to roll back. */
|
|
1117
1089
|
function checkFailed(deployed, host, previous, projectName, link, result, preview) {
|
|
1118
1090
|
const rollback = preview ? { note: "This was a preview deploy, so production did not change." } : rollbackFor(host, {
|
|
1119
1091
|
previous: previous && "deployment" in previous ? previous.deployment : void 0,
|