@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
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as createWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-
|
|
4
|
-
import { s as createMemoryWorkspaceStore, t as createWorkspaceStoreFromProvider } from "./provider-
|
|
1
|
+
import { _ as workspaceError, a as isExcludedWorkspacePath, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, o as matchesAny, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
|
+
import { _ as workspaceSourceRequestDescriptorPath, a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, n as createSourceContext, s as sourceMountContainsPath, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
|
|
3
|
+
import { n as createWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-B-dSFlGB.js";
|
|
4
|
+
import { s as createMemoryWorkspaceStore, t as createWorkspaceStoreFromProvider } from "./provider-B1yLjCJJ.js";
|
|
5
|
+
import { n as forwardWorkspaceRevisionMaterializer } from "./store-Dt_Jyys3.js";
|
|
5
6
|
import { t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
6
|
-
import { t as
|
|
7
|
-
import {
|
|
7
|
+
import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
|
|
8
|
+
import { t as searchText } from "./search-BpiCF2Tw.js";
|
|
9
|
+
import { a as hasFreshSourceSnapshot, c as readCurrentSourceSnapshot, i as hasCurrentSourceSnapshot, l as readResolvedSourceFile, o as materializeWorkspaceSources, p as statVirtualSourcePath, r as workspaceMetadataTarget, s as materializesCompleteSource, u as searchMaterializedStore } from "./metadata-target-B0tOmVW7.js";
|
|
8
10
|
import { minimatch } from "minimatch";
|
|
9
11
|
import { noExecutionAuthority } from "@vite-hub/runtime";
|
|
10
12
|
//#region src/session/scope.ts
|
|
@@ -319,497 +321,6 @@ function resolveWorkspaceAutoCommit(definition, diff) {
|
|
|
319
321
|
};
|
|
320
322
|
}
|
|
321
323
|
//#endregion
|
|
322
|
-
//#region src/sources/source-items.ts
|
|
323
|
-
function normalizeWorkspaceSourceItemPath(source, rawSourcePath, options = {}) {
|
|
324
|
-
const sourcePath = normalizeSafeWorkspacePath(rawSourcePath, {
|
|
325
|
-
allowEmpty: false,
|
|
326
|
-
allowReserved: true
|
|
327
|
-
});
|
|
328
|
-
const label = options.operation ? `${options.operation} item path` : "source item path";
|
|
329
|
-
if (sourcePath.split("/").some((part) => part === ".git" || part === ".vitehub")) throw workspaceError(`[vitehub] Workspace ${label} is reserved: ${rawSourcePath}.`);
|
|
330
|
-
const path = normalizeSafeWorkspacePath(source.mountPath ? `${source.mountPath}/${sourcePath}` : sourcePath, { allowEmpty: false });
|
|
331
|
-
if (source.mountPath && !sourceMountContainsPath(source, path)) throw workspaceError(`[vitehub] Workspace ${label} escapes source mount: ${rawSourcePath}.`);
|
|
332
|
-
return {
|
|
333
|
-
path,
|
|
334
|
-
sourcePath
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function normalizeSourceItemPath(source, item, options = {}) {
|
|
338
|
-
return normalizeWorkspaceSourceItemPath(source, item.path || item.key, options);
|
|
339
|
-
}
|
|
340
|
-
//#endregion
|
|
341
|
-
//#region src/sources/materialization.ts
|
|
342
|
-
function sourceSnapshotMetaKey(sourceKey) {
|
|
343
|
-
return `source:${sourceKey}:snapshot`;
|
|
344
|
-
}
|
|
345
|
-
function sourceConfigFingerprint(source) {
|
|
346
|
-
return {
|
|
347
|
-
cache: source.cache,
|
|
348
|
-
key: source.key,
|
|
349
|
-
materialize: source.materialize,
|
|
350
|
-
mountPath: source.mountPath,
|
|
351
|
-
source: source.source.fingerprint
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
async function sourceConfigHash(source) {
|
|
355
|
-
return await sha256(sourceConfigFingerprint(source));
|
|
356
|
-
}
|
|
357
|
-
function isSnapshotFresh(meta, source, configHash) {
|
|
358
|
-
if (!meta || meta.status !== "ready" || meta.configHash !== configHash) return false;
|
|
359
|
-
if (!source.cache || typeof source.cache.maxAge !== "number") return false;
|
|
360
|
-
if (!meta.materializedAt) return false;
|
|
361
|
-
return Date.now() - Date.parse(meta.materializedAt) <= source.cache.maxAge * 1e3;
|
|
362
|
-
}
|
|
363
|
-
async function readSourceSnapshotMetadata(store, sourceKey) {
|
|
364
|
-
return await store.getMeta?.(sourceSnapshotMetaKey(sourceKey));
|
|
365
|
-
}
|
|
366
|
-
async function hasCurrentSourceSnapshot(store, source) {
|
|
367
|
-
const configHash = await sourceConfigHash(source);
|
|
368
|
-
const meta = await readSourceSnapshotMetadata(store, source.key);
|
|
369
|
-
return meta?.status === "ready" && meta.configHash === configHash;
|
|
370
|
-
}
|
|
371
|
-
async function writeSourceSnapshotMetadata(store, metadata) {
|
|
372
|
-
await store.setMeta?.(sourceSnapshotMetaKey(metadata.source), metadata);
|
|
373
|
-
}
|
|
374
|
-
function materializedItemMeta(snapshot, configHash, path) {
|
|
375
|
-
if (!snapshot || snapshot.configHash !== configHash) return void 0;
|
|
376
|
-
if (snapshot.status !== "ready" && snapshot.status !== "updating" && snapshot.status !== "error") return void 0;
|
|
377
|
-
return snapshot.items?.[path];
|
|
378
|
-
}
|
|
379
|
-
function checkpointItems(items) {
|
|
380
|
-
return Object.keys(items).length ? items : void 0;
|
|
381
|
-
}
|
|
382
|
-
function contentSize(content) {
|
|
383
|
-
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
384
|
-
}
|
|
385
|
-
function sourcePathMatches(path, source, options) {
|
|
386
|
-
if (options?.sources?.length && !options.sources.includes(source.key)) return false;
|
|
387
|
-
const requested = normalizeWorkspacePath(options?.path || "");
|
|
388
|
-
if (!requested) return true;
|
|
389
|
-
return sourceMountIntersectsPath(source, requested);
|
|
390
|
-
}
|
|
391
|
-
function pathContains(container, path) {
|
|
392
|
-
return !container || path === container || path.startsWith(`${container}/`);
|
|
393
|
-
}
|
|
394
|
-
function materializationPathMatches(path, options) {
|
|
395
|
-
return pathContains(normalizeWorkspacePath(options?.path || ""), path);
|
|
396
|
-
}
|
|
397
|
-
function materializesCompleteSource(source, options) {
|
|
398
|
-
const requested = normalizeWorkspacePath(options?.path || "");
|
|
399
|
-
return !requested || Boolean(source.mountPath && pathContains(requested, source.mountPath));
|
|
400
|
-
}
|
|
401
|
-
function shouldMaterializeSource(source, options) {
|
|
402
|
-
if (source.requestOnly || !sourcePathMatches("", source, options)) return false;
|
|
403
|
-
if (source.materialize === "lazy") return true;
|
|
404
|
-
return source.materialize === "build" && Boolean(options?.path);
|
|
405
|
-
}
|
|
406
|
-
function throwIfAborted(signal) {
|
|
407
|
-
if (!signal?.aborted) return;
|
|
408
|
-
throw signal.reason instanceof Error ? signal.reason : workspaceError("[vitehub] Workspace source materialization aborted.");
|
|
409
|
-
}
|
|
410
|
-
async function reportMaterializationProgress(options, source, event) {
|
|
411
|
-
await options?.onProgress?.({
|
|
412
|
-
...event,
|
|
413
|
-
mountPath: source.mountPath,
|
|
414
|
-
path: normalizeWorkspacePath(options?.path || ""),
|
|
415
|
-
source: source.key
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
function shouldReportMaterializationUpdate(lastReportedAt, files) {
|
|
419
|
-
return files === 1 || files % 25 === 0 || Date.now() - lastReportedAt >= 1e3;
|
|
420
|
-
}
|
|
421
|
-
function looksLikeConcreteFilePath(path) {
|
|
422
|
-
const name = posix.basename(path);
|
|
423
|
-
return name.includes(".") || [
|
|
424
|
-
"Dockerfile",
|
|
425
|
-
"LICENSE",
|
|
426
|
-
"Makefile",
|
|
427
|
-
"Procfile",
|
|
428
|
-
"README"
|
|
429
|
-
].includes(name);
|
|
430
|
-
}
|
|
431
|
-
function directMaterializationSourceKey(source, options) {
|
|
432
|
-
const requested = normalizeWorkspacePath(options?.path || "");
|
|
433
|
-
if (!requested || !sourceMountContainsPath(source, requested) || requested === source.mountPath) return;
|
|
434
|
-
const sourcePath = source.mountPath ? requested.slice(source.mountPath.length + 1) : requested;
|
|
435
|
-
return sourcePath && looksLikeConcreteFilePath(sourcePath) ? sourcePath : void 0;
|
|
436
|
-
}
|
|
437
|
-
function parentDirectoryPaths(path) {
|
|
438
|
-
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
439
|
-
const paths = [];
|
|
440
|
-
for (let index = 1; index < parts.length; index++) paths.push(parts.slice(0, index).join("/"));
|
|
441
|
-
return paths;
|
|
442
|
-
}
|
|
443
|
-
async function removeStaleMaterializedSourceFiles(store, source, nextPaths, scope, options = {}) {
|
|
444
|
-
const entries = await store.list(source.mountPath, { recursive: true });
|
|
445
|
-
const nextDirectories = new Set([...nextPaths].flatMap((path) => parentDirectoryPaths(path)));
|
|
446
|
-
const staleDirectories = /* @__PURE__ */ new Set();
|
|
447
|
-
for (const entry of entries) {
|
|
448
|
-
if (!materializationPathMatches(entry.path, scope)) continue;
|
|
449
|
-
if (nextPaths.has(entry.path) || entry.type !== "file") continue;
|
|
450
|
-
const file = await store.readFile(entry.path);
|
|
451
|
-
if (options.removeUntracked || file?.metadata?.source === source.key) {
|
|
452
|
-
for (const directory of parentDirectoryPaths(entry.path)) staleDirectories.add(directory);
|
|
453
|
-
await store.rm(entry.path, { force: true });
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
for (const entry of entries.filter((entry) => entry.type === "directory" && staleDirectories.has(entry.path) && !nextDirectories.has(entry.path)).sort((a, b) => b.path.length - a.path.length)) try {
|
|
457
|
-
await store.rm(entry.path, { force: true });
|
|
458
|
-
} catch {}
|
|
459
|
-
}
|
|
460
|
-
async function* iterateSourceItems(source, ctx) {
|
|
461
|
-
if (source.source.getItems) {
|
|
462
|
-
yield* await source.source.getItems(ctx);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
for (const key of await source.source.getKeys(ctx)) yield await source.source.getItem(key, ctx);
|
|
466
|
-
}
|
|
467
|
-
function createMaterializationEntry(source, item, upstreamMeta) {
|
|
468
|
-
const { path, sourcePath } = normalizeSourceItemPath(source, item, { operation: "source materialization" });
|
|
469
|
-
return {
|
|
470
|
-
item,
|
|
471
|
-
metadata: createLazyMaterializedMetadata({
|
|
472
|
-
sourceKey: source.key,
|
|
473
|
-
sourcePath,
|
|
474
|
-
validate: source.validate
|
|
475
|
-
}, item, upstreamMeta),
|
|
476
|
-
path,
|
|
477
|
-
...sourceItemContent$1(item)
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
function sourceItemContent$1(item) {
|
|
481
|
-
if (item.contentStream) {
|
|
482
|
-
if (typeof item.content !== "undefined" || typeof item.data !== "undefined") throw workspaceError("[vitehub] Workspace source items cannot define contentStream with content or data.");
|
|
483
|
-
return { contentStream: item.contentStream };
|
|
484
|
-
}
|
|
485
|
-
return { content: item.content ?? (typeof item.data === "undefined" ? "" : JSON.stringify(item.data, null, 2)) };
|
|
486
|
-
}
|
|
487
|
-
async function* iterateMaterializationEntries(source, ctx, store, snapshot, configHash, options) {
|
|
488
|
-
const directKey = directMaterializationSourceKey(source, options);
|
|
489
|
-
if (directKey) {
|
|
490
|
-
const entry = createMaterializationEntry(source, await source.source.getItem(directKey, ctx), void 0);
|
|
491
|
-
if (materializationPathMatches(entry.path, options)) yield entry;
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
if (source.source.getItems) {
|
|
495
|
-
for await (const item of iterateSourceItems(source, ctx)) {
|
|
496
|
-
const entry = createMaterializationEntry(source, item, await source.source.getMeta?.(item.key, ctx));
|
|
497
|
-
if (materializationPathMatches(entry.path, options)) yield entry;
|
|
498
|
-
}
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
for (const key of await source.source.getKeys(ctx)) {
|
|
502
|
-
const upstreamMeta = await source.source.getMeta?.(key, ctx);
|
|
503
|
-
const { path, sourcePath } = normalizeWorkspaceSourceItemPath(source, key, { operation: "source materialization" });
|
|
504
|
-
if (!materializationPathMatches(path, options)) continue;
|
|
505
|
-
const previous = materializedItemMeta(snapshot, configHash, path);
|
|
506
|
-
if (upstreamMeta && previous?.source === source.key && previous.sourcePath === sourcePath && !hasSourceMetaChanged(previous, upstreamMeta)) {
|
|
507
|
-
const stat = await store.stat(path);
|
|
508
|
-
if (stat?.type === "file") {
|
|
509
|
-
yield {
|
|
510
|
-
metadata: previous,
|
|
511
|
-
path,
|
|
512
|
-
reused: stat
|
|
513
|
-
};
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
yield createMaterializationEntry(source, await source.source.getItem(key, ctx), upstreamMeta);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
async function materializeWorkspaceSources(definition, store, options = {}) {
|
|
521
|
-
const started = Date.now();
|
|
522
|
-
const sources = normalizeWorkspaceSources(definition.sources).filter((source) => shouldMaterializeSource(source, options));
|
|
523
|
-
const resultSources = [];
|
|
524
|
-
let files = 0;
|
|
525
|
-
let directories = 0;
|
|
526
|
-
let bytes = 0;
|
|
527
|
-
for (const source of sources) {
|
|
528
|
-
throwIfAborted(options.abortSignal);
|
|
529
|
-
const sourceStarted = Date.now();
|
|
530
|
-
await reportMaterializationProgress(options, source, { status: "started" });
|
|
531
|
-
const configHash = await sourceConfigHash(source);
|
|
532
|
-
const existing = await readSourceSnapshotMetadata(store, source.key);
|
|
533
|
-
const completeSource = materializesCompleteSource(source, options);
|
|
534
|
-
if (completeSource && isSnapshotFresh(existing, source, configHash)) {
|
|
535
|
-
resultSources.push({
|
|
536
|
-
source: source.key,
|
|
537
|
-
mountPath: source.mountPath,
|
|
538
|
-
status: "ready",
|
|
539
|
-
commit: existing?.commit,
|
|
540
|
-
materializedAt: existing?.materializedAt,
|
|
541
|
-
files: existing?.files,
|
|
542
|
-
bytes: existing?.bytes
|
|
543
|
-
});
|
|
544
|
-
files += existing?.files || 0;
|
|
545
|
-
bytes += existing?.bytes || 0;
|
|
546
|
-
await reportMaterializationProgress(options, source, {
|
|
547
|
-
bytes: existing?.bytes || 0,
|
|
548
|
-
durationMs: Date.now() - sourceStarted,
|
|
549
|
-
files: existing?.files || 0,
|
|
550
|
-
status: "completed"
|
|
551
|
-
});
|
|
552
|
-
continue;
|
|
553
|
-
}
|
|
554
|
-
const itemMetadata = existing?.configHash === configHash ? { ...existing.items || {} } : {};
|
|
555
|
-
if (completeSource) await writeSourceSnapshotMetadata(store, {
|
|
556
|
-
configHash,
|
|
557
|
-
source: source.key,
|
|
558
|
-
mountPath: source.mountPath,
|
|
559
|
-
status: "updating",
|
|
560
|
-
items: checkpointItems(itemMetadata),
|
|
561
|
-
cacheMaxAge: source.cache ? source.cache.maxAge : void 0
|
|
562
|
-
});
|
|
563
|
-
let sourceFiles = 0;
|
|
564
|
-
let sourceBytes = 0;
|
|
565
|
-
let lastProgressAt = 0;
|
|
566
|
-
try {
|
|
567
|
-
const ctx = createSourceContext(definition, source, store, { abortSignal: options.abortSignal });
|
|
568
|
-
throwIfAborted(options.abortSignal);
|
|
569
|
-
await source.source.prepare?.(ctx);
|
|
570
|
-
throwIfAborted(options.abortSignal);
|
|
571
|
-
if (source.mountPath) await store.mkdir(source.mountPath, { recursive: true });
|
|
572
|
-
let commit;
|
|
573
|
-
const directorySet = new Set(source.mountPath ? [source.mountPath] : []);
|
|
574
|
-
const nextPaths = /* @__PURE__ */ new Set();
|
|
575
|
-
for await (const entry of iterateMaterializationEntries(source, ctx, store, existing, configHash, options)) {
|
|
576
|
-
throwIfAborted(options.abortSignal);
|
|
577
|
-
const path = entry.path;
|
|
578
|
-
nextPaths.add(path);
|
|
579
|
-
const parts = path.split("/");
|
|
580
|
-
for (let index = 1; index < parts.length; index++) directorySet.add(parts.slice(0, index).join("/"));
|
|
581
|
-
itemMetadata[path] = entry.metadata;
|
|
582
|
-
if (entry.reused) {
|
|
583
|
-
commit ||= entry.metadata.ref || entry.metadata.sha;
|
|
584
|
-
sourceFiles++;
|
|
585
|
-
sourceBytes += entry.reused.size || 0;
|
|
586
|
-
if (completeSource) await writeSourceSnapshotMetadata(store, {
|
|
587
|
-
configHash,
|
|
588
|
-
source: source.key,
|
|
589
|
-
mountPath: source.mountPath,
|
|
590
|
-
status: "updating",
|
|
591
|
-
commit,
|
|
592
|
-
files: sourceFiles,
|
|
593
|
-
bytes: sourceBytes,
|
|
594
|
-
items: checkpointItems(itemMetadata),
|
|
595
|
-
cacheMaxAge: source.cache ? source.cache.maxAge : void 0
|
|
596
|
-
});
|
|
597
|
-
if (shouldReportMaterializationUpdate(lastProgressAt, sourceFiles)) {
|
|
598
|
-
lastProgressAt = Date.now();
|
|
599
|
-
await reportMaterializationProgress(options, source, {
|
|
600
|
-
bytes: sourceBytes,
|
|
601
|
-
files: sourceFiles,
|
|
602
|
-
status: "updating"
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
const item = entry.item;
|
|
608
|
-
const metadata = item.metadata || {};
|
|
609
|
-
commit ||= readStringMeta(metadata, "ref") || readStringMeta(metadata, "sha") || entry.metadata.ref || entry.metadata.sha;
|
|
610
|
-
const written = await writeMaterializedFile(store, path, {
|
|
611
|
-
path,
|
|
612
|
-
content: entry.content,
|
|
613
|
-
contentStream: entry.contentStream,
|
|
614
|
-
mediaType: item.mediaType,
|
|
615
|
-
metadata: {
|
|
616
|
-
...metadata,
|
|
617
|
-
...entry.metadata,
|
|
618
|
-
source: source.key
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
sourceFiles++;
|
|
622
|
-
sourceBytes += written.size || 0;
|
|
623
|
-
if (completeSource) await writeSourceSnapshotMetadata(store, {
|
|
624
|
-
configHash,
|
|
625
|
-
source: source.key,
|
|
626
|
-
mountPath: source.mountPath,
|
|
627
|
-
status: "updating",
|
|
628
|
-
commit,
|
|
629
|
-
files: sourceFiles,
|
|
630
|
-
bytes: sourceBytes,
|
|
631
|
-
items: checkpointItems(itemMetadata),
|
|
632
|
-
cacheMaxAge: source.cache ? source.cache.maxAge : void 0
|
|
633
|
-
});
|
|
634
|
-
if (shouldReportMaterializationUpdate(lastProgressAt, sourceFiles)) {
|
|
635
|
-
lastProgressAt = Date.now();
|
|
636
|
-
await reportMaterializationProgress(options, source, {
|
|
637
|
-
bytes: sourceBytes,
|
|
638
|
-
files: sourceFiles,
|
|
639
|
-
status: "updating"
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
throwIfAborted(options.abortSignal);
|
|
644
|
-
await removeStaleMaterializedSourceFiles(store, source, nextPaths, options, { removeUntracked: Boolean(source.mountPath) });
|
|
645
|
-
const readyItems = Object.fromEntries([...nextPaths].flatMap((path) => {
|
|
646
|
-
const metadata = itemMetadata[path];
|
|
647
|
-
return metadata ? [[path, metadata]] : [];
|
|
648
|
-
}));
|
|
649
|
-
const ready = {
|
|
650
|
-
configHash,
|
|
651
|
-
source: source.key,
|
|
652
|
-
mountPath: source.mountPath,
|
|
653
|
-
status: "ready",
|
|
654
|
-
commit,
|
|
655
|
-
materializedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
656
|
-
files: sourceFiles,
|
|
657
|
-
bytes: sourceBytes,
|
|
658
|
-
items: readyItems,
|
|
659
|
-
cacheMaxAge: source.cache ? source.cache.maxAge : void 0
|
|
660
|
-
};
|
|
661
|
-
if (completeSource) await writeSourceSnapshotMetadata(store, ready);
|
|
662
|
-
else if (existing?.configHash === configHash) await writeSourceSnapshotMetadata(store, {
|
|
663
|
-
...existing,
|
|
664
|
-
items: checkpointItems(itemMetadata)
|
|
665
|
-
});
|
|
666
|
-
resultSources.push(ready);
|
|
667
|
-
files += sourceFiles;
|
|
668
|
-
bytes += sourceBytes;
|
|
669
|
-
directories += directorySet.size;
|
|
670
|
-
await reportMaterializationProgress(options, source, {
|
|
671
|
-
bytes: sourceBytes,
|
|
672
|
-
directories: directorySet.size,
|
|
673
|
-
durationMs: Date.now() - sourceStarted,
|
|
674
|
-
files: sourceFiles,
|
|
675
|
-
status: "completed"
|
|
676
|
-
});
|
|
677
|
-
} catch (error) {
|
|
678
|
-
const failed = {
|
|
679
|
-
configHash,
|
|
680
|
-
source: source.key,
|
|
681
|
-
mountPath: source.mountPath,
|
|
682
|
-
status: "error",
|
|
683
|
-
error: error instanceof Error ? error.message : String(error),
|
|
684
|
-
files: sourceFiles,
|
|
685
|
-
bytes: sourceBytes,
|
|
686
|
-
items: checkpointItems(itemMetadata),
|
|
687
|
-
cacheMaxAge: source.cache ? source.cache.maxAge : void 0
|
|
688
|
-
};
|
|
689
|
-
if (!options.abortSignal?.aborted) await writeSourceSnapshotMetadata(store, failed);
|
|
690
|
-
resultSources.push(failed);
|
|
691
|
-
await reportMaterializationProgress(options, source, {
|
|
692
|
-
bytes: sourceBytes,
|
|
693
|
-
durationMs: Date.now() - sourceStarted,
|
|
694
|
-
error: failed.error,
|
|
695
|
-
files: sourceFiles,
|
|
696
|
-
status: "failed"
|
|
697
|
-
});
|
|
698
|
-
if (options.abortSignal?.aborted) throw error;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return {
|
|
702
|
-
bytes,
|
|
703
|
-
directories,
|
|
704
|
-
durationMs: Date.now() - started,
|
|
705
|
-
files,
|
|
706
|
-
path: normalizeWorkspacePath(options.path || ""),
|
|
707
|
-
sources: resultSources
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
async function readResolvedSourceFile(resolution, store, ctx, options) {
|
|
711
|
-
const file = await store.readFile(resolution.workspacePath);
|
|
712
|
-
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${resolution.workspacePath}.`);
|
|
713
|
-
return decodeFile(file.content, options);
|
|
714
|
-
}
|
|
715
|
-
async function writeMaterializedFile(store, path, file) {
|
|
716
|
-
if (file.contentStream) {
|
|
717
|
-
if (store.writeFileStream) return await store.writeFileStream(path, {
|
|
718
|
-
path: file.path,
|
|
719
|
-
content: file.contentStream,
|
|
720
|
-
mediaType: file.mediaType,
|
|
721
|
-
metadata: file.metadata
|
|
722
|
-
});
|
|
723
|
-
const content = await contentStreamToBytes(file.contentStream);
|
|
724
|
-
await store.writeFile(path, {
|
|
725
|
-
path: file.path,
|
|
726
|
-
content,
|
|
727
|
-
mediaType: file.mediaType,
|
|
728
|
-
metadata: file.metadata
|
|
729
|
-
});
|
|
730
|
-
return { size: content.byteLength };
|
|
731
|
-
}
|
|
732
|
-
const content = file.content ?? "";
|
|
733
|
-
await store.writeFile(path, {
|
|
734
|
-
path: file.path,
|
|
735
|
-
content,
|
|
736
|
-
mediaType: file.mediaType,
|
|
737
|
-
metadata: file.metadata
|
|
738
|
-
});
|
|
739
|
-
return { size: contentSize(content) };
|
|
740
|
-
}
|
|
741
|
-
async function statVirtualSourcePath(source, workspacePath, store, ctx) {
|
|
742
|
-
const stored = await store.stat(workspacePath);
|
|
743
|
-
if (stored) return stored;
|
|
744
|
-
const keys = await source.source.getKeys(ctx);
|
|
745
|
-
const sourcePath = normalizeSourcePath(source, workspacePath);
|
|
746
|
-
if (!sourcePath && keys.length > 0) return {
|
|
747
|
-
path: source.mountPath,
|
|
748
|
-
type: "directory"
|
|
749
|
-
};
|
|
750
|
-
if (keys.includes(sourcePath)) return {
|
|
751
|
-
path: workspacePath,
|
|
752
|
-
type: "file",
|
|
753
|
-
digest: readDigest(await source.source.getMeta?.(sourcePath, ctx))
|
|
754
|
-
};
|
|
755
|
-
if (keys.some((key) => key.startsWith(`${sourcePath}/`))) return {
|
|
756
|
-
path: workspacePath,
|
|
757
|
-
type: "directory"
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
async function searchMaterializedStore(store, query) {
|
|
761
|
-
const limit = query.limit ?? 100;
|
|
762
|
-
const result = [];
|
|
763
|
-
const entries = query.paths?.length ? (await Promise.all(query.paths.map(async (path) => {
|
|
764
|
-
const [stat, nested] = await Promise.all([store.stat(path), store.glob(`${path}/**/*`)]);
|
|
765
|
-
return [...stat?.type === "file" ? [stat] : [], ...nested];
|
|
766
|
-
}))).flat() : await store.glob("**/*");
|
|
767
|
-
for (const entry of entries) {
|
|
768
|
-
if (entry.type !== "file") continue;
|
|
769
|
-
const file = await store.readFile(entry.path);
|
|
770
|
-
if (!file) continue;
|
|
771
|
-
const text = typeof file.content === "string" ? file.content : new TextDecoder().decode(file.content);
|
|
772
|
-
result.push(...searchText(entry.path, text, {
|
|
773
|
-
...query,
|
|
774
|
-
limit: limit - result.length
|
|
775
|
-
}));
|
|
776
|
-
if (result.length >= limit) break;
|
|
777
|
-
}
|
|
778
|
-
return result.slice(0, limit);
|
|
779
|
-
}
|
|
780
|
-
function createLazyMaterializedMetadata(resolution, item, upstreamMeta) {
|
|
781
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
782
|
-
return {
|
|
783
|
-
source: resolution.sourceKey,
|
|
784
|
-
sourcePath: resolution.sourcePath,
|
|
785
|
-
materializedAt: now,
|
|
786
|
-
validatedAt: resolution.validate === "request" ? now : void 0,
|
|
787
|
-
etag: readStringMeta(upstreamMeta, "etag"),
|
|
788
|
-
sha: readStringMeta(upstreamMeta, "sha"),
|
|
789
|
-
digest: readStringMeta(upstreamMeta, "digest") || readStringMeta(item.metadata, "digest"),
|
|
790
|
-
ref: readStringMeta(upstreamMeta, "ref")
|
|
791
|
-
};
|
|
792
|
-
}
|
|
793
|
-
function hasSourceMetaChanged(current, upstreamMeta) {
|
|
794
|
-
const next = {
|
|
795
|
-
etag: readStringMeta(upstreamMeta, "etag"),
|
|
796
|
-
sha: readStringMeta(upstreamMeta, "sha"),
|
|
797
|
-
digest: readStringMeta(upstreamMeta, "digest"),
|
|
798
|
-
ref: readStringMeta(upstreamMeta, "ref")
|
|
799
|
-
};
|
|
800
|
-
return current.etag !== next.etag || current.sha !== next.sha || current.digest !== next.digest || current.ref !== next.ref;
|
|
801
|
-
}
|
|
802
|
-
function normalizeSourcePath(source, workspacePath) {
|
|
803
|
-
if (workspacePath === source.mountPath) return "";
|
|
804
|
-
return source.mountPath && workspacePath.startsWith(`${source.mountPath}/`) ? normalizeWorkspacePath(workspacePath.slice(source.mountPath.length + 1)) : normalizeWorkspacePath(workspacePath);
|
|
805
|
-
}
|
|
806
|
-
function readStringMeta(meta, key) {
|
|
807
|
-
return typeof meta?.[key] === "string" ? meta[key] : void 0;
|
|
808
|
-
}
|
|
809
|
-
function readDigest(meta) {
|
|
810
|
-
return readStringMeta(meta, "digest") || readStringMeta(meta, "sha");
|
|
811
|
-
}
|
|
812
|
-
//#endregion
|
|
813
324
|
//#region src/sources/resolver.ts
|
|
814
325
|
function resolveWorkspacePath(definition, path) {
|
|
815
326
|
const workspacePath = normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
@@ -872,17 +383,67 @@ function canonicalSourceSyncState(state) {
|
|
|
872
383
|
}
|
|
873
384
|
//#endregion
|
|
874
385
|
//#region src/sources/view.ts
|
|
875
|
-
|
|
386
|
+
const materializationByStore = /* @__PURE__ */ new WeakMap();
|
|
387
|
+
async function invalidateWorkspaceSourceMaterialization(definition, store, sourceKeys) {
|
|
388
|
+
const state = materializationByStore.get(store)?.get(definition);
|
|
389
|
+
if (!state) return;
|
|
390
|
+
const pending = /* @__PURE__ */ new Set();
|
|
391
|
+
for (const sourceKey of sourceKeys) {
|
|
392
|
+
state.completedSources.delete(sourceKey);
|
|
393
|
+
state.materializedSources.delete(sourceKey);
|
|
394
|
+
state.generationBySource.set(sourceKey, (state.generationBySource.get(sourceKey) ?? 0) + 1);
|
|
395
|
+
const operation = state.pendingBySource.get(sourceKey);
|
|
396
|
+
if (operation) pending.add(operation.tail);
|
|
397
|
+
}
|
|
398
|
+
await Promise.all(pending);
|
|
399
|
+
}
|
|
400
|
+
async function waitForMaterialization(pending, signal) {
|
|
401
|
+
if (!signal) return await pending;
|
|
402
|
+
signal.throwIfAborted();
|
|
403
|
+
let removeAbortListener = () => {};
|
|
404
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
405
|
+
const onAbort = () => reject(signal.reason);
|
|
406
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
407
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
408
|
+
if (signal.aborted) onAbort();
|
|
409
|
+
});
|
|
410
|
+
try {
|
|
411
|
+
return await Promise.race([pending, aborted]);
|
|
412
|
+
} finally {
|
|
413
|
+
removeAbortListener();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function createWorkspaceSourceView(definition, store, options = {}) {
|
|
876
417
|
const sourceContext = createSourceContext(definition, void 0, store);
|
|
877
418
|
const allSources = normalizeWorkspaceSources(definition.sources);
|
|
878
|
-
const sources = allSources.filter((source) => !source.requestOnly && source.materialize === "lazy");
|
|
419
|
+
const sources = allSources.filter((source) => !source.requestOnly && (source.materialize === "lazy" || source.materialize === "startup"));
|
|
879
420
|
const syncSources = allSources.filter((source) => source.sync);
|
|
880
421
|
const descriptorSources = allSources.filter((source) => source.requestDescriptor);
|
|
881
422
|
const writePolicy = createWorkspaceWritePolicy(definition);
|
|
882
423
|
const prepareBySource = /* @__PURE__ */ new Map();
|
|
883
|
-
const
|
|
424
|
+
const sourceContexts = /* @__PURE__ */ new Map();
|
|
425
|
+
let materializationByDefinition = materializationByStore.get(store);
|
|
426
|
+
if (!materializationByDefinition) {
|
|
427
|
+
materializationByDefinition = /* @__PURE__ */ new WeakMap();
|
|
428
|
+
materializationByStore.set(store, materializationByDefinition);
|
|
429
|
+
}
|
|
430
|
+
const materializationState = materializationByDefinition.get(definition) ?? {
|
|
431
|
+
completedSources: /* @__PURE__ */ new Set(),
|
|
432
|
+
generationBySource: /* @__PURE__ */ new Map(),
|
|
433
|
+
materializedSources: /* @__PURE__ */ new Set(),
|
|
434
|
+
pendingBySource: /* @__PURE__ */ new Map()
|
|
435
|
+
};
|
|
436
|
+
if (!materializationByDefinition.has(definition)) materializationByDefinition.set(definition, materializationState);
|
|
437
|
+
const { completedSources, generationBySource, materializedSources, pendingBySource } = materializationState;
|
|
438
|
+
const uncachedMaterializedSources = /* @__PURE__ */ new Set();
|
|
439
|
+
const persistsSourceSnapshots = Boolean(store.getMeta && store.setMeta);
|
|
884
440
|
function getSourceContext(source) {
|
|
885
|
-
|
|
441
|
+
let context = sourceContexts.get(source.key);
|
|
442
|
+
if (!context) {
|
|
443
|
+
context = createSourceContext(definition, source, store);
|
|
444
|
+
sourceContexts.set(source.key, context);
|
|
445
|
+
}
|
|
446
|
+
return context;
|
|
886
447
|
}
|
|
887
448
|
function isLazySourcePath(path) {
|
|
888
449
|
return sources.some((source) => sourceMountContainsPath(source, path));
|
|
@@ -954,17 +515,29 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
954
515
|
}, null, 2);
|
|
955
516
|
}
|
|
956
517
|
function isLiveSource(sourceKey) {
|
|
957
|
-
|
|
518
|
+
const source = sources.find((item) => item.key === sourceKey);
|
|
519
|
+
return Boolean(source?.livePaths && source.materialize !== "startup");
|
|
520
|
+
}
|
|
521
|
+
function usesLiveProvider(source) {
|
|
522
|
+
return Boolean(source.livePaths && source.materialize !== "startup");
|
|
958
523
|
}
|
|
959
524
|
function getLazySourcesForPath(path) {
|
|
960
525
|
return sources.filter((source) => sourceMountIntersectsPath(source, path));
|
|
961
526
|
}
|
|
962
527
|
async function ensurePrepared(sourceKey) {
|
|
963
528
|
const source = sources.find((item) => item.key === sourceKey);
|
|
964
|
-
if (!source
|
|
529
|
+
if (!source) return;
|
|
530
|
+
if (source.materialize === "startup" && completedSources.has(sourceKey)) {
|
|
531
|
+
if (!persistsSourceSnapshots || await hasCurrentSourceSnapshot(store, source)) return;
|
|
532
|
+
completedSources.delete(sourceKey);
|
|
533
|
+
}
|
|
534
|
+
if (source.materialize === "startup" && options.reuseStartupSnapshots && await hasCurrentSourceSnapshot(store, source)) {
|
|
535
|
+
completedSources.add(sourceKey);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
965
538
|
let pending = prepareBySource.get(sourceKey);
|
|
966
539
|
if (!pending) {
|
|
967
|
-
pending = source.source
|
|
540
|
+
pending = prepareWorkspaceSource(source.source, getSourceContext(source)).then(() => void 0);
|
|
968
541
|
prepareBySource.set(sourceKey, pending);
|
|
969
542
|
}
|
|
970
543
|
await pending;
|
|
@@ -972,24 +545,116 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
972
545
|
async function ensurePreparedSources(items = sources) {
|
|
973
546
|
await Promise.all(items.map(async (source) => await ensurePrepared(source.key)));
|
|
974
547
|
}
|
|
548
|
+
async function materializeSerialized(options = {}) {
|
|
549
|
+
const requestedPath = normalizeWorkspacePath(options.path || "");
|
|
550
|
+
const selectedSources = allSources.filter((source) => source.materialize === "lazy" || source.materialize === "startup" || source.materialize === "build" && Boolean(requestedPath)).filter((source) => (!options.sources?.length || options.sources.includes(source.key)) && sourceMountIntersectsPath(source, requestedPath));
|
|
551
|
+
const predecessors = selectedSources.flatMap((source) => {
|
|
552
|
+
const pending = pendingBySource.get(source.key);
|
|
553
|
+
return pending ? [pending.tail] : [];
|
|
554
|
+
});
|
|
555
|
+
const previous = waitForMaterialization(Promise.all(predecessors), options.abortSignal);
|
|
556
|
+
const current = (async () => {
|
|
557
|
+
await previous;
|
|
558
|
+
const generations = new Map(selectedSources.map((source) => {
|
|
559
|
+
const generation = (generationBySource.get(source.key) ?? 0) + 1;
|
|
560
|
+
generationBySource.set(source.key, generation);
|
|
561
|
+
return [source.key, generation];
|
|
562
|
+
}));
|
|
563
|
+
const mutations = /* @__PURE__ */ new Set();
|
|
564
|
+
const isCurrent = () => selectedSources.every((source) => generationBySource.get(source.key) === generations.get(source.key));
|
|
565
|
+
async function trackMutation(operation) {
|
|
566
|
+
if (!isCurrent()) throw options.abortSignal?.reason ?? workspaceError("[vitehub] Workspace source materialization was superseded.");
|
|
567
|
+
const mutation = operation();
|
|
568
|
+
mutations.add(mutation);
|
|
569
|
+
try {
|
|
570
|
+
return await mutation;
|
|
571
|
+
} finally {
|
|
572
|
+
mutations.delete(mutation);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
for (const source of selectedSources) {
|
|
576
|
+
if (!materializesCompleteSource(source, options)) continue;
|
|
577
|
+
materializedSources.delete(source.key);
|
|
578
|
+
if (source.materialize === "startup") completedSources.delete(source.key);
|
|
579
|
+
}
|
|
580
|
+
let result;
|
|
581
|
+
try {
|
|
582
|
+
result = await waitForMaterialization(materializeWorkspaceSources(definition, store, options, {
|
|
583
|
+
isCurrent,
|
|
584
|
+
async mutate(operation) {
|
|
585
|
+
options.abortSignal?.throwIfAborted();
|
|
586
|
+
return await trackMutation(operation);
|
|
587
|
+
},
|
|
588
|
+
async checkpoint(operation) {
|
|
589
|
+
return await trackMutation(operation);
|
|
590
|
+
}
|
|
591
|
+
}), options.abortSignal);
|
|
592
|
+
} catch (error) {
|
|
593
|
+
if (options.abortSignal?.aborted && mutations.size) await Promise.allSettled(mutations);
|
|
594
|
+
throw error;
|
|
595
|
+
}
|
|
596
|
+
for (const sourceResult of result.sources) {
|
|
597
|
+
const source = sources.find((item) => item.key === sourceResult.source);
|
|
598
|
+
if (sourceResult.status === "ready" && source && materializesCompleteSource(source, options)) {
|
|
599
|
+
materializedSources.add(source.key);
|
|
600
|
+
if (source.materialize === "lazy" && source.cache === false) uncachedMaterializedSources.add(source.key);
|
|
601
|
+
if (source.materialize === "startup") completedSources.add(source.key);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return result;
|
|
605
|
+
})();
|
|
606
|
+
const tail = current.then(() => void 0, async () => {
|
|
607
|
+
await Promise.allSettled(predecessors);
|
|
608
|
+
});
|
|
609
|
+
const entries = new Map(selectedSources.map((source) => [source.key, {
|
|
610
|
+
fullSource: materializesCompleteSource(source, options),
|
|
611
|
+
promise: current,
|
|
612
|
+
tail
|
|
613
|
+
}]));
|
|
614
|
+
for (const [sourceKey, entry] of entries) pendingBySource.set(sourceKey, entry);
|
|
615
|
+
tail.then(() => {
|
|
616
|
+
for (const [sourceKey, entry] of entries) if (pendingBySource.get(sourceKey) === entry) pendingBySource.delete(sourceKey);
|
|
617
|
+
});
|
|
618
|
+
return await current;
|
|
619
|
+
}
|
|
975
620
|
async function ensureMaterialized(sourceKey) {
|
|
976
|
-
|
|
977
|
-
if (!
|
|
978
|
-
|
|
979
|
-
|
|
621
|
+
const source = sources.find((item) => item.key === sourceKey);
|
|
622
|
+
if (!source) return;
|
|
623
|
+
const isUncachedLazySource = source.materialize === "lazy" && source.cache === false;
|
|
624
|
+
const pending = pendingBySource.get(sourceKey);
|
|
625
|
+
if (pending?.fullSource) {
|
|
626
|
+
try {
|
|
627
|
+
await pending.promise;
|
|
628
|
+
} catch {}
|
|
629
|
+
if (materializedSources.has(sourceKey) || completedSources.has(sourceKey)) {
|
|
630
|
+
if (isUncachedLazySource) uncachedMaterializedSources.add(sourceKey);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
980
633
|
}
|
|
981
|
-
|
|
634
|
+
if (isUncachedLazySource ? uncachedMaterializedSources.has(sourceKey) : materializedSources.has(sourceKey)) {
|
|
635
|
+
const maxAge = source.cache && source.cache.maxAge;
|
|
636
|
+
if (source.materialize !== "lazy" || !Number.isFinite(maxAge) || await hasFreshSourceSnapshot(store, source)) return;
|
|
637
|
+
materializedSources.delete(sourceKey);
|
|
638
|
+
}
|
|
639
|
+
if (completedSources.has(sourceKey)) {
|
|
640
|
+
if (!persistsSourceSnapshots || await hasCurrentSourceSnapshot(store, source)) return;
|
|
641
|
+
completedSources.delete(sourceKey);
|
|
642
|
+
}
|
|
643
|
+
await materializeSerialized({ sources: [sourceKey] });
|
|
982
644
|
}
|
|
983
645
|
async function ensureMaterializedSources(items = sources) {
|
|
984
646
|
await Promise.all(items.map(async (source) => await ensureMaterialized(source.key)));
|
|
985
647
|
}
|
|
986
648
|
async function listSourceAware(path = "", options = {}) {
|
|
987
|
-
const
|
|
649
|
+
const normalized = normalizeWorkspacePath(path);
|
|
650
|
+
const storeEntries = isDescriptorPath(normalized) ? [] : await store.list(path, options);
|
|
988
651
|
const result = new Map(storeEntries.map((entry) => [entry.path, entry]));
|
|
989
|
-
for (const entry of descriptorPathEntries(path, options)) result.set(entry.path, entry);
|
|
652
|
+
for (const entry of descriptorPathEntries(path, options)) if (!isExcludedWorkspacePath(entry.path, options.exclude)) result.set(entry.path, entry);
|
|
653
|
+
if (isDescriptorPath(normalized)) return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
990
654
|
for (const source of getLazySourcesForPath(path)) {
|
|
655
|
+
if (isExcludedWorkspacePath(source.mountPath, options.exclude)) continue;
|
|
991
656
|
await ensurePrepared(source.key);
|
|
992
|
-
if (source
|
|
657
|
+
if (usesLiveProvider(source)) {
|
|
993
658
|
await pruneLiveSourceStoreEntries(result, source);
|
|
994
659
|
continue;
|
|
995
660
|
}
|
|
@@ -1054,7 +719,7 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1054
719
|
for (const source of sources) {
|
|
1055
720
|
const paths = sourcePaths.get(source.key);
|
|
1056
721
|
if (query.paths?.length && !paths?.length && !query.paths.some((path) => !normalizeWorkspacePath(path))) continue;
|
|
1057
|
-
if (source
|
|
722
|
+
if (usesLiveProvider(source)) {
|
|
1058
723
|
await ensurePrepared(source.key);
|
|
1059
724
|
const liveEntries = liveSourceEntries(source).filter((entry) => entry.type === "file").filter((entry) => !paths?.length || paths.some((path) => !path || entry.path === path || entry.path.startsWith(`${path}/`)));
|
|
1060
725
|
for (const entry of liveEntries) {
|
|
@@ -1139,6 +804,11 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1139
804
|
if (resolution.type === "source") {
|
|
1140
805
|
await ensurePrepared(resolution.sourceKey);
|
|
1141
806
|
if (isLiveSource(resolution.sourceKey)) return decodeFile(await sourceItemContent(await resolution.source.source.getItem(resolution.sourcePath, getSourceContext(resolution.source))), options);
|
|
807
|
+
if (resolution.source.materialize === "startup" && !completedSources.has(resolution.sourceKey) && !materializedSources.has(resolution.sourceKey)) await ensureMaterialized(resolution.sourceKey);
|
|
808
|
+
const cacheMaxAge = resolution.source.cache && resolution.source.cache.maxAge;
|
|
809
|
+
let shouldRefreshCachedLazy = false;
|
|
810
|
+
if (resolution.source.materialize === "lazy" && Number.isFinite(cacheMaxAge)) shouldRefreshCachedLazy = materializedSources.has(resolution.sourceKey) || Boolean(await readCurrentSourceSnapshot(store, resolution.source));
|
|
811
|
+
if (shouldRefreshCachedLazy) await ensureMaterialized(resolution.sourceKey);
|
|
1142
812
|
const file = await store.readFile(resolution.workspacePath);
|
|
1143
813
|
if (file) return decodeFile(file.content, options);
|
|
1144
814
|
await ensureMaterialized(resolution.sourceKey);
|
|
@@ -1161,13 +831,19 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1161
831
|
workspace: definition.name
|
|
1162
832
|
});
|
|
1163
833
|
try {
|
|
1164
|
-
|
|
834
|
+
if (options?.preservePath && input.path !== resolution.workspacePath) throw workspaceError(`[vitehub] Workspace validator cannot rewrite preserved path: ${resolution.workspacePath} -> ${input.path}.`);
|
|
835
|
+
const file = {
|
|
1165
836
|
path: input.path,
|
|
1166
837
|
content: input.content ?? content,
|
|
1167
838
|
mediaType: input.mediaType,
|
|
1168
839
|
metadata: input.metadata
|
|
1169
|
-
}
|
|
840
|
+
};
|
|
841
|
+
if (options?.ifDigest !== void 0) {
|
|
842
|
+
if (!store.writeFileConditional) throw workspaceError("[vitehub] This Workspace Store does not support conditional writes.");
|
|
843
|
+
await store.writeFileConditional(input.path, file, options.ifDigest);
|
|
844
|
+
} else await store.writeFile(input.path, file);
|
|
1170
845
|
await writePolicy.after(input);
|
|
846
|
+
return input.path;
|
|
1171
847
|
} catch (error) {
|
|
1172
848
|
await writePolicy.error(input, error);
|
|
1173
849
|
throw error;
|
|
@@ -1179,11 +855,11 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1179
855
|
async glob(pattern, options) {
|
|
1180
856
|
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
1181
857
|
await ensurePreparedSources();
|
|
1182
|
-
await ensureMaterializedSources(sources.filter((source) => !source
|
|
858
|
+
await ensureMaterializedSources(sources.filter((source) => !usesLiveProvider(source)));
|
|
1183
859
|
const result = /* @__PURE__ */ new Map();
|
|
1184
860
|
for (const entry of await store.glob(patterns, options)) result.set(entry.path, entry);
|
|
1185
861
|
for (const entry of descriptorPathEntries("", { recursive: true })) if (entry.type === "file" && patterns.some((pattern) => matchesAny(entry.path, pattern))) result.set(entry.path, entry);
|
|
1186
|
-
for (const source of sources.filter(
|
|
862
|
+
for (const source of sources.filter(usesLiveProvider)) {
|
|
1187
863
|
await pruneLiveSourceStoreEntries(result, source);
|
|
1188
864
|
for (const entry of liveSourceEntries(source)) if (entry.type === "file" && patterns.some((pattern) => matchesAny(entry.path, pattern))) result.set(entry.path, entry);
|
|
1189
865
|
}
|
|
@@ -1207,8 +883,10 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1207
883
|
if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1208
884
|
return result;
|
|
1209
885
|
}
|
|
886
|
+
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
1210
887
|
const stored = await store.stat(resolution.workspacePath);
|
|
1211
888
|
if (stored) return stored;
|
|
889
|
+
if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1212
890
|
await ensureMaterialized(resolution.sourceKey);
|
|
1213
891
|
const result = await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source));
|
|
1214
892
|
if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
@@ -1216,7 +894,7 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1216
894
|
}
|
|
1217
895
|
let result = await store.stat(resolution.workspacePath);
|
|
1218
896
|
if (!result) {
|
|
1219
|
-
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && source
|
|
897
|
+
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return {
|
|
1220
898
|
path: "",
|
|
1221
899
|
type: "directory"
|
|
1222
900
|
};
|
|
@@ -1227,7 +905,7 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1227
905
|
return result;
|
|
1228
906
|
},
|
|
1229
907
|
async materializeSources(options) {
|
|
1230
|
-
return await
|
|
908
|
+
return await materializeSerialized(options);
|
|
1231
909
|
},
|
|
1232
910
|
async exists(path) {
|
|
1233
911
|
if (descriptorStat(normalizeWorkspacePath(path))) return true;
|
|
@@ -1238,12 +916,14 @@ function createWorkspaceSourceView(definition, store) {
|
|
|
1238
916
|
if (!resolution.workspacePath) return true;
|
|
1239
917
|
return Boolean(liveSourceStat(resolution.source, resolution.workspacePath));
|
|
1240
918
|
}
|
|
919
|
+
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
1241
920
|
if (await store.stat(resolution.workspacePath)) return true;
|
|
921
|
+
if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) return false;
|
|
1242
922
|
await ensureMaterialized(resolution.sourceKey);
|
|
1243
923
|
return Boolean(await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source)));
|
|
1244
924
|
}
|
|
1245
925
|
if (await store.stat(resolution.workspacePath)) return true;
|
|
1246
|
-
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && source
|
|
926
|
+
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return true;
|
|
1247
927
|
await materializeRootSourceForPath(resolution.workspacePath);
|
|
1248
928
|
return Boolean(await store.stat(resolution.workspacePath));
|
|
1249
929
|
},
|
|
@@ -1326,6 +1006,7 @@ function addLiveSourceEntries(result, path, options, sources) {
|
|
|
1326
1006
|
const normalized = normalizeWorkspacePath(path);
|
|
1327
1007
|
for (const source of sources.filter((source) => source.livePaths)) for (const entry of liveSourceEntries(source)) {
|
|
1328
1008
|
if (!isListedLiveEntry(entry, normalized, options)) continue;
|
|
1009
|
+
if (isExcludedWorkspacePath(entry.path, options.exclude)) continue;
|
|
1329
1010
|
result.set(entry.path, entry);
|
|
1330
1011
|
}
|
|
1331
1012
|
}
|
|
@@ -1371,6 +1052,9 @@ function getCachedWorkspaceStore(definition, create) {
|
|
|
1371
1052
|
}
|
|
1372
1053
|
return store;
|
|
1373
1054
|
}
|
|
1055
|
+
function invalidateCachedWorkspaceStore(definition) {
|
|
1056
|
+
storeByDefinition.delete(definition);
|
|
1057
|
+
}
|
|
1374
1058
|
function resetWorkspaceStoreCache() {
|
|
1375
1059
|
storeByDefinition = /* @__PURE__ */ new WeakMap();
|
|
1376
1060
|
}
|
|
@@ -1383,9 +1067,13 @@ function createWorkspace(definition) {
|
|
|
1383
1067
|
const store = getStore(definition);
|
|
1384
1068
|
const files = createWorkspaceSourceView(definition, store);
|
|
1385
1069
|
const workspace = {
|
|
1070
|
+
[workspaceMetadataTarget]: () => store,
|
|
1386
1071
|
name: definition.name,
|
|
1072
|
+
async capabilities() {
|
|
1073
|
+
return { conditionalWrites: hasRuntimeType(store.writeFileConditional, "function") };
|
|
1074
|
+
},
|
|
1387
1075
|
async sync(options) {
|
|
1388
|
-
const { syncWorkspaceSources } = await import("./sync-
|
|
1076
|
+
const { syncWorkspaceSources } = await import("./sync-DnTQwt8r.js");
|
|
1389
1077
|
return await syncWorkspaceSources(definition, store, options);
|
|
1390
1078
|
},
|
|
1391
1079
|
async materializeSources(options) {
|
|
@@ -1401,7 +1089,7 @@ function createWorkspace(definition) {
|
|
|
1401
1089
|
return await files.readFile(path, options);
|
|
1402
1090
|
},
|
|
1403
1091
|
async writeFile(path, content, options) {
|
|
1404
|
-
await files.writeFile(path, content, options);
|
|
1092
|
+
return await files.writeFile(path, content, options);
|
|
1405
1093
|
},
|
|
1406
1094
|
async list(path, options) {
|
|
1407
1095
|
return await files.list(path, options);
|
|
@@ -1425,52 +1113,43 @@ function createWorkspace(definition) {
|
|
|
1425
1113
|
await files.rm(path, options);
|
|
1426
1114
|
},
|
|
1427
1115
|
async publish(options) {
|
|
1428
|
-
const { publishWorkspace } = await import("./lifecycle-
|
|
1116
|
+
const { publishWorkspace } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
1429
1117
|
await publishWorkspace(definition, store, options);
|
|
1430
1118
|
},
|
|
1431
1119
|
async snapshot(options) {
|
|
1432
1120
|
const snapshot = await store.snapshot(options);
|
|
1433
|
-
const { publishWorkspaceSnapshot } = await import("./lifecycle-
|
|
1121
|
+
const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
1434
1122
|
await publishWorkspaceSnapshot(definition, store, snapshot);
|
|
1435
1123
|
return snapshot;
|
|
1436
1124
|
},
|
|
1125
|
+
async rebase(options) {
|
|
1126
|
+
if (!store.rebase) throw new Error("[vitehub] Workspace Store does not support rebasing.");
|
|
1127
|
+
await store.rebase(options);
|
|
1128
|
+
},
|
|
1437
1129
|
async diff(options) {
|
|
1438
1130
|
return await store.diff(options);
|
|
1439
1131
|
},
|
|
1440
1132
|
async startSession(options) {
|
|
1441
1133
|
const host = options?.host;
|
|
1442
1134
|
if (host) {
|
|
1443
|
-
const { createHostedWorkspaceSession } = await import("./host-
|
|
1135
|
+
const { createHostedWorkspaceSession } = await import("./host-DJH8cuoU.js").then((n) => n.n);
|
|
1444
1136
|
return await createHostedWorkspaceSession(workspace, {
|
|
1445
1137
|
...options,
|
|
1446
1138
|
host
|
|
1447
1139
|
});
|
|
1448
1140
|
}
|
|
1449
1141
|
return await createBasicWorkspaceSession(workspace, options);
|
|
1450
|
-
},
|
|
1451
|
-
mount(options) {
|
|
1452
|
-
return {
|
|
1453
|
-
workspace,
|
|
1454
|
-
mode: options?.mode || "read-only",
|
|
1455
|
-
target: options?.target || "/workspace",
|
|
1456
|
-
async diff() {
|
|
1457
|
-
return await workspace.diff();
|
|
1458
|
-
},
|
|
1459
|
-
async commit() {
|
|
1460
|
-
await workspace.snapshot({ name: "mount-commit" });
|
|
1461
|
-
},
|
|
1462
|
-
async export() {
|
|
1463
|
-
return await workspace.snapshot({ name: "mount-export" });
|
|
1464
|
-
}
|
|
1465
|
-
};
|
|
1466
1142
|
}
|
|
1467
1143
|
};
|
|
1468
1144
|
forwardWorkspaceStoreTarget(store, workspace);
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1145
|
+
if (!normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor || source.livePaths)) forwardWorkspaceRevisionMaterializer(store, workspace);
|
|
1146
|
+
const synchronizedWorkspace = workspace;
|
|
1147
|
+
synchronizedWorkspace.__workspaceDefinitionSyncKey = definition;
|
|
1148
|
+
synchronizedWorkspace.__syncWorkspaceDefinition = async (abortSignal) => {
|
|
1149
|
+
const { syncWorkspaceDefinition } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
1150
|
+
await syncWorkspaceDefinition(definition, store, abortSignal);
|
|
1472
1151
|
};
|
|
1473
1152
|
return attachWorkspaceSourceRequestExecution(workspace, createWorkspaceSourceRequestExecution(definition));
|
|
1474
1153
|
}
|
|
1475
1154
|
//#endregion
|
|
1476
|
-
export {
|
|
1155
|
+
export { isMissingWorkspacePathError as _, invalidateWorkspaceSourceMaterialization as a, workspaceSourceSyncStateEquals as c, resolveWorkspaceAutoCommit as d, createBasicWorkspaceSession as f, filterSessionEntries as g, filterSessionDiff as h, createWorkspaceSourceView as i, resolveWorkspacePath as l, assertPathInSessionScope as m, invalidateCachedWorkspaceStore as n, readWorkspaceSourceSyncState as o, assertDiffInsideSessionPaths as p, resetWorkspaceStoreCache as r, sourceSyncMetaKey as s, createWorkspace as t, createWorkspaceWritePolicy as u, scopedSearchQuery as v };
|