@vite-hub/workspace 0.0.3 → 0.0.4
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/LICENSE +201 -0
- package/README.md +13 -2
- package/dist/{ai-Ce3PtWFW.js → ai-BqCC8BpY.js} +2 -2
- package/dist/{ai-nmHdzjCM.d.ts → ai-CjxvGqM0.d.ts} +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
- package/dist/chunk-2rV9d50f.js +35 -0
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config-CZLO0m9h.js → config-Bc3c4Su1.js} +213 -120
- package/dist/{config-CDoyls2X.js → config-CHLLWklZ.js} +9 -3
- package/dist/{config-3I1BnsdO.d.ts → config-DE9xlaIw.d.ts} +1 -1
- package/dist/{file-CHfsZpso.js → file-Bc1X7pco.js} +3 -3
- package/dist/{files-QRV55OCx.js → files-Q6xZjDHA.js} +20 -9
- package/dist/{github-CfA5vpJ5.js → github-DHnjxQIX.js} +24 -15
- package/dist/{glob-D0vD_wRY.js → glob-CEZKeZFC.js} +5 -4
- package/dist/host-DJH8cuoU.js +1030 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-RPeJOCFz.js} +121 -31
- package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
- 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 +42 -51
- package/dist/index.js +124 -419
- package/dist/lifecycle-LrL3sA4n.js +316 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/metadata-target-B0tOmVW7.js +717 -0
- package/dist/mountx.d.ts +1 -1
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +8 -2
- package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
- package/dist/{provider-C3_elpEh.js → provider-B1yLjCJJ.js} +194 -47
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +2 -2
- package/dist/registry-D3yzt8HQ.js +127 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Uj6IVxes.d.ts} +3 -3
- package/dist/{request-execution-u9mgUXKX.js → request-execution-B-dSFlGB.js} +8 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -2
- 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 +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime-type-iEE6BjQJ.js +34 -0
- package/dist/runtime.d.ts +42 -7
- package/dist/runtime.js +275 -82
- package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +23 -50
- package/dist/{shared-jfogBrd5.js → shared-DTR1Hhma.js} +97 -39
- package/dist/source-metadata.d.ts +9 -2
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-tYcRWEh2.d.ts} +13 -12
- package/dist/store-Dt_Jyys3.js +608 -0
- package/dist/{sync-DiuDmSGk.js → sync-DnTQwt8r.js} +6 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CVzURBxC.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-CYuwjJ4V.d.ts} +94 -27
- package/dist/{use-CsV3oIxH.js → use-BTNDR5Rd.js} +145 -31
- package/dist/{use-CUFSnFCS.d.ts → use-BiHzt0xA.d.ts} +21 -4
- package/dist/vite-BptCrpv2.js +4526 -0
- package/dist/vite-CtA9guIM.d.ts +66 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/{workspace-C4k92Ow8.js → workspace-Dq08Yn72.js} +224 -529
- package/dist/{workspace-66SKyiec.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
- package/package.json +15 -18
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
package/dist/mountx.d.ts
CHANGED
package/dist/nitro.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as WorkspaceNitroConfigOptions, r as NitroConfig, s as createWorkspaceNitroConfig } from "./vite-CtA9guIM.js";
|
|
2
2
|
export { type NitroConfig, type WorkspaceNitroConfigOptions, createWorkspaceNitroConfig };
|
package/dist/nitro.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createWorkspaceNitroConfig } from "./vite-
|
|
1
|
+
import { t as createWorkspaceNitroConfig } from "./vite-BptCrpv2.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, r as setWorkspaceVitePluginHosting, t as createWorkspaceNitroConfig } from "./vite-BptCrpv2.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");
|
|
@@ -17,10 +17,16 @@ function viteHubWorkspaceNuxtModule(options = {}, nuxt) {
|
|
|
17
17
|
});
|
|
18
18
|
nuxt.options.vite ??= {};
|
|
19
19
|
const workspaceOptions = resolveWorkspaceOptions(options, nuxt.options.vite.workspace);
|
|
20
|
+
let resolvedNitroHosting;
|
|
20
21
|
const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
|
|
21
|
-
if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace(
|
|
22
|
+
if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace({
|
|
23
|
+
...workspaceOptions || {},
|
|
24
|
+
hosting: () => resolvedNitroHosting
|
|
25
|
+
}));
|
|
26
|
+
for (const plugin of plugins) if (isWorkspaceVitePlugin(plugin)) setWorkspaceVitePluginHosting(plugin, () => resolvedNitroHosting);
|
|
22
27
|
nuxt.options.vite.plugins = plugins;
|
|
23
28
|
nuxt.hook?.("nitro:config", async (nitroConfig) => {
|
|
29
|
+
resolvedNitroHosting = typeof nitroConfig.preset === "string" ? nitroConfig.preset : void 0;
|
|
24
30
|
const rootDir = nuxt.options.rootDir || process.cwd();
|
|
25
31
|
const nitro = await createWorkspaceNitroConfig({
|
|
26
32
|
aliases: nuxt.options.alias,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "./chunk-2rV9d50f.js";
|
|
2
2
|
import { relative, resolve, sep } from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { minimatch } from "minimatch";
|
|
@@ -7,6 +7,19 @@ import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
|
7
7
|
function workspaceError(message, options) {
|
|
8
8
|
return new ViteHubError("WORKSPACE_FAILED", message, options);
|
|
9
9
|
}
|
|
10
|
+
function workspaceConflict(message, options) {
|
|
11
|
+
return new ViteHubError("WORKSPACE_CONFLICT", message, options);
|
|
12
|
+
}
|
|
13
|
+
function workspaceConflictError(path, expected, actual) {
|
|
14
|
+
return workspaceConflict(`[vitehub] Workspace path changed before the conditional write: ${path}.`, { details: {
|
|
15
|
+
actual,
|
|
16
|
+
expected,
|
|
17
|
+
path
|
|
18
|
+
} });
|
|
19
|
+
}
|
|
20
|
+
function assertWorkspaceDigest(path, expected, actual) {
|
|
21
|
+
if (expected === null ? actual !== void 0 : actual !== expected) throw workspaceConflictError(path, expected, actual);
|
|
22
|
+
}
|
|
10
23
|
function workspaceNotFoundError(name) {
|
|
11
24
|
return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
|
|
12
25
|
}
|
|
@@ -16,7 +29,10 @@ function workspacePathError(path) {
|
|
|
16
29
|
}
|
|
17
30
|
function isWorkspaceError(value) {
|
|
18
31
|
const code = getViteHubErrorShape(value)?.code;
|
|
19
|
-
return code === "WORKSPACE_COLLECTION_CURSOR_INVALID" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
|
|
32
|
+
return code === "WORKSPACE_COLLECTION_CURSOR_INVALID" || code === "WORKSPACE_CONFLICT" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
|
|
33
|
+
}
|
|
34
|
+
function isWorkspaceConflict(value) {
|
|
35
|
+
return getViteHubErrorShape(value)?.code === "WORKSPACE_CONFLICT";
|
|
20
36
|
}
|
|
21
37
|
//#endregion
|
|
22
38
|
//#region src/core/path.ts
|
|
@@ -25,6 +41,7 @@ var path_exports = /* @__PURE__ */ __exportAll({
|
|
|
25
41
|
contentStreamToBytes: () => contentStreamToBytes,
|
|
26
42
|
contentToBytes: () => contentToBytes,
|
|
27
43
|
decodeFile: () => decodeFile,
|
|
44
|
+
isExcludedWorkspacePath: () => isExcludedWorkspacePath,
|
|
28
45
|
matchesAny: () => matchesAny,
|
|
29
46
|
normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
|
|
30
47
|
normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
|
|
@@ -35,13 +52,20 @@ var path_exports = /* @__PURE__ */ __exportAll({
|
|
|
35
52
|
function normalizeWorkspacePath(path = "") {
|
|
36
53
|
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
37
54
|
}
|
|
55
|
+
function isExcludedWorkspacePath(path, excluded = []) {
|
|
56
|
+
const normalized = normalizeWorkspacePath(path);
|
|
57
|
+
return excluded.some((item) => {
|
|
58
|
+
const excludedPath = normalizeWorkspacePath(item);
|
|
59
|
+
return excludedPath === "" || normalized === excludedPath || normalized.startsWith(`${excludedPath}/`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
38
62
|
function normalizeSafeWorkspacePath(path = "", options = {}) {
|
|
39
63
|
const raw = path.replace(/\\/g, "/");
|
|
40
64
|
const normalized = normalizeWorkspacePath(path);
|
|
41
65
|
const parts = normalized.split("/").filter(Boolean);
|
|
42
66
|
if (!options.allowEmpty && !normalized) throw workspacePathError(path);
|
|
43
67
|
if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw workspacePathError(path);
|
|
44
|
-
if (!options.allowReserved && (parts
|
|
68
|
+
if (!options.allowReserved && (parts.some((part) => part.toLowerCase() === ".git") || parts[0] === ".vitehub")) throw workspacePathError(path);
|
|
45
69
|
return normalized;
|
|
46
70
|
}
|
|
47
71
|
function normalizeSafeWorkspacePattern(pattern) {
|
|
@@ -112,4 +136,4 @@ async function sha256(input) {
|
|
|
112
136
|
return createHash("sha256").update(bytes).digest("hex");
|
|
113
137
|
}
|
|
114
138
|
//#endregion
|
|
115
|
-
export {
|
|
139
|
+
export { workspaceError as _, isExcludedWorkspacePath as a, normalizeSafeWorkspacePattern as c, resolveInside as d, sha256 as f, workspaceConflict as g, isWorkspaceError as h, decodeFile as i, normalizeWorkspacePath as l, isWorkspaceConflict as m, contentStreamToBytes as n, matchesAny as o, assertWorkspaceDigest as p, contentToBytes as r, normalizeSafeWorkspacePath as s, contentStreamChunks as t, path_exports as u, workspaceNotFoundError as v };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as createGitHubWorkspaceStore } from "./store-
|
|
1
|
+
import { _ as workspaceError, a as isExcludedWorkspacePath, d as resolveInside, f as sha256, l as normalizeWorkspacePath, o as matchesAny, p as assertWorkspaceDigest, r as contentToBytes, t as contentStreamChunks } from "./path-Cp59koVz.js";
|
|
2
|
+
import { t as createGitHubWorkspaceStore } from "./store-Dt_Jyys3.js";
|
|
3
|
+
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
4
|
import { resolve } from "node:path";
|
|
4
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
6
|
import { defu } from "defu";
|
|
6
7
|
import { createReadStream, createWriteStream } from "node:fs";
|
|
7
8
|
import { Readable, Transform } from "node:stream";
|
|
8
9
|
import { pipeline } from "node:stream/promises";
|
|
10
|
+
import { setTimeout } from "node:timers/promises";
|
|
9
11
|
//#region ../internal/src/env.ts
|
|
10
12
|
function trimmed(value) {
|
|
11
13
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
@@ -44,17 +46,102 @@ function getWorkspaceHostedStoreLoader() {
|
|
|
44
46
|
}
|
|
45
47
|
//#endregion
|
|
46
48
|
//#region src/storage/local.ts
|
|
47
|
-
async function
|
|
49
|
+
async function withFilesystemLock(lock, description, operation) {
|
|
50
|
+
const { mkdir, open, readFile, rename, rm, stat } = await import("node:fs/promises");
|
|
51
|
+
const { dirname } = await import("node:path");
|
|
52
|
+
const owner = randomUUID();
|
|
53
|
+
const ownerPath = `${lock}/owner`;
|
|
54
|
+
await mkdir(dirname(lock), { recursive: true });
|
|
55
|
+
const deadline = Date.now() + 1e4;
|
|
56
|
+
while (true) try {
|
|
57
|
+
await mkdir(lock);
|
|
58
|
+
const ownerFile = await open(ownerPath, "wx");
|
|
59
|
+
await ownerFile.writeFile(owner);
|
|
60
|
+
await ownerFile.close();
|
|
61
|
+
break;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (Reflect.get(Object(error), "code") !== "EEXIST") throw error;
|
|
64
|
+
const info = await stat(lock).catch(() => void 0);
|
|
65
|
+
if (info && Date.now() - info.mtimeMs > 3e5) {
|
|
66
|
+
const stale = `${lock}.stale-${randomUUID()}`;
|
|
67
|
+
if (await rename(lock, stale).then(() => true, (renameError) => {
|
|
68
|
+
if (renameError.code === "ENOENT") return false;
|
|
69
|
+
throw renameError;
|
|
70
|
+
})) await rm(stale, {
|
|
71
|
+
force: true,
|
|
72
|
+
recursive: true
|
|
73
|
+
});
|
|
74
|
+
} else if (Date.now() >= deadline) throw workspaceError(`[vitehub] Timed out waiting to write Workspace ${description}.`);
|
|
75
|
+
else await setTimeout(25);
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return await operation();
|
|
79
|
+
} finally {
|
|
80
|
+
if (await readFile(ownerPath, "utf8").catch(() => void 0) === owner) await rm(lock, {
|
|
81
|
+
force: true,
|
|
82
|
+
recursive: true
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function withFilesystemReadLock(lock, description, operation) {
|
|
87
|
+
const { mkdir, open, rm } = await import("node:fs/promises");
|
|
88
|
+
const reader = `${lock}.readers/${randomUUID()}`;
|
|
89
|
+
await withFilesystemLock(`${lock}.gate`, description, async () => {
|
|
90
|
+
await mkdir(`${lock}.readers`, { recursive: true });
|
|
91
|
+
await (await open(reader, "wx")).close();
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
return await operation();
|
|
95
|
+
} finally {
|
|
96
|
+
await rm(reader, { force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function withFilesystemWriteLock(lock, description, operation) {
|
|
100
|
+
const { readdir, rm, stat } = await import("node:fs/promises");
|
|
101
|
+
return await withFilesystemLock(`${lock}.gate`, description, async () => {
|
|
102
|
+
const readers = `${lock}.readers`;
|
|
103
|
+
const deadline = Date.now() + 1e4;
|
|
104
|
+
while (true) {
|
|
105
|
+
const active = await readdir(readers).catch((error) => {
|
|
106
|
+
if (error.code === "ENOENT") return [];
|
|
107
|
+
throw error;
|
|
108
|
+
});
|
|
109
|
+
if (active.length === 0) return await operation();
|
|
110
|
+
for (const owner of active) {
|
|
111
|
+
const path = `${readers}/${owner}`;
|
|
112
|
+
const info = await stat(path).catch(() => void 0);
|
|
113
|
+
if (info && Date.now() - info.mtimeMs > 3e5) await rm(path, { force: true });
|
|
114
|
+
}
|
|
115
|
+
if (Date.now() >= deadline) throw workspaceError(`[vitehub] Timed out waiting to write Workspace ${description}.`);
|
|
116
|
+
await setTimeout(25);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async function withWorkspacePathLock(root, path, operation) {
|
|
121
|
+
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
122
|
+
const paths = parts.map((_, index) => parts.slice(0, index + 1).join("/"));
|
|
123
|
+
const lock = async (index) => {
|
|
124
|
+
if (index === paths.length) return await operation();
|
|
125
|
+
const lockedPath = paths[index];
|
|
126
|
+
const lockPath = `${root}.vitehub-locks/${createHash("sha256").update(lockedPath).digest("hex")}`;
|
|
127
|
+
const next = () => lock(index + 1);
|
|
128
|
+
return index === paths.length - 1 ? await withFilesystemWriteLock(lockPath, `path: ${lockedPath}.`, next) : await withFilesystemReadLock(lockPath, `path: ${lockedPath}.`, next);
|
|
129
|
+
};
|
|
130
|
+
return await lock(0);
|
|
131
|
+
}
|
|
132
|
+
async function walk(root, current = root, excluded = [], recursive = true, includeDigest = false) {
|
|
48
133
|
const { readdir } = await import("node:fs/promises");
|
|
49
134
|
const { relative } = await import("node:path");
|
|
50
135
|
const entries = [];
|
|
51
136
|
const dirents = await readdir(current, { withFileTypes: true }).catch((error) => {
|
|
52
|
-
if (error.code === "ENOENT") return [];
|
|
137
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR") return [];
|
|
53
138
|
throw error;
|
|
54
139
|
});
|
|
55
140
|
for (const dirent of dirents) {
|
|
56
141
|
const absolute = `${current}/${dirent.name}`;
|
|
57
142
|
const path = normalizeWorkspacePath(relative(root, absolute));
|
|
143
|
+
if (path === ".vitehub" || path.startsWith(".vitehub/")) continue;
|
|
144
|
+
if (isExcludedWorkspacePath(path, excluded)) continue;
|
|
58
145
|
const { stat } = await import("node:fs/promises");
|
|
59
146
|
const info = await stat(absolute).catch((error) => {
|
|
60
147
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -67,16 +154,19 @@ async function walk(root, current = root) {
|
|
|
67
154
|
type: "directory",
|
|
68
155
|
mtime: info.mtimeMs
|
|
69
156
|
});
|
|
70
|
-
entries.push(...await walk(root, absolute));
|
|
157
|
+
if (recursive) entries.push(...await walk(root, absolute, excluded, true, includeDigest));
|
|
71
158
|
continue;
|
|
72
159
|
}
|
|
73
|
-
if (dirent.isFile())
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
160
|
+
if (dirent.isFile()) {
|
|
161
|
+
const entry = {
|
|
162
|
+
path,
|
|
163
|
+
type: "file",
|
|
164
|
+
size: info.size,
|
|
165
|
+
mtime: info.mtimeMs
|
|
166
|
+
};
|
|
167
|
+
if (includeDigest) entry.digest = await fileDigest(absolute);
|
|
168
|
+
entries.push(entry);
|
|
169
|
+
}
|
|
80
170
|
}
|
|
81
171
|
return entries;
|
|
82
172
|
}
|
|
@@ -117,9 +207,22 @@ var LocalWorkspaceStore = class {
|
|
|
117
207
|
};
|
|
118
208
|
}
|
|
119
209
|
async writeFile(path, file) {
|
|
210
|
+
await withWorkspacePathLock(this.root, path, () => this.#writeFile(path, file));
|
|
211
|
+
}
|
|
212
|
+
async writeFileConditional(path, file, ifDigest) {
|
|
213
|
+
await withWorkspacePathLock(this.root, path, async () => {
|
|
214
|
+
const normalized = normalizeWorkspacePath(path);
|
|
215
|
+
const current = await this.stat(normalized);
|
|
216
|
+
assertWorkspaceDigest(normalized, ifDigest, current?.type === "file" ? current.digest : void 0);
|
|
217
|
+
await this.#writeFile(normalized, file);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
async #writeFile(path, file) {
|
|
120
221
|
const { dirname } = await import("node:path");
|
|
121
|
-
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
222
|
+
const { mkdir, rename, rm, writeFile } = await import("node:fs/promises");
|
|
122
223
|
const absolute = resolveInside(this.root, path);
|
|
224
|
+
const tempRoot = `${this.root}/.vitehub/tmp`;
|
|
225
|
+
const temp = `${tempRoot}/${randomUUID()}.tmp`;
|
|
123
226
|
const normalized = normalizeWorkspacePath(path);
|
|
124
227
|
const bytes = contentToBytes(file.content);
|
|
125
228
|
const digest = await sha256(bytes);
|
|
@@ -131,22 +234,32 @@ var LocalWorkspaceStore = class {
|
|
|
131
234
|
});
|
|
132
235
|
return;
|
|
133
236
|
}
|
|
134
|
-
await mkdir(dirname(absolute), { recursive: true });
|
|
135
|
-
|
|
237
|
+
await Promise.all([mkdir(dirname(absolute), { recursive: true }), mkdir(tempRoot, { recursive: true })]);
|
|
238
|
+
try {
|
|
239
|
+
await writeFile(temp, bytes);
|
|
240
|
+
await rename(temp, absolute);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
await rm(temp, { force: true }).catch(() => void 0);
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
136
245
|
this.#files.set(normalized, {
|
|
137
246
|
mediaType: file.mediaType,
|
|
138
247
|
metadata: file.metadata
|
|
139
248
|
});
|
|
140
249
|
}
|
|
141
250
|
async writeFileStream(path, file) {
|
|
251
|
+
return await withWorkspacePathLock(this.root, path, () => this.#writeFileStream(path, file));
|
|
252
|
+
}
|
|
253
|
+
async #writeFileStream(path, file) {
|
|
142
254
|
const { dirname } = await import("node:path");
|
|
143
255
|
const { mkdir, rename, rm } = await import("node:fs/promises");
|
|
144
256
|
const normalized = normalizeWorkspacePath(path);
|
|
145
257
|
const absolute = resolveInside(this.root, path);
|
|
146
|
-
const
|
|
258
|
+
const tempRoot = `${this.root}/.vitehub/tmp`;
|
|
259
|
+
const temp = `${tempRoot}/${randomUUID()}.tmp`;
|
|
147
260
|
const hash = createHash("sha256");
|
|
148
261
|
let size = 0;
|
|
149
|
-
await mkdir(dirname(absolute), { recursive: true });
|
|
262
|
+
await Promise.all([mkdir(dirname(absolute), { recursive: true }), mkdir(tempRoot, { recursive: true })]);
|
|
150
263
|
try {
|
|
151
264
|
const hashing = new Transform({ transform(chunk, _encoding, callback) {
|
|
152
265
|
hash.update(chunk);
|
|
@@ -189,8 +302,12 @@ var LocalWorkspaceStore = class {
|
|
|
189
302
|
}
|
|
190
303
|
}
|
|
191
304
|
async list(prefix = "", options = {}) {
|
|
305
|
+
return await this.#list(prefix, options, false);
|
|
306
|
+
}
|
|
307
|
+
async #list(prefix, options, includeDigest) {
|
|
192
308
|
const normalizedPrefix = normalizeWorkspacePath(prefix);
|
|
193
|
-
|
|
309
|
+
const current = normalizedPrefix ? resolveInside(this.root, normalizedPrefix) : this.root;
|
|
310
|
+
return (await walk(this.root, current, options.exclude, options.recursive === true, includeDigest)).filter((entry) => {
|
|
194
311
|
if (!normalizedPrefix) return options.recursive || !entry.path.includes("/");
|
|
195
312
|
if (entry.path === normalizedPrefix) return false;
|
|
196
313
|
if (!entry.path.startsWith(`${normalizedPrefix}/`)) return false;
|
|
@@ -229,6 +346,9 @@ var LocalWorkspaceStore = class {
|
|
|
229
346
|
await mkdir(resolveInside(this.root, path), { recursive: options.recursive ?? true });
|
|
230
347
|
}
|
|
231
348
|
async rm(path, options = {}) {
|
|
349
|
+
await withWorkspacePathLock(this.root, path, () => this.#rm(path, options));
|
|
350
|
+
}
|
|
351
|
+
async #rm(path, options = {}) {
|
|
232
352
|
const { rm } = await import("node:fs/promises");
|
|
233
353
|
const normalized = normalizeWorkspacePath(path);
|
|
234
354
|
await rm(resolveInside(this.root, path), {
|
|
@@ -289,7 +409,7 @@ var LocalWorkspaceStore = class {
|
|
|
289
409
|
}
|
|
290
410
|
async #createSnapshot(name) {
|
|
291
411
|
const entries = {};
|
|
292
|
-
for (const entry of await this
|
|
412
|
+
for (const entry of await this.#list("", { recursive: true }, true)) entries[entry.path] = {
|
|
293
413
|
type: entry.type,
|
|
294
414
|
digest: entry.digest,
|
|
295
415
|
metadata: entry.metadata,
|
|
@@ -316,8 +436,8 @@ var LocalWorkspaceStore = class {
|
|
|
316
436
|
});
|
|
317
437
|
if (!content) return;
|
|
318
438
|
const value = JSON.parse(content);
|
|
319
|
-
if (!value ||
|
|
320
|
-
this.#meta = new Map(Object.entries(value));
|
|
439
|
+
if (!value || Object(value) !== value || Array.isArray(value)) return;
|
|
440
|
+
this.#meta = new Map(Object.entries(Object(value)));
|
|
321
441
|
}
|
|
322
442
|
async #writeMeta() {
|
|
323
443
|
const { dirname } = await import("node:path");
|
|
@@ -343,12 +463,16 @@ function now() {
|
|
|
343
463
|
return Date.now();
|
|
344
464
|
}
|
|
345
465
|
var MemoryWorkspaceStore = class {
|
|
466
|
+
[workspaceStoreTarget]() {
|
|
467
|
+
return { provider: "memory" };
|
|
468
|
+
}
|
|
346
469
|
#nodes = new Map([["", {
|
|
347
470
|
type: "directory",
|
|
348
471
|
mtime: now()
|
|
349
472
|
}]]);
|
|
350
473
|
#meta = /* @__PURE__ */ new Map();
|
|
351
474
|
#baseline;
|
|
475
|
+
#mutationQueue = Promise.resolve();
|
|
352
476
|
async readFile(path) {
|
|
353
477
|
const normalized = normalizeWorkspacePath(path);
|
|
354
478
|
const node = this.#nodes.get(normalized);
|
|
@@ -361,14 +485,14 @@ var MemoryWorkspaceStore = class {
|
|
|
361
485
|
};
|
|
362
486
|
}
|
|
363
487
|
async writeFile(path, file) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
488
|
+
await this.#mutate(() => this.#writeFile(path, file));
|
|
489
|
+
}
|
|
490
|
+
async writeFileConditional(path, file, ifDigest) {
|
|
491
|
+
await this.#mutate(async () => {
|
|
492
|
+
const normalized = normalizeWorkspacePath(path);
|
|
493
|
+
const current = this.#nodes.get(normalized);
|
|
494
|
+
assertWorkspaceDigest(normalized, ifDigest, current?.type === "file" ? (await this.#entry(normalized, current)).digest : void 0);
|
|
495
|
+
this.#writeFile(normalized, file);
|
|
372
496
|
});
|
|
373
497
|
}
|
|
374
498
|
async list(prefix = "", options = {}) {
|
|
@@ -376,6 +500,7 @@ var MemoryWorkspaceStore = class {
|
|
|
376
500
|
const result = [];
|
|
377
501
|
for (const [path, node] of this.#nodes) {
|
|
378
502
|
if (!path || path === normalizedPrefix) continue;
|
|
503
|
+
if (isExcludedWorkspacePath(path, options.exclude)) continue;
|
|
379
504
|
if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
|
|
380
505
|
if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
381
506
|
result.push(await this.#entry(path, node));
|
|
@@ -393,24 +518,28 @@ var MemoryWorkspaceStore = class {
|
|
|
393
518
|
return node ? await this.#entry(normalized, node) : void 0;
|
|
394
519
|
}
|
|
395
520
|
async mkdir(path, _options = {}) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
521
|
+
await this.#mutate(() => {
|
|
522
|
+
const normalized = normalizeWorkspacePath(path);
|
|
523
|
+
this.#ensureParents(normalized);
|
|
524
|
+
this.#nodes.set(normalized, {
|
|
525
|
+
type: "directory",
|
|
526
|
+
mtime: now()
|
|
527
|
+
});
|
|
401
528
|
});
|
|
402
529
|
}
|
|
403
530
|
async rm(path, options = {}) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
531
|
+
await this.#mutate(() => {
|
|
532
|
+
const normalized = normalizeWorkspacePath(path);
|
|
533
|
+
const node = this.#nodes.get(normalized);
|
|
534
|
+
if (!node) {
|
|
535
|
+
if (options.force) return;
|
|
536
|
+
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
537
|
+
}
|
|
538
|
+
if (node.type === "directory" && !options.recursive) {
|
|
539
|
+
for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
|
|
540
|
+
}
|
|
541
|
+
for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
|
|
542
|
+
});
|
|
414
543
|
}
|
|
415
544
|
async snapshot(options = {}) {
|
|
416
545
|
const snapshot = await this.#createSnapshot(options.name);
|
|
@@ -454,6 +583,22 @@ var MemoryWorkspaceStore = class {
|
|
|
454
583
|
async setMeta(key, value) {
|
|
455
584
|
this.#meta.set(key, value);
|
|
456
585
|
}
|
|
586
|
+
#writeFile(path, file) {
|
|
587
|
+
const normalized = normalizeWorkspacePath(path);
|
|
588
|
+
this.#ensureParents(normalized);
|
|
589
|
+
this.#nodes.set(normalized, {
|
|
590
|
+
type: "file",
|
|
591
|
+
content: file.content,
|
|
592
|
+
mediaType: file.mediaType,
|
|
593
|
+
metadata: file.metadata,
|
|
594
|
+
mtime: now()
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
#mutate(operation) {
|
|
598
|
+
const result = this.#mutationQueue.then(operation);
|
|
599
|
+
this.#mutationQueue = result.then(() => void 0, () => void 0);
|
|
600
|
+
return result;
|
|
601
|
+
}
|
|
457
602
|
#ensureParents(path) {
|
|
458
603
|
const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
459
604
|
for (let index = 1; index < parts.length; index++) {
|
|
@@ -537,12 +682,14 @@ function resolveVercelBlobWorkspaceStore(config = {}, env = process.env) {
|
|
|
537
682
|
};
|
|
538
683
|
}
|
|
539
684
|
function resolveGitHubWorkspaceStore(config = {}, env = process.env, input = {}) {
|
|
685
|
+
const branch = gitHubWorkspaceOption(config.branch) ?? readEnv(env, "WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH");
|
|
686
|
+
const root = gitHubWorkspaceOption(config.root) ?? readEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT");
|
|
540
687
|
return {
|
|
541
|
-
branch:
|
|
688
|
+
branch: branch ?? (input.runtime ? void 0 : "main"),
|
|
542
689
|
provider: "github",
|
|
543
690
|
repository: gitHubWorkspaceOption(config.repository) ?? gitHubWorkspaceOption(config.repo) ?? readEnv(env, "WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY"),
|
|
544
|
-
root:
|
|
545
|
-
token: input.runtime ? gitHubWorkspaceOption(config.token) ?? "********" : MASKED_WORKSPACE_RUNTIME_VALUE
|
|
691
|
+
root: root ?? (input.runtime ? void 0 : ".vitehub/workspaces/<workspace>"),
|
|
692
|
+
token: input.runtime ? gitHubWorkspaceOption(config.token) ?? readEnv(env, "WORKSPACE_GITHUB_TOKEN", "VITEHUB_WORKSPACE_GITHUB_TOKEN", "GITHUB_TOKEN", "GH_TOKEN") ?? "********" : MASKED_WORKSPACE_RUNTIME_VALUE
|
|
546
693
|
};
|
|
547
694
|
}
|
|
548
695
|
function hasVercelWorkspaceBlobEnv(env) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $t as WorkspaceStore, o as GitHubWorkspaceStoreOptions } from "../../types-CYuwjJ4V.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/github/store.d.ts
|
|
4
4
|
declare function createGitHubWorkspaceStore(options: GitHubWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createGitHubWorkspaceStore } from "../../store-
|
|
1
|
+
import { t as createGitHubWorkspaceStore } from "../../store-Dt_Jyys3.js";
|
|
2
2
|
export { createGitHubWorkspaceStore };
|
package/dist/publish.d.ts
CHANGED
package/dist/publish.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as workspaceError, l as normalizeWorkspacePath } from "./path-Cp59koVz.js";
|
|
2
2
|
import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
-
import { a as isWorkspaceFileEntry, d as
|
|
3
|
+
import { a as isWorkspaceFileEntry, d as requireGitHubOption, f as resolveGitHubBranchOption, g as resolveGitHubTokenOption, h as resolveGitHubRootOption, l as readGitHubBranchState, m as resolveGitHubRepositoryOption, p as resolveGitHubOption, r as createGitHubFileUpdate, t as commitGitHubChanges } from "./shared-DTR1Hhma.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
|