@vite-hub/workspace 0.0.3 → 0.1.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.
- package/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- 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.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- 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/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, p as workspaceError, r as contentToBytes, t as contentStreamChunks, u as resolveInside } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { t as createGitHubWorkspaceStore } from "./store-Bs1SLh55.js";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { defu } from "defu";
|
|
6
|
-
import { createReadStream, createWriteStream } from "node:fs";
|
|
7
|
-
import { Readable, Transform } from "node:stream";
|
|
8
|
-
import { pipeline } from "node:stream/promises";
|
|
9
|
-
//#region ../internal/src/env.ts
|
|
10
|
-
function trimmed(value) {
|
|
11
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
12
|
-
}
|
|
13
|
-
function readEnv(env, ...names) {
|
|
14
|
-
for (const name of names) {
|
|
15
|
-
const value = trimmed(env[name]);
|
|
16
|
-
if (value) return value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/runtime/config.ts
|
|
21
|
-
const workspaceRuntimeConfigKey = Symbol.for("vitehub.workspace.runtimeConfig");
|
|
22
|
-
function workspaceRuntimeConfigGlobal() {
|
|
23
|
-
const scope = globalThis;
|
|
24
|
-
scope[workspaceRuntimeConfigKey] ??= false;
|
|
25
|
-
return scope;
|
|
26
|
-
}
|
|
27
|
-
function setWorkspaceRuntimeConfig(config) {
|
|
28
|
-
workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] = config;
|
|
29
|
-
}
|
|
30
|
-
function getWorkspaceRuntimeConfig() {
|
|
31
|
-
return workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] ?? false;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/runtime/hosted-store-loader.ts
|
|
35
|
-
const workspaceHostedStoreLoaderKey = Symbol.for("vitehub.workspace.hostedStoreLoader");
|
|
36
|
-
function workspaceHostedStoreLoaderGlobal() {
|
|
37
|
-
return globalThis;
|
|
38
|
-
}
|
|
39
|
-
function setWorkspaceHostedStoreLoader(loader) {
|
|
40
|
-
workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey] = loader;
|
|
41
|
-
}
|
|
42
|
-
function getWorkspaceHostedStoreLoader() {
|
|
43
|
-
return workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey];
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/storage/local.ts
|
|
47
|
-
async function walk(root, current = root) {
|
|
48
|
-
const { readdir } = await import("node:fs/promises");
|
|
49
|
-
const { relative } = await import("node:path");
|
|
50
|
-
const entries = [];
|
|
51
|
-
const dirents = await readdir(current, { withFileTypes: true }).catch((error) => {
|
|
52
|
-
if (error.code === "ENOENT") return [];
|
|
53
|
-
throw error;
|
|
54
|
-
});
|
|
55
|
-
for (const dirent of dirents) {
|
|
56
|
-
const absolute = `${current}/${dirent.name}`;
|
|
57
|
-
const path = normalizeWorkspacePath(relative(root, absolute));
|
|
58
|
-
const { stat } = await import("node:fs/promises");
|
|
59
|
-
const info = await stat(absolute).catch((error) => {
|
|
60
|
-
if (error.code === "ENOENT") return void 0;
|
|
61
|
-
throw error;
|
|
62
|
-
});
|
|
63
|
-
if (!info) continue;
|
|
64
|
-
if (dirent.isDirectory()) {
|
|
65
|
-
entries.push({
|
|
66
|
-
path,
|
|
67
|
-
type: "directory",
|
|
68
|
-
mtime: info.mtimeMs
|
|
69
|
-
});
|
|
70
|
-
entries.push(...await walk(root, absolute));
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (dirent.isFile()) entries.push({
|
|
74
|
-
path,
|
|
75
|
-
type: "file",
|
|
76
|
-
size: info.size,
|
|
77
|
-
mtime: info.mtimeMs,
|
|
78
|
-
digest: await fileDigest(absolute)
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return entries;
|
|
82
|
-
}
|
|
83
|
-
async function fileDigest(path) {
|
|
84
|
-
return await new Promise((resolve, reject) => {
|
|
85
|
-
const hash = createHash("sha256");
|
|
86
|
-
const stream = createReadStream(path);
|
|
87
|
-
stream.on("data", (chunk) => hash.update(chunk));
|
|
88
|
-
stream.on("error", reject);
|
|
89
|
-
stream.on("end", () => resolve(hash.digest("hex")));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
var LocalWorkspaceStore = class {
|
|
93
|
-
root;
|
|
94
|
-
#baseline;
|
|
95
|
-
#files = /* @__PURE__ */ new Map();
|
|
96
|
-
#meta = /* @__PURE__ */ new Map();
|
|
97
|
-
#metaLoaded = false;
|
|
98
|
-
#metaPath;
|
|
99
|
-
constructor(root) {
|
|
100
|
-
this.root = root;
|
|
101
|
-
this.#metaPath = `${root}.meta.json`;
|
|
102
|
-
}
|
|
103
|
-
async readFile(path) {
|
|
104
|
-
const { readFile } = await import("node:fs/promises");
|
|
105
|
-
const bytes = await readFile(resolveInside(this.root, path)).catch((error) => {
|
|
106
|
-
if (error.code === "ENOENT") return void 0;
|
|
107
|
-
throw error;
|
|
108
|
-
});
|
|
109
|
-
if (!bytes) return void 0;
|
|
110
|
-
const normalized = normalizeWorkspacePath(path);
|
|
111
|
-
const metadata = this.#files.get(normalized);
|
|
112
|
-
return {
|
|
113
|
-
path: normalized,
|
|
114
|
-
content: new Uint8Array(bytes),
|
|
115
|
-
mediaType: metadata?.mediaType,
|
|
116
|
-
metadata: metadata?.metadata
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async writeFile(path, file) {
|
|
120
|
-
const { dirname } = await import("node:path");
|
|
121
|
-
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
122
|
-
const absolute = resolveInside(this.root, path);
|
|
123
|
-
const normalized = normalizeWorkspacePath(path);
|
|
124
|
-
const bytes = contentToBytes(file.content);
|
|
125
|
-
const digest = await sha256(bytes);
|
|
126
|
-
const existing = await this.stat(normalized);
|
|
127
|
-
if (existing?.type === "file" && existing.digest === digest) {
|
|
128
|
-
this.#files.set(normalized, {
|
|
129
|
-
mediaType: file.mediaType,
|
|
130
|
-
metadata: file.metadata
|
|
131
|
-
});
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
await mkdir(dirname(absolute), { recursive: true });
|
|
135
|
-
await writeFile(absolute, bytes);
|
|
136
|
-
this.#files.set(normalized, {
|
|
137
|
-
mediaType: file.mediaType,
|
|
138
|
-
metadata: file.metadata
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
async writeFileStream(path, file) {
|
|
142
|
-
const { dirname } = await import("node:path");
|
|
143
|
-
const { mkdir, rename, rm } = await import("node:fs/promises");
|
|
144
|
-
const normalized = normalizeWorkspacePath(path);
|
|
145
|
-
const absolute = resolveInside(this.root, path);
|
|
146
|
-
const temp = `${absolute}.${process.pid}.${Date.now()}.tmp`;
|
|
147
|
-
const hash = createHash("sha256");
|
|
148
|
-
let size = 0;
|
|
149
|
-
await mkdir(dirname(absolute), { recursive: true });
|
|
150
|
-
try {
|
|
151
|
-
const hashing = new Transform({ transform(chunk, _encoding, callback) {
|
|
152
|
-
hash.update(chunk);
|
|
153
|
-
size += chunk.byteLength;
|
|
154
|
-
callback(void 0, chunk);
|
|
155
|
-
} });
|
|
156
|
-
await pipeline(Readable.from(contentStreamChunks(file.content)), hashing, createWriteStream(temp));
|
|
157
|
-
const digest = hash.digest("hex");
|
|
158
|
-
const existing = await this.stat(normalized);
|
|
159
|
-
if (existing?.type === "file" && existing.digest === digest) {
|
|
160
|
-
await rm(temp, { force: true });
|
|
161
|
-
this.#files.set(normalized, {
|
|
162
|
-
mediaType: file.mediaType,
|
|
163
|
-
metadata: file.metadata
|
|
164
|
-
});
|
|
165
|
-
return {
|
|
166
|
-
...existing,
|
|
167
|
-
mediaType: file.mediaType,
|
|
168
|
-
metadata: file.metadata,
|
|
169
|
-
size,
|
|
170
|
-
digest
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
await rename(temp, absolute);
|
|
174
|
-
this.#files.set(normalized, {
|
|
175
|
-
mediaType: file.mediaType,
|
|
176
|
-
metadata: file.metadata
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
path: normalized,
|
|
180
|
-
type: "file",
|
|
181
|
-
size,
|
|
182
|
-
mediaType: file.mediaType,
|
|
183
|
-
metadata: file.metadata,
|
|
184
|
-
digest
|
|
185
|
-
};
|
|
186
|
-
} catch (error) {
|
|
187
|
-
await rm(temp, { force: true }).catch(() => void 0);
|
|
188
|
-
throw error;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
async list(prefix = "", options = {}) {
|
|
192
|
-
const normalizedPrefix = normalizeWorkspacePath(prefix);
|
|
193
|
-
return (await walk(this.root)).filter((entry) => {
|
|
194
|
-
if (!normalizedPrefix) return options.recursive || !entry.path.includes("/");
|
|
195
|
-
if (entry.path === normalizedPrefix) return false;
|
|
196
|
-
if (!entry.path.startsWith(`${normalizedPrefix}/`)) return false;
|
|
197
|
-
return options.recursive || !entry.path.slice(normalizedPrefix.length + 1).includes("/");
|
|
198
|
-
}).map((entry) => ({
|
|
199
|
-
...entry,
|
|
200
|
-
mediaType: entry.type === "file" ? this.#files.get(entry.path)?.mediaType : entry.mediaType,
|
|
201
|
-
metadata: entry.type === "file" ? this.#files.get(entry.path)?.metadata : entry.metadata
|
|
202
|
-
})).sort((a, b) => a.path.localeCompare(b.path));
|
|
203
|
-
}
|
|
204
|
-
async glob(pattern, _options = {}) {
|
|
205
|
-
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
206
|
-
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
|
|
207
|
-
}
|
|
208
|
-
async stat(path) {
|
|
209
|
-
const { stat } = await import("node:fs/promises");
|
|
210
|
-
const normalized = normalizeWorkspacePath(path);
|
|
211
|
-
const absolute = resolveInside(this.root, normalized);
|
|
212
|
-
const info = await stat(absolute).catch((error) => {
|
|
213
|
-
if (error.code === "ENOENT") return void 0;
|
|
214
|
-
throw error;
|
|
215
|
-
});
|
|
216
|
-
if (!info) return void 0;
|
|
217
|
-
return {
|
|
218
|
-
path: normalized,
|
|
219
|
-
type: info.isDirectory() ? "directory" : "file",
|
|
220
|
-
size: info.isFile() ? info.size : void 0,
|
|
221
|
-
mtime: info.mtimeMs,
|
|
222
|
-
mediaType: info.isFile() ? this.#files.get(normalized)?.mediaType : void 0,
|
|
223
|
-
metadata: info.isFile() ? this.#files.get(normalized)?.metadata : void 0,
|
|
224
|
-
digest: info.isFile() ? await fileDigest(absolute) : void 0
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
async mkdir(path, options = {}) {
|
|
228
|
-
const { mkdir } = await import("node:fs/promises");
|
|
229
|
-
await mkdir(resolveInside(this.root, path), { recursive: options.recursive ?? true });
|
|
230
|
-
}
|
|
231
|
-
async rm(path, options = {}) {
|
|
232
|
-
const { rm } = await import("node:fs/promises");
|
|
233
|
-
const normalized = normalizeWorkspacePath(path);
|
|
234
|
-
await rm(resolveInside(this.root, path), {
|
|
235
|
-
recursive: options.recursive ?? false,
|
|
236
|
-
force: options.force ?? false
|
|
237
|
-
}).catch((error) => {
|
|
238
|
-
if (error.code === "ENOENT" && options.force) return;
|
|
239
|
-
throw error;
|
|
240
|
-
});
|
|
241
|
-
for (const key of this.#files.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#files.delete(key);
|
|
242
|
-
}
|
|
243
|
-
async snapshot(options = {}) {
|
|
244
|
-
const { mkdir } = await import("node:fs/promises");
|
|
245
|
-
await mkdir(this.root, { recursive: true });
|
|
246
|
-
const snapshot = await this.#createSnapshot(options.name);
|
|
247
|
-
this.#baseline = snapshot;
|
|
248
|
-
return snapshot;
|
|
249
|
-
}
|
|
250
|
-
async diff(options = {}) {
|
|
251
|
-
const from = options.from || this.#baseline;
|
|
252
|
-
const to = await this.#createSnapshot();
|
|
253
|
-
const entries = [];
|
|
254
|
-
const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
|
|
255
|
-
for (const path of [...keys].sort()) {
|
|
256
|
-
const before = from?.entries[path];
|
|
257
|
-
const after = to.entries[path];
|
|
258
|
-
if (!before && after) entries.push({
|
|
259
|
-
path,
|
|
260
|
-
type: "added",
|
|
261
|
-
after
|
|
262
|
-
});
|
|
263
|
-
else if (before && !after) entries.push({
|
|
264
|
-
path,
|
|
265
|
-
type: "removed",
|
|
266
|
-
before
|
|
267
|
-
});
|
|
268
|
-
else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
|
|
269
|
-
path,
|
|
270
|
-
type: "modified",
|
|
271
|
-
before,
|
|
272
|
-
after
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
from: from?.id,
|
|
277
|
-
to: to.id,
|
|
278
|
-
entries
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
async getMeta(key) {
|
|
282
|
-
await this.#loadMeta();
|
|
283
|
-
return this.#meta.get(key);
|
|
284
|
-
}
|
|
285
|
-
async setMeta(key, value) {
|
|
286
|
-
await this.#loadMeta();
|
|
287
|
-
this.#meta.set(key, value);
|
|
288
|
-
await this.#writeMeta();
|
|
289
|
-
}
|
|
290
|
-
async #createSnapshot(name) {
|
|
291
|
-
const entries = {};
|
|
292
|
-
for (const entry of await this.list("", { recursive: true })) entries[entry.path] = {
|
|
293
|
-
type: entry.type,
|
|
294
|
-
digest: entry.digest,
|
|
295
|
-
metadata: entry.metadata,
|
|
296
|
-
size: entry.size
|
|
297
|
-
};
|
|
298
|
-
return {
|
|
299
|
-
id: await sha256({
|
|
300
|
-
name,
|
|
301
|
-
entries,
|
|
302
|
-
createdAt: Date.now()
|
|
303
|
-
}),
|
|
304
|
-
name,
|
|
305
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
306
|
-
entries
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
async #loadMeta() {
|
|
310
|
-
if (this.#metaLoaded) return;
|
|
311
|
-
this.#metaLoaded = true;
|
|
312
|
-
const { readFile } = await import("node:fs/promises");
|
|
313
|
-
const content = await readFile(this.#metaPath, "utf8").catch((error) => {
|
|
314
|
-
if (error.code === "ENOENT") return void 0;
|
|
315
|
-
throw error;
|
|
316
|
-
});
|
|
317
|
-
if (!content) return;
|
|
318
|
-
const value = JSON.parse(content);
|
|
319
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
320
|
-
this.#meta = new Map(Object.entries(value));
|
|
321
|
-
}
|
|
322
|
-
async #writeMeta() {
|
|
323
|
-
const { dirname } = await import("node:path");
|
|
324
|
-
const { mkdir, rename, rm, writeFile } = await import("node:fs/promises");
|
|
325
|
-
const temp = `${this.#metaPath}.${randomUUID()}.tmp`;
|
|
326
|
-
await mkdir(dirname(this.#metaPath), { recursive: true });
|
|
327
|
-
try {
|
|
328
|
-
await writeFile(temp, JSON.stringify(Object.fromEntries(this.#meta), null, 2));
|
|
329
|
-
await rename(temp, this.#metaPath);
|
|
330
|
-
} catch (error) {
|
|
331
|
-
await rm(temp, { force: true }).catch(() => void 0);
|
|
332
|
-
throw error;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
function createLocalWorkspaceStore(root) {
|
|
337
|
-
if (!root) throw workspaceError("[vitehub] Local workspace store requires a root directory.");
|
|
338
|
-
return new LocalWorkspaceStore(root);
|
|
339
|
-
}
|
|
340
|
-
//#endregion
|
|
341
|
-
//#region src/storage/memory.ts
|
|
342
|
-
function now() {
|
|
343
|
-
return Date.now();
|
|
344
|
-
}
|
|
345
|
-
var MemoryWorkspaceStore = class {
|
|
346
|
-
#nodes = new Map([["", {
|
|
347
|
-
type: "directory",
|
|
348
|
-
mtime: now()
|
|
349
|
-
}]]);
|
|
350
|
-
#meta = /* @__PURE__ */ new Map();
|
|
351
|
-
#baseline;
|
|
352
|
-
async readFile(path) {
|
|
353
|
-
const normalized = normalizeWorkspacePath(path);
|
|
354
|
-
const node = this.#nodes.get(normalized);
|
|
355
|
-
if (!node || node.type !== "file") return void 0;
|
|
356
|
-
return {
|
|
357
|
-
path: normalized,
|
|
358
|
-
content: node.content || "",
|
|
359
|
-
mediaType: node.mediaType,
|
|
360
|
-
metadata: node.metadata
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
async writeFile(path, file) {
|
|
364
|
-
const normalized = normalizeWorkspacePath(path);
|
|
365
|
-
this.#ensureParents(normalized);
|
|
366
|
-
this.#nodes.set(normalized, {
|
|
367
|
-
type: "file",
|
|
368
|
-
content: file.content,
|
|
369
|
-
mediaType: file.mediaType,
|
|
370
|
-
metadata: file.metadata,
|
|
371
|
-
mtime: now()
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
async list(prefix = "", options = {}) {
|
|
375
|
-
const normalizedPrefix = normalizeWorkspacePath(prefix);
|
|
376
|
-
const result = [];
|
|
377
|
-
for (const [path, node] of this.#nodes) {
|
|
378
|
-
if (!path || path === normalizedPrefix) continue;
|
|
379
|
-
if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
|
|
380
|
-
if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
381
|
-
result.push(await this.#entry(path, node));
|
|
382
|
-
}
|
|
383
|
-
return result.sort((a, b) => a.path.localeCompare(b.path));
|
|
384
|
-
}
|
|
385
|
-
async glob(pattern, _options = {}) {
|
|
386
|
-
const entries = await this.list("", { recursive: true });
|
|
387
|
-
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
388
|
-
return entries.filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
|
|
389
|
-
}
|
|
390
|
-
async stat(path) {
|
|
391
|
-
const normalized = normalizeWorkspacePath(path);
|
|
392
|
-
const node = this.#nodes.get(normalized);
|
|
393
|
-
return node ? await this.#entry(normalized, node) : void 0;
|
|
394
|
-
}
|
|
395
|
-
async mkdir(path, _options = {}) {
|
|
396
|
-
const normalized = normalizeWorkspacePath(path);
|
|
397
|
-
this.#ensureParents(normalized);
|
|
398
|
-
this.#nodes.set(normalized, {
|
|
399
|
-
type: "directory",
|
|
400
|
-
mtime: now()
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
async rm(path, options = {}) {
|
|
404
|
-
const normalized = normalizeWorkspacePath(path);
|
|
405
|
-
const node = this.#nodes.get(normalized);
|
|
406
|
-
if (!node) {
|
|
407
|
-
if (options.force) return;
|
|
408
|
-
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
409
|
-
}
|
|
410
|
-
if (node.type === "directory" && !options.recursive) {
|
|
411
|
-
for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
412
|
-
}
|
|
413
|
-
for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
|
|
414
|
-
}
|
|
415
|
-
async snapshot(options = {}) {
|
|
416
|
-
const snapshot = await this.#createSnapshot(options.name);
|
|
417
|
-
this.#baseline = snapshot;
|
|
418
|
-
return snapshot;
|
|
419
|
-
}
|
|
420
|
-
async diff(options = {}) {
|
|
421
|
-
const from = options.from || this.#baseline;
|
|
422
|
-
const to = await this.#createSnapshot();
|
|
423
|
-
const entries = [];
|
|
424
|
-
const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
|
|
425
|
-
for (const path of [...keys].sort()) {
|
|
426
|
-
const before = from?.entries[path];
|
|
427
|
-
const after = to.entries[path];
|
|
428
|
-
if (!before && after) entries.push({
|
|
429
|
-
path,
|
|
430
|
-
type: "added",
|
|
431
|
-
after
|
|
432
|
-
});
|
|
433
|
-
else if (before && !after) entries.push({
|
|
434
|
-
path,
|
|
435
|
-
type: "removed",
|
|
436
|
-
before
|
|
437
|
-
});
|
|
438
|
-
else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
|
|
439
|
-
path,
|
|
440
|
-
type: "modified",
|
|
441
|
-
before,
|
|
442
|
-
after
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
return {
|
|
446
|
-
from: from?.id,
|
|
447
|
-
to: to.id,
|
|
448
|
-
entries
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
async getMeta(key) {
|
|
452
|
-
return this.#meta.get(key);
|
|
453
|
-
}
|
|
454
|
-
async setMeta(key, value) {
|
|
455
|
-
this.#meta.set(key, value);
|
|
456
|
-
}
|
|
457
|
-
#ensureParents(path) {
|
|
458
|
-
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
459
|
-
for (let index = 1; index < parts.length; index++) {
|
|
460
|
-
const dir = parts.slice(0, index).join("/");
|
|
461
|
-
if (!this.#nodes.has(dir)) this.#nodes.set(dir, {
|
|
462
|
-
type: "directory",
|
|
463
|
-
mtime: now()
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
async #entry(path, node) {
|
|
468
|
-
const content = node.content || "";
|
|
469
|
-
const size = node.type === "file" ? typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength : void 0;
|
|
470
|
-
return {
|
|
471
|
-
path,
|
|
472
|
-
type: node.type,
|
|
473
|
-
size,
|
|
474
|
-
mtime: node.mtime,
|
|
475
|
-
mediaType: node.mediaType,
|
|
476
|
-
metadata: node.metadata,
|
|
477
|
-
digest: node.type === "file" ? await sha256(content) : void 0
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
async #createSnapshot(name) {
|
|
481
|
-
const entries = {};
|
|
482
|
-
for (const [path, node] of this.#nodes) {
|
|
483
|
-
if (!path) continue;
|
|
484
|
-
const entry = await this.#entry(path, node);
|
|
485
|
-
entries[path] = {
|
|
486
|
-
type: entry.type,
|
|
487
|
-
digest: entry.digest,
|
|
488
|
-
metadata: entry.metadata,
|
|
489
|
-
size: entry.size
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
return {
|
|
493
|
-
id: await sha256({
|
|
494
|
-
name,
|
|
495
|
-
entries,
|
|
496
|
-
createdAt: Date.now()
|
|
497
|
-
}),
|
|
498
|
-
name,
|
|
499
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
500
|
-
entries
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
function createMemoryWorkspaceStore() {
|
|
505
|
-
return new MemoryWorkspaceStore();
|
|
506
|
-
}
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/storage/provider.ts
|
|
509
|
-
const MASKED_WORKSPACE_RUNTIME_VALUE = "********";
|
|
510
|
-
function workspaceRepoName(name) {
|
|
511
|
-
return name ? name.replace(/[^a-zA-Z0-9_.-]/g, "-") : void 0;
|
|
512
|
-
}
|
|
513
|
-
function gitHubWorkspaceOption(value) {
|
|
514
|
-
return typeof value === "function" ? value : trimmed(value);
|
|
515
|
-
}
|
|
516
|
-
function resolveCloudflareArtifactsStore(config = {}, env = process.env) {
|
|
517
|
-
const repoPrefix = trimmed(config.repoPrefix) ?? readEnv(env, "WORKSPACE_ARTIFACTS_REPO_PREFIX", "VITEHUB_WORKSPACE_ARTIFACTS_REPO_PREFIX") ?? "vitehub-workspace-";
|
|
518
|
-
const repo = trimmed(config.repo) ?? workspaceRepoName(readEnv(env, "WORKSPACE_ARTIFACTS_REPO", "VITEHUB_WORKSPACE_ARTIFACTS_REPO"));
|
|
519
|
-
return defu({
|
|
520
|
-
binding: trimmed(config.binding) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BINDING", "VITEHUB_WORKSPACE_ARTIFACTS_BINDING"),
|
|
521
|
-
branch: trimmed(config.branch) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BRANCH", "VITEHUB_WORKSPACE_ARTIFACTS_BRANCH"),
|
|
522
|
-
namespace: trimmed(config.namespace) ?? readEnv(env, "WORKSPACE_ARTIFACTS_NAMESPACE", "VITEHUB_WORKSPACE_ARTIFACTS_NAMESPACE"),
|
|
523
|
-
repo,
|
|
524
|
-
repoPrefix
|
|
525
|
-
}, {
|
|
526
|
-
binding: "WORKSPACE_ARTIFACTS",
|
|
527
|
-
namespace: "vitehub",
|
|
528
|
-
provider: "cloudflare-artifacts"
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
function resolveVercelBlobWorkspaceStore(config = {}, env = process.env) {
|
|
532
|
-
return {
|
|
533
|
-
access: config.access ?? "private",
|
|
534
|
-
prefix: trimmed(config.prefix) ?? readEnv(env, "WORKSPACE_BLOB_PREFIX", "VITEHUB_WORKSPACE_BLOB_PREFIX") ?? ".vitehub/workspaces",
|
|
535
|
-
provider: "vercel-blob",
|
|
536
|
-
token: MASKED_WORKSPACE_RUNTIME_VALUE
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
function resolveGitHubWorkspaceStore(config = {}, env = process.env, input = {}) {
|
|
540
|
-
return {
|
|
541
|
-
branch: gitHubWorkspaceOption(config.branch) ?? readEnv(env, "WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH") ?? "main",
|
|
542
|
-
provider: "github",
|
|
543
|
-
repository: gitHubWorkspaceOption(config.repository) ?? gitHubWorkspaceOption(config.repo) ?? readEnv(env, "WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY"),
|
|
544
|
-
root: gitHubWorkspaceOption(config.root) ?? readEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") ?? ".vitehub/workspaces/<workspace>",
|
|
545
|
-
token: input.runtime ? gitHubWorkspaceOption(config.token) ?? "********" : MASKED_WORKSPACE_RUNTIME_VALUE
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
function hasVercelWorkspaceBlobEnv(env) {
|
|
549
|
-
return Boolean(readEnv(env, "BLOB_READ_WRITE_TOKEN"));
|
|
550
|
-
}
|
|
551
|
-
function normalizeWorkspaceStoreOptions(store, input = {}) {
|
|
552
|
-
if (store && "readFile" in store) return;
|
|
553
|
-
if (input.dev && !store) return { provider: "local" };
|
|
554
|
-
const env = input.env || process.env;
|
|
555
|
-
const hosting = input.hosting || "";
|
|
556
|
-
if (store?.provider === "cloudflare-artifacts") return resolveCloudflareArtifactsStore(store, env);
|
|
557
|
-
if (store?.provider === "github") return resolveGitHubWorkspaceStore(store, env, input);
|
|
558
|
-
if (store?.provider === "memory") return store;
|
|
559
|
-
if (store?.provider === "vercel-blob") return resolveVercelBlobWorkspaceStore(store, env);
|
|
560
|
-
if (store?.provider === "local" || store?.root) return defu(store, { provider: "local" });
|
|
561
|
-
if (store && "provider" in store) throw workspaceError(`[vitehub] Unsupported workspace store provider: ${String(store.provider)}.`);
|
|
562
|
-
if (hosting.includes("cloudflare")) return { provider: "memory" };
|
|
563
|
-
if (hasVercelWorkspaceBlobEnv(env)) return resolveVercelBlobWorkspaceStore({}, env);
|
|
564
|
-
if (hosting.includes("vercel")) return { provider: "memory" };
|
|
565
|
-
return { provider: "local" };
|
|
566
|
-
}
|
|
567
|
-
function createWorkspaceStoreFromProvider(definition) {
|
|
568
|
-
if (definition.store && "readFile" in definition.store) return definition.store;
|
|
569
|
-
const rootDir = definition.rootDir || process.cwd();
|
|
570
|
-
const runtimeConfig = getWorkspaceRuntimeConfig();
|
|
571
|
-
const runtimeStore = runtimeConfig ? runtimeConfig.store : void 0;
|
|
572
|
-
const store = normalizeWorkspaceStoreOptions(definition.store || runtimeStore, {
|
|
573
|
-
env: typeof process !== "undefined" ? process.env : {},
|
|
574
|
-
hosting: typeof process !== "undefined" ? process.env.VITEHUB_HOSTING : void 0,
|
|
575
|
-
rootDir,
|
|
576
|
-
runtime: true
|
|
577
|
-
});
|
|
578
|
-
if (store?.provider === "memory") return createMemoryWorkspaceStore();
|
|
579
|
-
if (store?.provider === "cloudflare-artifacts" || store?.provider === "github" || store?.provider === "vercel-blob") {
|
|
580
|
-
const loader = getWorkspaceHostedStoreLoader();
|
|
581
|
-
if (!loader && store.provider === "github") return createGitHubWorkspaceStore(store, definition.name);
|
|
582
|
-
if (!loader) throw workspaceError(`[vitehub] Hosted workspace store "${store.provider}" is not available in this runtime.`);
|
|
583
|
-
return loader(store, definition.name);
|
|
584
|
-
}
|
|
585
|
-
return createLocalWorkspaceStore(store?.root ? resolve(rootDir, store.root) : runtimeConfig ? resolve(runtimeConfig.root, definition.name) : resolve(rootDir, ".vitehub/workspaces", definition.name));
|
|
586
|
-
}
|
|
587
|
-
function isMaskedWorkspaceRuntimeValue(value) {
|
|
588
|
-
return !value || value === "********";
|
|
589
|
-
}
|
|
590
|
-
function resolveRuntimeVercelBlobWorkspaceStore(config, env) {
|
|
591
|
-
const token = readEnv(env, "BLOB_READ_WRITE_TOKEN");
|
|
592
|
-
if (isMaskedWorkspaceRuntimeValue(token)) throw new Error("Missing runtime environment variable `BLOB_READ_WRITE_TOKEN` for Vercel workspace Blob storage.");
|
|
593
|
-
return {
|
|
594
|
-
...config,
|
|
595
|
-
token
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
//#endregion
|
|
599
|
-
export { resolveRuntimeVercelBlobWorkspaceStore as a, getWorkspaceHostedStoreLoader as c, setWorkspaceRuntimeConfig as d, resolveGitHubWorkspaceStore as i, setWorkspaceHostedStoreLoader as l, normalizeWorkspaceStoreOptions as n, resolveVercelBlobWorkspaceStore as o, resolveCloudflareArtifactsStore as r, createMemoryWorkspaceStore as s, createWorkspaceStoreFromProvider as t, getWorkspaceRuntimeConfig as u };
|
package/dist/publish.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { a as GitHubWorkspaceOption, ct as WorkspacePublisher } from "./types-60Yn149G.js";
|
|
2
|
-
|
|
3
|
-
//#region src/publishers/manifest.d.ts
|
|
4
|
-
interface ManifestPublisherOptions {
|
|
5
|
-
path?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function manifest(options?: ManifestPublisherOptions): WorkspacePublisher;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/publishers/github.d.ts
|
|
10
|
-
type GitHubPublisherOption = GitHubWorkspaceOption;
|
|
11
|
-
interface GitHubPublisherOptions {
|
|
12
|
-
branch?: GitHubPublisherOption;
|
|
13
|
-
deleteUntracked?: boolean;
|
|
14
|
-
message?: GitHubPublisherOption;
|
|
15
|
-
repo?: GitHubPublisherOption;
|
|
16
|
-
repository?: GitHubPublisherOption;
|
|
17
|
-
root?: GitHubPublisherOption;
|
|
18
|
-
token?: GitHubPublisherOption;
|
|
19
|
-
}
|
|
20
|
-
declare function github(options?: GitHubPublisherOptions): WorkspacePublisher;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/publishers/types.d.ts
|
|
23
|
-
interface TypesPublisherOptions {
|
|
24
|
-
path?: string;
|
|
25
|
-
}
|
|
26
|
-
declare function types(options?: TypesPublisherOptions): WorkspacePublisher;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/publishers/virtual-module.d.ts
|
|
29
|
-
interface VirtualModulePublisherOptions {
|
|
30
|
-
id: string;
|
|
31
|
-
includeContent?: boolean;
|
|
32
|
-
}
|
|
33
|
-
declare function virtualModule(options: VirtualModulePublisherOptions): WorkspacePublisher;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { type GitHubPublisherOptions, type ManifestPublisherOptions, type TypesPublisherOptions, type VirtualModulePublisherOptions, github, manifest, types, virtualModule };
|