@vite-hub/kv 0.3.1 → 0.4.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 +14 -12
- package/dist/cli.js +4 -3
- package/dist/{cloudflare-kv-BIEUFzRT.js → cloudflare-kv-C3NO4C21.js} +18 -4
- package/dist/{cloudflare-kv-local-BBw3ZT1K.js → cloudflare-kv-local-C2sbIrFy.js} +2 -2
- package/dist/{config-BXEVoZE3.js → config-LfpUj9hs.js} +25 -23
- package/dist/{create-storage-BGsrQKw3.js → create-storage-BORQm2a8.js} +5 -5
- package/dist/{cursor-history-BqIQePNP.js → cursor-history-DRHh5bO5.js} +1 -1
- package/dist/{database-72Jk3VVk.js → database-oJdy0ZVX.js} +1 -1
- package/dist/{deno-kv-BM9mYdUp.js → deno-kv-D_VtffFv.js} +2 -2
- package/dist/{driver-BwxgaQ-f.d.ts → driver-R4Z5Z5fl.d.ts} +2 -2
- package/dist/{error-diagnostics-BxqvtEIb.js → error-diagnostics-C54QQEhN.js} +10 -2
- package/dist/{errors-DbwufFZp.js → errors-DzD6YNEH.js} +31 -3
- package/dist/errors.d.ts +6 -1
- package/dist/errors.js +2 -2
- package/dist/fs-lite-BAgpmNAF.js +2 -0
- package/dist/{fs-lite-BLZId9_P.js → fs-lite-BaklCLuV.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -27
- package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-nmRu_O3V.d.ts} +5 -0
- package/dist/{operations-Ch-gKaey.js → operations-CtrWLmPK.js} +3 -9
- package/dist/{operations-B-WZ7P1h.js → operations-D2iI9oN4.js} +238 -226
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +3 -2
- package/dist/{redis-shared-E5mahECF.js → redis-shared-5ogRd3-Y.js} +1 -1
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -1
- package/dist/runtime/nitro-plugin.js +7 -4
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +2 -2
- package/dist/runtime/unstorage-driver.js +6 -2
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -2
- package/dist/{types-DEiKew_3.d.ts → types-Dv-OSXZC.d.ts} +33 -20
- package/dist/{upstash-DDlqTttY.js → upstash-B-vaUYqO.js} +2 -2
- package/dist/virtual-module.d.ts +1 -0
- package/dist/vite.d.ts +17 -5
- package/dist/vite.js +601 -334
- package/package.json +5 -5
- package/dist/fs-lite-RAoxu8L0.js +0 -2
- package/dist/main-F3Y22_uV.js +0 -2353
- package/dist/rolldown-runtime-CMFfr-1z.js +0 -26
|
@@ -4,234 +4,11 @@ import { readdir } from "node:fs/promises";
|
|
|
4
4
|
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
|
+
import { defineDiagnostics } from "nostics";
|
|
7
8
|
import { tmpdir } from "node:os";
|
|
8
9
|
import "node:url";
|
|
9
|
-
import { defineDiagnostics } from "nostics";
|
|
10
10
|
import { createBirpc } from "birpc";
|
|
11
11
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
12
|
-
//#region ../internal/src/cli.ts
|
|
13
|
-
/**
|
|
14
|
-
* The seed files in `dir` and its subfolders, as sorted paths relative to `dir` with `/`. Files and folders whose name
|
|
15
|
-
* starts with `.`, such as `.gitkeep`, are not seed files. Returns `undefined` when `dir` does not exist.
|
|
16
|
-
*/
|
|
17
|
-
async function listSeedFiles(dir) {
|
|
18
|
-
const entries = await readdir(dir, {
|
|
19
|
-
recursive: true,
|
|
20
|
-
withFileTypes: true
|
|
21
|
-
}).catch((error) => {
|
|
22
|
-
if (error.code === "ENOENT") return void 0;
|
|
23
|
-
throw error;
|
|
24
|
-
});
|
|
25
|
-
if (!entries) return;
|
|
26
|
-
return entries.filter((entry) => entry.isFile()).map((entry) => relative(dir, join(entry.parentPath, entry.name)).replaceAll("\\", "/")).filter((file) => !file.split("/").some((segment) => segment.startsWith("."))).sort();
|
|
27
|
-
}
|
|
28
|
-
function parseViteHubDevTimeout(value, error) {
|
|
29
|
-
if (!/^\d+$/.test(value)) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
|
|
30
|
-
const timeout = Number(value);
|
|
31
|
-
if (timeout > 2147483647) throw error("--timeout must be at most 2147483647 milliseconds.");
|
|
32
|
-
if (!Number.isInteger(timeout) || timeout < 1) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
|
|
33
|
-
return timeout;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Reads one dev target option at `args[index]`: `--url <url>`, `--server <url>`,
|
|
37
|
-
* `--url=<url>`, `--timeout <ms>` or `--timeout=<ms>`.
|
|
38
|
-
*
|
|
39
|
-
* Returns the number of extra arguments that the option used (`0` or `1`), or
|
|
40
|
-
* `undefined` when `args[index]` is not a dev target option.
|
|
41
|
-
*/
|
|
42
|
-
function readViteHubDevTargetOption(args, index, target, errors) {
|
|
43
|
-
const arg = args[index];
|
|
44
|
-
if (arg === void 0) return;
|
|
45
|
-
const readValue = () => {
|
|
46
|
-
const value = args[index + 1];
|
|
47
|
-
if (!value || value.startsWith("-")) throw errors.missingValue(`Missing value for ${arg}.`);
|
|
48
|
-
return value;
|
|
49
|
-
};
|
|
50
|
-
if (arg === "--url" || arg === "--server") {
|
|
51
|
-
target.url = readValue();
|
|
52
|
-
return 1;
|
|
53
|
-
}
|
|
54
|
-
if (arg.startsWith("--url=")) {
|
|
55
|
-
const value = arg.slice(6);
|
|
56
|
-
if (!value) throw errors.missingValue(`Missing value for ${arg}.`);
|
|
57
|
-
target.url = value;
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
if (arg === "--timeout") {
|
|
61
|
-
target.timeout = parseViteHubDevTimeout(readValue(), errors.invalidTimeout);
|
|
62
|
-
return 1;
|
|
63
|
-
}
|
|
64
|
-
if (arg.startsWith("--timeout=")) {
|
|
65
|
-
target.timeout = parseViteHubDevTimeout(arg.slice(10), errors.invalidInlineTimeout);
|
|
66
|
-
return 0;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Reads `--<name> <value>` or `--<name>=<value>` at `args[index]`. Returns the value and the number of extra arguments
|
|
71
|
-
* that the option used (`0` or `1`), or `undefined` when `args[index]` is another argument. Throws `error` when the value
|
|
72
|
-
* is missing.
|
|
73
|
-
*/
|
|
74
|
-
function readCliOptionValue(args, index, name, error) {
|
|
75
|
-
const arg = args[index];
|
|
76
|
-
if (arg === `--${name}`) {
|
|
77
|
-
const value = args[index + 1];
|
|
78
|
-
if (value === void 0 || value.startsWith("--")) throw error(`--${name} needs a value.`);
|
|
79
|
-
return {
|
|
80
|
-
consumed: 1,
|
|
81
|
-
value
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (arg.startsWith(`--${name}=`)) return {
|
|
85
|
-
consumed: 0,
|
|
86
|
-
value: arg.slice(name.length + 3)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/** Reads the value of `--<name>` as an integer from 1. Throws `error` for any other value. */
|
|
90
|
-
function parseCliPositiveInteger(name, value, error) {
|
|
91
|
-
const number = Number(value);
|
|
92
|
-
if (!value || !Number.isInteger(number) || number < 1) throw error(`--${name} must be a positive integer.`);
|
|
93
|
-
return number;
|
|
94
|
-
}
|
|
95
|
-
/** Writes a command failure: as `{ error }` JSON on stdout with `--json`, else the message and fix on stderr. Returns exit code 1. */
|
|
96
|
-
function writeCliFailure(json, streams, failure) {
|
|
97
|
-
if (json) streams.stdout.write(`${JSON.stringify({ error: failure }, null, 2)}\n`);
|
|
98
|
-
else streams.stderr.write(`${failure.message}${failure.fix ? `\n${failure.fix}` : ""}\n`);
|
|
99
|
-
return 1;
|
|
100
|
-
}
|
|
101
|
-
/** Asks a question on the terminal through stderr. Only `y` or `yes`, in any case, is a yes. */
|
|
102
|
-
async function askOnTerminal(question) {
|
|
103
|
-
const terminal = createInterface({
|
|
104
|
-
input: process.stdin,
|
|
105
|
-
output: process.stderr
|
|
106
|
-
});
|
|
107
|
-
try {
|
|
108
|
-
return /^y(es)?$/i.test((await terminal.question(question)).trim());
|
|
109
|
-
} finally {
|
|
110
|
-
terminal.close();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/** File in the project root where the running dev server tells commands where it listens. */
|
|
114
|
-
const viteHubDevServerFile = ".vitehub/dev-server.json";
|
|
115
|
-
function writeViteHubDevServerFile(root, info) {
|
|
116
|
-
const file = join(root, viteHubDevServerFile);
|
|
117
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
118
|
-
writeFileSync(file, `${JSON.stringify(info)}\n`);
|
|
119
|
-
}
|
|
120
|
-
function removeViteHubDevServerFile(root) {
|
|
121
|
-
rmSync(join(root, viteHubDevServerFile), { force: true });
|
|
122
|
-
}
|
|
123
|
-
/** The dev server that runs in `root`, or undefined when there is no file or it is not valid. */
|
|
124
|
-
function readViteHubDevServerFile(root) {
|
|
125
|
-
try {
|
|
126
|
-
const value = JSON.parse(readFileSync(join(root, viteHubDevServerFile), "utf8"));
|
|
127
|
-
const url = isRecord(value) ? value.url : void 0;
|
|
128
|
-
const served = isRecord(value) ? value.root : void 0;
|
|
129
|
-
return typeof url === "string" && url && typeof served === "string" && served ? {
|
|
130
|
-
root: served,
|
|
131
|
-
url
|
|
132
|
-
} : void 0;
|
|
133
|
-
} catch {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Where a command finds the dev server of its project: the file that the server wrote in a project root, else
|
|
139
|
-
* `VITEHUB_DEV_SERVER_URL`. It never guesses a port, since another project may use it.
|
|
140
|
-
*/
|
|
141
|
-
function findViteHubDevServerUrl(roots, env) {
|
|
142
|
-
for (const root of roots) {
|
|
143
|
-
const file = readViteHubDevServerFile(root);
|
|
144
|
-
if (file && roots.some((candidate) => candidate.replace(/\/+$/, "") === file.root.replace(/\/+$/, ""))) return file.url;
|
|
145
|
-
}
|
|
146
|
-
return env["VITEHUB_DEV_SERVER_URL"] || void 0;
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region ../internal/src/build/vite.ts
|
|
150
|
-
const projectRootDirectoryMarkers = [
|
|
151
|
-
["server", "agents"],
|
|
152
|
-
["server", "channels"],
|
|
153
|
-
["server", "connections"],
|
|
154
|
-
["server", "browsers"],
|
|
155
|
-
["server", "emails"],
|
|
156
|
-
["server", "schedules"],
|
|
157
|
-
["server", "workspaces"]
|
|
158
|
-
];
|
|
159
|
-
const projectRootFileMarkers = [
|
|
160
|
-
["package.json"],
|
|
161
|
-
["nuxt.config.ts"],
|
|
162
|
-
["nuxt.config.mts"],
|
|
163
|
-
["nuxt.config.js"],
|
|
164
|
-
["nuxt.config.mjs"]
|
|
165
|
-
];
|
|
166
|
-
function createNoExternalAddition(...packageNames) {
|
|
167
|
-
return (current) => {
|
|
168
|
-
if (current === true) return;
|
|
169
|
-
const values = Array.isArray(current) ? current : [current];
|
|
170
|
-
const missing = packageNames.filter((packageName) => !values.includes(packageName));
|
|
171
|
-
return missing.length ? missing : void 0;
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function isServerEnvironment(name, config) {
|
|
175
|
-
return name === "ssr" || config.consumer === "server";
|
|
176
|
-
}
|
|
177
|
-
function includesNitroVitePlugin(value) {
|
|
178
|
-
if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
|
|
179
|
-
if (!value || typeof value !== "object") return false;
|
|
180
|
-
return "name" in value && value.name === "nitro:main";
|
|
181
|
-
}
|
|
182
|
-
function hasNitroConfigContext(config) {
|
|
183
|
-
return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
|
|
184
|
-
}
|
|
185
|
-
function shouldSkipViteProviderBuild(command) {
|
|
186
|
-
return command === "serve";
|
|
187
|
-
}
|
|
188
|
-
function resolveViteHubProjectRoot(root, options = {}) {
|
|
189
|
-
const resolvedRoot = resolve(root);
|
|
190
|
-
const temporaryRoot = resolve(tmpdir());
|
|
191
|
-
const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
|
|
192
|
-
if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
|
|
193
|
-
if (basename(resolvedRoot) === "app") {
|
|
194
|
-
const parent = dirname(resolvedRoot);
|
|
195
|
-
if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
|
|
196
|
-
"nuxt.config.ts",
|
|
197
|
-
"nuxt.config.mts",
|
|
198
|
-
"nuxt.config.js",
|
|
199
|
-
"nuxt.config.mjs"
|
|
200
|
-
]))) return parent;
|
|
201
|
-
}
|
|
202
|
-
let current = resolvedRoot;
|
|
203
|
-
while (true) {
|
|
204
|
-
if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
|
|
205
|
-
if (hasProjectRootMarker(current)) return current;
|
|
206
|
-
const parent = dirname(current);
|
|
207
|
-
if (parent === current) return resolvedRoot;
|
|
208
|
-
current = parent;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function hasProjectRootDirectoryMarker(root) {
|
|
212
|
-
for (const marker of projectRootDirectoryMarkers) try {
|
|
213
|
-
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if (error.code !== "ENOENT") throw error;
|
|
216
|
-
}
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
function hasProjectRootMarker(root) {
|
|
220
|
-
if (hasProjectRootDirectoryMarker(root)) return true;
|
|
221
|
-
return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
|
|
222
|
-
}
|
|
223
|
-
function hasProjectRootFileMarker(root, markers) {
|
|
224
|
-
for (const marker of markers) {
|
|
225
|
-
const path = Array.isArray(marker) ? marker : [marker];
|
|
226
|
-
try {
|
|
227
|
-
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
228
|
-
} catch (error) {
|
|
229
|
-
if (error.code !== "ENOENT") throw error;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
12
|
//#region ../internal/src/error-diagnostics.ts
|
|
236
13
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
237
14
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
@@ -403,7 +180,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
403
180
|
},
|
|
404
181
|
INTERNAL_R0004: {
|
|
405
182
|
...dynamicError,
|
|
406
|
-
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `
|
|
183
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
|
|
407
184
|
},
|
|
408
185
|
INTERNAL_R0005: {
|
|
409
186
|
...dynamicError,
|
|
@@ -449,6 +226,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
449
226
|
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
450
227
|
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
451
228
|
},
|
|
229
|
+
INTERNAL_DEV_SERVER_NOT_FOUND: {
|
|
230
|
+
why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
|
|
231
|
+
fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
|
|
232
|
+
},
|
|
452
233
|
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
453
234
|
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
454
235
|
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
@@ -496,6 +277,236 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
496
277
|
}
|
|
497
278
|
});
|
|
498
279
|
//#endregion
|
|
280
|
+
//#region ../internal/src/cli.ts
|
|
281
|
+
/**
|
|
282
|
+
* The seed files in `dir` and its subfolders, as sorted paths relative to `dir` with `/`. Files and folders whose name
|
|
283
|
+
* starts with `.`, such as `.gitkeep`, are not seed files. Returns `undefined` when `dir` does not exist.
|
|
284
|
+
*/
|
|
285
|
+
async function listSeedFiles(dir) {
|
|
286
|
+
const entries = await readdir(dir, {
|
|
287
|
+
recursive: true,
|
|
288
|
+
withFileTypes: true
|
|
289
|
+
}).catch((error) => {
|
|
290
|
+
if (error.code === "ENOENT") return void 0;
|
|
291
|
+
throw error;
|
|
292
|
+
});
|
|
293
|
+
if (!entries) return;
|
|
294
|
+
return entries.filter((entry) => entry.isFile()).map((entry) => relative(dir, join(entry.parentPath, entry.name)).replaceAll("\\", "/")).filter((file) => !file.split("/").some((segment) => segment.startsWith("."))).sort();
|
|
295
|
+
}
|
|
296
|
+
function parseViteHubDevTimeout(value, error) {
|
|
297
|
+
if (!/^\d+$/.test(value)) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
|
|
298
|
+
const timeout = Number(value);
|
|
299
|
+
if (timeout > 2147483647) throw error("--timeout must be at most 2147483647 milliseconds.");
|
|
300
|
+
if (!Number.isInteger(timeout) || timeout < 1) throw error("--timeout must be an integer from 1 to 2147483647 milliseconds.");
|
|
301
|
+
return timeout;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Reads one dev target option at `args[index]`: `--url <url>`, `--url=<url>`,
|
|
305
|
+
* `--timeout <ms>` or `--timeout=<ms>`. `--url` is always the app, and `--server` fails with the fix.
|
|
306
|
+
*
|
|
307
|
+
* Returns the number of extra arguments that the option used (`0` or `1`), or
|
|
308
|
+
* `undefined` when `args[index]` is not a dev target option.
|
|
309
|
+
*/
|
|
310
|
+
function readViteHubDevTargetOption(args, index, target, errors) {
|
|
311
|
+
const arg = args[index];
|
|
312
|
+
if (arg === void 0) return;
|
|
313
|
+
const readValue = () => {
|
|
314
|
+
const value = args[index + 1];
|
|
315
|
+
if (!value || value.startsWith("-")) throw errors.missingValue(`Missing value for ${arg}.`);
|
|
316
|
+
return value;
|
|
317
|
+
};
|
|
318
|
+
if (arg === "--server" || arg.startsWith("--server=")) throw errors.unknownOption("--server is now --url. Pass --url with the app URL, such as --url http://localhost:3000.");
|
|
319
|
+
if (arg === "--url") {
|
|
320
|
+
target.url = readValue();
|
|
321
|
+
return 1;
|
|
322
|
+
}
|
|
323
|
+
if (arg.startsWith("--url=")) {
|
|
324
|
+
const value = arg.slice(6);
|
|
325
|
+
if (!value) throw errors.missingValue(`Missing value for ${arg}.`);
|
|
326
|
+
target.url = value;
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
if (arg === "--timeout") {
|
|
330
|
+
target.timeout = parseViteHubDevTimeout(readValue(), errors.invalidTimeout);
|
|
331
|
+
return 1;
|
|
332
|
+
}
|
|
333
|
+
if (arg.startsWith("--timeout=")) {
|
|
334
|
+
target.timeout = parseViteHubDevTimeout(arg.slice(10), errors.invalidInlineTimeout);
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Reads `--<name> <value>` or `--<name>=<value>` at `args[index]`. Returns the value and the number of extra arguments
|
|
340
|
+
* that the option used (`0` or `1`), or `undefined` when `args[index]` is another argument. Throws `error` when the value
|
|
341
|
+
* is missing.
|
|
342
|
+
*/
|
|
343
|
+
function readCliOptionValue(args, index, name, error) {
|
|
344
|
+
const arg = args[index];
|
|
345
|
+
if (arg === `--${name}`) {
|
|
346
|
+
const value = args[index + 1];
|
|
347
|
+
if (value === void 0 || value.startsWith("--")) throw error(`--${name} needs a value.`);
|
|
348
|
+
return {
|
|
349
|
+
consumed: 1,
|
|
350
|
+
value
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
if (arg.startsWith(`--${name}=`)) return {
|
|
354
|
+
consumed: 0,
|
|
355
|
+
value: arg.slice(name.length + 3)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/** Reads the value of `--<name>` as an integer from 1. Throws `error` for any other value. */
|
|
359
|
+
function parseCliPositiveInteger(name, value, error) {
|
|
360
|
+
const number = Number(value);
|
|
361
|
+
if (!value || !Number.isInteger(number) || number < 1) throw error(`--${name} must be a positive integer.`);
|
|
362
|
+
return number;
|
|
363
|
+
}
|
|
364
|
+
/** Writes a command failure: as `{ error }` JSON on stdout with `--json`, else the message and fix on stderr. Returns exit code 1. */
|
|
365
|
+
function writeCliFailure(json, streams, failure) {
|
|
366
|
+
if (json) streams.stdout.write(`${JSON.stringify({ error: failure }, null, 2)}\n`);
|
|
367
|
+
else streams.stderr.write(`${failure.message}${failure.fix ? `\n${failure.fix}` : ""}\n`);
|
|
368
|
+
return 1;
|
|
369
|
+
}
|
|
370
|
+
/** Asks a question on the terminal through stderr. Only `y` or `yes`, in any case, is a yes. */
|
|
371
|
+
async function askOnTerminal(question) {
|
|
372
|
+
const terminal = createInterface({
|
|
373
|
+
input: process.stdin,
|
|
374
|
+
output: process.stderr
|
|
375
|
+
});
|
|
376
|
+
try {
|
|
377
|
+
return /^y(es)?$/i.test((await terminal.question(question)).trim());
|
|
378
|
+
} finally {
|
|
379
|
+
terminal.close();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/** File in the project root where the running dev server tells commands where it listens. */
|
|
383
|
+
const viteHubDevServerFile = ".vitehub/dev-server.json";
|
|
384
|
+
function writeViteHubDevServerFile(root, info) {
|
|
385
|
+
const file = join(root, viteHubDevServerFile);
|
|
386
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
387
|
+
writeFileSync(file, `${JSON.stringify(info)}\n`);
|
|
388
|
+
}
|
|
389
|
+
function removeViteHubDevServerFile(root) {
|
|
390
|
+
rmSync(join(root, viteHubDevServerFile), { force: true });
|
|
391
|
+
}
|
|
392
|
+
/** The dev server that runs in `root`, or undefined when there is no file or it is not valid. */
|
|
393
|
+
function readViteHubDevServerFile(root) {
|
|
394
|
+
try {
|
|
395
|
+
const value = JSON.parse(readFileSync(join(root, viteHubDevServerFile), "utf8"));
|
|
396
|
+
const url = isRecord(value) ? value.url : void 0;
|
|
397
|
+
const served = isRecord(value) ? value.root : void 0;
|
|
398
|
+
return typeof url === "string" && url && typeof served === "string" && served ? {
|
|
399
|
+
root: served,
|
|
400
|
+
url
|
|
401
|
+
} : void 0;
|
|
402
|
+
} catch {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Where a command finds the dev server of its project: the file that the server wrote in a project root, else
|
|
408
|
+
* `VITEHUB_DEV_SERVER_URL`. It never guesses a port, since another project may use it.
|
|
409
|
+
*/
|
|
410
|
+
function findViteHubDevServerUrl(roots, env) {
|
|
411
|
+
for (const root of roots) {
|
|
412
|
+
const file = readViteHubDevServerFile(root);
|
|
413
|
+
if (file && roots.some((candidate) => candidate.replace(/\/+$/, "") === file.root.replace(/\/+$/, ""))) return file.url;
|
|
414
|
+
}
|
|
415
|
+
return env["VITEHUB_DEV_SERVER_URL"] || void 0;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region ../internal/src/build/vite.ts
|
|
419
|
+
const projectRootDirectoryMarkers = [
|
|
420
|
+
["server", "agents"],
|
|
421
|
+
["server", "channels"],
|
|
422
|
+
["server", "connections"],
|
|
423
|
+
["server", "browsers"],
|
|
424
|
+
["server", "emails"],
|
|
425
|
+
["server", "schedules"],
|
|
426
|
+
["server", "workspaces"]
|
|
427
|
+
];
|
|
428
|
+
const projectRootFileMarkers = [
|
|
429
|
+
["package.json"],
|
|
430
|
+
["nuxt.config.ts"],
|
|
431
|
+
["nuxt.config.mts"],
|
|
432
|
+
["nuxt.config.js"],
|
|
433
|
+
["nuxt.config.mjs"]
|
|
434
|
+
];
|
|
435
|
+
function createNoExternalAddition(...packageNames) {
|
|
436
|
+
return (current) => {
|
|
437
|
+
if (current === true) return;
|
|
438
|
+
const values = Array.isArray(current) ? current : [current];
|
|
439
|
+
const missing = packageNames.filter((packageName) => !values.includes(packageName));
|
|
440
|
+
return missing.length ? missing : void 0;
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function isServerEnvironment(name, config) {
|
|
444
|
+
return name === "ssr" || config.consumer === "server";
|
|
445
|
+
}
|
|
446
|
+
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
447
|
+
/**
|
|
448
|
+
* Set by `vite-hub/nuxt` when it replays Vite config hooks for `nuxt prepare`. Prepare uses `command: "build"` to write
|
|
449
|
+
* the same types as the build, but it builds nothing.
|
|
450
|
+
*/
|
|
451
|
+
const VITEHUB_PREPARE = "__vitehubPrepare";
|
|
452
|
+
function includesNitroVitePlugin(value) {
|
|
453
|
+
if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
|
|
454
|
+
if (!value || typeof value !== "object") return false;
|
|
455
|
+
return "name" in value && value.name === "nitro:main";
|
|
456
|
+
}
|
|
457
|
+
function hasNitroConfigContext(config) {
|
|
458
|
+
return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
|
|
459
|
+
}
|
|
460
|
+
function shouldSkipViteProviderBuild(command) {
|
|
461
|
+
return command === "serve";
|
|
462
|
+
}
|
|
463
|
+
function resolveViteHubProjectRoot(root, options = {}) {
|
|
464
|
+
const resolvedRoot = resolve(root);
|
|
465
|
+
const temporaryRoot = resolve(tmpdir());
|
|
466
|
+
const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
|
|
467
|
+
if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
|
|
468
|
+
if (basename(resolvedRoot) === "app") {
|
|
469
|
+
const parent = dirname(resolvedRoot);
|
|
470
|
+
if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
|
|
471
|
+
"nuxt.config.ts",
|
|
472
|
+
"nuxt.config.mts",
|
|
473
|
+
"nuxt.config.js",
|
|
474
|
+
"nuxt.config.mjs"
|
|
475
|
+
]))) return parent;
|
|
476
|
+
}
|
|
477
|
+
let current = resolvedRoot;
|
|
478
|
+
while (true) {
|
|
479
|
+
if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
|
|
480
|
+
if (hasProjectRootMarker(current)) return current;
|
|
481
|
+
const parent = dirname(current);
|
|
482
|
+
if (parent === current) return resolvedRoot;
|
|
483
|
+
current = parent;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function hasProjectRootDirectoryMarker(root) {
|
|
487
|
+
for (const marker of projectRootDirectoryMarkers) try {
|
|
488
|
+
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
489
|
+
} catch (error) {
|
|
490
|
+
if (error.code !== "ENOENT") throw error;
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
function hasProjectRootMarker(root) {
|
|
495
|
+
if (hasProjectRootDirectoryMarker(root)) return true;
|
|
496
|
+
return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
|
|
497
|
+
}
|
|
498
|
+
function hasProjectRootFileMarker(root, markers) {
|
|
499
|
+
for (const marker of markers) {
|
|
500
|
+
const path = Array.isArray(marker) ? marker : [marker];
|
|
501
|
+
try {
|
|
502
|
+
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
503
|
+
} catch (error) {
|
|
504
|
+
if (error.code !== "ENOENT") throw error;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
499
510
|
//#region ../internal/src/operation-rpc.ts
|
|
500
511
|
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
501
512
|
const operationRpcPath = "/_vitehub/rpc";
|
|
@@ -900,6 +911,7 @@ const reservedOperationNamespaces = [
|
|
|
900
911
|
"drain",
|
|
901
912
|
"login",
|
|
902
913
|
"logout",
|
|
914
|
+
"update",
|
|
903
915
|
"whoami"
|
|
904
916
|
]
|
|
905
917
|
];
|
|
@@ -1348,4 +1360,4 @@ async function callOperationFromCli(call, name, input) {
|
|
|
1348
1360
|
}, name, input);
|
|
1349
1361
|
}
|
|
1350
1362
|
//#endregion
|
|
1351
|
-
export {
|
|
1363
|
+
export { writeCliFailure as A, askOnTerminal as C, readViteHubDevServerFile as D, readCliOptionValue as E, internalErrorDiagnostics as M, readViteHubDevTargetOption as O, shouldSkipViteProviderBuild as S, parseCliPositiveInteger as T, VITEHUB_PROJECT_ROOT as _, operationRootHeader as a, isServerEnvironment as b, projectRootHash as c, defineOperation as d, answerOperationRpc as f, VITEHUB_PREPARE as g, readOperationRpcCall as h, createOperationRegistry as i, writeViteHubDevServerFile as j, removeViteHubDevServerFile as k, runOperation as l, operationRpcRefusal as m, callOperationFromCli as n, operationRpcHeader as o, operationRpcPath as p, collectOperationContributions as r, operationsOf as s, assertOperationProject as t, toOperationFailure as u, createNoExternalAddition as v, listSeedFiles as w, resolveViteHubProjectRoot as x, hasNitroConfigContext as y };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
1
|
+
import { c as KVDriver } from "./types-Dv-OSXZC.js";
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-nmRu_O3V.js";
|
|
3
3
|
//#region src/runtime/operations.d.ts
|
|
4
4
|
interface KVDevListResult {
|
|
5
5
|
/** Present when more keys exist. Pass it as `--cursor` to read the next page. */
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc,
|
|
1
|
+
import { M as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-D2iI9oN4.js";
|
|
2
2
|
import { t as kvDevMaximumListLimit } from "./results-p7nPCnaJ.js";
|
|
3
3
|
import { n as isViteHubLoopbackPeer } from "./dev-peer-CHafxbtj.js";
|
|
4
4
|
import * as v from "valibot";
|
|
@@ -204,6 +204,7 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
204
204
|
sections: "all"
|
|
205
205
|
},
|
|
206
206
|
development: true,
|
|
207
|
+
projectRoot: root,
|
|
207
208
|
surface: "cli",
|
|
208
209
|
user: null,
|
|
209
210
|
request,
|
|
@@ -237,7 +238,7 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
237
238
|
}
|
|
238
239
|
//#endregion
|
|
239
240
|
//#region src/operations.ts
|
|
240
|
-
const runtime = () => import("./operations-
|
|
241
|
+
const runtime = () => import("./operations-CtrWLmPK.js");
|
|
241
242
|
const store = v.optional(v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name a store.")));
|
|
242
243
|
const key = v.string();
|
|
243
244
|
function defineKVOperation(definition) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-C54QQEhN.js";
|
|
2
2
|
//#region src/runtime/redis-shared.ts
|
|
3
3
|
const redisIncrementScript = `
|
|
4
4
|
local existed = redis.call('EXISTS', KEYS[1])
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { t as KVRuntimeDriver } from "../driver-R4Z5Z5fl.js";
|
|
2
2
|
//#region src/runtime/cloudflare-kv.d.ts
|
|
3
3
|
declare function createCloudflareDriver(options: Record<string, unknown>): KVRuntimeDriver;
|
|
4
4
|
export declare function createCloudflareKVStorage(options: Record<string, unknown>): unknown;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createCloudflareKVStorage, t as createCloudflareDriver } from "../cloudflare-kv-
|
|
1
|
+
import { n as createCloudflareKVStorage, t as createCloudflareDriver } from "../cloudflare-kv-C3NO4C21.js";
|
|
2
2
|
export { createCloudflareKVStorage, createCloudflareDriver as default };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { t as kvInferredStoreNotice } from "../config-
|
|
1
|
+
import { t as kvInferredStoreNotice } from "../config-LfpUj9hs.js";
|
|
2
2
|
import { disposeKVStores } from "@vite-hub/kv";
|
|
3
3
|
//#region src/runtime/nitro-plugin.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Prints the driver that each inferred store uses in this process. A Node build of `vitehub()` prints the stores in its
|
|
6
|
+
* Durability table at boot, so KV prints nothing there.
|
|
7
|
+
*/
|
|
5
8
|
async function logInferredStores() {
|
|
6
|
-
const { kv } = await import("#vitehub/kv/config");
|
|
7
|
-
if (!kv) return;
|
|
9
|
+
const { durabilityReportsStores, kv } = await import("#vitehub/kv/config");
|
|
10
|
+
if (!kv || durabilityReportsStores) return;
|
|
8
11
|
for (const [name, store] of Object.entries(kv.stores ?? { default: kv.store })) {
|
|
9
12
|
const notice = kvInferredStoreNotice(name, store);
|
|
10
13
|
if (notice) console.info(notice);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { z as ResolvedRedisKVStoreConfig } from "../types-Dv-OSXZC.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-R4Z5Z5fl.js";
|
|
3
3
|
//#region src/runtime/redis-driver.d.ts
|
|
4
4
|
/** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
|
|
5
5
|
export declare function resolveRedisUrl(url: string, env?: Record<string, string | undefined>): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as invariant } from "../invariant-DolT9EEx.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
+
import { n as kvErrorDiagnostics } from "../error-diagnostics-C54QQEhN.js";
|
|
3
3
|
import { o as normalizeKey } from "../utils2-FozcTsmb.js";
|
|
4
4
|
import { t as chunks } from "../batch--v0ri69O.js";
|
|
5
|
-
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-
|
|
5
|
+
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-5ogRd3-Y.js";
|
|
6
6
|
import { Redis } from "ioredis";
|
|
7
7
|
//#region src/runtime/redis-driver.ts
|
|
8
8
|
/** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
|
|
@@ -14,6 +14,10 @@ function createKVStorageDriver(options = {}) {
|
|
|
14
14
|
const base = normalizeKey(options.base);
|
|
15
15
|
const prefix = base ? `${base}:` : "";
|
|
16
16
|
const key = (name) => prefix + normalizeKey(name);
|
|
17
|
+
const below = (name) => {
|
|
18
|
+
const value = key(name);
|
|
19
|
+
return value && !value.endsWith(":") ? `${value}:` : value;
|
|
20
|
+
};
|
|
17
21
|
const store = () => options.store === void 0 ? kv : kv.store(options.store);
|
|
18
22
|
return {
|
|
19
23
|
name: "vitehub-kv",
|
|
@@ -24,9 +28,9 @@ function createKVStorageDriver(options = {}) {
|
|
|
24
28
|
setItem: (name, value, opts) => unwrap(store().set(key(name), value, typeof opts?.ttl === "number" ? { ttl: opts.ttl } : void 0)),
|
|
25
29
|
removeItem: (name) => unwrap(store().delete(key(name))),
|
|
26
30
|
async getKeys(keyBase) {
|
|
27
|
-
return (await unwrap(store().
|
|
31
|
+
return (await unwrap(store().list({ prefix: below(keyBase) }))).keys.map((name) => name.slice(prefix.length));
|
|
28
32
|
},
|
|
29
|
-
clear: (keyBase) => unwrap(store().clear(
|
|
33
|
+
clear: (keyBase) => unwrap(store().clear({ prefix: below(keyBase) }))
|
|
30
34
|
};
|
|
31
35
|
}
|
|
32
36
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { B as ResolvedUpstashKVStoreConfig } from "../types-Dv-OSXZC.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-R4Z5Z5fl.js";
|
|
3
3
|
//#region src/runtime/upstash-driver.d.ts
|
|
4
4
|
export default function createUpstashKVDriver(options: ResolvedUpstashKVStoreConfig): KVRuntimeDriver;
|
|
5
5
|
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as invariant } from "../invariant-DolT9EEx.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
+
import { n as kvErrorDiagnostics } from "../error-diagnostics-C54QQEhN.js";
|
|
3
3
|
import { o as normalizeKey } from "../utils2-FozcTsmb.js";
|
|
4
4
|
import { t as chunks } from "../batch--v0ri69O.js";
|
|
5
|
-
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-
|
|
5
|
+
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-5ogRd3-Y.js";
|
|
6
6
|
import createDriver from "unstorage/drivers/upstash";
|
|
7
7
|
//#region src/runtime/upstash-driver.ts
|
|
8
8
|
const keyBatchSize = 1e3;
|