@vite-hub/workspace 0.0.1 → 0.0.2
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/README.md +190 -17
- package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +137 -102
- package/dist/index.js +479 -594
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/nitro.d.ts +2 -31
- package/dist/nitro.js +2 -2
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
- package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
- package/dist/providers/cloudflare/artifacts-store.js +1 -383
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +1 -1
- package/dist/providers/vercel/blob-store.js +77 -18
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +2 -1
- package/dist/runtime/assets.js +5 -5
- 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 -21
- package/dist/runtime/state.js +7 -4
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +158 -62
- package/dist/asset-registry-CMuQbyvl.js +0 -14
- package/dist/cloudflare-env-DL94Uvpz.js +0 -12
- package/dist/config-CvS-7sre.js +0 -49
- package/dist/errors-BUL8SoFS.js +0 -21
- package/dist/lifecycle-uD82JeGh.js +0 -92
- package/dist/module-8LZUMEXC.js +0 -922
- package/dist/path-BVv9OXhg.js +0 -63
- package/dist/registry-Cnr0NoKv.js +0 -932
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- package/dist/sandbox-DtGXCWRq.js +0 -198
- package/dist/types-CwNcWTdt.d.ts +0 -378
- /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
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 { createGitHubWorkspaceStore } from "./providers/github/store.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
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";
|
|
5
9
|
//#region ../internal/src/env.ts
|
|
6
10
|
function trimmed(value) {
|
|
7
11
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
@@ -14,21 +18,29 @@ function readEnv(env, ...names) {
|
|
|
14
18
|
}
|
|
15
19
|
//#endregion
|
|
16
20
|
//#region src/runtime/config.ts
|
|
17
|
-
|
|
21
|
+
const workspaceRuntimeConfigKey = Symbol.for("vitehub.workspace.runtimeConfig");
|
|
22
|
+
function workspaceRuntimeConfigGlobal() {
|
|
23
|
+
const scope = globalThis;
|
|
24
|
+
scope[workspaceRuntimeConfigKey] ??= false;
|
|
25
|
+
return scope;
|
|
26
|
+
}
|
|
18
27
|
function setWorkspaceRuntimeConfig(config) {
|
|
19
|
-
|
|
28
|
+
workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] = config;
|
|
20
29
|
}
|
|
21
30
|
function getWorkspaceRuntimeConfig() {
|
|
22
|
-
return
|
|
31
|
+
return workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] ?? false;
|
|
23
32
|
}
|
|
24
33
|
//#endregion
|
|
25
34
|
//#region src/runtime/hosted-store-loader.ts
|
|
26
|
-
|
|
35
|
+
const workspaceHostedStoreLoaderKey = Symbol.for("vitehub.workspace.hostedStoreLoader");
|
|
36
|
+
function workspaceHostedStoreLoaderGlobal() {
|
|
37
|
+
return globalThis;
|
|
38
|
+
}
|
|
27
39
|
function setWorkspaceHostedStoreLoader(loader) {
|
|
28
|
-
|
|
40
|
+
workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey] = loader;
|
|
29
41
|
}
|
|
30
42
|
function getWorkspaceHostedStoreLoader() {
|
|
31
|
-
return
|
|
43
|
+
return workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey];
|
|
32
44
|
}
|
|
33
45
|
//#endregion
|
|
34
46
|
//#region src/storage/local.ts
|
|
@@ -43,7 +55,7 @@ async function walk(root, current = root) {
|
|
|
43
55
|
for (const dirent of dirents) {
|
|
44
56
|
const absolute = `${current}/${dirent.name}`;
|
|
45
57
|
const path = normalizeWorkspacePath(relative(root, absolute));
|
|
46
|
-
const { stat
|
|
58
|
+
const { stat } = await import("node:fs/promises");
|
|
47
59
|
const info = await stat(absolute).catch((error) => {
|
|
48
60
|
if (error.code === "ENOENT") return void 0;
|
|
49
61
|
throw error;
|
|
@@ -58,20 +70,27 @@ async function walk(root, current = root) {
|
|
|
58
70
|
entries.push(...await walk(root, absolute));
|
|
59
71
|
continue;
|
|
60
72
|
}
|
|
61
|
-
if (dirent.isFile()) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
digest: await sha256(bytes)
|
|
69
|
-
});
|
|
70
|
-
}
|
|
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
|
+
});
|
|
71
80
|
}
|
|
72
81
|
return entries;
|
|
73
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
|
+
}
|
|
74
92
|
var LocalWorkspaceStore = class {
|
|
93
|
+
root;
|
|
75
94
|
#baseline;
|
|
76
95
|
#files = /* @__PURE__ */ new Map();
|
|
77
96
|
#meta = /* @__PURE__ */ new Map();
|
|
@@ -101,13 +120,74 @@ var LocalWorkspaceStore = class {
|
|
|
101
120
|
const { dirname } = await import("node:path");
|
|
102
121
|
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
103
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
|
+
}
|
|
104
134
|
await mkdir(dirname(absolute), { recursive: true });
|
|
105
|
-
await writeFile(absolute,
|
|
106
|
-
this.#files.set(
|
|
135
|
+
await writeFile(absolute, bytes);
|
|
136
|
+
this.#files.set(normalized, {
|
|
107
137
|
mediaType: file.mediaType,
|
|
108
138
|
metadata: file.metadata
|
|
109
139
|
});
|
|
110
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
|
+
}
|
|
111
191
|
async list(prefix = "", options = {}) {
|
|
112
192
|
const normalizedPrefix = normalizeWorkspacePath(prefix);
|
|
113
193
|
return (await walk(this.root)).filter((entry) => {
|
|
@@ -117,7 +197,8 @@ var LocalWorkspaceStore = class {
|
|
|
117
197
|
return options.recursive || !entry.path.slice(normalizedPrefix.length + 1).includes("/");
|
|
118
198
|
}).map((entry) => ({
|
|
119
199
|
...entry,
|
|
120
|
-
mediaType: entry.type === "file" ? this.#files.get(entry.path)?.mediaType : entry.mediaType
|
|
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
|
|
121
202
|
})).sort((a, b) => a.path.localeCompare(b.path));
|
|
122
203
|
}
|
|
123
204
|
async glob(pattern, _options = {}) {
|
|
@@ -125,7 +206,7 @@ var LocalWorkspaceStore = class {
|
|
|
125
206
|
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
|
|
126
207
|
}
|
|
127
208
|
async stat(path) {
|
|
128
|
-
const {
|
|
209
|
+
const { stat } = await import("node:fs/promises");
|
|
129
210
|
const normalized = normalizeWorkspacePath(path);
|
|
130
211
|
const absolute = resolveInside(this.root, normalized);
|
|
131
212
|
const info = await stat(absolute).catch((error) => {
|
|
@@ -139,7 +220,8 @@ var LocalWorkspaceStore = class {
|
|
|
139
220
|
size: info.isFile() ? info.size : void 0,
|
|
140
221
|
mtime: info.mtimeMs,
|
|
141
222
|
mediaType: info.isFile() ? this.#files.get(normalized)?.mediaType : void 0,
|
|
142
|
-
|
|
223
|
+
metadata: info.isFile() ? this.#files.get(normalized)?.metadata : void 0,
|
|
224
|
+
digest: info.isFile() ? await fileDigest(absolute) : void 0
|
|
143
225
|
};
|
|
144
226
|
}
|
|
145
227
|
async mkdir(path, options = {}) {
|
|
@@ -183,7 +265,7 @@ var LocalWorkspaceStore = class {
|
|
|
183
265
|
type: "removed",
|
|
184
266
|
before
|
|
185
267
|
});
|
|
186
|
-
else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
|
|
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({
|
|
187
269
|
path,
|
|
188
270
|
type: "modified",
|
|
189
271
|
before,
|
|
@@ -210,6 +292,7 @@ var LocalWorkspaceStore = class {
|
|
|
210
292
|
for (const entry of await this.list("", { recursive: true })) entries[entry.path] = {
|
|
211
293
|
type: entry.type,
|
|
212
294
|
digest: entry.digest,
|
|
295
|
+
metadata: entry.metadata,
|
|
213
296
|
size: entry.size
|
|
214
297
|
};
|
|
215
298
|
return {
|
|
@@ -238,13 +321,20 @@ var LocalWorkspaceStore = class {
|
|
|
238
321
|
}
|
|
239
322
|
async #writeMeta() {
|
|
240
323
|
const { dirname } = await import("node:path");
|
|
241
|
-
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
324
|
+
const { mkdir, rename, rm, writeFile } = await import("node:fs/promises");
|
|
325
|
+
const temp = `${this.#metaPath}.${randomUUID()}.tmp`;
|
|
242
326
|
await mkdir(dirname(this.#metaPath), { recursive: true });
|
|
243
|
-
|
|
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
|
+
}
|
|
244
334
|
}
|
|
245
335
|
};
|
|
246
336
|
function createLocalWorkspaceStore(root) {
|
|
247
|
-
if (!root) throw
|
|
337
|
+
if (!root) throw workspaceError("[vitehub] Local workspace store requires a root directory.");
|
|
248
338
|
return new LocalWorkspaceStore(root);
|
|
249
339
|
}
|
|
250
340
|
//#endregion
|
|
@@ -315,10 +405,10 @@ var MemoryWorkspaceStore = class {
|
|
|
315
405
|
const node = this.#nodes.get(normalized);
|
|
316
406
|
if (!node) {
|
|
317
407
|
if (options.force) return;
|
|
318
|
-
throw
|
|
408
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
319
409
|
}
|
|
320
410
|
if (node.type === "directory" && !options.recursive) {
|
|
321
|
-
for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw
|
|
411
|
+
for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
322
412
|
}
|
|
323
413
|
for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
|
|
324
414
|
}
|
|
@@ -345,7 +435,7 @@ var MemoryWorkspaceStore = class {
|
|
|
345
435
|
type: "removed",
|
|
346
436
|
before
|
|
347
437
|
});
|
|
348
|
-
else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
|
|
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({
|
|
349
439
|
path,
|
|
350
440
|
type: "modified",
|
|
351
441
|
before,
|
|
@@ -383,6 +473,7 @@ var MemoryWorkspaceStore = class {
|
|
|
383
473
|
size,
|
|
384
474
|
mtime: node.mtime,
|
|
385
475
|
mediaType: node.mediaType,
|
|
476
|
+
metadata: node.metadata,
|
|
386
477
|
digest: node.type === "file" ? await sha256(content) : void 0
|
|
387
478
|
};
|
|
388
479
|
}
|
|
@@ -394,6 +485,7 @@ var MemoryWorkspaceStore = class {
|
|
|
394
485
|
entries[path] = {
|
|
395
486
|
type: entry.type,
|
|
396
487
|
digest: entry.digest,
|
|
488
|
+
metadata: entry.metadata,
|
|
397
489
|
size: entry.size
|
|
398
490
|
};
|
|
399
491
|
}
|
|
@@ -418,6 +510,9 @@ const MASKED_WORKSPACE_RUNTIME_VALUE = "********";
|
|
|
418
510
|
function workspaceRepoName(name) {
|
|
419
511
|
return name ? name.replace(/[^a-zA-Z0-9_.-]/g, "-") : void 0;
|
|
420
512
|
}
|
|
513
|
+
function gitHubWorkspaceOption(value) {
|
|
514
|
+
return typeof value === "function" ? value : trimmed(value);
|
|
515
|
+
}
|
|
421
516
|
function resolveCloudflareArtifactsStore(config = {}, env = process.env) {
|
|
422
517
|
const repoPrefix = trimmed(config.repoPrefix) ?? readEnv(env, "WORKSPACE_ARTIFACTS_REPO_PREFIX", "VITEHUB_WORKSPACE_ARTIFACTS_REPO_PREFIX") ?? "vitehub-workspace-";
|
|
423
518
|
const repo = trimmed(config.repo) ?? workspaceRepoName(readEnv(env, "WORKSPACE_ARTIFACTS_REPO", "VITEHUB_WORKSPACE_ARTIFACTS_REPO"));
|
|
@@ -429,7 +524,6 @@ function resolveCloudflareArtifactsStore(config = {}, env = process.env) {
|
|
|
429
524
|
repoPrefix
|
|
430
525
|
}, {
|
|
431
526
|
binding: "WORKSPACE_ARTIFACTS",
|
|
432
|
-
branch: "main",
|
|
433
527
|
namespace: "vitehub",
|
|
434
528
|
provider: "cloudflare-artifacts"
|
|
435
529
|
});
|
|
@@ -442,6 +536,15 @@ function resolveVercelBlobWorkspaceStore(config = {}, env = process.env) {
|
|
|
442
536
|
token: MASKED_WORKSPACE_RUNTIME_VALUE
|
|
443
537
|
};
|
|
444
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
|
+
}
|
|
445
548
|
function hasVercelWorkspaceBlobEnv(env) {
|
|
446
549
|
return Boolean(readEnv(env, "BLOB_READ_WRITE_TOKEN"));
|
|
447
550
|
}
|
|
@@ -451,10 +554,11 @@ function normalizeWorkspaceStoreOptions(store, input = {}) {
|
|
|
451
554
|
const env = input.env || process.env;
|
|
452
555
|
const hosting = input.hosting || "";
|
|
453
556
|
if (store?.provider === "cloudflare-artifacts") return resolveCloudflareArtifactsStore(store, env);
|
|
557
|
+
if (store?.provider === "github") return resolveGitHubWorkspaceStore(store, env, input);
|
|
454
558
|
if (store?.provider === "memory") return store;
|
|
455
559
|
if (store?.provider === "vercel-blob") return resolveVercelBlobWorkspaceStore(store, env);
|
|
456
560
|
if (store?.provider === "local" || store?.root) return defu(store, { provider: "local" });
|
|
457
|
-
if (store && "provider" in store) throw
|
|
561
|
+
if (store && "provider" in store) throw workspaceError(`[vitehub] Unsupported workspace store provider: ${String(store.provider)}.`);
|
|
458
562
|
if (hosting.includes("cloudflare")) return { provider: "memory" };
|
|
459
563
|
if (hasVercelWorkspaceBlobEnv(env)) return resolveVercelBlobWorkspaceStore({}, env);
|
|
460
564
|
if (hosting.includes("vercel")) return { provider: "memory" };
|
|
@@ -467,14 +571,15 @@ function createWorkspaceStoreFromProvider(definition) {
|
|
|
467
571
|
const runtimeStore = runtimeConfig ? runtimeConfig.store : void 0;
|
|
468
572
|
const store = normalizeWorkspaceStoreOptions(definition.store || runtimeStore, {
|
|
469
573
|
env: typeof process !== "undefined" ? process.env : {},
|
|
470
|
-
hosting: typeof process !== "undefined" ? process.env.VITEHUB_HOSTING
|
|
574
|
+
hosting: typeof process !== "undefined" ? process.env.VITEHUB_HOSTING : void 0,
|
|
471
575
|
rootDir,
|
|
472
576
|
runtime: true
|
|
473
577
|
});
|
|
474
578
|
if (store?.provider === "memory") return createMemoryWorkspaceStore();
|
|
475
|
-
if (store?.provider === "cloudflare-artifacts" || store?.provider === "vercel-blob") {
|
|
579
|
+
if (store?.provider === "cloudflare-artifacts" || store?.provider === "github" || store?.provider === "vercel-blob") {
|
|
476
580
|
const loader = getWorkspaceHostedStoreLoader();
|
|
477
|
-
if (!loader
|
|
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.`);
|
|
478
583
|
return loader(store, definition.name);
|
|
479
584
|
}
|
|
480
585
|
return createLocalWorkspaceStore(store?.root ? resolve(rootDir, store.root) : runtimeConfig ? resolve(runtimeConfig.root, definition.name) : resolve(rootDir, ".vitehub/workspaces", definition.name));
|
|
@@ -491,4 +596,4 @@ function resolveRuntimeVercelBlobWorkspaceStore(config, env) {
|
|
|
491
596
|
};
|
|
492
597
|
}
|
|
493
598
|
//#endregion
|
|
494
|
-
export {
|
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Zt as WorkspaceStore, t as CloudflareArtifactsWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/cloudflare/artifacts-store.d.ts
|
|
4
4
|
declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|