@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,20 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
1
|
+
import { d as cliErrorDiagnostics } from "./provision-D0ct9RDq.js";
|
|
2
|
+
import { u as selectConsole } from "./console-auth-BunROd7u.js";
|
|
3
|
+
import { c as __exportAll, o as writeSetupError, s as writeSetupJson } from "./envelope-DXB-0EcA.js";
|
|
3
4
|
import { execFile } from "node:child_process";
|
|
4
5
|
import { mkdtemp, open, rename, rm } from "node:fs/promises";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { parseArgs } from "node:util";
|
|
7
|
-
// \0rolldown/runtime.js
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __exportAll = (all, no_symbols) => {
|
|
10
|
-
let target = {};
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
-
return target;
|
|
17
|
-
};
|
|
18
8
|
// src/setup/console-env.ts
|
|
19
9
|
var console_env_exports = /* @__PURE__ */ __exportAll({ envPullFeature: () => envPullFeature });
|
|
20
10
|
const pullUsage = "vitehub env pull --from console [--stage <name>] [--project <id>] [--console <url>] [--yes] [--json]";
|
|
@@ -200,4 +190,4 @@ const envPullFeature = {
|
|
|
200
190
|
}
|
|
201
191
|
}
|
|
202
192
|
};
|
|
203
|
-
export { dotenvLine as n,
|
|
193
|
+
export { dotenvLine as n, console_env_exports as t };
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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-
|
|
1
|
+
import { c as shellQuote, s as setupStatus, u as hostFromNitroPreset } from "./status-HXNfm9mB.js";
|
|
2
|
+
import { d as cliErrorDiagnostics, l as resolveHostCredentials, o as planProvisionSteps } from "./provision-D0ct9RDq.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-BvSnsKMg.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-DVuxa-yY.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-DXB-0EcA.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-ClYz5iI7.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-B3NuFAyj.js";
|
|
8
|
+
import { g as readSetupProject } from "./console-auth-BunROd7u.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. */
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as isProvisionRequestError, d as cliErrorDiagnostics, f as loadAllEnv, l as resolveHostCredentials, n as createCloudflareProvisionClient, p as withViteStageEnvironment, r as createNetlifyApiClient, w as isRecord } from "./provision-D0ct9RDq.js";
|
|
2
|
+
import { c as shellQuote, d as resolveDeploymentPlan } from "./status-HXNfm9mB.js";
|
|
3
|
+
import { C as splitManifestCommand, S as redact, _ as isoTime, b as parseCommitMessage, d as commitMessage, f as createDeployRun, g as hostListFailed, h as hostCliFailed, m as hostCli, o as vercelEnv, p as findUrl, s as vercelProject, u as commandRejected, v as lastJsonObject, w as untilInterrupted, y as optionalString } from "./vercel-ClYz5iI7.js";
|
|
4
|
+
import { c as __exportAll, i as setupFailure, o as writeSetupError, r as setupExitCodes, s as writeSetupJson, t as isSetupFailure } from "./envelope-DXB-0EcA.js";
|
|
5
|
+
import { n as dotenvLine$1 } from "./console-env-BCw039oZ.js";
|
|
6
|
+
import { a as consoleClient, c as listConsoleApps, i as consoleAppUrl, n as checkConsoleApp, r as checkProblem, s as linkConsoleApp } from "./console-apps-Cvzc6tY4.js";
|
|
7
|
+
import { g as readSetupProject, u as selectConsole } from "./console-auth-BunROd7u.js";
|
|
8
|
+
import { a as hostRequired, f as readSetupLinks, l as readLinkHostOption, p as selectSetupLink } from "./link-B3NuFAyj.js";
|
|
3
9
|
import { constants, existsSync, lstatSync, statSync } from "node:fs";
|
|
4
10
|
import process from "node:process";
|
|
5
11
|
import { basename, dirname, join, relative } from "pathe";
|
|
@@ -236,7 +242,6 @@ async function wranglerVarNames(outputDir) {
|
|
|
236
242
|
const wrangler = await readWranglerConfig(outputDir, config);
|
|
237
243
|
return isRecord(wrangler.vars) ? Object.keys(wrangler.vars) : [];
|
|
238
244
|
}
|
|
239
|
-
/** The Wrangler config that the `--config` flag of `commands.deploy` names. */
|
|
240
245
|
async function readWranglerConfig(outputDir, config) {
|
|
241
246
|
const file = join(outputDir, config);
|
|
242
247
|
let value;
|
|
@@ -247,11 +252,6 @@ async function readWranglerConfig(outputDir, config) {
|
|
|
247
252
|
}
|
|
248
253
|
return isRecord(value) ? value : {};
|
|
249
254
|
}
|
|
250
|
-
/**
|
|
251
|
-
* The D1 bindings of the Wrangler config whose `migrations_dir` holds `.sql` files, except the bindings that the deploy
|
|
252
|
-
* command migrates. Wrangler reads `migrations_dir` relative to the config file, and its default pattern is `*.sql`
|
|
253
|
-
* without dot files. A binding with `migrations_pattern` selects other files, and ViteHub's build never writes one.
|
|
254
|
-
*/
|
|
255
255
|
async function unmigratedD1Bindings(outputDir, config, wrangler, migrated) {
|
|
256
256
|
const found = [];
|
|
257
257
|
for (const entry of Array.isArray(wrangler.d1_databases) ? wrangler.d1_databases : []) {
|
|
@@ -283,7 +283,6 @@ function d1BindingsWithoutId(wrangler) {
|
|
|
283
283
|
return !id || isPlaceholderCloudflareId(id) ? [entry] : [];
|
|
284
284
|
});
|
|
285
285
|
}
|
|
286
|
-
/** The `results` rows of `wrangler d1 execute --json`, which prints one `{ results, success, meta }` per statement. */
|
|
287
286
|
function d1ResultNames(result) {
|
|
288
287
|
let value;
|
|
289
288
|
try {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { d as cliErrorDiagnostics } from "./provision-D0ct9RDq.js";
|
|
2
|
+
import "node:module";
|
|
3
|
+
import { formatRuntimeDiagnosticError } from "@vite-hub/runtime";
|
|
4
|
+
// \0rolldown/runtime.js
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __exportAll = (all, no_symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
// src/setup/envelope.ts
|
|
16
|
+
/** Exit codes of the setup commands. */
|
|
17
|
+
const setupExitCodes = {
|
|
18
|
+
done: 0,
|
|
19
|
+
error: 1,
|
|
20
|
+
inputNeeded: 2,
|
|
21
|
+
conflict: 3,
|
|
22
|
+
stalePlan: 4
|
|
23
|
+
};
|
|
24
|
+
function isDiagnostic(error) {
|
|
25
|
+
return error instanceof Error && typeof Reflect.get(error, "code") === "string" && typeof Reflect.get(error, "why") === "string";
|
|
26
|
+
}
|
|
27
|
+
function toSetupError(error) {
|
|
28
|
+
const diagnostic = isDiagnostic(error) ? error : cliErrorDiagnostics.CLI_SETUP_FAILED({ message: error instanceof Error ? error.message : String(error) });
|
|
29
|
+
const why = diagnostic.why.replace(/^\[vitehub\] /u, "");
|
|
30
|
+
return {
|
|
31
|
+
code: diagnostic.code,
|
|
32
|
+
message: /^.*?[.!?](?=\s|$)/u.exec(why)?.[0] ?? why,
|
|
33
|
+
why,
|
|
34
|
+
...diagnostic.fix ? { fix: diagnostic.fix } : {},
|
|
35
|
+
...diagnostic.docs ? { docs: diagnostic.docs } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Prints one JSON document with `schemaVersion: 1` on stdout. */
|
|
39
|
+
function writeSetupJson(context, data) {
|
|
40
|
+
context.stdout.write(`${JSON.stringify({
|
|
41
|
+
schemaVersion: 1,
|
|
42
|
+
...data
|
|
43
|
+
})}\n`);
|
|
44
|
+
}
|
|
45
|
+
/** Adds the exit code and the missing input of a setup command to its diagnostic. */
|
|
46
|
+
function setupFailure(diagnostic, exitCode, details = {}) {
|
|
47
|
+
return Object.assign(diagnostic, {
|
|
48
|
+
details,
|
|
49
|
+
exitCode
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Whether `error` is a diagnostic that `setupFailure()` gave an exit code. */
|
|
53
|
+
function isSetupFailure(error) {
|
|
54
|
+
if (!(error instanceof Error)) return false;
|
|
55
|
+
const details = Reflect.get(error, "details");
|
|
56
|
+
return typeof Reflect.get(error, "exitCode") === "number" && typeof details === "object" && details !== null;
|
|
57
|
+
}
|
|
58
|
+
function formatMissing(missing) {
|
|
59
|
+
return missing.map((item) => {
|
|
60
|
+
const choices = item.choices ?? [];
|
|
61
|
+
if (choices.every((choice) => typeof choice === "string")) return `Missing: ${item.field}${choices.length ? ` (${choices.join(", ")})` : ""}\n`;
|
|
62
|
+
return `Missing: ${item.field}\n${choices.map((choice) => typeof choice === "string" ? ` ${choice}\n` : ` ${choice.id}${choice.name ? ` ${choice.name}` : ""}\n`).join("")}`;
|
|
63
|
+
}).join("");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reports `error` as one JSON document on stdout with `--json`, else on stderr, and returns its exit code.
|
|
67
|
+
* A `SetupFailure` adds `missing`, `rerun`, and its `data` to the document. Any other error exits with 1.
|
|
68
|
+
*/
|
|
69
|
+
function writeSetupError(context, json, error) {
|
|
70
|
+
if (isSetupFailure(error)) {
|
|
71
|
+
const { data, missing, rerun } = error.details;
|
|
72
|
+
if (json) writeSetupJson(context, {
|
|
73
|
+
...data,
|
|
74
|
+
error: toSetupError(error),
|
|
75
|
+
...missing ? { missing } : {},
|
|
76
|
+
...rerun ? { rerun } : {}
|
|
77
|
+
});
|
|
78
|
+
else context.stderr.write(`${formatRuntimeDiagnosticError(error)}\n${formatMissing(missing ?? [])}${rerun ? `Run: ${rerun}\n` : ""}`);
|
|
79
|
+
return error.exitCode;
|
|
80
|
+
}
|
|
81
|
+
if (json) writeSetupJson(context, { error: toSetupError(error) });
|
|
82
|
+
else context.stderr.write(`${formatRuntimeDiagnosticError(error)}\n`);
|
|
83
|
+
return setupExitCodes.error;
|
|
84
|
+
}
|
|
85
|
+
/** Reads `--json` and `--help`. Throws `CLI_R0003` for any other argument. */
|
|
86
|
+
function readSetupArgs(args, usage) {
|
|
87
|
+
const unknown = args.find((arg) => arg !== "--json" && arg !== "-h" && arg !== "--help");
|
|
88
|
+
if (unknown !== void 0) throw cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] Unknown argument ${JSON.stringify(unknown)}. Usage: ${usage}` });
|
|
89
|
+
return {
|
|
90
|
+
help: args.includes("-h") || args.includes("--help"),
|
|
91
|
+
json: args.includes("--json")
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Rows as plain text columns, two spaces apart. */
|
|
95
|
+
function table(rows) {
|
|
96
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
97
|
+
return rows.map((row) => row.map((cell, column) => cell.padEnd(widths[column])).join(" ").trimEnd()).join("\n");
|
|
98
|
+
}
|
|
99
|
+
export { table as a, __exportAll as c, setupFailure as i, readSetupArgs as n, writeSetupError as o, setupExitCodes as r, writeSetupJson as s, isSetupFailure as t };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { registerHooks } from "node:module";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
// src/help-cache.ts
|
|
7
|
+
const cacheVersion = 3;
|
|
8
|
+
const configExtensions = [
|
|
9
|
+
"js",
|
|
10
|
+
"mjs",
|
|
11
|
+
"cjs",
|
|
12
|
+
"ts",
|
|
13
|
+
"mts",
|
|
14
|
+
"cts"
|
|
15
|
+
];
|
|
16
|
+
const maxProjectFiles = 1e4;
|
|
17
|
+
const generatedDirs = /* @__PURE__ */ new Set([
|
|
18
|
+
".git",
|
|
19
|
+
".cache",
|
|
20
|
+
".data",
|
|
21
|
+
".netlify",
|
|
22
|
+
".nitro",
|
|
23
|
+
".nuxt",
|
|
24
|
+
".output",
|
|
25
|
+
".vercel",
|
|
26
|
+
".vitehub",
|
|
27
|
+
".wrangler",
|
|
28
|
+
"coverage",
|
|
29
|
+
"dist",
|
|
30
|
+
"node_modules"
|
|
31
|
+
]);
|
|
32
|
+
const workspaceFiles = [
|
|
33
|
+
"bun.lock",
|
|
34
|
+
"bun.lockb",
|
|
35
|
+
"npm-shrinkwrap.json",
|
|
36
|
+
"package-lock.json",
|
|
37
|
+
"package.json",
|
|
38
|
+
"pnpm-lock.yaml",
|
|
39
|
+
"pnpm-workspace.yaml",
|
|
40
|
+
"yarn.lock"
|
|
41
|
+
];
|
|
42
|
+
const installMarkers = [
|
|
43
|
+
".modules.yaml",
|
|
44
|
+
".package-lock.json",
|
|
45
|
+
".yarn-state.yml"
|
|
46
|
+
];
|
|
47
|
+
const shellEnv = /* @__PURE__ */ new Set([
|
|
48
|
+
"_",
|
|
49
|
+
"OLDPWD",
|
|
50
|
+
"PWD",
|
|
51
|
+
"SHLVL"
|
|
52
|
+
]);
|
|
53
|
+
function cacheFile(rootDir) {
|
|
54
|
+
return join(rootDir, ".vitehub/cli/help.json");
|
|
55
|
+
}
|
|
56
|
+
function hasProjectConfig(rootDir) {
|
|
57
|
+
return ["vite", "nuxt"].some((name) => configExtensions.some((extension) => existsSync(join(rootDir, `${name}.config.${extension}`))));
|
|
58
|
+
}
|
|
59
|
+
function statLine(path) {
|
|
60
|
+
try {
|
|
61
|
+
const stat = statSync(path);
|
|
62
|
+
return `${path}\t${stat.size}\t${stat.mtimeMs}`;
|
|
63
|
+
} catch {
|
|
64
|
+
return `${path}\t-`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function walkFiles(dir, lines) {
|
|
68
|
+
let entries;
|
|
69
|
+
try {
|
|
70
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
71
|
+
} catch {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
for (const entry of entries.sort((left, right) => left.name < right.name ? -1 : 1)) {
|
|
75
|
+
if (generatedDirs.has(entry.name)) continue;
|
|
76
|
+
const path = join(dir, entry.name);
|
|
77
|
+
if (entry.isDirectory()) {
|
|
78
|
+
if (!walkFiles(path, lines)) return false;
|
|
79
|
+
} else {
|
|
80
|
+
lines.push(statLine(path));
|
|
81
|
+
if (lines.length > maxProjectFiles) return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
function projectLines(rootDir, env) {
|
|
87
|
+
const root = resolve(rootDir);
|
|
88
|
+
const lines = [
|
|
89
|
+
`v${cacheVersion}`,
|
|
90
|
+
root,
|
|
91
|
+
statLine(fileURLToPath(import.meta.url)),
|
|
92
|
+
statLine(process.argv[1] ?? ""),
|
|
93
|
+
statLine(join(root, ".vitehub/link.json"))
|
|
94
|
+
];
|
|
95
|
+
for (const name of Object.keys(env).filter((name) => !shellEnv.has(name)).sort()) lines.push(`env ${name}=${env[name]}`);
|
|
96
|
+
for (let dir = root;; dir = dirname(dir)) {
|
|
97
|
+
for (const name of workspaceFiles) if (existsSync(join(dir, name))) lines.push(statLine(join(dir, name)));
|
|
98
|
+
for (const name of installMarkers) if (existsSync(join(dir, "node_modules", name))) lines.push(statLine(join(dir, "node_modules", name)));
|
|
99
|
+
if (dirname(dir) === dir) break;
|
|
100
|
+
}
|
|
101
|
+
return walkFiles(root, lines) ? lines : void 0;
|
|
102
|
+
}
|
|
103
|
+
function inputLines(files, dirs, known) {
|
|
104
|
+
const lines = files.map((file) => known?.get(file) ?? statLine(file));
|
|
105
|
+
for (const dir of dirs) {
|
|
106
|
+
lines.push(`dir ${dir}`);
|
|
107
|
+
if (!walkFiles(dir, lines)) return;
|
|
108
|
+
}
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
111
|
+
function hash(lines) {
|
|
112
|
+
return createHash("sha256").update(lines.join("\n")).digest("hex");
|
|
113
|
+
}
|
|
114
|
+
function isInside(path, dir) {
|
|
115
|
+
return path === dir || path.startsWith(dir.endsWith(sep) ? dir : `${dir}${sep}`);
|
|
116
|
+
}
|
|
117
|
+
function outsideProject(rootDir, paths) {
|
|
118
|
+
const root = resolve(rootDir);
|
|
119
|
+
return [...new Set([...paths].map((path) => resolve(path)))].filter((path) => !isInside(path, root) && !path.split(sep).includes("node_modules"));
|
|
120
|
+
}
|
|
121
|
+
function isDirectory(path) {
|
|
122
|
+
try {
|
|
123
|
+
return statSync(path).isDirectory();
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function readHelpCache(rootDir, env) {
|
|
129
|
+
if (!hasProjectConfig(rootDir)) return;
|
|
130
|
+
let cached;
|
|
131
|
+
try {
|
|
132
|
+
cached = JSON.parse(readFileSync(cacheFile(rootDir), "utf8"));
|
|
133
|
+
} catch {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (cached.version !== cacheVersion || !cached.help || !Array.isArray(cached.files) || !Array.isArray(cached.dirs)) return;
|
|
137
|
+
const project = projectLines(rootDir, env);
|
|
138
|
+
const inputs = project && inputLines(cached.files, cached.dirs);
|
|
139
|
+
return inputs && hash([...project, ...inputs]) === cached.key ? cached.help : void 0;
|
|
140
|
+
}
|
|
141
|
+
function recordHelpCache(rootDir, env) {
|
|
142
|
+
if (!hasProjectConfig(rootDir)) return;
|
|
143
|
+
const startEnv = { ...env };
|
|
144
|
+
const before = projectLines(rootDir, startEnv);
|
|
145
|
+
if (!before) return;
|
|
146
|
+
const imported = /* @__PURE__ */ new Map();
|
|
147
|
+
const hooks = registerHooks({ resolve(specifier, context, nextResolve) {
|
|
148
|
+
const result = nextResolve(specifier, context);
|
|
149
|
+
const path = result.url.startsWith("file:") ? fileURLToPath(result.url) : void 0;
|
|
150
|
+
if (path && !imported.has(path)) imported.set(path, statLine(path));
|
|
151
|
+
return result;
|
|
152
|
+
} });
|
|
153
|
+
return {
|
|
154
|
+
stop: () => hooks.deregister(),
|
|
155
|
+
write(namespaces, commands, inputs) {
|
|
156
|
+
hooks.deregister();
|
|
157
|
+
const after = projectLines(rootDir, startEnv);
|
|
158
|
+
if (!after || hash(after) !== hash(before)) return;
|
|
159
|
+
const inputPaths = outsideProject(rootDir, inputs);
|
|
160
|
+
const dirs = inputPaths.filter(isDirectory).sort();
|
|
161
|
+
const files = [.../* @__PURE__ */ new Set([...outsideProject(rootDir, imported.keys()), ...inputPaths.filter((path) => !dirs.includes(path))])].sort();
|
|
162
|
+
const extra = inputLines(files, dirs, imported);
|
|
163
|
+
if (!extra) return;
|
|
164
|
+
const content = {
|
|
165
|
+
dirs,
|
|
166
|
+
files,
|
|
167
|
+
help: {
|
|
168
|
+
commands,
|
|
169
|
+
namespaces: namespaces.map((namespace) => ({
|
|
170
|
+
...namespace.defaultFeature ? { defaultFeature: namespace.defaultFeature } : {},
|
|
171
|
+
...namespace.description ? { description: namespace.description } : {},
|
|
172
|
+
features: namespace.features.map((feature) => ({
|
|
173
|
+
...feature.description ? { description: feature.description } : {},
|
|
174
|
+
name: feature.name,
|
|
175
|
+
...feature.usage ? { usage: feature.usage } : {}
|
|
176
|
+
})),
|
|
177
|
+
name: namespace.name
|
|
178
|
+
}))
|
|
179
|
+
},
|
|
180
|
+
key: hash([...after, ...extra]),
|
|
181
|
+
version: cacheVersion
|
|
182
|
+
};
|
|
183
|
+
const file = cacheFile(rootDir);
|
|
184
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
185
|
+
try {
|
|
186
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
187
|
+
writeFileSync(temporary, JSON.stringify(content));
|
|
188
|
+
renameSync(temporary, file);
|
|
189
|
+
} catch {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export { readHelpCache, recordHelpCache };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ interface OperationResolveConfig {
|
|
|
22
22
|
tsconfigPaths?: boolean;
|
|
23
23
|
}
|
|
24
24
|
interface ViteHubCliLoadedConfig {
|
|
25
|
+
inputs?: readonly string[];
|
|
25
26
|
nitro?: unknown;
|
|
26
27
|
plugins: readonly unknown[];
|
|
27
28
|
resolve?: OperationResolveConfig;
|
|
@@ -47,6 +48,7 @@ export interface RunViteHubCliOptions {
|
|
|
47
48
|
* app. Every feature of such a namespace must print its help for `-h` or `--help` before it reads the project.
|
|
48
49
|
*/
|
|
49
50
|
helpNamespaces?: Record<string, () => Promise<ViteHubCliCommandNamespace | undefined>>;
|
|
51
|
+
helpCache?: boolean;
|
|
50
52
|
/** Optional guard for runtime features that have a project-level opt-out. */
|
|
51
53
|
runtimeFeatureGuard?: (namespace: string, feature: string, cwd: string) => boolean | Promise<boolean>;
|
|
52
54
|
/** Replaces `fetch` in commands that call a running app or a host API. */
|
|
@@ -57,6 +59,7 @@ export interface RunViteHubCliOptions {
|
|
|
57
59
|
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
58
60
|
loadConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<ViteHubCliLoadedConfig>;
|
|
59
61
|
loadNuxtViteConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<{
|
|
62
|
+
inputs?: readonly string[];
|
|
60
63
|
nitro?: unknown;
|
|
61
64
|
plugins: readonly unknown[];
|
|
62
65
|
resolve?: OperationResolveConfig;
|