@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
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { _ as workspaceError, a as isExcludedWorkspacePath, c as normalizeSafeWorkspacePattern, f as sha256, g as workspaceConflict, l as normalizeWorkspacePath, n as contentStreamToBytes, o as matchesAny, p as assertWorkspaceDigest, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
|
+
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
+
import { c as readGitHubArchive, d as requireGitHubOption, f as resolveGitHubBranchOption, g as resolveGitHubTokenOption, h as resolveGitHubRootOption, i as gitBlobSha, l as readGitHubBranchState, m as resolveGitHubRepositoryOption, n as createGitHubBlob, o as joinGitPath, r as createGitHubFileUpdate, t as commitGitHubChanges, u as readGitHubRawFile } from "./shared-DTR1Hhma.js";
|
|
4
|
+
import { posix } from "node:path";
|
|
5
|
+
//#region src/storage/utils.ts
|
|
6
|
+
const snapshotStatConcurrency = 16;
|
|
7
|
+
async function mapWithConcurrency(values, concurrency, visit) {
|
|
8
|
+
const results = [];
|
|
9
|
+
let next = 0;
|
|
10
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, values.length) }, async () => {
|
|
11
|
+
while (next < values.length) {
|
|
12
|
+
const index = next++;
|
|
13
|
+
results[index] = await visit(values[index]);
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
async function createCurrentSnapshotFromStore(store, name) {
|
|
19
|
+
return await createSnapshotFromEntries(await mapWithConcurrency(await store.list("", { recursive: true }), snapshotStatConcurrency, async (entry) => {
|
|
20
|
+
if (entry.type !== "file" || entry.digest) return entry;
|
|
21
|
+
return await store.stat(entry.path) || entry;
|
|
22
|
+
}), name);
|
|
23
|
+
}
|
|
24
|
+
async function createSnapshotFromEntries(entries, name) {
|
|
25
|
+
const snapshotEntries = {};
|
|
26
|
+
for (const entry of entries) snapshotEntries[entry.path] = {
|
|
27
|
+
digest: entry.digest,
|
|
28
|
+
metadata: entry.metadata,
|
|
29
|
+
size: entry.size,
|
|
30
|
+
type: entry.type
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34
|
+
entries: snapshotEntries,
|
|
35
|
+
id: await sha256({
|
|
36
|
+
entries: snapshotEntries,
|
|
37
|
+
name,
|
|
38
|
+
createdAt: Date.now()
|
|
39
|
+
}),
|
|
40
|
+
name
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function diffSnapshots(from, to) {
|
|
44
|
+
const entries = [];
|
|
45
|
+
const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
|
|
46
|
+
for (const path of [...keys].sort()) {
|
|
47
|
+
const before = from?.entries[path];
|
|
48
|
+
const after = to.entries[path];
|
|
49
|
+
if (!before && after) entries.push({
|
|
50
|
+
path,
|
|
51
|
+
type: "added",
|
|
52
|
+
after
|
|
53
|
+
});
|
|
54
|
+
else if (before && !after) entries.push({
|
|
55
|
+
path,
|
|
56
|
+
type: "removed",
|
|
57
|
+
before
|
|
58
|
+
});
|
|
59
|
+
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({
|
|
60
|
+
path,
|
|
61
|
+
type: "modified",
|
|
62
|
+
before,
|
|
63
|
+
after
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
from: from?.id,
|
|
68
|
+
to: to.id,
|
|
69
|
+
entries
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/storage/materialization.ts
|
|
74
|
+
const workspaceRevisionMaterializer = Symbol.for("vitehub.workspace.revisionMaterializer");
|
|
75
|
+
function forwardWorkspaceRevisionMaterializer(source, target) {
|
|
76
|
+
const materializer = source[workspaceRevisionMaterializer];
|
|
77
|
+
if (materializer) target[workspaceRevisionMaterializer] = materializer;
|
|
78
|
+
}
|
|
79
|
+
function resolveWorkspaceRevisionMaterializer(workspace) {
|
|
80
|
+
return workspace[workspaceRevisionMaterializer];
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/providers/github/store.ts
|
|
84
|
+
function sameGitHubTreeEntry(left, right) {
|
|
85
|
+
return left?.sha === right?.sha && (left?.mode || "100644") === (right?.mode || "100644");
|
|
86
|
+
}
|
|
87
|
+
function matchesGitHubRemote(file, remote) {
|
|
88
|
+
return file?.gitSha === remote?.sha && gitHubFileMode(file?.metadata) === (remote?.mode || "100644");
|
|
89
|
+
}
|
|
90
|
+
function githubRemoteFile(path, entry) {
|
|
91
|
+
return {
|
|
92
|
+
gitSha: entry.sha,
|
|
93
|
+
metadata: gitHubFileMetadata(entry),
|
|
94
|
+
path,
|
|
95
|
+
size: entry.size
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function isReservedWorkspacePath(path) {
|
|
99
|
+
const root = normalizeWorkspacePath(path).split("/")[0];
|
|
100
|
+
return root === ".git" || root === ".vitehub";
|
|
101
|
+
}
|
|
102
|
+
function contentLength(content) {
|
|
103
|
+
return ArrayBuffer.isView(content) ? content.byteLength : new TextEncoder().encode(content).byteLength;
|
|
104
|
+
}
|
|
105
|
+
function readStringMetadata(metadata, key) {
|
|
106
|
+
const value = metadata?.[key];
|
|
107
|
+
return Object.prototype.toString.call(value) === "[object String]" ? String(value) : void 0;
|
|
108
|
+
}
|
|
109
|
+
function gitHubFileMetadata(entry) {
|
|
110
|
+
return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
|
|
111
|
+
}
|
|
112
|
+
function gitHubFileMode(metadata) {
|
|
113
|
+
return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
|
|
114
|
+
}
|
|
115
|
+
function inheritedGitHubFileMetadata(file, current) {
|
|
116
|
+
if (file.metadata) return file.metadata;
|
|
117
|
+
return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
|
|
118
|
+
}
|
|
119
|
+
function parentDirectories(path) {
|
|
120
|
+
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
121
|
+
const directories = [];
|
|
122
|
+
for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
|
|
123
|
+
return directories;
|
|
124
|
+
}
|
|
125
|
+
function resolveSymlinkTarget(path, bytes) {
|
|
126
|
+
const target = gitSymlinkTargetFromBytes(bytes);
|
|
127
|
+
if (!target || target.startsWith("/")) return;
|
|
128
|
+
const base = path.split("/").slice(0, -1).join("/");
|
|
129
|
+
const resolved = posix.normalize(base ? `${base}/${target}` : target);
|
|
130
|
+
if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
|
|
131
|
+
return normalizeSafeWorkspacePath(resolved);
|
|
132
|
+
}
|
|
133
|
+
function gitSymlinkTargetFromBytes(bytes) {
|
|
134
|
+
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
|
135
|
+
}
|
|
136
|
+
async function waitForGitHubOperation(read, signal) {
|
|
137
|
+
signal?.throwIfAborted();
|
|
138
|
+
if (!signal) return await read;
|
|
139
|
+
return await new Promise((resolve, reject) => {
|
|
140
|
+
const abort = () => reject(signal.reason);
|
|
141
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
142
|
+
read.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
var GitHubWorkspaceStore = class {
|
|
146
|
+
workspaceName;
|
|
147
|
+
#baseline;
|
|
148
|
+
#archive;
|
|
149
|
+
#archiveReads = /* @__PURE__ */ new Map();
|
|
150
|
+
#baselineRefSha;
|
|
151
|
+
#baselineTreeSha;
|
|
152
|
+
#branch;
|
|
153
|
+
#dirty = false;
|
|
154
|
+
#files = /* @__PURE__ */ new Map();
|
|
155
|
+
#mutationQueue = Promise.resolve();
|
|
156
|
+
#ready;
|
|
157
|
+
#remoteFiles = /* @__PURE__ */ new Map();
|
|
158
|
+
#repository;
|
|
159
|
+
#root;
|
|
160
|
+
#token;
|
|
161
|
+
constructor(options, workspaceName) {
|
|
162
|
+
this.workspaceName = workspaceName;
|
|
163
|
+
this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
|
|
164
|
+
this.#branch = resolveGitHubBranchOption(options);
|
|
165
|
+
this.#root = resolveGitHubRootOption(options, workspaceName);
|
|
166
|
+
this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
|
|
167
|
+
}
|
|
168
|
+
[workspaceStoreTarget]() {
|
|
169
|
+
return {
|
|
170
|
+
provider: "github",
|
|
171
|
+
branch: this.#branch,
|
|
172
|
+
repository: this.#repository
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
[workspaceRevisionMaterializer] = {
|
|
176
|
+
currentRevision: async (options) => {
|
|
177
|
+
await waitForGitHubOperation(this.#mutate(async () => await this.#ensure({ refresh: options?.refresh !== false })), options?.abortSignal);
|
|
178
|
+
return this.#baselineRefSha;
|
|
179
|
+
},
|
|
180
|
+
materializeRevision: async (options) => {
|
|
181
|
+
await waitForGitHubOperation(this.#mutate(async () => await this.#ensure({ refresh: true })), options?.abortSignal);
|
|
182
|
+
const revision = this.#baselineRefSha;
|
|
183
|
+
const paths = options?.paths;
|
|
184
|
+
const files = [...this.#remoteFiles.keys()].filter((path) => !isReservedWorkspacePath(path) && (!paths || paths.some((root) => path === root || path.startsWith(`${root}/`)))).length;
|
|
185
|
+
if (!this.#dirty && paths === void 0 && this.#archive?.revision !== revision) {
|
|
186
|
+
let read = this.#archiveReads.get(revision);
|
|
187
|
+
if (!read) {
|
|
188
|
+
read = readGitHubArchive({
|
|
189
|
+
ref: revision,
|
|
190
|
+
repository: this.#repository,
|
|
191
|
+
token: this.#token
|
|
192
|
+
});
|
|
193
|
+
this.#archiveReads.set(revision, read);
|
|
194
|
+
read.finally(() => {
|
|
195
|
+
if (this.#archiveReads.get(revision) === read) this.#archiveReads.delete(revision);
|
|
196
|
+
}).catch(() => {});
|
|
197
|
+
}
|
|
198
|
+
this.#archive = {
|
|
199
|
+
bytes: await waitForGitHubOperation(read, options?.abortSignal),
|
|
200
|
+
revision
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
...!this.#dirty && paths === void 0 ? { archive: this.#archive.bytes } : {},
|
|
205
|
+
files,
|
|
206
|
+
paths,
|
|
207
|
+
revision,
|
|
208
|
+
root: this.#root
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
async readFile(path) {
|
|
213
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
214
|
+
await this.#ensure({ refresh: false });
|
|
215
|
+
return await this.#readWorkspaceFile(normalized);
|
|
216
|
+
}
|
|
217
|
+
async writeFile(path, file) {
|
|
218
|
+
await this.#mutate(async () => {
|
|
219
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
220
|
+
await this.#ensure({ refresh: false });
|
|
221
|
+
await this.#writeFile(normalized, file);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
async writeFileConditional(path, file, ifDigest) {
|
|
225
|
+
await this.#mutate(async () => {
|
|
226
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
227
|
+
await this.#ensure({ refresh: true });
|
|
228
|
+
assertWorkspaceDigest(normalized, ifDigest, this.#files.get(normalized)?.gitSha);
|
|
229
|
+
await this.#writeFile(normalized, file);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async #writeFile(normalized, file) {
|
|
233
|
+
const current = this.#files.get(normalized);
|
|
234
|
+
const metadata = inheritedGitHubFileMetadata(file, current);
|
|
235
|
+
const symlinkTarget = readStringMetadata(metadata, "symlinkTarget");
|
|
236
|
+
const content = gitHubFileMode(metadata) === "120000" && symlinkTarget !== void 0 ? symlinkTarget : file.content;
|
|
237
|
+
const update = await createGitHubFileUpdate(normalized, this.#root, content);
|
|
238
|
+
if (current?.gitSha === update.gitSha) {
|
|
239
|
+
if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
|
|
240
|
+
this.#files.set(normalized, {
|
|
241
|
+
...current,
|
|
242
|
+
mediaType: file.mediaType,
|
|
243
|
+
metadata,
|
|
244
|
+
size: contentLength(content)
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await createGitHubBlob({
|
|
249
|
+
bytes: update.bytes,
|
|
250
|
+
kind: "store",
|
|
251
|
+
repository: this.#repository,
|
|
252
|
+
token: this.#token
|
|
253
|
+
});
|
|
254
|
+
this.#files.set(normalized, {
|
|
255
|
+
bytes: update.bytes,
|
|
256
|
+
gitSha: update.gitSha,
|
|
257
|
+
mediaType: file.mediaType,
|
|
258
|
+
metadata,
|
|
259
|
+
path: normalized,
|
|
260
|
+
size: contentLength(content),
|
|
261
|
+
uploaded: true
|
|
262
|
+
});
|
|
263
|
+
this.#dirty = true;
|
|
264
|
+
}
|
|
265
|
+
#mutate(operation) {
|
|
266
|
+
const result = this.#mutationQueue.then(operation);
|
|
267
|
+
this.#mutationQueue = result.then(() => void 0, () => void 0);
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
async writeFileStream(path, file) {
|
|
271
|
+
const content = await contentStreamToBytes(file.content);
|
|
272
|
+
await this.writeFile(path, {
|
|
273
|
+
path: file.path,
|
|
274
|
+
content,
|
|
275
|
+
mediaType: file.mediaType,
|
|
276
|
+
metadata: file.metadata
|
|
277
|
+
});
|
|
278
|
+
return {
|
|
279
|
+
digest: await gitBlobSha(content),
|
|
280
|
+
mediaType: file.mediaType,
|
|
281
|
+
path: normalizeSafeWorkspacePath(path),
|
|
282
|
+
size: content.byteLength,
|
|
283
|
+
type: "file"
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async list(prefix = "", options = {}) {
|
|
287
|
+
return await this.#mutate(async () => {
|
|
288
|
+
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
289
|
+
await this.#ensure({ refresh: true });
|
|
290
|
+
return await this.#listEntries(normalizedPrefix, options);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async glob(pattern, _options = {}) {
|
|
294
|
+
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
295
|
+
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
296
|
+
}
|
|
297
|
+
async stat(path) {
|
|
298
|
+
return await this.#mutate(async () => {
|
|
299
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
300
|
+
await this.#ensure({ refresh: true });
|
|
301
|
+
const file = this.#files.get(normalized);
|
|
302
|
+
if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
|
|
303
|
+
if (this.#directoryExists(normalized)) return {
|
|
304
|
+
path: normalized,
|
|
305
|
+
type: "directory"
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async mkdir(path, _options = {}) {
|
|
310
|
+
normalizeSafeWorkspacePath(path);
|
|
311
|
+
}
|
|
312
|
+
async rm(path, options = {}) {
|
|
313
|
+
await this.#mutate(async () => {
|
|
314
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
315
|
+
await this.#ensure({ refresh: false });
|
|
316
|
+
if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
|
|
317
|
+
this.#files.delete(normalized);
|
|
318
|
+
this.#dirty = true;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const children = this.#publicDescendants(normalized);
|
|
322
|
+
if (!(children.length > 0)) {
|
|
323
|
+
if (options.force) return;
|
|
324
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
325
|
+
}
|
|
326
|
+
if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
327
|
+
for (const child of children) this.#files.delete(child);
|
|
328
|
+
this.#dirty = true;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
async snapshot(options = {}) {
|
|
332
|
+
return await this.#mutate(async () => await this.#snapshot(options));
|
|
333
|
+
}
|
|
334
|
+
async rebase(options = {}) {
|
|
335
|
+
await this.#mutate(async () => {
|
|
336
|
+
await this.#ensure({ refresh: false });
|
|
337
|
+
const remote = await readGitHubBranchState({
|
|
338
|
+
branch: this.#branch,
|
|
339
|
+
kind: "store",
|
|
340
|
+
repository: this.#repository,
|
|
341
|
+
root: this.#root,
|
|
342
|
+
token: this.#token
|
|
343
|
+
});
|
|
344
|
+
const takeRemote = options.takeRemote || [];
|
|
345
|
+
const shouldTakeRemote = (path) => takeRemote.some((root) => path === root || path.startsWith(`${root}/`));
|
|
346
|
+
const local = new Map(this.#files);
|
|
347
|
+
const previousRemoteFiles = this.#remoteFiles;
|
|
348
|
+
const changed = new Set([...previousRemoteFiles.keys(), ...local.keys()]);
|
|
349
|
+
if (remote.refSha === this.#baselineRefSha) {
|
|
350
|
+
for (const path of changed) {
|
|
351
|
+
if (!shouldTakeRemote(path)) continue;
|
|
352
|
+
const file = remote.files.get(path);
|
|
353
|
+
if (file) this.#files.set(path, githubRemoteFile(path, file));
|
|
354
|
+
else this.#files.delete(path);
|
|
355
|
+
}
|
|
356
|
+
this.#dirty = [...new Set([...this.#remoteFiles.keys(), ...this.#files.keys()])].some((path) => !matchesGitHubRemote(this.#files.get(path), this.#remoteFiles.get(path)));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
for (const path of changed) {
|
|
360
|
+
if (matchesGitHubRemote(local.get(path), previousRemoteFiles.get(path))) {
|
|
361
|
+
changed.delete(path);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const previous = previousRemoteFiles.get(path);
|
|
365
|
+
const current = remote.files.get(path);
|
|
366
|
+
if (!sameGitHubTreeEntry(previous, current) && !shouldTakeRemote(path) && !matchesGitHubRemote(local.get(path), current)) throw workspaceConflict(`[vitehub] GitHub Workspace Store rebase conflict for ${this.#repository}@${this.#branch}: ${path} changed locally and remotely.`);
|
|
367
|
+
}
|
|
368
|
+
this.#baselineRefSha = remote.refSha;
|
|
369
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
370
|
+
this.#remoteFiles = remote.files;
|
|
371
|
+
this.#files = new Map([...remote.files].map(([path, entry]) => [path, githubRemoteFile(path, entry)]));
|
|
372
|
+
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }, false), "github-workspace-store-rebase");
|
|
373
|
+
for (const path of changed) {
|
|
374
|
+
if (shouldTakeRemote(path)) continue;
|
|
375
|
+
const file = local.get(path);
|
|
376
|
+
if (file) this.#files.set(path, file);
|
|
377
|
+
else this.#files.delete(path);
|
|
378
|
+
}
|
|
379
|
+
this.#dirty = [...new Set([...this.#remoteFiles.keys(), ...this.#files.keys()])].some((path) => !matchesGitHubRemote(this.#files.get(path), this.#remoteFiles.get(path)));
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
async #snapshot(options) {
|
|
383
|
+
await this.#ensure({ refresh: false });
|
|
384
|
+
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
385
|
+
if (!this.#dirty) {
|
|
386
|
+
this.#baseline = snapshot;
|
|
387
|
+
return snapshot;
|
|
388
|
+
}
|
|
389
|
+
const remote = await readGitHubBranchState({
|
|
390
|
+
branch: this.#branch,
|
|
391
|
+
kind: "store",
|
|
392
|
+
repository: this.#repository,
|
|
393
|
+
root: this.#root,
|
|
394
|
+
token: this.#token
|
|
395
|
+
});
|
|
396
|
+
if (this.#baselineRefSha && remote.refSha !== this.#baselineRefSha) throw workspaceConflict(`[vitehub] GitHub Workspace Store conflict for ${this.#repository}@${this.#branch}: the branch changed after this Workspace Store loaded. Snapshotting requires a Workspace Store loaded from the current branch head.`);
|
|
397
|
+
this.#remoteFiles = remote.files;
|
|
398
|
+
this.#baselineRefSha = remote.refSha;
|
|
399
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
400
|
+
const changedFiles = [...this.#files.values()].filter((file) => {
|
|
401
|
+
const remote = this.#remoteFiles.get(file.path);
|
|
402
|
+
return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
|
|
403
|
+
});
|
|
404
|
+
const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
|
|
405
|
+
if (!changedFiles.length && !deletePaths.length) {
|
|
406
|
+
this.#dirty = false;
|
|
407
|
+
this.#baseline = snapshot;
|
|
408
|
+
return snapshot;
|
|
409
|
+
}
|
|
410
|
+
const files = changedFiles.map((file) => {
|
|
411
|
+
return {
|
|
412
|
+
bytes: file.uploaded ? void 0 : file.bytes,
|
|
413
|
+
fullPath: joinGitPath(this.#root, file.path),
|
|
414
|
+
gitSha: file.gitSha,
|
|
415
|
+
mode: gitHubFileMode(file.metadata)
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
const commit = await commitGitHubChanges({
|
|
419
|
+
baseTreeSha: this.#baselineTreeSha,
|
|
420
|
+
branch: this.#branch,
|
|
421
|
+
branchExists: remote.branchExists,
|
|
422
|
+
deletePaths,
|
|
423
|
+
files,
|
|
424
|
+
message: options.name || "chore: update workspace snapshot",
|
|
425
|
+
parentSha: this.#baselineRefSha,
|
|
426
|
+
repository: this.#repository,
|
|
427
|
+
token: this.#token
|
|
428
|
+
});
|
|
429
|
+
this.#dirty = false;
|
|
430
|
+
this.#baselineRefSha = commit.commitSha;
|
|
431
|
+
this.#baselineTreeSha = commit.treeSha;
|
|
432
|
+
this.#remoteFiles = this.#toRemoteFiles();
|
|
433
|
+
this.#baseline = {
|
|
434
|
+
...snapshot,
|
|
435
|
+
id: commit.commitSha
|
|
436
|
+
};
|
|
437
|
+
return this.#baseline;
|
|
438
|
+
}
|
|
439
|
+
async diff(options = {}) {
|
|
440
|
+
return await this.#mutate(async () => {
|
|
441
|
+
await this.#ensure({ refresh: true });
|
|
442
|
+
const fromSnapshot = options.from || this.#baseline;
|
|
443
|
+
return diffSnapshots(fromSnapshot && {
|
|
444
|
+
...fromSnapshot,
|
|
445
|
+
entries: Object.fromEntries(Object.entries(fromSnapshot.entries).map(([path, entry]) => [path, {
|
|
446
|
+
...entry,
|
|
447
|
+
...entry.metadata?.gitMode === "120000" ? { metadata: {
|
|
448
|
+
...entry.metadata,
|
|
449
|
+
symlinkTarget: void 0
|
|
450
|
+
} } : {}
|
|
451
|
+
}]))
|
|
452
|
+
}, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }, false)));
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
async getMeta(key) {
|
|
456
|
+
return await this.#mutate(async () => {
|
|
457
|
+
await this.#ensure({ refresh: true });
|
|
458
|
+
const file = await this.#readWorkspaceFile(this.#metaPath(key));
|
|
459
|
+
if (!file) return void 0;
|
|
460
|
+
return JSON.parse(new TextDecoder().decode(file.bytes));
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
async setMeta(key, value) {
|
|
464
|
+
await this.#mutate(async () => {
|
|
465
|
+
const path = this.#metaPath(key);
|
|
466
|
+
const content = JSON.stringify(value);
|
|
467
|
+
const bytes = new TextEncoder().encode(content);
|
|
468
|
+
await this.#ensure({ refresh: false });
|
|
469
|
+
this.#files.set(path, {
|
|
470
|
+
bytes,
|
|
471
|
+
gitSha: await gitBlobSha(bytes),
|
|
472
|
+
path,
|
|
473
|
+
size: bytes.byteLength
|
|
474
|
+
});
|
|
475
|
+
this.#dirty = true;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
async #ensure(options) {
|
|
479
|
+
const wasReady = !!this.#ready;
|
|
480
|
+
this.#ready ||= this.#load();
|
|
481
|
+
await this.#ready;
|
|
482
|
+
if (wasReady && options.refresh && !this.#dirty) await this.#load();
|
|
483
|
+
}
|
|
484
|
+
async #load() {
|
|
485
|
+
const previousFiles = this.#files;
|
|
486
|
+
const remote = await readGitHubBranchState({
|
|
487
|
+
branch: this.#branch,
|
|
488
|
+
kind: "store",
|
|
489
|
+
repository: this.#repository,
|
|
490
|
+
root: this.#root,
|
|
491
|
+
token: this.#token
|
|
492
|
+
});
|
|
493
|
+
this.#baselineRefSha = remote.refSha;
|
|
494
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
495
|
+
this.#remoteFiles = remote.files;
|
|
496
|
+
if (!this.#dirty) {
|
|
497
|
+
this.#files = new Map([...remote.files].map(([path, entry]) => {
|
|
498
|
+
const previous = previousFiles.get(path);
|
|
499
|
+
return [path, {
|
|
500
|
+
...previous && previous.gitSha === entry.sha && gitHubFileMode(previous.metadata) === (entry.mode || "100644") ? { bytes: previous.bytes } : {},
|
|
501
|
+
gitSha: entry.sha,
|
|
502
|
+
metadata: gitHubFileMetadata(entry),
|
|
503
|
+
path,
|
|
504
|
+
size: entry.size
|
|
505
|
+
}];
|
|
506
|
+
}));
|
|
507
|
+
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }, false), "github-workspace-store-load");
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
|
|
511
|
+
const current = this.#files.get(path);
|
|
512
|
+
if (!current) return void 0;
|
|
513
|
+
const currentBytes = await this.#readFileBytes(current);
|
|
514
|
+
if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
|
|
515
|
+
const target = resolveSymlinkTarget(path, currentBytes);
|
|
516
|
+
if (target && this.#files.has(target)) {
|
|
517
|
+
seen.add(path);
|
|
518
|
+
const resolved = await this.#readWorkspaceFile(target, seen);
|
|
519
|
+
if (resolved) return {
|
|
520
|
+
...resolved,
|
|
521
|
+
mediaType: current.mediaType ?? resolved.mediaType,
|
|
522
|
+
metadata: await this.#fileMetadata(current) ?? resolved.metadata,
|
|
523
|
+
path
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
content: currentBytes,
|
|
529
|
+
bytes: currentBytes,
|
|
530
|
+
mediaType: current.mediaType,
|
|
531
|
+
metadata: await this.#fileMetadata(current),
|
|
532
|
+
path
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
async #readFileBytes(file) {
|
|
536
|
+
if (!file.bytes) {
|
|
537
|
+
file.bytes = await readGitHubRawFile({
|
|
538
|
+
path: joinGitPath(this.#root, file.path),
|
|
539
|
+
ref: this.#baselineRefSha,
|
|
540
|
+
repository: this.#repository,
|
|
541
|
+
token: this.#token
|
|
542
|
+
});
|
|
543
|
+
file.size = file.bytes.byteLength;
|
|
544
|
+
}
|
|
545
|
+
return file.bytes;
|
|
546
|
+
}
|
|
547
|
+
async #fileMetadata(file) {
|
|
548
|
+
if (gitHubFileMode(file.metadata) !== "120000" || readStringMetadata(file.metadata, "symlinkTarget") !== void 0) return file.metadata;
|
|
549
|
+
return {
|
|
550
|
+
...file.metadata,
|
|
551
|
+
symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
async #listEntries(prefix, options, resolveSymlinks = true) {
|
|
555
|
+
const entries = /* @__PURE__ */ new Map();
|
|
556
|
+
for (const file of this.#files.values()) {
|
|
557
|
+
if (isReservedWorkspacePath(file.path) || isExcludedWorkspacePath(file.path, options.exclude)) continue;
|
|
558
|
+
for (const dir of parentDirectories(file.path)) {
|
|
559
|
+
if (isExcludedWorkspacePath(dir, options.exclude)) continue;
|
|
560
|
+
if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
|
|
561
|
+
path: dir,
|
|
562
|
+
type: "directory"
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file, resolveSymlinks));
|
|
566
|
+
}
|
|
567
|
+
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
568
|
+
}
|
|
569
|
+
#entryInPrefix(path, prefix, options) {
|
|
570
|
+
if (!prefix) return options.recursive || !path.includes("/");
|
|
571
|
+
if (path === prefix) return false;
|
|
572
|
+
if (!path.startsWith(`${prefix}/`)) return false;
|
|
573
|
+
return options.recursive || !path.slice(prefix.length + 1).includes("/");
|
|
574
|
+
}
|
|
575
|
+
async #fileEntry(file, resolveSymlinks = true) {
|
|
576
|
+
return {
|
|
577
|
+
digest: file.gitSha,
|
|
578
|
+
mediaType: file.mediaType,
|
|
579
|
+
metadata: resolveSymlinks ? await this.#fileMetadata(file) : file.metadata,
|
|
580
|
+
path: file.path,
|
|
581
|
+
size: file.size,
|
|
582
|
+
type: "file"
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
#directoryExists(path) {
|
|
586
|
+
return this.#publicDescendants(path).length > 0;
|
|
587
|
+
}
|
|
588
|
+
#publicDescendants(path) {
|
|
589
|
+
return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
|
|
590
|
+
}
|
|
591
|
+
#metaPath(key) {
|
|
592
|
+
return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
|
|
593
|
+
}
|
|
594
|
+
#toRemoteFiles() {
|
|
595
|
+
return new Map([...this.#files.values()].map((file) => [file.path, {
|
|
596
|
+
path: joinGitPath(this.#root, file.path),
|
|
597
|
+
sha: file.gitSha,
|
|
598
|
+
size: file.size,
|
|
599
|
+
type: "blob",
|
|
600
|
+
mode: gitHubFileMode(file.metadata)
|
|
601
|
+
}]));
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
function createGitHubWorkspaceStore(options, workspaceName) {
|
|
605
|
+
return new GitHubWorkspaceStore(options, workspaceName);
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
export { createSnapshotFromEntries as a, createCurrentSnapshotFromStore as i, forwardWorkspaceRevisionMaterializer as n, diffSnapshots as o, resolveWorkspaceRevisionMaterializer as r, createGitHubWorkspaceStore as t };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath } from "./config
|
|
3
|
-
import {
|
|
1
|
+
import { _ as workspaceError, f as sha256, n as contentStreamToBytes } from "./path-Cp59koVz.js";
|
|
2
|
+
import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
|
|
3
|
+
import { c as workspaceSourceSyncStateEquals, o as readWorkspaceSourceSyncState, s as sourceSyncMetaKey } from "./workspace-Dq08Yn72.js";
|
|
4
|
+
import { m as normalizeSourceItemPath } from "./metadata-target-B0tOmVW7.js";
|
|
4
5
|
//#region src/sources/sync.ts
|
|
5
6
|
const sourceSyncLocks = /* @__PURE__ */ new Map();
|
|
6
7
|
function zeroCounts() {
|
|
@@ -55,7 +56,7 @@ function selectedSyncSources(definition, options) {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
async function getSourceItems(source, ctx) {
|
|
58
|
-
await source.source
|
|
59
|
+
await prepareWorkspaceSource(source.source, ctx);
|
|
59
60
|
if (source.source.getItems) return await source.source.getItems(ctx);
|
|
60
61
|
return await Promise.all((await source.source.getKeys(ctx)).map(async (key) => await source.source.getItem(key, ctx)));
|
|
61
62
|
}
|
|
@@ -177,7 +178,7 @@ async function snapshotSyncedWorkspace(definition, store, options) {
|
|
|
177
178
|
const snapshotOptions = typeof options.snapshot === "object" ? options.snapshot : {};
|
|
178
179
|
const snapshot = await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
|
|
179
180
|
if (options.publish) {
|
|
180
|
-
const { publishWorkspaceSnapshot } = await import("./lifecycle-
|
|
181
|
+
const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
181
182
|
await publishWorkspaceSnapshot(definition, store, snapshot);
|
|
182
183
|
}
|
|
183
184
|
return snapshot;
|
package/dist/test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerWorkspace } from "./registry-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-Uj6IVxes.js";
|
|
2
2
|
export { registerWorkspace };
|
package/dist/test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerWorkspace } from "./registry-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-D3yzt8HQ.js";
|
|
2
2
|
export { registerWorkspace };
|