@vite-hub/workspace 0.0.0 → 0.0.1

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.
Files changed (47) hide show
  1. package/README.md +89 -1
  2. package/dist/ai-Bk3LLnit.js +352 -0
  3. package/dist/ai.d.ts +86 -0
  4. package/dist/ai.js +2 -0
  5. package/dist/asset-registry-CMuQbyvl.js +14 -0
  6. package/dist/chunk-DrSxFLj_.js +14 -0
  7. package/dist/cloudflare-env-DL94Uvpz.js +12 -0
  8. package/dist/config-CvS-7sre.js +49 -0
  9. package/dist/errors-BUL8SoFS.js +21 -0
  10. package/dist/files-DbsIjBya.js +50 -0
  11. package/dist/index.d.ts +150 -0
  12. package/dist/index.js +656 -0
  13. package/dist/lifecycle-uD82JeGh.js +92 -0
  14. package/dist/loader.d.ts +17 -0
  15. package/dist/loader.js +22 -0
  16. package/dist/module-8LZUMEXC.js +922 -0
  17. package/dist/nitro.d.ts +31 -0
  18. package/dist/nitro.js +2 -0
  19. package/dist/path-BVv9OXhg.js +63 -0
  20. package/dist/provider-BZuKAV4e.js +494 -0
  21. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  22. package/dist/providers/cloudflare/artifacts-store.js +384 -0
  23. package/dist/providers/vercel/blob-store.d.ts +6 -0
  24. package/dist/providers/vercel/blob-store.js +176 -0
  25. package/dist/publish.d.ts +34 -0
  26. package/dist/publish.js +206 -0
  27. package/dist/registry-Cnr0NoKv.js +932 -0
  28. package/dist/registry-D4Qzq26I.d.ts +10 -0
  29. package/dist/runtime/assets.d.ts +11 -0
  30. package/dist/runtime/assets.js +138 -0
  31. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  32. package/dist/runtime/empty-assets-registry.js +4 -0
  33. package/dist/runtime/empty-registry.d.ts +6 -0
  34. package/dist/runtime/empty-registry.js +4 -0
  35. package/dist/runtime/nitro-plugin.d.ts +6 -0
  36. package/dist/runtime/nitro-plugin.js +14 -0
  37. package/dist/runtime/state.d.ts +21 -0
  38. package/dist/runtime/state.js +12 -0
  39. package/dist/sandbox-DtGXCWRq.js +198 -0
  40. package/dist/search-DtaEyjpO.js +39 -0
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.js +2 -0
  43. package/dist/types-CwNcWTdt.d.ts +378 -0
  44. package/dist/utils-BtAm_K5P.js +51 -0
  45. package/dist/vite.d.ts +22 -0
  46. package/dist/vite.js +131 -0
  47. package/package.json +101 -5
@@ -0,0 +1,378 @@
1
+ //#region src/core/types.d.ts
2
+ type WorkspaceContent = string | Uint8Array;
3
+ interface ReadFileOptions {
4
+ encoding?: "utf8" | "binary";
5
+ }
6
+ type ReadFileResult<TOptions extends ReadFileOptions | undefined = undefined> = TOptions extends {
7
+ encoding: "binary";
8
+ } ? Uint8Array : string;
9
+ interface WriteFileOptions {
10
+ mediaType?: string;
11
+ }
12
+ interface ListOptions {
13
+ recursive?: boolean;
14
+ }
15
+ interface GlobOptions {
16
+ cwd?: string;
17
+ }
18
+ interface WorkspaceSearchQuery {
19
+ pattern: string;
20
+ cwd?: string;
21
+ paths?: string[];
22
+ regex?: boolean;
23
+ caseSensitive?: boolean;
24
+ limit?: number;
25
+ }
26
+ interface WorkspaceSearchHit {
27
+ path: string;
28
+ line: number;
29
+ column: number;
30
+ text: string;
31
+ }
32
+ interface MkdirOptions {
33
+ recursive?: boolean;
34
+ }
35
+ interface RmOptions {
36
+ recursive?: boolean;
37
+ force?: boolean;
38
+ }
39
+ type WorkspaceWriteOperation = "writeFile" | "mkdir" | "rm";
40
+ type WorkspaceWriteMode = boolean | "create" | "update" | "delete";
41
+ interface WorkspaceWriteInput {
42
+ workspace: string;
43
+ operation: WorkspaceWriteOperation;
44
+ path: string;
45
+ content?: WorkspaceContent;
46
+ mediaType?: string;
47
+ previous?: WorkspaceStat;
48
+ rule?: ResolvedWorkspaceRule;
49
+ }
50
+ type WorkspaceWriteValidatorResult = boolean | void | WorkspaceWriteInput;
51
+ type WorkspaceWriteValidator = (input: WorkspaceWriteInput) => WorkspaceWriteValidatorResult | Promise<WorkspaceWriteValidatorResult>;
52
+ interface WorkspaceRule {
53
+ commit?: boolean | string;
54
+ read?: boolean;
55
+ write?: WorkspaceWriteMode;
56
+ maxBytes?: number | `${number}kb` | `${number}mb`;
57
+ mediaType?: string | string[];
58
+ validate?: WorkspaceWriteValidator | WorkspaceWriteValidator[];
59
+ }
60
+ type WorkspaceRules = Record<string, WorkspaceRule>;
61
+ interface ResolvedWorkspaceRule extends Omit<WorkspaceRule, "maxBytes" | "validate"> {
62
+ maxBytes?: number;
63
+ pattern: string;
64
+ validate: WorkspaceWriteValidator[];
65
+ }
66
+ interface WorkspaceHookContext extends WorkspaceWriteInput {}
67
+ interface WorkspaceHooks {
68
+ "write:before"?: WorkspaceWriteHook | WorkspaceWriteHook[];
69
+ "write:validate"?: WorkspaceWriteHook | WorkspaceWriteHook[];
70
+ "write:after"?: WorkspaceWriteHook | WorkspaceWriteHook[];
71
+ "write:error"?: WorkspaceWriteErrorHook | WorkspaceWriteErrorHook[];
72
+ }
73
+ type WorkspaceWriteHook = (ctx: WorkspaceHookContext) => void | Promise<void>;
74
+ type WorkspaceWriteErrorHook = (ctx: WorkspaceHookContext & {
75
+ error: unknown;
76
+ }) => void | Promise<void>;
77
+ interface WorkspacePlugin {
78
+ id: string;
79
+ rules?: WorkspaceRules;
80
+ hooks?: WorkspaceHooks;
81
+ }
82
+ interface SnapshotOptions {
83
+ name?: string;
84
+ }
85
+ interface DiffOptions {
86
+ from?: WorkspaceSnapshot;
87
+ }
88
+ interface WorkspaceSyncOptions {
89
+ force?: boolean;
90
+ }
91
+ interface WorkspaceSessionOptions {
92
+ runtime?: never;
93
+ sandbox?: never;
94
+ }
95
+ type WorkspaceMountMode = "read-only" | "read-write" | "copy-on-write";
96
+ interface WorkspaceMountOptions {
97
+ mode: WorkspaceMountMode;
98
+ target?: string;
99
+ }
100
+ interface WorkspaceMount {
101
+ workspace: Workspace;
102
+ mode: WorkspaceMountMode;
103
+ target: string;
104
+ diff(): Promise<WorkspaceDiff>;
105
+ commit(options?: {
106
+ message?: string;
107
+ }): Promise<void>;
108
+ export(): Promise<WorkspaceSnapshot>;
109
+ }
110
+ interface ExecOptions {
111
+ cwd?: string;
112
+ env?: Record<string, string>;
113
+ timeout?: number;
114
+ }
115
+ interface ExecResult {
116
+ command: string;
117
+ args: string[];
118
+ exitCode: number;
119
+ stdout: string;
120
+ stderr: string;
121
+ }
122
+ interface WorkspaceSession {
123
+ readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: string, options?: TOptions): Promise<ReadFileResult<TOptions>>;
124
+ writeFile(path: string, content: WorkspaceContent, options?: WriteFileOptions): Promise<void>;
125
+ list(path?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
126
+ glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
127
+ search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
128
+ diff(): Promise<WorkspaceDiff>;
129
+ commit(options?: {
130
+ message?: string;
131
+ }): Promise<void>;
132
+ exec(command: string, args?: string[], options?: ExecOptions): Promise<ExecResult>;
133
+ tools?: {
134
+ aiSdk?(): Promise<Record<string, unknown>>;
135
+ };
136
+ close(): Promise<void>;
137
+ }
138
+ declare global {
139
+ interface ViteHubWorkspaceNameMap {}
140
+ interface ViteHubWorkspaceAssetMap {}
141
+ }
142
+ interface WorkspaceNameMap extends ViteHubWorkspaceNameMap {}
143
+ type WorkspaceName = [keyof ViteHubWorkspaceNameMap] extends [never] ? string : Extract<keyof ViteHubWorkspaceNameMap, string>;
144
+ type WorkspaceAssetPath<Name extends WorkspaceName = WorkspaceName> = Name extends keyof ViteHubWorkspaceAssetMap ? Extract<ViteHubWorkspaceAssetMap[Name], string> : string;
145
+ interface WorkspaceAssets<TKey extends string = string> {
146
+ readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: TKey, options?: TOptions): Promise<ReadFileResult<TOptions>>;
147
+ stat(path: TKey): Promise<WorkspaceStat>;
148
+ exists(path: TKey): Promise<boolean>;
149
+ list(path?: TKey | (string & {}) | "", options?: ListOptions): Promise<WorkspaceEntry[]>;
150
+ glob(pattern: TKey | (string & {}) | Array<TKey | (string & {})>, options?: GlobOptions): Promise<WorkspaceEntry[]>;
151
+ search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
152
+ materializeSources?(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
153
+ }
154
+ type WorkspaceAssetsRegistry = Record<string, WorkspaceAssets>;
155
+ interface WorkspaceFile {
156
+ path: string;
157
+ content: WorkspaceContent;
158
+ mediaType?: string;
159
+ metadata?: Record<string, unknown>;
160
+ }
161
+ interface WorkspaceEntry {
162
+ path: string;
163
+ type: "file" | "directory";
164
+ size?: number;
165
+ mtime?: number;
166
+ mediaType?: string;
167
+ digest?: string;
168
+ }
169
+ interface WorkspaceStat extends WorkspaceEntry {
170
+ type: "file" | "directory";
171
+ }
172
+ interface WorkspaceSnapshot {
173
+ id: string;
174
+ name?: string;
175
+ createdAt: string;
176
+ entries: Record<string, {
177
+ type: "file" | "directory";
178
+ digest?: string;
179
+ size?: number;
180
+ }>;
181
+ }
182
+ interface WorkspaceDiffEntry {
183
+ path: string;
184
+ type: "added" | "modified" | "removed";
185
+ before?: WorkspaceSnapshot["entries"][string];
186
+ after?: WorkspaceSnapshot["entries"][string];
187
+ }
188
+ interface WorkspaceDiff {
189
+ from?: string;
190
+ to: string;
191
+ entries: WorkspaceDiffEntry[];
192
+ }
193
+ interface WorkspaceAutoCommitPlan {
194
+ message: string;
195
+ paths: string[];
196
+ }
197
+ interface WorkspaceStore {
198
+ readFile(path: string): Promise<WorkspaceFile | undefined>;
199
+ writeFile(path: string, file: WorkspaceFile): Promise<void>;
200
+ list(prefix?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
201
+ glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
202
+ stat(path: string): Promise<WorkspaceStat | undefined>;
203
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
204
+ rm(path: string, options?: RmOptions): Promise<void>;
205
+ snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
206
+ diff(options?: DiffOptions): Promise<WorkspaceDiff>;
207
+ getMeta?(key: string): Promise<unknown>;
208
+ setMeta?(key: string, value: unknown): Promise<void>;
209
+ }
210
+ interface SourceContext {
211
+ rootDir: string;
212
+ sourceRootDir?: string;
213
+ workspace: string;
214
+ }
215
+ type WorkspaceMaterializeMode = "build" | "lazy";
216
+ type WorkspaceValidateMode = false | "request";
217
+ interface WorkspaceCacheOptions {
218
+ maxAge?: number;
219
+ }
220
+ interface WorkspaceSourceMountOptions {
221
+ path?: string;
222
+ materialize?: WorkspaceMaterializeMode;
223
+ cache?: false | WorkspaceCacheOptions;
224
+ validate?: WorkspaceValidateMode;
225
+ }
226
+ type WorkspaceSourceMount = string | WorkspaceSourceMountOptions;
227
+ interface WorkspaceSourceItem {
228
+ key: string;
229
+ path?: string;
230
+ content?: WorkspaceContent;
231
+ data?: unknown;
232
+ mediaType?: string;
233
+ metadata?: Record<string, unknown>;
234
+ }
235
+ interface WorkspaceSource {
236
+ mount?: WorkspaceSourceMount;
237
+ materialize?: WorkspaceMaterializeMode;
238
+ cache?: false | WorkspaceCacheOptions;
239
+ validate?: WorkspaceValidateMode;
240
+ fingerprint?: unknown;
241
+ prepare?(ctx: SourceContext): Promise<void>;
242
+ getKeys(ctx: SourceContext): Promise<string[]>;
243
+ getItem(key: string, ctx: SourceContext): Promise<WorkspaceSourceItem>;
244
+ getItems?(ctx: SourceContext): Promise<WorkspaceSourceItem[]>;
245
+ getMeta?(key: string, ctx: SourceContext): Promise<Record<string, unknown> | undefined>;
246
+ search?(query: WorkspaceSearchQuery, ctx: SourceContext): Promise<WorkspaceSearchHit[]>;
247
+ watch?: unknown[];
248
+ }
249
+ interface WorkspaceLoaderSource extends WorkspaceSource {
250
+ key: string;
251
+ }
252
+ interface LoaderContext {
253
+ workspace: string;
254
+ rootDir: string;
255
+ sourceRootDir?: string;
256
+ sources: WorkspaceLoaderSource[];
257
+ store: WorkspaceStore;
258
+ parseData(input: {
259
+ id: string;
260
+ data: unknown;
261
+ filePath?: string;
262
+ }): Promise<unknown>;
263
+ generateDigest(input: unknown): string;
264
+ logger: Logger;
265
+ watcher?: unknown;
266
+ }
267
+ interface WorkspaceLoader {
268
+ name: string;
269
+ schema?: unknown;
270
+ load(ctx: LoaderContext): Promise<void>;
271
+ }
272
+ interface PublishContext {
273
+ workspace: WorkspaceDefinition;
274
+ store: WorkspaceStore;
275
+ rootDir: string;
276
+ snapshot?: WorkspaceSnapshot;
277
+ }
278
+ interface WorkspacePublisher {
279
+ name: string;
280
+ clientSafe?: boolean;
281
+ publish(ctx: PublishContext): Promise<void>;
282
+ }
283
+ interface Logger {
284
+ debug(...args: unknown[]): void;
285
+ info(...args: unknown[]): void;
286
+ warn(...args: unknown[]): void;
287
+ error(...args: unknown[]): void;
288
+ }
289
+ interface LocalWorkspaceStoreOptions {
290
+ provider?: "local";
291
+ root?: string;
292
+ }
293
+ interface MemoryWorkspaceStoreOptions {
294
+ provider: "memory";
295
+ }
296
+ interface CloudflareArtifactsWorkspaceStoreOptions {
297
+ provider: "cloudflare-artifacts";
298
+ binding?: string;
299
+ namespace?: string;
300
+ repo?: string;
301
+ repoPrefix?: string;
302
+ branch?: string;
303
+ }
304
+ interface VercelBlobWorkspaceStoreOptions {
305
+ provider: "vercel-blob";
306
+ token?: string;
307
+ prefix?: string;
308
+ access?: "private" | "public";
309
+ }
310
+ type WorkspaceStoreOptions = LocalWorkspaceStoreOptions | MemoryWorkspaceStoreOptions | CloudflareArtifactsWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions | WorkspaceStore;
311
+ interface WorkspaceDefinition {
312
+ name: string;
313
+ rootDir?: string;
314
+ sourceRootDir?: string;
315
+ runtime?: "sandbox";
316
+ store?: WorkspaceStoreOptions;
317
+ sources?: Record<string, WorkspaceSource>;
318
+ loaders?: WorkspaceLoader[];
319
+ publish?: WorkspacePublisher[];
320
+ plugins?: WorkspacePlugin[];
321
+ rules?: WorkspaceRules;
322
+ hooks?: WorkspaceHooks;
323
+ }
324
+ type WorkspaceDefinitionInput = Omit<WorkspaceDefinition, "name"> & {
325
+ name?: never;
326
+ };
327
+ interface WorkspaceModuleOptions {
328
+ root?: string;
329
+ assets?: boolean | string[];
330
+ store?: WorkspaceStoreOptions;
331
+ }
332
+ interface ResolvedWorkspaceModuleOptions {
333
+ root: string;
334
+ assets?: boolean | string[];
335
+ store: Exclude<WorkspaceStoreOptions, WorkspaceStore>;
336
+ }
337
+ interface Workspace {
338
+ name: string;
339
+ sync(options?: WorkspaceSyncOptions): Promise<void>;
340
+ materializeSources?(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
341
+ readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: string, options?: TOptions): Promise<ReadFileResult<TOptions>>;
342
+ writeFile(path: string, content: WorkspaceContent, options?: WriteFileOptions): Promise<void>;
343
+ list(path?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
344
+ glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
345
+ search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
346
+ stat(path: string): Promise<WorkspaceStat>;
347
+ exists(path: string): Promise<boolean>;
348
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
349
+ rm(path: string, options?: RmOptions): Promise<void>;
350
+ snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
351
+ diff(options?: DiffOptions): Promise<WorkspaceDiff>;
352
+ startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
353
+ mount(options?: WorkspaceMountOptions): WorkspaceMount;
354
+ }
355
+ interface WorkspaceSourceMaterializationStatus {
356
+ source: string;
357
+ mountPath: string;
358
+ status: "lazy" | "updating" | "ready" | "error";
359
+ commit?: string;
360
+ materializedAt?: string;
361
+ files?: number;
362
+ bytes?: number;
363
+ error?: string;
364
+ }
365
+ interface WorkspaceMaterializeSourcesOptions {
366
+ sources?: string[];
367
+ path?: string;
368
+ }
369
+ interface WorkspaceMaterializeSourcesResult {
370
+ bytes: number;
371
+ directories: number;
372
+ durationMs: number;
373
+ files: number;
374
+ path: string;
375
+ sources: WorkspaceSourceMaterializationStatus[];
376
+ }
377
+ //#endregion
378
+ export { WorkspaceSession as $, WorkspaceDiff as A, WorkspaceMaterializeSourcesResult as B, WorkspaceAssets as C, WorkspaceContent as D, WorkspaceCacheOptions as E, WorkspaceHooks as F, WorkspaceName as G, WorkspaceMount as H, WorkspaceLoader as I, WorkspacePublisher as J, WorkspaceNameMap as K, WorkspaceLoaderSource as L, WorkspaceEntry as M, WorkspaceFile as N, WorkspaceDefinition as O, WorkspaceHookContext as P, WorkspaceSearchQuery as Q, WorkspaceMaterializeMode as R, WorkspaceAssetPath as S, WorkspaceAutoCommitPlan as T, WorkspaceMountMode as U, WorkspaceModuleOptions as V, WorkspaceMountOptions as W, WorkspaceRules as X, WorkspaceRule as Y, WorkspaceSearchHit as Z, RmOptions as _, WorkspaceWriteValidator as _t, GlobOptions as a, WorkspaceSourceMount as at, VercelBlobWorkspaceStoreOptions as b, LocalWorkspaceStoreOptions as c, WorkspaceStore as ct, MkdirOptions as d, WorkspaceValidateMode as dt, WorkspaceSessionOptions as et, PublishContext as f, WorkspaceWriteErrorHook as ft, ResolvedWorkspaceRule as g, WorkspaceWriteOperation as gt, ResolvedWorkspaceModuleOptions as h, WorkspaceWriteMode as ht, ExecResult as i, WorkspaceSourceMaterializationStatus as it, WorkspaceDiffEntry as j, WorkspaceDefinitionInput as k, Logger as l, WorkspaceStoreOptions as lt, ReadFileResult as m, WorkspaceWriteInput as mt, DiffOptions as n, WorkspaceSource as nt, ListOptions as o, WorkspaceSourceMountOptions as ot, ReadFileOptions as p, WorkspaceWriteHook as pt, WorkspacePlugin as q, ExecOptions as r, WorkspaceSourceItem as rt, LoaderContext as s, WorkspaceStat as st, CloudflareArtifactsWorkspaceStoreOptions as t, WorkspaceSnapshot as tt, MemoryWorkspaceStoreOptions as u, WorkspaceSyncOptions as ut, SnapshotOptions as v, WorkspaceWriteValidatorResult as vt, WorkspaceAssetsRegistry as w, Workspace as x, SourceContext as y, WriteFileOptions as yt, WorkspaceMaterializeSourcesOptions as z };
@@ -0,0 +1,51 @@
1
+ import { l as sha256 } from "./path-BVv9OXhg.js";
2
+ //#region src/storage/utils.ts
3
+ async function createSnapshotFromEntries(entries, name) {
4
+ const snapshotEntries = {};
5
+ for (const entry of entries) snapshotEntries[entry.path] = {
6
+ digest: entry.digest,
7
+ size: entry.size,
8
+ type: entry.type
9
+ };
10
+ return {
11
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
12
+ entries: snapshotEntries,
13
+ id: await sha256({
14
+ entries: snapshotEntries,
15
+ name,
16
+ createdAt: Date.now()
17
+ }),
18
+ name
19
+ };
20
+ }
21
+ function diffSnapshots(from, to) {
22
+ const entries = [];
23
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
24
+ for (const path of [...keys].sort()) {
25
+ const before = from?.entries[path];
26
+ const after = to.entries[path];
27
+ if (!before && after) entries.push({
28
+ path,
29
+ type: "added",
30
+ after
31
+ });
32
+ else if (before && !after) entries.push({
33
+ path,
34
+ type: "removed",
35
+ before
36
+ });
37
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
38
+ path,
39
+ type: "modified",
40
+ before,
41
+ after
42
+ });
43
+ }
44
+ return {
45
+ from: from?.id,
46
+ to: to.id,
47
+ entries
48
+ };
49
+ }
50
+ //#endregion
51
+ export { diffSnapshots as n, createSnapshotFromEntries as t };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { V as WorkspaceModuleOptions } from "./types-CwNcWTdt.js";
2
+ import { NitroModule } from "nitro/types";
3
+ import { Plugin } from "vite";
4
+
5
+ //#region src/hosts/vite/plugin.d.ts
6
+ interface WorkspaceVitePluginAPI {
7
+ getWorkspaces: () => Array<{
8
+ name: string;
9
+ }>;
10
+ }
11
+ type WorkspaceVitePlugin = Plugin & {
12
+ api: WorkspaceVitePluginAPI;
13
+ nitro: NitroModule;
14
+ };
15
+ declare function hubWorkspace(options?: WorkspaceModuleOptions): WorkspaceVitePlugin;
16
+ declare module "vite" {
17
+ interface UserConfig {
18
+ workspace?: false | WorkspaceModuleOptions;
19
+ }
20
+ }
21
+ //#endregion
22
+ export { WorkspaceVitePlugin, WorkspaceVitePluginAPI, hubWorkspace };
package/dist/vite.js ADDED
@@ -0,0 +1,131 @@
1
+ import { a as refreshWorkspaceBuildState, c as workspaceSuffixPattern, i as initializeWorkspaceAssetRegistry, n as workspaceNitroModule, o as syncWorkspaceBuildAssets, r as normalizeWorkspaceOptions, s as discoverViteWorkspaceDefinitions } from "./module-8LZUMEXC.js";
2
+ import { resolve } from "node:path";
3
+ //#region ../internal/src/build/vite.ts
4
+ const generatedViteHubFilesPattern = "**/.vitehub/**";
5
+ function createNoExternalMerger(packageName) {
6
+ return (current) => {
7
+ if (current === true) return true;
8
+ if (!current) return [packageName];
9
+ const values = Array.isArray(current) ? current : [current];
10
+ return values.includes(packageName) ? values : [...values, packageName];
11
+ };
12
+ }
13
+ function isServerEnvironment(name, config) {
14
+ return name === "ssr" || config.consumer === "server";
15
+ }
16
+ function mergeGeneratedViteHubWatchIgnored(ignored) {
17
+ if (!ignored) return [generatedViteHubFilesPattern];
18
+ if (Array.isArray(ignored)) return ignored.includes(generatedViteHubFilesPattern) ? ignored : [...ignored, generatedViteHubFilesPattern];
19
+ return [ignored, generatedViteHubFilesPattern];
20
+ }
21
+ //#endregion
22
+ //#region src/hosts/vite/plugin.ts
23
+ const WORKSPACE_PACKAGE_NAME = "@vite-hub/workspace";
24
+ const WORKSPACES_ID = "#vitehub/workspaces";
25
+ const WORKSPACE_PREFIX = "#vitehub/workspaces/";
26
+ const WORKSPACE_ASSETS_REGISTRY_ID = "#vitehub-workspace-assets-registry";
27
+ const WORKSPACE_REGISTRY_ID = "#vitehub-workspace-registry";
28
+ const RESOLVED_WORKSPACES_ID = `\0${WORKSPACES_ID}`;
29
+ const RESOLVED_WORKSPACE_PREFIX = `\0${WORKSPACE_PREFIX}`;
30
+ const RESOLVED_WORKSPACE_REGISTRY_ID = `\0${WORKSPACE_REGISTRY_ID}`;
31
+ const mergeNoExternal = createNoExternalMerger(WORKSPACE_PACKAGE_NAME);
32
+ const workspacesDirSegment = /[\\/](?:server[\\/])?workspaces(?:[\\/]|$)/;
33
+ function isWorkspaceFile(file) {
34
+ return workspaceSuffixPattern.test(file) || workspacesDirSegment.test(file);
35
+ }
36
+ function hubWorkspace(options) {
37
+ let resolved;
38
+ let resolvedOptions = false;
39
+ let assetsRegistryFile;
40
+ let manifest = { workspaces: [] };
41
+ let registryContents = "export default {}\n";
42
+ let server;
43
+ async function refreshManifest(root) {
44
+ const state = await refreshWorkspaceBuildState(root, discoverViteWorkspaceDefinitions(root));
45
+ manifest = state.manifest;
46
+ registryContents = state.registryContents;
47
+ }
48
+ function invalidateVirtualWorkspaceModules() {
49
+ if (!server) return;
50
+ const moduleGraph = server.moduleGraph;
51
+ const ids = [
52
+ RESOLVED_WORKSPACE_REGISTRY_ID,
53
+ RESOLVED_WORKSPACES_ID,
54
+ ...manifest.workspaces.map((w) => `${RESOLVED_WORKSPACE_PREFIX}${w.name}`)
55
+ ];
56
+ for (const id of ids) {
57
+ const mod = moduleGraph.getModuleById(id);
58
+ if (mod) moduleGraph.invalidateModule(mod);
59
+ }
60
+ }
61
+ async function maybeRefreshTypesForFile(root, file) {
62
+ if (!isWorkspaceFile(file)) return;
63
+ await refreshManifest(root);
64
+ invalidateVirtualWorkspaceModules();
65
+ }
66
+ return {
67
+ name: "@vite-hub/workspace/vite",
68
+ api: { getWorkspaces: () => manifest.workspaces },
69
+ nitro: workspaceNitroModule,
70
+ config(config) {
71
+ return { server: { watch: { ignored: mergeGeneratedViteHubWatchIgnored(config.server?.watch?.ignored) } } };
72
+ },
73
+ async configResolved(config) {
74
+ resolved = config;
75
+ if (config.command !== "build") process.env.VITEHUB_WORKSPACE_DEV = "true";
76
+ else delete process.env.VITEHUB_WORKSPACE_DEV;
77
+ resolvedOptions = normalizeWorkspaceOptions(config.workspace ?? options, {
78
+ dev: config.command !== "build",
79
+ env: process.env,
80
+ hosting: process.env.VITEHUB_HOSTING,
81
+ rootDir: config.root
82
+ });
83
+ assetsRegistryFile = resolve(config.root, ".vitehub/vite-runtime/workspace/assets/registry.mjs");
84
+ await initializeWorkspaceAssetRegistry(assetsRegistryFile);
85
+ await refreshManifest(config.root);
86
+ },
87
+ configEnvironment(name, config) {
88
+ if (!isServerEnvironment(name, config)) return;
89
+ return { resolve: { noExternal: mergeNoExternal(config.resolve?.noExternal) } };
90
+ },
91
+ async buildStart() {
92
+ if (!resolved) return;
93
+ await refreshManifest(resolved.root);
94
+ if (resolved.command !== "build" || !assetsRegistryFile) return;
95
+ await syncWorkspaceBuildAssets(discoverViteWorkspaceDefinitions(resolved.root), resolved.root, resolvedOptions, assetsRegistryFile);
96
+ },
97
+ configureServer(devServer) {
98
+ server = devServer;
99
+ const refresh = async (file) => await maybeRefreshTypesForFile(devServer.config.root, file);
100
+ devServer.watcher.on("add", refresh);
101
+ devServer.watcher.on("unlink", refresh);
102
+ },
103
+ async handleHotUpdate(ctx) {
104
+ if (!resolved) return;
105
+ await maybeRefreshTypesForFile(resolved.root, ctx.file);
106
+ },
107
+ resolveId(id) {
108
+ if (id === WORKSPACE_ASSETS_REGISTRY_ID) return assetsRegistryFile;
109
+ if (id === WORKSPACE_REGISTRY_ID) return RESOLVED_WORKSPACE_REGISTRY_ID;
110
+ if (id === WORKSPACES_ID) return RESOLVED_WORKSPACES_ID;
111
+ if (id.startsWith(WORKSPACE_PREFIX)) return `${RESOLVED_WORKSPACE_PREFIX}${id.slice(20)}`;
112
+ },
113
+ load(id) {
114
+ if (id === RESOLVED_WORKSPACE_REGISTRY_ID) return registryContents;
115
+ if (id === RESOLVED_WORKSPACES_ID) return `export const workspaces = ${JSON.stringify(manifest.workspaces)};\nexport default { workspaces };\n`;
116
+ if (id.startsWith(RESOLVED_WORKSPACE_PREFIX)) {
117
+ const name = id.slice(RESOLVED_WORKSPACE_PREFIX.length);
118
+ const workspace = manifest.workspaces.find((item) => item.name === name);
119
+ return `const manifest = ${JSON.stringify(workspace ? {
120
+ ...workspace,
121
+ entries: []
122
+ } : {
123
+ name,
124
+ entries: []
125
+ })};\nexport default manifest;\n`;
126
+ }
127
+ }
128
+ };
129
+ }
130
+ //#endregion
131
+ export { hubWorkspace };
package/package.json CHANGED
@@ -1,9 +1,105 @@
1
1
  {
2
2
  "name": "@vite-hub/workspace",
3
- "version": "0.0.0",
4
- "description": "Reserved package name for ViteHub.",
3
+ "version": "0.0.1",
4
+ "description": "Agent-oriented filesystem state and Vite/Nitro integration for ViteHub.",
5
+ "author": "onmax <maximogarciamtnez@gmail.com>",
5
6
  "license": "Apache-2.0",
6
- "publishConfig": {
7
- "access": "public"
7
+ "homepage": "https://github.com/vite-hub/vitehub#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vite-hub/vitehub.git",
11
+ "directory": "packages/workspace"
12
+ },
13
+ "bugs": "https://github.com/vite-hub/vitehub/issues",
14
+ "keywords": [
15
+ "vitehub",
16
+ "vite",
17
+ "nitro",
18
+ "workspace",
19
+ "cloudflare",
20
+ "vercel"
21
+ ],
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "types": "./dist/index.d.ts",
25
+ "imports": {
26
+ "#vitehub-workspace-assets-registry": {
27
+ "types": "./dist/runtime/empty-assets-registry.d.ts",
28
+ "default": "./dist/runtime/empty-assets-registry.js"
29
+ },
30
+ "#vitehub-workspace-registry": {
31
+ "types": "./dist/runtime/empty-registry.d.ts",
32
+ "default": "./dist/runtime/empty-registry.js"
33
+ }
34
+ },
35
+ "exports": {
36
+ ".": "./dist/index.js",
37
+ "./ai": "./dist/ai.js",
38
+ "./loader": "./dist/loader.js",
39
+ "./nitro": "./dist/nitro.js",
40
+ "./publish": "./dist/publish.js",
41
+ "./test": "./dist/test.js",
42
+ "./vite": "./dist/vite.js",
43
+ "./package.json": "./package.json",
44
+ "./internal/runtime/assets": "./dist/runtime/assets.js",
45
+ "./internal/runtime/empty-assets-registry": "./dist/runtime/empty-assets-registry.js",
46
+ "./internal/runtime/empty-registry": "./dist/runtime/empty-registry.js",
47
+ "./internal/runtime/nitro-plugin": "./dist/runtime/nitro-plugin.js",
48
+ "./internal/runtime/state": "./dist/runtime/state.js",
49
+ "./internal/stores/cloudflare-artifacts": "./dist/providers/cloudflare/artifacts-store.js",
50
+ "./internal/stores/vercel-blob": "./dist/providers/vercel/blob-store.js"
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "package.json"
55
+ ],
56
+ "dependencies": {
57
+ "defu": "^6.1.4",
58
+ "exsolve": "^1.0.8",
59
+ "files-sdk": "^1.2.0",
60
+ "isomorphic-git": "^1.37.6",
61
+ "jiti": "^2.6.1",
62
+ "minimatch": "^10.1.1",
63
+ "@vite-hub/shell": "0.0.1",
64
+ "@vite-hub/source": "0.0.1"
65
+ },
66
+ "peerDependencies": {
67
+ "ai": "^6.0.0",
68
+ "nitro": "^3.0.0-0",
69
+ "vite": ">=8.0.0",
70
+ "@vite-hub/sandbox": "0.0.1"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "@vite-hub/sandbox": {
74
+ "optional": true
75
+ },
76
+ "nitro": {
77
+ "optional": true
78
+ },
79
+ "vite": {
80
+ "optional": true
81
+ }
82
+ },
83
+ "devDependencies": {
84
+ "@types/node": "^25.6.0",
85
+ "ai": "^6.0.172",
86
+ "nitro": "3.0.260311-beta",
87
+ "ocache": "^0.1.4",
88
+ "ofetch": "^1.5.1",
89
+ "publint": "^0.3.15",
90
+ "tsdown": "^0.21.8",
91
+ "tsx": "^4.21.0",
92
+ "typescript": "^6.0.2",
93
+ "vite": "^8.0.8",
94
+ "vitest": "^4.1.4",
95
+ "@vite-hub/internal": "0.0.1",
96
+ "@vite-hub/sandbox": "0.0.1"
97
+ },
98
+ "scripts": {
99
+ "build": "tsdown --tsconfig tsconfig.build.json",
100
+ "dev": "tsdown --watch",
101
+ "test:e2e": "tsx ./test/e2e.ts",
102
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
103
+ "test": "pnpm --filter @vite-hub/workspace... build && vitest run"
8
104
  }
9
- }
105
+ }