@vite-hub/workspace 0.0.1 → 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 (95) hide show
  1. package/README.md +225 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
  3. package/dist/ai-nmHdzjCM.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/asset-registry-CaG9b7tf.js +19 -0
  7. package/dist/cloudflare.d.ts +18 -0
  8. package/dist/cloudflare.js +2 -0
  9. package/dist/collections/client.d.ts +39 -0
  10. package/dist/collections/client.js +137 -0
  11. package/dist/collections.d.ts +59 -0
  12. package/dist/collections.js +159 -0
  13. package/dist/config-3I1BnsdO.d.ts +28 -0
  14. package/dist/config-CDoyls2X.js +30 -0
  15. package/dist/config-CZLO0m9h.js +7811 -0
  16. package/dist/file-CHfsZpso.js +23 -0
  17. package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
  18. package/dist/github-CfA5vpJ5.js +189 -0
  19. package/dist/glob-D0vD_wRY.js +17 -0
  20. package/dist/host-CAnbugpI.js +370 -0
  21. package/dist/hosted-C1-tTTTf.js +581 -0
  22. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
  23. package/dist/hosted-vercel-blob.d.ts +15 -0
  24. package/dist/hosted-vercel-blob.js +2 -0
  25. package/dist/hosted.d.ts +18 -0
  26. package/dist/hosted.js +2 -0
  27. package/dist/index.d.ts +129 -102
  28. package/dist/index.js +477 -599
  29. package/dist/lifecycle-BYoa9hVb.js +176 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/mountx.d.ts +10 -0
  33. package/dist/mountx.js +143 -0
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-C3_elpEh.js} +142 -37
  40. package/dist/providers/github/store.d.ts +6 -0
  41. package/dist/providers/github/store.js +2 -0
  42. package/dist/publish.d.ts +3 -2
  43. package/dist/publish.js +48 -142
  44. package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
  45. package/dist/registry-CqyDTW9Y.js +74 -0
  46. package/dist/request-execution-u9mgUXKX.js +80 -0
  47. package/dist/runtime/assets.d.ts +2 -1
  48. package/dist/runtime/assets.js +5 -5
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -21
  52. package/dist/runtime/state.js +7 -4
  53. package/dist/runtime/workspace.d.ts +2 -0
  54. package/dist/runtime/workspace.js +2 -0
  55. package/dist/runtime-options-BsPSv5O7.js +13 -0
  56. package/dist/runtime.d.ts +38 -0
  57. package/dist/runtime.js +626 -0
  58. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  59. package/dist/server.d.ts +65 -0
  60. package/dist/server.js +355 -0
  61. package/dist/shared-jfogBrd5.js +273 -0
  62. package/dist/source-metadata.d.ts +2 -0
  63. package/dist/source-metadata.js +2 -0
  64. package/dist/state-TTqa3x3Y.d.ts +25 -0
  65. package/dist/store-Bs1SLh55.js +414 -0
  66. package/dist/sync-DiuDmSGk.js +269 -0
  67. package/dist/target-D4Bqb1eH.js +11 -0
  68. package/dist/test.d.ts +1 -1
  69. package/dist/test.js +1 -1
  70. package/dist/types-60Yn149G.d.ts +612 -0
  71. package/dist/use-CUFSnFCS.d.ts +86 -0
  72. package/dist/use-CsV3oIxH.js +336 -0
  73. package/dist/vite-tbfDxtlu.js +2191 -0
  74. package/dist/vite.d.ts +33 -5
  75. package/dist/vite.js +2 -131
  76. package/dist/workspace-66SKyiec.d.ts +6 -0
  77. package/dist/workspace-C4k92Ow8.js +1460 -0
  78. package/package.json +143 -62
  79. package/dist/asset-registry-CMuQbyvl.js +0 -14
  80. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  81. package/dist/config-CvS-7sre.js +0 -49
  82. package/dist/errors-BUL8SoFS.js +0 -21
  83. package/dist/lifecycle-uD82JeGh.js +0 -92
  84. package/dist/module-8LZUMEXC.js +0 -922
  85. package/dist/path-BVv9OXhg.js +0 -63
  86. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  87. package/dist/providers/cloudflare/artifacts-store.js +0 -384
  88. package/dist/providers/vercel/blob-store.d.ts +0 -6
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. package/dist/utils-BtAm_K5P.js +0 -51
  95. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -0,0 +1,273 @@
1
+ import { c as normalizeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ //#region ../internal/src/runtime/cloudflare-env.ts
4
+ let activeEnv;
5
+ const activeEnvStorage = new AsyncLocalStorage();
6
+ function setActiveCloudflareEnv(env) {
7
+ activeEnv = env;
8
+ globalThis.__env__ = env;
9
+ try {
10
+ activeEnvStorage.enterWith({ env });
11
+ } catch {}
12
+ }
13
+ function getActiveCloudflareEnv() {
14
+ const scoped = activeEnvStorage.getStore();
15
+ return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
16
+ }
17
+ function getActiveCloudflareBinding(name) {
18
+ return getActiveCloudflareEnv()?.[name];
19
+ }
20
+ //#endregion
21
+ //#region src/providers/github/shared.ts
22
+ var GitHubRequestError = class extends Error {
23
+ status;
24
+ constructor(message, status) {
25
+ super(message);
26
+ this.status = status;
27
+ this.name = "GitHubRequestError";
28
+ }
29
+ };
30
+ function githubRequestStatus(error) {
31
+ return (error instanceof GitHubRequestError ? error : error instanceof Error && error.cause instanceof GitHubRequestError ? error.cause : void 0)?.status;
32
+ }
33
+ function processEnv(env, ...keys) {
34
+ return keys.map((key) => env[key]).find((value) => typeof value === "string" && value.length > 0);
35
+ }
36
+ function resolveGitHubOption(value) {
37
+ return typeof value === "function" ? value() : value;
38
+ }
39
+ function isMaskedGitHubTokenOption(value) {
40
+ return value === "********" || value === "<redacted>" || value === "[redacted]";
41
+ }
42
+ function requireGitHubOption(kind, label, value) {
43
+ if (!value) throw workspaceError(`[vitehub] GitHub workspace ${kind} requires ${label}.`);
44
+ return value;
45
+ }
46
+ function splitGitHubRepository(repository, kind) {
47
+ const [owner, repo] = repository.split("/");
48
+ if (!owner || !repo) throw workspaceError(`[vitehub] GitHub workspace ${kind} requires a repository in owner/repo format.`);
49
+ return {
50
+ owner,
51
+ repo
52
+ };
53
+ }
54
+ function joinGitPath(...parts) {
55
+ return parts.join("/").replaceAll("\\", "/").split("/").filter(Boolean).join("/");
56
+ }
57
+ function resolveGitHubWorkspaceRoot(root, workspaceName) {
58
+ return joinGitPath(root.replaceAll("<workspace>", workspaceName));
59
+ }
60
+ function workspacePathFromGitPath(path, root) {
61
+ const normalized = joinGitPath(path);
62
+ const normalizedRoot = joinGitPath(root);
63
+ if (!normalizedRoot) return normalizeWorkspacePath(normalized);
64
+ if (!normalized.startsWith(`${normalizedRoot}/`)) return void 0;
65
+ return normalizeWorkspacePath(normalized.slice(normalizedRoot.length + 1));
66
+ }
67
+ function isWorkspaceFileEntry(entry) {
68
+ return entry.type === "file";
69
+ }
70
+ function toHex(bytes) {
71
+ return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
72
+ }
73
+ async function gitBlobSha(bytes) {
74
+ const prefix = new TextEncoder().encode(`blob ${bytes.byteLength}\0`);
75
+ const input = new Uint8Array(prefix.byteLength + bytes.byteLength);
76
+ input.set(prefix);
77
+ input.set(bytes, prefix.byteLength);
78
+ return toHex(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-1", input)));
79
+ }
80
+ function toBase64(bytes) {
81
+ let binary = "";
82
+ for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
83
+ const encode = globalThis.btoa;
84
+ return encode ? encode(binary) : Buffer.from(bytes).toString("base64");
85
+ }
86
+ function fromBase64(input) {
87
+ const normalized = input.replace(/\s/g, "");
88
+ const decode = globalThis.atob;
89
+ if (!decode) return new Uint8Array(Buffer.from(normalized, "base64"));
90
+ const binary = decode(normalized);
91
+ const bytes = new Uint8Array(binary.length);
92
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
93
+ return bytes;
94
+ }
95
+ function resolveGitHubRepositoryOption(options, env = typeof process !== "undefined" ? process.env : {}) {
96
+ return resolveGitHubOption(options.repository) || resolveGitHubOption(options.repo) || processEnv(env, "WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY");
97
+ }
98
+ function resolveGitHubBranchOption(options, env = typeof process !== "undefined" ? process.env : {}) {
99
+ return resolveGitHubOption(options.branch) || processEnv(env, "WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH") || "main";
100
+ }
101
+ function resolveGitHubRootOption(options, workspaceName, env = typeof process !== "undefined" ? process.env : {}) {
102
+ return resolveGitHubWorkspaceRoot(resolveGitHubOption(options.root) || processEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") || ".vitehub/workspaces/<workspace>", workspaceName);
103
+ }
104
+ function resolveGitHubTokenOption(options, env = typeof process !== "undefined" ? process.env : {}) {
105
+ const token = resolveGitHubOption(options.token);
106
+ if (token && !isMaskedGitHubTokenOption(token)) return token;
107
+ const bindingToken = getActiveCloudflareBinding("GITHUB_TOKEN");
108
+ if (bindingToken && !isMaskedGitHubTokenOption(bindingToken)) return bindingToken;
109
+ return processEnv(env, "WORKSPACE_GITHUB_TOKEN", "VITEHUB_WORKSPACE_GITHUB_TOKEN", "GITHUB_TOKEN", "GH_TOKEN");
110
+ }
111
+ async function requestGitHubJson(repository, token, path, init) {
112
+ const response = await fetch(`https://api.github.com${path}`, {
113
+ ...init,
114
+ headers: {
115
+ accept: "application/vnd.github+json",
116
+ authorization: `Bearer ${token}`,
117
+ "content-type": "application/json",
118
+ "user-agent": "vitehub-workspace",
119
+ "x-github-api-version": "2022-11-28",
120
+ ...init?.headers
121
+ }
122
+ });
123
+ if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace request failed for ${repository}: ${response.status} ${response.statusText} ${await response.text().catch(() => "")}`, response.status) });
124
+ return await response.json();
125
+ }
126
+ async function requestGitHubBytes(repository, token, path, init) {
127
+ const response = await fetch(`https://api.github.com${path}`, {
128
+ ...init,
129
+ headers: {
130
+ accept: "application/vnd.github.raw+json",
131
+ authorization: `Bearer ${token}`,
132
+ "user-agent": "vitehub-workspace",
133
+ "x-github-api-version": "2022-11-28",
134
+ ...init?.headers
135
+ }
136
+ });
137
+ if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace request failed for ${repository}: ${response.status} ${response.statusText} ${await response.text().catch(() => "")}`, response.status) });
138
+ if (response.headers.get("content-type")?.includes("application/json")) {
139
+ const blob = await response.json();
140
+ if (blob.encoding === "base64" && typeof blob.content === "string") return fromBase64(blob.content);
141
+ throw workspaceError(`[vitehub] GitHub workspace request for ${repository} returned unsupported byte response.`);
142
+ }
143
+ return new Uint8Array(await response.arrayBuffer());
144
+ }
145
+ function findGitHubRemoteFiles(tree, root, kind) {
146
+ if (tree.truncated) throw workspaceError(`[vitehub] GitHub workspace ${kind} could not compare the remote tree because GitHub returned a truncated tree.`);
147
+ const files = /* @__PURE__ */ new Map();
148
+ for (const entry of tree.tree) {
149
+ if (entry.type !== "blob" || !entry.sha) continue;
150
+ const path = workspacePathFromGitPath(entry.path, root);
151
+ if (path) files.set(path, entry);
152
+ }
153
+ return files;
154
+ }
155
+ async function readGitHubBranchState(input) {
156
+ const { owner, repo } = splitGitHubRepository(input.repository, input.kind);
157
+ let branchExists = true;
158
+ let ref;
159
+ try {
160
+ ref = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/ref/heads/${input.branch}`);
161
+ } catch (error) {
162
+ if (githubRequestStatus(error) !== 404) throw error;
163
+ const repository = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}`);
164
+ ref = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/ref/heads/${repository.default_branch}`);
165
+ branchExists = false;
166
+ }
167
+ const current = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/commits/${ref.object.sha}`);
168
+ if (input.paths) {
169
+ const entries = await Promise.all(input.paths.map(async (path) => {
170
+ const encodedPath = joinGitPath(input.root, path).split("/").map(encodeURIComponent).join("/");
171
+ try {
172
+ return await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/contents/${encodedPath}?ref=${encodeURIComponent(ref.object.sha)}`, { headers: { accept: "application/vnd.github.object+json" } });
173
+ } catch (error) {
174
+ if (githubRequestStatus(error) === 404) return void 0;
175
+ throw error;
176
+ }
177
+ }));
178
+ return {
179
+ branchExists,
180
+ files: new Map(input.paths.flatMap((path, index) => {
181
+ const entry = entries[index];
182
+ return entry?.type === "file" && entry.sha ? [[path, entry]] : [];
183
+ })),
184
+ refSha: ref.object.sha,
185
+ treeSha: current.tree.sha
186
+ };
187
+ }
188
+ const tree = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/trees/${current.tree.sha}?recursive=1`);
189
+ return {
190
+ branchExists,
191
+ files: findGitHubRemoteFiles(tree, input.root, input.kind),
192
+ refSha: ref.object.sha,
193
+ treeSha: current.tree.sha
194
+ };
195
+ }
196
+ async function readGitHubBlob(input) {
197
+ const { owner, repo } = splitGitHubRepository(input.repository, input.kind);
198
+ return await requestGitHubBytes(input.repository, input.token, `/repos/${owner}/${repo}/git/blobs/${input.sha}`);
199
+ }
200
+ async function commitGitHubChanges(input) {
201
+ const kind = input.kind || "store";
202
+ const { owner, repo } = splitGitHubRepository(input.repository, kind);
203
+ const blobs = await Promise.all(input.files.map((file) => file.bytes ? createGitHubBlob({
204
+ bytes: file.bytes,
205
+ kind,
206
+ repository: input.repository,
207
+ token: input.token
208
+ }) : { sha: file.gitSha }));
209
+ const tree = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/trees`, {
210
+ body: JSON.stringify({
211
+ base_tree: input.baseTreeSha,
212
+ tree: [...input.files.map((file, index) => ({
213
+ mode: file.mode || "100644",
214
+ path: file.fullPath,
215
+ sha: blobs[index].sha,
216
+ type: "blob"
217
+ })), ...input.deletePaths.map((path) => ({
218
+ mode: "100644",
219
+ path,
220
+ sha: null,
221
+ type: "blob"
222
+ }))]
223
+ }),
224
+ method: "POST"
225
+ });
226
+ const commit = await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/commits`, {
227
+ body: JSON.stringify({
228
+ message: input.message,
229
+ parents: [input.parentSha],
230
+ tree: tree.sha
231
+ }),
232
+ method: "POST"
233
+ });
234
+ if (input.branchExists) await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/refs/heads/${input.branch}`, {
235
+ body: JSON.stringify({
236
+ force: false,
237
+ sha: commit.sha
238
+ }),
239
+ method: "PATCH"
240
+ });
241
+ else await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/refs`, {
242
+ body: JSON.stringify({
243
+ ref: `refs/heads/${input.branch}`,
244
+ sha: commit.sha
245
+ }),
246
+ method: "POST"
247
+ });
248
+ return {
249
+ commitSha: commit.sha,
250
+ treeSha: tree.sha
251
+ };
252
+ }
253
+ async function createGitHubBlob(input) {
254
+ const kind = input.kind || "store";
255
+ const { owner, repo } = splitGitHubRepository(input.repository, kind);
256
+ return await requestGitHubJson(input.repository, input.token, `/repos/${owner}/${repo}/git/blobs`, {
257
+ body: JSON.stringify({
258
+ content: toBase64(input.bytes),
259
+ encoding: "base64"
260
+ }),
261
+ method: "POST"
262
+ });
263
+ }
264
+ async function createGitHubFileUpdate(path, root, content) {
265
+ const bytes = contentToBytes(content);
266
+ return {
267
+ bytes,
268
+ fullPath: joinGitPath(root, path),
269
+ gitSha: await gitBlobSha(bytes)
270
+ };
271
+ }
272
+ //#endregion
273
+ export { setActiveCloudflareEnv as _, isWorkspaceFileEntry as a, readGitHubBlob as c, resolveGitHubBranchOption as d, resolveGitHubOption as f, getActiveCloudflareBinding as g, resolveGitHubTokenOption as h, gitBlobSha as i, readGitHubBranchState as l, resolveGitHubRootOption as m, createGitHubBlob as n, joinGitPath as o, resolveGitHubRepositoryOption as p, createGitHubFileUpdate as r, processEnv as s, commitGitHubChanges as t, requireGitHubOption as u };
@@ -0,0 +1,2 @@
1
+ import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-3I1BnsdO.js";
2
+ export { type WorkspaceSourceMetadata, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, workspaceSourceGrantPaths };
@@ -0,0 +1,2 @@
1
+ import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config-CZLO0m9h.js";
2
+ export { normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, workspaceSourceGrantPaths };
@@ -0,0 +1,25 @@
1
+ import { Jt as WorkspaceStore, O as WorkspaceAssetsRegistry, o as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions, w as VercelBlobWorkspaceStoreOptions } from "./types-60Yn149G.js";
2
+ import { t as WorkspaceRegistry } from "./registry-BIQVCBWI.js";
3
+
4
+ //#region src/runtime/config.d.ts
5
+ declare function setWorkspaceRuntimeConfig(config: false | ResolvedWorkspaceModuleOptions): void;
6
+ declare function getWorkspaceRuntimeConfig(): false | ResolvedWorkspaceModuleOptions;
7
+ //#endregion
8
+ //#region src/runtime/hosted-store-loader.d.ts
9
+ type HostedWorkspaceStoreOptions = CloudflareArtifactsWorkspaceStoreOptions | GitHubWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions;
10
+ type WorkspaceHostedStoreLoader = (options: HostedWorkspaceStoreOptions, workspaceName: string) => WorkspaceStore;
11
+ declare function setWorkspaceHostedStoreLoader(loader: WorkspaceHostedStoreLoader | undefined): void;
12
+ declare function getWorkspaceHostedStoreLoader(): WorkspaceHostedStoreLoader | undefined;
13
+ //#endregion
14
+ //#region ../internal/src/runtime/cloudflare-env.d.ts
15
+ type CloudflareWorkerEnv = Record<string, unknown>;
16
+ declare function setActiveCloudflareEnv(env: CloudflareWorkerEnv | undefined): void;
17
+ //#endregion
18
+ //#region src/core/workspace-cache.d.ts
19
+ declare function resetWorkspaceStoreCache(): void;
20
+ //#endregion
21
+ //#region src/runtime/state.d.ts
22
+ declare function setWorkspaceRuntimeRegistry(registry: WorkspaceRegistry): void;
23
+ declare function setWorkspaceRuntimeAssetsRegistry(registry: WorkspaceAssetsRegistry): void;
24
+ //#endregion
25
+ export { HostedWorkspaceStoreOptions as a, setWorkspaceHostedStoreLoader as c, setActiveCloudflareEnv as i, getWorkspaceRuntimeConfig as l, setWorkspaceRuntimeRegistry as n, WorkspaceHostedStoreLoader as o, resetWorkspaceStoreCache as r, getWorkspaceHostedStoreLoader as s, setWorkspaceRuntimeAssetsRegistry as t, setWorkspaceRuntimeConfig as u };