@vite-hub/workspace 0.0.1 → 0.0.2
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 +190 -17
- package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +137 -102
- package/dist/index.js +479 -594
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/nitro.d.ts +2 -31
- package/dist/nitro.js +2 -2
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
- package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
- package/dist/providers/cloudflare/artifacts-store.js +1 -383
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +1 -1
- package/dist/providers/vercel/blob-store.js +77 -18
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +2 -1
- package/dist/runtime/assets.js +5 -5
- 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 -21
- package/dist/runtime/state.js +7 -4
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +158 -62
- package/dist/asset-registry-CMuQbyvl.js +0 -14
- package/dist/cloudflare-env-DL94Uvpz.js +0 -12
- package/dist/config-CvS-7sre.js +0 -49
- package/dist/errors-BUL8SoFS.js +0 -21
- package/dist/lifecycle-uD82JeGh.js +0 -92
- package/dist/module-8LZUMEXC.js +0 -922
- package/dist/path-BVv9OXhg.js +0 -63
- package/dist/registry-Cnr0NoKv.js +0 -932
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- package/dist/sandbox-DtGXCWRq.js +0 -198
- package/dist/types-CwNcWTdt.d.ts +0 -378
- /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
+
import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
|
|
3
|
+
import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config--r5unwPc.js";
|
|
4
|
+
import { t as createCurrentSnapshotFromStore } from "./utils-BPdaCyI6.js";
|
|
5
|
+
import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
|
|
6
|
+
import { t as files } from "./files-xy0le-_U.js";
|
|
7
|
+
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
8
|
+
//#region src/lifecycle.ts
|
|
9
|
+
var lifecycle_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
publishWorkspace: () => publishWorkspace,
|
|
11
|
+
publishWorkspaceSnapshot: () => publishWorkspaceSnapshot,
|
|
12
|
+
syncWorkspaceDefinition: () => syncWorkspaceDefinition
|
|
13
|
+
});
|
|
14
|
+
const buildSourcesMetaKey = "workspace:build-sources";
|
|
15
|
+
async function publishWorkspace(definition, store, options = {}) {
|
|
16
|
+
if (!definition.publish?.length) return;
|
|
17
|
+
await publishWorkspaceSnapshot(definition, store, await createCurrentSnapshotFromStore(store, options.name), false);
|
|
18
|
+
}
|
|
19
|
+
async function publishWorkspaceSnapshot(definition, store, snapshot, durable = true) {
|
|
20
|
+
for (const publisher of definition.publish || []) await publisher.publish({
|
|
21
|
+
durable,
|
|
22
|
+
workspace: definition,
|
|
23
|
+
store,
|
|
24
|
+
rootDir: definition.rootDir || process.cwd(),
|
|
25
|
+
snapshot
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function syncWorkspaceDefinition(definition, store) {
|
|
29
|
+
const loaders = definition.loaders?.length ? definition.loaders : [files()];
|
|
30
|
+
const hasExplicitLoaders = !!definition.loaders?.length;
|
|
31
|
+
const ctxSource = createSourceContext(definition, void 0, store);
|
|
32
|
+
const buildSources = normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "build");
|
|
33
|
+
const hasBuildSourceState = await reconcileBuildSourceMounts(store, buildSources);
|
|
34
|
+
const bundledBuildSources = !hasExplicitLoaders ? await syncRuntimeBuildAssets(definition, store, buildSources) : void 0;
|
|
35
|
+
if (bundledBuildSources && buildSources.every((source) => bundledBuildSources.has(source.key))) {
|
|
36
|
+
await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!hasBuildSourceState && !hasExplicitLoaders) return;
|
|
40
|
+
const normalizedSources = buildSources.filter((source) => !bundledBuildSources?.has(source.key)).map((source) => createMountedBuildSource(source));
|
|
41
|
+
const ctx = {
|
|
42
|
+
workspace: definition.name,
|
|
43
|
+
rootDir: ctxSource.rootDir,
|
|
44
|
+
sourceRootDir: ctxSource.sourceRootDir,
|
|
45
|
+
sources: normalizedSources,
|
|
46
|
+
store,
|
|
47
|
+
parseData: async (input) => input.data,
|
|
48
|
+
generateDigest: (input) => JSON.stringify(input),
|
|
49
|
+
logger: console
|
|
50
|
+
};
|
|
51
|
+
for (const loader of loaders) await loader.load(ctx);
|
|
52
|
+
await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
|
|
53
|
+
}
|
|
54
|
+
async function reconcileBuildSourceMounts(store, currentSources) {
|
|
55
|
+
const previousSources = await readSyncedBuildSources(store);
|
|
56
|
+
const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
|
|
57
|
+
const resetPaths = [...new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
|
|
58
|
+
for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) await store.rm(mountPath, {
|
|
59
|
+
recursive: true,
|
|
60
|
+
force: true
|
|
61
|
+
});
|
|
62
|
+
for (const source of [...previousSources, ...currentSources].filter((source) => !source.mountPath)) await removeRootBuildSourceFiles(store, source);
|
|
63
|
+
for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) await store.mkdir(mountPath, { recursive: true });
|
|
64
|
+
await store.setMeta?.(buildSourcesMetaKey, currentSources.map(({ key, mountPath }) => ({
|
|
65
|
+
key,
|
|
66
|
+
mountPath
|
|
67
|
+
})));
|
|
68
|
+
return hasBuildSourceState;
|
|
69
|
+
}
|
|
70
|
+
async function syncRuntimeBuildAssets(definition, store, currentSources) {
|
|
71
|
+
if (!currentSources.length) return void 0;
|
|
72
|
+
let assets;
|
|
73
|
+
try {
|
|
74
|
+
assets = useWorkspaceAssets(definition.name);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
const files = (await assets.list("", { recursive: true })).filter((entry) => entry.type === "file");
|
|
80
|
+
const bundledPaths = new Set(files.map((entry) => entry.path));
|
|
81
|
+
const bundledSourceByPath = /* @__PURE__ */ new Map();
|
|
82
|
+
const bundledBuildSources = /* @__PURE__ */ new Set();
|
|
83
|
+
for (const source of currentSources) if (await hasCompleteBundledBuildSource(definition, store, source, bundledPaths, files, bundledSourceByPath)) bundledBuildSources.add(source.key);
|
|
84
|
+
for (const entry of files) {
|
|
85
|
+
const sourceKey = typeof entry.metadata?.source === "string" ? entry.metadata.source : bundledSourceByPath.get(entry.path) || findBuildSourceForPath(entry.path, currentSources)?.key;
|
|
86
|
+
await store.writeFile(entry.path, {
|
|
87
|
+
path: entry.path,
|
|
88
|
+
content: await assets.readFile(entry.path, { encoding: "binary" }),
|
|
89
|
+
mediaType: entry.mediaType,
|
|
90
|
+
metadata: sourceKey ? {
|
|
91
|
+
...entry.metadata,
|
|
92
|
+
source: sourceKey
|
|
93
|
+
} : entry.metadata
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return bundledBuildSources;
|
|
97
|
+
}
|
|
98
|
+
async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath) {
|
|
99
|
+
const probeKeys = source.source.probeKeys;
|
|
100
|
+
if (!probeKeys?.length) {
|
|
101
|
+
const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
|
|
102
|
+
const sourcePaths = await tryListBuildSourcePaths(definition, store, source);
|
|
103
|
+
if (sourcePaths && !sourcePaths.every((path) => paths.includes(path))) return false;
|
|
104
|
+
for (const path of paths) bundledSourceByPath?.set(path, source.key);
|
|
105
|
+
return paths.length > 0;
|
|
106
|
+
}
|
|
107
|
+
const paths = probeKeys.map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
|
|
108
|
+
if (!paths.every((path) => bundledPaths.has(path))) return false;
|
|
109
|
+
for (const path of paths) bundledSourceByPath?.set(path, source.key);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
async function tryListBuildSourcePaths(definition, store, source) {
|
|
113
|
+
const ctx = createSourceContext(definition, {
|
|
114
|
+
key: source.key,
|
|
115
|
+
mountPath: source.mountPath
|
|
116
|
+
}, store);
|
|
117
|
+
try {
|
|
118
|
+
await source.source.prepare?.(ctx);
|
|
119
|
+
return (await source.source.getKeys(ctx)).map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
|
|
120
|
+
} catch {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function findBuildSourceForPath(path, sources) {
|
|
125
|
+
const matches = sources.filter((source) => !source.mountPath || path === source.mountPath || path.startsWith(`${source.mountPath}/`)).sort((left, right) => right.mountPath.length - left.mountPath.length)[0];
|
|
126
|
+
if (!matches?.mountPath && sources.filter((source) => !source.mountPath).length > 1) return void 0;
|
|
127
|
+
return matches;
|
|
128
|
+
}
|
|
129
|
+
async function readSyncedBuildSources(store) {
|
|
130
|
+
const value = await store.getMeta?.(buildSourcesMetaKey);
|
|
131
|
+
if (!Array.isArray(value)) return [];
|
|
132
|
+
return value.filter(isSyncedBuildSource);
|
|
133
|
+
}
|
|
134
|
+
async function removeRootBuildSourceFiles(store, source) {
|
|
135
|
+
const entries = await store.list("", { recursive: true });
|
|
136
|
+
await Promise.all(entries.map(async (entry) => {
|
|
137
|
+
if (entry.type !== "file") return;
|
|
138
|
+
if ((await store.readFile(entry.path))?.metadata?.source === source.key) await store.rm(entry.path, { force: true });
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
function isSyncedBuildSource(value) {
|
|
142
|
+
return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
|
|
143
|
+
}
|
|
144
|
+
function createMountedBuildSource(source) {
|
|
145
|
+
function getSourceContext(ctx) {
|
|
146
|
+
return {
|
|
147
|
+
...ctx,
|
|
148
|
+
mountPath: source.mountPath,
|
|
149
|
+
source: source.key
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...source.source,
|
|
154
|
+
key: source.key,
|
|
155
|
+
async prepare(ctx) {
|
|
156
|
+
await source.source.prepare?.(getSourceContext(ctx));
|
|
157
|
+
},
|
|
158
|
+
async getKeys(ctx) {
|
|
159
|
+
return await source.source.getKeys(getSourceContext(ctx));
|
|
160
|
+
},
|
|
161
|
+
async getItem(key, ctx) {
|
|
162
|
+
const item = await source.source.getItem(key, getSourceContext(ctx));
|
|
163
|
+
const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
|
|
164
|
+
return {
|
|
165
|
+
...item,
|
|
166
|
+
path,
|
|
167
|
+
metadata: {
|
|
168
|
+
...item.metadata,
|
|
169
|
+
source: source.key
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { syncWorkspaceDefinition as n, lifecycle_exports as t };
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ot as WorkspaceSourceItem, Y as WorkspaceLoader, j as WorkspaceContent } from "./types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/loaders/files.d.ts
|
|
4
4
|
interface FilesLoaderOptions {
|
package/dist/loader.js
CHANGED
package/dist/nitro.d.ts
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/hosts/nitro/module.d.ts
|
|
4
|
-
interface WorkspaceNitroModule {
|
|
5
|
-
name: string;
|
|
6
|
-
setup(this: void, nitro: unknown): void | Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
declare function workspaceNitro(options?: false | WorkspaceModuleOptions): WorkspaceNitroModule;
|
|
9
|
-
declare const workspaceNitroModule: WorkspaceNitroModule;
|
|
10
|
-
declare module "nitro/types" {
|
|
11
|
-
interface NitroConfig {
|
|
12
|
-
workspace?: false | WorkspaceModuleOptions;
|
|
13
|
-
}
|
|
14
|
-
interface NitroOptions {
|
|
15
|
-
workspace?: false | WorkspaceModuleOptions;
|
|
16
|
-
cloudflare?: {
|
|
17
|
-
wrangler?: {
|
|
18
|
-
artifacts?: Array<{
|
|
19
|
-
binding: string;
|
|
20
|
-
namespace: string;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface NitroRuntimeConfig {
|
|
26
|
-
hosting?: string;
|
|
27
|
-
workspace?: false | ResolvedWorkspaceModuleOptions;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { WorkspaceNitroModule, workspaceNitroModule as default, workspaceNitro };
|
|
1
|
+
import { NitroConfig, WorkspaceNitroConfigOptions, createWorkspaceNitroConfig } from "./vite.js";
|
|
2
|
+
export { type NitroConfig, type WorkspaceNitroConfigOptions, createWorkspaceNitroConfig };
|
package/dist/nitro.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { t as createWorkspaceNitroConfig } from "./vite-NWC9mFjI.js";
|
|
2
|
+
export { createWorkspaceNitroConfig };
|
package/dist/nuxt.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { nt as WorkspaceModuleOptions } from "./types-DHkae7Cb.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
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { n as hubWorkspace, t as createWorkspaceNitroConfig } from "./vite-NWC9mFjI.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
|
+
const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
|
|
21
|
+
if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace(workspaceOptions === false ? void 0 : workspaceOptions));
|
|
22
|
+
nuxt.options.vite.plugins = plugins;
|
|
23
|
+
nuxt.hook?.("nitro:config", async (nitroConfig) => {
|
|
24
|
+
const rootDir = nuxt.options.rootDir || process.cwd();
|
|
25
|
+
const nitro = await createWorkspaceNitroConfig({
|
|
26
|
+
aliases: nuxt.options.alias,
|
|
27
|
+
command: nuxt.options.dev ? "serve" : "build",
|
|
28
|
+
nitro: nitroConfig,
|
|
29
|
+
viteRoot: nuxt.options.srcDir || rootDir,
|
|
30
|
+
workspace: workspaceOptions
|
|
31
|
+
});
|
|
32
|
+
if (nitro) Object.assign(nitroConfig, nitro);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { viteHubWorkspaceNuxtModule as default };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-8H4AJuhK.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 workspaceNotFoundError(name) {
|
|
11
|
+
return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
|
|
12
|
+
}
|
|
13
|
+
function workspacePathError(path) {
|
|
14
|
+
const publicPath = path.slice(0, 4096);
|
|
15
|
+
return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
16
|
+
}
|
|
17
|
+
function isWorkspaceError(value) {
|
|
18
|
+
const code = getViteHubErrorShape(value)?.code;
|
|
19
|
+
return code === "WORKSPACE_COLLECTION_CURSOR_INVALID" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/path.ts
|
|
23
|
+
var path_exports = /* @__PURE__ */ __exportAll({
|
|
24
|
+
contentStreamChunks: () => contentStreamChunks,
|
|
25
|
+
contentStreamToBytes: () => contentStreamToBytes,
|
|
26
|
+
contentToBytes: () => contentToBytes,
|
|
27
|
+
decodeFile: () => decodeFile,
|
|
28
|
+
matchesAny: () => matchesAny,
|
|
29
|
+
normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
|
|
30
|
+
normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
|
|
31
|
+
normalizeWorkspacePath: () => normalizeWorkspacePath,
|
|
32
|
+
resolveInside: () => resolveInside,
|
|
33
|
+
sha256: () => sha256
|
|
34
|
+
});
|
|
35
|
+
function normalizeWorkspacePath(path = "") {
|
|
36
|
+
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
37
|
+
}
|
|
38
|
+
function normalizeSafeWorkspacePath(path = "", options = {}) {
|
|
39
|
+
const raw = path.replace(/\\/g, "/");
|
|
40
|
+
const normalized = normalizeWorkspacePath(path);
|
|
41
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
42
|
+
if (!options.allowEmpty && !normalized) throw workspacePathError(path);
|
|
43
|
+
if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw workspacePathError(path);
|
|
44
|
+
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw workspacePathError(path);
|
|
45
|
+
return normalized;
|
|
46
|
+
}
|
|
47
|
+
function normalizeSafeWorkspacePattern(pattern) {
|
|
48
|
+
return normalizeSafeWorkspacePath(pattern, {
|
|
49
|
+
allowEmpty: true,
|
|
50
|
+
pattern: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function resolveInside(root, path = "") {
|
|
54
|
+
const resolvedRoot = resolve(root);
|
|
55
|
+
const resolved = resolve(resolvedRoot, normalizeWorkspacePath(path));
|
|
56
|
+
const rel = relative(resolvedRoot, resolved);
|
|
57
|
+
if (rel.startsWith("..") || rel === ".." || rel.includes(`..${sep}`) || rel === "") {
|
|
58
|
+
if (rel === "") return resolved;
|
|
59
|
+
throw workspacePathError(path);
|
|
60
|
+
}
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
63
|
+
function matchesAny(path, patterns) {
|
|
64
|
+
if (!patterns) return true;
|
|
65
|
+
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
66
|
+
const normalizedPath = normalizeWorkspacePath(path);
|
|
67
|
+
return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
|
|
68
|
+
}
|
|
69
|
+
function contentToBytes(content) {
|
|
70
|
+
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
71
|
+
}
|
|
72
|
+
function isReadableStream(value) {
|
|
73
|
+
return Boolean(value && typeof value.getReader === "function");
|
|
74
|
+
}
|
|
75
|
+
async function* contentStreamChunks(stream) {
|
|
76
|
+
if (isReadableStream(stream)) {
|
|
77
|
+
const reader = stream.getReader();
|
|
78
|
+
try {
|
|
79
|
+
while (true) {
|
|
80
|
+
const chunk = await reader.read();
|
|
81
|
+
if (chunk.done) return;
|
|
82
|
+
yield chunk.value;
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
reader.releaseLock();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
yield* stream;
|
|
90
|
+
}
|
|
91
|
+
async function contentStreamToBytes(stream) {
|
|
92
|
+
const chunks = [];
|
|
93
|
+
let size = 0;
|
|
94
|
+
for await (const chunk of contentStreamChunks(stream)) {
|
|
95
|
+
chunks.push(chunk);
|
|
96
|
+
size += chunk.byteLength;
|
|
97
|
+
}
|
|
98
|
+
const bytes = new Uint8Array(size);
|
|
99
|
+
let offset = 0;
|
|
100
|
+
for (const chunk of chunks) {
|
|
101
|
+
bytes.set(chunk, offset);
|
|
102
|
+
offset += chunk.byteLength;
|
|
103
|
+
}
|
|
104
|
+
return bytes;
|
|
105
|
+
}
|
|
106
|
+
function decodeFile(content, options) {
|
|
107
|
+
if (options?.encoding === "binary") return content;
|
|
108
|
+
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
109
|
+
}
|
|
110
|
+
async function sha256(input) {
|
|
111
|
+
const bytes = contentToBytes(typeof input === "string" || input instanceof Uint8Array ? input : JSON.stringify(input));
|
|
112
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
export { matchesAny as a, normalizeWorkspacePath as c, sha256 as d, isWorkspaceError as f, decodeFile as i, path_exports as l, workspaceNotFoundError as m, contentStreamToBytes as n, normalizeSafeWorkspacePath as o, workspaceError as p, contentToBytes as r, normalizeSafeWorkspacePattern as s, contentStreamChunks as t, resolveInside as u };
|