@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,701 @@
|
|
|
1
|
+
import { d as cliErrorDiagnostics, i as createVercelProvisionClient, w as isRecord } from "./provision-9QsGgeiq.js";
|
|
2
|
+
import { c as __exportAll, i as setupFailure, r as setupExitCodes } from "./envelope-BJQ7xPyX.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { dirname, join } from "pathe";
|
|
7
|
+
import { mkdtemp, open, readFile, rm, unlink } from "node:fs/promises";
|
|
8
|
+
import { delimiter } from "node:path";
|
|
9
|
+
import { constants as constants$1, tmpdir } from "node:os";
|
|
10
|
+
import { stripVTControlCharacters } from "node:util";
|
|
11
|
+
// src/setup/deploy/host.ts
|
|
12
|
+
/** A failed host CLI that may print values on stdout, such as `vercel env ls --json`: only stderr goes into the reason. */
|
|
13
|
+
function hostListFailed(step, result, secrets) {
|
|
14
|
+
return hostCliFailed(step, {
|
|
15
|
+
...result,
|
|
16
|
+
stdout: ""
|
|
17
|
+
}, secrets);
|
|
18
|
+
}
|
|
19
|
+
/** Replaces every value in `secrets` with `<redacted>`. */
|
|
20
|
+
function redact(text, secrets) {
|
|
21
|
+
return [...secrets].sort((a, b) => b.length - a.length).reduce((result, secret) => secret ? result.replaceAll(secret, "<redacted>") : result, text);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runs `work` with a signal that SIGINT and SIGTERM abort. The abort stops the host CLI that `work` runs and lets its
|
|
25
|
+
* `finally` remove the files it wrote. Then the process exits with 128 + the signal number, as a shell reports it.
|
|
26
|
+
* It exits instead of raising the signal again: another listener, such as signal-exit, would delay that past our exit.
|
|
27
|
+
*/
|
|
28
|
+
async function untilInterrupted(work) {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
let received;
|
|
31
|
+
const stop = (signal) => {
|
|
32
|
+
received ??= signal;
|
|
33
|
+
controller.abort();
|
|
34
|
+
};
|
|
35
|
+
process.on("SIGINT", stop);
|
|
36
|
+
process.on("SIGTERM", stop);
|
|
37
|
+
try {
|
|
38
|
+
return await work(controller.signal);
|
|
39
|
+
} finally {
|
|
40
|
+
process.off("SIGINT", stop);
|
|
41
|
+
process.off("SIGTERM", stop);
|
|
42
|
+
if (received) process.exit(128 + constants$1.signals[received]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The default runner. It never uses a shell, so no argument is parsed again. Shown output is redacted per line, and a
|
|
47
|
+
* line end that could start a secret waits for the next chunk, so a value split across chunks, even at its own
|
|
48
|
+
* newline, is still found.
|
|
49
|
+
*/
|
|
50
|
+
function createDeployRun(stderr, secrets) {
|
|
51
|
+
return async (command, args, options) => {
|
|
52
|
+
if (options.stdinAsFile) {
|
|
53
|
+
const directory = await mkdtemp(join(tmpdir(), "vitehub-env-"));
|
|
54
|
+
try {
|
|
55
|
+
const path = join(directory, "stdin");
|
|
56
|
+
const file = await open(path, "wx+", 384);
|
|
57
|
+
try {
|
|
58
|
+
await unlink(path);
|
|
59
|
+
const input = Buffer.from(options.stdin ?? "", "utf8");
|
|
60
|
+
let offset = 0;
|
|
61
|
+
while (offset < input.length) {
|
|
62
|
+
const { bytesWritten } = await file.write(input, offset, input.length - offset, offset);
|
|
63
|
+
offset += bytesWritten;
|
|
64
|
+
}
|
|
65
|
+
return await run(file.fd);
|
|
66
|
+
} finally {
|
|
67
|
+
await file.close();
|
|
68
|
+
}
|
|
69
|
+
} finally {
|
|
70
|
+
await rm(directory, {
|
|
71
|
+
recursive: true,
|
|
72
|
+
force: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return await run();
|
|
77
|
+
function run(stdinFd) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const child = spawn(command, [...args], {
|
|
80
|
+
cwd: options.cwd,
|
|
81
|
+
env: options.env,
|
|
82
|
+
shell: false,
|
|
83
|
+
stdio: [
|
|
84
|
+
stdinFd ?? "pipe",
|
|
85
|
+
"pipe",
|
|
86
|
+
"pipe"
|
|
87
|
+
],
|
|
88
|
+
detached: process.platform !== "win32"
|
|
89
|
+
});
|
|
90
|
+
const output = {
|
|
91
|
+
stderr: "",
|
|
92
|
+
stdout: ""
|
|
93
|
+
};
|
|
94
|
+
const pending = {
|
|
95
|
+
stderr: "",
|
|
96
|
+
stdout: ""
|
|
97
|
+
};
|
|
98
|
+
const lines = {
|
|
99
|
+
stderr: "",
|
|
100
|
+
stdout: ""
|
|
101
|
+
};
|
|
102
|
+
const values = [...new Set(secrets.filter(Boolean))].sort((a, b) => b.length - a.length);
|
|
103
|
+
const show = (stream, chunk, flush = false) => {
|
|
104
|
+
if (!options.show) return;
|
|
105
|
+
const text = pending[stream] + chunk;
|
|
106
|
+
let index = 0;
|
|
107
|
+
let ready = "";
|
|
108
|
+
while (index < text.length) {
|
|
109
|
+
const rest = text.slice(index);
|
|
110
|
+
if (!flush && values.some((value) => value.length > rest.length && value.startsWith(rest))) break;
|
|
111
|
+
const match = values.find((value) => rest.startsWith(value));
|
|
112
|
+
ready += match ? "<redacted>" : text[index];
|
|
113
|
+
index += match?.length ?? 1;
|
|
114
|
+
}
|
|
115
|
+
pending[stream] = text.slice(index);
|
|
116
|
+
lines[stream] += ready;
|
|
117
|
+
const end = flush ? lines[stream].length : lines[stream].lastIndexOf("\n") + 1;
|
|
118
|
+
if (end) stderr.write(lines[stream].slice(0, end));
|
|
119
|
+
lines[stream] = lines[stream].slice(end);
|
|
120
|
+
};
|
|
121
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
122
|
+
const outputStream = child[stream];
|
|
123
|
+
if (!outputStream) continue;
|
|
124
|
+
outputStream.setEncoding("utf8");
|
|
125
|
+
outputStream.on("data", (chunk) => {
|
|
126
|
+
output[stream] += chunk;
|
|
127
|
+
show(stream, chunk);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let failure;
|
|
131
|
+
let finished = false;
|
|
132
|
+
let stopping = false;
|
|
133
|
+
let closed = false;
|
|
134
|
+
let code = null;
|
|
135
|
+
let timeout;
|
|
136
|
+
const finish = () => {
|
|
137
|
+
if (finished) return;
|
|
138
|
+
finished = true;
|
|
139
|
+
if (timeout) clearTimeout(timeout);
|
|
140
|
+
options.signal?.removeEventListener("abort", abort);
|
|
141
|
+
if (failure !== void 0) return reject(failure);
|
|
142
|
+
show("stdout", "", true);
|
|
143
|
+
show("stderr", "", true);
|
|
144
|
+
resolve({
|
|
145
|
+
exitCode: stopping ? null : code,
|
|
146
|
+
stdout: redact(output.stdout, secrets),
|
|
147
|
+
stderr: redact(output.stderr, secrets)
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const killTree = (signal) => {
|
|
151
|
+
if (!child.pid) return;
|
|
152
|
+
if (process.platform === "win32") spawn("taskkill", [
|
|
153
|
+
"/pid",
|
|
154
|
+
String(child.pid),
|
|
155
|
+
"/T",
|
|
156
|
+
"/F"
|
|
157
|
+
], {
|
|
158
|
+
stdio: "ignore",
|
|
159
|
+
windowsHide: true
|
|
160
|
+
}).on("error", () => {
|
|
161
|
+
child.kill(signal);
|
|
162
|
+
});
|
|
163
|
+
else try {
|
|
164
|
+
process.kill(-child.pid, signal);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.code !== "ESRCH") child.kill(signal);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const stop = () => {
|
|
170
|
+
if (stopping) return;
|
|
171
|
+
stopping = true;
|
|
172
|
+
killTree("SIGTERM");
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
killTree("SIGKILL");
|
|
175
|
+
setTimeout(() => {
|
|
176
|
+
child.stdin?.destroy();
|
|
177
|
+
child.stdout?.destroy();
|
|
178
|
+
child.stderr?.destroy();
|
|
179
|
+
finish();
|
|
180
|
+
}, closed ? 0 : 500);
|
|
181
|
+
}, 500);
|
|
182
|
+
};
|
|
183
|
+
const abort = () => {
|
|
184
|
+
failure = Object.assign(/* @__PURE__ */ new Error("The operation was aborted"), { name: "AbortError" });
|
|
185
|
+
stop();
|
|
186
|
+
};
|
|
187
|
+
child.on("error", (error) => {
|
|
188
|
+
failure = error;
|
|
189
|
+
if (!stopping) finish();
|
|
190
|
+
});
|
|
191
|
+
child.on("close", (exitCode) => {
|
|
192
|
+
closed = true;
|
|
193
|
+
code = exitCode;
|
|
194
|
+
if (!stopping) finish();
|
|
195
|
+
});
|
|
196
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
197
|
+
if (options.timeoutMs) timeout = setTimeout(stop, options.timeoutMs);
|
|
198
|
+
if (options.signal?.aborted) abort();
|
|
199
|
+
child.stdin?.on("error", (error) => {
|
|
200
|
+
if (!(error.code === "EPIPE" || stopping && error.code === "ERR_STREAM_DESTROYED")) failure ??= error;
|
|
201
|
+
});
|
|
202
|
+
child.stdin?.end(options.stdin ?? "");
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function windowsNodeEntry(file) {
|
|
208
|
+
if (/\.(?:exe|cmd|bat)$/iu.test(file)) return;
|
|
209
|
+
if (!existsSync(file)) return;
|
|
210
|
+
const source = readFileSync(file, "utf8");
|
|
211
|
+
if (/\.[cm]?js$/iu.test(file) || /^#![^\r\n]*\bnode(?:\.exe)?(?:\s|$)/u.test(source)) return [process.execPath, file];
|
|
212
|
+
}
|
|
213
|
+
function executableIn(folder, name, platform) {
|
|
214
|
+
const file = join(folder, name);
|
|
215
|
+
if (platform !== "win32") return existsSync(file) ? [file] : void 0;
|
|
216
|
+
if (existsSync(`${file}.exe`)) return [`${file}.exe`];
|
|
217
|
+
const shim = `${file}.cmd`;
|
|
218
|
+
if (existsSync(shim)) for (const match of readFileSync(shim, "utf8").matchAll(/"(?:%dp0%|%~dp0)[\\/]([^"\r\n]+)"/giu)) {
|
|
219
|
+
const entry = windowsNodeEntry(join(folder, match[1].replaceAll("\\", "/")));
|
|
220
|
+
if (entry) return entry;
|
|
221
|
+
}
|
|
222
|
+
return windowsNodeEntry(file);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The host CLI as a command and its first arguments: the project's `node_modules/.bin` (walking up), then `PATH`,
|
|
226
|
+
* then `npx --yes <package>`, which the build output also names.
|
|
227
|
+
*/
|
|
228
|
+
function hostCli(name, npmPackage, root, env, platform = process.platform) {
|
|
229
|
+
for (let folder = root;; folder = dirname(folder)) {
|
|
230
|
+
const found = executableIn(join(folder, "node_modules", ".bin"), name, platform);
|
|
231
|
+
if (found) return found;
|
|
232
|
+
if (dirname(folder) === folder) break;
|
|
233
|
+
}
|
|
234
|
+
const path = (env.PATH ?? "").split(platform === "win32" ? ";" : delimiter).filter(Boolean);
|
|
235
|
+
for (const folder of path) {
|
|
236
|
+
const found = executableIn(folder, name, platform);
|
|
237
|
+
if (found) return found;
|
|
238
|
+
}
|
|
239
|
+
if (platform === "win32") {
|
|
240
|
+
for (const folder of [...path, dirname(process.execPath)]) {
|
|
241
|
+
const npx = executableIn(folder, "npx", platform);
|
|
242
|
+
if (npx) return [
|
|
243
|
+
...npx,
|
|
244
|
+
"--yes",
|
|
245
|
+
npmPackage
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_FAILED({
|
|
249
|
+
exitCode: null,
|
|
250
|
+
output: "Could not find a Node.js entrypoint for npx. Install Node.js with npm or install the host CLI locally.",
|
|
251
|
+
step: "npx"
|
|
252
|
+
}), setupExitCodes.error);
|
|
253
|
+
}
|
|
254
|
+
return [
|
|
255
|
+
"npx",
|
|
256
|
+
"--yes",
|
|
257
|
+
npmPackage
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Splits a command that the build wrote into words, the way a POSIX shell reads plain words and single quotes.
|
|
262
|
+
* Anything a shell would expand or run (`$`, backquotes, `;`, `|`, `&`, `<`, `>`, `(`, `)`, double quotes, `\`) is
|
|
263
|
+
* rejected, so the words are exactly what the build meant.
|
|
264
|
+
*/
|
|
265
|
+
function splitManifestCommand(command) {
|
|
266
|
+
const words = [];
|
|
267
|
+
let word;
|
|
268
|
+
for (let index = 0; index < command.length; index++) {
|
|
269
|
+
const char = command[index];
|
|
270
|
+
if (char === "'") {
|
|
271
|
+
const end = command.indexOf("'", index + 1);
|
|
272
|
+
if (end === -1) throw commandRejected(command);
|
|
273
|
+
word = (word ?? "") + command.slice(index + 1, end);
|
|
274
|
+
index = end;
|
|
275
|
+
} else if (char === " " || char === " ") {
|
|
276
|
+
if (word !== void 0) words.push(word);
|
|
277
|
+
word = void 0;
|
|
278
|
+
} else if (/[$`;|&<>()"\\\n*?~#{}]/u.test(char)) throw commandRejected(command);
|
|
279
|
+
else word = (word ?? "") + char;
|
|
280
|
+
}
|
|
281
|
+
if (word !== void 0) words.push(word);
|
|
282
|
+
return words;
|
|
283
|
+
}
|
|
284
|
+
function commandRejected(command) {
|
|
285
|
+
return setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_COMMAND_REJECTED({ command }), setupExitCodes.error);
|
|
286
|
+
}
|
|
287
|
+
/** A host CLI that exited with an error. Its last lines go into the reason, redacted. */
|
|
288
|
+
function hostCliFailed(step, result, secrets) {
|
|
289
|
+
const lines = redact(`${result.stderr}\n${result.stdout}`, secrets).split("\n").map((line) => line.trimEnd()).filter(Boolean).slice(-6).join("\n");
|
|
290
|
+
return setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_FAILED({
|
|
291
|
+
exitCode: result.exitCode,
|
|
292
|
+
output: lines,
|
|
293
|
+
step
|
|
294
|
+
}), setupExitCodes.error);
|
|
295
|
+
}
|
|
296
|
+
/** The last JSON object in `text`. Host CLIs may print a line before it. */
|
|
297
|
+
function lastJsonObject(text) {
|
|
298
|
+
for (let start = text.lastIndexOf("{"); start !== -1; start = text.lastIndexOf("{", start - 1)) try {
|
|
299
|
+
const value = JSON.parse(text.slice(start));
|
|
300
|
+
if (isRecord(value)) return value;
|
|
301
|
+
} catch {}
|
|
302
|
+
}
|
|
303
|
+
function optionalString(value) {
|
|
304
|
+
return typeof value === "string" && value ? value : void 0;
|
|
305
|
+
}
|
|
306
|
+
/** The first `https://` URL in `text` that matches `host`, else undefined. */
|
|
307
|
+
function findUrl(text, host) {
|
|
308
|
+
for (const match of text.matchAll(/https:\/\/[^\s"'`<>)\]]+/gu)) {
|
|
309
|
+
const url = match[0].replace(/[.,;]+$/u, "");
|
|
310
|
+
if (host.test(new URL(url).hostname)) return url;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** The `vitehub:` marker that Cloudflare and Netlify store as the deploy message. */
|
|
314
|
+
function commitMessage(commit) {
|
|
315
|
+
return `vitehub:${JSON.stringify({
|
|
316
|
+
commit: commit.sha,
|
|
317
|
+
dirty: commit.dirty
|
|
318
|
+
})}`;
|
|
319
|
+
}
|
|
320
|
+
/** Reads the `vitehub:` marker of `commitMessage`. Returns undefined for any other message. */
|
|
321
|
+
function parseCommitMessage(message) {
|
|
322
|
+
if (typeof message !== "string" || !message.startsWith("vitehub:")) return;
|
|
323
|
+
let value;
|
|
324
|
+
try {
|
|
325
|
+
value = JSON.parse(message.slice(8));
|
|
326
|
+
} catch {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (!isRecord(value) || typeof value.commit !== "string" || !/^[0-9a-f]{40,64}$/u.test(value.commit)) return;
|
|
330
|
+
return {
|
|
331
|
+
dirty: value.dirty === true,
|
|
332
|
+
sha: value.commit
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/** A host time, such as an ISO string or a millisecond timestamp, as an ISO string. */
|
|
336
|
+
function isoTime(value) {
|
|
337
|
+
const time = typeof value === "number" || typeof value === "string" ? new Date(value) : void 0;
|
|
338
|
+
return time && !Number.isNaN(time.getTime()) ? time.toISOString() : "";
|
|
339
|
+
}
|
|
340
|
+
/** Reads the commit with git, using argument arrays. Returns undefined without git or outside a repository. */
|
|
341
|
+
async function readDeployCommit(run, root, env) {
|
|
342
|
+
try {
|
|
343
|
+
const head = await run("git", [
|
|
344
|
+
"rev-parse",
|
|
345
|
+
"--verify",
|
|
346
|
+
"HEAD"
|
|
347
|
+
], {
|
|
348
|
+
cwd: root,
|
|
349
|
+
env
|
|
350
|
+
});
|
|
351
|
+
const sha = head.stdout.trim();
|
|
352
|
+
if (head.exitCode !== 0 || !/^[0-9a-f]{40,64}$/u.test(sha)) return;
|
|
353
|
+
const status = await run("git", ["status", "--porcelain"], {
|
|
354
|
+
cwd: root,
|
|
355
|
+
env
|
|
356
|
+
});
|
|
357
|
+
return {
|
|
358
|
+
dirty: status.exitCode !== 0 || status.stdout.trim() !== "",
|
|
359
|
+
sha
|
|
360
|
+
};
|
|
361
|
+
} catch {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
// ../internal/dist/abort.js
|
|
366
|
+
/**
|
|
367
|
+
* Runs `task` and rejects as soon as `signal` aborts, without waiting for the task.
|
|
368
|
+
*
|
|
369
|
+
* The rejection is `signal.reason`. When the reason is absent, it is an `AbortError` with `message`.
|
|
370
|
+
* When `signal` is already aborted, `task` does not run. The task should stop its own work
|
|
371
|
+
* through the same signal.
|
|
372
|
+
*/
|
|
373
|
+
function abortable(signal, message, task) {
|
|
374
|
+
return new Promise((resolve, reject) => {
|
|
375
|
+
if (signal?.aborted) {
|
|
376
|
+
reject(abortReason(signal, message));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const onAbort = () => reject(abortReason(signal, message));
|
|
380
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
381
|
+
const settle = () => signal?.removeEventListener("abort", onAbort);
|
|
382
|
+
new Promise((resolveTask) => resolveTask(task())).then((value) => {
|
|
383
|
+
settle();
|
|
384
|
+
resolve(value);
|
|
385
|
+
}, (error) => {
|
|
386
|
+
settle();
|
|
387
|
+
reject(error);
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function abortReason(signal, message) {
|
|
392
|
+
if (signal?.reason !== void 0) return signal.reason;
|
|
393
|
+
return new DOMException(message, "AbortError");
|
|
394
|
+
}
|
|
395
|
+
// src/setup/deploy/vercel.ts
|
|
396
|
+
var vercel_exports = /* @__PURE__ */ __exportAll({ resolveVercelTarget: () => resolveVercelTarget });
|
|
397
|
+
async function resolveVercelTarget(root, env, link) {
|
|
398
|
+
const explicitId = link ? void 0 : optionalString(env.VERCEL_PROJECT_ID?.trim());
|
|
399
|
+
const folder = explicitId ? void 0 : await readFile(join(root, ".vercel", "project.json"), "utf8").then((text) => JSON.parse(text)).catch(() => void 0);
|
|
400
|
+
const folderId = isRecord(folder) ? optionalString(folder.projectId)?.trim() : void 0;
|
|
401
|
+
const orgId = isRecord(folder) ? optionalString(folder.orgId) : void 0;
|
|
402
|
+
const name = isRecord(folder) ? optionalString(folder.projectName) : void 0;
|
|
403
|
+
const scope = link?.account?.id ?? vercelScope(env);
|
|
404
|
+
if (link) {
|
|
405
|
+
if ((link.project.id ? link.project.id === folderId : link.project.name === name) && folderId && orgId && (!scope || scope === orgId)) return {
|
|
406
|
+
...link,
|
|
407
|
+
account: link.account ?? { id: orgId },
|
|
408
|
+
project: {
|
|
409
|
+
...link.project,
|
|
410
|
+
id: folderId
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
return link;
|
|
414
|
+
}
|
|
415
|
+
const projectId = explicitId ?? folderId;
|
|
416
|
+
if (!projectId) return;
|
|
417
|
+
const folderTeam = !env.VERCEL_TEAM_ID?.trim() && !env.VERCEL_ORG_ID?.trim() && orgId?.startsWith("team_") ? orgId : void 0;
|
|
418
|
+
return {
|
|
419
|
+
host: "vercel",
|
|
420
|
+
project: {
|
|
421
|
+
id: projectId,
|
|
422
|
+
name: name ?? projectId
|
|
423
|
+
},
|
|
424
|
+
...folderTeam ? { account: { id: folderTeam } } : {},
|
|
425
|
+
verified: false,
|
|
426
|
+
linkedAt: ""
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function vercelCliEnv(env) {
|
|
430
|
+
return {
|
|
431
|
+
...env,
|
|
432
|
+
VERCEL_PROJECT_ID: void 0,
|
|
433
|
+
VERCEL_ORG_ID: void 0,
|
|
434
|
+
VERCEL_TEAM_ID: void 0
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/** Check the CLI's saved session without reading its auth files or exposing a token. */
|
|
438
|
+
async function hasVercelLogin(root, context, signal) {
|
|
439
|
+
try {
|
|
440
|
+
const [command, ...args] = hostCli("vercel", "vercel", root, context.env);
|
|
441
|
+
const run = context.runHostCli ?? createDeployRun(context.stderr, []);
|
|
442
|
+
return (await abortable(signal, "Vercel login check timed out", () => run(command, [...args, "whoami"], {
|
|
443
|
+
cwd: root,
|
|
444
|
+
env: context.env,
|
|
445
|
+
...signal ? { signal } : {}
|
|
446
|
+
}))).exitCode === 0;
|
|
447
|
+
} catch {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async function readClaim(root) {
|
|
452
|
+
let value;
|
|
453
|
+
try {
|
|
454
|
+
value = JSON.parse(await readFile(join(root, ".vercel", "anonymous.json"), "utf8"));
|
|
455
|
+
} catch {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const url = isRecord(value) ? optionalString(value.claimUrl) : void 0;
|
|
459
|
+
if (!url || !isRecord(value)) return;
|
|
460
|
+
return {
|
|
461
|
+
url,
|
|
462
|
+
...typeof value.expiresAt === "number" ? { expiresAt: new Date(value.expiresAt).toISOString() } : {}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function vercelScope(env) {
|
|
466
|
+
return optionalString(env.VERCEL_TEAM_ID?.trim()) ?? optionalString(env.VERCEL_ORG_ID?.trim());
|
|
467
|
+
}
|
|
468
|
+
function vercelDeployLink(name, env) {
|
|
469
|
+
const scope = vercelScope(env);
|
|
470
|
+
return {
|
|
471
|
+
host: "vercel",
|
|
472
|
+
project: { name },
|
|
473
|
+
...scope ? { account: { id: scope } } : {},
|
|
474
|
+
verified: false,
|
|
475
|
+
linkedAt: ""
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function vercelAdapter(context) {
|
|
479
|
+
const vercel = hostCli("vercel", "vercel", context.root, context.env);
|
|
480
|
+
const team = (context.link?.host === "vercel" ? context.link.account?.id : void 0) ?? vercelScope(context.env);
|
|
481
|
+
const projectId = context.link?.host === "vercel" ? context.link.project.id : void 0;
|
|
482
|
+
const project = projectId ?? context.projectName;
|
|
483
|
+
const target = context.temporary ? [] : [
|
|
484
|
+
"--project",
|
|
485
|
+
project,
|
|
486
|
+
...team ? ["--scope", team] : []
|
|
487
|
+
];
|
|
488
|
+
const env = context.temporary ? context.env : vercelCliEnv(context.env);
|
|
489
|
+
const run = (args, options = {}) => context.run(vercel[0], [...vercel.slice(1), ...args], {
|
|
490
|
+
cwd: context.root,
|
|
491
|
+
env,
|
|
492
|
+
...options
|
|
493
|
+
});
|
|
494
|
+
return { async deploy() {
|
|
495
|
+
const args = [
|
|
496
|
+
"deploy",
|
|
497
|
+
"--prebuilt",
|
|
498
|
+
"--yes",
|
|
499
|
+
"--json",
|
|
500
|
+
...context.preview ? ["--environment", "preview"] : ["--prod"]
|
|
501
|
+
];
|
|
502
|
+
if (context.temporary) args.push("--temporary");
|
|
503
|
+
else {
|
|
504
|
+
args.push(...target);
|
|
505
|
+
if (!context.preview && !projectId) args.push("--create-if-missing");
|
|
506
|
+
}
|
|
507
|
+
if (context.commit) args.push("--meta", `vitehubCommit=${context.commit.sha}`, "--meta", `vitehubDirty=${context.commit.dirty}`);
|
|
508
|
+
const result = await run(args, { show: true });
|
|
509
|
+
if (result.exitCode !== 0) throw hostCliFailed("vercel deploy", result, context.secrets);
|
|
510
|
+
const json = lastJsonObject(result.stdout);
|
|
511
|
+
const deployment = isRecord(json?.deployment) ? json.deployment : json;
|
|
512
|
+
const productionUrl = context.preview ? void 0 : optionalString(deployment?.productionUrl);
|
|
513
|
+
const url = productionUrl ?? optionalString(deployment?.url);
|
|
514
|
+
if (!url) throw hostCliFailed("vercel deploy printed no URL", result, context.secrets);
|
|
515
|
+
const id = optionalString(deployment?.id);
|
|
516
|
+
const claim = context.temporary ? await readClaim(context.root) : void 0;
|
|
517
|
+
return {
|
|
518
|
+
url,
|
|
519
|
+
...productionUrl ? { productionUrl } : {},
|
|
520
|
+
...id ? { deploymentId: id } : {},
|
|
521
|
+
...claim ? { claim } : {},
|
|
522
|
+
...context.temporary ? {} : { project: {
|
|
523
|
+
name: context.projectName,
|
|
524
|
+
...projectId ? { id: projectId } : {},
|
|
525
|
+
...team ? { accountId: team } : {}
|
|
526
|
+
} }
|
|
527
|
+
};
|
|
528
|
+
} };
|
|
529
|
+
}
|
|
530
|
+
function vercelProjectCli(context) {
|
|
531
|
+
const vercel = hostCli("vercel", "vercel", context.root, context.env);
|
|
532
|
+
const team = context.link.account?.id ?? vercelScope(context.env);
|
|
533
|
+
const env = vercelCliEnv(context.env);
|
|
534
|
+
const run = (args, stdin) => context.run(vercel[0], [...vercel.slice(1), ...args], {
|
|
535
|
+
cwd: context.root,
|
|
536
|
+
env,
|
|
537
|
+
...stdin === void 0 ? {} : { stdin }
|
|
538
|
+
});
|
|
539
|
+
return {
|
|
540
|
+
project: context.link.project.id ?? context.link.project.name,
|
|
541
|
+
run,
|
|
542
|
+
scope: team ? ["--scope", team] : []
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function vercelProject(context) {
|
|
546
|
+
const { project, run, scope } = vercelProjectCli(context);
|
|
547
|
+
return {
|
|
548
|
+
name: project,
|
|
549
|
+
async exists() {
|
|
550
|
+
const result = await run([
|
|
551
|
+
"project",
|
|
552
|
+
"inspect",
|
|
553
|
+
project,
|
|
554
|
+
...scope
|
|
555
|
+
]);
|
|
556
|
+
if (result.exitCode === 0) return true;
|
|
557
|
+
if (!stripVTControlCharacters(result.stderr).split("\n").some((line) => line.trim() === `Error: There is no project for "${project}"`)) throw hostCliFailed(`vercel project inspect ${project}`, result, context.secrets);
|
|
558
|
+
if (context.target === "preview") throw setupFailure(cliErrorDiagnostics.SETUP_DEPLOY_VERCEL_PREVIEW_REQUIRES_PRODUCTION(), setupExitCodes.inputNeeded);
|
|
559
|
+
return false;
|
|
560
|
+
},
|
|
561
|
+
async create() {
|
|
562
|
+
const result = await run([
|
|
563
|
+
"project",
|
|
564
|
+
"add",
|
|
565
|
+
project,
|
|
566
|
+
...scope
|
|
567
|
+
]);
|
|
568
|
+
if (result.exitCode !== 0) throw hostCliFailed(`vercel project add ${project}`, result, context.secrets);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* The Environment Variables of the linked project for `production` or `preview`. Vercel CLI 65.11 (`vercel env add
|
|
574
|
+
* --help`, `vercel env ls --help`, in test/fixtures/host-cli-help/). `env add` reads the value from stdin, and `--force`
|
|
575
|
+
* replaces the value in the same environment. `env ls --json` prints readable values too, so its stdout never goes
|
|
576
|
+
* into an error.
|
|
577
|
+
*/
|
|
578
|
+
function vercelEnv(context, overwrite = true) {
|
|
579
|
+
const { project: name, run, scope } = vercelProjectCli(context);
|
|
580
|
+
const project = [
|
|
581
|
+
"--project",
|
|
582
|
+
name,
|
|
583
|
+
...scope
|
|
584
|
+
];
|
|
585
|
+
return {
|
|
586
|
+
async listSecretNames() {
|
|
587
|
+
const result = await run([
|
|
588
|
+
"env",
|
|
589
|
+
"ls",
|
|
590
|
+
"--environment",
|
|
591
|
+
context.target,
|
|
592
|
+
"--json",
|
|
593
|
+
...project
|
|
594
|
+
]);
|
|
595
|
+
if (result.exitCode !== 0) throw hostListFailed("vercel env ls", result, context.secrets);
|
|
596
|
+
const envs = lastJsonObject(result.stdout)?.envs;
|
|
597
|
+
if (!Array.isArray(envs)) throw hostListFailed("vercel env ls printed no envs", result, context.secrets);
|
|
598
|
+
return envs.flatMap((item) => {
|
|
599
|
+
if (!isRecord(item) || typeof item.key !== "string") return [];
|
|
600
|
+
const targets = Array.isArray(item.target) ? item.target : typeof item.target === "string" ? [item.target] : void 0;
|
|
601
|
+
return !targets || targets.includes(context.target) ? [item.key] : [];
|
|
602
|
+
});
|
|
603
|
+
},
|
|
604
|
+
async setSecret(name, value, { secret }) {
|
|
605
|
+
const result = await run([
|
|
606
|
+
"env",
|
|
607
|
+
"add",
|
|
608
|
+
name,
|
|
609
|
+
"--environment",
|
|
610
|
+
context.target,
|
|
611
|
+
secret ? "--sensitive" : "--no-sensitive",
|
|
612
|
+
...overwrite ? ["--force"] : [],
|
|
613
|
+
"--yes",
|
|
614
|
+
...project
|
|
615
|
+
], value);
|
|
616
|
+
if (result.exitCode !== 0) throw hostCliFailed(`vercel env add ${name}`, result, context.secrets);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
const gitSources = /* @__PURE__ */ new Set([
|
|
621
|
+
"git",
|
|
622
|
+
"git-deploy-hook",
|
|
623
|
+
"api-trigger-git-deploy",
|
|
624
|
+
"import/repo",
|
|
625
|
+
"clone/repo"
|
|
626
|
+
]);
|
|
627
|
+
function vercelSource(value, commit) {
|
|
628
|
+
if (value === "cli") return "cli";
|
|
629
|
+
if (typeof value === "string" && gitSources.has(value)) return "git";
|
|
630
|
+
if (value === "redeploy" || value === "import" || value === "drop" || value === "v0-web") return "dashboard";
|
|
631
|
+
return commit?.from === "host" ? "git" : "unknown";
|
|
632
|
+
}
|
|
633
|
+
function vercelState(value) {
|
|
634
|
+
if (value === "READY") return "ready";
|
|
635
|
+
if (value === "ERROR") return "error";
|
|
636
|
+
if (value === "CANCELED" || value === "DELETED") return "canceled";
|
|
637
|
+
if (value === "BUILDING" || value === "INITIALIZING" || value === "QUEUED" || value === "BLOCKED") return "building";
|
|
638
|
+
return "unknown";
|
|
639
|
+
}
|
|
640
|
+
function vercelCommit(meta) {
|
|
641
|
+
if (!isRecord(meta)) return;
|
|
642
|
+
const marked = optionalString(meta.vitehubCommit);
|
|
643
|
+
if (marked && /^[0-9a-f]{40,64}$/u.test(marked)) return {
|
|
644
|
+
dirty: meta.vitehubDirty === "true",
|
|
645
|
+
from: "vitehub",
|
|
646
|
+
sha: marked
|
|
647
|
+
};
|
|
648
|
+
const git = optionalString(meta.githubCommitSha) ?? optionalString(meta.gitlabCommitSha) ?? optionalString(meta.bitbucketCommitSha);
|
|
649
|
+
return git ? {
|
|
650
|
+
dirty: false,
|
|
651
|
+
from: "host",
|
|
652
|
+
sha: git
|
|
653
|
+
} : void 0;
|
|
654
|
+
}
|
|
655
|
+
function parseVercelDeployments(value, production) {
|
|
656
|
+
return (isRecord(value) && Array.isArray(value.deployments) ? value.deployments : []).flatMap((item) => {
|
|
657
|
+
const id = isRecord(item) ? optionalString(item.uid) ?? optionalString(item.id) : void 0;
|
|
658
|
+
if (!id || !isRecord(item)) return [];
|
|
659
|
+
const commit = vercelCommit(item.meta);
|
|
660
|
+
const url = optionalString(item.url);
|
|
661
|
+
return [{
|
|
662
|
+
createdAt: isoTime(item.created ?? item.createdAt),
|
|
663
|
+
id,
|
|
664
|
+
live: id === production,
|
|
665
|
+
source: vercelSource(item.source, commit),
|
|
666
|
+
state: vercelState(item.state ?? item.readyState),
|
|
667
|
+
target: item.target === "production" ? "production" : "preview",
|
|
668
|
+
...url ? { url: url.startsWith("https://") ? url : `https://${url}` } : {},
|
|
669
|
+
...commit ? { commit } : {}
|
|
670
|
+
}];
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Vercel REST API, with `teamId` for a team:
|
|
675
|
+
* - `GET /v6/deployments?projectId=&limit=`, newest first. The Vercel CLI 65.11 lists with v6; the docs show the same
|
|
676
|
+
* fields on v7: https://vercel.com/docs/rest-api/reference/endpoints/deployments/list-deployments
|
|
677
|
+
* - `GET /v9/projects/{idOrName}`: `targets.production` is the deployment that serves production, which the Vercel CLI
|
|
678
|
+
* also reads. https://vercel.com/docs/rest-api/reference/endpoints/projects/find-a-project-by-id-or-name
|
|
679
|
+
*/
|
|
680
|
+
const listVercelDeployments = async (context, { limit, includeLive }) => {
|
|
681
|
+
const linked = context.link.account?.id;
|
|
682
|
+
const teamId = linked ? linked.startsWith("team_") ? linked : void 0 : context.credentials.teamId;
|
|
683
|
+
const client = createVercelProvisionClient({
|
|
684
|
+
teamId,
|
|
685
|
+
token: context.credentials.token
|
|
686
|
+
}, context.fetch);
|
|
687
|
+
const project = context.link.project.id ?? context.link.project.name;
|
|
688
|
+
const [details, list] = await Promise.all([client(`/v9/projects/${encodeURIComponent(project)}`), client("/v6/deployments", { query: {
|
|
689
|
+
limit: String(limit),
|
|
690
|
+
projectId: project
|
|
691
|
+
} })]);
|
|
692
|
+
const targets = isRecord(details) && isRecord(details.targets) ? details.targets : void 0;
|
|
693
|
+
const production = targets && isRecord(targets.production) ? optionalString(targets.production.id) : void 0;
|
|
694
|
+
const recent = parseVercelDeployments(list, production).slice(0, limit);
|
|
695
|
+
if (includeLive && production && !recent.some((item) => item.live)) {
|
|
696
|
+
const live = await client(`/v13/deployments/${encodeURIComponent(production)}`);
|
|
697
|
+
recent.push(...parseVercelDeployments({ deployments: [live] }, production));
|
|
698
|
+
}
|
|
699
|
+
return recent;
|
|
700
|
+
};
|
|
701
|
+
export { splitManifestCommand as C, redact as S, isoTime as _, vercelDeployLink as a, parseCommitMessage as b, vercel_exports as c, commitMessage as d, createDeployRun as f, hostListFailed as g, hostCliFailed as h, vercelAdapter as i, abortable as l, hostCli as m, listVercelDeployments as n, vercelEnv as o, findUrl as p, resolveVercelTarget as r, vercelProject as s, hasVercelLogin as t, commandRejected as u, lastJsonObject as v, untilInterrupted as w, readDeployCommit as x, optionalString as y };
|