@vite-hub/workspace 0.0.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -1,316 +0,0 @@
1
- import { n as __exportAll } from "./chunk-2rV9d50f.js";
2
- import { l as normalizeWorkspacePath } from "./path-Cp59koVz.js";
3
- import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, n as createSourceContext, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
4
- import { i as createCurrentSnapshotFromStore } from "./store-Dt_Jyys3.js";
5
- import { n as useWorkspaceAssets } from "./asset-registry-8QI3ML3K.js";
6
- import { a as invalidateWorkspaceSourceMaterialization } from "./workspace-Dq08Yn72.js";
7
- import { d as sourceSnapshotMetaKey, f as sourceSnapshotOwnsAnyPath } from "./metadata-target-B0tOmVW7.js";
8
- import { t as files } from "./files-Q6xZjDHA.js";
9
- import { getViteHubErrorShape } from "@vite-hub/runtime";
10
- //#region src/lifecycle.ts
11
- var lifecycle_exports = /* @__PURE__ */ __exportAll({
12
- publishWorkspace: () => publishWorkspace,
13
- publishWorkspaceSnapshot: () => publishWorkspaceSnapshot,
14
- syncWorkspaceDefinition: () => syncWorkspaceDefinition
15
- });
16
- const buildSourcesMetaKey = "workspace:build-sources";
17
- async function publishWorkspace(definition, store, options = {}) {
18
- if (!definition.publish?.length) return;
19
- await publishWorkspaceSnapshot(definition, store, await createCurrentSnapshotFromStore(store, options.name), false);
20
- }
21
- async function publishWorkspaceSnapshot(definition, store, snapshot, durable = true, abortSignal, trackOperation) {
22
- for (const publisher of definition.publish || []) {
23
- abortSignal?.throwIfAborted();
24
- const operation = publisher.publish({
25
- abortSignal,
26
- durable,
27
- workspace: definition,
28
- store,
29
- rootDir: definition.rootDir || process.cwd(),
30
- snapshot
31
- });
32
- await (trackOperation ? trackOperation(operation) : operation);
33
- }
34
- }
35
- const STORE_MUTATIONS = new Set([
36
- "mkdir",
37
- "rebase",
38
- "rm",
39
- "setMeta",
40
- "snapshot",
41
- "writeFile",
42
- "writeFileConditional",
43
- "writeFileStream"
44
- ]);
45
- function createAbortFencedStore(store, abortSignal) {
46
- const active = /* @__PURE__ */ new Set();
47
- let settleIdle;
48
- const idle = () => active.size ? new Promise((resolve) => {
49
- settleIdle = resolve;
50
- }) : Promise.resolve();
51
- const track = (operation) => {
52
- active.add(operation);
53
- operation.then(() => {
54
- active.delete(operation);
55
- if (!active.size) {
56
- settleIdle?.();
57
- settleIdle = void 0;
58
- }
59
- }, () => {
60
- active.delete(operation);
61
- if (!active.size) {
62
- settleIdle?.();
63
- settleIdle = void 0;
64
- }
65
- });
66
- return operation;
67
- };
68
- return {
69
- fenced: new Proxy(store, { get(target, property) {
70
- const value = Reflect.get(target, property, target);
71
- if (!STORE_MUTATIONS.has(String(property))) return value?.bind(target);
72
- if (value === void 0) return void 0;
73
- return (...args) => {
74
- abortSignal.throwIfAborted();
75
- return track(Promise.resolve(Reflect.apply(value, target, args)));
76
- };
77
- } }),
78
- idle,
79
- track
80
- };
81
- }
82
- async function waitForFencedSync(operation, signal, idle) {
83
- let removeAbortListener = () => {};
84
- const aborted = new Promise((_resolve, reject) => {
85
- const onAbort = () => {
86
- idle().then(() => reject(signal.reason));
87
- };
88
- signal.addEventListener("abort", onAbort, { once: true });
89
- removeAbortListener = () => signal.removeEventListener("abort", onAbort);
90
- if (signal.aborted) onAbort();
91
- });
92
- try {
93
- await Promise.race([operation, aborted]);
94
- } finally {
95
- removeAbortListener();
96
- }
97
- }
98
- async function syncWorkspaceDefinition(definition, store, abortSignal) {
99
- if (!abortSignal) return await syncWorkspaceDefinitionInternal(definition, store);
100
- const { fenced, idle, track } = createAbortFencedStore(store, abortSignal);
101
- await waitForFencedSync(syncWorkspaceDefinitionInternal(definition, fenced, abortSignal, store, track), abortSignal, idle);
102
- }
103
- async function syncWorkspaceDefinitionInternal(definition, store, abortSignal, materializationStore = store, trackOperation) {
104
- abortSignal?.throwIfAborted();
105
- const loaders = definition.loaders?.length ? definition.loaders : [files()];
106
- const hasExplicitLoaders = !!definition.loaders?.length;
107
- const ctxSource = createSourceContext(definition, void 0, store);
108
- const sources = normalizeWorkspaceSources(definition.sources);
109
- const buildSources = sources.filter((source) => source.materialize === "build");
110
- const hasBuildSourceState = await reconcileBuildSourceMounts(definition, store, materializationStore, buildSources, sources.filter((source) => source.materialize === "startup"), abortSignal);
111
- abortSignal?.throwIfAborted();
112
- const bundledBuildSources = !hasExplicitLoaders ? await syncRuntimeBuildAssets(definition, store, buildSources, abortSignal) : void 0;
113
- abortSignal?.throwIfAborted();
114
- if (bundledBuildSources && buildSources.every((source) => bundledBuildSources.has(source.key))) {
115
- await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }), true, abortSignal, trackOperation);
116
- return;
117
- }
118
- if (!hasBuildSourceState && !hasExplicitLoaders) return;
119
- const normalizedSources = buildSources.filter((source) => !bundledBuildSources?.has(source.key)).map((source) => createMountedBuildSource(source));
120
- const ctx = {
121
- abortSignal,
122
- workspace: definition.name,
123
- rootDir: ctxSource.rootDir,
124
- sourceRootDir: ctxSource.sourceRootDir,
125
- sources: normalizedSources,
126
- store,
127
- parseData: async (input) => input.data,
128
- generateDigest: (input) => JSON.stringify(input),
129
- logger: console
130
- };
131
- for (const loader of loaders) {
132
- abortSignal?.throwIfAborted();
133
- await loader.load(ctx);
134
- }
135
- abortSignal?.throwIfAborted();
136
- await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }), true, abortSignal, trackOperation);
137
- }
138
- async function reconcileBuildSourceMounts(definition, store, materializationStore, currentSources, startupSources, abortSignal) {
139
- abortSignal?.throwIfAborted();
140
- const previousSources = await readSyncedBuildSources(store);
141
- abortSignal?.throwIfAborted();
142
- const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
143
- const resetPaths = [...new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
144
- for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) {
145
- abortSignal?.throwIfAborted();
146
- const removedPaths = (await store.list(mountPath, { recursive: true })).filter((entry) => entry.type === "file").map((entry) => entry.path);
147
- const affected = [];
148
- for (const startup of startupSources.filter((source) => sourceMountIntersectsPath(source, mountPath))) {
149
- if (!(startup.mountPath === mountPath || startup.mountPath.startsWith(`${mountPath}/`)) && await sourceSnapshotOwnsAnyPath(store, startup.key, removedPaths) === false) continue;
150
- affected.push(startup);
151
- }
152
- await invalidateWorkspaceSourceMaterialization(definition, materializationStore, affected.map((source) => source.key));
153
- for (const source of affected) await store.setMeta?.(sourceSnapshotMetaKey(source.key), {});
154
- abortSignal?.throwIfAborted();
155
- await store.rm(mountPath, {
156
- recursive: true,
157
- force: true
158
- });
159
- abortSignal?.throwIfAborted();
160
- }
161
- for (const source of [...previousSources, ...currentSources].filter((source) => !source.mountPath)) {
162
- abortSignal?.throwIfAborted();
163
- const removedPaths = await rootBuildSourceFilePaths(store, source);
164
- const affected = [];
165
- for (const startup of startupSources) {
166
- if (!removedPaths.some((path) => sourceMountIntersectsPath(startup, path))) continue;
167
- if (await sourceSnapshotOwnsAnyPath(store, startup.key, removedPaths) === false) continue;
168
- affected.push(startup);
169
- }
170
- await invalidateWorkspaceSourceMaterialization(definition, materializationStore, affected.map((startup) => startup.key));
171
- for (const startup of affected) await store.setMeta?.(sourceSnapshotMetaKey(startup.key), {});
172
- abortSignal?.throwIfAborted();
173
- await removeRootBuildSourceFiles(store, removedPaths);
174
- abortSignal?.throwIfAborted();
175
- }
176
- for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) {
177
- abortSignal?.throwIfAborted();
178
- await store.mkdir(mountPath, { recursive: true });
179
- abortSignal?.throwIfAborted();
180
- }
181
- abortSignal?.throwIfAborted();
182
- await store.setMeta?.(buildSourcesMetaKey, currentSources.map(({ key, mountPath }) => ({
183
- key,
184
- mountPath
185
- })));
186
- return hasBuildSourceState;
187
- }
188
- async function syncRuntimeBuildAssets(definition, store, currentSources, abortSignal) {
189
- abortSignal?.throwIfAborted();
190
- if (!currentSources.length) return void 0;
191
- let assets;
192
- try {
193
- assets = useWorkspaceAssets(definition.name);
194
- } catch (error) {
195
- if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
196
- throw error;
197
- }
198
- const entries = await assets.list("", { recursive: true });
199
- abortSignal?.throwIfAborted();
200
- const files = entries.filter((entry) => entry.type === "file");
201
- const bundledPaths = new Set(files.map((entry) => entry.path));
202
- const bundledSourceByPath = /* @__PURE__ */ new Map();
203
- const bundledBuildSources = /* @__PURE__ */ new Set();
204
- for (const source of currentSources) {
205
- abortSignal?.throwIfAborted();
206
- if (await hasCompleteBundledBuildSource(definition, store, source, bundledPaths, files, bundledSourceByPath, abortSignal)) {
207
- abortSignal?.throwIfAborted();
208
- bundledBuildSources.add(source.key);
209
- }
210
- }
211
- for (const entry of files) {
212
- abortSignal?.throwIfAborted();
213
- const sourceKey = typeof entry.metadata?.source === "string" ? entry.metadata.source : bundledSourceByPath.get(entry.path) || findBuildSourceForPath(entry.path, currentSources)?.key;
214
- const content = await assets.readFile(entry.path, { encoding: "binary" });
215
- abortSignal?.throwIfAborted();
216
- await store.writeFile(entry.path, {
217
- path: entry.path,
218
- content,
219
- mediaType: entry.mediaType,
220
- metadata: sourceKey ? {
221
- ...entry.metadata,
222
- source: sourceKey
223
- } : entry.metadata
224
- });
225
- }
226
- return bundledBuildSources;
227
- }
228
- async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath, abortSignal) {
229
- const probeKeys = source.source.probeKeys;
230
- if (!probeKeys?.length) {
231
- const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
232
- const sourcePaths = await tryListBuildSourcePaths(definition, store, source, abortSignal);
233
- if (sourcePaths && !sourcePaths.every((path) => paths.includes(path))) return false;
234
- for (const path of paths) bundledSourceByPath?.set(path, source.key);
235
- return paths.length > 0;
236
- }
237
- const paths = probeKeys.map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
238
- if (!paths.every((path) => bundledPaths.has(path))) return false;
239
- for (const path of paths) bundledSourceByPath?.set(path, source.key);
240
- return true;
241
- }
242
- async function tryListBuildSourcePaths(definition, store, source, abortSignal) {
243
- const ctx = createSourceContext(definition, {
244
- key: source.key,
245
- mountPath: source.mountPath
246
- }, store, { abortSignal });
247
- try {
248
- await prepareWorkspaceSource(source.source, ctx);
249
- return (await source.source.getKeys(ctx)).map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
250
- } catch {
251
- return;
252
- }
253
- }
254
- function findBuildSourceForPath(path, sources) {
255
- const matches = sources.filter((source) => !source.mountPath || path === source.mountPath || path.startsWith(`${source.mountPath}/`)).sort((left, right) => right.mountPath.length - left.mountPath.length)[0];
256
- if (!matches?.mountPath && sources.filter((source) => !source.mountPath).length > 1) return void 0;
257
- return matches;
258
- }
259
- async function readSyncedBuildSources(store) {
260
- const value = await store.getMeta?.(buildSourcesMetaKey);
261
- if (!Array.isArray(value)) return [];
262
- return value.filter(isSyncedBuildSource);
263
- }
264
- async function rootBuildSourceFilePaths(store, source) {
265
- return (await store.list("", { recursive: true })).filter((entry) => entry.type === "file" && entry.metadata?.source === source.key).map((entry) => entry.path);
266
- }
267
- async function removeRootBuildSourceFiles(store, paths) {
268
- await Promise.all(paths.map((path) => store.rm(path, { force: true })));
269
- }
270
- function isSyncedBuildSource(value) {
271
- return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
272
- }
273
- function createMountedBuildSource(source) {
274
- const sourceContexts = /* @__PURE__ */ new WeakMap();
275
- function getSourceContext(ctx) {
276
- let sourceContext = sourceContexts.get(ctx);
277
- if (sourceContext) return sourceContext;
278
- sourceContext = {
279
- ...ctx,
280
- mountPath: source.mountPath,
281
- source: source.key
282
- };
283
- sourceContexts.set(ctx, sourceContext);
284
- return sourceContext;
285
- }
286
- return {
287
- ...source.source,
288
- key: source.key,
289
- async resolveRevision(ctx) {
290
- const sourceContext = getSourceContext(ctx);
291
- const revision = await source.source.resolveRevision?.(sourceContext);
292
- if (revision) sourceContext.revision = revision;
293
- return revision;
294
- },
295
- async prepare(ctx) {
296
- await prepareWorkspaceSource(source.source, getSourceContext(ctx));
297
- },
298
- async getKeys(ctx) {
299
- return await source.source.getKeys(getSourceContext(ctx));
300
- },
301
- async getItem(key, ctx) {
302
- const item = await source.source.getItem(key, getSourceContext(ctx));
303
- const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
304
- return {
305
- ...item,
306
- path,
307
- metadata: {
308
- ...item.metadata,
309
- source: source.key
310
- }
311
- };
312
- }
313
- };
314
- }
315
- //#endregion
316
- export { syncWorkspaceDefinition as n, lifecycle_exports as t };