@vite-hub/cli 0.4.1 → 0.5.1
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-C003KqWY.js} +359 -158
- package/dist/{console-auth-B0HxFFiX.js → console-auth-CpOpbA7U.js} +3 -7
- package/dist/{console-env-DSAuhgRZ.js → console-env-CsBruJnE.js} +4 -10
- package/dist/{deploy-C0RdI5OK.js → deploy-BZ2iQjZL.js} +10 -47
- package/dist/{env-B1Gg-WnA.js → env-DRI0QH4-.js} +1160 -1099
- package/dist/{envelope-B4mPbSbj.js → envelope-DbplCDko.js} +2 -3
- package/dist/index.d.ts +2 -4
- package/dist/index.js +241 -83
- package/dist/{provision-DXl97xG0.js → provision-DlknnTAt.js} +916 -204
- package/dist/{provision-C9p1wSzq.d.ts → provision-kiD8Emd7.d.ts} +1 -9
- package/dist/rolldown-runtime-BJohB4LM.js +13 -0
- package/dist/setup/index.d.ts +16 -61
- package/dist/setup/index.js +8 -10
- package/package.json +13 -12
|
@@ -1,10 +1,10 @@
|
|
|
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-DlknnTAt.js";
|
|
2
|
+
import { o as writeSetupError, r as setupExitCodes, s as writeSetupJson } from "./envelope-DbplCDko.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";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
|
-
|
|
7
|
+
// src/setup/console-auth.ts
|
|
8
8
|
/** The hosted Console. `--console` and `VITEHUB_CONSOLE_URL` name a self-hosted one. */
|
|
9
9
|
const defaultConsoleUrl = "https://console.vitehub.dev";
|
|
10
10
|
/** An API key for CI. It wins over the saved key, and `vitehub logout` does not remove it. */
|
|
@@ -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,
|
|
@@ -311,5 +308,4 @@ const logoutCommand = {
|
|
|
311
308
|
}
|
|
312
309
|
}
|
|
313
310
|
};
|
|
314
|
-
//#endregion
|
|
315
311
|
export { defaultConsoleUrl as a, readConsoleCredential as c, consoleUrlVariable as i, whoamiCommand as l, consoleOrigin as n, loginCommand as o, consoleTokenVariable as r, logoutCommand as s, consoleCredentialsFile as t };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { m as cliErrorDiagnostics } from "./provision-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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";
|
|
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";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
|
-
|
|
8
|
+
// src/setup/console-env.ts
|
|
9
9
|
const pullUsage = "vitehub env pull --from console [--stage <name>] [--project <id>] [--console <url>] [--yes] [--json]";
|
|
10
10
|
const stagePattern = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
11
11
|
/** One line of a `.env` file. A value that a parser could read in two ways goes in quotes. */
|
|
@@ -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, [
|
|
@@ -194,5 +189,4 @@ const envPullFeature = {
|
|
|
194
189
|
}
|
|
195
190
|
}
|
|
196
191
|
};
|
|
197
|
-
//#endregion
|
|
198
192
|
export { envPullFeature };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C as
|
|
3
|
-
import { a as
|
|
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";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import process from "node:process";
|
|
@@ -9,7 +10,7 @@ import { readFile } from "node:fs/promises";
|
|
|
9
10
|
import { createInterface } from "node:readline/promises";
|
|
10
11
|
import { pathToFileURL } from "node:url";
|
|
11
12
|
import { parseArgs } from "node:util";
|
|
12
|
-
|
|
13
|
+
// src/setup/deploy/after.ts
|
|
13
14
|
/** Waits between the attempts of one path: a new version can take a few seconds to reach every edge location. */
|
|
14
15
|
const checkRetryDelaysMs = [
|
|
15
16
|
1e3,
|
|
@@ -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.
|
|
@@ -194,25 +192,17 @@ async function submitIndexNow(indexNow, fetchImpl) {
|
|
|
194
192
|
submitted: urlList.length
|
|
195
193
|
};
|
|
196
194
|
}
|
|
197
|
-
|
|
198
|
-
//#region src/setup/deploy/checkouts.ts
|
|
199
|
-
/** The lock file of `vitehub pull` and `vitehub push`, at the project root. */
|
|
195
|
+
// src/setup/deploy/checkouts.ts
|
|
200
196
|
const lockFile = "vitehub.lock";
|
|
201
197
|
function isCheckoutModule(value) {
|
|
202
198
|
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
199
|
}
|
|
204
|
-
/** The checkout module of the Workspace package. */
|
|
205
200
|
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
201
|
function isNotInstalled(error, specifier) {
|
|
208
202
|
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
209
203
|
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return true;
|
|
210
204
|
return code === "MODULE_NOT_FOUND" && error instanceof Error && error.message.includes(`'${specifier}'`);
|
|
211
205
|
}
|
|
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
206
|
async function importCheckoutModule(root) {
|
|
217
207
|
const require = createRequire(join(root, "package.json"));
|
|
218
208
|
for (const specifier of checkoutSpecifiers) {
|
|
@@ -241,10 +231,6 @@ function moduleFailure(specifier, file, error) {
|
|
|
241
231
|
specifier
|
|
242
232
|
}), setupExitCodes.error);
|
|
243
233
|
}
|
|
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
234
|
async function lockHasCheckouts(root) {
|
|
249
235
|
let source;
|
|
250
236
|
try {
|
|
@@ -358,8 +344,7 @@ function formatDeployCheckouts(pushed) {
|
|
|
358
344
|
if (!pushed.changed.length) return text;
|
|
359
345
|
return `${text}The push changed these files. Commit them:\n${pushed.changed.map((path) => ` ${path}`).join("\n")}\n`;
|
|
360
346
|
}
|
|
361
|
-
|
|
362
|
-
//#region src/setup/deployments.ts
|
|
347
|
+
// src/setup/deployments.ts
|
|
363
348
|
const usage$1 = "vitehub deployments [--host <host>] [--limit <n>] [--json]";
|
|
364
349
|
const listers = {
|
|
365
350
|
cloudflare: listCloudflareDeployments,
|
|
@@ -367,11 +352,9 @@ const listers = {
|
|
|
367
352
|
netlify: listNetlifyDeployments,
|
|
368
353
|
vercel: listVercelDeployments
|
|
369
354
|
};
|
|
370
|
-
/** How long `vitehub deployments` waits for the host. */
|
|
371
355
|
const DEPLOYMENTS_TIMEOUT_MS = 3e4;
|
|
372
356
|
/** How long `vitehub status` waits for the host before it reports `liveReason: "timeout"`. */
|
|
373
357
|
const STATUS_HOST_TIMEOUT_MS = 5e3;
|
|
374
|
-
/** A fetch that gives up after `ms`, so a slow host cannot hold the command. */
|
|
375
358
|
function fetchWithTimeout(fetchImpl, ms, signal) {
|
|
376
359
|
return async (input, init) => {
|
|
377
360
|
signal?.throwIfAborted();
|
|
@@ -503,10 +486,6 @@ const deploymentsCommand = {
|
|
|
503
486
|
},
|
|
504
487
|
usage: usage$1
|
|
505
488
|
};
|
|
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
489
|
async function compareWithHead(run, root, env, sha) {
|
|
511
490
|
const git = async (args) => {
|
|
512
491
|
try {
|
|
@@ -606,7 +585,6 @@ async function readSetupLive(root, link, credentials, context, options) {
|
|
|
606
585
|
};
|
|
607
586
|
}
|
|
608
587
|
}
|
|
609
|
-
/** How long `vitehub deploy` waits for the host when it reads the deployment that a failed check rolls back to. */
|
|
610
588
|
const DEPLOY_PREVIOUS_TIMEOUT_MS = 1e4;
|
|
611
589
|
/**
|
|
612
590
|
* The deployment that receives production traffic now, read before `vitehub deploy` replaces it. It throws when the
|
|
@@ -647,14 +625,11 @@ function liveLabel(status) {
|
|
|
647
625
|
if (live.commit?.dirty) notes.push("with uncommitted changes");
|
|
648
626
|
return `${name} (${notes.join(", ")})${live.url ? ` ${live.url}` : ""}`;
|
|
649
627
|
}
|
|
650
|
-
|
|
651
|
-
//#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. */
|
|
628
|
+
// src/setup/deploy/provision.ts
|
|
653
629
|
function declaresResources(step, env) {
|
|
654
630
|
const described = step.recordedState?.({ env });
|
|
655
631
|
return described === void 0 || described.some((category) => category.declared.length > 0);
|
|
656
632
|
}
|
|
657
|
-
/** Says which credential the steps miss, for the reason of SETUP_DEPLOY_PROVISION_UNCHECKED. */
|
|
658
633
|
function missingCredential(host, env) {
|
|
659
634
|
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
635
|
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.";
|
|
@@ -740,13 +715,8 @@ async function provisionForDeploy(input, context) {
|
|
|
740
715
|
ids: state[host] ?? {}
|
|
741
716
|
};
|
|
742
717
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
var deploy_exports = /* @__PURE__ */ __exportAll({
|
|
746
|
-
deployCommand: () => deployCommand,
|
|
747
|
-
readDeployArgs: () => readDeployArgs,
|
|
748
|
-
resolveDefaultDeployTarget: () => resolveDefaultDeployTarget
|
|
749
|
-
});
|
|
718
|
+
// src/setup/deploy.ts
|
|
719
|
+
var deploy_exports = /* @__PURE__ */ __exportAll({ resolveDefaultDeployTarget: () => resolveDefaultDeployTarget });
|
|
750
720
|
const deployHosts = [
|
|
751
721
|
"cloudflare",
|
|
752
722
|
"vercel",
|
|
@@ -886,7 +856,6 @@ async function resolveDefaultDeployTarget(root, env, command) {
|
|
|
886
856
|
link: selected.link
|
|
887
857
|
};
|
|
888
858
|
}
|
|
889
|
-
/** `--host`, else the default target, else the only target, else the config host. The CLI host wins over the config. */
|
|
890
859
|
function deployTarget(project, links, option, env) {
|
|
891
860
|
if (option !== void 0) {
|
|
892
861
|
const named = hostFromNitroPreset(option);
|
|
@@ -911,7 +880,6 @@ function deployTarget(project, links, option, env) {
|
|
|
911
880
|
function temporaryUnsupported(reason) {
|
|
912
881
|
return setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_TEMPORARY_UNSUPPORTED({ reason }), setupExitCodes.conflict);
|
|
913
882
|
}
|
|
914
|
-
/** Cloudflare: Wrangler refuses `--temporary` with a login. Vercel: the CLI refuses it in CI and in a linked folder. */
|
|
915
883
|
function assertTemporary(host, args, credentials, project, env) {
|
|
916
884
|
if (!temporaryHosts.includes(host)) throw temporaryUnsupported(`${host} has no temporary deploy. Only cloudflare and vercel have one.`);
|
|
917
885
|
if (args.preview) throw temporaryUnsupported("A temporary deploy always goes to production, so --preview does not apply.");
|
|
@@ -951,7 +919,6 @@ async function hostAdapter(host, context) {
|
|
|
951
919
|
case "deno": return await denoAdapter(context, denoOrganization(context.link, context.env));
|
|
952
920
|
}
|
|
953
921
|
}
|
|
954
|
-
/** Records the host project after a first deploy, so `status` finds it. It stays unverified until `vitehub link`. */
|
|
955
922
|
async function recordLink(root, host, result, fallbackName) {
|
|
956
923
|
const project = result.project ?? { name: fallbackName };
|
|
957
924
|
await addSetupLink(root, {
|
|
@@ -977,7 +944,6 @@ function writeDeployed(output, name, context) {
|
|
|
977
944
|
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
945
|
}
|
|
979
946
|
}
|
|
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
947
|
async function pushCheckouts(checkouts, deployed, args, context) {
|
|
982
948
|
try {
|
|
983
949
|
const pushed = await pushDeployCheckouts(checkouts, context);
|
|
@@ -1103,7 +1069,6 @@ async function runDeploy(args, context) {
|
|
|
1103
1069
|
if (args.json) writeSetupJson(context, final);
|
|
1104
1070
|
return setupExitCodes.done;
|
|
1105
1071
|
}
|
|
1106
|
-
/** The deployment that serves production before this deploy. Without a link or a token there is nothing to read. */
|
|
1107
1072
|
async function previousDeployment(root, link, credentials, context, run) {
|
|
1108
1073
|
if (!link) return { failed: "the project was not linked before this deploy." };
|
|
1109
1074
|
if (!credentials.ok) return { failed: `deploy used the saved ${link.host} CLI login, which gives no API token.` };
|
|
@@ -1113,7 +1078,6 @@ async function previousDeployment(root, link, credentials, context, run) {
|
|
|
1113
1078
|
return { failed: error instanceof Error ? error.message : String(error) };
|
|
1114
1079
|
}
|
|
1115
1080
|
}
|
|
1116
|
-
/** A deployed app that failed a check. Production now serves it, so the error says how to roll back. */
|
|
1117
1081
|
function checkFailed(deployed, host, previous, projectName, link, result, preview) {
|
|
1118
1082
|
const rollback = preview ? { note: "This was a preview deploy, so production did not change." } : rollbackFor(host, {
|
|
1119
1083
|
previous: previous && "deployment" in previous ? previous.deployment : void 0,
|
|
@@ -1149,5 +1113,4 @@ const deployCommand = {
|
|
|
1149
1113
|
},
|
|
1150
1114
|
usage
|
|
1151
1115
|
};
|
|
1152
|
-
//#endregion
|
|
1153
1116
|
export { deploymentsCommand as a, STATUS_HOST_TIMEOUT_MS as i, deploy_exports as n, liveLabel as o, readDeployArgs as r, readSetupLive as s, deployCommand as t };
|