@vite-hub/workspace 0.0.2 → 0.0.4

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/LICENSE +201 -0
  2. package/README.md +48 -2
  3. package/dist/{ai-Cztw4eLk.js → ai-BqCC8BpY.js} +15 -4
  4. package/dist/{ai-hFdsvDHC.d.ts → ai-CjxvGqM0.d.ts} +1 -1
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
  8. package/dist/chunk-2rV9d50f.js +35 -0
  9. package/dist/cloudflare.d.ts +4 -2
  10. package/dist/cloudflare.js +1 -2
  11. package/dist/collections.d.ts +2 -2
  12. package/dist/collections.js +1 -1
  13. package/dist/{config--r5unwPc.js → config-Bc3c4Su1.js} +213 -120
  14. package/dist/{config-DCQ6y30R.js → config-CHLLWklZ.js} +9 -3
  15. package/dist/{config-Ca5DM8fF.d.ts → config-DE9xlaIw.d.ts} +1 -1
  16. package/dist/{file-B2q9NE18.js → file-Bc1X7pco.js} +9 -10
  17. package/dist/{files-xy0le-_U.js → files-Q6xZjDHA.js} +20 -9
  18. package/dist/{github-lIO6-2sH.js → github-DHnjxQIX.js} +27 -23
  19. package/dist/glob-CEZKeZFC.js +18 -0
  20. package/dist/host-DJH8cuoU.js +1030 -0
  21. package/dist/{artifacts-store-BAV9jZpd.js → hosted-RPeJOCFz.js} +146 -30
  22. package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
  23. package/dist/hosted-vercel-blob.d.ts +1 -1
  24. package/dist/hosted-vercel-blob.js +1 -25
  25. package/dist/hosted.d.ts +1 -1
  26. package/dist/hosted.js +1 -29
  27. package/dist/index.d.ts +61 -78
  28. package/dist/index.js +133 -435
  29. package/dist/lifecycle-LrL3sA4n.js +316 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/metadata-target-B0tOmVW7.js +717 -0
  33. package/dist/mountx.d.ts +10 -0
  34. package/dist/mountx.js +143 -0
  35. package/dist/nitro.d.ts +1 -1
  36. package/dist/nitro.js +1 -1
  37. package/dist/nuxt.d.ts +1 -1
  38. package/dist/nuxt.js +8 -2
  39. package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
  40. package/dist/{provider-CeQciesl.js → provider-B1yLjCJJ.js} +194 -47
  41. package/dist/providers/github/store.d.ts +1 -1
  42. package/dist/providers/github/store.js +1 -361
  43. package/dist/publish.d.ts +1 -1
  44. package/dist/publish.js +2 -2
  45. package/dist/registry-D3yzt8HQ.js +127 -0
  46. package/dist/{registry-CoC9JxVt.d.ts → registry-Uj6IVxes.d.ts} +3 -3
  47. package/dist/{request-execution-C8qRcReq.js → request-execution-B-dSFlGB.js} +8 -4
  48. package/dist/runtime/assets.d.ts +1 -1
  49. package/dist/runtime/assets.js +4 -2
  50. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  51. package/dist/runtime/empty-registry.d.ts +1 -1
  52. package/dist/runtime/state.d.ts +4 -4
  53. package/dist/runtime/state.js +10 -7
  54. package/dist/runtime/workspace.d.ts +1 -1
  55. package/dist/runtime/workspace.js +1 -1
  56. package/dist/runtime-options-BsPSv5O7.js +13 -0
  57. package/dist/runtime-type-iEE6BjQJ.js +34 -0
  58. package/dist/runtime.d.ts +42 -7
  59. package/dist/runtime.js +276 -100
  60. package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
  61. package/dist/server.d.ts +2 -2
  62. package/dist/server.js +24 -51
  63. package/dist/{shared-BRycRSbo.js → shared-DTR1Hhma.js} +115 -39
  64. package/dist/source-metadata.d.ts +9 -2
  65. package/dist/source-metadata.js +34 -2
  66. package/dist/{state-DSAHEsq6.d.ts → state-tYcRWEh2.d.ts} +13 -12
  67. package/dist/store-Dt_Jyys3.js +608 -0
  68. package/dist/{sync-DO42ypji.js → sync-DnTQwt8r.js} +6 -5
  69. package/dist/test.d.ts +1 -1
  70. package/dist/test.js +1 -1
  71. package/dist/token-CVzURBxC.js +61 -0
  72. package/dist/{types-DHkae7Cb.d.ts → types-CYuwjJ4V.d.ts} +94 -43
  73. package/dist/{use-d_PlAdOu.js → use-BTNDR5Rd.js} +147 -50
  74. package/dist/{use-D16tf8Ph.d.ts → use-BiHzt0xA.d.ts} +21 -4
  75. package/dist/vite-BptCrpv2.js +4526 -0
  76. package/dist/vite-CtA9guIM.d.ts +66 -0
  77. package/dist/vite.d.ts +2 -50
  78. package/dist/vite.js +2 -2
  79. package/dist/{workspace-n4wBmdaM.js → workspace-Dq08Yn72.js} +224 -545
  80. package/dist/{workspace-f2DBLmPZ.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
  81. package/package.json +20 -38
  82. package/dist/chunk-8H4AJuhK.js +0 -14
  83. package/dist/cli.d.ts +0 -31
  84. package/dist/cli.js +0 -303
  85. package/dist/cloudflare-env-CKxUs2fa.js +0 -20
  86. package/dist/glob-DeH0dzZX.js +0 -23
  87. package/dist/host-I-_vDs05.js +0 -370
  88. package/dist/lifecycle-Lhk3dAMt.js +0 -176
  89. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  90. package/dist/providers/cloudflare/artifacts-store.js +0 -2
  91. package/dist/providers/vercel/blob-store.d.ts +0 -6
  92. package/dist/providers/vercel/blob-store.js +0 -235
  93. package/dist/registry-C7DMdBXN.js +0 -74
  94. package/dist/utils-BPdaCyI6.js +0 -55
  95. package/dist/vite-NWC9mFjI.js +0 -1882
@@ -1,370 +0,0 @@
1
- import { c as normalizeWorkspacePath, d as sha256, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
2
- import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-BPdaCyI6.js";
3
- import { _ as scopedSearchQuery, f as assertDiffInsideSessionPaths, g as isMissingWorkspacePathError, h as filterSessionEntries, m as filterSessionDiff, p as assertPathInSessionScope } from "./workspace-n4wBmdaM.js";
4
- import { posix } from "node:path";
5
- import { normalizeExecutionAuthority } from "@vite-hub/runtime";
6
- //#region src/session/host.ts
7
- function normalizeTarget(target = "/workspace") {
8
- const normalized = posix.resolve("/", target.replace(/\\/g, "/"));
9
- if (normalized === "/") throw workspaceError("[vitehub] Workspace session target cannot be the host root.");
10
- return normalized;
11
- }
12
- function normalizeSearchRoot(path) {
13
- const normalized = posix.normalize(path.replace(/\\/g, "/"));
14
- return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
15
- }
16
- function toHostPath(root, path = "") {
17
- const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
18
- return normalized ? posix.join(root, normalized) : root;
19
- }
20
- function toHostCwd(root, cwd) {
21
- if (cwd === void 0) return root;
22
- if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
23
- const normalized = posix.normalize(cwd);
24
- if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
25
- if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
26
- throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
27
- }
28
- function fromHostPath(root, path) {
29
- const normalizedRoot = root.replace(/\/+$/, "");
30
- const normalizedPath = posix.resolve(root, path).replace(/\/+$/, "");
31
- if (normalizedPath === normalizedRoot) return "";
32
- if (!normalizedPath.startsWith(`${normalizedRoot}/`)) throw workspaceError(`[vitehub] Workspace host returned a path outside ${root}: ${path}.`);
33
- return normalizeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1));
34
- }
35
- function isGitSymlinkEntry(entry) {
36
- return entry.metadata?.gitMode === "120000";
37
- }
38
- function hasSymlinkParent(path, symlinks) {
39
- let parent = posix.dirname(path);
40
- while (parent && parent !== "." && parent !== "/") {
41
- if (symlinks.has(parent)) return true;
42
- parent = posix.dirname(parent);
43
- }
44
- return false;
45
- }
46
- function isSafeHostSymlink(root, path, target) {
47
- if (posix.isAbsolute(target)) return false;
48
- const resolved = posix.resolve(posix.dirname(toHostPath(root, path)), target);
49
- return resolved === root || resolved.startsWith(`${root}/`);
50
- }
51
- async function assertNoHostSymlinkParent(host, root, target) {
52
- const path = fromHostPath(root, target);
53
- if (hasSymlinkParent(path, new Set((await listHostEntries(host, root, "", true)).filter(isGitSymlinkEntry).map((entry) => entry.path)))) throw workspaceError(`[vitehub] Workspace host path crosses a symlink parent: ${path}.`);
54
- }
55
- function toWorkspaceEntry(root, entry) {
56
- return {
57
- metadata: entry.type === "symlink" ? { gitMode: "120000" } : void 0,
58
- path: fromHostPath(root, entry.path),
59
- size: entry.size,
60
- type: entry.type === "directory" ? "directory" : "file"
61
- };
62
- }
63
- async function ensureHostParent(host, path) {
64
- const parent = posix.dirname(path);
65
- if (parent && parent !== "." && parent !== "/") await host.files.mkdir(parent, { recursive: true });
66
- }
67
- async function readHostSymlinkTarget(host, root, path) {
68
- const result = await host.exec("readlink", [fromHostPath(root, path)], { cwd: root });
69
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
70
- return result.stdout.replace(/\n$/, "");
71
- }
72
- async function writeHostSymlink(host, root, path, target) {
73
- await host.files.remove(path).catch(() => void 0);
74
- const result = await host.exec("ln", [
75
- "-s",
76
- target,
77
- fromHostPath(root, path)
78
- ], { cwd: root });
79
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to create workspace symlink: ${path}. ${result.stderr || "ln failed"}`);
80
- }
81
- async function readHostFile(host, root, path) {
82
- if (!await host.files.exists(path)) return void 0;
83
- const content = await host.files.read(path);
84
- return content ? {
85
- content,
86
- path: fromHostPath(root, path)
87
- } : void 0;
88
- }
89
- async function listHostEntries(host, root, path = "", recursive = false) {
90
- const entries = await host.files.list(toHostPath(root, path), { recursive });
91
- return (await Promise.all(entries.map(async (entry) => {
92
- const workspaceEntry = toWorkspaceEntry(root, entry);
93
- if (workspaceEntry.type !== "file" || isGitSymlinkEntry(workspaceEntry)) return workspaceEntry;
94
- return (await host.exec("test", ["-x", fromHostPath(root, entry.path)], { cwd: root })).code === 0 ? {
95
- ...workspaceEntry,
96
- metadata: {
97
- ...workspaceEntry.metadata,
98
- gitMode: "100755"
99
- }
100
- } : workspaceEntry;
101
- }))).filter((entry) => entry.path && entry.path !== ".git" && !entry.path.startsWith(".git/")).sort((left, right) => left.path.localeCompare(right.path));
102
- }
103
- async function makeHostFileExecutable(host, root, path) {
104
- const result = await host.exec("chmod", ["+x", fromHostPath(root, path)], { cwd: root });
105
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to preserve executable Workspace file: ${path}. ${result.stderr || "chmod failed"}`);
106
- }
107
- async function snapshotHost(host, root, name) {
108
- return (await captureHostState(host, root, name)).snapshot;
109
- }
110
- async function captureHostState(host, root, name) {
111
- const entries = await listHostEntries(host, root, "", true);
112
- const contents = /* @__PURE__ */ new Map();
113
- return {
114
- contents,
115
- snapshot: await createSnapshotFromEntries(await Promise.all(entries.map(async (entry) => {
116
- if (entry.type !== "file") return entry;
117
- const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path)) : await host.files.read(toHostPath(root, entry.path));
118
- if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
119
- contents.set(entry.path, content);
120
- return {
121
- ...entry,
122
- digest: await sha256(content),
123
- size: contentToBytes(content).byteLength
124
- };
125
- })), name)
126
- };
127
- }
128
- async function restoreAttachedHost(host, root, diff, state) {
129
- const changed = [...new Set(diff.entries.map((entry) => entry.path))];
130
- for (const path of changed.sort((left, right) => right.length - left.length)) await host.files.remove(toHostPath(root, path), { recursive: true }).catch(() => void 0);
131
- const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
132
- for (const [path, entry] of baselineEntries) {
133
- const target = toHostPath(root, path);
134
- if (entry.type === "directory") {
135
- await host.files.mkdir(target, { recursive: true });
136
- continue;
137
- }
138
- const content = state.contents.get(path);
139
- if (content === void 0) continue;
140
- await ensureHostParent(host, target);
141
- if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content));
142
- else {
143
- await host.files.write(target, contentToBytes(content));
144
- if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
145
- }
146
- }
147
- }
148
- async function resetHostWorkspaceRoot(host, root) {
149
- await host.files.remove(root, { recursive: true }).catch(() => void 0);
150
- await host.files.mkdir(root, { recursive: true });
151
- }
152
- function normalizeSessionPaths(options) {
153
- const paths = [...new Set((options?.paths || []).map((path) => normalizeSafeWorkspacePath(path, {
154
- allowEmpty: true,
155
- allowReserved: true
156
- })))];
157
- if (!paths.length || paths.includes("")) return void 0;
158
- return paths.sort((left, right) => left.length - right.length || left.localeCompare(right));
159
- }
160
- async function sessionEntries(workspace, options) {
161
- const paths = normalizeSessionPaths(options);
162
- if (!paths) return await workspace.list("", { recursive: true });
163
- const entries = /* @__PURE__ */ new Map();
164
- for (const path of paths) {
165
- const stat = await workspace.stat(path).catch((error) => {
166
- if (isMissingWorkspacePathError(error)) return void 0;
167
- throw error;
168
- });
169
- if (!stat) continue;
170
- entries.set(stat.path, stat);
171
- if (stat.type === "directory") for (const entry of await workspace.list(path, { recursive: true })) entries.set(entry.path, entry);
172
- }
173
- return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
174
- }
175
- async function materializeWorkspace(workspace, host, root, options) {
176
- await resetHostWorkspaceRoot(host, root);
177
- const entries = await sessionEntries(workspace, options);
178
- const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
179
- const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
180
- if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
181
- for (const entry of entries.filter((entry) => entry.type === "directory")) await host.files.mkdir(toHostPath(root, entry.path), { recursive: true });
182
- for (const entry of entries) {
183
- if (entry.type !== "file") continue;
184
- const target = toHostPath(root, entry.path);
185
- await ensureHostParent(host, target);
186
- if (isGitSymlinkEntry(entry)) {
187
- const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
188
- if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
189
- else await host.files.write(target, contentToBytes(symlinkTarget));
190
- } else {
191
- await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
192
- if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
193
- }
194
- }
195
- return await snapshotHost(host, root, "host-open");
196
- }
197
- async function commitHostChanges(host, root, workspace, diff, mediaTypes, message) {
198
- for (const entry of diff.entries) {
199
- if (entry.after?.type === "directory") {
200
- if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
201
- await workspace.mkdir(entry.path, { recursive: true });
202
- continue;
203
- }
204
- if (entry.type === "removed") {
205
- await workspace.rm(entry.path, {
206
- force: true,
207
- recursive: true
208
- });
209
- continue;
210
- }
211
- if (entry.after?.type !== "file") continue;
212
- if (entry.before?.type === "directory") await workspace.rm(entry.path, {
213
- force: true,
214
- recursive: true
215
- });
216
- const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
217
- const target = toHostPath(root, entry.path);
218
- const symlinkTarget = entry.after.metadata?.gitMode === "120000" ? await readHostSymlinkTarget(host, root, target) : void 0;
219
- const file = symlinkTarget === void 0 ? await readHostFile(host, root, target) : isSafeHostSymlink(root, entry.path, symlinkTarget) ? {
220
- content: symlinkTarget,
221
- metadata: entry.after.metadata,
222
- path: entry.path
223
- } : {
224
- content: symlinkTarget,
225
- path: entry.path
226
- };
227
- if (file) await workspace.writeFile(entry.path, file.content, {
228
- mediaType: file.mediaType || mediaTypes.get(entry.path) || before?.mediaType,
229
- metadata: symlinkTarget === void 0 ? entry.after.metadata : file.metadata
230
- });
231
- }
232
- await workspace.snapshot({ name: message || "host-commit" });
233
- }
234
- async function createHostedWorkspaceSession(workspace, options) {
235
- const host = options.host;
236
- let executionAuthority;
237
- try {
238
- executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
239
- } catch {
240
- throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
241
- }
242
- const root = normalizeTarget(options.target);
243
- const sessionPaths = normalizeSessionPaths(options);
244
- let closed = false;
245
- let attachedState = options.attach ? await captureHostState(host, root, "host-attach") : void 0;
246
- let baseline = attachedState?.snapshot || await materializeWorkspace(workspace, host, root, options);
247
- const mediaTypes = /* @__PURE__ */ new Map();
248
- function assertOpen() {
249
- if (closed) throw workspaceError("[vitehub] Workspace host session is already closed.");
250
- }
251
- async function currentDiff() {
252
- assertOpen();
253
- return diffSnapshots(baseline, await snapshotHost(host, root));
254
- }
255
- return {
256
- executionAuthority,
257
- async readFile(path, readOptions) {
258
- assertOpen();
259
- const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths, { masked: true })));
260
- if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
261
- return decodeFile(file.content, readOptions);
262
- },
263
- async writeFile(path, content, writeOptions) {
264
- assertOpen();
265
- const target = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths));
266
- await assertNoHostSymlinkParent(host, root, target);
267
- await ensureHostParent(host, target);
268
- await host.files.remove(target, { recursive: true }).catch(() => void 0);
269
- const symlinkTarget = writeOptions?.metadata?.gitMode === "120000" ? new TextDecoder().decode(contentToBytes(content)) : void 0;
270
- if (symlinkTarget !== void 0 && isSafeHostSymlink(root, fromHostPath(root, target), symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
271
- else {
272
- await host.files.write(target, contentToBytes(content));
273
- const workspacePath = fromHostPath(root, target);
274
- if (writeOptions?.metadata?.gitMode === "100755" || baseline.entries[workspacePath]?.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
275
- }
276
- const workspacePath = fromHostPath(root, target);
277
- if (writeOptions?.mediaType) mediaTypes.set(workspacePath, writeOptions.mediaType);
278
- else mediaTypes.delete(workspacePath);
279
- },
280
- async mkdir(path, mkdirOptions = {}) {
281
- assertOpen();
282
- const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
283
- await assertNoHostSymlinkParent(host, root, hostTarget);
284
- await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
285
- },
286
- async rm(path, rmOptions) {
287
- assertOpen();
288
- const workspacePath = assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths);
289
- const target = toHostPath(root, workspacePath);
290
- await assertNoHostSymlinkParent(host, root, target);
291
- await host.files.remove(target, { recursive: rmOptions?.recursive });
292
- mediaTypes.delete(normalizeWorkspacePath(workspacePath));
293
- },
294
- async list(path = "", listOptions = {}) {
295
- assertOpen();
296
- return filterSessionEntries(await listHostEntries(host, root, path, listOptions.recursive), sessionPaths);
297
- },
298
- async glob(pattern, globOptions) {
299
- assertOpen();
300
- const patterns = Array.isArray(pattern) ? pattern : [pattern];
301
- const cwd = normalizeSearchRoot(globOptions?.cwd || "");
302
- const { matchesAny } = await import("./path-CNI6wKIU.js").then((n) => n.l);
303
- return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
304
- if (entry.type !== "file") return false;
305
- if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
306
- if (!entry.path.startsWith(`${cwd}/`)) return false;
307
- const relative = entry.path.slice(cwd.length + 1);
308
- return patterns.some((item) => matchesAny(relative, item));
309
- });
310
- },
311
- async search(query) {
312
- assertOpen();
313
- const { searchText } = await import("./search-C4REyHj9.js").then((n) => n.n);
314
- const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
315
- if (!scoped) return [];
316
- const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
317
- const limit = scoped.limit ?? 100;
318
- const hits = [];
319
- for (const entry of filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((item) => item.type === "file")) {
320
- if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
321
- const content = await host.files.read(toHostPath(root, entry.path));
322
- if (content === null) continue;
323
- const text = new TextDecoder().decode(content);
324
- hits.push(...searchText(entry.path, text, {
325
- ...scoped,
326
- limit: limit - hits.length
327
- }));
328
- if (hits.length >= limit) break;
329
- }
330
- return hits;
331
- },
332
- async diff() {
333
- return filterSessionDiff(await currentDiff(), sessionPaths);
334
- },
335
- async commit(commitOptions) {
336
- const diff = await currentDiff();
337
- if (!diff.entries.length) return;
338
- assertDiffInsideSessionPaths(diff, sessionPaths);
339
- await commitHostChanges(host, root, workspace, diff, mediaTypes, commitOptions?.message);
340
- if (options.attach) {
341
- attachedState = await captureHostState(host, root, commitOptions?.message || "host-commit");
342
- baseline = attachedState.snapshot;
343
- } else baseline = await snapshotHost(host, root, commitOptions?.message || "host-commit");
344
- },
345
- async exec(command, args = [], execOptions = {}) {
346
- assertOpen();
347
- const result = await host.exec(command, args, {
348
- cwd: toHostCwd(root, execOptions.cwd),
349
- env: execOptions.env,
350
- signal: execOptions.abortSignal,
351
- timeout: execOptions.timeout
352
- });
353
- return {
354
- args,
355
- command,
356
- exitCode: result.code,
357
- stderr: result.stderr,
358
- stdout: result.stdout
359
- };
360
- },
361
- async close() {
362
- if (closed) return;
363
- if (options.attach && attachedState) await restoreAttachedHost(host, root, filterSessionDiff(diffSnapshots(baseline, await snapshotHost(host, root)), sessionPaths), attachedState);
364
- closed = true;
365
- if (!options.attach) await materializeWorkspace(workspace, host, root, options);
366
- }
367
- };
368
- }
369
- //#endregion
370
- export { createHostedWorkspaceSession };
@@ -1,176 +0,0 @@
1
- import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
- import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
3
- import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config--r5unwPc.js";
4
- import { t as createCurrentSnapshotFromStore } from "./utils-BPdaCyI6.js";
5
- import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
6
- import { t as files } from "./files-xy0le-_U.js";
7
- import { getViteHubErrorShape } from "@vite-hub/runtime";
8
- //#region src/lifecycle.ts
9
- var lifecycle_exports = /* @__PURE__ */ __exportAll({
10
- publishWorkspace: () => publishWorkspace,
11
- publishWorkspaceSnapshot: () => publishWorkspaceSnapshot,
12
- syncWorkspaceDefinition: () => syncWorkspaceDefinition
13
- });
14
- const buildSourcesMetaKey = "workspace:build-sources";
15
- async function publishWorkspace(definition, store, options = {}) {
16
- if (!definition.publish?.length) return;
17
- await publishWorkspaceSnapshot(definition, store, await createCurrentSnapshotFromStore(store, options.name), false);
18
- }
19
- async function publishWorkspaceSnapshot(definition, store, snapshot, durable = true) {
20
- for (const publisher of definition.publish || []) await publisher.publish({
21
- durable,
22
- workspace: definition,
23
- store,
24
- rootDir: definition.rootDir || process.cwd(),
25
- snapshot
26
- });
27
- }
28
- async function syncWorkspaceDefinition(definition, store) {
29
- const loaders = definition.loaders?.length ? definition.loaders : [files()];
30
- const hasExplicitLoaders = !!definition.loaders?.length;
31
- const ctxSource = createSourceContext(definition, void 0, store);
32
- const buildSources = normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "build");
33
- const hasBuildSourceState = await reconcileBuildSourceMounts(store, buildSources);
34
- const bundledBuildSources = !hasExplicitLoaders ? await syncRuntimeBuildAssets(definition, store, buildSources) : void 0;
35
- if (bundledBuildSources && buildSources.every((source) => bundledBuildSources.has(source.key))) {
36
- await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
37
- return;
38
- }
39
- if (!hasBuildSourceState && !hasExplicitLoaders) return;
40
- const normalizedSources = buildSources.filter((source) => !bundledBuildSources?.has(source.key)).map((source) => createMountedBuildSource(source));
41
- const ctx = {
42
- workspace: definition.name,
43
- rootDir: ctxSource.rootDir,
44
- sourceRootDir: ctxSource.sourceRootDir,
45
- sources: normalizedSources,
46
- store,
47
- parseData: async (input) => input.data,
48
- generateDigest: (input) => JSON.stringify(input),
49
- logger: console
50
- };
51
- for (const loader of loaders) await loader.load(ctx);
52
- await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
53
- }
54
- async function reconcileBuildSourceMounts(store, currentSources) {
55
- const previousSources = await readSyncedBuildSources(store);
56
- const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
57
- const resetPaths = [...new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
58
- for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) await store.rm(mountPath, {
59
- recursive: true,
60
- force: true
61
- });
62
- for (const source of [...previousSources, ...currentSources].filter((source) => !source.mountPath)) await removeRootBuildSourceFiles(store, source);
63
- for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) await store.mkdir(mountPath, { recursive: true });
64
- await store.setMeta?.(buildSourcesMetaKey, currentSources.map(({ key, mountPath }) => ({
65
- key,
66
- mountPath
67
- })));
68
- return hasBuildSourceState;
69
- }
70
- async function syncRuntimeBuildAssets(definition, store, currentSources) {
71
- if (!currentSources.length) return void 0;
72
- let assets;
73
- try {
74
- assets = useWorkspaceAssets(definition.name);
75
- } catch (error) {
76
- if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
77
- throw error;
78
- }
79
- const files = (await assets.list("", { recursive: true })).filter((entry) => entry.type === "file");
80
- const bundledPaths = new Set(files.map((entry) => entry.path));
81
- const bundledSourceByPath = /* @__PURE__ */ new Map();
82
- const bundledBuildSources = /* @__PURE__ */ new Set();
83
- for (const source of currentSources) if (await hasCompleteBundledBuildSource(definition, store, source, bundledPaths, files, bundledSourceByPath)) bundledBuildSources.add(source.key);
84
- for (const entry of files) {
85
- const sourceKey = typeof entry.metadata?.source === "string" ? entry.metadata.source : bundledSourceByPath.get(entry.path) || findBuildSourceForPath(entry.path, currentSources)?.key;
86
- await store.writeFile(entry.path, {
87
- path: entry.path,
88
- content: await assets.readFile(entry.path, { encoding: "binary" }),
89
- mediaType: entry.mediaType,
90
- metadata: sourceKey ? {
91
- ...entry.metadata,
92
- source: sourceKey
93
- } : entry.metadata
94
- });
95
- }
96
- return bundledBuildSources;
97
- }
98
- async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath) {
99
- const probeKeys = source.source.probeKeys;
100
- if (!probeKeys?.length) {
101
- const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
102
- const sourcePaths = await tryListBuildSourcePaths(definition, store, source);
103
- if (sourcePaths && !sourcePaths.every((path) => paths.includes(path))) return false;
104
- for (const path of paths) bundledSourceByPath?.set(path, source.key);
105
- return paths.length > 0;
106
- }
107
- const paths = probeKeys.map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
108
- if (!paths.every((path) => bundledPaths.has(path))) return false;
109
- for (const path of paths) bundledSourceByPath?.set(path, source.key);
110
- return true;
111
- }
112
- async function tryListBuildSourcePaths(definition, store, source) {
113
- const ctx = createSourceContext(definition, {
114
- key: source.key,
115
- mountPath: source.mountPath
116
- }, store);
117
- try {
118
- await source.source.prepare?.(ctx);
119
- return (await source.source.getKeys(ctx)).map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
120
- } catch {
121
- return;
122
- }
123
- }
124
- function findBuildSourceForPath(path, sources) {
125
- const matches = sources.filter((source) => !source.mountPath || path === source.mountPath || path.startsWith(`${source.mountPath}/`)).sort((left, right) => right.mountPath.length - left.mountPath.length)[0];
126
- if (!matches?.mountPath && sources.filter((source) => !source.mountPath).length > 1) return void 0;
127
- return matches;
128
- }
129
- async function readSyncedBuildSources(store) {
130
- const value = await store.getMeta?.(buildSourcesMetaKey);
131
- if (!Array.isArray(value)) return [];
132
- return value.filter(isSyncedBuildSource);
133
- }
134
- async function removeRootBuildSourceFiles(store, source) {
135
- const entries = await store.list("", { recursive: true });
136
- await Promise.all(entries.map(async (entry) => {
137
- if (entry.type !== "file") return;
138
- if ((await store.readFile(entry.path))?.metadata?.source === source.key) await store.rm(entry.path, { force: true });
139
- }));
140
- }
141
- function isSyncedBuildSource(value) {
142
- return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
143
- }
144
- function createMountedBuildSource(source) {
145
- function getSourceContext(ctx) {
146
- return {
147
- ...ctx,
148
- mountPath: source.mountPath,
149
- source: source.key
150
- };
151
- }
152
- return {
153
- ...source.source,
154
- key: source.key,
155
- async prepare(ctx) {
156
- await source.source.prepare?.(getSourceContext(ctx));
157
- },
158
- async getKeys(ctx) {
159
- return await source.source.getKeys(getSourceContext(ctx));
160
- },
161
- async getItem(key, ctx) {
162
- const item = await source.source.getItem(key, getSourceContext(ctx));
163
- const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
164
- return {
165
- ...item,
166
- path,
167
- metadata: {
168
- ...item.metadata,
169
- source: source.key
170
- }
171
- };
172
- }
173
- };
174
- }
175
- //#endregion
176
- export { syncWorkspaceDefinition as n, lifecycle_exports 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 };