@vite-hub/workspace 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +48 -2
- package/dist/{ai-Cztw4eLk.js → ai-BqCC8BpY.js} +15 -4
- package/dist/{ai-hFdsvDHC.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 +4 -2
- package/dist/cloudflare.js +1 -2
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config--r5unwPc.js → config-Bc3c4Su1.js} +213 -120
- package/dist/{config-DCQ6y30R.js → config-CHLLWklZ.js} +9 -3
- package/dist/{config-Ca5DM8fF.d.ts → config-DE9xlaIw.d.ts} +1 -1
- package/dist/{file-B2q9NE18.js → file-Bc1X7pco.js} +9 -10
- package/dist/{files-xy0le-_U.js → files-Q6xZjDHA.js} +20 -9
- package/dist/{github-lIO6-2sH.js → github-DHnjxQIX.js} +27 -23
- package/dist/glob-CEZKeZFC.js +18 -0
- package/dist/host-DJH8cuoU.js +1030 -0
- package/dist/{artifacts-store-BAV9jZpd.js → hosted-RPeJOCFz.js} +146 -30
- 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 -25
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -29
- package/dist/index.d.ts +61 -78
- package/dist/index.js +133 -435
- 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 +10 -0
- package/dist/mountx.js +143 -0
- 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-CeQciesl.js → provider-B1yLjCJJ.js} +194 -47
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -361
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +2 -2
- package/dist/registry-D3yzt8HQ.js +127 -0
- package/dist/{registry-CoC9JxVt.d.ts → registry-Uj6IVxes.d.ts} +3 -3
- package/dist/{request-execution-C8qRcReq.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-options-BsPSv5O7.js +13 -0
- package/dist/runtime-type-iEE6BjQJ.js +34 -0
- package/dist/runtime.d.ts +42 -7
- package/dist/runtime.js +276 -100
- package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +24 -51
- package/dist/{shared-BRycRSbo.js → shared-DTR1Hhma.js} +115 -39
- package/dist/source-metadata.d.ts +9 -2
- package/dist/source-metadata.js +34 -2
- package/dist/{state-DSAHEsq6.d.ts → state-tYcRWEh2.d.ts} +13 -12
- package/dist/store-Dt_Jyys3.js +608 -0
- package/dist/{sync-DO42ypji.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-DHkae7Cb.d.ts → types-CYuwjJ4V.d.ts} +94 -43
- package/dist/{use-d_PlAdOu.js → use-BTNDR5Rd.js} +147 -50
- package/dist/{use-D16tf8Ph.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-n4wBmdaM.js → workspace-Dq08Yn72.js} +224 -545
- package/dist/{workspace-f2DBLmPZ.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
- package/package.json +20 -38
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/cli.d.ts +0 -31
- package/dist/cli.js +0 -303
- package/dist/cloudflare-env-CKxUs2fa.js +0 -20
- package/dist/glob-DeH0dzZX.js +0 -23
- package/dist/host-I-_vDs05.js +0 -370
- package/dist/lifecycle-Lhk3dAMt.js +0 -176
- package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
- package/dist/providers/cloudflare/artifacts-store.js +0 -2
- package/dist/providers/vercel/blob-store.d.ts +0 -6
- package/dist/providers/vercel/blob-store.js +0 -235
- package/dist/registry-C7DMdBXN.js +0 -74
- package/dist/utils-BPdaCyI6.js +0 -55
- package/dist/vite-NWC9mFjI.js +0 -1882
package/dist/server.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { o as matchesAny, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
|
+
import { d as resolveWorkspaceAutoCommit } from "./workspace-Dq08Yn72.js";
|
|
3
|
+
import { r as withWorkspaceProgress } from "./host-DJH8cuoU.js";
|
|
4
|
+
import { t as useWorkspace } from "./use-BTNDR5Rd.js";
|
|
4
5
|
import { getWorkspaceCollectionItem, queryWorkspaceCollection, workspaceCollectionEmpty } from "./collections.js";
|
|
5
6
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
6
|
-
import { createError, defineEventHandler, getQuery, getRouterParam } from "h3";
|
|
7
7
|
import { lookup } from "mrmime";
|
|
8
|
+
import { createError, defineEventHandler, getQuery, getRouterParam } from "h3";
|
|
8
9
|
//#region src/server.ts
|
|
9
10
|
const workspaceDevRoute = "/__vitehub/workspace/dev";
|
|
10
11
|
const workspaceDevHeader = "x-vitehub-workspace-dev";
|
|
@@ -33,8 +34,7 @@ async function workspaceDevTokenRoot(rootDir, options = {}) {
|
|
|
33
34
|
const serverKey = createHash("sha256").update(options.serverId || "default").digest("hex");
|
|
34
35
|
return {
|
|
35
36
|
file: join(tmpdir(), "vitehub-workspace-dev", rootKey, serverKey, "dev-token"),
|
|
36
|
-
key: `${rootKey}:${serverKey}
|
|
37
|
-
legacyFile: join(resolvedRoot, ".vitehub", "dev-token")
|
|
37
|
+
key: `${rootKey}:${serverKey}`
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
function headerValue(headers, name) {
|
|
@@ -49,13 +49,12 @@ async function refreshWorkspaceDevToken(rootDir, options = {}) {
|
|
|
49
49
|
const token = randomToken();
|
|
50
50
|
const tokenRoot = await workspaceDevTokenRoot(rootDir, options);
|
|
51
51
|
workspaceDevTokens().set(tokenRoot.key, token);
|
|
52
|
-
const [{ mkdir,
|
|
52
|
+
const [{ mkdir, writeFile }, { dirname }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
53
53
|
const file = tokenRoot.file;
|
|
54
54
|
await mkdir(dirname(file), {
|
|
55
55
|
mode: 448,
|
|
56
56
|
recursive: true
|
|
57
57
|
});
|
|
58
|
-
await rm(tokenRoot.legacyFile, { force: true });
|
|
59
58
|
await writeFile(file, `${token}\n`, { mode: 384 });
|
|
60
59
|
return token;
|
|
61
60
|
}
|
|
@@ -159,45 +158,11 @@ function workspaceSessionStarter(input) {
|
|
|
159
158
|
function workspaceSourceMaterializer(input) {
|
|
160
159
|
return input && typeof input === "object" && typeof input.materializeSources === "function" ? input.materializeSources.bind(input) : void 0;
|
|
161
160
|
}
|
|
162
|
-
async function withWorkspaceDevProgress(onProgress, event, fn) {
|
|
163
|
-
const startedAt = Date.now();
|
|
164
|
-
await onProgress?.({
|
|
165
|
-
data: event.data,
|
|
166
|
-
id: event.id,
|
|
167
|
-
label: event.label,
|
|
168
|
-
status: "started"
|
|
169
|
-
});
|
|
170
|
-
try {
|
|
171
|
-
const result = await fn();
|
|
172
|
-
await onProgress?.({
|
|
173
|
-
data: event.data,
|
|
174
|
-
durationMs: Date.now() - startedAt,
|
|
175
|
-
id: event.id,
|
|
176
|
-
label: event.label,
|
|
177
|
-
status: "completed"
|
|
178
|
-
});
|
|
179
|
-
return result;
|
|
180
|
-
} catch (error) {
|
|
181
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
-
await onProgress?.({
|
|
183
|
-
data: {
|
|
184
|
-
...event.data,
|
|
185
|
-
error: message
|
|
186
|
-
},
|
|
187
|
-
durationMs: Date.now() - startedAt,
|
|
188
|
-
error: message,
|
|
189
|
-
id: event.id,
|
|
190
|
-
label: event.label,
|
|
191
|
-
status: "failed"
|
|
192
|
-
});
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
161
|
async function materializeWorkspaceDevSources(workspace, input) {
|
|
197
162
|
const materialize = workspaceSourceMaterializer(workspace) ?? workspaceSourceMaterializer(workspace.fs);
|
|
198
163
|
if (!materialize) return;
|
|
199
164
|
const paths = input.paths?.length ? input.paths : [""];
|
|
200
|
-
await
|
|
165
|
+
await withWorkspaceProgress(input.onProgress, {
|
|
201
166
|
data: { paths },
|
|
202
167
|
id: "workspace.dev.materialize",
|
|
203
168
|
label: "Materializing workspace sources"
|
|
@@ -320,20 +285,26 @@ async function runWorkspaceDevCommand(input) {
|
|
|
320
285
|
const startSession = starter?.startSession.bind(starter);
|
|
321
286
|
if (!startSession) throw new Error("Workspace Dev command requires a Workspace Session.");
|
|
322
287
|
await materializeWorkspaceDevSources(workspace, input);
|
|
323
|
-
|
|
324
|
-
data: { paths: input.paths ?? null },
|
|
325
|
-
id: "workspace.dev.start-session",
|
|
326
|
-
label: "Starting workspace session"
|
|
327
|
-
}, async () => await startSession({
|
|
328
|
-
host: input.host,
|
|
329
|
-
paths: input.paths
|
|
330
|
-
}));
|
|
288
|
+
let session;
|
|
331
289
|
const execOptions = {
|
|
332
290
|
abortSignal: input.abortSignal,
|
|
333
291
|
timeout: input.timeout
|
|
334
292
|
};
|
|
335
293
|
let result;
|
|
336
294
|
try {
|
|
295
|
+
await withWorkspaceProgress(input.onProgress, {
|
|
296
|
+
data: { paths: input.paths ?? null },
|
|
297
|
+
id: "workspace.dev.start-session",
|
|
298
|
+
label: "Starting workspace session"
|
|
299
|
+
}, async () => {
|
|
300
|
+
session = await startSession({
|
|
301
|
+
abortSignal: input.abortSignal,
|
|
302
|
+
host: input.host,
|
|
303
|
+
paths: input.paths
|
|
304
|
+
});
|
|
305
|
+
return session;
|
|
306
|
+
});
|
|
307
|
+
if (!session) throw new Error("Workspace Dev Session did not start.");
|
|
337
308
|
result = input.args ? await session.exec(command, input.args, execOptions) : await session.exec("sh", ["-lc", command], execOptions);
|
|
338
309
|
const diff = result.exitCode === 0 ? await session.diff() : void 0;
|
|
339
310
|
if (diff?.entries.length) {
|
|
@@ -341,6 +312,7 @@ async function runWorkspaceDevCommand(input) {
|
|
|
341
312
|
if (!definition || !hasWorkspaceCommitRules(definition) || commit) await session.commit({ message: commit?.message || "workspace dev command" });
|
|
342
313
|
}
|
|
343
314
|
} catch (error) {
|
|
315
|
+
if (!session) throw error;
|
|
344
316
|
try {
|
|
345
317
|
await session.close();
|
|
346
318
|
} catch (closeError) {
|
|
@@ -348,6 +320,7 @@ async function runWorkspaceDevCommand(input) {
|
|
|
348
320
|
}
|
|
349
321
|
throw error;
|
|
350
322
|
}
|
|
323
|
+
if (!session) throw new Error("Workspace Dev Session did not start.");
|
|
351
324
|
await session.close();
|
|
352
325
|
return result;
|
|
353
326
|
}
|
|
@@ -1,6 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ as workspaceError, l as normalizeWorkspacePath, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
4
|
+
let activeEnv;
|
|
5
|
+
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
6
|
+
const runtimeGlobal = globalThis;
|
|
7
|
+
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
8
|
+
function setActiveCloudflareEnv(env) {
|
|
9
|
+
activeEnv = env;
|
|
10
|
+
globalThis.__env__ = env;
|
|
11
|
+
try {
|
|
12
|
+
activeEnvStorage.enterWith({ env });
|
|
13
|
+
} catch {}
|
|
14
|
+
}
|
|
15
|
+
function getActiveCloudflareEnv() {
|
|
16
|
+
const scoped = activeEnvStorage.getStore();
|
|
17
|
+
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
18
|
+
}
|
|
19
|
+
function getActiveCloudflareBinding(name) {
|
|
20
|
+
return getActiveCloudflareEnv()?.[name];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
3
23
|
//#region src/providers/github/shared.ts
|
|
24
|
+
const githubReadAttempts = 3;
|
|
25
|
+
function retryDelay(response, attempt) {
|
|
26
|
+
const retryAfter = response.headers.get("retry-after");
|
|
27
|
+
if (retryAfter) {
|
|
28
|
+
const seconds = Number(retryAfter);
|
|
29
|
+
if (Number.isFinite(seconds)) return Math.min(seconds * 1e3, 2e3);
|
|
30
|
+
const date = Date.parse(retryAfter);
|
|
31
|
+
if (Number.isFinite(date)) return Math.min(Math.max(date - Date.now(), 0), 2e3);
|
|
32
|
+
}
|
|
33
|
+
return 100 * 2 ** attempt;
|
|
34
|
+
}
|
|
35
|
+
function retryableGitHubRead(response) {
|
|
36
|
+
return response.status === 429 || response.status >= 500;
|
|
37
|
+
}
|
|
38
|
+
async function waitForRetry(delay, signal) {
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
const aborted = () => {
|
|
42
|
+
clearTimeout(timeout);
|
|
43
|
+
reject(signal?.reason || new DOMException("The operation was aborted.", "AbortError"));
|
|
44
|
+
};
|
|
45
|
+
const timeout = setTimeout(() => {
|
|
46
|
+
signal?.removeEventListener("abort", aborted);
|
|
47
|
+
resolve();
|
|
48
|
+
}, delay);
|
|
49
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function requestGitHub(input, init = {}) {
|
|
53
|
+
const method = (init.method || "GET").toUpperCase();
|
|
54
|
+
const retryable = method === "GET" || method === "HEAD";
|
|
55
|
+
for (let attempt = 0;; attempt++) {
|
|
56
|
+
init.signal?.throwIfAborted();
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await fetch(input, init);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (!retryable || init.signal?.aborted || attempt + 1 >= githubReadAttempts) throw error;
|
|
62
|
+
await waitForRetry(100 * 2 ** attempt, init.signal || void 0);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!retryable || !retryableGitHubRead(response) || attempt + 1 >= githubReadAttempts) return response;
|
|
66
|
+
await response.body?.cancel().catch(() => void 0);
|
|
67
|
+
await waitForRetry(retryDelay(response, attempt), init.signal || void 0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
4
70
|
var GitHubRequestError = class extends Error {
|
|
5
71
|
status;
|
|
6
72
|
constructor(message, status) {
|
|
@@ -16,11 +82,15 @@ function processEnv(env, ...keys) {
|
|
|
16
82
|
return keys.map((key) => env[key]).find((value) => typeof value === "string" && value.length > 0);
|
|
17
83
|
}
|
|
18
84
|
function resolveGitHubOption(value) {
|
|
19
|
-
|
|
85
|
+
const resolved = typeof value === "function" ? value() : value;
|
|
86
|
+
return typeof resolved === "string" ? resolved.trim() || void 0 : resolved;
|
|
20
87
|
}
|
|
21
88
|
function isMaskedGitHubTokenOption(value) {
|
|
22
89
|
return value === "********" || value === "<redacted>" || value === "[redacted]";
|
|
23
90
|
}
|
|
91
|
+
function activeCloudflareEnv(keys, accept = () => true) {
|
|
92
|
+
return keys.map((key) => getActiveCloudflareBinding(key)).map((value) => typeof value === "string" ? value.trim() : void 0).find((value) => typeof value === "string" && value.length > 0 && accept(value));
|
|
93
|
+
}
|
|
24
94
|
function requireGitHubOption(kind, label, value) {
|
|
25
95
|
if (!value) throw workspaceError(`[vitehub] GitHub workspace ${kind} requires ${label}.`);
|
|
26
96
|
return value;
|
|
@@ -37,7 +107,10 @@ function joinGitPath(...parts) {
|
|
|
37
107
|
return parts.join("/").replaceAll("\\", "/").split("/").filter(Boolean).join("/");
|
|
38
108
|
}
|
|
39
109
|
function resolveGitHubWorkspaceRoot(root, workspaceName) {
|
|
40
|
-
return joinGitPath(root.replaceAll("<workspace>", workspaceName))
|
|
110
|
+
return normalizeSafeWorkspacePath(joinGitPath(root.replaceAll("<workspace>", workspaceName)), {
|
|
111
|
+
allowEmpty: true,
|
|
112
|
+
allowReserved: true
|
|
113
|
+
});
|
|
41
114
|
}
|
|
42
115
|
function workspacePathFromGitPath(path, root) {
|
|
43
116
|
const normalized = joinGitPath(path);
|
|
@@ -65,33 +138,37 @@ function toBase64(bytes) {
|
|
|
65
138
|
const encode = globalThis.btoa;
|
|
66
139
|
return encode ? encode(binary) : Buffer.from(bytes).toString("base64");
|
|
67
140
|
}
|
|
68
|
-
function fromBase64(input) {
|
|
69
|
-
const normalized = input.replace(/\s/g, "");
|
|
70
|
-
const decode = globalThis.atob;
|
|
71
|
-
if (!decode) return new Uint8Array(Buffer.from(normalized, "base64"));
|
|
72
|
-
const binary = decode(normalized);
|
|
73
|
-
const bytes = new Uint8Array(binary.length);
|
|
74
|
-
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
75
|
-
return bytes;
|
|
76
|
-
}
|
|
77
141
|
function resolveGitHubRepositoryOption(options, env = typeof process !== "undefined" ? process.env : {}) {
|
|
78
|
-
return resolveGitHubOption(options.repository) || resolveGitHubOption(options.repo) ||
|
|
142
|
+
return resolveGitHubOption(options.repository) || resolveGitHubOption(options.repo) || activeCloudflareEnv([
|
|
143
|
+
"WORKSPACE_GITHUB_REPOSITORY",
|
|
144
|
+
"VITEHUB_WORKSPACE_GITHUB_REPOSITORY",
|
|
145
|
+
"GITHUB_REPOSITORY"
|
|
146
|
+
]) || processEnv(env, "WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY");
|
|
79
147
|
}
|
|
80
148
|
function resolveGitHubBranchOption(options, env = typeof process !== "undefined" ? process.env : {}) {
|
|
81
|
-
return resolveGitHubOption(options.branch) ||
|
|
149
|
+
return resolveGitHubOption(options.branch) || activeCloudflareEnv([
|
|
150
|
+
"WORKSPACE_GITHUB_BRANCH",
|
|
151
|
+
"VITEHUB_WORKSPACE_GITHUB_BRANCH",
|
|
152
|
+
"GITHUB_BRANCH"
|
|
153
|
+
]) || processEnv(env, "WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH") || "main";
|
|
82
154
|
}
|
|
83
155
|
function resolveGitHubRootOption(options, workspaceName, env = typeof process !== "undefined" ? process.env : {}) {
|
|
84
|
-
return resolveGitHubWorkspaceRoot(resolveGitHubOption(options.root) || processEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") || ".vitehub/workspaces/<workspace>", workspaceName);
|
|
156
|
+
return resolveGitHubWorkspaceRoot(resolveGitHubOption(options.root) || activeCloudflareEnv(["WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT"]) || processEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") || ".vitehub/workspaces/<workspace>", workspaceName);
|
|
85
157
|
}
|
|
86
158
|
function resolveGitHubTokenOption(options, env = typeof process !== "undefined" ? process.env : {}) {
|
|
87
159
|
const token = resolveGitHubOption(options.token);
|
|
88
160
|
if (token && !isMaskedGitHubTokenOption(token)) return token;
|
|
89
|
-
const bindingToken =
|
|
90
|
-
|
|
161
|
+
const bindingToken = activeCloudflareEnv([
|
|
162
|
+
"WORKSPACE_GITHUB_TOKEN",
|
|
163
|
+
"VITEHUB_WORKSPACE_GITHUB_TOKEN",
|
|
164
|
+
"GITHUB_TOKEN",
|
|
165
|
+
"GH_TOKEN"
|
|
166
|
+
], (value) => !isMaskedGitHubTokenOption(value));
|
|
167
|
+
if (bindingToken) return bindingToken;
|
|
91
168
|
return processEnv(env, "WORKSPACE_GITHUB_TOKEN", "VITEHUB_WORKSPACE_GITHUB_TOKEN", "GITHUB_TOKEN", "GH_TOKEN");
|
|
92
169
|
}
|
|
93
170
|
async function requestGitHubJson(repository, token, path, init) {
|
|
94
|
-
const response = await
|
|
171
|
+
const response = await requestGitHub(`https://api.github.com${path}`, {
|
|
95
172
|
...init,
|
|
96
173
|
headers: {
|
|
97
174
|
accept: "application/vnd.github+json",
|
|
@@ -105,23 +182,26 @@ async function requestGitHubJson(repository, token, path, init) {
|
|
|
105
182
|
if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace request failed for ${repository}: ${response.status} ${response.statusText} ${await response.text().catch(() => "")}`, response.status) });
|
|
106
183
|
return await response.json();
|
|
107
184
|
}
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
110
|
-
|
|
185
|
+
async function readGitHubRawFile(input) {
|
|
186
|
+
const { owner, repo } = splitGitHubRepository(input.repository, "store");
|
|
187
|
+
const path = input.path.split("/").map(encodeURIComponent).join("/");
|
|
188
|
+
const response = await requestGitHub(`https://raw.githubusercontent.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${encodeURIComponent(input.ref)}/${path}`, { headers: {
|
|
189
|
+
authorization: `Bearer ${input.token}`,
|
|
190
|
+
"user-agent": "vitehub-workspace"
|
|
191
|
+
} });
|
|
192
|
+
if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace raw file request failed for ${input.repository}: ${response.status} ${response.statusText}`, response.status) });
|
|
193
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
194
|
+
}
|
|
195
|
+
async function readGitHubArchive(input) {
|
|
196
|
+
const { owner, repo } = splitGitHubRepository(input.repository, "store");
|
|
197
|
+
const response = await requestGitHub(`https://codeload.github.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/tar.gz/${encodeURIComponent(input.ref)}`, {
|
|
111
198
|
headers: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
...init?.headers
|
|
117
|
-
}
|
|
199
|
+
authorization: `Bearer ${input.token}`,
|
|
200
|
+
"user-agent": "vitehub-workspace"
|
|
201
|
+
},
|
|
202
|
+
signal: input.signal
|
|
118
203
|
});
|
|
119
|
-
if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace request failed for ${repository}: ${response.status} ${response.statusText}
|
|
120
|
-
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
121
|
-
const blob = await response.json();
|
|
122
|
-
if (blob.encoding === "base64" && typeof blob.content === "string") return fromBase64(blob.content);
|
|
123
|
-
throw workspaceError(`[vitehub] GitHub workspace request for ${repository} returned unsupported byte response.`);
|
|
124
|
-
}
|
|
204
|
+
if (!response.ok) throw workspaceError("[vitehub] GitHub workspace request failed.", { cause: new GitHubRequestError(`[vitehub] GitHub workspace archive request failed for ${input.repository}: ${response.status} ${response.statusText}`, response.status) });
|
|
125
205
|
return new Uint8Array(await response.arrayBuffer());
|
|
126
206
|
}
|
|
127
207
|
function findGitHubRemoteFiles(tree, root, kind) {
|
|
@@ -175,10 +255,6 @@ async function readGitHubBranchState(input) {
|
|
|
175
255
|
treeSha: current.tree.sha
|
|
176
256
|
};
|
|
177
257
|
}
|
|
178
|
-
async function readGitHubBlob(input) {
|
|
179
|
-
const { owner, repo } = splitGitHubRepository(input.repository, input.kind);
|
|
180
|
-
return await requestGitHubBytes(input.repository, input.token, `/repos/${owner}/${repo}/git/blobs/${input.sha}`);
|
|
181
|
-
}
|
|
182
258
|
async function commitGitHubChanges(input) {
|
|
183
259
|
const kind = input.kind || "store";
|
|
184
260
|
const { owner, repo } = splitGitHubRepository(input.repository, kind);
|
|
@@ -252,4 +328,4 @@ async function createGitHubFileUpdate(path, root, content) {
|
|
|
252
328
|
};
|
|
253
329
|
}
|
|
254
330
|
//#endregion
|
|
255
|
-
export { isWorkspaceFileEntry as a,
|
|
331
|
+
export { getActiveCloudflareBinding as _, isWorkspaceFileEntry as a, readGitHubArchive as c, requireGitHubOption as d, resolveGitHubBranchOption as f, resolveGitHubTokenOption as g, resolveGitHubRootOption as h, gitBlobSha as i, readGitHubBranchState as l, resolveGitHubRepositoryOption as m, createGitHubBlob as n, joinGitPath as o, resolveGitHubOption as p, createGitHubFileUpdate as r, processEnv as s, commitGitHubChanges as t, readGitHubRawFile as u, setActiveCloudflareEnv as v };
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { jt as WorkspaceSourceMaterializationStatus, z as WorkspaceEntry } from "./types-CYuwjJ4V.js";
|
|
2
|
+
import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-DE9xlaIw.js";
|
|
3
|
+
|
|
4
|
+
//#region src/source-metadata.d.ts
|
|
5
|
+
declare function listMaterializedWorkspaceEntries(workspace: unknown): Promise<WorkspaceEntry[] | undefined>;
|
|
6
|
+
declare function listMaterializedWorkspaceSourceEntries(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceEntry[] | undefined>;
|
|
7
|
+
declare function readWorkspaceSourceMaterializationStatus(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceSourceMaterializationStatus | undefined>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type WorkspaceSourceMetadata, listMaterializedWorkspaceEntries, listMaterializedWorkspaceSourceEntries, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, readWorkspaceSourceMaterializationStatus, workspaceSourceGrantPaths };
|
package/dist/source-metadata.js
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config
|
|
2
|
-
|
|
1
|
+
import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config-Bc3c4Su1.js";
|
|
2
|
+
import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
|
|
3
|
+
import { c as readCurrentSourceSnapshot, n as resolveWorkspaceMetadataTarget } from "./metadata-target-B0tOmVW7.js";
|
|
4
|
+
//#region src/source-metadata.ts
|
|
5
|
+
async function listMaterializedWorkspaceEntries(workspace) {
|
|
6
|
+
return await (await resolveWorkspaceMetadataTarget(workspace))?.list?.("", { recursive: true });
|
|
7
|
+
}
|
|
8
|
+
async function listMaterializedWorkspaceSourceEntries(workspace, source) {
|
|
9
|
+
const metadata = await resolveWorkspaceMetadataTarget(workspace);
|
|
10
|
+
if (!metadata?.list) return;
|
|
11
|
+
const snapshot = await readCurrentSourceSnapshot(metadata, source);
|
|
12
|
+
if (!snapshot) return [];
|
|
13
|
+
const ownedPaths = new Set(Object.keys(snapshot.items || {}));
|
|
14
|
+
return (await metadata.list("", { recursive: true })).filter((entry) => {
|
|
15
|
+
if (entry.type === "file") return ownedPaths.has(entry.path);
|
|
16
|
+
return [...ownedPaths].some((path) => path.startsWith(`${entry.path}/`));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function readWorkspaceSourceMaterializationStatus(workspace, source) {
|
|
20
|
+
const metadata = await resolveWorkspaceMetadataTarget(workspace);
|
|
21
|
+
if (!metadata) return;
|
|
22
|
+
const snapshot = await readCurrentSourceSnapshot(metadata, source);
|
|
23
|
+
if (!hasRuntimeType(snapshot, "object") || snapshot === null) return;
|
|
24
|
+
const status = snapshot.status;
|
|
25
|
+
if (status !== "lazy" && status !== "updating" && status !== "ready" && status !== "error") return;
|
|
26
|
+
return {
|
|
27
|
+
materializedAt: hasRuntimeType(snapshot.materializedAt, "string") ? snapshot.materializedAt : void 0,
|
|
28
|
+
mountPath: hasRuntimeType(snapshot.mountPath, "string") ? snapshot.mountPath : "",
|
|
29
|
+
source: hasRuntimeType(snapshot.source, "string") ? snapshot.source : source.key,
|
|
30
|
+
status
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { listMaterializedWorkspaceEntries, listMaterializedWorkspaceSourceEntries, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, readWorkspaceSourceMaterializationStatus, workspaceSourceGrantPaths };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as WorkspaceRegistry } from "./registry-
|
|
1
|
+
import { $t as WorkspaceStore, O as WorkspaceAssetsRegistry, o as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions, w as VercelBlobWorkspaceStoreOptions } from "./types-CYuwjJ4V.js";
|
|
2
|
+
import { t as WorkspaceRegistry } from "./registry-Uj6IVxes.js";
|
|
3
3
|
|
|
4
|
-
//#region src/runtime/
|
|
5
|
-
|
|
6
|
-
declare function
|
|
4
|
+
//#region ../internal/src/runtime/cloudflare-env.d.ts
|
|
5
|
+
type CloudflareWorkerEnv = Record<string, unknown>;
|
|
6
|
+
declare function setActiveCloudflareEnv(env: CloudflareWorkerEnv | undefined): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/core/workspace-cache.d.ts
|
|
9
|
+
declare function resetWorkspaceStoreCache(): void;
|
|
7
10
|
//#endregion
|
|
8
11
|
//#region src/runtime/hosted-store-loader.d.ts
|
|
9
12
|
type HostedWorkspaceStoreOptions = CloudflareArtifactsWorkspaceStoreOptions | GitHubWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions;
|
|
@@ -11,15 +14,13 @@ type WorkspaceHostedStoreLoader = (options: HostedWorkspaceStoreOptions, workspa
|
|
|
11
14
|
declare function setWorkspaceHostedStoreLoader(loader: WorkspaceHostedStoreLoader | undefined): void;
|
|
12
15
|
declare function getWorkspaceHostedStoreLoader(): WorkspaceHostedStoreLoader | undefined;
|
|
13
16
|
//#endregion
|
|
14
|
-
//#region
|
|
15
|
-
|
|
16
|
-
declare function
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/core/workspace-cache.d.ts
|
|
19
|
-
declare function resetWorkspaceStoreCache(): void;
|
|
17
|
+
//#region src/runtime/config.d.ts
|
|
18
|
+
declare function setWorkspaceRuntimeConfig(config: false | ResolvedWorkspaceModuleOptions): void;
|
|
19
|
+
declare function getWorkspaceRuntimeConfig(): false | ResolvedWorkspaceModuleOptions;
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/runtime/state.d.ts
|
|
22
|
+
declare function invalidateWorkspaceStore(name: string): Promise<void>;
|
|
22
23
|
declare function setWorkspaceRuntimeRegistry(registry: WorkspaceRegistry): void;
|
|
23
24
|
declare function setWorkspaceRuntimeAssetsRegistry(registry: WorkspaceAssetsRegistry): void;
|
|
24
25
|
//#endregion
|
|
25
|
-
export {
|
|
26
|
+
export { setWorkspaceRuntimeConfig as a, getWorkspaceHostedStoreLoader as c, setActiveCloudflareEnv as d, getWorkspaceRuntimeConfig as i, setWorkspaceHostedStoreLoader as l, setWorkspaceRuntimeAssetsRegistry as n, HostedWorkspaceStoreOptions as o, setWorkspaceRuntimeRegistry as r, WorkspaceHostedStoreLoader as s, invalidateWorkspaceStore as t, resetWorkspaceStoreCache as u };
|