@vite-hub/workspace 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -17
- package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +137 -102
- package/dist/index.js +479 -594
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/nitro.d.ts +2 -31
- package/dist/nitro.js +2 -2
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
- package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
- package/dist/providers/cloudflare/artifacts-store.js +1 -383
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +1 -1
- package/dist/providers/vercel/blob-store.js +77 -18
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +2 -1
- package/dist/runtime/assets.js +5 -5
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +4 -21
- package/dist/runtime/state.js +7 -4
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +158 -62
- package/dist/asset-registry-CMuQbyvl.js +0 -14
- package/dist/cloudflare-env-DL94Uvpz.js +0 -12
- package/dist/config-CvS-7sre.js +0 -49
- package/dist/errors-BUL8SoFS.js +0 -21
- package/dist/lifecycle-uD82JeGh.js +0 -92
- package/dist/module-8LZUMEXC.js +0 -922
- package/dist/path-BVv9OXhg.js +0 -63
- package/dist/registry-Cnr0NoKv.js +0 -932
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- package/dist/sandbox-DtGXCWRq.js +0 -198
- package/dist/types-CwNcWTdt.d.ts +0 -378
- /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { a as matchesAny, c as normalizeWorkspacePath, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
|
|
2
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
|
|
3
|
+
import { r as workspaceStoreTarget } from "../../target-D4Bqb1eH.js";
|
|
4
|
+
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-BRycRSbo.js";
|
|
5
|
+
import { posix } from "node:path";
|
|
6
|
+
//#region src/providers/github/store.ts
|
|
7
|
+
function isReservedWorkspacePath(path) {
|
|
8
|
+
const root = normalizeWorkspacePath(path).split("/")[0];
|
|
9
|
+
return root === ".git" || root === ".vitehub";
|
|
10
|
+
}
|
|
11
|
+
function contentLength(content) {
|
|
12
|
+
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
13
|
+
}
|
|
14
|
+
function gitHubFileMetadata(entry) {
|
|
15
|
+
return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
|
|
16
|
+
}
|
|
17
|
+
function gitHubFileMode(metadata) {
|
|
18
|
+
return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
|
|
19
|
+
}
|
|
20
|
+
function inheritedGitHubFileMetadata(file, current) {
|
|
21
|
+
if (file.metadata) return file.metadata;
|
|
22
|
+
return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
|
|
23
|
+
}
|
|
24
|
+
function parentDirectories(path) {
|
|
25
|
+
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
26
|
+
const directories = [];
|
|
27
|
+
for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
|
|
28
|
+
return directories;
|
|
29
|
+
}
|
|
30
|
+
function resolveSymlinkTarget(path, bytes) {
|
|
31
|
+
const target = gitSymlinkTargetFromBytes(bytes);
|
|
32
|
+
if (!target || target.startsWith("/")) return;
|
|
33
|
+
const base = path.split("/").slice(0, -1).join("/");
|
|
34
|
+
const resolved = posix.normalize(base ? `${base}/${target}` : target);
|
|
35
|
+
if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
|
|
36
|
+
return normalizeSafeWorkspacePath(resolved);
|
|
37
|
+
}
|
|
38
|
+
function gitSymlinkTargetFromBytes(bytes) {
|
|
39
|
+
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
|
40
|
+
}
|
|
41
|
+
var GitHubWorkspaceStore = class {
|
|
42
|
+
workspaceName;
|
|
43
|
+
#baseline;
|
|
44
|
+
#baselineRefSha;
|
|
45
|
+
#baselineTreeSha;
|
|
46
|
+
#branch;
|
|
47
|
+
#dirty = false;
|
|
48
|
+
#files = /* @__PURE__ */ new Map();
|
|
49
|
+
#ready;
|
|
50
|
+
#remoteFiles = /* @__PURE__ */ new Map();
|
|
51
|
+
#repository;
|
|
52
|
+
#root;
|
|
53
|
+
#token;
|
|
54
|
+
constructor(options, workspaceName) {
|
|
55
|
+
this.workspaceName = workspaceName;
|
|
56
|
+
this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
|
|
57
|
+
this.#branch = resolveGitHubBranchOption(options);
|
|
58
|
+
this.#root = resolveGitHubRootOption(options, workspaceName);
|
|
59
|
+
this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
|
|
60
|
+
}
|
|
61
|
+
[workspaceStoreTarget]() {
|
|
62
|
+
return {
|
|
63
|
+
provider: "github",
|
|
64
|
+
branch: this.#branch,
|
|
65
|
+
repository: this.#repository
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async readFile(path) {
|
|
69
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
70
|
+
await this.#ensure({ refresh: true });
|
|
71
|
+
return await this.#readWorkspaceFile(normalized);
|
|
72
|
+
}
|
|
73
|
+
async writeFile(path, file) {
|
|
74
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
75
|
+
await this.#ensure({ refresh: false });
|
|
76
|
+
const current = this.#files.get(normalized);
|
|
77
|
+
const metadata = inheritedGitHubFileMetadata(file, current);
|
|
78
|
+
const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
|
|
79
|
+
const update = await createGitHubFileUpdate(normalized, this.#root, content);
|
|
80
|
+
if (current?.gitSha === update.gitSha) {
|
|
81
|
+
if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
|
|
82
|
+
this.#files.set(normalized, {
|
|
83
|
+
...current,
|
|
84
|
+
mediaType: file.mediaType,
|
|
85
|
+
metadata,
|
|
86
|
+
size: contentLength(content)
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await createGitHubBlob({
|
|
91
|
+
bytes: update.bytes,
|
|
92
|
+
kind: "store",
|
|
93
|
+
repository: this.#repository,
|
|
94
|
+
token: this.#token
|
|
95
|
+
});
|
|
96
|
+
this.#files.set(normalized, {
|
|
97
|
+
gitSha: update.gitSha,
|
|
98
|
+
mediaType: file.mediaType,
|
|
99
|
+
metadata,
|
|
100
|
+
path: normalized,
|
|
101
|
+
size: contentLength(content)
|
|
102
|
+
});
|
|
103
|
+
this.#dirty = true;
|
|
104
|
+
}
|
|
105
|
+
async writeFileStream(path, file) {
|
|
106
|
+
const content = await contentStreamToBytes(file.content);
|
|
107
|
+
await this.writeFile(path, {
|
|
108
|
+
path: file.path,
|
|
109
|
+
content,
|
|
110
|
+
mediaType: file.mediaType,
|
|
111
|
+
metadata: file.metadata
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
digest: await gitBlobSha(content),
|
|
115
|
+
mediaType: file.mediaType,
|
|
116
|
+
path: normalizeSafeWorkspacePath(path),
|
|
117
|
+
size: content.byteLength,
|
|
118
|
+
type: "file"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async list(prefix = "", options = {}) {
|
|
122
|
+
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
123
|
+
await this.#ensure({ refresh: true });
|
|
124
|
+
return await this.#listEntries(normalizedPrefix, options);
|
|
125
|
+
}
|
|
126
|
+
async glob(pattern, _options = {}) {
|
|
127
|
+
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
128
|
+
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
129
|
+
}
|
|
130
|
+
async stat(path) {
|
|
131
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
132
|
+
await this.#ensure({ refresh: true });
|
|
133
|
+
const file = this.#files.get(normalized);
|
|
134
|
+
if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
|
|
135
|
+
if (this.#directoryExists(normalized)) return {
|
|
136
|
+
path: normalized,
|
|
137
|
+
type: "directory"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async mkdir(path, _options = {}) {
|
|
141
|
+
normalizeSafeWorkspacePath(path);
|
|
142
|
+
}
|
|
143
|
+
async rm(path, options = {}) {
|
|
144
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
145
|
+
await this.#ensure({ refresh: false });
|
|
146
|
+
if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
|
|
147
|
+
this.#files.delete(normalized);
|
|
148
|
+
this.#dirty = true;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const children = this.#publicDescendants(normalized);
|
|
152
|
+
if (!(children.length > 0)) {
|
|
153
|
+
if (options.force) return;
|
|
154
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
155
|
+
}
|
|
156
|
+
if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
157
|
+
for (const child of children) this.#files.delete(child);
|
|
158
|
+
this.#dirty = true;
|
|
159
|
+
}
|
|
160
|
+
async snapshot(options = {}) {
|
|
161
|
+
await this.#ensure({ refresh: false });
|
|
162
|
+
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
163
|
+
if (!this.#dirty) {
|
|
164
|
+
this.#baseline = snapshot;
|
|
165
|
+
return snapshot;
|
|
166
|
+
}
|
|
167
|
+
const remote = await readGitHubBranchState({
|
|
168
|
+
branch: this.#branch,
|
|
169
|
+
kind: "store",
|
|
170
|
+
repository: this.#repository,
|
|
171
|
+
root: this.#root,
|
|
172
|
+
token: this.#token
|
|
173
|
+
});
|
|
174
|
+
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.`);
|
|
175
|
+
this.#remoteFiles = remote.files;
|
|
176
|
+
this.#baselineRefSha = remote.refSha;
|
|
177
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
178
|
+
const changedFiles = [...this.#files.values()].filter((file) => {
|
|
179
|
+
const remote = this.#remoteFiles.get(file.path);
|
|
180
|
+
return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
|
|
181
|
+
});
|
|
182
|
+
const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
|
|
183
|
+
if (!changedFiles.length && !deletePaths.length) {
|
|
184
|
+
this.#dirty = false;
|
|
185
|
+
this.#baseline = snapshot;
|
|
186
|
+
return snapshot;
|
|
187
|
+
}
|
|
188
|
+
const files = changedFiles.map((file) => {
|
|
189
|
+
return {
|
|
190
|
+
bytes: file.bytes,
|
|
191
|
+
fullPath: joinGitPath(this.#root, file.path),
|
|
192
|
+
gitSha: file.gitSha,
|
|
193
|
+
mode: gitHubFileMode(file.metadata)
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
const commit = await commitGitHubChanges({
|
|
197
|
+
baseTreeSha: this.#baselineTreeSha,
|
|
198
|
+
branch: this.#branch,
|
|
199
|
+
branchExists: remote.branchExists,
|
|
200
|
+
deletePaths,
|
|
201
|
+
files,
|
|
202
|
+
message: options.name || "chore: update workspace snapshot",
|
|
203
|
+
parentSha: this.#baselineRefSha,
|
|
204
|
+
repository: this.#repository,
|
|
205
|
+
token: this.#token
|
|
206
|
+
});
|
|
207
|
+
this.#dirty = false;
|
|
208
|
+
this.#baselineRefSha = commit.commitSha;
|
|
209
|
+
this.#baselineTreeSha = commit.treeSha;
|
|
210
|
+
this.#remoteFiles = this.#toRemoteFiles();
|
|
211
|
+
this.#baseline = {
|
|
212
|
+
...snapshot,
|
|
213
|
+
id: commit.commitSha
|
|
214
|
+
};
|
|
215
|
+
return this.#baseline;
|
|
216
|
+
}
|
|
217
|
+
async diff(options = {}) {
|
|
218
|
+
await this.#ensure({ refresh: true });
|
|
219
|
+
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
|
|
220
|
+
}
|
|
221
|
+
async getMeta(key) {
|
|
222
|
+
await this.#ensure({ refresh: true });
|
|
223
|
+
const file = await this.#readWorkspaceFile(this.#metaPath(key));
|
|
224
|
+
if (!file) return void 0;
|
|
225
|
+
return JSON.parse(new TextDecoder().decode(file.bytes));
|
|
226
|
+
}
|
|
227
|
+
async setMeta(key, value) {
|
|
228
|
+
const path = this.#metaPath(key);
|
|
229
|
+
const content = JSON.stringify(value);
|
|
230
|
+
const bytes = new TextEncoder().encode(content);
|
|
231
|
+
await this.#ensure({ refresh: false });
|
|
232
|
+
this.#files.set(path, {
|
|
233
|
+
bytes,
|
|
234
|
+
gitSha: await gitBlobSha(bytes),
|
|
235
|
+
path,
|
|
236
|
+
size: bytes.byteLength
|
|
237
|
+
});
|
|
238
|
+
this.#dirty = true;
|
|
239
|
+
}
|
|
240
|
+
async #ensure(options) {
|
|
241
|
+
const wasReady = !!this.#ready;
|
|
242
|
+
this.#ready ||= this.#load();
|
|
243
|
+
await this.#ready;
|
|
244
|
+
if (wasReady && options.refresh && !this.#dirty) await this.#load();
|
|
245
|
+
}
|
|
246
|
+
async #load() {
|
|
247
|
+
const remote = await readGitHubBranchState({
|
|
248
|
+
branch: this.#branch,
|
|
249
|
+
kind: "store",
|
|
250
|
+
repository: this.#repository,
|
|
251
|
+
root: this.#root,
|
|
252
|
+
token: this.#token
|
|
253
|
+
});
|
|
254
|
+
this.#baselineRefSha = remote.refSha;
|
|
255
|
+
this.#baselineTreeSha = remote.treeSha;
|
|
256
|
+
this.#remoteFiles = remote.files;
|
|
257
|
+
if (!this.#dirty) {
|
|
258
|
+
this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
|
|
259
|
+
gitSha: entry.sha,
|
|
260
|
+
metadata: gitHubFileMetadata(entry),
|
|
261
|
+
path,
|
|
262
|
+
size: entry.size
|
|
263
|
+
}]));
|
|
264
|
+
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
|
|
268
|
+
const current = this.#files.get(path);
|
|
269
|
+
if (!current) return void 0;
|
|
270
|
+
const currentBytes = await this.#readFileBytes(current);
|
|
271
|
+
if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
|
|
272
|
+
const target = resolveSymlinkTarget(path, currentBytes);
|
|
273
|
+
if (target && this.#files.has(target)) {
|
|
274
|
+
seen.add(path);
|
|
275
|
+
const resolved = await this.#readWorkspaceFile(target, seen);
|
|
276
|
+
if (resolved) return {
|
|
277
|
+
...resolved,
|
|
278
|
+
mediaType: current.mediaType ?? resolved.mediaType,
|
|
279
|
+
metadata: await this.#fileMetadata(current) ?? resolved.metadata,
|
|
280
|
+
path
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
content: currentBytes,
|
|
286
|
+
bytes: currentBytes,
|
|
287
|
+
mediaType: current.mediaType,
|
|
288
|
+
metadata: await this.#fileMetadata(current),
|
|
289
|
+
path
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async #readFileBytes(file) {
|
|
293
|
+
if (!file.bytes) {
|
|
294
|
+
file.bytes = await readGitHubBlob({
|
|
295
|
+
kind: "store",
|
|
296
|
+
repository: this.#repository,
|
|
297
|
+
sha: file.gitSha,
|
|
298
|
+
token: this.#token
|
|
299
|
+
});
|
|
300
|
+
file.size = file.bytes.byteLength;
|
|
301
|
+
}
|
|
302
|
+
return file.bytes;
|
|
303
|
+
}
|
|
304
|
+
async #fileMetadata(file) {
|
|
305
|
+
if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
|
|
306
|
+
return {
|
|
307
|
+
...file.metadata,
|
|
308
|
+
symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async #listEntries(prefix, options) {
|
|
312
|
+
const entries = /* @__PURE__ */ new Map();
|
|
313
|
+
for (const file of this.#files.values()) {
|
|
314
|
+
if (isReservedWorkspacePath(file.path)) continue;
|
|
315
|
+
for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
|
|
316
|
+
path: dir,
|
|
317
|
+
type: "directory"
|
|
318
|
+
});
|
|
319
|
+
if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
|
|
320
|
+
}
|
|
321
|
+
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
322
|
+
}
|
|
323
|
+
#entryInPrefix(path, prefix, options) {
|
|
324
|
+
if (!prefix) return options.recursive || !path.includes("/");
|
|
325
|
+
if (path === prefix) return false;
|
|
326
|
+
if (!path.startsWith(`${prefix}/`)) return false;
|
|
327
|
+
return options.recursive || !path.slice(prefix.length + 1).includes("/");
|
|
328
|
+
}
|
|
329
|
+
async #fileEntry(file) {
|
|
330
|
+
return {
|
|
331
|
+
digest: file.gitSha,
|
|
332
|
+
mediaType: file.mediaType,
|
|
333
|
+
metadata: await this.#fileMetadata(file),
|
|
334
|
+
path: file.path,
|
|
335
|
+
size: file.size,
|
|
336
|
+
type: "file"
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
#directoryExists(path) {
|
|
340
|
+
return this.#publicDescendants(path).length > 0;
|
|
341
|
+
}
|
|
342
|
+
#publicDescendants(path) {
|
|
343
|
+
return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
|
|
344
|
+
}
|
|
345
|
+
#metaPath(key) {
|
|
346
|
+
return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
|
|
347
|
+
}
|
|
348
|
+
#toRemoteFiles() {
|
|
349
|
+
return new Map([...this.#files.values()].map((file) => [file.path, {
|
|
350
|
+
path: joinGitPath(this.#root, file.path),
|
|
351
|
+
sha: file.gitSha,
|
|
352
|
+
size: file.size,
|
|
353
|
+
type: "blob",
|
|
354
|
+
mode: gitHubFileMode(file.metadata)
|
|
355
|
+
}]));
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
function createGitHubWorkspaceStore(options, workspaceName) {
|
|
359
|
+
return new GitHubWorkspaceStore(options, workspaceName);
|
|
360
|
+
}
|
|
361
|
+
//#endregion
|
|
362
|
+
export { createGitHubWorkspaceStore };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Zt as WorkspaceStore, w as VercelBlobWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/vercel/blob-store.d.ts
|
|
4
4
|
declare function createVercelBlobWorkspaceStore(options: VercelBlobWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { r as
|
|
4
|
-
import { n as diffSnapshots, t as createSnapshotFromEntries } from "../../utils-BtAm_K5P.js";
|
|
1
|
+
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
|
|
2
|
+
import { a as resolveRuntimeVercelBlobWorkspaceStore } from "../../provider-CeQciesl.js";
|
|
3
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
|
|
5
4
|
//#region src/providers/vercel/blob-store.ts
|
|
6
5
|
function joinBlobPath(...parts) {
|
|
7
6
|
return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
|
|
@@ -11,16 +10,80 @@ function contentType(path, fallback) {
|
|
|
11
10
|
if (path.endsWith(".json")) return "application/json; charset=utf-8";
|
|
12
11
|
if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
function auth(options) {
|
|
14
|
+
return options.token ? { token: options.token } : {};
|
|
15
|
+
}
|
|
16
|
+
async function createVercelBlobClient(options) {
|
|
17
|
+
const blob = await importVercelBlobPeer();
|
|
18
|
+
const access = options.access || "private";
|
|
19
|
+
return {
|
|
20
|
+
async delete(key) {
|
|
21
|
+
await blob.del(key, auth(options));
|
|
22
|
+
},
|
|
23
|
+
async download(key) {
|
|
24
|
+
const result = await blob.get(key, {
|
|
25
|
+
access,
|
|
26
|
+
...auth(options)
|
|
27
|
+
});
|
|
28
|
+
if (!result || result.statusCode !== 200 || !result.stream) throw Object.assign(/* @__PURE__ */ new Error("not found"), { code: "NotFound" });
|
|
29
|
+
return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
|
|
30
|
+
},
|
|
31
|
+
async head(key) {
|
|
32
|
+
const result = await blob.head(key, auth(options));
|
|
33
|
+
return {
|
|
34
|
+
key: result.pathname,
|
|
35
|
+
lastModified: result.uploadedAt.getTime(),
|
|
36
|
+
size: result.size,
|
|
37
|
+
type: result.contentType
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
async list(optionsInput) {
|
|
41
|
+
const result = await blob.list({
|
|
42
|
+
...optionsInput,
|
|
43
|
+
...auth(options)
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
cursor: result.cursor,
|
|
47
|
+
items: result.blobs.map((item) => ({
|
|
48
|
+
key: item.pathname,
|
|
49
|
+
lastModified: item.uploadedAt?.getTime(),
|
|
50
|
+
size: item.size
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
async upload(key, body, uploadOptions = {}) {
|
|
55
|
+
await blob.put(key, body, {
|
|
56
|
+
access,
|
|
57
|
+
addRandomSuffix: false,
|
|
58
|
+
allowOverwrite: true,
|
|
59
|
+
contentType: uploadOptions.contentType,
|
|
60
|
+
...auth(options)
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const vercelBlobPeerSpecifier = "@vercel/blob";
|
|
66
|
+
async function importVercelBlobPeer() {
|
|
67
|
+
try {
|
|
68
|
+
const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
|
|
69
|
+
if (testImport) return await testImport();
|
|
70
|
+
return await import(vercelBlobPeerSpecifier);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
handleVercelBlobImportError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function handleVercelBlobImportError(error) {
|
|
76
|
+
if (isMissingVercelBlobError(error)) throw workspaceError("[vitehub] @vercel/blob is required for the Vercel Blob Workspace Store. Package: @vercel/blob.", { cause: error });
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
function isMissingVercelBlobError(error) {
|
|
80
|
+
if (!(error instanceof Error)) return false;
|
|
81
|
+
const code = error.code;
|
|
82
|
+
if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") return false;
|
|
83
|
+
return error.message.includes("Cannot find package '@vercel/blob'") || error.message.includes("Cannot find module '@vercel/blob'");
|
|
22
84
|
}
|
|
23
85
|
var VercelBlobWorkspaceStore = class {
|
|
86
|
+
workspaceName;
|
|
24
87
|
#baseline;
|
|
25
88
|
#options;
|
|
26
89
|
#files;
|
|
@@ -35,7 +98,7 @@ var VercelBlobWorkspaceStore = class {
|
|
|
35
98
|
return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
|
|
36
99
|
}
|
|
37
100
|
async #client() {
|
|
38
|
-
this.#files ||=
|
|
101
|
+
this.#files ||= createVercelBlobClient(this.#options);
|
|
39
102
|
return await this.#files;
|
|
40
103
|
}
|
|
41
104
|
#metaKey(key) {
|
|
@@ -127,7 +190,7 @@ var VercelBlobWorkspaceStore = class {
|
|
|
127
190
|
else if (options.recursive) for (const blob of await this.#listBlobs(`${this.#fileKey(normalized)}/`)) targets.push(blob.key);
|
|
128
191
|
if (!targets.length) {
|
|
129
192
|
if (options.force) return;
|
|
130
|
-
throw
|
|
193
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
131
194
|
}
|
|
132
195
|
await Promise.all(targets.map((target) => client.delete(target)));
|
|
133
196
|
}
|
|
@@ -160,10 +223,6 @@ var VercelBlobWorkspaceStore = class {
|
|
|
160
223
|
} while (cursor);
|
|
161
224
|
return blobs;
|
|
162
225
|
}
|
|
163
|
-
async #readBytes(path) {
|
|
164
|
-
const file = await this.readFile(path);
|
|
165
|
-
return file ? contentToBytes(file.content) : void 0;
|
|
166
|
-
}
|
|
167
226
|
async #readJson(pathname) {
|
|
168
227
|
const file = await (await this.#client()).download(pathname).catch(() => null);
|
|
169
228
|
return file ? JSON.parse(await file.text()) : void 0;
|
package/dist/publish.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as GitHubWorkspaceOption, dt as WorkspacePublisher } from "./types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/publishers/manifest.d.ts
|
|
4
4
|
interface ManifestPublisherOptions {
|
|
@@ -7,9 +7,10 @@ interface ManifestPublisherOptions {
|
|
|
7
7
|
declare function manifest(options?: ManifestPublisherOptions): WorkspacePublisher;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/publishers/github.d.ts
|
|
10
|
-
type GitHubPublisherOption =
|
|
10
|
+
type GitHubPublisherOption = GitHubWorkspaceOption;
|
|
11
11
|
interface GitHubPublisherOptions {
|
|
12
12
|
branch?: GitHubPublisherOption;
|
|
13
|
+
deleteUntracked?: boolean;
|
|
13
14
|
message?: GitHubPublisherOption;
|
|
14
15
|
repo?: GitHubPublisherOption;
|
|
15
16
|
repository?: GitHubPublisherOption;
|