@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
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import { i as
|
|
4
|
-
import {
|
|
1
|
+
import { _ as workspaceError, a as isExcludedWorkspacePath, c as normalizeSafeWorkspacePattern, f as sha256, g as workspaceConflict, l as normalizeWorkspacePath, o as matchesAny, p as assertWorkspaceDigest, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
|
+
import { n as isPlainObject } from "./config-CHLLWklZ.js";
|
|
3
|
+
import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, i as resolveGitHubWorkspaceStore, l as setWorkspaceHostedStoreLoader, r as resolveCloudflareArtifactsStore } from "./provider-B1yLjCJJ.js";
|
|
4
|
+
import { a as createSnapshotFromEntries, o as diffSnapshots, t as createGitHubWorkspaceStore } from "./store-Dt_Jyys3.js";
|
|
5
|
+
import { _ as getActiveCloudflareBinding } from "./shared-DTR1Hhma.js";
|
|
5
6
|
import { resolve } from "node:path";
|
|
6
7
|
//#region src/storage/memory-fs.ts
|
|
8
|
+
function copyBinaryData(data) {
|
|
9
|
+
if (ArrayBuffer.isView(data)) return Uint8Array.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
10
|
+
if (Object.prototype.toString.call(data) === "[object ArrayBuffer]") return Uint8Array.from(new Uint8Array(data));
|
|
11
|
+
}
|
|
7
12
|
var MemoryStats = class {
|
|
8
13
|
entry;
|
|
9
14
|
constructor(entry) {
|
|
@@ -72,49 +77,61 @@ var MemoryFS = class {
|
|
|
72
77
|
}
|
|
73
78
|
async mkdir(path, options) {
|
|
74
79
|
const target = this.normalize(path);
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
const recursive = isPlainObject(options) && options.recursive === true;
|
|
81
|
+
if (target === "/") {
|
|
82
|
+
if (recursive) return;
|
|
83
|
+
throw memoryFsError("EEXIST", path);
|
|
84
|
+
}
|
|
77
85
|
const parent = this.parent(target);
|
|
78
86
|
if (!this.entries.has(parent)) {
|
|
79
|
-
if (!recursive) throw
|
|
87
|
+
if (!recursive) throw memoryFsError("ENOENT", parent);
|
|
80
88
|
await this.mkdir(parent, { recursive: true });
|
|
81
89
|
}
|
|
82
|
-
|
|
90
|
+
const existing = this.entries.get(target);
|
|
91
|
+
if (existing) {
|
|
92
|
+
if (existing.kind === "dir" && recursive) return;
|
|
93
|
+
throw memoryFsError("EEXIST", path);
|
|
94
|
+
}
|
|
95
|
+
const parentEntry = this.#requireDir(parent);
|
|
83
96
|
this.entries.set(target, {
|
|
84
97
|
kind: "dir",
|
|
85
98
|
children: /* @__PURE__ */ new Set(),
|
|
86
99
|
mtimeMs: Date.now()
|
|
87
100
|
});
|
|
88
|
-
|
|
101
|
+
parentEntry.children.add(this.basename(target));
|
|
89
102
|
}
|
|
90
103
|
async writeFile(path, data) {
|
|
91
104
|
const target = this.normalize(path);
|
|
92
|
-
|
|
93
|
-
const
|
|
105
|
+
if (this.entries.get(target)?.kind === "dir") throw memoryFsError("EISDIR", path);
|
|
106
|
+
const parentPath = this.parent(target);
|
|
107
|
+
if (!this.entries.has(parentPath)) await this.mkdir(parentPath, { recursive: true });
|
|
108
|
+
const parent = this.#requireDir(parentPath);
|
|
109
|
+
const bytes = copyBinaryData(data) ?? this.#encoder.encode(String(data));
|
|
94
110
|
this.entries.set(target, {
|
|
95
111
|
kind: "file",
|
|
96
112
|
data: bytes,
|
|
97
113
|
mtimeMs: Date.now()
|
|
98
114
|
});
|
|
99
|
-
|
|
115
|
+
parent.children.add(this.basename(target));
|
|
100
116
|
}
|
|
101
117
|
async readFile(path, options) {
|
|
102
118
|
const entry = this.#requireEntry(path);
|
|
103
|
-
if (entry.kind !== "file") throw
|
|
104
|
-
return (
|
|
119
|
+
if (entry.kind !== "file") throw memoryFsError("EISDIR", path);
|
|
120
|
+
return (isPlainObject(options) ? options.encoding : options) ? this.#decoder.decode(entry.data) : Uint8Array.from(entry.data);
|
|
105
121
|
}
|
|
106
122
|
async readdir(path) {
|
|
107
123
|
return [...this.#requireDir(path).children].sort();
|
|
108
124
|
}
|
|
109
125
|
async unlink(path) {
|
|
110
126
|
const target = this.normalize(path);
|
|
111
|
-
if (this.#requireEntry(target).kind !== "file") throw
|
|
127
|
+
if (this.#requireEntry(target).kind !== "file") throw memoryFsError("EISDIR", path);
|
|
112
128
|
this.entries.delete(target);
|
|
113
129
|
this.#requireDir(this.parent(target)).children.delete(this.basename(target));
|
|
114
130
|
}
|
|
115
131
|
async rmdir(path) {
|
|
116
132
|
const target = this.normalize(path);
|
|
117
|
-
if (
|
|
133
|
+
if (target === "/") throw memoryFsError("EBUSY", path);
|
|
134
|
+
if (this.#requireDir(target).children.size) throw memoryFsError("ENOTEMPTY", path);
|
|
118
135
|
this.entries.delete(target);
|
|
119
136
|
this.#requireDir(this.parent(target)).children.delete(this.basename(target));
|
|
120
137
|
}
|
|
@@ -150,7 +167,7 @@ var MemoryFS = class {
|
|
|
150
167
|
}
|
|
151
168
|
#requireDir(path) {
|
|
152
169
|
const entry = this.#requireEntry(path);
|
|
153
|
-
if (entry.kind !== "dir") throw
|
|
170
|
+
if (entry.kind !== "dir") throw memoryFsError("ENOTDIR", path);
|
|
154
171
|
return entry;
|
|
155
172
|
}
|
|
156
173
|
};
|
|
@@ -162,6 +179,9 @@ function memoryFsError(code, path) {
|
|
|
162
179
|
const dir = "/workspace";
|
|
163
180
|
const fileMetadataPath = ".vitehub/files.json";
|
|
164
181
|
const tokenRefreshWindow = 6e4;
|
|
182
|
+
function sameSnapshotEntry(left, right) {
|
|
183
|
+
return left?.digest === right?.digest && left?.type === right?.type && left?.size === right?.size && JSON.stringify(left?.metadata) === JSON.stringify(right?.metadata);
|
|
184
|
+
}
|
|
165
185
|
function tokenSecret(token) {
|
|
166
186
|
return token.split("?expires=")[0] || token;
|
|
167
187
|
}
|
|
@@ -221,6 +241,9 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
221
241
|
async readFile(path) {
|
|
222
242
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
223
243
|
await this.#ensure();
|
|
244
|
+
return await this.#mutate(() => this.#readFile(normalized));
|
|
245
|
+
}
|
|
246
|
+
async #readFile(normalized) {
|
|
224
247
|
const filepath = this.#absolute(normalized);
|
|
225
248
|
const content = await this.#fs.promises.readFile(filepath).catch(() => void 0);
|
|
226
249
|
if (!content) return void 0;
|
|
@@ -233,21 +256,22 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
233
256
|
};
|
|
234
257
|
}
|
|
235
258
|
async writeFile(path, file) {
|
|
259
|
+
const normalized = normalizeSafeWorkspacePath(path);
|
|
260
|
+
await this.#ensure();
|
|
261
|
+
await this.#mutate(() => this.#writeFile(normalized, file));
|
|
262
|
+
}
|
|
263
|
+
async writeFileConditional(path, file, ifDigest) {
|
|
236
264
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
237
265
|
await this.#ensure();
|
|
238
266
|
await this.#mutate(async () => {
|
|
239
|
-
await this.#
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
metadata: file.metadata
|
|
243
|
-
});
|
|
244
|
-
else this.#files.delete(normalized);
|
|
245
|
-
await this.#writeFileMetadata();
|
|
267
|
+
const current = await this.#stat(normalized).catch(() => void 0);
|
|
268
|
+
assertWorkspaceDigest(normalized, ifDigest, current?.type === "file" ? current.digest : void 0);
|
|
269
|
+
await this.#writeFile(normalized, file);
|
|
246
270
|
});
|
|
247
271
|
}
|
|
248
272
|
async list(prefix = "", options = {}) {
|
|
249
273
|
await this.#ensure();
|
|
250
|
-
return this.#listEntries(prefix, options);
|
|
274
|
+
return await this.#mutate(() => this.#listEntries(prefix, options));
|
|
251
275
|
}
|
|
252
276
|
async #listEntries(prefix = "", options = {}) {
|
|
253
277
|
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
@@ -256,6 +280,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
256
280
|
if (absolute === dir || !absolute.startsWith(`${dir}/`)) continue;
|
|
257
281
|
const path = normalizeWorkspacePath(absolute.slice(`${dir}/`.length));
|
|
258
282
|
if (!path || path === ".git" || path.startsWith(".git/") || path === ".vitehub" || path.startsWith(".vitehub/")) continue;
|
|
283
|
+
if (isExcludedWorkspacePath(path, options.exclude)) continue;
|
|
259
284
|
if (normalizedPrefix) {
|
|
260
285
|
if (path === normalizedPrefix) continue;
|
|
261
286
|
if (!path.startsWith(`${normalizedPrefix}/`)) continue;
|
|
@@ -287,6 +312,9 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
287
312
|
async stat(path) {
|
|
288
313
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
289
314
|
await this.#ensure();
|
|
315
|
+
return await this.#mutate(() => this.#stat(normalized));
|
|
316
|
+
}
|
|
317
|
+
async #stat(normalized) {
|
|
290
318
|
const stat = await this.#fs.promises.stat(this.#absolute(normalized)).catch(() => void 0);
|
|
291
319
|
if (!stat) return void 0;
|
|
292
320
|
const bytes = stat.isFile() ? await this.#fs.promises.readFile(this.#absolute(normalized)) : void 0;
|
|
@@ -328,6 +356,55 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
328
356
|
await this.#ensure();
|
|
329
357
|
return this.#mutate(() => this.#createSnapshot(options));
|
|
330
358
|
}
|
|
359
|
+
async rebase(options = {}) {
|
|
360
|
+
await this.#ensure();
|
|
361
|
+
await this.#mutate(async () => {
|
|
362
|
+
const baseline = this.#baseline;
|
|
363
|
+
const current = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }));
|
|
364
|
+
const changes = diffSnapshots(baseline, current).entries.filter((change) => change.before?.type === "file" || change.after?.type === "file");
|
|
365
|
+
const local = /* @__PURE__ */ new Map();
|
|
366
|
+
for (const change of changes) local.set(change.path, change.after ? await this.#readFile(change.path) : void 0);
|
|
367
|
+
const previous = {
|
|
368
|
+
baseline: this.#baseline,
|
|
369
|
+
branch: this.#branch,
|
|
370
|
+
files: this.#files,
|
|
371
|
+
fs: this.#fs,
|
|
372
|
+
head: this.#head,
|
|
373
|
+
pendingCommit: this.#pendingCommit,
|
|
374
|
+
remote: this.#remote
|
|
375
|
+
};
|
|
376
|
+
const restore = () => {
|
|
377
|
+
this.#baseline = previous.baseline;
|
|
378
|
+
this.#branch = previous.branch;
|
|
379
|
+
this.#files = previous.files;
|
|
380
|
+
this.#fs = previous.fs;
|
|
381
|
+
this.#head = previous.head;
|
|
382
|
+
this.#pendingCommit = previous.pendingCommit;
|
|
383
|
+
this.#remote = previous.remote;
|
|
384
|
+
};
|
|
385
|
+
try {
|
|
386
|
+
this.#files = /* @__PURE__ */ new Map();
|
|
387
|
+
this.#pendingCommit = void 0;
|
|
388
|
+
await this.#load();
|
|
389
|
+
const remoteChanges = new Map(diffSnapshots(baseline, this.#baseline).entries.map((change) => [change.path, change]));
|
|
390
|
+
const takeRemote = new Set(options.takeRemote || []);
|
|
391
|
+
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.`);
|
|
392
|
+
for (const change of changes) {
|
|
393
|
+
if (remoteChanges.has(change.path) && takeRemote.has(change.path)) continue;
|
|
394
|
+
const file = local.get(change.path);
|
|
395
|
+
if (file) await this.#writeFile(change.path, file);
|
|
396
|
+
else {
|
|
397
|
+
this.#fs.deleteTree(this.#absolute(change.path));
|
|
398
|
+
this.#files.delete(change.path);
|
|
399
|
+
await this.#writeFileMetadata();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
} catch (error) {
|
|
403
|
+
restore();
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
331
408
|
async #createSnapshot(options) {
|
|
332
409
|
const git = await import("isomorphic-git");
|
|
333
410
|
const http = await import("isomorphic-git/http/web");
|
|
@@ -381,7 +458,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
381
458
|
url: this.#remote
|
|
382
459
|
});
|
|
383
460
|
} catch (error) {
|
|
384
|
-
if (isNonFastForward(error)) throw
|
|
461
|
+
if (isNonFastForward(error)) throw workspaceConflict(`[vitehub] Workspace "${this.workspaceName}" changed remotely while snapshotting branch "${this.#branch}". Reload the Workspace before retrying.`, { cause: error });
|
|
385
462
|
throw error;
|
|
386
463
|
}
|
|
387
464
|
this.#head = id;
|
|
@@ -396,20 +473,33 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
396
473
|
}
|
|
397
474
|
async diff(options = {}) {
|
|
398
475
|
await this.#ensure();
|
|
399
|
-
return
|
|
476
|
+
return await this.#mutate(async () => {
|
|
477
|
+
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
|
|
478
|
+
});
|
|
400
479
|
}
|
|
401
480
|
async getMeta(key) {
|
|
402
481
|
const path = this.#metaAbsolute(key);
|
|
403
482
|
await this.#ensure();
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
483
|
+
return await this.#mutate(async () => {
|
|
484
|
+
const content = await this.#fs.promises.readFile(path).catch(() => void 0);
|
|
485
|
+
if (!content) return void 0;
|
|
486
|
+
return JSON.parse(new TextDecoder().decode(contentToBytes(content)));
|
|
487
|
+
});
|
|
407
488
|
}
|
|
408
489
|
async setMeta(key, value) {
|
|
409
490
|
const path = this.#metaAbsolute(key);
|
|
410
491
|
await this.#ensure();
|
|
411
492
|
await this.#mutate(() => this.#fs.promises.writeFile(path, contentToBytes(JSON.stringify(value))));
|
|
412
493
|
}
|
|
494
|
+
async #writeFile(path, file) {
|
|
495
|
+
await this.#fs.promises.writeFile(this.#absolute(path), contentToBytes(file.content));
|
|
496
|
+
if (file.mediaType !== void 0 || file.metadata !== void 0) this.#files.set(path, {
|
|
497
|
+
mediaType: file.mediaType,
|
|
498
|
+
metadata: file.metadata
|
|
499
|
+
});
|
|
500
|
+
else this.#files.delete(path);
|
|
501
|
+
await this.#writeFileMetadata();
|
|
502
|
+
}
|
|
413
503
|
#absolute(path) {
|
|
414
504
|
return `${dir}/${path}`;
|
|
415
505
|
}
|
|
@@ -566,7 +656,7 @@ function installHostedWorkspaceRuntime() {
|
|
|
566
656
|
}
|
|
567
657
|
function configureHostedWorkspaceRuntime(options = {}) {
|
|
568
658
|
const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
|
|
569
|
-
const store = options.store?.provider === "github" ? resolveGitHubWorkspaceStore(options.store, options.env, { runtime: true }) : options.store?.provider === "vercel-blob" ? void 0 : resolveCloudflareArtifactsStore(options.store, options.env);
|
|
659
|
+
const store = options.store?.provider === "github" ? resolveGitHubWorkspaceStore(options.store, options.env || {}, { runtime: true }) : options.store?.provider === "vercel-blob" ? void 0 : resolveCloudflareArtifactsStore(options.store, options.env);
|
|
570
660
|
if (!store) throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime must use @vite-hub/workspace/internal/runtime/hosted-vercel-blob.");
|
|
571
661
|
const config = {
|
|
572
662
|
assets: options.assets,
|