@vite-hub/workspace 0.0.4 → 0.3.0
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 +339 -115
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/blob-database.d.ts +474 -0
- package/dist/blob-database.js +608 -0
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +6 -7
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/config-BAgL2dtB.js +1076 -0
- package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
- package/dist/glob-B8YGvTrZ.js +21 -0
- package/dist/glob-Cjxms1t7.js +30 -0
- package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
- package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +6 -7
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +10 -9
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +26 -47
- package/dist/index.js +30 -100
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-B-enk_4A.js +596 -0
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-DF0F5rcL.js +39 -0
- package/dist/memory-BOexthyW.js +247 -0
- package/dist/metadata-target-CWz6KHKq.js +1589 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +90 -0
- package/dist/operations.js +3 -0
- package/dist/path--wrT_Azm.js +113 -0
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-C8C0auoW.d.ts +10 -0
- package/dist/provider-9s4Ufkm5.js +1479 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +52 -17
- package/dist/runtime.js +324 -67
- package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
- package/dist/server-8tGltlGz.js +303 -0
- package/dist/server.d.ts +36 -39
- package/dist/server.js +2 -328
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +10 -7
- package/dist/source-metadata.js +12 -12
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
- package/dist/store-ybhyD38Z.js +1873 -0
- package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
- package/dist/utils-CgMZCHsX.js +616 -0
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21369 -2
- package/dist/workspace-CYB2xZ1T.d.ts +7 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
- package/package.json +97 -72
- package/dist/ai-CjxvGqM0.d.ts +0 -162
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/mountx.d.ts +0 -10
- package/dist/mountx.js +0 -143
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -26
- package/dist/nuxt.js +0 -42
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-Uj6IVxes.d.ts +0 -11
- package/dist/request-execution-B-dSFlGB.js +0 -84
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/state-tYcRWEh2.d.ts +0 -26
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/token-CVzURBxC.js +0 -61
- package/dist/use-BiHzt0xA.d.ts +0 -103
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
- package/dist/workspace-Xddf4G1B.d.ts +0 -6
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
|
|
2
|
+
import { s as workspaceError } from "./path-DrSIenjj.js";
|
|
3
|
+
import { f as sha256, l as normalizeWorkspacePath, t as contentStreamChunks } from "./path--wrT_Azm.js";
|
|
4
|
+
import { s as invalidateWorkspaceSourceMaterialization } from "./workspace-sPWn2Jxj.js";
|
|
5
|
+
import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, n as createSourceContext } from "./config-BAgL2dtB.js";
|
|
6
|
+
import { A as removeWorkspaceOwnedFile, C as withWorkspaceStoreMutation, D as readWorkspaceFileOwner, M as registerWorkspaceStoreAlias, N as workspaceStoreIdentity, O as recordWorkspaceFileOwner, _ as reconcileRemovedStartupSources, d as invalidateSourceSnapshot, j as withWorkspaceFileCheckpoint, k as removeWorkspaceFileOwner, m as readCurrentSourceSnapshot, y as sourceSnapshotOwnsAnyPath } from "./metadata-target-CWz6KHKq.js";
|
|
7
|
+
import { n as useWorkspaceAssets } from "./asset-registry-DfBV5kmw.js";
|
|
8
|
+
import { t as files } from "./files-BOo4SbwE.js";
|
|
9
|
+
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
//#region src/lifecycle.ts
|
|
12
|
+
var lifecycle_exports = /* @__PURE__ */ __exportAll({ syncWorkspaceDefinition: () => syncWorkspaceDefinition });
|
|
13
|
+
const buildSourcesMetaKey = (workspace) => `workspace:${encodeURIComponent(workspace)}:build-sources`;
|
|
14
|
+
const buildFilesMetaKey = (workspace) => `workspace:${encodeURIComponent(workspace)}:build-files`;
|
|
15
|
+
const volatileBuildMetadata = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
async function readBuildMetadata(store, key) {
|
|
17
|
+
const state = volatileBuildMetadata.get(workspaceStoreIdentity(store));
|
|
18
|
+
return state?.has(key) ? state.get(key) : await store.getMeta?.(key);
|
|
19
|
+
}
|
|
20
|
+
async function writeBuildMetadata(store, key, value) {
|
|
21
|
+
const identity = workspaceStoreIdentity(store);
|
|
22
|
+
let state = volatileBuildMetadata.get(identity);
|
|
23
|
+
if (!state) {
|
|
24
|
+
state = /* @__PURE__ */ new Map();
|
|
25
|
+
volatileBuildMetadata.set(identity, state);
|
|
26
|
+
}
|
|
27
|
+
state.set(key, value);
|
|
28
|
+
if (store.getMeta && store.setMeta) {
|
|
29
|
+
await store.setMeta(key, value);
|
|
30
|
+
state.delete(key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const buildDirectoriesMetaKey = (workspace) => `workspace:${encodeURIComponent(workspace)}:build-directories`;
|
|
34
|
+
function parentPaths(path) {
|
|
35
|
+
const parts = normalizeWorkspacePath(path).split("/");
|
|
36
|
+
return parts.slice(0, -1).map((_part, index) => parts.slice(0, index + 1).join("/"));
|
|
37
|
+
}
|
|
38
|
+
async function readBuildDirectories(store, workspace) {
|
|
39
|
+
const value = await readBuildMetadata(store, buildDirectoriesMetaKey(workspace));
|
|
40
|
+
return Array.isArray(value) ? value.filter((path) => typeof path === "string" && !!path) : [];
|
|
41
|
+
}
|
|
42
|
+
const buildDirectoryUsersMetaKey = "workspace:build-directory-users";
|
|
43
|
+
async function readBuildDirectoryUsers(store) {
|
|
44
|
+
const value = await readBuildMetadata(store, buildDirectoryUsersMetaKey);
|
|
45
|
+
const users = Object.create(null);
|
|
46
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return users;
|
|
47
|
+
const entries = Object.entries(value).filter((entry) => Array.isArray(entry[1]) && entry[1].every((name) => typeof name === "string"));
|
|
48
|
+
const directories = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const [path, names] of entries) {
|
|
50
|
+
const current = [];
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
let owned = directories.get(name);
|
|
53
|
+
if (!owned) {
|
|
54
|
+
owned = await readBuildDirectories(store, name);
|
|
55
|
+
directories.set(name, owned);
|
|
56
|
+
}
|
|
57
|
+
if (owned.includes(path)) current.push(name);
|
|
58
|
+
}
|
|
59
|
+
if (current.length) users[path] = current;
|
|
60
|
+
}
|
|
61
|
+
return users;
|
|
62
|
+
}
|
|
63
|
+
async function missingBuildDirectories(store, paths) {
|
|
64
|
+
const missing = /* @__PURE__ */ new Set();
|
|
65
|
+
for (const path of paths) if (!await store.stat(path)) missing.add(path);
|
|
66
|
+
return missing;
|
|
67
|
+
}
|
|
68
|
+
async function recordBuildDirectories(store, workspace, paths, missing) {
|
|
69
|
+
const owned = new Set(await readBuildDirectories(store, workspace));
|
|
70
|
+
const users = await readBuildDirectoryUsers(store);
|
|
71
|
+
for (const path of paths) {
|
|
72
|
+
if (!missing.has(path) && !Object.hasOwn(users, path)) continue;
|
|
73
|
+
if ((await store.stat(path))?.type !== "directory") continue;
|
|
74
|
+
owned.add(path);
|
|
75
|
+
users[path] = [.../* @__PURE__ */ new Set([...Object.hasOwn(users, path) ? users[path] : [], workspace])];
|
|
76
|
+
}
|
|
77
|
+
await writeBuildMetadata(store, buildDirectoriesMetaKey(workspace), [...owned]);
|
|
78
|
+
await writeBuildMetadata(store, buildDirectoryUsersMetaKey, users);
|
|
79
|
+
}
|
|
80
|
+
async function pruneBuildDirectories(store, workspace) {
|
|
81
|
+
await withWorkspaceStoreMutation(store, async () => {
|
|
82
|
+
const owned = await readBuildDirectories(store, workspace);
|
|
83
|
+
const users = await readBuildDirectoryUsers(store);
|
|
84
|
+
const retained = [];
|
|
85
|
+
const pending = new Set(owned);
|
|
86
|
+
for (const path of owned.sort((a, b) => b.length - a.length)) {
|
|
87
|
+
const others = (Object.hasOwn(users, path) ? users[path] : []).filter((name) => name !== workspace);
|
|
88
|
+
if (others.length) {
|
|
89
|
+
users[path] = others;
|
|
90
|
+
pending.delete(path);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if ((await store.stat(path))?.type !== "directory") {
|
|
94
|
+
delete users[path];
|
|
95
|
+
pending.delete(path);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if ((await store.list(path)).length) {
|
|
99
|
+
retained.push(path);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!store.removeEmptyDirectory) {
|
|
103
|
+
retained.push(path);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const previousUsers = users[path];
|
|
107
|
+
delete users[path];
|
|
108
|
+
pending.delete(path);
|
|
109
|
+
await writeBuildMetadata(store, buildDirectoriesMetaKey(workspace), [...pending]);
|
|
110
|
+
await writeBuildMetadata(store, buildDirectoryUsersMetaKey, users);
|
|
111
|
+
try {
|
|
112
|
+
await store.removeEmptyDirectory(path);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
pending.add(path);
|
|
115
|
+
if (previousUsers) users[path] = previousUsers;
|
|
116
|
+
await writeBuildMetadata(store, buildDirectoriesMetaKey(workspace), [...pending]);
|
|
117
|
+
await writeBuildMetadata(store, buildDirectoryUsersMetaKey, users);
|
|
118
|
+
const code = error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
119
|
+
if (code === "ENOTEMPTY" || code === "WORKSPACE_FAILED" && error instanceof Error && error.message === `[vitehub] Workspace directory is not empty: ${path}.`) {
|
|
120
|
+
retained.push(path);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
await writeBuildMetadata(store, buildDirectoriesMetaKey(workspace), retained);
|
|
127
|
+
await writeBuildMetadata(store, buildDirectoryUsersMetaKey, users);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function createBuildLoaderStore(workspace, store, sources, mutationStore = store, abortSignal, trackOperation) {
|
|
131
|
+
const records = await readBuildFiles(store, workspace);
|
|
132
|
+
const record = async (path, source, digest) => {
|
|
133
|
+
if (typeof source !== "string") return;
|
|
134
|
+
const normalized = normalizeWorkspacePath(path);
|
|
135
|
+
records[normalized] = {
|
|
136
|
+
source,
|
|
137
|
+
digest
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
await recordWorkspaceFileOwner(mutationStore, normalized, {
|
|
141
|
+
workspace,
|
|
142
|
+
source,
|
|
143
|
+
digest
|
|
144
|
+
});
|
|
145
|
+
} finally {
|
|
146
|
+
await writeBuildMetadata(mutationStore, buildFilesMetaKey(workspace), records);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const checkpointWrite = async (path, write, checkpoint) => {
|
|
150
|
+
const normalized = normalizeWorkspacePath(path);
|
|
151
|
+
const previous = records[normalized];
|
|
152
|
+
return await withWorkspaceFileCheckpoint(mutationStore, path, write, checkpoint, async () => {
|
|
153
|
+
if (previous) records[normalized] = previous;
|
|
154
|
+
else delete records[normalized];
|
|
155
|
+
await writeBuildMetadata(mutationStore, buildFilesMetaKey(workspace), records);
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
let writes = Promise.resolve();
|
|
159
|
+
const mutate = (operation) => {
|
|
160
|
+
abortSignal?.throwIfAborted();
|
|
161
|
+
const pending = writes.then(() => withWorkspaceStoreMutation(mutationStore, operation));
|
|
162
|
+
writes = pending.then(() => {}, () => {});
|
|
163
|
+
return trackOperation ? trackOperation(pending) : pending;
|
|
164
|
+
};
|
|
165
|
+
const mounts = [...sources].sort((a, b) => b.mountPath.length - a.mountPath.length);
|
|
166
|
+
const tag = (path, file) => {
|
|
167
|
+
const normalized = normalizeWorkspacePath(path);
|
|
168
|
+
const candidates = mounts.filter((source) => !source.mountPath || normalized.startsWith(`${source.mountPath}/`));
|
|
169
|
+
const declared = candidates.find((source) => source.key === file.metadata?.source);
|
|
170
|
+
const closest = candidates.filter((source) => source.mountPath.length === candidates[0]?.mountPath.length);
|
|
171
|
+
if (!declared && closest.length > 1) throw workspaceError(`[vitehub] Loader output "${normalized}" matches multiple build Sources. Set metadata.source to the Source key that owns this output.`);
|
|
172
|
+
const source = declared ?? closest[0];
|
|
173
|
+
return source ? {
|
|
174
|
+
...file,
|
|
175
|
+
metadata: {
|
|
176
|
+
...file.metadata,
|
|
177
|
+
workspaceBuildSource: source.key,
|
|
178
|
+
workspaceSourceOwner: workspace
|
|
179
|
+
}
|
|
180
|
+
} : file;
|
|
181
|
+
};
|
|
182
|
+
return new Proxy(store, { get(target, property) {
|
|
183
|
+
if (property === "writeFile") return async (path, file) => await mutate(async () => {
|
|
184
|
+
const tagged = tag(path, file);
|
|
185
|
+
const directories = parentPaths(path);
|
|
186
|
+
const missing = await missingBuildDirectories(mutationStore, directories);
|
|
187
|
+
await checkpointWrite(path, () => mutationStore.writeFile(path, tagged), async () => {
|
|
188
|
+
try {
|
|
189
|
+
await record(path, tagged.metadata?.workspaceBuildSource, await sha256(file.content));
|
|
190
|
+
} finally {
|
|
191
|
+
await recordBuildDirectories(mutationStore, workspace, directories, missing);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
if (property === "writeFileConditional" && target.writeFileConditional) return async (path, file, digest) => await mutate(async () => {
|
|
196
|
+
const tagged = tag(path, file);
|
|
197
|
+
const directories = parentPaths(path);
|
|
198
|
+
const missing = await missingBuildDirectories(mutationStore, directories);
|
|
199
|
+
await checkpointWrite(path, () => mutationStore.writeFileConditional(path, tagged, digest), async () => {
|
|
200
|
+
try {
|
|
201
|
+
await record(path, tagged.metadata?.workspaceBuildSource, await sha256(file.content));
|
|
202
|
+
} finally {
|
|
203
|
+
await recordBuildDirectories(mutationStore, workspace, directories, missing);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
if (property === "writeFileStream" && target.writeFileStream) return async (path, file) => await mutate(async () => {
|
|
208
|
+
const tagged = tag(path, file);
|
|
209
|
+
const hash = createHash("sha256");
|
|
210
|
+
const content = (async function* () {
|
|
211
|
+
for await (const chunk of contentStreamChunks(tagged.content)) {
|
|
212
|
+
hash.update(chunk);
|
|
213
|
+
yield chunk;
|
|
214
|
+
}
|
|
215
|
+
})();
|
|
216
|
+
const directories = parentPaths(path);
|
|
217
|
+
const missing = await missingBuildDirectories(mutationStore, directories);
|
|
218
|
+
return await checkpointWrite(path, () => mutationStore.writeFileStream(path, {
|
|
219
|
+
...tagged,
|
|
220
|
+
content
|
|
221
|
+
}), async () => {
|
|
222
|
+
try {
|
|
223
|
+
await record(path, tagged.metadata?.workspaceBuildSource, hash.digest("hex"));
|
|
224
|
+
} finally {
|
|
225
|
+
await recordBuildDirectories(mutationStore, workspace, directories, missing);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
return Reflect.get(target, property, target)?.bind(target);
|
|
230
|
+
} });
|
|
231
|
+
}
|
|
232
|
+
const STORE_MUTATIONS = /* @__PURE__ */ new Set([
|
|
233
|
+
"mkdir",
|
|
234
|
+
"rebase",
|
|
235
|
+
"removeEmptyDirectory",
|
|
236
|
+
"rm",
|
|
237
|
+
"setMeta",
|
|
238
|
+
"snapshot",
|
|
239
|
+
"writeFile",
|
|
240
|
+
"writeFileConditional",
|
|
241
|
+
"writeFileStream"
|
|
242
|
+
]);
|
|
243
|
+
function createAbortFencedStore(store, abortSignal) {
|
|
244
|
+
const active = /* @__PURE__ */ new Set();
|
|
245
|
+
let settleIdle;
|
|
246
|
+
const idle = () => active.size ? new Promise((resolve) => {
|
|
247
|
+
settleIdle = resolve;
|
|
248
|
+
}) : Promise.resolve();
|
|
249
|
+
const track = (operation) => {
|
|
250
|
+
active.add(operation);
|
|
251
|
+
operation.then(() => {
|
|
252
|
+
active.delete(operation);
|
|
253
|
+
if (!active.size) {
|
|
254
|
+
settleIdle?.();
|
|
255
|
+
settleIdle = void 0;
|
|
256
|
+
}
|
|
257
|
+
}, () => {
|
|
258
|
+
active.delete(operation);
|
|
259
|
+
if (!active.size) {
|
|
260
|
+
settleIdle?.();
|
|
261
|
+
settleIdle = void 0;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
return operation;
|
|
265
|
+
};
|
|
266
|
+
const fenced = new Proxy(store, { get(target, property) {
|
|
267
|
+
const value = Reflect.get(target, property, target);
|
|
268
|
+
if (!STORE_MUTATIONS.has(String(property))) return value?.bind(target);
|
|
269
|
+
if (value === void 0) return void 0;
|
|
270
|
+
return (...args) => {
|
|
271
|
+
abortSignal.throwIfAborted();
|
|
272
|
+
const operation = Promise.resolve(Reflect.apply(value, target, args));
|
|
273
|
+
return track(operation);
|
|
274
|
+
};
|
|
275
|
+
} });
|
|
276
|
+
registerWorkspaceStoreAlias(fenced, store);
|
|
277
|
+
return {
|
|
278
|
+
fenced,
|
|
279
|
+
idle,
|
|
280
|
+
track
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async function waitForFencedSync(operation, signal, idle) {
|
|
284
|
+
let removeAbortListener = () => {};
|
|
285
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
286
|
+
const onAbort = () => {
|
|
287
|
+
idle().then(() => reject(signal.reason));
|
|
288
|
+
};
|
|
289
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
290
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
291
|
+
if (signal.aborted) onAbort();
|
|
292
|
+
});
|
|
293
|
+
try {
|
|
294
|
+
await Promise.race([operation, aborted]);
|
|
295
|
+
} finally {
|
|
296
|
+
removeAbortListener();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async function syncWorkspaceDefinition(definition, store, abortSignal) {
|
|
300
|
+
if (!abortSignal) return await syncWorkspaceDefinitionInternal(definition, store);
|
|
301
|
+
const { fenced, idle, track } = createAbortFencedStore(store, abortSignal);
|
|
302
|
+
await waitForFencedSync(syncWorkspaceDefinitionInternal(definition, fenced, abortSignal, store, track), abortSignal, idle);
|
|
303
|
+
}
|
|
304
|
+
async function syncWorkspaceDefinitionInternal(definition, store, abortSignal, materializationStore = store, trackOperation) {
|
|
305
|
+
abortSignal?.throwIfAborted();
|
|
306
|
+
const loaders = definition.loaders?.length ? definition.loaders : [files()];
|
|
307
|
+
const hasExplicitLoaders = !!definition.loaders?.length;
|
|
308
|
+
const ctxSource = createSourceContext(definition, void 0, store);
|
|
309
|
+
const sources = normalizeWorkspaceSources(definition.sources);
|
|
310
|
+
const buildSources = sources.filter((source) => source.materialize === "build");
|
|
311
|
+
const startupSources = sources.filter((source) => source.materialize === "startup");
|
|
312
|
+
await reconcileRemovedStartupSources(definition.name, store, startupSources, void 0, materializationStore);
|
|
313
|
+
abortSignal?.throwIfAborted();
|
|
314
|
+
const hasBuildSourceState = await reconcileBuildSourceMounts(definition, store, materializationStore, buildSources, startupSources, abortSignal, trackOperation);
|
|
315
|
+
abortSignal?.throwIfAborted();
|
|
316
|
+
const buildStore = await createBuildLoaderStore(definition.name, store, buildSources, materializationStore, abortSignal, trackOperation);
|
|
317
|
+
const bundledBuildSources = !hasExplicitLoaders ? await syncRuntimeBuildAssets(definition, buildStore, buildSources, abortSignal) : void 0;
|
|
318
|
+
abortSignal?.throwIfAborted();
|
|
319
|
+
if (bundledBuildSources && buildSources.every((source) => bundledBuildSources.has(source.key))) {
|
|
320
|
+
await invalidateOverwrittenStartupSnapshots(definition, store, materializationStore, startupSources, buildSources);
|
|
321
|
+
await store.snapshot({ name: "sync" });
|
|
322
|
+
abortSignal?.throwIfAborted();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (!hasBuildSourceState && !hasExplicitLoaders) return;
|
|
326
|
+
const normalizedSources = buildSources.filter((source) => !bundledBuildSources?.has(source.key)).map((source) => createMountedBuildSource(source, definition.name));
|
|
327
|
+
const ctx = {
|
|
328
|
+
abortSignal,
|
|
329
|
+
workspace: definition.name,
|
|
330
|
+
rootDir: ctxSource.rootDir,
|
|
331
|
+
sourceRootDir: ctxSource.sourceRootDir,
|
|
332
|
+
sources: normalizedSources,
|
|
333
|
+
store: buildStore,
|
|
334
|
+
parseData: async (input) => input.data,
|
|
335
|
+
generateDigest: (input) => JSON.stringify(input),
|
|
336
|
+
logger: console
|
|
337
|
+
};
|
|
338
|
+
for (const loader of loaders) {
|
|
339
|
+
abortSignal?.throwIfAborted();
|
|
340
|
+
await loader.load(ctx);
|
|
341
|
+
}
|
|
342
|
+
abortSignal?.throwIfAborted();
|
|
343
|
+
await invalidateOverwrittenStartupSnapshots(definition, store, materializationStore, startupSources, buildSources);
|
|
344
|
+
await store.snapshot({ name: "sync" });
|
|
345
|
+
abortSignal?.throwIfAborted();
|
|
346
|
+
}
|
|
347
|
+
async function invalidateOverwrittenStartupSnapshots(definition, store, materializationStore, startupSources, buildSources) {
|
|
348
|
+
for (const source of startupSources) {
|
|
349
|
+
const snapshot = await readCurrentSourceSnapshot(store, definition.name, source);
|
|
350
|
+
if (snapshot?.status !== "ready") continue;
|
|
351
|
+
for (const path of Object.keys(snapshot.items || {})) {
|
|
352
|
+
const file = await store.readFile(path);
|
|
353
|
+
if (!file) continue;
|
|
354
|
+
const owner = await readWorkspaceFileOwner(store, path);
|
|
355
|
+
if (!(owner ? owner.workspace === definition.name && buildSources.some((buildSource) => buildSource.key === owner.source) && await sha256(file.content) === owner.digest : (file.metadata?.workspaceSourceOwner === void 0 || file.metadata.workspaceSourceOwner === definition.name) && buildSources.some((buildSource) => buildSource.key === file.metadata?.source || buildSource.key === file.metadata?.workspaceBuildSource))) continue;
|
|
356
|
+
await invalidateWorkspaceSourceMaterialization(definition, materializationStore, [source.key]);
|
|
357
|
+
await invalidateSourceSnapshot(store, definition.name, source.key);
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
async function reconcileBuildSourceMounts(definition, store, materializationStore, currentSources, startupSources, abortSignal, trackOperation) {
|
|
363
|
+
abortSignal?.throwIfAborted();
|
|
364
|
+
const previousSources = await readSyncedBuildSources(store, definition.name);
|
|
365
|
+
abortSignal?.throwIfAborted();
|
|
366
|
+
const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
|
|
367
|
+
const resetPaths = [.../* @__PURE__ */ new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
|
|
368
|
+
const mutate = async (operation) => {
|
|
369
|
+
abortSignal?.throwIfAborted();
|
|
370
|
+
const pending = operation();
|
|
371
|
+
await (trackOperation ? trackOperation(pending) : pending);
|
|
372
|
+
};
|
|
373
|
+
for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) {
|
|
374
|
+
abortSignal?.throwIfAborted();
|
|
375
|
+
const buildKeys = [...previousSources, ...currentSources].filter((source) => source.mountPath === mountPath).map((source) => source.key);
|
|
376
|
+
await mutate(() => withWorkspaceStoreMutation(materializationStore, async () => {
|
|
377
|
+
const removedPaths = await buildSourceFilePaths(materializationStore, definition.name, mountPath, buildKeys);
|
|
378
|
+
const affected = [];
|
|
379
|
+
for (const startup of startupSources.filter((source) => sourceMountIntersectsPath(source, mountPath))) {
|
|
380
|
+
if (!(startup.mountPath === mountPath || startup.mountPath.startsWith(`${mountPath}/`)) && await sourceSnapshotOwnsAnyPath(store, definition.name, startup.key, removedPaths) === false) continue;
|
|
381
|
+
affected.push(startup);
|
|
382
|
+
}
|
|
383
|
+
await invalidateWorkspaceSourceMaterialization(definition, materializationStore, affected.map((source) => source.key));
|
|
384
|
+
for (const source of affected) await invalidateSourceSnapshot(store, definition.name, source.key);
|
|
385
|
+
abortSignal?.throwIfAborted();
|
|
386
|
+
await removeBuildSourceFiles(materializationStore, definition.name, removedPaths);
|
|
387
|
+
}));
|
|
388
|
+
abortSignal?.throwIfAborted();
|
|
389
|
+
}
|
|
390
|
+
const rootSourceKeys = new Set([...previousSources, ...currentSources].filter((source) => !source.mountPath).map((source) => source.key));
|
|
391
|
+
for (const key of rootSourceKeys) {
|
|
392
|
+
abortSignal?.throwIfAborted();
|
|
393
|
+
await mutate(() => withWorkspaceStoreMutation(materializationStore, async () => {
|
|
394
|
+
const removedPaths = await buildSourceFilePaths(materializationStore, definition.name, "", [key]);
|
|
395
|
+
const affected = [];
|
|
396
|
+
for (const startup of startupSources) {
|
|
397
|
+
if (!removedPaths.some((path) => sourceMountIntersectsPath(startup, path))) continue;
|
|
398
|
+
if (await sourceSnapshotOwnsAnyPath(store, definition.name, startup.key, removedPaths) === false) continue;
|
|
399
|
+
affected.push(startup);
|
|
400
|
+
}
|
|
401
|
+
await invalidateWorkspaceSourceMaterialization(definition, materializationStore, affected.map((startup) => startup.key));
|
|
402
|
+
for (const startup of affected) await invalidateSourceSnapshot(store, definition.name, startup.key);
|
|
403
|
+
abortSignal?.throwIfAborted();
|
|
404
|
+
await removeBuildSourceFiles(materializationStore, definition.name, removedPaths);
|
|
405
|
+
}));
|
|
406
|
+
abortSignal?.throwIfAborted();
|
|
407
|
+
}
|
|
408
|
+
await mutate(() => pruneBuildDirectories(materializationStore, definition.name));
|
|
409
|
+
for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) {
|
|
410
|
+
abortSignal?.throwIfAborted();
|
|
411
|
+
await mutate(() => withWorkspaceStoreMutation(materializationStore, async () => {
|
|
412
|
+
const directories = [...parentPaths(mountPath), mountPath];
|
|
413
|
+
const missing = await missingBuildDirectories(materializationStore, directories);
|
|
414
|
+
await materializationStore.mkdir(mountPath, { recursive: true });
|
|
415
|
+
await recordBuildDirectories(materializationStore, definition.name, directories, missing);
|
|
416
|
+
}));
|
|
417
|
+
abortSignal?.throwIfAborted();
|
|
418
|
+
}
|
|
419
|
+
abortSignal?.throwIfAborted();
|
|
420
|
+
await writeBuildMetadata(store, buildFilesMetaKey(definition.name), {});
|
|
421
|
+
await writeBuildMetadata(store, buildSourcesMetaKey(definition.name), currentSources.map(({ key, mountPath }) => ({
|
|
422
|
+
key,
|
|
423
|
+
mountPath
|
|
424
|
+
})));
|
|
425
|
+
return hasBuildSourceState;
|
|
426
|
+
}
|
|
427
|
+
async function syncRuntimeBuildAssets(definition, store, currentSources, abortSignal) {
|
|
428
|
+
abortSignal?.throwIfAborted();
|
|
429
|
+
if (!currentSources.length) return void 0;
|
|
430
|
+
let assets;
|
|
431
|
+
try {
|
|
432
|
+
assets = useWorkspaceAssets(definition.name);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
const entries = await assets.list("", { recursive: true });
|
|
438
|
+
abortSignal?.throwIfAborted();
|
|
439
|
+
const files = entries.filter((entry) => entry.type === "file");
|
|
440
|
+
const bundledPaths = new Set(files.map((entry) => entry.path));
|
|
441
|
+
const bundledSourceByPath = /* @__PURE__ */ new Map();
|
|
442
|
+
const bundledBuildSources = /* @__PURE__ */ new Set();
|
|
443
|
+
for (const source of currentSources) {
|
|
444
|
+
abortSignal?.throwIfAborted();
|
|
445
|
+
if (await hasCompleteBundledBuildSource(definition, store, source, bundledPaths, files, bundledSourceByPath, abortSignal)) {
|
|
446
|
+
abortSignal?.throwIfAborted();
|
|
447
|
+
bundledBuildSources.add(source.key);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
for (const entry of files) {
|
|
451
|
+
abortSignal?.throwIfAborted();
|
|
452
|
+
const sourceKey = typeof entry.metadata?.source === "string" ? entry.metadata.source : bundledSourceByPath.get(entry.path) || findBuildSourceForPath(entry.path, currentSources)?.key;
|
|
453
|
+
const content = await assets.readFile(entry.path, { encoding: "binary" });
|
|
454
|
+
abortSignal?.throwIfAborted();
|
|
455
|
+
await store.writeFile(entry.path, {
|
|
456
|
+
path: entry.path,
|
|
457
|
+
content,
|
|
458
|
+
mediaType: entry.mediaType,
|
|
459
|
+
metadata: sourceKey ? {
|
|
460
|
+
...entry.metadata,
|
|
461
|
+
source: sourceKey,
|
|
462
|
+
workspaceSourceOwner: definition.name
|
|
463
|
+
} : entry.metadata
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return bundledBuildSources;
|
|
467
|
+
}
|
|
468
|
+
async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath, abortSignal) {
|
|
469
|
+
const probeKeys = source.probeKeys;
|
|
470
|
+
if (!probeKeys?.length) {
|
|
471
|
+
const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
|
|
472
|
+
const sourcePaths = await tryListBuildSourcePaths(definition, store, source, abortSignal);
|
|
473
|
+
if (sourcePaths && !sourcePaths.every((path) => paths.includes(path))) return false;
|
|
474
|
+
for (const path of paths) bundledSourceByPath?.set(path, source.key);
|
|
475
|
+
return paths.length > 0;
|
|
476
|
+
}
|
|
477
|
+
const paths = probeKeys.map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
|
|
478
|
+
if (!paths.every((path) => bundledPaths.has(path))) return false;
|
|
479
|
+
for (const path of paths) bundledSourceByPath?.set(path, source.key);
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
async function tryListBuildSourcePaths(definition, store, source, abortSignal) {
|
|
483
|
+
const ctx = createSourceContext(definition, {
|
|
484
|
+
key: source.key,
|
|
485
|
+
mountPath: source.mountPath
|
|
486
|
+
}, store, { abortSignal });
|
|
487
|
+
try {
|
|
488
|
+
await prepareWorkspaceSource(source.source, ctx);
|
|
489
|
+
return (await source.source.getKeys(ctx)).map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
|
|
490
|
+
} catch {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function findBuildSourceForPath(path, sources) {
|
|
495
|
+
const matches = sources.filter((source) => !source.mountPath || path === source.mountPath || path.startsWith(`${source.mountPath}/`)).sort((left, right) => right.mountPath.length - left.mountPath.length)[0];
|
|
496
|
+
if (!matches?.mountPath && sources.filter((source) => !source.mountPath).length > 1) return void 0;
|
|
497
|
+
return matches;
|
|
498
|
+
}
|
|
499
|
+
async function readSyncedBuildSources(store, workspace) {
|
|
500
|
+
const value = await readBuildMetadata(store, buildSourcesMetaKey(workspace));
|
|
501
|
+
if (!Array.isArray(value)) return [];
|
|
502
|
+
return value.filter(isSyncedBuildSource);
|
|
503
|
+
}
|
|
504
|
+
async function readBuildFiles(store, workspace) {
|
|
505
|
+
const value = await readBuildMetadata(store, buildFilesMetaKey(workspace));
|
|
506
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
507
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => {
|
|
508
|
+
const record = entry[1];
|
|
509
|
+
return !!record && typeof record === "object" && "source" in record && typeof record.source === "string" && "digest" in record && typeof record.digest === "string";
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
async function buildSourceFilePaths(store, workspace, mountPath, keys) {
|
|
513
|
+
const paths = [];
|
|
514
|
+
const records = await readBuildFiles(store, workspace);
|
|
515
|
+
for (const [path, record] of Object.entries(records)) if (keys.includes(record.source)) await readWorkspaceFileOwner(store, path, true);
|
|
516
|
+
for (const entry of await store.list(mountPath, { recursive: true })) {
|
|
517
|
+
if (entry.type !== "file") continue;
|
|
518
|
+
const file = entry.metadata ? void 0 : await store.readFile(entry.path);
|
|
519
|
+
const metadata = entry.metadata ?? file?.metadata;
|
|
520
|
+
if (metadata?.workspaceSourceOwner !== void 0 && metadata.workspaceSourceOwner !== workspace) continue;
|
|
521
|
+
const owner = await readWorkspaceFileOwner(store, entry.path);
|
|
522
|
+
const record = records[entry.path] ?? (owner?.workspace === workspace && owner.digest ? {
|
|
523
|
+
source: owner.source,
|
|
524
|
+
digest: owner.digest
|
|
525
|
+
} : void 0);
|
|
526
|
+
if (record && keys.includes(record.source)) {
|
|
527
|
+
if (metadata?.workspaceSourceOwner === void 0 && (metadata?.source !== void 0 || metadata?.workspaceBuildSource !== void 0)) continue;
|
|
528
|
+
if (owner?.workspace !== workspace || owner.source !== record.source || owner.digest !== record.digest) continue;
|
|
529
|
+
if (entry.digest !== record.digest) {
|
|
530
|
+
const current = file ?? await store.readFile(entry.path);
|
|
531
|
+
if (!current || await sha256(current.content) !== record.digest) {
|
|
532
|
+
await removeWorkspaceFileOwner(store, entry.path);
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
paths.push(entry.path);
|
|
537
|
+
} else if (metadata?.workspaceSourceOwner === workspace && keys.some((key) => metadata.source === key || metadata.workspaceBuildSource === key)) paths.push(entry.path);
|
|
538
|
+
}
|
|
539
|
+
return paths;
|
|
540
|
+
}
|
|
541
|
+
async function removeBuildSourceFiles(store, workspace, paths) {
|
|
542
|
+
const records = await readBuildFiles(store, workspace);
|
|
543
|
+
for (const path of paths) {
|
|
544
|
+
await removeWorkspaceOwnedFile(store, path);
|
|
545
|
+
delete records[path];
|
|
546
|
+
await writeBuildMetadata(store, buildFilesMetaKey(workspace), records);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function isSyncedBuildSource(value) {
|
|
550
|
+
return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
|
|
551
|
+
}
|
|
552
|
+
function createMountedBuildSource(source, workspace) {
|
|
553
|
+
const sourceContexts = /* @__PURE__ */ new WeakMap();
|
|
554
|
+
function getSourceContext(ctx) {
|
|
555
|
+
let sourceContext = sourceContexts.get(ctx);
|
|
556
|
+
if (sourceContext) return sourceContext;
|
|
557
|
+
sourceContext = {
|
|
558
|
+
...ctx,
|
|
559
|
+
mountPath: source.mountPath,
|
|
560
|
+
source: source.key
|
|
561
|
+
};
|
|
562
|
+
sourceContexts.set(ctx, sourceContext);
|
|
563
|
+
return sourceContext;
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
...source.source,
|
|
567
|
+
key: source.key,
|
|
568
|
+
async resolveRevision(ctx) {
|
|
569
|
+
const sourceContext = getSourceContext(ctx);
|
|
570
|
+
const revision = await source.source.resolveRevision?.(sourceContext);
|
|
571
|
+
if (revision) sourceContext.revision = revision;
|
|
572
|
+
return revision;
|
|
573
|
+
},
|
|
574
|
+
async prepare(ctx) {
|
|
575
|
+
await prepareWorkspaceSource(source.source, getSourceContext(ctx));
|
|
576
|
+
},
|
|
577
|
+
async getKeys(ctx) {
|
|
578
|
+
return await source.source.getKeys(getSourceContext(ctx));
|
|
579
|
+
},
|
|
580
|
+
async getItem(key, ctx) {
|
|
581
|
+
const item = await source.source.getItem(key, getSourceContext(ctx));
|
|
582
|
+
const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
|
|
583
|
+
return {
|
|
584
|
+
...item,
|
|
585
|
+
path,
|
|
586
|
+
metadata: {
|
|
587
|
+
...item.metadata,
|
|
588
|
+
source: source.key,
|
|
589
|
+
workspaceSourceOwner: workspace
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
//#endregion
|
|
596
|
+
export { syncWorkspaceDefinition as n, lifecycle_exports as t };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/lineage.d.ts
|
|
2
|
+
/** Where a derived file, such as a translation, came from: a Workspace path and the SHA-256 of its bytes then. */
|
|
3
|
+
export interface WorkspaceDerivedFrom {
|
|
4
|
+
path: string;
|
|
5
|
+
digest: string;
|
|
6
|
+
}
|
|
7
|
+
/** A derived file whose source changed or is gone since it was made. */
|
|
8
|
+
export interface WorkspaceStaleFile {
|
|
9
|
+
path: string;
|
|
10
|
+
derivedFrom: WorkspaceDerivedFrom;
|
|
11
|
+
/** `changed`: the source has other bytes now. `missing`: the source is gone. */
|
|
12
|
+
reason: "changed" | "missing";
|
|
13
|
+
/** The digest of the source now. Write it as `derivedFrom.digest` after you update the file. */
|
|
14
|
+
sourceDigest?: string;
|
|
15
|
+
}
|
|
16
|
+
/** The digest that `derivedFrom.digest` holds: `sha256-` and the hex SHA-256 of the file bytes. */
|
|
17
|
+
export declare function lineageDigest(bytes: Uint8Array): string;
|
|
18
|
+
/**
|
|
19
|
+
* Reads `derivedFrom` of a file: the YAML frontmatter of Markdown (`.md`, `.markdown`, `.mdx`),
|
|
20
|
+
* a YAML file (`.yaml`, `.yml`), or the top-level key of a JSON file (`.json`).
|
|
21
|
+
* Returns undefined for other files and for files without it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readDerivedFrom(path: string, bytes: Uint8Array): WorkspaceDerivedFrom | undefined;
|
|
24
|
+
/** The derived files of a file set whose source changed or is gone, sorted by path. */
|
|
25
|
+
export declare function staleDerivedFiles(files: ReadonlyMap<string, Uint8Array>): WorkspaceStaleFile[];
|
|
26
|
+
//#endregion
|