@vite-hub/workspace 0.0.4 → 0.3.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 +339 -115
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/blob-database.d.ts +474 -0
- package/dist/blob-database.js +608 -0
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +6 -7
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/config-BAgL2dtB.js +1076 -0
- package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
- package/dist/glob-B8YGvTrZ.js +21 -0
- package/dist/glob-Cjxms1t7.js +30 -0
- package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
- package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +6 -7
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +10 -9
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +26 -47
- package/dist/index.js +30 -100
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-B-enk_4A.js +596 -0
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-DF0F5rcL.js +39 -0
- package/dist/memory-BOexthyW.js +247 -0
- package/dist/metadata-target-CWz6KHKq.js +1589 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +90 -0
- package/dist/operations.js +3 -0
- package/dist/path--wrT_Azm.js +113 -0
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-C8C0auoW.d.ts +10 -0
- package/dist/provider-9s4Ufkm5.js +1479 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +52 -17
- package/dist/runtime.js +324 -67
- package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
- package/dist/server-8tGltlGz.js +303 -0
- package/dist/server.d.ts +36 -39
- package/dist/server.js +2 -328
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +10 -7
- package/dist/source-metadata.js +12 -12
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
- package/dist/store-ybhyD38Z.js +1873 -0
- package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
- package/dist/utils-CgMZCHsX.js +616 -0
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21369 -2
- package/dist/workspace-CYB2xZ1T.d.ts +7 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
- package/package.json +97 -72
- package/dist/ai-CjxvGqM0.d.ts +0 -162
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/mountx.d.ts +0 -10
- package/dist/mountx.js +0 -143
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -26
- package/dist/nuxt.js +0 -42
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-Uj6IVxes.d.ts +0 -11
- package/dist/request-execution-B-dSFlGB.js +0 -84
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/state-tYcRWEh2.d.ts +0 -26
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/token-CVzURBxC.js +0 -61
- package/dist/use-BiHzt0xA.d.ts +0 -103
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
- package/dist/workspace-Xddf4G1B.d.ts +0 -6
package/dist/mountx.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { _t as WorkspaceSession } from "./types-CYuwjJ4V.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
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
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.d.ts
DELETED
package/dist/nitro.js
DELETED
package/dist/nuxt.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { rt as WorkspaceModuleOptions } from "./types-CYuwjJ4V.js";
|
|
2
|
-
|
|
3
|
-
//#region src/nuxt.d.ts
|
|
4
|
-
interface WorkspaceNuxtModuleOptions extends WorkspaceModuleOptions {}
|
|
5
|
-
type NuxtLike = {
|
|
6
|
-
hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
|
|
7
|
-
options: {
|
|
8
|
-
alias?: Record<string, string>;
|
|
9
|
-
dev?: boolean;
|
|
10
|
-
imports?: {
|
|
11
|
-
imports?: Array<{
|
|
12
|
-
from: string;
|
|
13
|
-
name: string;
|
|
14
|
-
}>;
|
|
15
|
-
};
|
|
16
|
-
rootDir?: string;
|
|
17
|
-
srcDir?: string;
|
|
18
|
-
vite?: {
|
|
19
|
-
plugins?: unknown[];
|
|
20
|
-
workspace?: false | WorkspaceModuleOptions;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
declare function viteHubWorkspaceNuxtModule(options?: WorkspaceNuxtModuleOptions, nuxt?: NuxtLike): void;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { WorkspaceNuxtModuleOptions, viteHubWorkspaceNuxtModule as default };
|
package/dist/nuxt.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { n as hubWorkspace, r as setWorkspaceVitePluginHosting, t as createWorkspaceNitroConfig } from "./vite-BptCrpv2.js";
|
|
2
|
-
//#region src/nuxt.ts
|
|
3
|
-
function isWorkspaceVitePlugin(value) {
|
|
4
|
-
return Boolean(value && typeof value === "object" && value.name === "@vite-hub/workspace/vite");
|
|
5
|
-
}
|
|
6
|
-
function resolveWorkspaceOptions(options, viteOptions) {
|
|
7
|
-
if (viteOptions !== void 0) return viteOptions;
|
|
8
|
-
return Object.keys(options).length > 0 ? options : void 0;
|
|
9
|
-
}
|
|
10
|
-
function viteHubWorkspaceNuxtModule(options = {}, nuxt) {
|
|
11
|
-
if (!nuxt) return;
|
|
12
|
-
nuxt.options.imports ??= {};
|
|
13
|
-
nuxt.options.imports.imports ??= [];
|
|
14
|
-
for (const name of ["useWorkspaceCollection", "useWorkspaceCollectionItem"]) if (!nuxt.options.imports.imports.some((entry) => entry.name === name)) nuxt.options.imports.imports.push({
|
|
15
|
-
from: "@vite-hub/workspace/collections/client",
|
|
16
|
-
name
|
|
17
|
-
});
|
|
18
|
-
nuxt.options.vite ??= {};
|
|
19
|
-
const workspaceOptions = resolveWorkspaceOptions(options, nuxt.options.vite.workspace);
|
|
20
|
-
let resolvedNitroHosting;
|
|
21
|
-
const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
|
|
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);
|
|
27
|
-
nuxt.options.vite.plugins = plugins;
|
|
28
|
-
nuxt.hook?.("nitro:config", async (nitroConfig) => {
|
|
29
|
-
resolvedNitroHosting = typeof nitroConfig.preset === "string" ? nitroConfig.preset : void 0;
|
|
30
|
-
const rootDir = nuxt.options.rootDir || process.cwd();
|
|
31
|
-
const nitro = await createWorkspaceNitroConfig({
|
|
32
|
-
aliases: nuxt.options.alias,
|
|
33
|
-
command: nuxt.options.dev ? "serve" : "build",
|
|
34
|
-
nitro: nitroConfig,
|
|
35
|
-
viteRoot: nuxt.options.srcDir || rootDir,
|
|
36
|
-
workspace: workspaceOptions
|
|
37
|
-
});
|
|
38
|
-
if (nitro) Object.assign(nitroConfig, nitro);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { viteHubWorkspaceNuxtModule as default };
|
package/dist/path-Cp59koVz.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { n as __exportAll } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { relative, resolve, sep } from "node:path";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { minimatch } from "minimatch";
|
|
5
|
-
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
6
|
-
//#region src/core/errors.ts
|
|
7
|
-
function workspaceError(message, options) {
|
|
8
|
-
return new ViteHubError("WORKSPACE_FAILED", message, options);
|
|
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
|
-
}
|
|
23
|
-
function workspaceNotFoundError(name) {
|
|
24
|
-
return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
|
|
25
|
-
}
|
|
26
|
-
function workspacePathError(path) {
|
|
27
|
-
const publicPath = path.slice(0, 4096);
|
|
28
|
-
return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
29
|
-
}
|
|
30
|
-
function isWorkspaceError(value) {
|
|
31
|
-
const code = getViteHubErrorShape(value)?.code;
|
|
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";
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/core/path.ts
|
|
39
|
-
var path_exports = /* @__PURE__ */ __exportAll({
|
|
40
|
-
contentStreamChunks: () => contentStreamChunks,
|
|
41
|
-
contentStreamToBytes: () => contentStreamToBytes,
|
|
42
|
-
contentToBytes: () => contentToBytes,
|
|
43
|
-
decodeFile: () => decodeFile,
|
|
44
|
-
isExcludedWorkspacePath: () => isExcludedWorkspacePath,
|
|
45
|
-
matchesAny: () => matchesAny,
|
|
46
|
-
normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
|
|
47
|
-
normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
|
|
48
|
-
normalizeWorkspacePath: () => normalizeWorkspacePath,
|
|
49
|
-
resolveInside: () => resolveInside,
|
|
50
|
-
sha256: () => sha256
|
|
51
|
-
});
|
|
52
|
-
function normalizeWorkspacePath(path = "") {
|
|
53
|
-
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
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
|
-
}
|
|
62
|
-
function normalizeSafeWorkspacePath(path = "", options = {}) {
|
|
63
|
-
const raw = path.replace(/\\/g, "/");
|
|
64
|
-
const normalized = normalizeWorkspacePath(path);
|
|
65
|
-
const parts = normalized.split("/").filter(Boolean);
|
|
66
|
-
if (!options.allowEmpty && !normalized) throw workspacePathError(path);
|
|
67
|
-
if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw workspacePathError(path);
|
|
68
|
-
if (!options.allowReserved && (parts.some((part) => part.toLowerCase() === ".git") || parts[0] === ".vitehub")) throw workspacePathError(path);
|
|
69
|
-
return normalized;
|
|
70
|
-
}
|
|
71
|
-
function normalizeSafeWorkspacePattern(pattern) {
|
|
72
|
-
return normalizeSafeWorkspacePath(pattern, {
|
|
73
|
-
allowEmpty: true,
|
|
74
|
-
pattern: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function resolveInside(root, path = "") {
|
|
78
|
-
const resolvedRoot = resolve(root);
|
|
79
|
-
const resolved = resolve(resolvedRoot, normalizeWorkspacePath(path));
|
|
80
|
-
const rel = relative(resolvedRoot, resolved);
|
|
81
|
-
if (rel.startsWith("..") || rel === ".." || rel.includes(`..${sep}`) || rel === "") {
|
|
82
|
-
if (rel === "") return resolved;
|
|
83
|
-
throw workspacePathError(path);
|
|
84
|
-
}
|
|
85
|
-
return resolved;
|
|
86
|
-
}
|
|
87
|
-
function matchesAny(path, patterns) {
|
|
88
|
-
if (!patterns) return true;
|
|
89
|
-
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
90
|
-
const normalizedPath = normalizeWorkspacePath(path);
|
|
91
|
-
return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
|
|
92
|
-
}
|
|
93
|
-
function contentToBytes(content) {
|
|
94
|
-
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
95
|
-
}
|
|
96
|
-
function isReadableStream(value) {
|
|
97
|
-
return Boolean(value && typeof value.getReader === "function");
|
|
98
|
-
}
|
|
99
|
-
async function* contentStreamChunks(stream) {
|
|
100
|
-
if (isReadableStream(stream)) {
|
|
101
|
-
const reader = stream.getReader();
|
|
102
|
-
try {
|
|
103
|
-
while (true) {
|
|
104
|
-
const chunk = await reader.read();
|
|
105
|
-
if (chunk.done) return;
|
|
106
|
-
yield chunk.value;
|
|
107
|
-
}
|
|
108
|
-
} finally {
|
|
109
|
-
reader.releaseLock();
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
yield* stream;
|
|
114
|
-
}
|
|
115
|
-
async function contentStreamToBytes(stream) {
|
|
116
|
-
const chunks = [];
|
|
117
|
-
let size = 0;
|
|
118
|
-
for await (const chunk of contentStreamChunks(stream)) {
|
|
119
|
-
chunks.push(chunk);
|
|
120
|
-
size += chunk.byteLength;
|
|
121
|
-
}
|
|
122
|
-
const bytes = new Uint8Array(size);
|
|
123
|
-
let offset = 0;
|
|
124
|
-
for (const chunk of chunks) {
|
|
125
|
-
bytes.set(chunk, offset);
|
|
126
|
-
offset += chunk.byteLength;
|
|
127
|
-
}
|
|
128
|
-
return bytes;
|
|
129
|
-
}
|
|
130
|
-
function decodeFile(content, options) {
|
|
131
|
-
if (options?.encoding === "binary") return content;
|
|
132
|
-
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
133
|
-
}
|
|
134
|
-
async function sha256(input) {
|
|
135
|
-
const bytes = contentToBytes(typeof input === "string" || input instanceof Uint8Array ? input : JSON.stringify(input));
|
|
136
|
-
return createHash("sha256").update(bytes).digest("hex");
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
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 };
|