@vite-hub/workspace 0.1.0 → 0.3.1
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 +164 -107
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/blob-database.d.ts +70 -117
- package/dist/blob-database.js +48 -41
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
- package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
- package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
- package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
- package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
- package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +2 -2
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +5 -3
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +9 -51
- package/dist/index.js +21 -91
- package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
- package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
- package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +41 -4
- package/dist/operations.js +3 -2
- package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
- package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +3 -3
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -1
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +9 -8
- package/dist/runtime.js +23 -26
- package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
- package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
- package/dist/server.d.ts +17 -8
- package/dist/server.js +1 -1
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +6 -2
- package/dist/source-metadata.js +8 -8
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
- package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
- package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
- package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21368 -1
- package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
- package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
- package/package.json +46 -55
- package/dist/ai-BW2ZhizI.d.ts +0 -177
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-DY5GP47p.js +0 -96
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
- package/dist/file-C0_aPWSS.js +0 -26
- package/dist/file-metadata-CxDy-E2H.js +0 -58
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
- package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
- package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
- package/dist/inspect-BoObD2cJ.js +0 -167
- package/dist/mountx.d.ts +0 -8
- package/dist/mountx.js +0 -145
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -27
- package/dist/nuxt.js +0 -38
- package/dist/operations-BcpWr41m.js +0 -159
- package/dist/operations-CGqY1XeG.js +0 -965
- package/dist/operations-DnOwKsJT.d.ts +0 -136
- package/dist/registry-Cg1TJVVZ.d.ts +0 -10
- package/dist/request-execution-Dk9rY-Yh.js +0 -84
- package/dist/shared-DalXdP0i.js +0 -2158
- package/dist/state-B8zbLi5t.d.ts +0 -26
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
- package/dist/token-CO62GglH.js +0 -61
- package/dist/use-DhwhbAVV.d.ts +0 -108
- package/dist/vite-BEvgU2GY.js +0 -20909
- package/dist/vite-CcZmMQ7S.d.ts +0 -476
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { n as __exportAll } from "./rolldown-runtime-
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
|
|
2
2
|
import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
3
|
-
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes } from "./path
|
|
4
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
5
|
-
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-
|
|
6
|
-
import { r as resolveWorkspaceRevisionMaterializer } from "./store-
|
|
7
|
-
import {
|
|
3
|
+
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes } from "./path--wrT_Azm.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
|
|
5
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-CgMZCHsX.js";
|
|
6
|
+
import { r as resolveWorkspaceRevisionMaterializer } from "./store-ybhyD38Z.js";
|
|
7
|
+
import { C as isMissingWorkspacePathError, S as filterSessionEntries, b as assertPathInSessionScope, w as scopedSearchQuery, x as filterSessionDiff, y as assertDiffInsideSessionPaths } from "./workspace-sPWn2Jxj.js";
|
|
8
|
+
import { normalizeExecutionAuthority } from "@vite-hub/runtime";
|
|
8
9
|
import { posix } from "node:path";
|
|
9
10
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { normalizeExecutionAuthority } from "@vite-hub/runtime";
|
|
11
11
|
//#region src/session/progress.ts
|
|
12
12
|
async function withWorkspaceProgress(onProgress, event, fn) {
|
|
13
13
|
const startedAt = Date.now();
|
|
@@ -465,15 +465,7 @@ function mergeExcludedHostState(before, materialized, excluded) {
|
|
|
465
465
|
}
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
|
-
async function
|
|
469
|
-
const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
|
|
470
|
-
const excludedRoots = [.../* @__PURE__ */ new Set([...excluded, ...currentGitRoots])];
|
|
471
|
-
const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
|
|
472
|
-
for (const path of roots.sort((left, right) => right.length - left.length)) {
|
|
473
|
-
abortSignal?.throwIfAborted();
|
|
474
|
-
await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
|
|
475
|
-
}
|
|
476
|
-
const entries = Object.entries(state.snapshot.entries).sort(([left], [right]) => left.split("/").length - right.split("/").length);
|
|
468
|
+
async function restoreHostEntries(host, root, entries, contents, abortSignal) {
|
|
477
469
|
for (const [path, entry] of entries) {
|
|
478
470
|
abortSignal?.throwIfAborted();
|
|
479
471
|
const target = toHostPath(root, path);
|
|
@@ -485,7 +477,7 @@ async function restoreExcludedHostState(host, root, excluded, state, abortSignal
|
|
|
485
477
|
});
|
|
486
478
|
continue;
|
|
487
479
|
}
|
|
488
|
-
const content =
|
|
480
|
+
const content = contents.get(path);
|
|
489
481
|
if (content === void 0) continue;
|
|
490
482
|
await ensureHostParent(host, target, abortSignal);
|
|
491
483
|
if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
|
|
@@ -495,33 +487,23 @@ async function restoreExcludedHostState(host, root, excluded, state, abortSignal
|
|
|
495
487
|
}
|
|
496
488
|
}
|
|
497
489
|
}
|
|
490
|
+
async function restoreExcludedHostState(host, root, excluded, state, abortSignal) {
|
|
491
|
+
const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
|
|
492
|
+
const excludedRoots = [.../* @__PURE__ */ new Set([...excluded, ...currentGitRoots])];
|
|
493
|
+
const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
|
|
494
|
+
for (const path of roots.sort((left, right) => right.length - left.length)) {
|
|
495
|
+
abortSignal?.throwIfAborted();
|
|
496
|
+
await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
|
|
497
|
+
}
|
|
498
|
+
await restoreHostEntries(host, root, Object.entries(state.snapshot.entries).sort(([left], [right]) => left.split("/").length - right.split("/").length), state.contents, abortSignal);
|
|
499
|
+
}
|
|
498
500
|
async function restoreAttachedHost(host, root, diff, state, abortSignal) {
|
|
499
501
|
const changed = [...new Set(diff.entries.map((entry) => entry.path))];
|
|
500
502
|
for (const path of changed.sort((left, right) => right.length - left.length)) {
|
|
501
503
|
abortSignal?.throwIfAborted();
|
|
502
504
|
await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
|
|
503
505
|
}
|
|
504
|
-
|
|
505
|
-
for (const [path, entry] of baselineEntries) {
|
|
506
|
-
abortSignal?.throwIfAborted();
|
|
507
|
-
const target = toHostPath(root, path);
|
|
508
|
-
await removeHostSymlinkAncestors(host, root, target, abortSignal);
|
|
509
|
-
if (entry.type === "directory") {
|
|
510
|
-
await host.files.mkdir(target, {
|
|
511
|
-
recursive: true,
|
|
512
|
-
signal: abortSignal
|
|
513
|
-
});
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
const content = state.contents.get(path);
|
|
517
|
-
if (content === void 0) continue;
|
|
518
|
-
await ensureHostParent(host, target, abortSignal);
|
|
519
|
-
if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
|
|
520
|
-
else {
|
|
521
|
-
await host.files.write(target, contentToBytes(content), { signal: abortSignal });
|
|
522
|
-
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
506
|
+
await restoreHostEntries(host, root, changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length), state.contents, abortSignal);
|
|
525
507
|
}
|
|
526
508
|
async function resetHostWorkspaceRoot(host, root, abortSignal) {
|
|
527
509
|
if (await ensureHostWorkspaceRoot(host, root, abortSignal)) return;
|
|
@@ -585,6 +567,27 @@ async function sessionEntries(workspace, options) {
|
|
|
585
567
|
}
|
|
586
568
|
return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
587
569
|
}
|
|
570
|
+
async function observeRetainedWorkspaceRevision(workspace, options) {
|
|
571
|
+
try {
|
|
572
|
+
const revision = await workspace.history.head();
|
|
573
|
+
if (!revision) return;
|
|
574
|
+
const entries = await sessionEntries(await workspace.history.open(revision.id), options);
|
|
575
|
+
return {
|
|
576
|
+
revision: revision.id,
|
|
577
|
+
files: new Map(entries.filter((entry) => entry.type === "file").map((entry) => [entry.path, entry]))
|
|
578
|
+
};
|
|
579
|
+
} catch {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
async function matchesRetainedWorkspaceFile(workspace, entry, content, retained) {
|
|
584
|
+
if (!retained?.digest || retained.metadata?.gitMode !== entry.metadata?.gitMode) return false;
|
|
585
|
+
try {
|
|
586
|
+
return retained.digest === await (workspace.history.digest?.(content) ?? sha256(content));
|
|
587
|
+
} catch {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
588
591
|
async function extractRevisionArchive(host, root, materialization, signal) {
|
|
589
592
|
const stagingRoot = posix.join(root, `.vitehub-workspace-${randomUUID()}`);
|
|
590
593
|
const archive = posix.join(stagingRoot, "revision.tar.gz");
|
|
@@ -685,6 +688,7 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
|
|
|
685
688
|
abortSignal: options?.abortSignal,
|
|
686
689
|
paths
|
|
687
690
|
})) : void 0;
|
|
691
|
+
const retained = !materializer && useRevisionMaterializer ? await observeRetainedWorkspaceRevision(workspace, options) : void 0;
|
|
688
692
|
await withWorkspaceProgress(options?.onProgress, {
|
|
689
693
|
id: "workspace.prepare.reset-sandbox",
|
|
690
694
|
label: "Resetting sandbox workspace"
|
|
@@ -724,6 +728,8 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
|
|
|
724
728
|
id: "workspace.prepare.entries",
|
|
725
729
|
label: "Resolving workspace entries"
|
|
726
730
|
}, async () => await sessionEntries(workspace, options));
|
|
731
|
+
const files = entries.filter((entry) => entry.type === "file");
|
|
732
|
+
let matchesRetained = Boolean(retained && files.length === retained.files.size);
|
|
727
733
|
const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
|
|
728
734
|
const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
|
|
729
735
|
if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
|
|
@@ -738,32 +744,36 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
|
|
|
738
744
|
await withWorkspaceProgress(options?.onProgress, {
|
|
739
745
|
data: {
|
|
740
746
|
bytes: entries.reduce((total, entry) => total + (entry.size || 0), 0),
|
|
741
|
-
files:
|
|
747
|
+
files: files.length
|
|
742
748
|
},
|
|
743
749
|
id: "workspace.prepare.read-files",
|
|
744
750
|
label: "Reading workspace files"
|
|
745
751
|
}, async () => {
|
|
746
752
|
abortSignal?.throwIfAborted();
|
|
747
|
-
await mapHostMaterialization(host,
|
|
753
|
+
await mapHostMaterialization(host, files, async (entry) => {
|
|
748
754
|
abortSignal?.throwIfAborted();
|
|
749
755
|
const target = toHostPath(root, entry.path);
|
|
750
756
|
await ensureHostParent(host, target, abortSignal);
|
|
757
|
+
const content = isGitSymlinkEntry(entry) && typeof entry.metadata?.symlinkTarget === "string" ? contentToBytes(entry.metadata.symlinkTarget) : contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" }));
|
|
751
758
|
if (isGitSymlinkEntry(entry)) {
|
|
752
|
-
const symlinkTarget =
|
|
759
|
+
const symlinkTarget = new TextDecoder().decode(content);
|
|
753
760
|
if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget, abortSignal);
|
|
754
|
-
else
|
|
761
|
+
else {
|
|
762
|
+
matchesRetained = false;
|
|
763
|
+
await host.files.write(target, contentToBytes(symlinkTarget), { signal: abortSignal });
|
|
764
|
+
}
|
|
755
765
|
} else {
|
|
756
|
-
const content = contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" }));
|
|
757
766
|
await host.files.write(target, content, { signal: abortSignal });
|
|
758
767
|
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
759
768
|
}
|
|
769
|
+
if (matchesRetained && !await matchesRetainedWorkspaceFile(workspace, entry, content, retained?.files.get(entry.path))) matchesRetained = false;
|
|
760
770
|
abortSignal?.throwIfAborted();
|
|
761
771
|
}, abortSignal);
|
|
762
772
|
});
|
|
763
773
|
if (revision && await materializer?.currentRevision({ abortSignal: options?.abortSignal }) !== revision.revision) throw workspaceConflict(`[vitehub] Workspace revision changed while this Session materialized: ${revision.revision}.`);
|
|
764
774
|
const snapshot = captureSnapshot ? options?.writeBack === false ? await createSnapshotFromEntries(entries, "host-open") : await snapshotHost(host, root, "host-open", abortSignal) : void 0;
|
|
765
775
|
return {
|
|
766
|
-
revision: revision?.revision,
|
|
776
|
+
revision: revision?.revision ?? (matchesRetained ? retained?.revision : void 0),
|
|
767
777
|
snapshot
|
|
768
778
|
};
|
|
769
779
|
}
|
|
@@ -836,7 +846,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
836
846
|
throw error;
|
|
837
847
|
}
|
|
838
848
|
let baseline = materialization.snapshot;
|
|
839
|
-
let baseRevision = materialization.revision;
|
|
849
|
+
let baseRevision = resolveWorkspaceRevisionMaterializer(workspace) ? materialization.revision : void 0;
|
|
840
850
|
const excludedState = attachedState ? existingExcludedState : mergeExcludedHostState(existingExcludedState, materializedExcludedState, excludedWriteBackPaths);
|
|
841
851
|
const mediaTypes = /* @__PURE__ */ new Map();
|
|
842
852
|
function assertOpen() {
|
|
@@ -848,6 +858,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
848
858
|
}
|
|
849
859
|
return {
|
|
850
860
|
executionAuthority,
|
|
861
|
+
revision: materialization.revision,
|
|
851
862
|
async readFile(path, readOptions) {
|
|
852
863
|
assertOpen();
|
|
853
864
|
const target = toHostPath(root, assertPathInSessionScope(normalizeReadableSessionPath(path), sessionPaths, { masked: true }));
|
|
@@ -895,7 +906,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
895
906
|
assertOpen();
|
|
896
907
|
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
897
908
|
const cwd = normalizeSearchRoot(globOptions?.cwd || "");
|
|
898
|
-
const { matchesAny } = await import("./path
|
|
909
|
+
const { matchesAny } = await import("./path--wrT_Azm.js").then((n) => n.u);
|
|
899
910
|
return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
|
|
900
911
|
if (entry.type !== "file") return false;
|
|
901
912
|
if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
|
|
@@ -906,7 +917,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
906
917
|
},
|
|
907
918
|
async search(query) {
|
|
908
919
|
assertOpen();
|
|
909
|
-
const { searchText } = await import("./search-
|
|
920
|
+
const { searchText } = await import("./search-C_RfoM2j.js").then((n) => n.n);
|
|
910
921
|
const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
|
|
911
922
|
if (!scoped) return [];
|
|
912
923
|
const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { a as workspaceConflict, n as assertWorkspaceDigest, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-
|
|
6
|
-
import { t as createWorkspaceGlobMatcher } from "./glob
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import { o as copyJsonFileMetadata } from "./target-jWhTdIuF.js";
|
|
3
|
+
import { a as isExcludedWorkspacePath, c as normalizeSafeWorkspacePattern, f as sha256, l as normalizeWorkspacePath, r as contentToBytes } from "./path--wrT_Azm.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
|
|
5
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-CgMZCHsX.js";
|
|
6
|
+
import { t as createWorkspaceGlobMatcher } from "./glob-Cjxms1t7.js";
|
|
7
|
+
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
8
|
+
import { T as getActiveCloudflareBinding } from "./shared-B3_EUk89.js";
|
|
9
|
+
import { a as resolveGitHubWorkspaceStore, d as setWorkspaceHostedStoreLoader, i as resolveCloudflareArtifactsStore, u as getWorkspaceHostedStoreLoader } from "./provider-9s4Ufkm5.js";
|
|
10
|
+
import { t as workspaceStoreDiscard } from "./discard-CNNtCozM.js";
|
|
11
|
+
import { t as createGitHubWorkspaceStore } from "./store-ybhyD38Z.js";
|
|
12
|
+
import { n as setWorkspaceRuntimeConfig } from "./config-B-863EgC.js";
|
|
10
13
|
import { resolve } from "node:path";
|
|
11
14
|
import { boolean, check, object, optional, parse as parse$1, pipe, record, string, unknown } from "valibot";
|
|
12
|
-
//#region ../internal/src/object.ts
|
|
13
|
-
function isPlainObject(value) {
|
|
14
|
-
if (value === null || Object(value) !== value || Array.isArray(value)) return false;
|
|
15
|
-
return typeof value === "object";
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
15
|
//#region src/storage/memory-fs.ts
|
|
19
16
|
function copyBinaryData(data) {
|
|
20
17
|
if (ArrayBuffer.isView(data)) return Uint8Array.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
@@ -88,7 +85,7 @@ var MemoryFS = class {
|
|
|
88
85
|
}
|
|
89
86
|
async mkdir(path, options) {
|
|
90
87
|
const target = this.normalize(path);
|
|
91
|
-
const recursive =
|
|
88
|
+
const recursive = isRecord(options) && options.recursive === true;
|
|
92
89
|
if (target === "/") {
|
|
93
90
|
if (recursive) return;
|
|
94
91
|
throw memoryFsError("EEXIST", path);
|
|
@@ -128,7 +125,7 @@ var MemoryFS = class {
|
|
|
128
125
|
async readFile(path, options) {
|
|
129
126
|
const entry = this.#requireEntry(path);
|
|
130
127
|
if (entry.kind !== "file") throw memoryFsError("EISDIR", path);
|
|
131
|
-
return (
|
|
128
|
+
return (isRecord(options) ? options.encoding : options) ? this.#decoder.decode(entry.data) : Uint8Array.from(entry.data);
|
|
132
129
|
}
|
|
133
130
|
async readdir(path) {
|
|
134
131
|
return [...this.#requireDir(path).children].sort();
|
|
@@ -191,6 +188,8 @@ const dir = "/workspace";
|
|
|
191
188
|
const fileMetadataPath = ".vitehub/files.json";
|
|
192
189
|
const fileMetadataJournalPath = ".vitehub/files.pending.json";
|
|
193
190
|
const tokenRefreshWindow = 6e4;
|
|
191
|
+
/** How long a Store without staged writes trusts the branch head that it loaded, in milliseconds. */
|
|
192
|
+
const remoteHeadCacheMs = 5e3;
|
|
194
193
|
const fileMetadataSchema = object({
|
|
195
194
|
mediaType: optional(string()),
|
|
196
195
|
metadata: optional(pipe(record(string(), unknown()), check((value) => value.source === void 0 || typeof value.source === "string", "metadata.source must be a string when provided")))
|
|
@@ -255,7 +254,12 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
255
254
|
#files = /* @__PURE__ */ new Map();
|
|
256
255
|
#fs;
|
|
257
256
|
#head;
|
|
257
|
+
#loadedAt = 0;
|
|
258
258
|
#pendingCommit;
|
|
259
|
+
/** Whether files or metadata changed since the last load or push. */
|
|
260
|
+
#staged = false;
|
|
261
|
+
/** Metadata written since the last load or push, by absolute path. A rebase writes it again on the new head. */
|
|
262
|
+
#stagedMeta = /* @__PURE__ */ new Map();
|
|
259
263
|
#remote;
|
|
260
264
|
#ready;
|
|
261
265
|
#mutationQueue = Promise.resolve();
|
|
@@ -264,6 +268,17 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
264
268
|
this.options = options;
|
|
265
269
|
this.workspaceName = workspaceName;
|
|
266
270
|
}
|
|
271
|
+
/** Drops the staged writes. The next call clones the branch again, as the first call does. */
|
|
272
|
+
async [workspaceStoreDiscard]() {
|
|
273
|
+
await this.#mutate(async () => {
|
|
274
|
+
this.#files = /* @__PURE__ */ new Map();
|
|
275
|
+
this.#head = void 0;
|
|
276
|
+
this.#pendingCommit = void 0;
|
|
277
|
+
this.#ready = void 0;
|
|
278
|
+
this.#staged = false;
|
|
279
|
+
this.#stagedMeta = /* @__PURE__ */ new Map();
|
|
280
|
+
});
|
|
281
|
+
}
|
|
267
282
|
async readFile(path) {
|
|
268
283
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
269
284
|
await this.#ensure();
|
|
@@ -386,7 +401,9 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
386
401
|
if (stat.isDirectory() && !options.recursive) {
|
|
387
402
|
if ((await this.#fs.promises.readdir(absolute)).length) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
388
403
|
}
|
|
389
|
-
|
|
404
|
+
const removed = this.#fs.deleteTree(absolute);
|
|
405
|
+
if (!removed && !options.force) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
406
|
+
if (removed) this.#staged = true;
|
|
390
407
|
for (const key of this.#files.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#files.delete(key);
|
|
391
408
|
await this.#writeFileMetadata();
|
|
392
409
|
});
|
|
@@ -397,54 +414,75 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
397
414
|
}
|
|
398
415
|
async rebase(options = {}) {
|
|
399
416
|
await this.#ensure();
|
|
400
|
-
await this.#mutate(async () =>
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
417
|
+
await this.#mutate(async () => await this.#rebase(options));
|
|
418
|
+
}
|
|
419
|
+
/** Load the current branch head and write the staged changes on it again. A path that changed on both sides fails with its name in `details.paths`. */
|
|
420
|
+
async #rebase(options) {
|
|
421
|
+
const baseline = this.#baseline;
|
|
422
|
+
const current = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }));
|
|
423
|
+
const changes = diffSnapshots(baseline, current).entries.filter((change) => change.before?.type === "file" || change.after?.type === "file");
|
|
424
|
+
const local = /* @__PURE__ */ new Map();
|
|
425
|
+
for (const change of changes) local.set(change.path, change.after ? await this.#readFile(change.path) : void 0);
|
|
426
|
+
const previous = {
|
|
427
|
+
baseline: this.#baseline,
|
|
428
|
+
branch: this.#branch,
|
|
429
|
+
files: this.#files,
|
|
430
|
+
fs: this.#fs,
|
|
431
|
+
head: this.#head,
|
|
432
|
+
pendingCommit: this.#pendingCommit,
|
|
433
|
+
remote: this.#remote,
|
|
434
|
+
staged: this.#staged,
|
|
435
|
+
stagedMeta: this.#stagedMeta
|
|
436
|
+
};
|
|
437
|
+
const restore = () => {
|
|
438
|
+
this.#baseline = previous.baseline;
|
|
439
|
+
this.#branch = previous.branch;
|
|
440
|
+
this.#files = previous.files;
|
|
441
|
+
this.#fs = previous.fs;
|
|
442
|
+
this.#head = previous.head;
|
|
443
|
+
this.#pendingCommit = previous.pendingCommit;
|
|
444
|
+
this.#remote = previous.remote;
|
|
445
|
+
this.#staged = previous.staged;
|
|
446
|
+
this.#stagedMeta = previous.stagedMeta;
|
|
447
|
+
};
|
|
448
|
+
try {
|
|
449
|
+
this.#files = /* @__PURE__ */ new Map();
|
|
450
|
+
this.#pendingCommit = void 0;
|
|
451
|
+
await this.#load();
|
|
452
|
+
const remoteChanges = new Map(diffSnapshots(baseline, this.#baseline).entries.map((change) => [change.path, change]));
|
|
453
|
+
const takeRemote = new Set(options.takeRemote || []);
|
|
454
|
+
const conflicts = changes.filter((change) => remoteChanges.has(change.path) && !takeRemote.has(change.path) && !sameSnapshotEntry(current.entries[change.path], this.#baseline?.entries[change.path])).map((change) => change.path).sort();
|
|
455
|
+
if (conflicts.length) throw workspaceConflict(`[vitehub] Cloudflare Artifacts Workspace Store rebase conflict: ${conflicts.join(", ")} changed locally and remotely.`, { details: {
|
|
408
456
|
branch: this.#branch,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
this.#
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
this.#pendingCommit = previous.pendingCommit;
|
|
422
|
-
this.#remote = previous.remote;
|
|
423
|
-
};
|
|
424
|
-
try {
|
|
425
|
-
this.#files = /* @__PURE__ */ new Map();
|
|
426
|
-
this.#pendingCommit = void 0;
|
|
427
|
-
await this.#load();
|
|
428
|
-
const remoteChanges = new Map(diffSnapshots(baseline, this.#baseline).entries.map((change) => [change.path, change]));
|
|
429
|
-
const takeRemote = new Set(options.takeRemote || []);
|
|
430
|
-
for (const change of changes) if (remoteChanges.has(change.path) && !takeRemote.has(change.path) && !sameSnapshotEntry(current.entries[change.path], this.#baseline?.entries[change.path])) throw workspaceConflict(`[vitehub] Cloudflare Artifacts Workspace Store rebase conflict: ${change.path} changed locally and remotely.`);
|
|
431
|
-
for (const change of changes) {
|
|
432
|
-
if (remoteChanges.has(change.path) && takeRemote.has(change.path)) continue;
|
|
433
|
-
const file = local.get(change.path);
|
|
434
|
-
if (file) await this.#writeFile(change.path, file);
|
|
435
|
-
else {
|
|
436
|
-
this.#fs.deleteTree(this.#absolute(change.path));
|
|
437
|
-
this.#files.delete(change.path);
|
|
438
|
-
await this.#writeFileMetadata();
|
|
439
|
-
}
|
|
457
|
+
paths: conflicts
|
|
458
|
+
} });
|
|
459
|
+
let replayed = 0;
|
|
460
|
+
for (const change of changes) {
|
|
461
|
+
if (remoteChanges.has(change.path) && takeRemote.has(change.path)) continue;
|
|
462
|
+
replayed++;
|
|
463
|
+
const file = local.get(change.path);
|
|
464
|
+
if (file) await this.#writeFile(change.path, file);
|
|
465
|
+
else {
|
|
466
|
+
this.#fs.deleteTree(this.#absolute(change.path));
|
|
467
|
+
this.#files.delete(change.path);
|
|
468
|
+
await this.#writeFileMetadata();
|
|
440
469
|
}
|
|
441
|
-
} catch (error) {
|
|
442
|
-
restore();
|
|
443
|
-
throw error;
|
|
444
470
|
}
|
|
445
|
-
|
|
471
|
+
for (const [path, bytes] of previous.stagedMeta) if (bytes.byteLength) await this.#fs.promises.writeFile(path, bytes);
|
|
472
|
+
else this.#fs.deleteTree(path);
|
|
473
|
+
this.#stagedMeta = new Map(previous.stagedMeta);
|
|
474
|
+
this.#staged = replayed > 0 || previous.stagedMeta.size > 0;
|
|
475
|
+
} catch (error) {
|
|
476
|
+
restore();
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
446
479
|
}
|
|
447
|
-
|
|
480
|
+
/**
|
|
481
|
+
* Commit and push the staged changes. When the branch moved since the Store loaded, for example because another
|
|
482
|
+
* isolate pushed, the Store loads the new head, writes the staged changes on it again, and pushes once more. A path
|
|
483
|
+
* that changed on both sides, or a second move, fails with `WORKSPACE_CONFLICT`.
|
|
484
|
+
*/
|
|
485
|
+
async #createSnapshot(options, retry = true) {
|
|
448
486
|
const git = await import("isomorphic-git");
|
|
449
487
|
const http = await import("isomorphic-git/http/web");
|
|
450
488
|
const matrix = await git.statusMatrix({
|
|
@@ -452,28 +490,30 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
452
490
|
fs: this.#fs,
|
|
453
491
|
ignored: true
|
|
454
492
|
});
|
|
455
|
-
|
|
493
|
+
const removed = [];
|
|
494
|
+
const added = [];
|
|
456
495
|
for (const [filepath, head, workdir, stage] of matrix) {
|
|
457
496
|
if (filepath.startsWith(".git/")) continue;
|
|
458
|
-
if (workdir === 0 && (head !== 0 || stage !== 0))
|
|
459
|
-
|
|
460
|
-
dir,
|
|
461
|
-
filepath,
|
|
462
|
-
fs: this.#fs
|
|
463
|
-
});
|
|
464
|
-
changed = true;
|
|
465
|
-
} else if (workdir !== stage) {
|
|
466
|
-
await git.add({
|
|
467
|
-
dir,
|
|
468
|
-
filepath,
|
|
469
|
-
force: true,
|
|
470
|
-
fs: this.#fs
|
|
471
|
-
});
|
|
472
|
-
changed = true;
|
|
473
|
-
}
|
|
497
|
+
if (workdir === 0 && (head !== 0 || stage !== 0)) removed.push(filepath);
|
|
498
|
+
else if (workdir !== stage) added.push(filepath);
|
|
474
499
|
}
|
|
475
|
-
if (
|
|
476
|
-
|
|
500
|
+
if (removed.length) await git.remove({
|
|
501
|
+
dir,
|
|
502
|
+
filepath: removed,
|
|
503
|
+
fs: this.#fs
|
|
504
|
+
});
|
|
505
|
+
if (added.length) await git.add({
|
|
506
|
+
dir,
|
|
507
|
+
filepath: added,
|
|
508
|
+
force: true,
|
|
509
|
+
fs: this.#fs
|
|
510
|
+
});
|
|
511
|
+
if (removed.length > 0 || added.length > 0 || !this.#head && !this.#pendingCommit) this.#pendingCommit = await git.commit({
|
|
512
|
+
author: options.author ?? {
|
|
513
|
+
email: "workspace@vitehub.dev",
|
|
514
|
+
name: "ViteHub Workspace"
|
|
515
|
+
},
|
|
516
|
+
committer: {
|
|
477
517
|
email: "workspace@vitehub.dev",
|
|
478
518
|
name: "ViteHub Workspace"
|
|
479
519
|
},
|
|
@@ -497,12 +537,21 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
497
537
|
url: this.#remote
|
|
498
538
|
});
|
|
499
539
|
} catch (error) {
|
|
500
|
-
if (isNonFastForward(error))
|
|
540
|
+
if (isNonFastForward(error)) {
|
|
541
|
+
if (retry) {
|
|
542
|
+
await this.#rebase({});
|
|
543
|
+
return await this.#createSnapshot(options, false);
|
|
544
|
+
}
|
|
545
|
+
throw workspaceConflict(`[vitehub] Workspace "${this.workspaceName}" changed remotely while snapshotting branch "${this.#branch}". Reload the Workspace before retrying.`, { cause: error });
|
|
546
|
+
}
|
|
501
547
|
throw error;
|
|
502
548
|
}
|
|
503
549
|
this.#head = id;
|
|
504
550
|
this.#pendingCommit = void 0;
|
|
505
551
|
}
|
|
552
|
+
this.#staged = false;
|
|
553
|
+
this.#stagedMeta = /* @__PURE__ */ new Map();
|
|
554
|
+
this.#loadedAt = Date.now();
|
|
506
555
|
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
507
556
|
this.#baseline = {
|
|
508
557
|
...snapshot,
|
|
@@ -523,14 +572,21 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
523
572
|
await this.#ensure();
|
|
524
573
|
return await this.#mutate(async () => {
|
|
525
574
|
const content = await this.#fs.promises.readFile(path).catch(() => void 0);
|
|
526
|
-
|
|
527
|
-
|
|
575
|
+
const bytes = content === void 0 ? void 0 : contentToBytes(content);
|
|
576
|
+
if (!bytes?.byteLength) return void 0;
|
|
577
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
528
578
|
});
|
|
529
579
|
}
|
|
530
580
|
async setMeta(key, value) {
|
|
531
581
|
const path = this.#metaAbsolute(key);
|
|
532
582
|
await this.#ensure();
|
|
533
|
-
await this.#mutate(() =>
|
|
583
|
+
await this.#mutate(async () => {
|
|
584
|
+
const bytes = value === void 0 ? /* @__PURE__ */ new Uint8Array() : contentToBytes(JSON.stringify(value));
|
|
585
|
+
if (bytes.byteLength) await this.#fs.promises.writeFile(path, bytes);
|
|
586
|
+
else this.#fs.deleteTree(path);
|
|
587
|
+
this.#stagedMeta.set(path, bytes);
|
|
588
|
+
this.#staged = true;
|
|
589
|
+
});
|
|
534
590
|
}
|
|
535
591
|
async #writeFile(path, file) {
|
|
536
592
|
file = {
|
|
@@ -550,6 +606,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
550
606
|
}
|
|
551
607
|
}));
|
|
552
608
|
await this.#fs.promises.writeFile(this.#absolute(path), content);
|
|
609
|
+
this.#staged = true;
|
|
553
610
|
if (file.mediaType !== void 0 || file.metadata !== void 0) this.#files.set(path, {
|
|
554
611
|
mediaType: file.mediaType,
|
|
555
612
|
metadata: file.metadata
|
|
@@ -633,9 +690,62 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
633
690
|
if (!binding) throw workspaceError(`[vitehub] Cloudflare Artifacts binding "${bindingName}" not found.`);
|
|
634
691
|
return binding;
|
|
635
692
|
}
|
|
693
|
+
/**
|
|
694
|
+
* Load the branch once. A Store without staged changes that loaded more than `remoteHeadCacheMs` ago asks for the
|
|
695
|
+
* branch head again and loads it when it moved, so a Store that one isolate keeps for many requests sees pushes from
|
|
696
|
+
* other writers before it stages new changes.
|
|
697
|
+
*/
|
|
636
698
|
async #ensure() {
|
|
637
|
-
|
|
699
|
+
const wasReady = !!this.#ready;
|
|
700
|
+
this.#ready ||= this.#load().catch((error) => {
|
|
701
|
+
this.#ready = void 0;
|
|
702
|
+
throw error;
|
|
703
|
+
});
|
|
638
704
|
await this.#ready;
|
|
705
|
+
if (!wasReady) return;
|
|
706
|
+
await this.#mutate(async () => {
|
|
707
|
+
if (this.#staged || this.#pendingCommit || Date.now() - this.#loadedAt < remoteHeadCacheMs) return;
|
|
708
|
+
if (await this.#remoteHead() === this.#head) {
|
|
709
|
+
this.#loadedAt = Date.now();
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const previous = {
|
|
713
|
+
baseline: this.#baseline,
|
|
714
|
+
branch: this.#branch,
|
|
715
|
+
files: this.#files,
|
|
716
|
+
fs: this.#fs,
|
|
717
|
+
head: this.#head,
|
|
718
|
+
remote: this.#remote
|
|
719
|
+
};
|
|
720
|
+
try {
|
|
721
|
+
this.#files = /* @__PURE__ */ new Map();
|
|
722
|
+
this.#head = void 0;
|
|
723
|
+
await this.#load();
|
|
724
|
+
} catch (error) {
|
|
725
|
+
this.#baseline = previous.baseline;
|
|
726
|
+
this.#branch = previous.branch;
|
|
727
|
+
this.#files = previous.files;
|
|
728
|
+
this.#fs = previous.fs;
|
|
729
|
+
this.#head = previous.head;
|
|
730
|
+
this.#remote = previous.remote;
|
|
731
|
+
throw error;
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
async #remoteHead() {
|
|
736
|
+
const git = await import("isomorphic-git");
|
|
737
|
+
const http = await import("isomorphic-git/http/web");
|
|
738
|
+
const token = await this.#writeToken();
|
|
739
|
+
const branchRef = `refs/heads/${this.#branch}`;
|
|
740
|
+
return (await git.listServerRefs({
|
|
741
|
+
http,
|
|
742
|
+
onAuth: () => ({
|
|
743
|
+
password: token,
|
|
744
|
+
username: "x"
|
|
745
|
+
}),
|
|
746
|
+
prefix: branchRef,
|
|
747
|
+
url: this.#remote
|
|
748
|
+
})).find((ref) => ref.ref === branchRef)?.oid;
|
|
639
749
|
}
|
|
640
750
|
#mutate(operation) {
|
|
641
751
|
const result = this.#mutationQueue.then(operation);
|
|
@@ -721,6 +831,9 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
721
831
|
...baseline,
|
|
722
832
|
id: this.#head
|
|
723
833
|
} : baseline;
|
|
834
|
+
this.#loadedAt = Date.now();
|
|
835
|
+
this.#staged = false;
|
|
836
|
+
this.#stagedMeta = /* @__PURE__ */ new Map();
|
|
724
837
|
}
|
|
725
838
|
};
|
|
726
839
|
function createCloudflareArtifactsWorkspaceStore(options, workspaceName) {
|
|
@@ -728,27 +841,37 @@ function createCloudflareArtifactsWorkspaceStore(options, workspaceName) {
|
|
|
728
841
|
}
|
|
729
842
|
//#endregion
|
|
730
843
|
//#region src/hosted.ts
|
|
731
|
-
function
|
|
844
|
+
function installHostedGitHubWorkspaceStore() {
|
|
845
|
+
const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
|
|
846
|
+
setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
|
|
847
|
+
if (storeOptions.driver === "github") return createGitHubWorkspaceStore(storeOptions, workspaceName);
|
|
848
|
+
return existingWorkspaceHostedStoreLoader?.(storeOptions, workspaceName);
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
function installHostedCloudflareArtifactsWorkspaceStore() {
|
|
732
852
|
const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
|
|
733
853
|
setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
|
|
734
|
-
if (storeOptions.
|
|
735
|
-
|
|
736
|
-
if (existingWorkspaceHostedStoreLoader) return existingWorkspaceHostedStoreLoader(storeOptions, workspaceName);
|
|
737
|
-
throw workspaceError("[vitehub] Hosted workspace runtime cannot load unsupported hosted store.");
|
|
854
|
+
if (storeOptions.driver === "cloudflare") return createCloudflareArtifactsWorkspaceStore(storeOptions, workspaceName);
|
|
855
|
+
return existingWorkspaceHostedStoreLoader?.(storeOptions, workspaceName);
|
|
738
856
|
});
|
|
739
857
|
}
|
|
858
|
+
function installHostedWorkspaceRuntime() {
|
|
859
|
+
installHostedGitHubWorkspaceStore();
|
|
860
|
+
installHostedCloudflareArtifactsWorkspaceStore();
|
|
861
|
+
}
|
|
740
862
|
function configureHostedWorkspaceRuntime(options = {}) {
|
|
741
863
|
const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
|
|
742
|
-
const store = options.store?.
|
|
864
|
+
const store = options.store?.driver === "github" ? resolveGitHubWorkspaceStore(options.store, options.env || {}, { runtime: true }) : options.store?.driver === "vercel" ? void 0 : resolveCloudflareArtifactsStore(options.store, options.env);
|
|
743
865
|
if (!store) throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime must use @vite-hub/workspace/internal/runtime/hosted-vercel-blob.");
|
|
744
866
|
const config = {
|
|
745
867
|
assets: options.assets,
|
|
746
868
|
root,
|
|
747
869
|
store
|
|
748
870
|
};
|
|
749
|
-
|
|
871
|
+
if (store.driver === "github") installHostedGitHubWorkspaceStore();
|
|
872
|
+
else installHostedCloudflareArtifactsWorkspaceStore();
|
|
750
873
|
setWorkspaceRuntimeConfig(config);
|
|
751
874
|
return config;
|
|
752
875
|
}
|
|
753
876
|
//#endregion
|
|
754
|
-
export {
|
|
877
|
+
export { createCloudflareArtifactsWorkspaceStore as a, installHostedWorkspaceRuntime as i, installHostedCloudflareArtifactsWorkspaceStore as n, installHostedGitHubWorkspaceStore as r, configureHostedWorkspaceRuntime as t };
|