@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.
- package/README.md +6 -3
- package/dist/{commands-FOmqEZUi.js → commands-w7tEEJph.js} +469 -160
- package/dist/console-apps-BQX-Np9Q.js +271 -0
- package/dist/console-auth-cCodgT_T.js +2813 -0
- package/dist/{console-env-lQ3_eMOy.js → console-env-eXdVI6kw.js} +7 -4
- package/dist/{deploy-DDen0JC0.js → deploy-CqR6pJa-.js} +49 -17
- package/dist/dist-CEIUyD15.js +2495 -0
- package/dist/env-D_CN5DyX.js +2169 -0
- package/dist/envelope-BJQ7xPyX.js +99 -0
- package/dist/help-cache-BI6y5pN8.js +195 -0
- package/dist/index.d.ts +13 -14
- package/dist/index.js +217 -66
- package/dist/link-BRNWNqT9.js +663 -0
- package/dist/provision-9QsGgeiq.js +1741 -0
- package/dist/{provision-kiD8Emd7.d.ts → provision-ByxmUa19.d.ts} +16 -1
- package/dist/provision-Fiosv3Un.js +1391 -0
- package/dist/setup/index.d.ts +37 -15
- package/dist/setup/index.js +12 -9
- package/dist/status-gjvZVutV.js +599 -0
- package/dist/vercel-B5CJLsT0.js +701 -0
- package/package.json +5 -4
- package/dist/env-DzYHxq9A.js +0 -5657
- package/dist/provision-YzxNsbhs.js +0 -4139
- package/dist/rolldown-runtime-BJohB4LM.js +0 -13
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { d as cliErrorDiagnostics } from "./provision-9QsGgeiq.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
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
interface ViteHubCliSpawnResult {
|
|
3
|
-
exitCode: number | null;
|
|
4
|
-
signal?: NodeJS.Signals | null;
|
|
5
|
-
stdout?: string;
|
|
6
|
-
}
|
|
7
|
-
interface ViteHubCliSpawnOptions {
|
|
8
|
-
cwd?: string;
|
|
9
|
-
env?: NodeJS.ProcessEnv;
|
|
10
|
-
stderr?: "inherit" | "pipe";
|
|
11
|
-
stdin?: "ignore" | "inherit";
|
|
12
|
-
stdout?: "inherit" | "pipe" | "stderr";
|
|
13
|
-
}
|
|
14
|
-
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
1
|
+
import { a as ViteHubCliSpawn, i as ViteHubCliProvision, l as HostCliRun, n as ViteHubCliCommandNamespace, o as ProvisionProvider, t as ViteHubCliCommand } from "./provision-ByxmUa19.js";
|
|
15
2
|
interface ViteHubCliStreams {
|
|
16
3
|
stderr: ViteHubCliStream;
|
|
17
4
|
stdout: ViteHubCliStream;
|
|
@@ -27,9 +14,18 @@ type ViteHubCliEntrypointStream = {
|
|
|
27
14
|
flush?: never;
|
|
28
15
|
write: (chunk: string | Uint8Array) => void | PromiseLike<unknown>;
|
|
29
16
|
};
|
|
17
|
+
interface OperationResolveConfig {
|
|
18
|
+
alias?: Readonly<Record<string, string>> | readonly {
|
|
19
|
+
find: string | RegExp;
|
|
20
|
+
replacement: string;
|
|
21
|
+
}[];
|
|
22
|
+
tsconfigPaths?: boolean;
|
|
23
|
+
}
|
|
30
24
|
interface ViteHubCliLoadedConfig {
|
|
25
|
+
inputs?: readonly string[];
|
|
31
26
|
nitro?: unknown;
|
|
32
27
|
plugins: readonly unknown[];
|
|
28
|
+
resolve?: OperationResolveConfig;
|
|
33
29
|
root: string;
|
|
34
30
|
vitehubConfigResolved?: true;
|
|
35
31
|
}
|
|
@@ -52,6 +48,7 @@ export interface RunViteHubCliOptions {
|
|
|
52
48
|
* app. Every feature of such a namespace must print its help for `-h` or `--help` before it reads the project.
|
|
53
49
|
*/
|
|
54
50
|
helpNamespaces?: Record<string, () => Promise<ViteHubCliCommandNamespace | undefined>>;
|
|
51
|
+
helpCache?: boolean;
|
|
55
52
|
/** Optional guard for runtime features that have a project-level opt-out. */
|
|
56
53
|
runtimeFeatureGuard?: (namespace: string, feature: string, cwd: string) => boolean | Promise<boolean>;
|
|
57
54
|
/** Replaces `fetch` in commands that call a running app or a host API. */
|
|
@@ -62,8 +59,10 @@ export interface RunViteHubCliOptions {
|
|
|
62
59
|
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
63
60
|
loadConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<ViteHubCliLoadedConfig>;
|
|
64
61
|
loadNuxtViteConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<{
|
|
62
|
+
inputs?: readonly string[];
|
|
65
63
|
nitro?: unknown;
|
|
66
64
|
plugins: readonly unknown[];
|
|
65
|
+
resolve?: OperationResolveConfig;
|
|
67
66
|
root?: string;
|
|
68
67
|
} | undefined>;
|
|
69
68
|
spawn?: ViteHubCliSpawn;
|