@vite-hub/workspace 0.0.2 → 0.0.3
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 +35 -0
- package/dist/{ai-Cztw4eLk.js → ai-Ce3PtWFW.js} +14 -3
- package/dist/{ai-hFdsvDHC.d.ts → ai-nmHdzjCM.d.ts} +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/cloudflare.d.ts +4 -2
- package/dist/cloudflare.js +1 -2
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config-Ca5DM8fF.d.ts → config-3I1BnsdO.d.ts} +1 -1
- package/dist/{config-DCQ6y30R.js → config-CDoyls2X.js} +1 -1
- package/dist/{config--r5unwPc.js → config-CZLO0m9h.js} +3 -3
- package/dist/{file-B2q9NE18.js → file-CHfsZpso.js} +7 -8
- package/dist/{files-xy0le-_U.js → files-QRV55OCx.js} +1 -1
- package/dist/{github-lIO6-2sH.js → github-CfA5vpJ5.js} +5 -10
- package/dist/{glob-DeH0dzZX.js → glob-D0vD_wRY.js} +6 -12
- package/dist/{host-I-_vDs05.js → host-CAnbugpI.js} +2 -2
- package/dist/{artifacts-store-BAV9jZpd.js → hosted-C1-tTTTf.js} +29 -3
- package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +26 -4
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +1 -25
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -29
- package/dist/index.d.ts +27 -35
- package/dist/index.js +18 -25
- package/dist/{lifecycle-Lhk3dAMt.js → lifecycle-BYoa9hVb.js} +3 -3
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/mountx.d.ts +10 -0
- package/dist/mountx.js +143 -0
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +1 -1
- package/dist/{provider-CeQciesl.js → provider-C3_elpEh.js} +1 -1
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -361
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +1 -1
- package/dist/{registry-CoC9JxVt.d.ts → registry-BIQVCBWI.d.ts} +1 -1
- package/dist/{registry-C7DMdBXN.js → registry-CqyDTW9Y.js} +1 -1
- package/dist/{request-execution-C8qRcReq.js → request-execution-u9mgUXKX.js} +1 -1
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +5 -5
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime-options-BsPSv5O7.js +13 -0
- package/dist/runtime.d.ts +5 -5
- package/dist/runtime.js +11 -28
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -3
- package/dist/{shared-BRycRSbo.js → shared-jfogBrd5.js} +20 -2
- package/dist/source-metadata.d.ts +1 -1
- package/dist/source-metadata.js +1 -1
- package/dist/{state-DSAHEsq6.d.ts → state-TTqa3x3Y.d.ts} +2 -2
- package/dist/store-Bs1SLh55.js +414 -0
- package/dist/{sync-DO42ypji.js → sync-DiuDmSGk.js} +3 -3
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-DHkae7Cb.d.ts → types-60Yn149G.d.ts} +1 -17
- package/dist/{use-D16tf8Ph.d.ts → use-CUFSnFCS.d.ts} +2 -2
- package/dist/{use-d_PlAdOu.js → use-CsV3oIxH.js} +6 -23
- package/dist/{vite-NWC9mFjI.js → vite-tbfDxtlu.js} +332 -23
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/dist/{workspace-f2DBLmPZ.d.ts → workspace-66SKyiec.d.ts} +1 -1
- package/dist/{workspace-n4wBmdaM.js → workspace-C4k92Ow8.js} +8 -24
- package/package.json +13 -28
- package/dist/cli.d.ts +0 -31
- package/dist/cli.js +0 -303
- package/dist/cloudflare-env-CKxUs2fa.js +0 -20
- package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
- package/dist/providers/cloudflare/artifacts-store.js +0 -2
- package/dist/providers/vercel/blob-store.d.ts +0 -6
- package/dist/utils-BPdaCyI6.js +0 -55
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
2
|
import { o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
|
|
3
|
-
import { t as createWorkspaceTools } from "./ai-
|
|
4
|
-
import { d as fetch, g as markLiveWorkspaceSource, u as registerMcpResourcesSourceLoader } from "./config
|
|
5
|
-
import { g as isMissingWorkspacePathError, t as createWorkspace, u as resolveWorkspaceAutoCommit } from "./workspace-
|
|
6
|
-
import { r as resolveRegisteredWorkspaceDefinition } from "./registry-
|
|
7
|
-
import { t as useWorkspace } from "./use-
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as
|
|
3
|
+
import { t as createWorkspaceTools } from "./ai-Ce3PtWFW.js";
|
|
4
|
+
import { d as fetch, g as markLiveWorkspaceSource, u as registerMcpResourcesSourceLoader } from "./config-CZLO0m9h.js";
|
|
5
|
+
import { g as isMissingWorkspacePathError, t as createWorkspace, u as resolveWorkspaceAutoCommit } from "./workspace-C4k92Ow8.js";
|
|
6
|
+
import { r as resolveRegisteredWorkspaceDefinition } from "./registry-CqyDTW9Y.js";
|
|
7
|
+
import { t as useWorkspace } from "./use-CsV3oIxH.js";
|
|
8
|
+
import { t as withWorkspaceRuntimeOptions } from "./runtime-options-BsPSv5O7.js";
|
|
9
|
+
import { t as file } from "./file-CHfsZpso.js";
|
|
10
|
+
import { t as github } from "./github-CfA5vpJ5.js";
|
|
11
|
+
import { t as glob } from "./glob-D0vD_wRY.js";
|
|
11
12
|
import { posix } from "node:path";
|
|
12
13
|
import { lookup } from "mrmime";
|
|
13
|
-
import { markdown as markdown$1 } from "@vite-hub/source
|
|
14
|
-
import { mcpResources as mcpResources$1 } from "@vite-hub/source/sources/mcp-resources";
|
|
14
|
+
import { markdown as markdown$1, mcpResources as mcpResources$1 } from "@vite-hub/source";
|
|
15
15
|
import { gzipSync } from "node:zlib";
|
|
16
16
|
//#region src/core/define.ts
|
|
17
17
|
const workspaceDefinitionKeys = new Set([
|
|
@@ -70,13 +70,8 @@ function custom(source) {
|
|
|
70
70
|
function markdown(options) {
|
|
71
71
|
const key = normalizeSafeWorkspacePath(options.workspacePath || options.path || "");
|
|
72
72
|
return {
|
|
73
|
-
...markdown$1(options),
|
|
74
|
-
|
|
75
|
-
materialize: options.materialize,
|
|
76
|
-
mount: options.mount,
|
|
77
|
-
probeKeys: options.probeKeys || [key],
|
|
78
|
-
sync: options.sync,
|
|
79
|
-
validate: options.validate
|
|
73
|
+
...withWorkspaceRuntimeOptions(markdown$1(options), options),
|
|
74
|
+
probeKeys: options.probeKeys || [key]
|
|
80
75
|
};
|
|
81
76
|
}
|
|
82
77
|
//#endregion
|
|
@@ -87,18 +82,16 @@ function mcpResources(options) {
|
|
|
87
82
|
...options,
|
|
88
83
|
cache: options.cache
|
|
89
84
|
});
|
|
90
|
-
return markLiveWorkspaceSource({
|
|
85
|
+
return markLiveWorkspaceSource(withWorkspaceRuntimeOptions({
|
|
91
86
|
...baseSource,
|
|
92
|
-
cache: options.cache,
|
|
93
|
-
materialize: options.materialize || (options.sync ? "none" : "lazy"),
|
|
94
|
-
mount: options.mount,
|
|
95
87
|
async prepare(ctx) {
|
|
96
88
|
await baseSource.prepare?.(ctx);
|
|
97
89
|
resetLivePaths(livePaths, resolveMountPath(options.mount, ctx), await baseSource.getKeys(ctx));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
...options,
|
|
93
|
+
materialize: options.materialize || (options.sync ? "none" : "lazy")
|
|
94
|
+
}), livePaths);
|
|
102
95
|
}
|
|
103
96
|
registerMcpResourcesSourceLoader((input) => mcpResources(input));
|
|
104
97
|
function resolveMountPath(mount, ctx) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
2
|
import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
|
|
3
|
-
import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config
|
|
4
|
-
import {
|
|
3
|
+
import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config-CZLO0m9h.js";
|
|
4
|
+
import { n as createCurrentSnapshotFromStore } from "./store-Bs1SLh55.js";
|
|
5
5
|
import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
|
|
6
|
-
import { t as files } from "./files-
|
|
6
|
+
import { t as files } from "./files-QRV55OCx.js";
|
|
7
7
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
8
8
|
//#region src/lifecycle.ts
|
|
9
9
|
var lifecycle_exports = /* @__PURE__ */ __exportAll({
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tt as WorkspaceSourceItem, Y as WorkspaceLoader, j as WorkspaceContent } from "./types-60Yn149G.js";
|
|
2
2
|
|
|
3
3
|
//#region src/loaders/files.d.ts
|
|
4
4
|
interface FilesLoaderOptions {
|
package/dist/loader.js
CHANGED
package/dist/mountx.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ht as WorkspaceSession } from "./types-60Yn149G.js";
|
|
2
|
+
import { FsDriver } from "mountx";
|
|
3
|
+
|
|
4
|
+
//#region src/mountx.d.ts
|
|
5
|
+
interface WorkspaceMountXDriverOptions {
|
|
6
|
+
readOnly?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function createWorkspaceDriver(session: WorkspaceSession, options?: WorkspaceMountXDriverOptions): FsDriver;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { WorkspaceMountXDriverOptions, createWorkspaceDriver };
|
package/dist/mountx.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { createUnstorageDriver } from "mountx/drivers/unstorage";
|
|
3
|
+
//#region src/mountx.ts
|
|
4
|
+
function keyToPath(key) {
|
|
5
|
+
return key.split(":").join("/");
|
|
6
|
+
}
|
|
7
|
+
function pathToKey(path) {
|
|
8
|
+
return path.split("/").join(":");
|
|
9
|
+
}
|
|
10
|
+
function valueToBytes(value) {
|
|
11
|
+
if (value instanceof Uint8Array) return value;
|
|
12
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
13
|
+
if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
14
|
+
return new TextEncoder().encode(typeof value === "string" ? value : JSON.stringify(value));
|
|
15
|
+
}
|
|
16
|
+
async function findEntry(session, path) {
|
|
17
|
+
if (!path) return void 0;
|
|
18
|
+
const parent = posix.dirname(path);
|
|
19
|
+
return (await session.list(parent === "." ? "" : parent)).find((entry) => entry.path === path);
|
|
20
|
+
}
|
|
21
|
+
function assertProjectablePath(path) {
|
|
22
|
+
const invalidName = path.split("/").find((segment) => segment.includes(":") || segment.includes("?") || segment.endsWith("$"));
|
|
23
|
+
if (invalidName) throw Object.assign(/* @__PURE__ */ new Error(`Workspace filename is not representable as an unstorage key: ${invalidName}`), {
|
|
24
|
+
code: "EINVAL",
|
|
25
|
+
path
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function assertProjectableEntry(entry) {
|
|
29
|
+
if (entry) assertProjectablePath(entry.path);
|
|
30
|
+
if (entry?.metadata?.gitMode !== "120000") return entry;
|
|
31
|
+
throw Object.assign(/* @__PURE__ */ new Error(`MountX cannot project Workspace symlink semantics: ${entry.path}`), {
|
|
32
|
+
code: "ENOTSUP",
|
|
33
|
+
path: entry.path
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function createWorkspaceStorage(session, readOnly) {
|
|
37
|
+
const writeOptionsByValue = /* @__PURE__ */ new WeakMap();
|
|
38
|
+
async function readItem(key) {
|
|
39
|
+
const path = keyToPath(key);
|
|
40
|
+
const entry = assertProjectableEntry(await findEntry(session, path));
|
|
41
|
+
if (entry?.type !== "file") return null;
|
|
42
|
+
const value = valueToBytes(await session.readFile(path, { encoding: "binary" }));
|
|
43
|
+
writeOptionsByValue.set(value, {
|
|
44
|
+
mediaType: entry.mediaType,
|
|
45
|
+
metadata: entry.metadata
|
|
46
|
+
});
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
getItem: readItem,
|
|
51
|
+
getItemRaw: readItem,
|
|
52
|
+
async getKeys(base) {
|
|
53
|
+
const path = keyToPath(base);
|
|
54
|
+
return (await session.list(path, { recursive: true })).filter((entry) => assertProjectableEntry(entry)?.type === "file").map((entry) => pathToKey(entry.path));
|
|
55
|
+
},
|
|
56
|
+
async getMeta(key) {
|
|
57
|
+
const entry = assertProjectableEntry(await findEntry(session, keyToPath(key)));
|
|
58
|
+
if (!entry) return null;
|
|
59
|
+
return {
|
|
60
|
+
mtime: entry.mtime === void 0 ? void 0 : new Date(entry.mtime),
|
|
61
|
+
size: entry.size
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
async hasItem(key) {
|
|
65
|
+
return assertProjectableEntry(await findEntry(session, keyToPath(key)))?.type === "file";
|
|
66
|
+
},
|
|
67
|
+
...readOnly ? {} : {
|
|
68
|
+
async removeItem(key) {
|
|
69
|
+
await session.rm(keyToPath(key), { force: true });
|
|
70
|
+
},
|
|
71
|
+
async setItemRaw(key, value) {
|
|
72
|
+
const path = keyToPath(key);
|
|
73
|
+
const entry = assertProjectableEntry(await findEntry(session, path));
|
|
74
|
+
const writeOptions = value instanceof Uint8Array ? writeOptionsByValue.get(value) : void 0;
|
|
75
|
+
await session.writeFile(path, valueToBytes(value), writeOptions ?? {
|
|
76
|
+
mediaType: entry?.mediaType,
|
|
77
|
+
metadata: entry?.metadata
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function createWorkspaceDriver(session, options = {}) {
|
|
84
|
+
const readOnly = options.readOnly ?? false;
|
|
85
|
+
const driver = createUnstorageDriver(createWorkspaceStorage(session, readOnly), { readOnly });
|
|
86
|
+
function projectExecutableMode(stats, executable) {
|
|
87
|
+
if (executable) stats.mode |= 73;
|
|
88
|
+
return stats;
|
|
89
|
+
}
|
|
90
|
+
async function projectStats(path, stats) {
|
|
91
|
+
return projectExecutableMode(stats, assertProjectableEntry(await findEntry(session, path.replace(/^\/+/, "")))?.metadata?.gitMode === "100755");
|
|
92
|
+
}
|
|
93
|
+
async function stat(path) {
|
|
94
|
+
assertProjectablePath(path);
|
|
95
|
+
return await projectStats(path, await driver.stat(path));
|
|
96
|
+
}
|
|
97
|
+
const singlePathMethods = new Set([
|
|
98
|
+
"chmod",
|
|
99
|
+
"chown",
|
|
100
|
+
"lchown",
|
|
101
|
+
"lutimes",
|
|
102
|
+
"mkdir",
|
|
103
|
+
"readlink",
|
|
104
|
+
"readdir",
|
|
105
|
+
"rmdir",
|
|
106
|
+
"statfs",
|
|
107
|
+
"truncate",
|
|
108
|
+
"unlink",
|
|
109
|
+
"utimes"
|
|
110
|
+
]);
|
|
111
|
+
const twoPathMethods = new Set(["link", "rename"]);
|
|
112
|
+
return new Proxy(driver, { get(target, property) {
|
|
113
|
+
if (property === "stat" || property === "lstat") return stat;
|
|
114
|
+
const value = Reflect.get(target, property, target);
|
|
115
|
+
if (typeof value !== "function") return value;
|
|
116
|
+
if (property === "open") return async (path, ...args) => {
|
|
117
|
+
assertProjectablePath(path);
|
|
118
|
+
const executable = assertProjectableEntry(await findEntry(session, path.replace(/^\/+/, "")))?.metadata?.gitMode === "100755";
|
|
119
|
+
const handle = await value.call(target, path, ...args);
|
|
120
|
+
return new Proxy(handle, { get(handleTarget, handleProperty) {
|
|
121
|
+
if (handleProperty === "stat") return async () => projectExecutableMode(await handleTarget.stat(), executable);
|
|
122
|
+
const handleValue = Reflect.get(handleTarget, handleProperty, handleTarget);
|
|
123
|
+
return typeof handleValue === "function" ? handleValue.bind(handleTarget) : handleValue;
|
|
124
|
+
} });
|
|
125
|
+
};
|
|
126
|
+
if (singlePathMethods.has(property)) return (path, ...args) => {
|
|
127
|
+
assertProjectablePath(path);
|
|
128
|
+
return value.call(target, path, ...args);
|
|
129
|
+
};
|
|
130
|
+
if (twoPathMethods.has(property)) return (from, to, ...args) => {
|
|
131
|
+
assertProjectablePath(from);
|
|
132
|
+
assertProjectablePath(to);
|
|
133
|
+
return value.call(target, from, to, ...args);
|
|
134
|
+
};
|
|
135
|
+
if (property === "symlink") return (linkTarget, path, ...args) => {
|
|
136
|
+
assertProjectablePath(path);
|
|
137
|
+
return value.call(target, linkTarget, path, ...args);
|
|
138
|
+
};
|
|
139
|
+
return value.bind(target);
|
|
140
|
+
} });
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { createWorkspaceDriver };
|
package/dist/nitro.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createWorkspaceNitroConfig } from "./vite-
|
|
1
|
+
import { t as createWorkspaceNitroConfig } from "./vite-tbfDxtlu.js";
|
|
2
2
|
export { createWorkspaceNitroConfig };
|
package/dist/nuxt.d.ts
CHANGED
package/dist/nuxt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as hubWorkspace, t as createWorkspaceNitroConfig } from "./vite-
|
|
1
|
+
import { n as hubWorkspace, t as createWorkspaceNitroConfig } from "./vite-tbfDxtlu.js";
|
|
2
2
|
//#region src/nuxt.ts
|
|
3
3
|
function isWorkspaceVitePlugin(value) {
|
|
4
4
|
return Boolean(value && typeof value === "object" && value.name === "@vite-hub/workspace/vite");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, p as workspaceError, r as contentToBytes, t as contentStreamChunks, u as resolveInside } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { createGitHubWorkspaceStore } from "./
|
|
2
|
+
import { t as createGitHubWorkspaceStore } from "./store-Bs1SLh55.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { defu } from "defu";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Jt as WorkspaceStore, o as GitHubWorkspaceStoreOptions } from "../../types-60Yn149G.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/github/store.d.ts
|
|
4
4
|
declare function createGitHubWorkspaceStore(options: GitHubWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|
|
@@ -1,362 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
|
|
3
|
-
import { r as workspaceStoreTarget } from "../../target-D4Bqb1eH.js";
|
|
4
|
-
import { c as readGitHubBlob, d as resolveGitHubBranchOption, h as resolveGitHubTokenOption, i as gitBlobSha, l as readGitHubBranchState, m as resolveGitHubRootOption, n as createGitHubBlob, o as joinGitPath, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "../../shared-BRycRSbo.js";
|
|
5
|
-
import { posix } from "node:path";
|
|
6
|
-
//#region src/providers/github/store.ts
|
|
7
|
-
function isReservedWorkspacePath(path) {
|
|
8
|
-
const root = normalizeWorkspacePath(path).split("/")[0];
|
|
9
|
-
return root === ".git" || root === ".vitehub";
|
|
10
|
-
}
|
|
11
|
-
function contentLength(content) {
|
|
12
|
-
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
13
|
-
}
|
|
14
|
-
function gitHubFileMetadata(entry) {
|
|
15
|
-
return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
|
|
16
|
-
}
|
|
17
|
-
function gitHubFileMode(metadata) {
|
|
18
|
-
return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
|
|
19
|
-
}
|
|
20
|
-
function inheritedGitHubFileMetadata(file, current) {
|
|
21
|
-
if (file.metadata) return file.metadata;
|
|
22
|
-
return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
|
|
23
|
-
}
|
|
24
|
-
function parentDirectories(path) {
|
|
25
|
-
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
26
|
-
const directories = [];
|
|
27
|
-
for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
|
|
28
|
-
return directories;
|
|
29
|
-
}
|
|
30
|
-
function resolveSymlinkTarget(path, bytes) {
|
|
31
|
-
const target = gitSymlinkTargetFromBytes(bytes);
|
|
32
|
-
if (!target || target.startsWith("/")) return;
|
|
33
|
-
const base = path.split("/").slice(0, -1).join("/");
|
|
34
|
-
const resolved = posix.normalize(base ? `${base}/${target}` : target);
|
|
35
|
-
if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
|
|
36
|
-
return normalizeSafeWorkspacePath(resolved);
|
|
37
|
-
}
|
|
38
|
-
function gitSymlinkTargetFromBytes(bytes) {
|
|
39
|
-
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
|
40
|
-
}
|
|
41
|
-
var GitHubWorkspaceStore = class {
|
|
42
|
-
workspaceName;
|
|
43
|
-
#baseline;
|
|
44
|
-
#baselineRefSha;
|
|
45
|
-
#baselineTreeSha;
|
|
46
|
-
#branch;
|
|
47
|
-
#dirty = false;
|
|
48
|
-
#files = /* @__PURE__ */ new Map();
|
|
49
|
-
#ready;
|
|
50
|
-
#remoteFiles = /* @__PURE__ */ new Map();
|
|
51
|
-
#repository;
|
|
52
|
-
#root;
|
|
53
|
-
#token;
|
|
54
|
-
constructor(options, workspaceName) {
|
|
55
|
-
this.workspaceName = workspaceName;
|
|
56
|
-
this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
|
|
57
|
-
this.#branch = resolveGitHubBranchOption(options);
|
|
58
|
-
this.#root = resolveGitHubRootOption(options, workspaceName);
|
|
59
|
-
this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
|
|
60
|
-
}
|
|
61
|
-
[workspaceStoreTarget]() {
|
|
62
|
-
return {
|
|
63
|
-
provider: "github",
|
|
64
|
-
branch: this.#branch,
|
|
65
|
-
repository: this.#repository
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
async readFile(path) {
|
|
69
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
70
|
-
await this.#ensure({ refresh: true });
|
|
71
|
-
return await this.#readWorkspaceFile(normalized);
|
|
72
|
-
}
|
|
73
|
-
async writeFile(path, file) {
|
|
74
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
75
|
-
await this.#ensure({ refresh: false });
|
|
76
|
-
const current = this.#files.get(normalized);
|
|
77
|
-
const metadata = inheritedGitHubFileMetadata(file, current);
|
|
78
|
-
const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
|
|
79
|
-
const update = await createGitHubFileUpdate(normalized, this.#root, content);
|
|
80
|
-
if (current?.gitSha === update.gitSha) {
|
|
81
|
-
if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
|
|
82
|
-
this.#files.set(normalized, {
|
|
83
|
-
...current,
|
|
84
|
-
mediaType: file.mediaType,
|
|
85
|
-
metadata,
|
|
86
|
-
size: contentLength(content)
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
await createGitHubBlob({
|
|
91
|
-
bytes: update.bytes,
|
|
92
|
-
kind: "store",
|
|
93
|
-
repository: this.#repository,
|
|
94
|
-
token: this.#token
|
|
95
|
-
});
|
|
96
|
-
this.#files.set(normalized, {
|
|
97
|
-
gitSha: update.gitSha,
|
|
98
|
-
mediaType: file.mediaType,
|
|
99
|
-
metadata,
|
|
100
|
-
path: normalized,
|
|
101
|
-
size: contentLength(content)
|
|
102
|
-
});
|
|
103
|
-
this.#dirty = true;
|
|
104
|
-
}
|
|
105
|
-
async writeFileStream(path, file) {
|
|
106
|
-
const content = await contentStreamToBytes(file.content);
|
|
107
|
-
await this.writeFile(path, {
|
|
108
|
-
path: file.path,
|
|
109
|
-
content,
|
|
110
|
-
mediaType: file.mediaType,
|
|
111
|
-
metadata: file.metadata
|
|
112
|
-
});
|
|
113
|
-
return {
|
|
114
|
-
digest: await gitBlobSha(content),
|
|
115
|
-
mediaType: file.mediaType,
|
|
116
|
-
path: normalizeSafeWorkspacePath(path),
|
|
117
|
-
size: content.byteLength,
|
|
118
|
-
type: "file"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async list(prefix = "", options = {}) {
|
|
122
|
-
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
123
|
-
await this.#ensure({ refresh: true });
|
|
124
|
-
return await this.#listEntries(normalizedPrefix, options);
|
|
125
|
-
}
|
|
126
|
-
async glob(pattern, _options = {}) {
|
|
127
|
-
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
128
|
-
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
129
|
-
}
|
|
130
|
-
async stat(path) {
|
|
131
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
132
|
-
await this.#ensure({ refresh: true });
|
|
133
|
-
const file = this.#files.get(normalized);
|
|
134
|
-
if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
|
|
135
|
-
if (this.#directoryExists(normalized)) return {
|
|
136
|
-
path: normalized,
|
|
137
|
-
type: "directory"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async mkdir(path, _options = {}) {
|
|
141
|
-
normalizeSafeWorkspacePath(path);
|
|
142
|
-
}
|
|
143
|
-
async rm(path, options = {}) {
|
|
144
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
145
|
-
await this.#ensure({ refresh: false });
|
|
146
|
-
if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
|
|
147
|
-
this.#files.delete(normalized);
|
|
148
|
-
this.#dirty = true;
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const children = this.#publicDescendants(normalized);
|
|
152
|
-
if (!(children.length > 0)) {
|
|
153
|
-
if (options.force) return;
|
|
154
|
-
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
155
|
-
}
|
|
156
|
-
if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
157
|
-
for (const child of children) this.#files.delete(child);
|
|
158
|
-
this.#dirty = true;
|
|
159
|
-
}
|
|
160
|
-
async snapshot(options = {}) {
|
|
161
|
-
await this.#ensure({ refresh: false });
|
|
162
|
-
const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
|
|
163
|
-
if (!this.#dirty) {
|
|
164
|
-
this.#baseline = snapshot;
|
|
165
|
-
return snapshot;
|
|
166
|
-
}
|
|
167
|
-
const remote = await readGitHubBranchState({
|
|
168
|
-
branch: this.#branch,
|
|
169
|
-
kind: "store",
|
|
170
|
-
repository: this.#repository,
|
|
171
|
-
root: this.#root,
|
|
172
|
-
token: this.#token
|
|
173
|
-
});
|
|
174
|
-
if (this.#baselineRefSha && remote.refSha !== this.#baselineRefSha) throw workspaceError(`[vitehub] GitHub Workspace Store conflict for ${this.#repository}@${this.#branch}: the branch changed after this Workspace Store loaded. Snapshotting requires a Workspace Store loaded from the current branch head.`);
|
|
175
|
-
this.#remoteFiles = remote.files;
|
|
176
|
-
this.#baselineRefSha = remote.refSha;
|
|
177
|
-
this.#baselineTreeSha = remote.treeSha;
|
|
178
|
-
const changedFiles = [...this.#files.values()].filter((file) => {
|
|
179
|
-
const remote = this.#remoteFiles.get(file.path);
|
|
180
|
-
return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
|
|
181
|
-
});
|
|
182
|
-
const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
|
|
183
|
-
if (!changedFiles.length && !deletePaths.length) {
|
|
184
|
-
this.#dirty = false;
|
|
185
|
-
this.#baseline = snapshot;
|
|
186
|
-
return snapshot;
|
|
187
|
-
}
|
|
188
|
-
const files = changedFiles.map((file) => {
|
|
189
|
-
return {
|
|
190
|
-
bytes: file.bytes,
|
|
191
|
-
fullPath: joinGitPath(this.#root, file.path),
|
|
192
|
-
gitSha: file.gitSha,
|
|
193
|
-
mode: gitHubFileMode(file.metadata)
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
const commit = await commitGitHubChanges({
|
|
197
|
-
baseTreeSha: this.#baselineTreeSha,
|
|
198
|
-
branch: this.#branch,
|
|
199
|
-
branchExists: remote.branchExists,
|
|
200
|
-
deletePaths,
|
|
201
|
-
files,
|
|
202
|
-
message: options.name || "chore: update workspace snapshot",
|
|
203
|
-
parentSha: this.#baselineRefSha,
|
|
204
|
-
repository: this.#repository,
|
|
205
|
-
token: this.#token
|
|
206
|
-
});
|
|
207
|
-
this.#dirty = false;
|
|
208
|
-
this.#baselineRefSha = commit.commitSha;
|
|
209
|
-
this.#baselineTreeSha = commit.treeSha;
|
|
210
|
-
this.#remoteFiles = this.#toRemoteFiles();
|
|
211
|
-
this.#baseline = {
|
|
212
|
-
...snapshot,
|
|
213
|
-
id: commit.commitSha
|
|
214
|
-
};
|
|
215
|
-
return this.#baseline;
|
|
216
|
-
}
|
|
217
|
-
async diff(options = {}) {
|
|
218
|
-
await this.#ensure({ refresh: true });
|
|
219
|
-
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
|
|
220
|
-
}
|
|
221
|
-
async getMeta(key) {
|
|
222
|
-
await this.#ensure({ refresh: true });
|
|
223
|
-
const file = await this.#readWorkspaceFile(this.#metaPath(key));
|
|
224
|
-
if (!file) return void 0;
|
|
225
|
-
return JSON.parse(new TextDecoder().decode(file.bytes));
|
|
226
|
-
}
|
|
227
|
-
async setMeta(key, value) {
|
|
228
|
-
const path = this.#metaPath(key);
|
|
229
|
-
const content = JSON.stringify(value);
|
|
230
|
-
const bytes = new TextEncoder().encode(content);
|
|
231
|
-
await this.#ensure({ refresh: false });
|
|
232
|
-
this.#files.set(path, {
|
|
233
|
-
bytes,
|
|
234
|
-
gitSha: await gitBlobSha(bytes),
|
|
235
|
-
path,
|
|
236
|
-
size: bytes.byteLength
|
|
237
|
-
});
|
|
238
|
-
this.#dirty = true;
|
|
239
|
-
}
|
|
240
|
-
async #ensure(options) {
|
|
241
|
-
const wasReady = !!this.#ready;
|
|
242
|
-
this.#ready ||= this.#load();
|
|
243
|
-
await this.#ready;
|
|
244
|
-
if (wasReady && options.refresh && !this.#dirty) await this.#load();
|
|
245
|
-
}
|
|
246
|
-
async #load() {
|
|
247
|
-
const remote = await readGitHubBranchState({
|
|
248
|
-
branch: this.#branch,
|
|
249
|
-
kind: "store",
|
|
250
|
-
repository: this.#repository,
|
|
251
|
-
root: this.#root,
|
|
252
|
-
token: this.#token
|
|
253
|
-
});
|
|
254
|
-
this.#baselineRefSha = remote.refSha;
|
|
255
|
-
this.#baselineTreeSha = remote.treeSha;
|
|
256
|
-
this.#remoteFiles = remote.files;
|
|
257
|
-
if (!this.#dirty) {
|
|
258
|
-
this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
|
|
259
|
-
gitSha: entry.sha,
|
|
260
|
-
metadata: gitHubFileMetadata(entry),
|
|
261
|
-
path,
|
|
262
|
-
size: entry.size
|
|
263
|
-
}]));
|
|
264
|
-
this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
|
|
268
|
-
const current = this.#files.get(path);
|
|
269
|
-
if (!current) return void 0;
|
|
270
|
-
const currentBytes = await this.#readFileBytes(current);
|
|
271
|
-
if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
|
|
272
|
-
const target = resolveSymlinkTarget(path, currentBytes);
|
|
273
|
-
if (target && this.#files.has(target)) {
|
|
274
|
-
seen.add(path);
|
|
275
|
-
const resolved = await this.#readWorkspaceFile(target, seen);
|
|
276
|
-
if (resolved) return {
|
|
277
|
-
...resolved,
|
|
278
|
-
mediaType: current.mediaType ?? resolved.mediaType,
|
|
279
|
-
metadata: await this.#fileMetadata(current) ?? resolved.metadata,
|
|
280
|
-
path
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
content: currentBytes,
|
|
286
|
-
bytes: currentBytes,
|
|
287
|
-
mediaType: current.mediaType,
|
|
288
|
-
metadata: await this.#fileMetadata(current),
|
|
289
|
-
path
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
async #readFileBytes(file) {
|
|
293
|
-
if (!file.bytes) {
|
|
294
|
-
file.bytes = await readGitHubBlob({
|
|
295
|
-
kind: "store",
|
|
296
|
-
repository: this.#repository,
|
|
297
|
-
sha: file.gitSha,
|
|
298
|
-
token: this.#token
|
|
299
|
-
});
|
|
300
|
-
file.size = file.bytes.byteLength;
|
|
301
|
-
}
|
|
302
|
-
return file.bytes;
|
|
303
|
-
}
|
|
304
|
-
async #fileMetadata(file) {
|
|
305
|
-
if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
|
|
306
|
-
return {
|
|
307
|
-
...file.metadata,
|
|
308
|
-
symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
async #listEntries(prefix, options) {
|
|
312
|
-
const entries = /* @__PURE__ */ new Map();
|
|
313
|
-
for (const file of this.#files.values()) {
|
|
314
|
-
if (isReservedWorkspacePath(file.path)) continue;
|
|
315
|
-
for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
|
|
316
|
-
path: dir,
|
|
317
|
-
type: "directory"
|
|
318
|
-
});
|
|
319
|
-
if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
|
|
320
|
-
}
|
|
321
|
-
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
322
|
-
}
|
|
323
|
-
#entryInPrefix(path, prefix, options) {
|
|
324
|
-
if (!prefix) return options.recursive || !path.includes("/");
|
|
325
|
-
if (path === prefix) return false;
|
|
326
|
-
if (!path.startsWith(`${prefix}/`)) return false;
|
|
327
|
-
return options.recursive || !path.slice(prefix.length + 1).includes("/");
|
|
328
|
-
}
|
|
329
|
-
async #fileEntry(file) {
|
|
330
|
-
return {
|
|
331
|
-
digest: file.gitSha,
|
|
332
|
-
mediaType: file.mediaType,
|
|
333
|
-
metadata: await this.#fileMetadata(file),
|
|
334
|
-
path: file.path,
|
|
335
|
-
size: file.size,
|
|
336
|
-
type: "file"
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
#directoryExists(path) {
|
|
340
|
-
return this.#publicDescendants(path).length > 0;
|
|
341
|
-
}
|
|
342
|
-
#publicDescendants(path) {
|
|
343
|
-
return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
|
|
344
|
-
}
|
|
345
|
-
#metaPath(key) {
|
|
346
|
-
return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
|
|
347
|
-
}
|
|
348
|
-
#toRemoteFiles() {
|
|
349
|
-
return new Map([...this.#files.values()].map((file) => [file.path, {
|
|
350
|
-
path: joinGitPath(this.#root, file.path),
|
|
351
|
-
sha: file.gitSha,
|
|
352
|
-
size: file.size,
|
|
353
|
-
type: "blob",
|
|
354
|
-
mode: gitHubFileMode(file.metadata)
|
|
355
|
-
}]));
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
function createGitHubWorkspaceStore(options, workspaceName) {
|
|
359
|
-
return new GitHubWorkspaceStore(options, workspaceName);
|
|
360
|
-
}
|
|
361
|
-
//#endregion
|
|
1
|
+
import { t as createGitHubWorkspaceStore } from "../../store-Bs1SLh55.js";
|
|
362
2
|
export { createGitHubWorkspaceStore };
|
package/dist/publish.d.ts
CHANGED
package/dist/publish.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as normalizeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
|
|
2
2
|
import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
-
import { a as isWorkspaceFileEntry, d as resolveGitHubBranchOption, f as resolveGitHubOption, h as resolveGitHubTokenOption, l as readGitHubBranchState, m as resolveGitHubRootOption, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-
|
|
3
|
+
import { a as isWorkspaceFileEntry, d as resolveGitHubBranchOption, f as resolveGitHubOption, h as resolveGitHubTokenOption, l as readGitHubBranchState, m as resolveGitHubRootOption, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-jfogBrd5.js";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
6
|
//#region src/publishers/manifest.ts
|