@vite-hub/workspace 0.4.1 → 0.5.1
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 +62 -19
- package/dist/{abort-BCwpdrN0.js → abort-CQGxJBqa.js} +1 -2
- package/dist/{asset-registry-DfBV5kmw.js → asset-registry-0CdRAjIV.js} +2 -3
- package/dist/blob-database/postgres.d.ts +423 -0
- package/dist/blob-database/postgres.js +1 -0
- package/dist/blob-database-sources-CQPAyCz3.js +8 -0
- package/dist/blob-database.d.ts +29 -449
- package/dist/blob-database.js +636 -210
- package/dist/checkout.d.ts +1 -2
- package/dist/checkout.js +3 -4
- package/dist/cloudflare.d.ts +1 -5
- package/dist/cloudflare.js +1 -2
- package/dist/{config-B-863EgC.js → config-CsgNNVAI.js} +1 -2
- package/dist/{config-CDeGd0RB.d.ts → config-DeA287c0.d.ts} +1 -5
- package/dist/{config-D1QENneP.js → config-jo5QgE1w.js} +18 -27
- package/dist/{discard-CNNtCozM.js → discard-BkoLmmmN.js} +1 -2
- package/dist/durability.d.ts +10 -4
- package/dist/durability.js +47 -6
- package/dist/{error-diagnostics-B5s9kNEA.js → error-diagnostics-B4me-ouV.js} +11 -4
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-kKXseq8d.js} +10 -3
- package/dist/{path-uxLkzrZm.d.ts → errors-CnFDXxeJ.d.ts} +0 -3
- package/dist/{file-CqG9zqiF.js → file-BrNAXQgY.js} +4 -8
- package/dist/{target-Dm9dHAVJ.js → file-metadata-Bpsvjw_X.js} +3 -32
- package/dist/{files-B6wpAhEx.js → files--z2dLC5z.js} +3 -4
- package/dist/files.d.ts +12 -8
- package/dist/files.js +7 -6
- package/dist/{github-DKAlO0Vh.js → github-k--_LCrX.js} +7 -9
- package/dist/{glob-BOqSKzSg.js → glob-BEutagp1.js} +9 -10
- package/dist/{glob-Cjxms1t7.js → glob-BreFjNAV.js} +3 -4
- package/dist/history-schema-BR4UDPHL.d.ts +434 -0
- package/dist/history-schema-postgres-DZepCSBq.js +40 -0
- package/dist/{host-Bf1a2uo_.js → host-C8yZizfk.js} +153 -22
- package/dist/{hosted-zG7HJaE4.js → hosted-8BTKAtMX.js} +27 -21
- package/dist/{hosted-vercel-blob-AbXG8fvR.js → hosted-vercel-blob-B6kygYqn.js} +10 -12
- package/dist/hosted-vercel-blob.d.ts +1 -3
- package/dist/hosted-vercel-blob.js +1 -2
- package/dist/hosted.d.ts +1 -3
- package/dist/hosted.js +1 -2
- package/dist/index.d.ts +11 -41
- package/dist/index.js +34 -116
- package/dist/internal/path.d.ts +1 -1
- package/dist/internal/path.js +1 -2
- package/dist/internal/workspace.d.ts +10 -0
- package/dist/internal/workspace.js +85 -0
- package/dist/{lifecycle-D8FdpBod.js → lifecycle-IReZfi0b.js} +15 -13
- package/dist/lineage.d.ts +1 -3
- package/dist/lineage.js +1 -2
- package/dist/loader.d.ts +1 -7
- package/dist/loader.js +4 -6
- package/dist/{mcp-resources-DntxtmDU.js → mcp-resources-DeJnbOaw.js} +4 -5
- package/dist/{memory-D5jq9HZW.js → memory-BlSRrBH1.js} +19 -13
- package/dist/{metadata-target-DDoOQNp1.js → metadata-target-CaGLY4ay.js} +214 -77
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-DsY2MQnG.js → operations-CtRDU3cA.js} +34 -29
- package/dist/{operations-D8uCpzhM.js → operations-DfbqHWAe.js} +7 -8
- package/dist/operations.d.ts +2 -6
- package/dist/operations.js +2 -2
- package/dist/{path--wrT_Azm.js → path-Bb9OIc_F.js} +3 -19
- package/dist/{path-zHxQUbqa.d.ts → path-C0uZxDdW.d.ts} +0 -2
- package/dist/{path-DrSIenjj.js → path-CuYE8-X6.js} +2 -4
- package/dist/{plugins-CsrXCA1Q.d.ts → plugins-CLc32jvL.d.ts} +1 -3
- package/dist/{provider-sm9uzkLg.js → provider-CN14ewvx.js} +30 -22
- package/dist/providers/github/store.d.ts +2 -4
- package/dist/providers/github/store.js +1 -2
- package/dist/{registry-CFl1Htyc.d.ts → registry-B0g19sdy.d.ts} +5 -8
- package/dist/{registry-DmVfUe4K.js → registry-BbUg9vJB.js} +10 -6
- package/dist/registry-s2Ob9PeX.d.ts +9 -0
- package/dist/{request-scope-Dw5n8bMC.js → request-scope-CXCI_wCb.js} +4 -4
- package/dist/{results-DgkZUmTL.js → results-z-HpV9EP.js} +1 -2
- package/dist/{rolldown-runtime-rQ84J-ij.js → rolldown-runtime-DnNXxpGL.js} +2 -3
- package/dist/rule-keys-BLEbi1h5.js +18 -0
- package/dist/rules-BPDXypZV.js +267 -0
- package/dist/runtime/assets.d.ts +2 -3
- package/dist/runtime/assets.js +5 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -3
- package/dist/runtime/empty-assets-registry.js +1 -2
- package/dist/runtime/empty-registry.d.ts +2 -4
- package/dist/runtime/empty-registry.js +1 -2
- package/dist/runtime/registry.d.ts +2 -2
- package/dist/runtime/registry.js +2 -3
- package/dist/runtime/request.d.ts +1 -3
- package/dist/runtime/request.js +2 -3
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +18 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -2
- package/dist/runtime.d.ts +9 -24
- package/dist/runtime.js +29 -25
- package/dist/{search-C_RfoM2j.js → search-C_nVorq7.js} +3 -4
- package/dist/{server-Cd4-iCh5.js → server-aa1a4rkV.js} +8 -10
- package/dist/server.d.ts +3 -4
- package/dist/server.js +1 -2
- package/dist/{shared-ovXVSV3-.js → shared-C20Wh1mp.js} +23 -19
- package/dist/source-metadata.d.ts +2 -6
- package/dist/source-metadata.js +4 -5
- package/dist/state-BdDfBtOR.d.ts +17 -0
- package/dist/{store-NZoRto-Y.js → store-cx3OqNTi.js} +42 -44
- package/dist/{sync-CrT8zjwc.js → sync-BBfR4g5y.js} +6 -7
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -2
- package/dist/{types-1Z-tKK3g.d.ts → types-Bel5IDmF.d.ts} +52 -6
- package/dist/{use-CjbF8EO9.d.ts → use-CpphIBof.d.ts} +20 -32
- package/dist/{use-B0o5HoBl.js → use-D0DyTMxM.js} +19 -21
- package/dist/use-tools-CAK10LTc.d.ts +10 -0
- package/dist/{state-Cb_hIyAw.js → use-tools-CHduR5k6.js} +8 -24
- package/dist/{utils-Dw-WULEZ.js → utils-DXP9xfXo.js} +80 -273
- package/dist/vite.d.ts +30 -19
- package/dist/vite.js +1481 -1617
- package/dist/vitehub-grants-Co713QTg.js +36 -0
- package/dist/workspace-BOuxrZrP.d.ts +5 -0
- package/dist/{workspace-DvKu5PRa.js → workspace-CLuPkyZR.js} +28 -36
- package/package.json +34 -24
- package/dist/registry-CwryP59t.d.ts +0 -9
- package/dist/state-C-YtsaiJ.d.ts +0 -35
- package/dist/workspace-CIXgHeyX.d.ts +0 -7
|
@@ -1,273 +1,11 @@
|
|
|
1
|
-
import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-CuYE8-X6.js";
|
|
2
|
+
import { n as copyJsonWorkspaceMetadata, t as copyJsonFileMetadata } from "./file-metadata-Bpsvjw_X.js";
|
|
3
|
+
import { d as sha256, o as isWorkspaceBytes, r as contentToBytes } from "./path-Bb9OIc_F.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-B4me-ouV.js";
|
|
5
|
+
import { t as createWorkspaceWritePolicy } from "./rules-BPDXypZV.js";
|
|
5
6
|
import { lookup } from "mrmime";
|
|
6
7
|
import { isRuntimeObject } from "@vite-hub/runtime/internal/runtime-type";
|
|
7
|
-
|
|
8
|
-
//#region src/core/plugins.ts
|
|
9
|
-
const contributedPluginsKey = Symbol.for("vitehub.workspace.contributedPlugins");
|
|
10
|
-
function contributedPluginState() {
|
|
11
|
-
const scope = globalThis;
|
|
12
|
-
scope[contributedPluginsKey] ??= {
|
|
13
|
-
plugins: /* @__PURE__ */ new Map(),
|
|
14
|
-
version: 0
|
|
15
|
-
};
|
|
16
|
-
return scope[contributedPluginsKey];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Add a plugin's rules and hooks to a Workspace by name, including discovered Workspaces the caller does not define.
|
|
20
|
-
* Registering the same plugin id again replaces the earlier registration. A plugin declared by the Workspace Definition
|
|
21
|
-
* with the same id wins. The returned function removes this registration.
|
|
22
|
-
*/
|
|
23
|
-
function registerWorkspacePlugin(workspace, plugin) {
|
|
24
|
-
if (typeof workspace !== "string" || !workspace) throw workspaceErrorDiagnostics.WORKSPACE_R0022({ message: "[vitehub] registerWorkspacePlugin requires a Workspace name." });
|
|
25
|
-
if (!plugin || typeof plugin.id !== "string" || !plugin.id) throw workspaceErrorDiagnostics.WORKSPACE_R0024({ message: "[vitehub] Workspace plugins require an id." });
|
|
26
|
-
assertWorkspaceRules(plugin.rules);
|
|
27
|
-
const state = contributedPluginState();
|
|
28
|
-
let plugins = state.plugins.get(workspace);
|
|
29
|
-
if (!plugins) state.plugins.set(workspace, plugins = /* @__PURE__ */ new Map());
|
|
30
|
-
plugins.set(plugin.id, plugin);
|
|
31
|
-
state.version++;
|
|
32
|
-
return () => {
|
|
33
|
-
if (state.plugins.get(workspace)?.get(plugin.id) !== plugin) return;
|
|
34
|
-
plugins.delete(plugin.id);
|
|
35
|
-
if (!plugins.size) state.plugins.delete(workspace);
|
|
36
|
-
state.version++;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** Changes whenever a contributed plugin is added, replaced, or removed. */
|
|
40
|
-
function workspacePluginsVersion() {
|
|
41
|
-
return contributedPluginState().version;
|
|
42
|
-
}
|
|
43
|
-
/** The Definition's own plugins followed by contributed plugins with other ids. */
|
|
44
|
-
function workspaceDefinitionPlugins(definition) {
|
|
45
|
-
const own = definition.plugins ?? [];
|
|
46
|
-
const contributed = contributedPluginState().plugins.get(definition.name);
|
|
47
|
-
if (!contributed?.size) return own;
|
|
48
|
-
const ids = new Set(own.map((plugin) => plugin?.id));
|
|
49
|
-
return [...own, ...[...contributed.values()].filter((plugin) => !ids.has(plugin.id))];
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/core/rules.ts
|
|
53
|
-
function normalizeMaxBytes(value) {
|
|
54
|
-
if (value === void 0) return void 0;
|
|
55
|
-
if (typeof value === "number") return value;
|
|
56
|
-
const match = /^(\d+)(kb|mb)$/.exec(value.toLowerCase());
|
|
57
|
-
if (!match) throw workspaceErrorDiagnostics.WORKSPACE_R0023({ message: `[vitehub] Invalid workspace rule maxBytes value "${value}".` });
|
|
58
|
-
const count = Number(match[1]);
|
|
59
|
-
return match[2] === "kb" ? count * 1024 : count * 1024 * 1024;
|
|
60
|
-
}
|
|
61
|
-
function toArray(value) {
|
|
62
|
-
if (value === void 0) return [];
|
|
63
|
-
return Array.isArray(value) ? value : [value];
|
|
64
|
-
}
|
|
65
|
-
function mergeHooks(left = {}, right = {}) {
|
|
66
|
-
return {
|
|
67
|
-
"write:after": [...toArray(left["write:after"]), ...toArray(right["write:after"])],
|
|
68
|
-
"write:before": [...toArray(left["write:before"]), ...toArray(right["write:before"])],
|
|
69
|
-
"write:error": [...toArray(left["write:error"]), ...toArray(right["write:error"])],
|
|
70
|
-
"write:validate": [...toArray(left["write:validate"]), ...toArray(right["write:validate"])]
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/** Merges rules on the same pattern field by field. A later rule replaces only the fields it sets, and validators add up. */
|
|
74
|
-
function mergeRules(left, right = {}) {
|
|
75
|
-
assertWorkspaceRules(right);
|
|
76
|
-
const merged = { ...left };
|
|
77
|
-
for (const [pattern, rule] of Object.entries(right)) {
|
|
78
|
-
const previous = merged[pattern];
|
|
79
|
-
if (!previous) {
|
|
80
|
-
merged[pattern] = rule;
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
const next = {
|
|
84
|
-
...previous,
|
|
85
|
-
validate: [...toArray(previous.validate), ...toArray(rule.validate)]
|
|
86
|
-
};
|
|
87
|
-
if (rule.commit !== void 0) next.commit = rule.commit;
|
|
88
|
-
if (rule.maxBytes !== void 0) next.maxBytes = rule.maxBytes;
|
|
89
|
-
if (rule.mediaType !== void 0) next.mediaType = rule.mediaType;
|
|
90
|
-
if (rule.write !== void 0) next.write = rule.write;
|
|
91
|
-
merged[pattern] = next;
|
|
92
|
-
}
|
|
93
|
-
return merged;
|
|
94
|
-
}
|
|
95
|
-
function normalizeRules(rules) {
|
|
96
|
-
return Object.entries(rules).map(([pattern, rule]) => {
|
|
97
|
-
const normalizedPattern = normalizeWorkspacePath(pattern);
|
|
98
|
-
return {
|
|
99
|
-
...rule,
|
|
100
|
-
maxBytes: normalizeMaxBytes(rule.maxBytes),
|
|
101
|
-
pattern: normalizedPattern,
|
|
102
|
-
specificity: normalizedPattern.replace(/\*/g, "").length,
|
|
103
|
-
validate: toArray(rule.validate)
|
|
104
|
-
};
|
|
105
|
-
}).sort((left, right) => left.specificity - right.specificity || left.pattern.localeCompare(right.pattern));
|
|
106
|
-
}
|
|
107
|
-
function normalizePolicy(definition) {
|
|
108
|
-
let hooks = {};
|
|
109
|
-
let rules = {};
|
|
110
|
-
for (const plugin of workspaceDefinitionPlugins(definition)) {
|
|
111
|
-
if (!plugin?.id) throw workspaceErrorDiagnostics.WORKSPACE_R0024({ message: "[vitehub] Workspace plugins require an id." });
|
|
112
|
-
rules = mergeRules(rules, plugin.rules);
|
|
113
|
-
hooks = mergeHooks(hooks, plugin.hooks);
|
|
114
|
-
}
|
|
115
|
-
rules = mergeRules(rules, definition.rules);
|
|
116
|
-
hooks = mergeHooks(hooks, definition.hooks);
|
|
117
|
-
return {
|
|
118
|
-
hooks,
|
|
119
|
-
rules: normalizeRules(rules)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Resolves every rule that matches the path, from the least to the most specific. A more specific rule replaces a
|
|
124
|
-
* field only when it sets that field, so `"docs/**": { maxBytes }` keeps a broader `write: false`. Validators of every
|
|
125
|
-
* matching rule run, the least specific first.
|
|
126
|
-
*/
|
|
127
|
-
function matchRule(policy, path) {
|
|
128
|
-
const normalized = normalizeWorkspacePath(path);
|
|
129
|
-
let matched;
|
|
130
|
-
for (const rule of policy.rules) {
|
|
131
|
-
const globstarDirectory = rule.pattern.endsWith("/**") ? rule.pattern.slice(0, -3) : void 0;
|
|
132
|
-
if (!minimatch(normalized, rule.pattern, { dot: true }) && normalized !== globstarDirectory) continue;
|
|
133
|
-
matched ??= {
|
|
134
|
-
origins: {},
|
|
135
|
-
rule: {
|
|
136
|
-
pattern: rule.pattern,
|
|
137
|
-
validate: []
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
matched.rule.pattern = rule.pattern;
|
|
141
|
-
matched.rule.validate = [...matched.rule.validate, ...rule.validate];
|
|
142
|
-
for (const key of cascadingRuleKeys) {
|
|
143
|
-
if (rule[key] === void 0) continue;
|
|
144
|
-
matched.origins[key] = rule.pattern;
|
|
145
|
-
Object.assign(matched.rule, { [key]: rule[key] });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return matched;
|
|
149
|
-
}
|
|
150
|
-
function writeAllowed(write, operation, exists) {
|
|
151
|
-
if (write === void 0 || write === true) return true;
|
|
152
|
-
if (write === false) return false;
|
|
153
|
-
if (write === "delete") return operation === "rm";
|
|
154
|
-
if (write === "create") return operation !== "rm" && !exists;
|
|
155
|
-
if (write === "update") return operation === "writeFile" && exists;
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
function sizeOf(content) {
|
|
159
|
-
return content === void 0 ? 0 : contentToBytes(content).byteLength;
|
|
160
|
-
}
|
|
161
|
-
/** The media type that a file write stores: the one the caller passed, else the one its path implies. */
|
|
162
|
-
function writeMediaType(input) {
|
|
163
|
-
return input.mediaType || lookup(input.path) || "application/octet-stream";
|
|
164
|
-
}
|
|
165
|
-
function assertRuleAllows(input, matched) {
|
|
166
|
-
if (!matched) return;
|
|
167
|
-
const { origins, rule } = matched;
|
|
168
|
-
const exists = Boolean(input.previous);
|
|
169
|
-
if (!writeAllowed(rule.write, input.operation, exists)) throw workspaceError(`[vitehub] Workspace rule "${origins.write}" does not allow ${input.operation} for ${input.path}.`);
|
|
170
|
-
if (rule.maxBytes !== void 0 && sizeOf(input.content) > rule.maxBytes) throw workspaceError(`[vitehub] Workspace rule "${origins.maxBytes}" limits writes to ${rule.maxBytes} bytes: ${input.path}.`);
|
|
171
|
-
if (rule.mediaType && input.operation === "writeFile") {
|
|
172
|
-
const allowed = Array.isArray(rule.mediaType) ? rule.mediaType : [rule.mediaType];
|
|
173
|
-
const mediaType = writeMediaType(input);
|
|
174
|
-
if (!allowed.includes(mediaType)) throw workspaceError(`[vitehub] Workspace rule "${origins.mediaType}" does not allow media type ${mediaType}: ${input.path}.`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/** Stores the media type that the rule checked, so the stored file cannot get another type from the Store. */
|
|
178
|
-
function withCheckedMediaType(input, matched) {
|
|
179
|
-
if (!matched?.rule.mediaType || input.operation !== "writeFile" || input.mediaType) return input;
|
|
180
|
-
return {
|
|
181
|
-
...input,
|
|
182
|
-
mediaType: writeMediaType(input)
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async function runHooks(hooks, name, input) {
|
|
186
|
-
for (const hook of toArray(hooks[name])) await hook(input);
|
|
187
|
-
}
|
|
188
|
-
async function runValidators(validators, input) {
|
|
189
|
-
let current = input;
|
|
190
|
-
for (const validate of validators) {
|
|
191
|
-
const result = await validate(current);
|
|
192
|
-
if (result === false) throw workspaceError(`[vitehub] Workspace validator rejected ${current.operation} for ${current.path}.`);
|
|
193
|
-
if (typeof result === "object" && result !== null) current = result;
|
|
194
|
-
}
|
|
195
|
-
return current;
|
|
196
|
-
}
|
|
197
|
-
function createWorkspaceWritePolicy(definition) {
|
|
198
|
-
let cached = {
|
|
199
|
-
version: workspacePluginsVersion(),
|
|
200
|
-
policy: normalizePolicy(definition)
|
|
201
|
-
};
|
|
202
|
-
const currentPolicy = () => {
|
|
203
|
-
const version = workspacePluginsVersion();
|
|
204
|
-
if (cached.version !== version) cached = {
|
|
205
|
-
version,
|
|
206
|
-
policy: normalizePolicy(definition)
|
|
207
|
-
};
|
|
208
|
-
return cached.policy;
|
|
209
|
-
};
|
|
210
|
-
return {
|
|
211
|
-
check(input) {
|
|
212
|
-
const matched = matchRule(currentPolicy(), input.path);
|
|
213
|
-
const checked = {
|
|
214
|
-
...input,
|
|
215
|
-
rule: matched?.rule
|
|
216
|
-
};
|
|
217
|
-
assertRuleAllows(checked, matched);
|
|
218
|
-
return withCheckedMediaType(checked, matched);
|
|
219
|
-
},
|
|
220
|
-
async before(input) {
|
|
221
|
-
const policy = currentPolicy();
|
|
222
|
-
const matched = matchRule(policy, input.path);
|
|
223
|
-
const rule = matched?.rule;
|
|
224
|
-
let current = {
|
|
225
|
-
...input,
|
|
226
|
-
rule
|
|
227
|
-
};
|
|
228
|
-
await runHooks(policy.hooks, "write:before", current);
|
|
229
|
-
current = {
|
|
230
|
-
...current,
|
|
231
|
-
rule
|
|
232
|
-
};
|
|
233
|
-
assertRuleAllows(current, matched);
|
|
234
|
-
if (rule?.validate.length) current = await runValidators(rule.validate, current);
|
|
235
|
-
await runHooks(policy.hooks, "write:validate", current);
|
|
236
|
-
current = {
|
|
237
|
-
...current,
|
|
238
|
-
rule
|
|
239
|
-
};
|
|
240
|
-
assertRuleAllows(current, matched);
|
|
241
|
-
return withCheckedMediaType(current, matched);
|
|
242
|
-
},
|
|
243
|
-
async after(input) {
|
|
244
|
-
await runHooks(currentPolicy().hooks, "write:after", input);
|
|
245
|
-
},
|
|
246
|
-
async error(input, error) {
|
|
247
|
-
for (const hook of toArray(currentPolicy().hooks["write:error"])) await hook({
|
|
248
|
-
...input,
|
|
249
|
-
error
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
function resolveWorkspaceAutoCommit(definition, diff) {
|
|
255
|
-
if (!diff.entries.length) return;
|
|
256
|
-
if (definition.commit === true || typeof definition.commit === "string") return {
|
|
257
|
-
message: (typeof definition.commit === "string" ? definition.commit.trim() : "") || `chore: update ${definition.name} workspace`,
|
|
258
|
-
paths: diff.entries.map((entry) => normalizeWorkspacePath(entry.path))
|
|
259
|
-
};
|
|
260
|
-
const policy = normalizePolicy(definition);
|
|
261
|
-
const paths = diff.entries.map((entry) => normalizeWorkspacePath(entry.path));
|
|
262
|
-
const rules = paths.map((path) => matchRule(policy, path)?.rule);
|
|
263
|
-
if (!rules.length || rules.some((rule) => !rule?.commit)) return;
|
|
264
|
-
return {
|
|
265
|
-
message: rules.map((rule) => rule?.commit).find((commit) => typeof commit === "string" && commit.trim().length > 0)?.trim() || `chore: update ${definition.name} workspace`,
|
|
266
|
-
paths
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/core/history.ts
|
|
8
|
+
// src/core/history.ts
|
|
271
9
|
/** The ref used when a history call omits `ref`. A Store's working tree follows this ref. */
|
|
272
10
|
const defaultWorkspaceHistoryRef = "main";
|
|
273
11
|
const historyRefPattern = /^[\w-]+(?:[./][\w-]+)*$/;
|
|
@@ -334,7 +72,61 @@ function createWorkspaceHistoryReader(history, complete) {
|
|
|
334
72
|
list: async (options) => await requireHistory().list(options),
|
|
335
73
|
refs: async () => await requireHistory().refs(),
|
|
336
74
|
open: async (id) => await requireHistory().open(id),
|
|
337
|
-
usage: async () => await requireHistory().usage()
|
|
75
|
+
usage: async () => await requireHistory().usage(),
|
|
76
|
+
diff: async (options) => await diffWorkspaceRevisions(requireHistory(), options)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** The files whose bytes or retained attributes changed from one revision to another. */
|
|
80
|
+
async function diffWorkspaceRevisions(history, options) {
|
|
81
|
+
const open = async (id) => {
|
|
82
|
+
const view = await history.open(id);
|
|
83
|
+
const files = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const entry of await view.list("", { recursive: true })) if (entry.type === "file") files.set(entry.path, entry);
|
|
85
|
+
return {
|
|
86
|
+
view,
|
|
87
|
+
files
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const [from, to] = await Promise.all([options.from === void 0 ? void 0 : open(options.from), open(options.to)]);
|
|
91
|
+
const sameBytes = async (path, before, after) => {
|
|
92
|
+
if (before.digest !== void 0 && after.digest !== void 0) return before.digest === after.digest;
|
|
93
|
+
const [left, right] = await Promise.all([from.view.readFile(path, { encoding: "binary" }), to.view.readFile(path, { encoding: "binary" })]);
|
|
94
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
95
|
+
};
|
|
96
|
+
const entries = [];
|
|
97
|
+
for (const path of [.../* @__PURE__ */ new Set([...from?.files.keys() ?? [], ...to.files.keys()])].sort()) {
|
|
98
|
+
const before = from?.files.get(path);
|
|
99
|
+
const after = to.files.get(path);
|
|
100
|
+
if (!before) entries.push({
|
|
101
|
+
path,
|
|
102
|
+
type: "added",
|
|
103
|
+
after: snapshotEntry(after)
|
|
104
|
+
});
|
|
105
|
+
else if (!after) entries.push({
|
|
106
|
+
path,
|
|
107
|
+
type: "removed",
|
|
108
|
+
before: snapshotEntry(before)
|
|
109
|
+
});
|
|
110
|
+
else if (before.mediaType !== after.mediaType || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata) || !await sameBytes(path, before, after)) entries.push({
|
|
111
|
+
path,
|
|
112
|
+
type: "modified",
|
|
113
|
+
before: snapshotEntry(before),
|
|
114
|
+
after: snapshotEntry(after)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
...options.from === void 0 ? {} : { from: options.from },
|
|
119
|
+
to: options.to,
|
|
120
|
+
entries
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function snapshotEntry({ digest, mediaType, metadata, size }) {
|
|
124
|
+
return {
|
|
125
|
+
type: "file",
|
|
126
|
+
...digest === void 0 ? {} : { digest },
|
|
127
|
+
...mediaType === void 0 ? {} : { mediaType },
|
|
128
|
+
...metadata === void 0 ? {} : { metadata },
|
|
129
|
+
...size === void 0 ? {} : { size }
|
|
338
130
|
};
|
|
339
131
|
}
|
|
340
132
|
function validateHistoryMessage(message) {
|
|
@@ -346,6 +138,21 @@ function normalizeHistoryRef(ref) {
|
|
|
346
138
|
if (typeof ref !== "string" || ref.length > 128 || !historyRefPattern.test(ref)) throw workspaceErrorDiagnostics.WORKSPACE_R0071({ message: `[vitehub] Invalid history ref${typeof ref === "string" ? ` ${JSON.stringify(ref.slice(0, 128))}` : ""}. Use up to 128 letters, numbers, underscores, and dashes, separated by single dots or slashes.` });
|
|
347
139
|
return ref;
|
|
348
140
|
}
|
|
141
|
+
/** `history.deleteRef()` of a Workspace facade. A Store without it throws `WORKSPACE_R0069`. */
|
|
142
|
+
async function deleteWorkspaceHistoryRef(history, options) {
|
|
143
|
+
if (!history?.deleteRef) throw workspaceErrorDiagnostics.WORKSPACE_R0069({ message: "[vitehub] This Workspace Store cannot delete history refs. Use the Blob + Database Store or the GitHub Store." });
|
|
144
|
+
return await history.deleteRef(options);
|
|
145
|
+
}
|
|
146
|
+
/** Check the options of `history.deleteRef()`. The default ref stays, because the working tree follows it. */
|
|
147
|
+
function readHistoryDeleteRef(options) {
|
|
148
|
+
const ref = normalizeHistoryRef(options?.ref);
|
|
149
|
+
if (ref === "main") throw workspaceErrorDiagnostics.WORKSPACE_DEFAULT_REF_DELETE();
|
|
150
|
+
if (options.ifHead !== void 0 && (typeof options.ifHead !== "string" || !options.ifHead)) throw workspaceError("[vitehub] history.deleteRef() requires ifHead to be a revision id.");
|
|
151
|
+
return options.ifHead === void 0 ? { ref } : {
|
|
152
|
+
ref,
|
|
153
|
+
ifHead: options.ifHead
|
|
154
|
+
};
|
|
155
|
+
}
|
|
349
156
|
function normalizeHistoryPath(path) {
|
|
350
157
|
return normalizeSafeWorkspacePath(path).split("/").filter(Boolean).join("/");
|
|
351
158
|
}
|
|
@@ -542,16 +349,17 @@ function createWorkspaceHistory(definition, store, files) {
|
|
|
542
349
|
});
|
|
543
350
|
} } : {},
|
|
544
351
|
...store.history?.openPullRequest ? { openPullRequest: async (options) => await store.history.openPullRequest(options) } : {},
|
|
352
|
+
...store.history?.deleteRef ? { deleteRef: async (options) => await store.history.deleteRef(readHistoryDeleteRef(options)) } : {},
|
|
545
353
|
head: async (options) => await history().head(options),
|
|
546
354
|
list: async (options) => await history().list(options),
|
|
547
355
|
refs: async () => await history().refs(),
|
|
548
356
|
open: async (id) => await history().open(id),
|
|
549
357
|
usage: async () => await history().usage(),
|
|
358
|
+
diff: async (options) => await diffWorkspaceRevisions(history(), options),
|
|
550
359
|
commit
|
|
551
360
|
};
|
|
552
361
|
}
|
|
553
|
-
|
|
554
|
-
//#region src/storage/utils.ts
|
|
362
|
+
// src/storage/utils.ts
|
|
555
363
|
const snapshotStatConcurrency = 16;
|
|
556
364
|
async function mapWithConcurrency(values, concurrency, visit) {
|
|
557
365
|
const results = [];
|
|
@@ -618,5 +426,4 @@ function diffSnapshots(from, to) {
|
|
|
618
426
|
entries
|
|
619
427
|
};
|
|
620
428
|
}
|
|
621
|
-
|
|
622
|
-
export { registerWorkspacePlugin as _, createWorkspaceHistoryReader as a, forwardWorkspaceHistoryMerge as c, normalizeHistoryRef as d, rejectHistoryHead as f, resolveWorkspaceAutoCommit as g, createWorkspaceWritePolicy as h, createWorkspaceHistory as i, historyConflict as l, validateHistoryMessage as m, createSnapshotFromEntries as n, defaultWorkspaceHistoryRef as o, requireWorkspaceHistory as p, diffSnapshots as r, forwardWorkspaceHistoryFiles as s, createCurrentSnapshotFromStore as t, normalizeHistoryPath as u, workspaceDefinitionPlugins as v };
|
|
429
|
+
export { createWorkspaceHistoryReader as a, forwardWorkspaceHistoryFiles as c, normalizeHistoryPath as d, normalizeHistoryRef as f, validateHistoryMessage as g, requireWorkspaceHistory as h, createWorkspaceHistory as i, forwardWorkspaceHistoryMerge as l, rejectHistoryHead as m, createSnapshotFromEntries as n, defaultWorkspaceHistoryRef as o, readHistoryDeleteRef as p, diffSnapshots as r, deleteWorkspaceHistoryRef as s, createCurrentSnapshotFromStore as t, historyConflict as u };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
3
|
-
import { Plugin } from "vite";
|
|
4
|
-
|
|
1
|
+
import { At as WorkspaceOptions } from "./types-Bel5IDmF.js";
|
|
2
|
+
import { n as OperationContributionEntry } from "./operation-definition-CqZkx1Rm.js";
|
|
3
|
+
import { EnvironmentOptions, Plugin } from "vite";
|
|
4
|
+
type NitroPackageLoadingOptions = {
|
|
5
|
+
devServer?: {
|
|
6
|
+
runner?: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Use one app's effective Nitro runner for both environment configuration and generated imports.
|
|
11
|
+
* `configureEnvironment` reads the runner after Nitro's `build:before` hooks and saves the decision for `load`.
|
|
12
|
+
*/
|
|
13
|
+
declare function createNativePackageLoading(ssrPackageEntries?: readonly string[]): {
|
|
14
|
+
nitro: {
|
|
15
|
+
setup(instance: {
|
|
16
|
+
options: NitroPackageLoadingOptions;
|
|
17
|
+
}): void;
|
|
18
|
+
};
|
|
19
|
+
configureEnvironment(name: string, env: {
|
|
20
|
+
command: string;
|
|
21
|
+
isSsrTargetWebworker?: boolean;
|
|
22
|
+
}, options?: EnvironmentOptions): boolean;
|
|
23
|
+
load(id: string, environmentName: string | undefined): string | undefined;
|
|
24
|
+
};
|
|
5
25
|
/**
|
|
6
26
|
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
7
27
|
* imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
|
|
@@ -24,8 +44,6 @@ interface DurabilityPluginMetadata {
|
|
|
24
44
|
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
25
45
|
durability?: () => readonly DurabilityContribution[];
|
|
26
46
|
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region ../internal/src/inspect.d.ts
|
|
29
47
|
interface ViteHubDefinitionField {
|
|
30
48
|
label: string;
|
|
31
49
|
value: string;
|
|
@@ -75,6 +93,8 @@ interface ViteHubResourceSummary {
|
|
|
75
93
|
owner: string;
|
|
76
94
|
/** Absent when no id is known yet. */
|
|
77
95
|
source?: ViteHubResourceIdSource;
|
|
96
|
+
/** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
|
|
97
|
+
standalone?: boolean;
|
|
78
98
|
}
|
|
79
99
|
interface ViteHubInspectionContributor {
|
|
80
100
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
@@ -85,8 +105,6 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
|
|
|
85
105
|
interface ViteHubInspectionPluginMetadata {
|
|
86
106
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
87
107
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/hosts/vite/plugin.d.ts
|
|
90
108
|
interface WorkspaceNitroConfigOptions {
|
|
91
109
|
aliases?: Record<string, string>;
|
|
92
110
|
command?: "build" | "serve";
|
|
@@ -129,12 +147,12 @@ interface WorkspaceCliContributingPlugin {
|
|
|
129
147
|
declare const setWorkspacePluginHosting: unique symbol;
|
|
130
148
|
type WorkspacePluginHosting = string | (() => string | undefined);
|
|
131
149
|
type WorkspaceVitePlugin = Plugin & WorkspaceCliContributingPlugin & {
|
|
150
|
+
/** Nitro module that reads the app's dev runner. Typed here because a program without Nitro's Vite types has no `nitro` on `Plugin`. */
|
|
151
|
+
nitro?: ReturnType<typeof createNativePackageLoading>["nitro"];
|
|
132
152
|
[setWorkspacePluginHosting]?: (hosting: WorkspacePluginHosting) => void;
|
|
133
153
|
api: WorkspaceVitePluginAPI;
|
|
134
154
|
};
|
|
135
155
|
export declare function hubWorkspace(options?: WorkspaceOptions | false): WorkspaceVitePlugin;
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region ../internal/src/contributions.d.ts
|
|
138
156
|
/** Module and export that hold a contributed Definition. */
|
|
139
157
|
interface ContributionDefinition {
|
|
140
158
|
/**
|
|
@@ -164,6 +182,8 @@ interface ContributionContext {
|
|
|
164
182
|
projectRoot: string;
|
|
165
183
|
/** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
|
|
166
184
|
serverDirs?: readonly string[];
|
|
185
|
+
/** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
|
|
186
|
+
plugins?: readonly unknown[];
|
|
167
187
|
}
|
|
168
188
|
/**
|
|
169
189
|
* Returns the contributions of a plugin. It runs once per discovery pass, so it must be idempotent and must not depend
|
|
@@ -187,8 +207,6 @@ interface CollectedContribution {
|
|
|
187
207
|
/** Name of the contributing Vite plugin. */
|
|
188
208
|
plugin: string;
|
|
189
209
|
}
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/build/contributions.d.ts
|
|
192
210
|
/**
|
|
193
211
|
* A Workspace Definition that another package registers from its Vite plugin. The Workspace plugin adds it to the
|
|
194
212
|
* generated registry next to the discovered files, so `useWorkspace(name)`, typegen, inspection, and the Console
|
|
@@ -213,8 +231,6 @@ type CollectedWorkspaceContribution = CollectedContribution;
|
|
|
213
231
|
* contributions with one name fail with `WORKSPACE_B0003`.
|
|
214
232
|
*/
|
|
215
233
|
export declare function collectWorkspaceContributions(plugins: readonly unknown[] | undefined, context: WorkspaceContributionContext): Promise<CollectedWorkspaceContribution[]>;
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/build/discovery.d.ts
|
|
218
234
|
interface DiscoveredWorkspaceDefinition {
|
|
219
235
|
/** Plugin that contributed the definition. Only set for contributed definitions. */
|
|
220
236
|
contributor?: string;
|
|
@@ -236,8 +252,6 @@ interface ViteWorkspaceDiscoveryOptions {
|
|
|
236
252
|
serverRootDir?: string;
|
|
237
253
|
}
|
|
238
254
|
export declare function discoverViteWorkspaceDefinitions(rootDir: string, options?: ViteWorkspaceDiscoveryOptions): DiscoveredWorkspaceDefinition[];
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region ../internal/src/console.d.ts
|
|
241
255
|
type MaybePromise<T> = T | Promise<T>;
|
|
242
256
|
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
243
257
|
interface ViteHubConsoleDefinitionCatalogView {
|
|
@@ -569,8 +583,6 @@ interface ViteHubConsoleDocumentSetup {
|
|
|
569
583
|
*/
|
|
570
584
|
schedule?: ViteHubConsoleDocumentHint;
|
|
571
585
|
}
|
|
572
|
-
//#endregion
|
|
573
|
-
//#region src/inspect.d.ts
|
|
574
586
|
interface WorkspaceInspectionOptions {
|
|
575
587
|
/** Vite plugins that can contribute Workspace Definitions through `vitehub.workspaces`. */
|
|
576
588
|
plugins?: readonly unknown[];
|
|
@@ -583,5 +595,4 @@ interface WorkspaceInspectionOptions {
|
|
|
583
595
|
export declare function inspectWorkspaceDefinitions(options: WorkspaceInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
|
|
584
596
|
/** Console section that lists discovered Workspace Definitions. `vitehub inspect definitions` reads the same data. */
|
|
585
597
|
export declare const workspaceConsoleSection: ViteHubConsoleSectionContribution<WorkspaceInspectionOptions>;
|
|
586
|
-
//#endregion
|
|
587
598
|
export type { CollectedWorkspaceContribution, DiscoveredWorkspaceDefinition, NitroConfig, ViteWorkspaceDiscoveryOptions, WorkspaceContributingPlugin, WorkspaceContribution, WorkspaceContributionContext, WorkspaceContributionFactory, WorkspaceInspectionOptions, WorkspaceNitroConfigOptions, WorkspaceVitePlugin, WorkspaceVitePluginAPI };
|