@vite-hub/workspace 0.0.3 → 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.
- package/LICENSE +201 -0
- package/README.md +13 -2
- package/dist/{ai-Ce3PtWFW.js → ai-BqCC8BpY.js} +2 -2
- package/dist/{ai-nmHdzjCM.d.ts → ai-CjxvGqM0.d.ts} +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
- package/dist/chunk-2rV9d50f.js +35 -0
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config-CZLO0m9h.js → config-Bc3c4Su1.js} +213 -120
- package/dist/{config-CDoyls2X.js → config-CHLLWklZ.js} +9 -3
- package/dist/{config-3I1BnsdO.d.ts → config-DE9xlaIw.d.ts} +1 -1
- package/dist/{file-CHfsZpso.js → file-Bc1X7pco.js} +3 -3
- package/dist/{files-QRV55OCx.js → files-Q6xZjDHA.js} +20 -9
- package/dist/{github-CfA5vpJ5.js → github-DHnjxQIX.js} +24 -15
- package/dist/{glob-D0vD_wRY.js → glob-CEZKeZFC.js} +5 -4
- package/dist/host-DJH8cuoU.js +1030 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-RPeJOCFz.js} +121 -31
- package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +42 -51
- package/dist/index.js +124 -419
- package/dist/lifecycle-LrL3sA4n.js +316 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/metadata-target-B0tOmVW7.js +717 -0
- package/dist/mountx.d.ts +1 -1
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +8 -2
- package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
- package/dist/{provider-C3_elpEh.js → provider-B1yLjCJJ.js} +194 -47
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +2 -2
- package/dist/registry-D3yzt8HQ.js +127 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Uj6IVxes.d.ts} +3 -3
- package/dist/{request-execution-u9mgUXKX.js → request-execution-B-dSFlGB.js} +8 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -2
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime-type-iEE6BjQJ.js +34 -0
- package/dist/runtime.d.ts +42 -7
- package/dist/runtime.js +275 -82
- package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +23 -50
- package/dist/{shared-jfogBrd5.js → shared-DTR1Hhma.js} +97 -39
- package/dist/source-metadata.d.ts +9 -2
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-tYcRWEh2.d.ts} +13 -12
- package/dist/store-Dt_Jyys3.js +608 -0
- package/dist/{sync-DiuDmSGk.js → sync-DnTQwt8r.js} +6 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CVzURBxC.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-CYuwjJ4V.d.ts} +94 -27
- package/dist/{use-CsV3oIxH.js → use-BTNDR5Rd.js} +145 -31
- package/dist/{use-CUFSnFCS.d.ts → use-BiHzt0xA.d.ts} +21 -4
- package/dist/vite-BptCrpv2.js +4526 -0
- package/dist/vite-CtA9guIM.d.ts +66 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/{workspace-C4k92Ow8.js → workspace-Dq08Yn72.js} +224 -529
- package/dist/{workspace-66SKyiec.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
- package/package.json +15 -18
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { a as resolveRuntimeVercelBlobWorkspaceStore, c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, o as resolveVercelBlobWorkspaceStore } from "./provider-C3_elpEh.js";
|
|
3
|
-
import { i as diffSnapshots, r as createSnapshotFromEntries } from "./store-Bs1SLh55.js";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
//#region src/providers/vercel/blob-store.ts
|
|
6
|
-
function joinBlobPath(...parts) {
|
|
7
|
-
return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
|
|
8
|
-
}
|
|
9
|
-
function contentType(path, fallback) {
|
|
10
|
-
if (fallback) return fallback;
|
|
11
|
-
if (path.endsWith(".json")) return "application/json; charset=utf-8";
|
|
12
|
-
if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
|
|
13
|
-
}
|
|
14
|
-
function auth(options) {
|
|
15
|
-
return options.token ? { token: options.token } : {};
|
|
16
|
-
}
|
|
17
|
-
async function createVercelBlobClient(options) {
|
|
18
|
-
const blob = await importVercelBlobPeer();
|
|
19
|
-
const access = options.access || "private";
|
|
20
|
-
return {
|
|
21
|
-
async delete(key) {
|
|
22
|
-
await blob.del(key, auth(options));
|
|
23
|
-
},
|
|
24
|
-
async download(key) {
|
|
25
|
-
const result = await blob.get(key, {
|
|
26
|
-
access,
|
|
27
|
-
...auth(options)
|
|
28
|
-
});
|
|
29
|
-
if (!result || result.statusCode !== 200 || !result.stream) throw Object.assign(/* @__PURE__ */ new Error("not found"), { code: "NotFound" });
|
|
30
|
-
return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
|
|
31
|
-
},
|
|
32
|
-
async head(key) {
|
|
33
|
-
const result = await blob.head(key, auth(options));
|
|
34
|
-
return {
|
|
35
|
-
key: result.pathname,
|
|
36
|
-
lastModified: result.uploadedAt.getTime(),
|
|
37
|
-
size: result.size,
|
|
38
|
-
type: result.contentType
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
async list(optionsInput) {
|
|
42
|
-
const result = await blob.list({
|
|
43
|
-
...optionsInput,
|
|
44
|
-
...auth(options)
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
cursor: result.cursor,
|
|
48
|
-
items: result.blobs.map((item) => ({
|
|
49
|
-
key: item.pathname,
|
|
50
|
-
lastModified: item.uploadedAt?.getTime(),
|
|
51
|
-
size: item.size
|
|
52
|
-
}))
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
async upload(key, body, uploadOptions = {}) {
|
|
56
|
-
await blob.put(key, body, {
|
|
57
|
-
access,
|
|
58
|
-
addRandomSuffix: false,
|
|
59
|
-
allowOverwrite: true,
|
|
60
|
-
contentType: uploadOptions.contentType,
|
|
61
|
-
...auth(options)
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const vercelBlobPeerSpecifier = "@vercel/blob";
|
|
67
|
-
async function importVercelBlobPeer() {
|
|
68
|
-
try {
|
|
69
|
-
const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
|
|
70
|
-
if (testImport) return await testImport();
|
|
71
|
-
return await import(vercelBlobPeerSpecifier);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
handleVercelBlobImportError(error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function handleVercelBlobImportError(error) {
|
|
77
|
-
if (isMissingVercelBlobError(error)) throw workspaceError("[vitehub] @vercel/blob is required for the Vercel Blob Workspace Store. Package: @vercel/blob.", { cause: error });
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
function isMissingVercelBlobError(error) {
|
|
81
|
-
if (!(error instanceof Error)) return false;
|
|
82
|
-
const code = error.code;
|
|
83
|
-
if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") return false;
|
|
84
|
-
return error.message.includes("Cannot find package '@vercel/blob'") || error.message.includes("Cannot find module '@vercel/blob'");
|
|
85
|
-
}
|
|
86
|
-
var VercelBlobWorkspaceStore = class {
|
|
87
|
-
workspaceName;
|
|
88
|
-
#baseline;
|
|
89
|
-
#options;
|
|
90
|
-
#files;
|
|
91
|
-
constructor(options, workspaceName) {
|
|
92
|
-
this.workspaceName = workspaceName;
|
|
93
|
-
this.#options = resolveRuntimeVercelBlobWorkspaceStore(options, typeof process !== "undefined" ? process.env : {});
|
|
94
|
-
}
|
|
95
|
-
get #root() {
|
|
96
|
-
return joinBlobPath(this.#options.prefix || ".vitehub/workspaces", this.workspaceName);
|
|
97
|
-
}
|
|
98
|
-
#fileKey(path, options = {}) {
|
|
99
|
-
return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
|
|
100
|
-
}
|
|
101
|
-
async #client() {
|
|
102
|
-
this.#files ||= createVercelBlobClient(this.#options);
|
|
103
|
-
return await this.#files;
|
|
104
|
-
}
|
|
105
|
-
#metaKey(key) {
|
|
106
|
-
return joinBlobPath(this.#root, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
|
|
107
|
-
}
|
|
108
|
-
#snapshotKey(id) {
|
|
109
|
-
return joinBlobPath(this.#root, ".vitehub/snapshots", `${id}.json`);
|
|
110
|
-
}
|
|
111
|
-
async readFile(path) {
|
|
112
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
113
|
-
const pathname = this.#fileKey(normalized);
|
|
114
|
-
const file = await (await this.#client()).download(pathname).catch(() => null);
|
|
115
|
-
if (!file) return void 0;
|
|
116
|
-
const bytes = await file.arrayBuffer();
|
|
117
|
-
return {
|
|
118
|
-
path: normalized,
|
|
119
|
-
content: new Uint8Array(bytes)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
async writeFile(path, file) {
|
|
123
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
124
|
-
await (await this.#client()).upload(this.#fileKey(normalized), new Blob([contentToBytes(file.content)]), { contentType: contentType(normalized, file.mediaType) });
|
|
125
|
-
}
|
|
126
|
-
async list(prefix = "", options = {}) {
|
|
127
|
-
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
128
|
-
const filePrefix = this.#fileKey(normalizedPrefix, { allowEmpty: true });
|
|
129
|
-
const files = await this.#listBlobs(normalizedPrefix ? `${filePrefix}/` : `${this.#fileKey("", { allowEmpty: true })}/`);
|
|
130
|
-
const entries = /* @__PURE__ */ new Map();
|
|
131
|
-
for (const blob of files) {
|
|
132
|
-
const path = normalizeWorkspacePath(blob.key.slice(`${this.#fileKey("", { allowEmpty: true })}/`.length));
|
|
133
|
-
if (!path) continue;
|
|
134
|
-
if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
|
|
135
|
-
if (!options.recursive && normalizedPrefix && path.slice(normalizedPrefix.length + 1).includes("/")) continue;
|
|
136
|
-
if (!options.recursive && !normalizedPrefix && path.includes("/")) {
|
|
137
|
-
entries.set(path.split("/")[0], {
|
|
138
|
-
path: path.split("/")[0],
|
|
139
|
-
type: "directory"
|
|
140
|
-
});
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
entries.set(path, {
|
|
144
|
-
mtime: blob.lastModified,
|
|
145
|
-
path,
|
|
146
|
-
size: blob.size,
|
|
147
|
-
type: "file"
|
|
148
|
-
});
|
|
149
|
-
if (options.recursive) {
|
|
150
|
-
const parts = path.split("/");
|
|
151
|
-
for (let index = 1; index < parts.length; index++) {
|
|
152
|
-
const dir = parts.slice(0, index).join("/");
|
|
153
|
-
entries.set(dir, {
|
|
154
|
-
path: dir,
|
|
155
|
-
type: "directory"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
161
|
-
}
|
|
162
|
-
async glob(pattern, _options = {}) {
|
|
163
|
-
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
164
|
-
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
165
|
-
}
|
|
166
|
-
async stat(path) {
|
|
167
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
168
|
-
const file = await this.readFile(normalized);
|
|
169
|
-
if (file) {
|
|
170
|
-
const bytes = contentToBytes(file.content);
|
|
171
|
-
return {
|
|
172
|
-
digest: await sha256(bytes),
|
|
173
|
-
path: normalized,
|
|
174
|
-
size: bytes.byteLength,
|
|
175
|
-
type: "file"
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return (await this.list(normalized, { recursive: false })).length ? {
|
|
179
|
-
path: normalized,
|
|
180
|
-
type: "directory"
|
|
181
|
-
} : void 0;
|
|
182
|
-
}
|
|
183
|
-
async mkdir(path, _options = {}) {
|
|
184
|
-
normalizeSafeWorkspacePath(path);
|
|
185
|
-
}
|
|
186
|
-
async rm(path, options = {}) {
|
|
187
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
188
|
-
const client = await this.#client();
|
|
189
|
-
const targets = [];
|
|
190
|
-
if (await client.head(this.#fileKey(normalized)).catch(() => null)) targets.push(this.#fileKey(normalized));
|
|
191
|
-
else if (options.recursive) for (const blob of await this.#listBlobs(`${this.#fileKey(normalized)}/`)) targets.push(blob.key);
|
|
192
|
-
if (!targets.length) {
|
|
193
|
-
if (options.force) return;
|
|
194
|
-
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
195
|
-
}
|
|
196
|
-
await Promise.all(targets.map((target) => client.delete(target)));
|
|
197
|
-
}
|
|
198
|
-
async snapshot(options = {}) {
|
|
199
|
-
const snapshot = await createSnapshotFromEntries(await this.list("", { recursive: true }), options.name);
|
|
200
|
-
await (await this.#client()).upload(this.#snapshotKey(snapshot.id), JSON.stringify(snapshot), { contentType: "application/json; charset=utf-8" });
|
|
201
|
-
this.#baseline = snapshot;
|
|
202
|
-
return snapshot;
|
|
203
|
-
}
|
|
204
|
-
async diff(options = {}) {
|
|
205
|
-
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.list("", { recursive: true })));
|
|
206
|
-
}
|
|
207
|
-
async getMeta(key) {
|
|
208
|
-
return await this.#readJson(this.#metaKey(key));
|
|
209
|
-
}
|
|
210
|
-
async setMeta(key, value) {
|
|
211
|
-
await (await this.#client()).upload(this.#metaKey(key), JSON.stringify(value), { contentType: "application/json; charset=utf-8" });
|
|
212
|
-
}
|
|
213
|
-
async #listBlobs(prefix) {
|
|
214
|
-
const blobs = [];
|
|
215
|
-
let cursor;
|
|
216
|
-
do {
|
|
217
|
-
const result = await (await this.#client()).list({
|
|
218
|
-
cursor,
|
|
219
|
-
limit: 1e3,
|
|
220
|
-
prefix
|
|
221
|
-
});
|
|
222
|
-
blobs.push(...result.items);
|
|
223
|
-
cursor = result.cursor;
|
|
224
|
-
} while (cursor);
|
|
225
|
-
return blobs;
|
|
226
|
-
}
|
|
227
|
-
async #readJson(pathname) {
|
|
228
|
-
const file = await (await this.#client()).download(pathname).catch(() => null);
|
|
229
|
-
return file ? JSON.parse(await file.text()) : void 0;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
function createVercelBlobWorkspaceStore(options, workspaceName) {
|
|
233
|
-
return new VercelBlobWorkspaceStore(options, workspaceName);
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/hosted-vercel-blob.ts
|
|
237
|
-
function installHostedVercelBlobWorkspaceRuntime() {
|
|
238
|
-
const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
|
|
239
|
-
setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
|
|
240
|
-
if (storeOptions.provider === "vercel-blob") return createVercelBlobWorkspaceStore(storeOptions, workspaceName);
|
|
241
|
-
if (existingWorkspaceHostedStoreLoader) return existingWorkspaceHostedStoreLoader(storeOptions, workspaceName);
|
|
242
|
-
throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime cannot load unsupported hosted store.");
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function configureHostedVercelBlobWorkspaceRuntime(options = {}) {
|
|
246
|
-
const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
|
|
247
|
-
const config = {
|
|
248
|
-
assets: options.assets,
|
|
249
|
-
root,
|
|
250
|
-
store: resolveVercelBlobWorkspaceStore(options.store, options.env)
|
|
251
|
-
};
|
|
252
|
-
installHostedVercelBlobWorkspaceRuntime();
|
|
253
|
-
setWorkspaceRuntimeConfig(config);
|
|
254
|
-
return config;
|
|
255
|
-
}
|
|
256
|
-
//#endregion
|
|
257
|
-
export { installHostedVercelBlobWorkspaceRuntime as n, configureHostedVercelBlobWorkspaceRuntime as t };
|
|
@@ -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-CZLO0m9h.js";
|
|
4
|
-
import { n as createCurrentSnapshotFromStore } from "./store-Bs1SLh55.js";
|
|
5
|
-
import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
|
|
6
|
-
import { t as files } from "./files-QRV55OCx.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,74 +0,0 @@
|
|
|
1
|
-
import { m as workspaceNotFoundError } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { t as createWorkspace } from "./workspace-C4k92Ow8.js";
|
|
3
|
-
import runtimeRegistry from "#vitehub-workspace-registry";
|
|
4
|
-
//#region src/core/registry.ts
|
|
5
|
-
const workspaceRegistryStateKey = Symbol.for("vitehub.workspace.registryState");
|
|
6
|
-
function workspaceRegistryState() {
|
|
7
|
-
const scope = globalThis;
|
|
8
|
-
scope[workspaceRegistryStateKey] ??= {
|
|
9
|
-
loadedDefinitions: /* @__PURE__ */ new Map(),
|
|
10
|
-
loaders: runtimeRegistry,
|
|
11
|
-
registeredDefinitions: /* @__PURE__ */ new Map()
|
|
12
|
-
};
|
|
13
|
-
return scope[workspaceRegistryStateKey];
|
|
14
|
-
}
|
|
15
|
-
function pickWorkspaceFields(definition) {
|
|
16
|
-
const { __vitehubWorkspaceAgent: _agent, __vitehubWorkspaceAgentOptions: _agentOptions, description: _description, fallback: _fallback, instructions: _instructions, model: _model, name: _agentName, resolve: _resolve, run: _run, stepLimit: _stepLimit, workspace: _workspace, ...workspace } = definition;
|
|
17
|
-
return workspace;
|
|
18
|
-
}
|
|
19
|
-
function normalizeWorkspaceDefinition(name, definition) {
|
|
20
|
-
if (!definition) throw workspaceNotFoundError(name);
|
|
21
|
-
const workspaceAgentOptions = definition.__vitehubWorkspaceAgentOptions;
|
|
22
|
-
if (workspaceAgentOptions?.workspace) {
|
|
23
|
-
const injectedWorkspace = pickWorkspaceFields(definition);
|
|
24
|
-
const configuredWorkspace = typeof workspaceAgentOptions.workspace === "string" ? {} : workspaceAgentOptions.workspace;
|
|
25
|
-
const sources = mergeWorkspaceSources(injectedWorkspace.sources, configuredWorkspace.sources);
|
|
26
|
-
return {
|
|
27
|
-
...injectedWorkspace,
|
|
28
|
-
...configuredWorkspace,
|
|
29
|
-
...sources ? { sources } : {},
|
|
30
|
-
rootDir: configuredWorkspace.rootDir ?? injectedWorkspace.rootDir,
|
|
31
|
-
sourceRootDir: configuredWorkspace.sourceRootDir ?? injectedWorkspace.sourceRootDir,
|
|
32
|
-
name
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
if ("name" in definition) throw new TypeError(`[vitehub] Workspace definition "${name}" must not declare a name. Workspace names are inferred from filenames.`);
|
|
36
|
-
return {
|
|
37
|
-
...pickWorkspaceFields(definition),
|
|
38
|
-
name
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function mergeWorkspaceSources(injected, configured) {
|
|
42
|
-
if (!injected && !configured) return void 0;
|
|
43
|
-
return {
|
|
44
|
-
...injected,
|
|
45
|
-
...configured
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function registerWorkspace(name, definition) {
|
|
49
|
-
if (!name || typeof name !== "string") throw new TypeError("[vitehub] registerWorkspace requires a string name.");
|
|
50
|
-
workspaceRegistryState().registeredDefinitions.set(name, normalizeWorkspaceDefinition(name, definition));
|
|
51
|
-
}
|
|
52
|
-
function setWorkspaceRegistry(registry) {
|
|
53
|
-
const state = workspaceRegistryState();
|
|
54
|
-
state.loaders = registry;
|
|
55
|
-
state.loadedDefinitions.clear();
|
|
56
|
-
}
|
|
57
|
-
async function resolveWorkspaceDefinition(name) {
|
|
58
|
-
const state = workspaceRegistryState();
|
|
59
|
-
const existing = state.registeredDefinitions.get(name) || state.loadedDefinitions.get(name);
|
|
60
|
-
if (existing) return existing;
|
|
61
|
-
const load = state.loaders[name];
|
|
62
|
-
if (!load) throw workspaceNotFoundError(name);
|
|
63
|
-
const definition = normalizeWorkspaceDefinition(name, (await load()).default);
|
|
64
|
-
state.loadedDefinitions.set(name, definition);
|
|
65
|
-
return definition;
|
|
66
|
-
}
|
|
67
|
-
async function resolveRegisteredWorkspaceDefinition(name) {
|
|
68
|
-
return resolveWorkspaceDefinition(name);
|
|
69
|
-
}
|
|
70
|
-
async function useRegisteredWorkspace(name) {
|
|
71
|
-
return createWorkspace(await resolveWorkspaceDefinition(name));
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { useRegisteredWorkspace as a, setWorkspaceRegistry as i, registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, normalizeWorkspaceDefinition as t };
|