@vite-hub/workspace 0.0.3 → 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 +13 -2
- package/dist/{ai-Ce3PtWFW.js → ai-BqCC8BpY.js} +2 -2
- package/dist/{ai-nmHdzjCM.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 +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config-CZLO0m9h.js → config-Bc3c4Su1.js} +213 -120
- package/dist/{config-CDoyls2X.js → config-CHLLWklZ.js} +9 -3
- package/dist/{config-3I1BnsdO.d.ts → config-DE9xlaIw.d.ts} +1 -1
- package/dist/{file-CHfsZpso.js → file-Bc1X7pco.js} +3 -3
- package/dist/{files-QRV55OCx.js → files-Q6xZjDHA.js} +20 -9
- package/dist/{github-CfA5vpJ5.js → github-DHnjxQIX.js} +24 -15
- package/dist/{glob-D0vD_wRY.js → glob-CEZKeZFC.js} +5 -4
- package/dist/host-DJH8cuoU.js +1030 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-RPeJOCFz.js} +121 -31
- 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 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +42 -51
- package/dist/index.js +124 -419
- 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 +1 -1
- 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-C3_elpEh.js → provider-B1yLjCJJ.js} +194 -47
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +2 -2
- package/dist/registry-D3yzt8HQ.js +127 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Uj6IVxes.d.ts} +3 -3
- package/dist/{request-execution-u9mgUXKX.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-type-iEE6BjQJ.js +34 -0
- package/dist/runtime.d.ts +42 -7
- package/dist/runtime.js +275 -82
- package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +23 -50
- package/dist/{shared-jfogBrd5.js → shared-DTR1Hhma.js} +97 -39
- package/dist/source-metadata.d.ts +9 -2
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-tYcRWEh2.d.ts} +13 -12
- package/dist/store-Dt_Jyys3.js +608 -0
- package/dist/{sync-DiuDmSGk.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-60Yn149G.d.ts → types-CYuwjJ4V.d.ts} +94 -27
- package/dist/{use-CsV3oIxH.js → use-BTNDR5Rd.js} +145 -31
- package/dist/{use-CUFSnFCS.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-C4k92Ow8.js → workspace-Dq08Yn72.js} +224 -529
- package/dist/{workspace-66SKyiec.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
- package/package.json +15 -18
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
package/dist/store-Bs1SLh55.js
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
-
import { c as readGitHubBlob, d as resolveGitHubBranchOption, h as resolveGitHubTokenOption, i as gitBlobSha, l as readGitHubBranchState, m as resolveGitHubRootOption, n as createGitHubBlob, o as joinGitPath, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-jfogBrd5.js";
|
|
4
|
-
import { posix } from "node:path";
|
|
5
|
-
//#region src/storage/utils.ts
|
|
6
|
-
async function createCurrentSnapshotFromStore(store, name) {
|
|
7
|
-
return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
|
|
8
|
-
}
|
|
9
|
-
async function createSnapshotFromEntries(entries, name) {
|
|
10
|
-
const snapshotEntries = {};
|
|
11
|
-
for (const entry of entries) snapshotEntries[entry.path] = {
|
|
12
|
-
digest: entry.digest,
|
|
13
|
-
metadata: entry.metadata,
|
|
14
|
-
size: entry.size,
|
|
15
|
-
type: entry.type
|
|
16
|
-
};
|
|
17
|
-
return {
|
|
18
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19
|
-
entries: snapshotEntries,
|
|
20
|
-
id: await sha256({
|
|
21
|
-
entries: snapshotEntries,
|
|
22
|
-
name,
|
|
23
|
-
createdAt: Date.now()
|
|
24
|
-
}),
|
|
25
|
-
name
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function diffSnapshots(from, to) {
|
|
29
|
-
const entries = [];
|
|
30
|
-
const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
|
|
31
|
-
for (const path of [...keys].sort()) {
|
|
32
|
-
const before = from?.entries[path];
|
|
33
|
-
const after = to.entries[path];
|
|
34
|
-
if (!before && after) entries.push({
|
|
35
|
-
path,
|
|
36
|
-
type: "added",
|
|
37
|
-
after
|
|
38
|
-
});
|
|
39
|
-
else if (before && !after) entries.push({
|
|
40
|
-
path,
|
|
41
|
-
type: "removed",
|
|
42
|
-
before
|
|
43
|
-
});
|
|
44
|
-
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({
|
|
45
|
-
path,
|
|
46
|
-
type: "modified",
|
|
47
|
-
before,
|
|
48
|
-
after
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
from: from?.id,
|
|
53
|
-
to: to.id,
|
|
54
|
-
entries
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/providers/github/store.ts
|
|
59
|
-
function isReservedWorkspacePath(path) {
|
|
60
|
-
const root = normalizeWorkspacePath(path).split("/")[0];
|
|
61
|
-
return root === ".git" || root === ".vitehub";
|
|
62
|
-
}
|
|
63
|
-
function contentLength(content) {
|
|
64
|
-
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
65
|
-
}
|
|
66
|
-
function gitHubFileMetadata(entry) {
|
|
67
|
-
return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
|
|
68
|
-
}
|
|
69
|
-
function gitHubFileMode(metadata) {
|
|
70
|
-
return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
|
|
71
|
-
}
|
|
72
|
-
function inheritedGitHubFileMetadata(file, current) {
|
|
73
|
-
if (file.metadata) return file.metadata;
|
|
74
|
-
return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
|
|
75
|
-
}
|
|
76
|
-
function parentDirectories(path) {
|
|
77
|
-
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
78
|
-
const directories = [];
|
|
79
|
-
for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
|
|
80
|
-
return directories;
|
|
81
|
-
}
|
|
82
|
-
function resolveSymlinkTarget(path, bytes) {
|
|
83
|
-
const target = gitSymlinkTargetFromBytes(bytes);
|
|
84
|
-
if (!target || target.startsWith("/")) return;
|
|
85
|
-
const base = path.split("/").slice(0, -1).join("/");
|
|
86
|
-
const resolved = posix.normalize(base ? `${base}/${target}` : target);
|
|
87
|
-
if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
|
|
88
|
-
return normalizeSafeWorkspacePath(resolved);
|
|
89
|
-
}
|
|
90
|
-
function gitSymlinkTargetFromBytes(bytes) {
|
|
91
|
-
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
|
92
|
-
}
|
|
93
|
-
var GitHubWorkspaceStore = class {
|
|
94
|
-
workspaceName;
|
|
95
|
-
#baseline;
|
|
96
|
-
#baselineRefSha;
|
|
97
|
-
#baselineTreeSha;
|
|
98
|
-
#branch;
|
|
99
|
-
#dirty = false;
|
|
100
|
-
#files = /* @__PURE__ */ new Map();
|
|
101
|
-
#ready;
|
|
102
|
-
#remoteFiles = /* @__PURE__ */ new Map();
|
|
103
|
-
#repository;
|
|
104
|
-
#root;
|
|
105
|
-
#token;
|
|
106
|
-
constructor(options, workspaceName) {
|
|
107
|
-
this.workspaceName = workspaceName;
|
|
108
|
-
this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
|
|
109
|
-
this.#branch = resolveGitHubBranchOption(options);
|
|
110
|
-
this.#root = resolveGitHubRootOption(options, workspaceName);
|
|
111
|
-
this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
|
|
112
|
-
}
|
|
113
|
-
[workspaceStoreTarget]() {
|
|
114
|
-
return {
|
|
115
|
-
provider: "github",
|
|
116
|
-
branch: this.#branch,
|
|
117
|
-
repository: this.#repository
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async readFile(path) {
|
|
121
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
122
|
-
await this.#ensure({ refresh: true });
|
|
123
|
-
return await this.#readWorkspaceFile(normalized);
|
|
124
|
-
}
|
|
125
|
-
async writeFile(path, file) {
|
|
126
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
127
|
-
await this.#ensure({ refresh: false });
|
|
128
|
-
const current = this.#files.get(normalized);
|
|
129
|
-
const metadata = inheritedGitHubFileMetadata(file, current);
|
|
130
|
-
const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
|
|
131
|
-
const update = await createGitHubFileUpdate(normalized, this.#root, content);
|
|
132
|
-
if (current?.gitSha === update.gitSha) {
|
|
133
|
-
if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
|
|
134
|
-
this.#files.set(normalized, {
|
|
135
|
-
...current,
|
|
136
|
-
mediaType: file.mediaType,
|
|
137
|
-
metadata,
|
|
138
|
-
size: contentLength(content)
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
await createGitHubBlob({
|
|
143
|
-
bytes: update.bytes,
|
|
144
|
-
kind: "store",
|
|
145
|
-
repository: this.#repository,
|
|
146
|
-
token: this.#token
|
|
147
|
-
});
|
|
148
|
-
this.#files.set(normalized, {
|
|
149
|
-
gitSha: update.gitSha,
|
|
150
|
-
mediaType: file.mediaType,
|
|
151
|
-
metadata,
|
|
152
|
-
path: normalized,
|
|
153
|
-
size: contentLength(content)
|
|
154
|
-
});
|
|
155
|
-
this.#dirty = true;
|
|
156
|
-
}
|
|
157
|
-
async writeFileStream(path, file) {
|
|
158
|
-
const content = await contentStreamToBytes(file.content);
|
|
159
|
-
await this.writeFile(path, {
|
|
160
|
-
path: file.path,
|
|
161
|
-
content,
|
|
162
|
-
mediaType: file.mediaType,
|
|
163
|
-
metadata: file.metadata
|
|
164
|
-
});
|
|
165
|
-
return {
|
|
166
|
-
digest: await gitBlobSha(content),
|
|
167
|
-
mediaType: file.mediaType,
|
|
168
|
-
path: normalizeSafeWorkspacePath(path),
|
|
169
|
-
size: content.byteLength,
|
|
170
|
-
type: "file"
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
async list(prefix = "", options = {}) {
|
|
174
|
-
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
175
|
-
await this.#ensure({ refresh: true });
|
|
176
|
-
return await this.#listEntries(normalizedPrefix, options);
|
|
177
|
-
}
|
|
178
|
-
async glob(pattern, _options = {}) {
|
|
179
|
-
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
180
|
-
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
181
|
-
}
|
|
182
|
-
async stat(path) {
|
|
183
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
184
|
-
await this.#ensure({ refresh: true });
|
|
185
|
-
const file = this.#files.get(normalized);
|
|
186
|
-
if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
|
|
187
|
-
if (this.#directoryExists(normalized)) return {
|
|
188
|
-
path: normalized,
|
|
189
|
-
type: "directory"
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
async mkdir(path, _options = {}) {
|
|
193
|
-
normalizeSafeWorkspacePath(path);
|
|
194
|
-
}
|
|
195
|
-
async rm(path, options = {}) {
|
|
196
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
197
|
-
await this.#ensure({ refresh: false });
|
|
198
|
-
if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
|
|
199
|
-
this.#files.delete(normalized);
|
|
200
|
-
this.#dirty = true;
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
const children = this.#publicDescendants(normalized);
|
|
204
|
-
if (!(children.length > 0)) {
|
|
205
|
-
if (options.force) return;
|
|
206
|
-
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
207
|
-
}
|
|
208
|
-
if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
209
|
-
for (const child of children) this.#files.delete(child);
|
|
210
|
-
this.#dirty = true;
|
|
211
|
-
}
|
|
212
|
-
async snapshot(options = {}) {
|
|
213
|
-
await this.#ensure({ refresh: false });
|
|
214
|
-
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
215
|
-
if (!this.#dirty) {
|
|
216
|
-
this.#baseline = snapshot;
|
|
217
|
-
return snapshot;
|
|
218
|
-
}
|
|
219
|
-
const remote = await readGitHubBranchState({
|
|
220
|
-
branch: this.#branch,
|
|
221
|
-
kind: "store",
|
|
222
|
-
repository: this.#repository,
|
|
223
|
-
root: this.#root,
|
|
224
|
-
token: this.#token
|
|
225
|
-
});
|
|
226
|
-
if (this.#baselineRefSha && remote.refSha !== this.#baselineRefSha) throw workspaceError(`[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.`);
|
|
227
|
-
this.#remoteFiles = remote.files;
|
|
228
|
-
this.#baselineRefSha = remote.refSha;
|
|
229
|
-
this.#baselineTreeSha = remote.treeSha;
|
|
230
|
-
const changedFiles = [...this.#files.values()].filter((file) => {
|
|
231
|
-
const remote = this.#remoteFiles.get(file.path);
|
|
232
|
-
return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
|
|
233
|
-
});
|
|
234
|
-
const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
|
|
235
|
-
if (!changedFiles.length && !deletePaths.length) {
|
|
236
|
-
this.#dirty = false;
|
|
237
|
-
this.#baseline = snapshot;
|
|
238
|
-
return snapshot;
|
|
239
|
-
}
|
|
240
|
-
const files = changedFiles.map((file) => {
|
|
241
|
-
return {
|
|
242
|
-
bytes: file.bytes,
|
|
243
|
-
fullPath: joinGitPath(this.#root, file.path),
|
|
244
|
-
gitSha: file.gitSha,
|
|
245
|
-
mode: gitHubFileMode(file.metadata)
|
|
246
|
-
};
|
|
247
|
-
});
|
|
248
|
-
const commit = await commitGitHubChanges({
|
|
249
|
-
baseTreeSha: this.#baselineTreeSha,
|
|
250
|
-
branch: this.#branch,
|
|
251
|
-
branchExists: remote.branchExists,
|
|
252
|
-
deletePaths,
|
|
253
|
-
files,
|
|
254
|
-
message: options.name || "chore: update workspace snapshot",
|
|
255
|
-
parentSha: this.#baselineRefSha,
|
|
256
|
-
repository: this.#repository,
|
|
257
|
-
token: this.#token
|
|
258
|
-
});
|
|
259
|
-
this.#dirty = false;
|
|
260
|
-
this.#baselineRefSha = commit.commitSha;
|
|
261
|
-
this.#baselineTreeSha = commit.treeSha;
|
|
262
|
-
this.#remoteFiles = this.#toRemoteFiles();
|
|
263
|
-
this.#baseline = {
|
|
264
|
-
...snapshot,
|
|
265
|
-
id: commit.commitSha
|
|
266
|
-
};
|
|
267
|
-
return this.#baseline;
|
|
268
|
-
}
|
|
269
|
-
async diff(options = {}) {
|
|
270
|
-
await this.#ensure({ refresh: true });
|
|
271
|
-
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
|
|
272
|
-
}
|
|
273
|
-
async getMeta(key) {
|
|
274
|
-
await this.#ensure({ refresh: true });
|
|
275
|
-
const file = await this.#readWorkspaceFile(this.#metaPath(key));
|
|
276
|
-
if (!file) return void 0;
|
|
277
|
-
return JSON.parse(new TextDecoder().decode(file.bytes));
|
|
278
|
-
}
|
|
279
|
-
async setMeta(key, value) {
|
|
280
|
-
const path = this.#metaPath(key);
|
|
281
|
-
const content = JSON.stringify(value);
|
|
282
|
-
const bytes = new TextEncoder().encode(content);
|
|
283
|
-
await this.#ensure({ refresh: false });
|
|
284
|
-
this.#files.set(path, {
|
|
285
|
-
bytes,
|
|
286
|
-
gitSha: await gitBlobSha(bytes),
|
|
287
|
-
path,
|
|
288
|
-
size: bytes.byteLength
|
|
289
|
-
});
|
|
290
|
-
this.#dirty = true;
|
|
291
|
-
}
|
|
292
|
-
async #ensure(options) {
|
|
293
|
-
const wasReady = !!this.#ready;
|
|
294
|
-
this.#ready ||= this.#load();
|
|
295
|
-
await this.#ready;
|
|
296
|
-
if (wasReady && options.refresh && !this.#dirty) await this.#load();
|
|
297
|
-
}
|
|
298
|
-
async #load() {
|
|
299
|
-
const remote = await readGitHubBranchState({
|
|
300
|
-
branch: this.#branch,
|
|
301
|
-
kind: "store",
|
|
302
|
-
repository: this.#repository,
|
|
303
|
-
root: this.#root,
|
|
304
|
-
token: this.#token
|
|
305
|
-
});
|
|
306
|
-
this.#baselineRefSha = remote.refSha;
|
|
307
|
-
this.#baselineTreeSha = remote.treeSha;
|
|
308
|
-
this.#remoteFiles = remote.files;
|
|
309
|
-
if (!this.#dirty) {
|
|
310
|
-
this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
|
|
311
|
-
gitSha: entry.sha,
|
|
312
|
-
metadata: gitHubFileMetadata(entry),
|
|
313
|
-
path,
|
|
314
|
-
size: entry.size
|
|
315
|
-
}]));
|
|
316
|
-
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
|
|
320
|
-
const current = this.#files.get(path);
|
|
321
|
-
if (!current) return void 0;
|
|
322
|
-
const currentBytes = await this.#readFileBytes(current);
|
|
323
|
-
if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
|
|
324
|
-
const target = resolveSymlinkTarget(path, currentBytes);
|
|
325
|
-
if (target && this.#files.has(target)) {
|
|
326
|
-
seen.add(path);
|
|
327
|
-
const resolved = await this.#readWorkspaceFile(target, seen);
|
|
328
|
-
if (resolved) return {
|
|
329
|
-
...resolved,
|
|
330
|
-
mediaType: current.mediaType ?? resolved.mediaType,
|
|
331
|
-
metadata: await this.#fileMetadata(current) ?? resolved.metadata,
|
|
332
|
-
path
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return {
|
|
337
|
-
content: currentBytes,
|
|
338
|
-
bytes: currentBytes,
|
|
339
|
-
mediaType: current.mediaType,
|
|
340
|
-
metadata: await this.#fileMetadata(current),
|
|
341
|
-
path
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
async #readFileBytes(file) {
|
|
345
|
-
if (!file.bytes) {
|
|
346
|
-
file.bytes = await readGitHubBlob({
|
|
347
|
-
kind: "store",
|
|
348
|
-
repository: this.#repository,
|
|
349
|
-
sha: file.gitSha,
|
|
350
|
-
token: this.#token
|
|
351
|
-
});
|
|
352
|
-
file.size = file.bytes.byteLength;
|
|
353
|
-
}
|
|
354
|
-
return file.bytes;
|
|
355
|
-
}
|
|
356
|
-
async #fileMetadata(file) {
|
|
357
|
-
if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
|
|
358
|
-
return {
|
|
359
|
-
...file.metadata,
|
|
360
|
-
symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
async #listEntries(prefix, options) {
|
|
364
|
-
const entries = /* @__PURE__ */ new Map();
|
|
365
|
-
for (const file of this.#files.values()) {
|
|
366
|
-
if (isReservedWorkspacePath(file.path)) continue;
|
|
367
|
-
for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
|
|
368
|
-
path: dir,
|
|
369
|
-
type: "directory"
|
|
370
|
-
});
|
|
371
|
-
if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
|
|
372
|
-
}
|
|
373
|
-
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
374
|
-
}
|
|
375
|
-
#entryInPrefix(path, prefix, options) {
|
|
376
|
-
if (!prefix) return options.recursive || !path.includes("/");
|
|
377
|
-
if (path === prefix) return false;
|
|
378
|
-
if (!path.startsWith(`${prefix}/`)) return false;
|
|
379
|
-
return options.recursive || !path.slice(prefix.length + 1).includes("/");
|
|
380
|
-
}
|
|
381
|
-
async #fileEntry(file) {
|
|
382
|
-
return {
|
|
383
|
-
digest: file.gitSha,
|
|
384
|
-
mediaType: file.mediaType,
|
|
385
|
-
metadata: await this.#fileMetadata(file),
|
|
386
|
-
path: file.path,
|
|
387
|
-
size: file.size,
|
|
388
|
-
type: "file"
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
#directoryExists(path) {
|
|
392
|
-
return this.#publicDescendants(path).length > 0;
|
|
393
|
-
}
|
|
394
|
-
#publicDescendants(path) {
|
|
395
|
-
return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
|
|
396
|
-
}
|
|
397
|
-
#metaPath(key) {
|
|
398
|
-
return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
|
|
399
|
-
}
|
|
400
|
-
#toRemoteFiles() {
|
|
401
|
-
return new Map([...this.#files.values()].map((file) => [file.path, {
|
|
402
|
-
path: joinGitPath(this.#root, file.path),
|
|
403
|
-
sha: file.gitSha,
|
|
404
|
-
size: file.size,
|
|
405
|
-
type: "blob",
|
|
406
|
-
mode: gitHubFileMode(file.metadata)
|
|
407
|
-
}]));
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
function createGitHubWorkspaceStore(options, workspaceName) {
|
|
411
|
-
return new GitHubWorkspaceStore(options, workspaceName);
|
|
412
|
-
}
|
|
413
|
-
//#endregion
|
|
414
|
-
export { diffSnapshots as i, createCurrentSnapshotFromStore as n, createSnapshotFromEntries as r, createGitHubWorkspaceStore as t };
|