@vite-hub/workspace 0.0.2 → 0.0.3

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.
Files changed (77) hide show
  1. package/README.md +35 -0
  2. package/dist/{ai-Cztw4eLk.js → ai-Ce3PtWFW.js} +14 -3
  3. package/dist/{ai-hFdsvDHC.d.ts → ai-nmHdzjCM.d.ts} +1 -1
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/cloudflare.d.ts +4 -2
  7. package/dist/cloudflare.js +1 -2
  8. package/dist/collections.d.ts +2 -2
  9. package/dist/collections.js +1 -1
  10. package/dist/{config-Ca5DM8fF.d.ts → config-3I1BnsdO.d.ts} +1 -1
  11. package/dist/{config-DCQ6y30R.js → config-CDoyls2X.js} +1 -1
  12. package/dist/{config--r5unwPc.js → config-CZLO0m9h.js} +3 -3
  13. package/dist/{file-B2q9NE18.js → file-CHfsZpso.js} +7 -8
  14. package/dist/{files-xy0le-_U.js → files-QRV55OCx.js} +1 -1
  15. package/dist/{github-lIO6-2sH.js → github-CfA5vpJ5.js} +5 -10
  16. package/dist/{glob-DeH0dzZX.js → glob-D0vD_wRY.js} +6 -12
  17. package/dist/{host-I-_vDs05.js → host-CAnbugpI.js} +2 -2
  18. package/dist/{artifacts-store-BAV9jZpd.js → hosted-C1-tTTTf.js} +29 -3
  19. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +26 -4
  20. package/dist/hosted-vercel-blob.d.ts +1 -1
  21. package/dist/hosted-vercel-blob.js +1 -25
  22. package/dist/hosted.d.ts +1 -1
  23. package/dist/hosted.js +1 -29
  24. package/dist/index.d.ts +27 -35
  25. package/dist/index.js +18 -25
  26. package/dist/{lifecycle-Lhk3dAMt.js → lifecycle-BYoa9hVb.js} +3 -3
  27. package/dist/loader.d.ts +1 -1
  28. package/dist/loader.js +1 -1
  29. package/dist/mountx.d.ts +10 -0
  30. package/dist/mountx.js +143 -0
  31. package/dist/nitro.js +1 -1
  32. package/dist/nuxt.d.ts +1 -1
  33. package/dist/nuxt.js +1 -1
  34. package/dist/{provider-CeQciesl.js → provider-C3_elpEh.js} +1 -1
  35. package/dist/providers/github/store.d.ts +1 -1
  36. package/dist/providers/github/store.js +1 -361
  37. package/dist/publish.d.ts +1 -1
  38. package/dist/publish.js +1 -1
  39. package/dist/{registry-CoC9JxVt.d.ts → registry-BIQVCBWI.d.ts} +1 -1
  40. package/dist/{registry-C7DMdBXN.js → registry-CqyDTW9Y.js} +1 -1
  41. package/dist/{request-execution-C8qRcReq.js → request-execution-u9mgUXKX.js} +1 -1
  42. package/dist/runtime/assets.d.ts +1 -1
  43. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  44. package/dist/runtime/empty-registry.d.ts +1 -1
  45. package/dist/runtime/state.d.ts +3 -3
  46. package/dist/runtime/state.js +5 -5
  47. package/dist/runtime/workspace.d.ts +1 -1
  48. package/dist/runtime/workspace.js +1 -1
  49. package/dist/runtime-options-BsPSv5O7.js +13 -0
  50. package/dist/runtime.d.ts +5 -5
  51. package/dist/runtime.js +11 -28
  52. package/dist/server.d.ts +2 -2
  53. package/dist/server.js +3 -3
  54. package/dist/{shared-BRycRSbo.js → shared-jfogBrd5.js} +20 -2
  55. package/dist/source-metadata.d.ts +1 -1
  56. package/dist/source-metadata.js +1 -1
  57. package/dist/{state-DSAHEsq6.d.ts → state-TTqa3x3Y.d.ts} +2 -2
  58. package/dist/store-Bs1SLh55.js +414 -0
  59. package/dist/{sync-DO42ypji.js → sync-DiuDmSGk.js} +3 -3
  60. package/dist/test.d.ts +1 -1
  61. package/dist/test.js +1 -1
  62. package/dist/{types-DHkae7Cb.d.ts → types-60Yn149G.d.ts} +1 -17
  63. package/dist/{use-D16tf8Ph.d.ts → use-CUFSnFCS.d.ts} +2 -2
  64. package/dist/{use-d_PlAdOu.js → use-CsV3oIxH.js} +6 -23
  65. package/dist/{vite-NWC9mFjI.js → vite-tbfDxtlu.js} +332 -23
  66. package/dist/vite.d.ts +1 -1
  67. package/dist/vite.js +1 -1
  68. package/dist/{workspace-f2DBLmPZ.d.ts → workspace-66SKyiec.d.ts} +1 -1
  69. package/dist/{workspace-n4wBmdaM.js → workspace-C4k92Ow8.js} +8 -24
  70. package/package.json +13 -28
  71. package/dist/cli.d.ts +0 -31
  72. package/dist/cli.js +0 -303
  73. package/dist/cloudflare-env-CKxUs2fa.js +0 -20
  74. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  75. package/dist/providers/cloudflare/artifacts-store.js +0 -2
  76. package/dist/providers/vercel/blob-store.d.ts +0 -6
  77. package/dist/utils-BPdaCyI6.js +0 -55
package/dist/cli.d.ts DELETED
@@ -1,31 +0,0 @@
1
- //#region src/cli.d.ts
2
- interface WorkspaceCliContext {
3
- cwd: string;
4
- env: NodeJS.ProcessEnv;
5
- rootDir: string;
6
- stderr: {
7
- write: (chunk: string | Uint8Array) => unknown;
8
- };
9
- stdout: {
10
- write: (chunk: string | Uint8Array) => unknown;
11
- };
12
- }
13
- interface WorkspaceCliContributor {
14
- namespaces: Array<{
15
- description?: string;
16
- features: Array<{
17
- description?: string;
18
- name: string;
19
- run: (args: string[], context: WorkspaceCliContext) => Promise<number | void> | number | void;
20
- usage?: string;
21
- }>;
22
- name: string;
23
- }>;
24
- }
25
- interface WorkspaceDevCliOptions {
26
- fetch?: typeof fetch;
27
- }
28
- declare function runWorkspaceDevCli(args: string[], context: WorkspaceCliContext, options?: WorkspaceDevCliOptions): Promise<number>;
29
- declare function createWorkspaceCliContributor(): WorkspaceCliContributor;
30
- //#endregion
31
- export { createWorkspaceCliContributor, runWorkspaceDevCli };
package/dist/cli.js DELETED
@@ -1,303 +0,0 @@
1
- import { readWorkspaceDevToken, workspaceDevHeader, workspaceDevRoute, workspaceDevTokenHeader } from "./server.js";
2
- //#region src/cli.ts
3
- const workspaceCommandFeedbackIntervalMs = 15e3;
4
- const workspaceCommandStartedMessage = "[workspace] command started; first run may materialize sources.\n";
5
- const workspaceCommandWaitingMessage = "[workspace] command still running; sources may still be materializing.\n";
6
- function startWorkspaceCommandFeedback(context) {
7
- context.stderr.write(workspaceCommandStartedMessage);
8
- const timer = setInterval(() => context.stderr.write(workspaceCommandWaitingMessage), workspaceCommandFeedbackIntervalMs);
9
- timer.unref?.();
10
- return () => clearInterval(timer);
11
- }
12
- function formatDurationMs(durationMs) {
13
- return durationMs < 1e3 ? `${durationMs}ms` : `${(durationMs / 1e3).toFixed(1)}s`;
14
- }
15
- function workspaceDevDataNumber(event, key) {
16
- const value = event.data?.[key];
17
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
18
- }
19
- function writeWorkspaceDevProgress(context, event) {
20
- const duration = typeof event.durationMs === "number" ? ` (${formatDurationMs(event.durationMs)})` : "";
21
- if (event.status === "started") {
22
- context.stderr.write(`[workspace] ${event.label}...\n`);
23
- return;
24
- }
25
- if (event.status === "updating") {
26
- const files = workspaceDevDataNumber(event, "files");
27
- const bytes = workspaceDevDataNumber(event, "bytes");
28
- const detail = files === void 0 ? "" : `: ${files} file${files === 1 ? "" : "s"}${bytes === void 0 ? "" : `, ${bytes} bytes`}`;
29
- context.stderr.write(`[workspace] ${event.label}${detail}\n`);
30
- return;
31
- }
32
- if (event.status === "failed") {
33
- context.stderr.write(`[workspace] ${event.label} failed${duration}${event.error ? `: ${event.error}` : ""}\n`);
34
- return;
35
- }
36
- context.stderr.write(`[workspace] ${event.label} completed${duration}\n`);
37
- }
38
- function isWorkspaceDevStream(response) {
39
- return response.headers.get("content-type")?.toLowerCase().includes("application/x-ndjson") === true;
40
- }
41
- function handleWorkspaceDevStreamLine(line, context) {
42
- const parsed = JSON.parse(line);
43
- if (parsed.type === "progress" && parsed.event) {
44
- writeWorkspaceDevProgress(context, parsed.event);
45
- return;
46
- }
47
- if (parsed.type === "error") {
48
- context.stderr.write(`${parsed.error || "Workspace Dev command failed."}\n`);
49
- return {
50
- exitCode: 1,
51
- stderr: "",
52
- stdout: ""
53
- };
54
- }
55
- if (parsed.type === "result") return parsed.result || {};
56
- }
57
- async function readWorkspaceDevStream(response, context) {
58
- const reader = response.body?.getReader();
59
- if (!reader) return {};
60
- const decoder = new TextDecoder();
61
- let buffer = "";
62
- let result;
63
- for (;;) {
64
- const { done, value } = await reader.read();
65
- buffer += decoder.decode(value, { stream: !done });
66
- let newline = buffer.indexOf("\n");
67
- while (newline >= 0) {
68
- const line = buffer.slice(0, newline).trim();
69
- buffer = buffer.slice(newline + 1);
70
- if (line) result = handleWorkspaceDevStreamLine(line, context) ?? result;
71
- newline = buffer.indexOf("\n");
72
- }
73
- if (done) break;
74
- }
75
- const line = buffer.trim();
76
- if (line) result = handleWorkspaceDevStreamLine(line, context) ?? result;
77
- return result || {};
78
- }
79
- function writeWorkspaceDevUsage(context) {
80
- context.stdout.write([
81
- "Usage: vitehub workspace dev <workspace> [exec <command...>] [--url <url>] [--timeout <ms>]",
82
- "",
83
- "Run Workspace commands through a running Vite Development Server.",
84
- "Omit exec to open the interactive command loop.",
85
- "",
86
- "Options:",
87
- " --url <url> Compatible Vite Development Server URL. Defaults to http://localhost:5173.",
88
- " --timeout <ms> Workspace command timeout.",
89
- " --path <path> Workspace path to materialize for command sessions. Repeatable.",
90
- " -h, --help Show this help.",
91
- ""
92
- ].join("\n"));
93
- }
94
- function readOptionValue(args, index, flag) {
95
- const value = args[index + 1];
96
- if (!value || value.startsWith("-")) throw new Error(`Missing value for ${flag}.`);
97
- return value;
98
- }
99
- function parseWorkspaceDevArgs(args, env) {
100
- const parsed = {
101
- help: false,
102
- url: env.VITEHUB_DEV_SERVER_URL || "http://localhost:5173"
103
- };
104
- for (let index = 0; index < args.length; index += 1) {
105
- const arg = args[index];
106
- if (arg === "-h" || arg === "--help") {
107
- parsed.help = true;
108
- continue;
109
- }
110
- if (arg === "--url" || arg === "--server") {
111
- parsed.url = readOptionValue(args, index, arg);
112
- index += 1;
113
- continue;
114
- }
115
- if (arg.startsWith("--url=")) {
116
- parsed.url = arg.slice(6);
117
- continue;
118
- }
119
- if (arg === "--timeout") {
120
- const timeout = Number.parseInt(readOptionValue(args, index, arg), 10);
121
- if (!Number.isFinite(timeout) || timeout <= 0) throw new Error("--timeout must be a positive number.");
122
- parsed.timeout = timeout;
123
- index += 1;
124
- continue;
125
- }
126
- if (arg.startsWith("--timeout=")) {
127
- const timeout = Number.parseInt(arg.slice(10), 10);
128
- if (!Number.isFinite(timeout) || timeout <= 0) throw new Error("--timeout must be a positive number.");
129
- parsed.timeout = timeout;
130
- continue;
131
- }
132
- if (arg === "--path") {
133
- parsed.paths ??= [];
134
- parsed.paths.push(readOptionValue(args, index, arg));
135
- index += 1;
136
- continue;
137
- }
138
- if (arg.startsWith("--path=")) {
139
- parsed.paths ??= [];
140
- parsed.paths.push(arg.slice(7));
141
- continue;
142
- }
143
- if (arg.startsWith("-") && !parsed.workspace) throw new Error(`Unknown option: ${arg}.`);
144
- if (!parsed.workspace) {
145
- parsed.workspace = arg;
146
- continue;
147
- }
148
- if (arg === "exec") {
149
- const [command, ...commandArgs] = args.slice(index + 1);
150
- if (!command?.trim()) throw new Error("workspace dev exec requires a command.");
151
- parsed.command = command;
152
- if (commandArgs.length) parsed.args = commandArgs;
153
- break;
154
- }
155
- throw new Error(`Unexpected argument: ${arg}. Use exec <command...> for one-shot commands.`);
156
- }
157
- return parsed;
158
- }
159
- function endpointUrl(baseUrl) {
160
- return new URL(workspaceDevRoute, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).href;
161
- }
162
- async function readWorkspaceDiscovery(parsed, context, fetchImpl) {
163
- if (!parsed.workspace) {
164
- context.stderr.write("Missing Workspace Dev target.\n");
165
- return;
166
- }
167
- let url;
168
- try {
169
- url = endpointUrl(parsed.url);
170
- } catch {
171
- context.stderr.write(`Invalid Vite Development Server URL: ${parsed.url}\n`);
172
- return;
173
- }
174
- let response;
175
- try {
176
- response = await fetchImpl(url, { headers: {
177
- accept: "application/json",
178
- [workspaceDevHeader]: "1"
179
- } });
180
- } catch {
181
- context.stderr.write(`No Compatible Vite Development Server found at ${parsed.url}.\n`);
182
- return;
183
- }
184
- if (!response.ok) {
185
- context.stderr.write(`No Compatible Vite Development Server found at ${parsed.url}.\n`);
186
- return;
187
- }
188
- const discovery = await response.json().catch(() => ({}));
189
- if (typeof discovery.root === "string" && discovery.root !== context.rootDir) {
190
- context.stderr.write(`Compatible Vite Development Server root mismatch: ${discovery.root}\n`);
191
- return;
192
- }
193
- if (!(discovery.workspaces || []).flatMap((workspace) => typeof workspace.name === "string" ? [workspace.name] : []).includes(parsed.workspace)) {
194
- context.stderr.write(`Unknown Workspace Dev target: ${parsed.workspace}\n`);
195
- return;
196
- }
197
- return {
198
- tokenOptions: typeof discovery.workspaceDevTokenServerId === "string" ? { serverId: discovery.workspaceDevTokenServerId } : {},
199
- url
200
- };
201
- }
202
- async function sendWorkspaceCommand(target, parsed, context, fetchImpl) {
203
- if (!parsed.command) {
204
- context.stderr.write("Pass a command or run in an interactive terminal.\n");
205
- return 1;
206
- }
207
- const token = await readWorkspaceDevToken(context.rootDir, target.tokenOptions);
208
- if (!token) {
209
- context.stderr.write("No private Workspace Dev token found. Start the Compatible Vite Development Server first.\n");
210
- return 1;
211
- }
212
- const startedAt = Date.now();
213
- const stopFeedback = startWorkspaceCommandFeedback(context);
214
- try {
215
- const response = await fetchImpl(target.url, {
216
- body: JSON.stringify({ workspaceCommand: {
217
- ...parsed.args ? { args: parsed.args } : {},
218
- command: parsed.command,
219
- ...parsed.paths?.length ? { paths: parsed.paths } : {},
220
- ...parsed.timeout ? { timeout: parsed.timeout } : {},
221
- workspace: parsed.workspace
222
- } }),
223
- headers: {
224
- accept: "application/x-ndjson, application/json",
225
- "content-type": "application/json",
226
- [workspaceDevHeader]: "1",
227
- [workspaceDevTokenHeader]: token
228
- },
229
- method: "POST"
230
- });
231
- if (!response.ok) {
232
- context.stderr.write(`${await response.text()}\n`);
233
- return 1;
234
- }
235
- if (isWorkspaceDevStream(response)) stopFeedback();
236
- const result = isWorkspaceDevStream(response) ? await readWorkspaceDevStream(response, context) : await response.json().catch(() => ({}));
237
- if (typeof result.stdout === "string") context.stdout.write(result.stdout);
238
- if (typeof result.stderr === "string" && result.stderr) context.stderr.write(result.stderr);
239
- context.stderr.write(`[workspace] command completed (${formatDurationMs(Date.now() - startedAt)})\n`);
240
- return typeof result.exitCode === "number" ? result.exitCode : 0;
241
- } finally {
242
- stopFeedback();
243
- }
244
- }
245
- async function runInteractiveWorkspaceDev(parsed, context, fetchImpl, target) {
246
- const { createInterface } = await import("node:readline/promises");
247
- const readline = createInterface({
248
- input: process.stdin,
249
- output: process.stdout
250
- });
251
- context.stdout.write(`Connected to ${parsed.workspace} at ${parsed.url}\n`);
252
- try {
253
- for (;;) {
254
- const command = (await readline.question("> ")).trim();
255
- if (!command) continue;
256
- if (command === ".exit" || command === "exit") return 0;
257
- const exitCode = await sendWorkspaceCommand(target, {
258
- ...parsed,
259
- command
260
- }, context, fetchImpl);
261
- if (exitCode !== 0) return exitCode;
262
- }
263
- } finally {
264
- readline.close();
265
- }
266
- }
267
- async function runWorkspaceDevCli(args, context, options = {}) {
268
- let parsed;
269
- try {
270
- parsed = parseWorkspaceDevArgs(args, context.env);
271
- } catch (error) {
272
- context.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
273
- writeWorkspaceDevUsage(context);
274
- return 1;
275
- }
276
- if (parsed.help) {
277
- writeWorkspaceDevUsage(context);
278
- return 0;
279
- }
280
- const fetchImpl = options.fetch || globalThis.fetch;
281
- const target = await readWorkspaceDiscovery(parsed, context, fetchImpl);
282
- if (!target) return 1;
283
- if (parsed.command) return await sendWorkspaceCommand(target, parsed, context, fetchImpl);
284
- if (!process.stdin.isTTY) {
285
- context.stderr.write("Pass a command or run in an interactive terminal.\n");
286
- return 1;
287
- }
288
- return await runInteractiveWorkspaceDev(parsed, context, fetchImpl, target);
289
- }
290
- function createWorkspaceCliContributor() {
291
- return { namespaces: [{
292
- description: "Workspace development workflows.",
293
- features: [{
294
- description: "Run commands through a Workspace Session.",
295
- name: "dev",
296
- run: async (args, context) => await runWorkspaceDevCli(args, context),
297
- usage: "vitehub workspace dev <workspace> [exec <command...>]"
298
- }],
299
- name: "workspace"
300
- }] };
301
- }
302
- //#endregion
303
- export { createWorkspaceCliContributor, runWorkspaceDevCli };
@@ -1,20 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- //#region ../internal/src/runtime/cloudflare-env.ts
3
- let activeEnv;
4
- const activeEnvStorage = new AsyncLocalStorage();
5
- function setActiveCloudflareEnv(env) {
6
- activeEnv = env;
7
- globalThis.__env__ = env;
8
- try {
9
- activeEnvStorage.enterWith({ env });
10
- } catch {}
11
- }
12
- function getActiveCloudflareEnv() {
13
- const scoped = activeEnvStorage.getStore();
14
- return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
15
- }
16
- function getActiveCloudflareBinding(name) {
17
- return getActiveCloudflareEnv()?.[name];
18
- }
19
- //#endregion
20
- export { setActiveCloudflareEnv as n, getActiveCloudflareBinding as t };
@@ -1,6 +0,0 @@
1
- import { Zt as WorkspaceStore, t as CloudflareArtifactsWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
2
-
3
- //#region src/providers/cloudflare/artifacts-store.d.ts
4
- declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
5
- //#endregion
6
- export { createCloudflareArtifactsWorkspaceStore };
@@ -1,2 +0,0 @@
1
- import { t as createCloudflareArtifactsWorkspaceStore } from "../../artifacts-store-BAV9jZpd.js";
2
- export { createCloudflareArtifactsWorkspaceStore };
@@ -1,6 +0,0 @@
1
- import { Zt as WorkspaceStore, w as VercelBlobWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
2
-
3
- //#region src/providers/vercel/blob-store.d.ts
4
- declare function createVercelBlobWorkspaceStore(options: VercelBlobWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
5
- //#endregion
6
- export { createVercelBlobWorkspaceStore };
@@ -1,55 +0,0 @@
1
- import { d as sha256 } from "./path-CNI6wKIU.js";
2
- //#region src/storage/utils.ts
3
- async function createCurrentSnapshotFromStore(store, name) {
4
- return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
5
- }
6
- async function createSnapshotFromEntries(entries, name) {
7
- const snapshotEntries = {};
8
- for (const entry of entries) snapshotEntries[entry.path] = {
9
- digest: entry.digest,
10
- metadata: entry.metadata,
11
- size: entry.size,
12
- type: entry.type
13
- };
14
- return {
15
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
16
- entries: snapshotEntries,
17
- id: await sha256({
18
- entries: snapshotEntries,
19
- name,
20
- createdAt: Date.now()
21
- }),
22
- name
23
- };
24
- }
25
- function diffSnapshots(from, to) {
26
- const entries = [];
27
- const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
28
- for (const path of [...keys].sort()) {
29
- const before = from?.entries[path];
30
- const after = to.entries[path];
31
- if (!before && after) entries.push({
32
- path,
33
- type: "added",
34
- after
35
- });
36
- else if (before && !after) entries.push({
37
- path,
38
- type: "removed",
39
- before
40
- });
41
- else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
42
- path,
43
- type: "modified",
44
- before,
45
- after
46
- });
47
- }
48
- return {
49
- from: from?.id,
50
- to: to.id,
51
- entries
52
- };
53
- }
54
- //#endregion
55
- export { createSnapshotFromEntries as n, diffSnapshots as r, createCurrentSnapshotFromStore as t };