@vite-hub/workspace 0.4.1 → 0.5.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 +62 -19
- package/dist/blob-database/postgres.d.ts +424 -0
- package/dist/blob-database/postgres.js +2 -0
- package/dist/blob-database-sources-DDZ1wV9w.js +9 -0
- package/dist/blob-database.d.ts +33 -447
- package/dist/blob-database.js +637 -208
- package/dist/checkout.js +1 -1
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/{config-D1QENneP.js → config-DiyPi3Ff.js} +7 -7
- package/dist/{config-CDeGd0RB.d.ts → config-hxABr_Gg.d.ts} +1 -1
- package/dist/durability.d.ts +11 -2
- package/dist/durability.js +46 -4
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-C0KyI408.js} +5 -1
- package/dist/{error-diagnostics-B5s9kNEA.js → error-diagnostics-Cth97txN.js} +10 -2
- package/dist/{path-uxLkzrZm.d.ts → errors-DXCZjdUU.d.ts} +0 -1
- package/dist/{file-CqG9zqiF.js → file-C1DYoGz3.js} +1 -1
- package/dist/{target-Dm9dHAVJ.js → file-metadata-Dv2JZwal.js} +1 -29
- package/dist/{files-B6wpAhEx.js → files-iHyik8jj.js} +2 -2
- package/dist/files.d.ts +13 -5
- package/dist/files.js +6 -5
- package/dist/{github-DKAlO0Vh.js → github-CFHl6RI0.js} +4 -4
- package/dist/{glob-BOqSKzSg.js → glob-BitxqDhb.js} +7 -7
- package/dist/{glob-Cjxms1t7.js → glob-Buxfvmyy.js} +1 -1
- package/dist/history-schema-BBWbpDk4.d.ts +436 -0
- package/dist/history-schema-postgres-U_ueRvmO.js +41 -0
- package/dist/{host-Bf1a2uo_.js → host-Dmr2Ctem.js} +150 -16
- package/dist/{hosted-zG7HJaE4.js → hosted-BktlvkF2.js} +20 -11
- package/dist/{hosted-vercel-blob-AbXG8fvR.js → hosted-vercel-blob-D0IPAjb1.js} +5 -5
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +11 -23
- package/dist/index.js +28 -106
- package/dist/internal/workspace.d.ts +14 -0
- package/dist/internal/workspace.js +86 -0
- package/dist/{lifecycle-D8FdpBod.js → lifecycle-D6WN2dd_.js} +11 -8
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-DntxtmDU.js → mcp-resources-TtxLNSL6.js} +1 -1
- package/dist/{memory-D5jq9HZW.js → memory-DjzwSng2.js} +16 -8
- package/dist/{metadata-target-DDoOQNp1.js → metadata-target-CR0aDtvS.js} +205 -60
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/{operations-D8uCpzhM.js → operations-Cib30_dt.js} +5 -5
- package/dist/{operations-DsY2MQnG.js → operations-dtcU5LkD.js} +22 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +1 -1
- package/dist/{path--wrT_Azm.js → path-BlIBpI7U.js} +1 -16
- package/dist/{plugins-CsrXCA1Q.d.ts → plugins-DKCBrH31.d.ts} +1 -1
- package/dist/{provider-sm9uzkLg.js → provider-Fc3M6bEx.js} +23 -10
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-CwryP59t.d.ts → registry-CLL0TY0L.d.ts} +5 -3
- package/dist/{registry-DmVfUe4K.js → registry-CedQvQxW.js} +8 -3
- package/dist/{registry-CFl1Htyc.d.ts → registry-DpB5PBA4.d.ts} +5 -4
- package/dist/{request-scope-Dw5n8bMC.js → request-scope-Bcv2kD8h.js} +2 -1
- package/dist/rule-keys-Bsz6jTTF.js +19 -0
- package/dist/rules-OHaPFopX.js +269 -0
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +3 -3
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +2 -2
- package/dist/runtime/request.js +1 -1
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +18 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +9 -8
- package/dist/runtime.js +23 -16
- package/dist/{search-C_RfoM2j.js → search-BqNV9LnO.js} +1 -1
- package/dist/{server-Cd4-iCh5.js → server-CFtrOPk6.js} +5 -5
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/dist/{shared-ovXVSV3-.js → shared-BgDjxY3J.js} +14 -3
- package/dist/source-metadata.d.ts +2 -2
- package/dist/source-metadata.js +3 -3
- package/dist/{state-C-YtsaiJ.d.ts → state-DBV6VHS6.d.ts} +13 -21
- package/dist/{store-NZoRto-Y.js → store-BRMdD8Ft.js} +37 -36
- package/dist/{sync-CrT8zjwc.js → sync-BezGVzrW.js} +4 -4
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-1Z-tKK3g.d.ts → types-9DMtFjaa.d.ts} +52 -4
- package/dist/{use-B0o5HoBl.js → use-Dm2tbI5F.js} +15 -15
- package/dist/{use-CjbF8EO9.d.ts → use-Dv973swc.d.ts} +20 -28
- package/dist/{state-Cb_hIyAw.js → use-tools-C1qvhzme.js} +4 -17
- package/dist/use-tools-CMUthOdy.d.ts +12 -0
- package/dist/{utils-Dw-WULEZ.js → utils-C0Au2R16.js} +77 -268
- package/dist/vite.d.ts +32 -3
- package/dist/vite.js +990 -1286
- package/dist/vitehub-grants-C8IAl5-M.js +38 -0
- package/dist/{workspace-DvKu5PRa.js → workspace-CFrwWhEm.js} +18 -17
- package/dist/{workspace-CIXgHeyX.d.ts → workspace-Cw4ycIW-.d.ts} +1 -1
- package/package.json +22 -12
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { g as getWorkspaceSourceRequestExecution
|
|
4
|
-
import { i as
|
|
5
|
-
import { t as setWorkspaceAssetsRegistry } from "./asset-registry-DfBV5kmw.js";
|
|
6
|
-
import { a as copyWorkspacePath, i as appendWorkspaceFile, n as createWorkspaceFileRuntime, t as createReadonlyFs } from "./use-B0o5HoBl.js";
|
|
2
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-Cth97txN.js";
|
|
3
|
+
import { g as getWorkspaceSourceRequestExecution } from "./workspace-CFrwWhEm.js";
|
|
4
|
+
import { a as copyWorkspacePath, i as appendWorkspaceFile, n as createWorkspaceFileRuntime, t as createReadonlyFs } from "./use-Dm2tbI5F.js";
|
|
7
5
|
import { executionBudgetCharged, executionBudgetOverride, markExecutionBudgetHandled } from "@vite-hub/runtime/internal/execution-budget";
|
|
8
6
|
//#region src/runtime/dependency-loaders.ts
|
|
9
7
|
const shellWorkspaceSpecifier = "@vite-hub/shell/workspace";
|
|
@@ -592,15 +590,4 @@ function useWorkspace(name, options) {
|
|
|
592
590
|
return Object.assign(runtime.facade, { tools });
|
|
593
591
|
}
|
|
594
592
|
//#endregion
|
|
595
|
-
|
|
596
|
-
async function invalidateWorkspaceStore(name) {
|
|
597
|
-
invalidateCachedWorkspaceStore(await resolveRegisteredWorkspaceDefinition(name));
|
|
598
|
-
}
|
|
599
|
-
function setWorkspaceRuntimeRegistry(registry) {
|
|
600
|
-
setWorkspaceRegistry(registry);
|
|
601
|
-
}
|
|
602
|
-
function setWorkspaceRuntimeAssetsRegistry(registry) {
|
|
603
|
-
setWorkspaceAssetsRegistry(registry);
|
|
604
|
-
}
|
|
605
|
-
//#endregion
|
|
606
|
-
export { createWorkspaceTools as a, useWorkspace as i, setWorkspaceRuntimeAssetsRegistry as n, getWorkspaceDependencyRuntimeLoaders as o, setWorkspaceRuntimeRegistry as r, setWorkspaceDependencyRuntimeLoaders as s, invalidateWorkspaceStore as t };
|
|
593
|
+
export { setWorkspaceDependencyRuntimeLoaders as i, createWorkspaceTools as n, getWorkspaceDependencyRuntimeLoaders as r, useWorkspace as t };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { gt as WorkspaceLookupName } from "./types-9DMtFjaa.js";
|
|
2
|
+
import { h as WritableWorkspaceFacade, i as ReadonlyWorkspaceFacade, s as UseWorkspaceOptions } from "./use-Dv973swc.js";
|
|
3
|
+
//#region src/core/use-tools.d.ts
|
|
4
|
+
declare function useWorkspace<Name extends WorkspaceLookupName>(name: Name): ReadonlyWorkspaceFacade<Name>;
|
|
5
|
+
declare function useWorkspace<Name extends WorkspaceLookupName>(name: Name, options: UseWorkspaceOptions & {
|
|
6
|
+
mode?: "read";
|
|
7
|
+
}): ReadonlyWorkspaceFacade<Name>;
|
|
8
|
+
declare function useWorkspace<Name extends WorkspaceLookupName>(name: Name, options: UseWorkspaceOptions & {
|
|
9
|
+
mode: "write";
|
|
10
|
+
}): WritableWorkspaceFacade<Name>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useWorkspace as t };
|
|
@@ -1,272 +1,10 @@
|
|
|
1
1
|
import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { n as copyJsonWorkspaceMetadata, t as copyJsonFileMetadata } from "./file-metadata-Dv2JZwal.js";
|
|
3
|
+
import { d as sha256, o as isWorkspaceBytes, r as contentToBytes } from "./path-BlIBpI7U.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-Cth97txN.js";
|
|
5
|
+
import { t as createWorkspaceWritePolicy } from "./rules-OHaPFopX.js";
|
|
5
6
|
import { lookup } from "mrmime";
|
|
6
7
|
import { isRuntimeObject } from "@vite-hub/runtime/internal/runtime-type";
|
|
7
|
-
import { minimatch } from "minimatch";
|
|
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
8
|
//#region 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";
|
|
@@ -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,11 +349,13 @@ 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
|
}
|
|
@@ -619,4 +428,4 @@ function diffSnapshots(from, to) {
|
|
|
619
428
|
};
|
|
620
429
|
}
|
|
621
430
|
//#endregion
|
|
622
|
-
export {
|
|
431
|
+
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,6 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
3
|
-
import { Plugin } from "vite";
|
|
1
|
+
import { At as WorkspaceOptions } from "./types-9DMtFjaa.js";
|
|
2
|
+
import { n as OperationContributionEntry } from "./operation-definition-CI2PJGqu.js";
|
|
3
|
+
import { EnvironmentOptions, Plugin } from "vite";
|
|
4
|
+
//#region ../internal/src/build/vite.d.ts
|
|
5
|
+
type NitroPackageLoadingOptions = {
|
|
6
|
+
devServer?: {
|
|
7
|
+
runner?: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Use one app's effective Nitro runner for both environment configuration and generated imports.
|
|
12
|
+
* `configureEnvironment` reads the runner after Nitro's `build:before` hooks and saves the decision for `load`.
|
|
13
|
+
*/
|
|
14
|
+
declare function createNativePackageLoading(ssrPackageEntries?: readonly string[]): {
|
|
15
|
+
nitro: {
|
|
16
|
+
setup(instance: {
|
|
17
|
+
options: NitroPackageLoadingOptions;
|
|
18
|
+
}): void;
|
|
19
|
+
};
|
|
20
|
+
configureEnvironment(name: string, env: {
|
|
21
|
+
command: string;
|
|
22
|
+
isSsrTargetWebworker?: boolean;
|
|
23
|
+
}, options?: EnvironmentOptions): boolean;
|
|
24
|
+
load(id: string, environmentName: string | undefined): string | undefined;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
4
27
|
//#region ../internal/src/durability.d.ts
|
|
5
28
|
/**
|
|
6
29
|
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
@@ -75,6 +98,8 @@ interface ViteHubResourceSummary {
|
|
|
75
98
|
owner: string;
|
|
76
99
|
/** Absent when no id is known yet. */
|
|
77
100
|
source?: ViteHubResourceIdSource;
|
|
101
|
+
/** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
|
|
102
|
+
standalone?: boolean;
|
|
78
103
|
}
|
|
79
104
|
interface ViteHubInspectionContributor {
|
|
80
105
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
@@ -129,6 +154,8 @@ interface WorkspaceCliContributingPlugin {
|
|
|
129
154
|
declare const setWorkspacePluginHosting: unique symbol;
|
|
130
155
|
type WorkspacePluginHosting = string | (() => string | undefined);
|
|
131
156
|
type WorkspaceVitePlugin = Plugin & WorkspaceCliContributingPlugin & {
|
|
157
|
+
/** Nitro module that reads the app's dev runner. Typed here because a program without Nitro's Vite types has no `nitro` on `Plugin`. */
|
|
158
|
+
nitro?: ReturnType<typeof createNativePackageLoading>["nitro"];
|
|
132
159
|
[setWorkspacePluginHosting]?: (hosting: WorkspacePluginHosting) => void;
|
|
133
160
|
api: WorkspaceVitePluginAPI;
|
|
134
161
|
};
|
|
@@ -164,6 +191,8 @@ interface ContributionContext {
|
|
|
164
191
|
projectRoot: string;
|
|
165
192
|
/** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
|
|
166
193
|
serverDirs?: readonly string[];
|
|
194
|
+
/** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
|
|
195
|
+
plugins?: readonly unknown[];
|
|
167
196
|
}
|
|
168
197
|
/**
|
|
169
198
|
* Returns the contributions of a plugin. It runs once per discovery pass, so it must be idempotent and must not depend
|