@vite-hub/workspace 0.6.1 → 0.8.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 +6 -6
- package/dist/{asset-registry-0CdRAjIV.js → asset-registry-DJyE42kr.js} +1 -1
- package/dist/blob-database.d.ts +1 -1
- package/dist/blob-database.js +6 -6
- package/dist/checkout.js +2 -2
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/{config-jo5QgE1w.js → config-Bze7OyvB.js} +15 -10
- package/dist/{config-DeA287c0.d.ts → config-DF6sqKXB.d.ts} +1 -1
- package/dist/durability.d.ts +1 -1
- package/dist/durability.js +2 -2
- package/dist/{error-diagnostics-B4me-ouV.js → error-diagnostics-CHgE8TQM.js} +16 -0
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{file-BrNAXQgY.js → file-DIBPXqbk.js} +1 -1
- package/dist/{file-metadata-Bpsvjw_X.js → file-metadata-Dqpldj0h.js} +7 -2
- package/dist/{files--z2dLC5z.js → files-DAJyo7TU.js} +2 -2
- package/dist/files.d.ts +5 -5
- package/dist/files.js +5 -5
- package/dist/{github-k--_LCrX.js → github-DcrnEGNN.js} +4 -4
- package/dist/{glob-BreFjNAV.js → glob-BIg9O4yY.js} +2 -2
- package/dist/{glob-BEutagp1.js → glob-YVshR7WP.js} +1 -1
- package/dist/{host-C8yZizfk.js → host-BT7EnmZf.js} +7 -7
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +464 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +917 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +13 -13
- package/dist/internal/path.js +108 -1
- package/dist/internal/workspace.d.ts +2 -3
- package/dist/internal/workspace.js +2 -2
- package/dist/{lifecycle-IReZfi0b.js → lifecycle-B0ucHUum.js} +8 -8
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-DeJnbOaw.js → mcp-resources-BDL0llKW.js} +2 -2
- package/dist/{memory-BlSRrBH1.js → memory-BCZl_ZsJ.js} +26 -4
- package/dist/{metadata-target-CaGLY4ay.js → metadata-target-mlHAv1p4.js} +59 -24
- package/dist/{object-CAK6UYR5.js → object-DNOrQSl5.js} +5 -1
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BALFFdKj.d.ts} +1 -0
- package/dist/{operations-BIaK_uYG.js → operations-D3mZArDi.js} +8 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +1341 -2
- package/dist/{path-Bb9OIc_F.js → path-DYHw5KNk.js} +11 -3
- package/dist/plugins-BYxsPDBH.d.ts +12 -0
- package/dist/{provider-CN14ewvx.js → provider-DZY1cLP5.js} +281 -87
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1994 -1
- package/dist/{registry-BbUg9vJB.js → registry-OonxXCbd.js} +3 -3
- package/dist/{registry-B0g19sdy.d.ts → registry-h1-cT-cE.d.ts} +1 -1
- package/dist/{registry-s2Ob9PeX.d.ts → registry-hnARUKNF.d.ts} +2 -2
- package/dist/replacement-CVZVsflC.js +76 -0
- package/dist/{request-scope-CXCI_wCb.js → request-scope-jH4H0Sbm.js} +3 -1
- package/dist/{rule-keys-BLEbi1h5.js → rule-keys-xMpiTLq1.js} +1 -1
- package/dist/{rules-BPDXypZV.js → rules-DYQCKYdt.js} +4 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -4
- 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 +1 -1
- package/dist/runtime/request.js +1 -1
- package/dist/runtime/state.d.ts +17 -6
- package/dist/runtime/state.js +7 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +39 -24
- package/dist/{search-C_nVorq7.js → search-CG6UNOtn.js} +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +301 -1
- package/dist/{shared-C20Wh1mp.js → shared-DCAyMX8U.js} +68 -21
- package/dist/source-metadata.d.ts +2 -2
- package/dist/source-metadata.js +3 -3
- package/dist/{sync-BBfR4g5y.js → sync-DkpTCr9u.js} +5 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-Bel5IDmF.d.ts → types-BnSUug2v.d.ts} +13 -1
- package/dist/{use-CpphIBof.d.ts → use-CJ5rdIrW.d.ts} +1 -1
- package/dist/{use-D0DyTMxM.js → use-hLouCwGz.js} +15 -51
- package/dist/{use-tools-CAK10LTc.d.ts → use-tools-DFVqZwgc.d.ts} +2 -2
- package/dist/{use-tools-CHduR5k6.js → use-tools-NXEQt099.js} +4 -4
- package/dist/{utils-DXP9xfXo.js → utils-Bv1NBg8r.js} +5 -5
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +517 -121
- package/dist/{workspace-BOuxrZrP.d.ts → workspace-B6QreLJd.d.ts} +1 -1
- package/dist/{workspace-CLuPkyZR.js → workspace-Cz-5Ne1c.js} +340 -104
- package/dist/workspace-inspection-scanner-BlJ8bCAB.js +140 -0
- package/package.json +12 -12
- package/dist/errors-CnFDXxeJ.d.ts +0 -4
- package/dist/hosted-8BTKAtMX.js +0 -883
- package/dist/hosted-vercel-blob-B6kygYqn.js +0 -408
- package/dist/operations-DS1C4uXd.js +0 -1308
- package/dist/path-CuYE8-X6.js +0 -57
- package/dist/plugins-CLc32jvL.d.ts +0 -8
- package/dist/server-aa1a4rkV.js +0 -301
- package/dist/state-BdDfBtOR.d.ts +0 -17
- package/dist/store-cx3OqNTi.js +0 -1971
package/dist/path-CuYE8-X6.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
2
|
-
// src/core/errors.ts
|
|
3
|
-
function workspaceError(message, options) {
|
|
4
|
-
const code = message.startsWith("[vitehub] Workspace file does not exist:") || message.startsWith("[vitehub] Workspace path does not exist:") || message.startsWith("[vitehub] Custom Workspace Source file does not exist:") ? "WORKSPACE_NOT_FOUND" : "WORKSPACE_FAILED";
|
|
5
|
-
return new ViteHubError(code, message, options);
|
|
6
|
-
}
|
|
7
|
-
function workspaceConflict(message, options) {
|
|
8
|
-
return new ViteHubError("WORKSPACE_CONFLICT", message, options);
|
|
9
|
-
}
|
|
10
|
-
function workspaceConflictError(path, expected, actual) {
|
|
11
|
-
return workspaceConflict(`[vitehub] Workspace path changed before the conditional write: ${path}.`, { details: {
|
|
12
|
-
actual,
|
|
13
|
-
expected,
|
|
14
|
-
path
|
|
15
|
-
} });
|
|
16
|
-
}
|
|
17
|
-
function assertWorkspaceDigest(path, expected, actual) {
|
|
18
|
-
if (expected === null ? actual !== void 0 : actual !== expected) throw workspaceConflictError(path, expected, actual);
|
|
19
|
-
}
|
|
20
|
-
function workspaceNotFoundError(name) {
|
|
21
|
-
return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
|
|
22
|
-
}
|
|
23
|
-
function workspacePathError(path) {
|
|
24
|
-
const publicPath = path.slice(0, 4096);
|
|
25
|
-
return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
26
|
-
}
|
|
27
|
-
function isWorkspaceError(value) {
|
|
28
|
-
const code = getViteHubErrorShape(value)?.code;
|
|
29
|
-
return code === "WORKSPACE_CONFLICT" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
|
|
30
|
-
}
|
|
31
|
-
function isWorkspaceConflict(value) {
|
|
32
|
-
return getViteHubErrorShape(value)?.code === "WORKSPACE_CONFLICT";
|
|
33
|
-
}
|
|
34
|
-
// src/internal/path.ts
|
|
35
|
-
function classifyWindowsComponent(part) {
|
|
36
|
-
const withoutStream = part.toLowerCase().split(":", 1)[0];
|
|
37
|
-
return {
|
|
38
|
-
normalized: withoutStream.replace(/[ .]+$/, ""),
|
|
39
|
-
isTraversal: /^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(withoutStream)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function normalizeSafeWorkspacePath(path = "", options = {}) {
|
|
43
|
-
const raw = path.replace(/\\/g, "/");
|
|
44
|
-
const normalized = raw.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
45
|
-
const parts = normalized.split("/").filter(Boolean);
|
|
46
|
-
if (!options.allowEmpty && !normalized) throw workspacePathError(path);
|
|
47
|
-
if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0")) throw workspacePathError(path);
|
|
48
|
-
if (parts.some((part, index) => {
|
|
49
|
-
const name = part.toLowerCase();
|
|
50
|
-
const classification = classifyWindowsComponent(part);
|
|
51
|
-
const reserved = classification.normalized === ".git" || /^git~\d+$/.test(classification.normalized) || index === 0 && classification.normalized === ".vitehub" || index === 0 && /^vitehu~\d+$/.test(classification.normalized);
|
|
52
|
-
const canonical = (classification.normalized === ".git" || index === 0 && classification.normalized === ".vitehub") && name === classification.normalized;
|
|
53
|
-
return classification.isTraversal || reserved && (!options.allowReserved || !canonical);
|
|
54
|
-
})) throw workspacePathError(path);
|
|
55
|
-
return normalized;
|
|
56
|
-
}
|
|
57
|
-
export { workspaceConflict as a, workspaceNotFoundError as c, isWorkspaceError as i, workspacePathError as l, assertWorkspaceDigest as n, workspaceConflictError as o, isWorkspaceConflict as r, workspaceError as s, normalizeSafeWorkspacePath as t };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { jt as WorkspacePlugin } from "./types-Bel5IDmF.js";
|
|
2
|
-
/**
|
|
3
|
-
* Add a plugin's rules and hooks to a Workspace by name, including discovered Workspaces the caller does not define.
|
|
4
|
-
* Registering the same plugin id again replaces the earlier registration. A plugin declared by the Workspace Definition
|
|
5
|
-
* with the same id wins. The returned function removes this registration.
|
|
6
|
-
*/
|
|
7
|
-
declare function registerWorkspacePlugin(workspace: string, plugin: WorkspacePlugin): () => void;
|
|
8
|
-
export { registerWorkspacePlugin as t };
|
package/dist/server-aa1a4rkV.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { t as normalizeSafeWorkspacePath } from "./path-CuYE8-X6.js";
|
|
2
|
-
import { s as matchesAny } from "./path-Bb9OIc_F.js";
|
|
3
|
-
import { i as workspaceDefinitionPlugins, n as resolveWorkspaceAutoCommit } from "./rules-BPDXypZV.js";
|
|
4
|
-
import { r as useWorkspaceFiles } from "./use-D0DyTMxM.js";
|
|
5
|
-
import { r as withWorkspaceProgress } from "./host-C8yZizfk.js";
|
|
6
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-B4me-ouV.js";
|
|
7
|
-
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
8
|
-
import { lookup } from "mrmime";
|
|
9
|
-
// ../internal/src/secret.ts
|
|
10
|
-
const secretEncoder = new TextEncoder();
|
|
11
|
-
/**
|
|
12
|
-
* Compares a request value with an expected secret in constant time for the length of `expected`. Returns `false`
|
|
13
|
-
* when either value is missing or empty. It uses no Node API, so it also runs in Worker runtimes.
|
|
14
|
-
*/
|
|
15
|
-
function isViteHubSecretEqual(actual, expected) {
|
|
16
|
-
if (!actual || !expected) return false;
|
|
17
|
-
const left = secretEncoder.encode(actual);
|
|
18
|
-
const right = secretEncoder.encode(expected);
|
|
19
|
-
let difference = left.length ^ right.length;
|
|
20
|
-
for (let index = 0; index < right.length; index += 1) difference |= (left[index] ?? 0) ^ right[index];
|
|
21
|
-
return difference === 0;
|
|
22
|
-
}
|
|
23
|
-
Object.freeze({ prefix: "sha256=" });
|
|
24
|
-
// src/server.ts
|
|
25
|
-
const workspaceDevRoute = "/__vitehub/workspace/dev";
|
|
26
|
-
const workspaceDevHeader = "x-vitehub-workspace-dev";
|
|
27
|
-
const workspaceDevHeaderValue = "1";
|
|
28
|
-
const workspaceDevTokenHeader = "x-vitehub-dev-token";
|
|
29
|
-
function hasWorkspaceCommitRules(definition) {
|
|
30
|
-
return [...Object.values(definition.rules || {}), ...workspaceDefinitionPlugins(definition).flatMap((plugin) => Object.values(plugin.rules || {}))].some((rule) => rule.commit !== void 0);
|
|
31
|
-
}
|
|
32
|
-
const workspaceDevTokensKey = Symbol.for("vitehub.workspace.devTokens");
|
|
33
|
-
function workspaceDevTokens() {
|
|
34
|
-
const scope = globalThis;
|
|
35
|
-
scope[workspaceDevTokensKey] ??= /* @__PURE__ */ new Map();
|
|
36
|
-
return scope[workspaceDevTokensKey];
|
|
37
|
-
}
|
|
38
|
-
function workspaceDevTokenServerId(port) {
|
|
39
|
-
return `${process.pid}:${port ?? "unknown"}`;
|
|
40
|
-
}
|
|
41
|
-
async function workspaceDevTokenRoot(rootDir, options = {}) {
|
|
42
|
-
const [{ createHash }, { tmpdir }, { join, resolve }] = await Promise.all([
|
|
43
|
-
import("node:crypto"),
|
|
44
|
-
import("node:os"),
|
|
45
|
-
import("node:path")
|
|
46
|
-
]);
|
|
47
|
-
const resolvedRoot = resolve(rootDir);
|
|
48
|
-
const rootKey = createHash("sha256").update(resolvedRoot).digest("hex");
|
|
49
|
-
const serverKey = createHash("sha256").update(options.serverId || "default").digest("hex");
|
|
50
|
-
return {
|
|
51
|
-
file: join(tmpdir(), "vitehub-workspace-dev", rootKey, serverKey, "dev-token"),
|
|
52
|
-
key: `${rootKey}:${serverKey}`
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function headerValue(headers, name, expectedToken) {
|
|
56
|
-
try {
|
|
57
|
-
const prototype = Object.getPrototypeOf(headers);
|
|
58
|
-
const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
|
|
59
|
-
const constructorSource = typeof constructor === "function" ? Function.prototype.toString.call(constructor) : "";
|
|
60
|
-
const prototypeGet = prototype ? Object.getOwnPropertyDescriptor(prototype, "get")?.value : void 0;
|
|
61
|
-
const realmHeaders = typeof Headers === "function" ? Headers : void 0;
|
|
62
|
-
if (typeof constructor === "function" && Reflect.get(constructor, "name") === "Headers" && (constructor === realmHeaders || /^class\s+Headers\b/.test(constructorSource) && constructorSource.includes("#") || /^function\s+Headers\(\)\s*\{\s*\[native code\]\s*\}$/.test(constructorSource) || constructorSource.includes("webidl.brandCheck") || constructorSource.includes("#")) && Reflect.get(constructor, "prototype") === prototype && (() => {
|
|
63
|
-
try {
|
|
64
|
-
return headers instanceof constructor;
|
|
65
|
-
} catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
})() && typeof prototypeGet === "function") {
|
|
69
|
-
const get = typeof Headers === "function" ? Reflect.get(Headers.prototype, "get") : void 0;
|
|
70
|
-
for (const getter of [get, prototypeGet]) {
|
|
71
|
-
if (typeof getter !== "function") continue;
|
|
72
|
-
try {
|
|
73
|
-
const value = Reflect.apply(getter, headers, [name]);
|
|
74
|
-
return typeof value === "string" && value ? value : void 0;
|
|
75
|
-
} catch {}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const ownGet = Object.hasOwn(headers, "get") ? Reflect.get(headers, "get") : void 0;
|
|
80
|
-
if (typeof ownGet === "function") {
|
|
81
|
-
const value = Reflect.apply(ownGet, headers, [name]);
|
|
82
|
-
return typeof value === "string" && value ? value : void 0;
|
|
83
|
-
}
|
|
84
|
-
if (!Object.hasOwn(headers, name)) return void 0;
|
|
85
|
-
const value = Reflect.get(headers, name);
|
|
86
|
-
if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
|
|
87
|
-
return typeof value === "string" ? value : void 0;
|
|
88
|
-
} catch {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
} catch {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function randomToken() {
|
|
96
|
-
return [...globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
97
|
-
}
|
|
98
|
-
async function refreshWorkspaceDevToken(rootDir, options = {}) {
|
|
99
|
-
const token = randomToken();
|
|
100
|
-
const tokenRoot = await workspaceDevTokenRoot(rootDir, options);
|
|
101
|
-
workspaceDevTokens().set(tokenRoot.key, token);
|
|
102
|
-
const [{ mkdir, writeFile }, { dirname }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
103
|
-
const file = tokenRoot.file;
|
|
104
|
-
await mkdir(dirname(file), {
|
|
105
|
-
mode: 448,
|
|
106
|
-
recursive: true
|
|
107
|
-
});
|
|
108
|
-
await writeFile(file, `${token}\n`, { mode: 384 });
|
|
109
|
-
return token;
|
|
110
|
-
}
|
|
111
|
-
async function ensureWorkspaceDevToken(rootDir, options = {}) {
|
|
112
|
-
return workspaceDevTokens().get((await workspaceDevTokenRoot(rootDir, options)).key) || await refreshWorkspaceDevToken(rootDir, options);
|
|
113
|
-
}
|
|
114
|
-
async function readWorkspaceDevToken(rootDir, options = {}) {
|
|
115
|
-
try {
|
|
116
|
-
const { readFile } = await import("node:fs/promises");
|
|
117
|
-
return (await readFile((await workspaceDevTokenRoot(rootDir, options)).file, "utf8")).trim() || void 0;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return;
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function validateWorkspaceDevToken(rootDir, headers, options = {}) {
|
|
124
|
-
const expectedToken = await ensureWorkspaceDevToken(rootDir, options);
|
|
125
|
-
return isViteHubSecretEqual(headerValue(headers, workspaceDevTokenHeader, expectedToken), expectedToken);
|
|
126
|
-
}
|
|
127
|
-
async function resolveWorkspace(workspace) {
|
|
128
|
-
if (typeof workspace === "string") return useWorkspaceFiles(workspace);
|
|
129
|
-
if (typeof workspace === "function") return await workspace();
|
|
130
|
-
return workspace;
|
|
131
|
-
}
|
|
132
|
-
function resolveWorkspaceFilePath(path, root) {
|
|
133
|
-
const normalizedPath = normalizeSafeWorkspacePath(path, { allowEmpty: false });
|
|
134
|
-
if (!root) return normalizedPath;
|
|
135
|
-
return `${normalizeSafeWorkspacePath(root, { allowEmpty: false })}/${normalizedPath}`;
|
|
136
|
-
}
|
|
137
|
-
function resolveContentType(path, mediaType, contentTypes) {
|
|
138
|
-
if (mediaType) return mediaType;
|
|
139
|
-
if (contentTypes && Object.hasOwn(contentTypes, path) && contentTypes[path]) return contentTypes[path];
|
|
140
|
-
const extension = path.includes(".") ? `.${path.split(".").at(-1)}` : "";
|
|
141
|
-
if (extension && contentTypes && Object.hasOwn(contentTypes, extension) && contentTypes[extension]) return contentTypes[extension];
|
|
142
|
-
return lookup(path) || "application/octet-stream";
|
|
143
|
-
}
|
|
144
|
-
function errorMessage(error) {
|
|
145
|
-
if (Object(error) !== error) return;
|
|
146
|
-
try {
|
|
147
|
-
const message = Object.getOwnPropertyDescriptor(error, "message")?.value;
|
|
148
|
-
return message === String(message) ? String(message) : void 0;
|
|
149
|
-
} catch {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function isNotFoundError(error) {
|
|
154
|
-
const code = getViteHubErrorShape(error)?.code;
|
|
155
|
-
const message = errorMessage(error);
|
|
156
|
-
return code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID" || message?.includes("Workspace file does not exist:") === true || message?.includes("Workspace path does not exist:") === true;
|
|
157
|
-
}
|
|
158
|
-
function workspaceSessionStarter(input) {
|
|
159
|
-
return input && typeof input === "object" && typeof input.startSession === "function" ? input : void 0;
|
|
160
|
-
}
|
|
161
|
-
function workspaceSourceMaterializer(input) {
|
|
162
|
-
return input && typeof input === "object" && typeof input.materializeSources === "function" ? input.materializeSources.bind(input) : void 0;
|
|
163
|
-
}
|
|
164
|
-
async function materializeWorkspaceDevSources(workspace, input) {
|
|
165
|
-
const materialize = workspaceSourceMaterializer(workspace) ?? workspaceSourceMaterializer(workspace.fs);
|
|
166
|
-
if (!materialize) return;
|
|
167
|
-
const paths = input.paths?.length ? input.paths : [""];
|
|
168
|
-
await withWorkspaceProgress(input.onProgress, {
|
|
169
|
-
data: { paths },
|
|
170
|
-
id: "workspace.dev.materialize",
|
|
171
|
-
label: "Materializing workspace sources"
|
|
172
|
-
}, async () => {
|
|
173
|
-
await Promise.all(paths.map(async (path) => {
|
|
174
|
-
await materialize({
|
|
175
|
-
abortSignal: input.abortSignal,
|
|
176
|
-
onProgress: async (event) => await input.onProgress?.({
|
|
177
|
-
data: { ...event },
|
|
178
|
-
durationMs: event.durationMs,
|
|
179
|
-
error: event.error,
|
|
180
|
-
id: `workspace.dev.materialize.${event.source}`,
|
|
181
|
-
label: `Materializing source ${event.source}`,
|
|
182
|
-
status: event.status
|
|
183
|
-
}),
|
|
184
|
-
path
|
|
185
|
-
}).catch((error) => {
|
|
186
|
-
if (path && isNotFoundError(error)) return;
|
|
187
|
-
throw error;
|
|
188
|
-
});
|
|
189
|
-
}));
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function workspaceFileNotFound() {
|
|
193
|
-
return Response.json({
|
|
194
|
-
status: 404,
|
|
195
|
-
message: "Workspace file not found."
|
|
196
|
-
}, { status: 404 });
|
|
197
|
-
}
|
|
198
|
-
/** Read a Workspace file as a Response. A missing, disallowed, or unsafe path gets a 404 Response. */
|
|
199
|
-
async function readWorkspaceFileResponse(options) {
|
|
200
|
-
let filePath;
|
|
201
|
-
try {
|
|
202
|
-
filePath = resolveWorkspaceFilePath(options.path, options.root);
|
|
203
|
-
} catch (error) {
|
|
204
|
-
if (isNotFoundError(error)) return workspaceFileNotFound();
|
|
205
|
-
throw error;
|
|
206
|
-
}
|
|
207
|
-
if (!matchesAny(filePath, options.allow)) return workspaceFileNotFound();
|
|
208
|
-
const workspace = await resolveWorkspace(options.workspace);
|
|
209
|
-
try {
|
|
210
|
-
const [content, stat] = await Promise.all([workspace.fs.readFile(filePath, { encoding: "binary" }), workspace.fs.stat(filePath)]);
|
|
211
|
-
if (stat.type !== "file") return workspaceFileNotFound();
|
|
212
|
-
const headers = new Headers(options.headers);
|
|
213
|
-
headers.set("content-type", resolveContentType(filePath, stat.mediaType, options.contentTypes));
|
|
214
|
-
headers.set("x-content-type-options", "nosniff");
|
|
215
|
-
if (options.cacheControl) headers.set("cache-control", options.cacheControl);
|
|
216
|
-
return new Response(content, { headers });
|
|
217
|
-
} catch (error) {
|
|
218
|
-
if (isNotFoundError(error)) return workspaceFileNotFound();
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Serve Workspace files from a route. The file path is the part of the URL path after `base`, percent-decoded, so
|
|
224
|
-
* `/files/my%20file.md` serves `my file.md`. A path that is not valid percent-encoding gets a 400 Response.
|
|
225
|
-
*/
|
|
226
|
-
function defineWorkspaceFileHandler(options) {
|
|
227
|
-
const { base, baseURL, ...fileOptions } = options;
|
|
228
|
-
const segments = [baseURL ?? "", base].map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
|
|
229
|
-
const prefix = segments ? `/${segments}/` : "/";
|
|
230
|
-
return { async fetch(request) {
|
|
231
|
-
const pathname = new URL(request.url).pathname;
|
|
232
|
-
if (baseURL !== void 0 && !pathname.startsWith(prefix)) return workspaceFileNotFound();
|
|
233
|
-
const start = baseURL === void 0 ? pathname.indexOf(prefix) : 0;
|
|
234
|
-
if (start < 0) return workspaceFileNotFound();
|
|
235
|
-
let path;
|
|
236
|
-
try {
|
|
237
|
-
path = decodeURIComponent(pathname.slice(start + prefix.length));
|
|
238
|
-
} catch {
|
|
239
|
-
return Response.json({
|
|
240
|
-
status: 400,
|
|
241
|
-
message: "Workspace file path is not valid percent-encoding."
|
|
242
|
-
}, { status: 400 });
|
|
243
|
-
}
|
|
244
|
-
return await readWorkspaceFileResponse({
|
|
245
|
-
...fileOptions,
|
|
246
|
-
path
|
|
247
|
-
});
|
|
248
|
-
} };
|
|
249
|
-
}
|
|
250
|
-
async function runWorkspaceDevCommand(input) {
|
|
251
|
-
const command = input.command.trim();
|
|
252
|
-
if (!command) throw workspaceErrorDiagnostics.WORKSPACE_R0040({ message: "Workspace Dev command cannot be empty." });
|
|
253
|
-
const definition = input.definition;
|
|
254
|
-
const workspace = typeof input.workspace === "string" ? await useWorkspaceFiles(input.workspace, definition ? {
|
|
255
|
-
definition,
|
|
256
|
-
mode: "write"
|
|
257
|
-
} : { mode: "write" }) : input.workspace;
|
|
258
|
-
const starter = workspaceSessionStarter(workspace) ?? workspaceSessionStarter(workspace.fs);
|
|
259
|
-
const startSession = starter?.startSession.bind(starter);
|
|
260
|
-
if (!startSession) throw workspaceErrorDiagnostics.WORKSPACE_R0041({ message: "Workspace Dev command requires a Workspace Session." });
|
|
261
|
-
await materializeWorkspaceDevSources(workspace, input);
|
|
262
|
-
let session;
|
|
263
|
-
const execOptions = {
|
|
264
|
-
abortSignal: input.abortSignal,
|
|
265
|
-
timeout: input.timeout
|
|
266
|
-
};
|
|
267
|
-
let result;
|
|
268
|
-
try {
|
|
269
|
-
await withWorkspaceProgress(input.onProgress, {
|
|
270
|
-
data: { paths: input.paths ?? null },
|
|
271
|
-
id: "workspace.dev.start-session",
|
|
272
|
-
label: "Starting workspace session"
|
|
273
|
-
}, async () => {
|
|
274
|
-
session = await startSession({
|
|
275
|
-
abortSignal: input.abortSignal,
|
|
276
|
-
host: input.host,
|
|
277
|
-
paths: input.paths
|
|
278
|
-
});
|
|
279
|
-
return session;
|
|
280
|
-
});
|
|
281
|
-
if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0042({ message: "Workspace Dev Session did not start." });
|
|
282
|
-
result = input.args ? await session.exec(command, input.args, execOptions) : await session.exec("sh", ["-c", command], execOptions);
|
|
283
|
-
const diff = result.exitCode === 0 ? await session.diff() : void 0;
|
|
284
|
-
if (diff?.entries.length) {
|
|
285
|
-
const commit = definition ? resolveWorkspaceAutoCommit(definition, diff) : void 0;
|
|
286
|
-
if (!definition || !hasWorkspaceCommitRules(definition) || commit) await session.commit({ message: commit?.message || "workspace dev command" });
|
|
287
|
-
}
|
|
288
|
-
} catch (error) {
|
|
289
|
-
if (!session) throw error;
|
|
290
|
-
try {
|
|
291
|
-
await session.close();
|
|
292
|
-
} catch (closeError) {
|
|
293
|
-
throw new AggregateError([error, closeError], "[vitehub] Workspace Dev command failed and session cleanup also failed.");
|
|
294
|
-
}
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0043({ message: "Workspace Dev Session did not start." });
|
|
298
|
-
await session.close();
|
|
299
|
-
return result;
|
|
300
|
-
}
|
|
301
|
-
export { refreshWorkspaceDevToken as a, workspaceDevHeader as c, workspaceDevTokenHeader as d, workspaceDevTokenServerId as f, readWorkspaceFileResponse as i, workspaceDevHeaderValue as l, ensureWorkspaceDevToken as n, runWorkspaceDevCommand as o, isViteHubSecretEqual as p, readWorkspaceDevToken as r, validateWorkspaceDevToken as s, defineWorkspaceFileHandler as t, workspaceDevRoute as u };
|
package/dist/state-BdDfBtOR.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import "./registry-s2Ob9PeX.js";
|
|
2
|
-
import { En as WorkspaceStore, T as VercelBlobWorkspaceStoreOptions, k as WorkspaceAssetsRegistry, s as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions } from "./types-Bel5IDmF.js";
|
|
3
|
-
import "./use-tools-CAK10LTc.js";
|
|
4
|
-
import "./use-CpphIBof.js";
|
|
5
|
-
import { t as WorkspaceRegistry } from "./registry-B0g19sdy.js";
|
|
6
|
-
type HostedWorkspaceStoreOptions = CloudflareArtifactsWorkspaceStoreOptions | GitHubWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions;
|
|
7
|
-
/** Returns `undefined` when no installed hosted store handles `options.provider`. */
|
|
8
|
-
type WorkspaceHostedStoreLoader = (options: HostedWorkspaceStoreOptions, workspaceName: string) => WorkspaceStore | undefined;
|
|
9
|
-
declare function setWorkspaceHostedStoreLoader(loader: WorkspaceHostedStoreLoader | undefined): void;
|
|
10
|
-
declare function getWorkspaceHostedStoreLoader(): WorkspaceHostedStoreLoader | undefined;
|
|
11
|
-
type CloudflareWorkerEnv = Record<string, unknown>;
|
|
12
|
-
declare function setActiveCloudflareEnv(env: CloudflareWorkerEnv | undefined): void;
|
|
13
|
-
declare function resetWorkspaceStoreCache(): void;
|
|
14
|
-
declare function invalidateWorkspaceStore(name: string): Promise<void>;
|
|
15
|
-
declare function setWorkspaceRuntimeRegistry(registry: WorkspaceRegistry): void;
|
|
16
|
-
declare function setWorkspaceRuntimeAssetsRegistry(registry: WorkspaceAssetsRegistry): void;
|
|
17
|
-
export { setActiveCloudflareEnv as a, getWorkspaceHostedStoreLoader as c, resetWorkspaceStoreCache as i, setWorkspaceHostedStoreLoader as l, setWorkspaceRuntimeAssetsRegistry as n, HostedWorkspaceStoreOptions as o, setWorkspaceRuntimeRegistry as r, WorkspaceHostedStoreLoader as s, invalidateWorkspaceStore as t };
|