@vite-hub/workspace 0.0.0 → 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.
Files changed (84) hide show
  1. package/README.md +262 -1
  2. package/dist/ai-Cztw4eLk.js +472 -0
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +3 -0
  5. package/dist/ai.js +2 -0
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/chunk-8H4AJuhK.js +14 -0
  9. package/dist/cli.d.ts +31 -0
  10. package/dist/cli.js +303 -0
  11. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  12. package/dist/cloudflare.d.ts +16 -0
  13. package/dist/cloudflare.js +3 -0
  14. package/dist/collections/client.d.ts +39 -0
  15. package/dist/collections/client.js +137 -0
  16. package/dist/collections.d.ts +59 -0
  17. package/dist/collections.js +159 -0
  18. package/dist/config--r5unwPc.js +7811 -0
  19. package/dist/config-Ca5DM8fF.d.ts +28 -0
  20. package/dist/config-DCQ6y30R.js +30 -0
  21. package/dist/file-B2q9NE18.js +24 -0
  22. package/dist/files-xy0le-_U.js +51 -0
  23. package/dist/github-lIO6-2sH.js +194 -0
  24. package/dist/glob-DeH0dzZX.js +23 -0
  25. package/dist/host-I-_vDs05.js +370 -0
  26. package/dist/hosted-vercel-blob.d.ts +15 -0
  27. package/dist/hosted-vercel-blob.js +26 -0
  28. package/dist/hosted.d.ts +18 -0
  29. package/dist/hosted.js +30 -0
  30. package/dist/index.d.ts +185 -0
  31. package/dist/index.js +541 -0
  32. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  33. package/dist/loader.d.ts +17 -0
  34. package/dist/loader.js +22 -0
  35. package/dist/nitro.d.ts +2 -0
  36. package/dist/nitro.js +2 -0
  37. package/dist/nuxt.d.ts +26 -0
  38. package/dist/nuxt.js +36 -0
  39. package/dist/path-CNI6wKIU.js +115 -0
  40. package/dist/provider-CeQciesl.js +599 -0
  41. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  42. package/dist/providers/cloudflare/artifacts-store.js +2 -0
  43. package/dist/providers/github/store.d.ts +6 -0
  44. package/dist/providers/github/store.js +362 -0
  45. package/dist/providers/vercel/blob-store.d.ts +6 -0
  46. package/dist/providers/vercel/blob-store.js +235 -0
  47. package/dist/publish.d.ts +35 -0
  48. package/dist/publish.js +112 -0
  49. package/dist/registry-C7DMdBXN.js +74 -0
  50. package/dist/registry-CoC9JxVt.d.ts +11 -0
  51. package/dist/request-execution-C8qRcReq.js +80 -0
  52. package/dist/runtime/assets.d.ts +12 -0
  53. package/dist/runtime/assets.js +138 -0
  54. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  55. package/dist/runtime/empty-assets-registry.js +4 -0
  56. package/dist/runtime/empty-registry.d.ts +6 -0
  57. package/dist/runtime/empty-registry.js +4 -0
  58. package/dist/runtime/state.d.ts +4 -0
  59. package/dist/runtime/state.js +15 -0
  60. package/dist/runtime/workspace.d.ts +2 -0
  61. package/dist/runtime/workspace.js +2 -0
  62. package/dist/runtime.d.ts +38 -0
  63. package/dist/runtime.js +643 -0
  64. package/dist/search-C4REyHj9.js +39 -0
  65. package/dist/server.d.ts +65 -0
  66. package/dist/server.js +355 -0
  67. package/dist/shared-BRycRSbo.js +255 -0
  68. package/dist/source-metadata.d.ts +2 -0
  69. package/dist/source-metadata.js +2 -0
  70. package/dist/state-DSAHEsq6.d.ts +25 -0
  71. package/dist/sync-DO42ypji.js +269 -0
  72. package/dist/target-D4Bqb1eH.js +11 -0
  73. package/dist/test.d.ts +2 -0
  74. package/dist/test.js +2 -0
  75. package/dist/types-DHkae7Cb.d.ts +628 -0
  76. package/dist/use-D16tf8Ph.d.ts +86 -0
  77. package/dist/use-d_PlAdOu.js +353 -0
  78. package/dist/utils-BPdaCyI6.js +55 -0
  79. package/dist/vite-NWC9mFjI.js +1882 -0
  80. package/dist/vite.d.ts +50 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  83. package/dist/workspace-n4wBmdaM.js +1476 -0
  84. package/package.json +197 -5
@@ -0,0 +1,28 @@
1
+ import { A as WorkspaceCacheOptions, Dt as WorkspaceSourceInput, Mt as WorkspaceSourceRequestDescriptor, P as WorkspaceDefinition, Z as WorkspaceMaterializeMode, qt as WorkspaceSourceSyncPolicy, rn as WorkspaceValidateMode, wt as WorkspaceSource } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/sources/request-metadata.d.ts
4
+ declare function getWorkspaceSourceRequestDescriptor(source: WorkspaceSource): WorkspaceSourceRequestDescriptor | undefined;
5
+ declare function isWorkspaceSourceRequestOnly(source: WorkspaceSource): boolean;
6
+ declare function workspaceSourceRequestDescriptorPath(sourceKey: string): string;
7
+ //#endregion
8
+ //#region src/sources/config.d.ts
9
+ interface ResolvedWorkspaceSource {
10
+ key: string;
11
+ source: WorkspaceSource;
12
+ mountPath: string;
13
+ materialize: WorkspaceMaterializeMode;
14
+ cache: false | WorkspaceCacheOptions;
15
+ sync: false | WorkspaceSourceSyncPolicy;
16
+ validate: WorkspaceValidateMode;
17
+ livePaths?: Record<string, string>;
18
+ probeKeys?: string[];
19
+ readonly: true;
20
+ requestDescriptor?: WorkspaceSourceRequestDescriptor;
21
+ requestOnly?: boolean;
22
+ }
23
+ type WorkspaceSourceMetadata = Pick<ResolvedWorkspaceSource, "cache" | "key" | "materialize" | "mountPath" | "probeKeys" | "requestOnly" | "source" | "sync">;
24
+ declare function normalizeWorkspaceSourcesMetadata(sources: WorkspaceDefinition["sources"]): WorkspaceSourceMetadata[];
25
+ declare function normalizeWorkspaceSourceMetadata(key: string, input: WorkspaceSourceInput): WorkspaceSourceMetadata;
26
+ declare function workspaceSourceGrantPaths(key: string, input: WorkspaceSourceInput): string[];
27
+ //#endregion
28
+ export { getWorkspaceSourceRequestDescriptor as a, workspaceSourceGrantPaths as i, normalizeWorkspaceSourceMetadata as n, isWorkspaceSourceRequestOnly as o, normalizeWorkspaceSourcesMetadata as r, workspaceSourceRequestDescriptorPath as s, WorkspaceSourceMetadata as t };
@@ -0,0 +1,30 @@
1
+ import { n as normalizeWorkspaceStoreOptions } from "./provider-CeQciesl.js";
2
+ import { resolve } from "node:path";
3
+ //#region ../internal/src/object.ts
4
+ function isPlainObject(value) {
5
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6
+ }
7
+ //#endregion
8
+ //#region src/config.ts
9
+ const workspaceConfigKeys = new Set([
10
+ "assets",
11
+ "projectRoot",
12
+ "root",
13
+ "store"
14
+ ]);
15
+ function normalizeWorkspaceOptions(options, input = {}) {
16
+ if (options === false) return false;
17
+ if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`workspace` must be a plain object.");
18
+ const resolvedOptions = options || {};
19
+ const unsupported = Object.keys(resolvedOptions).filter((key) => !workspaceConfigKeys.has(key));
20
+ if (unsupported.length) throw new TypeError(`[vitehub] workspace config does not support option${unsupported.length === 1 ? "" : "s"}: ${unsupported.join(", ")}.`);
21
+ const rootDir = input.rootDir || process.cwd();
22
+ const root = resolvedOptions.root || ".vitehub/workspaces";
23
+ return {
24
+ assets: resolvedOptions.assets,
25
+ root: resolve(rootDir, root),
26
+ store: normalizeWorkspaceStoreOptions(resolvedOptions.store, input) || { provider: "local" }
27
+ };
28
+ }
29
+ //#endregion
30
+ export { normalizeWorkspaceOptions as t };
@@ -0,0 +1,24 @@
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { o as normalizeSafeWorkspacePath } from "./path-CNI6wKIU.js";
3
+ import { file } from "@vite-hub/source/sources/file";
4
+ //#region src/sources/file.ts
5
+ var file_exports = /* @__PURE__ */ __exportAll({ file: () => file$1 });
6
+ function file$1(input) {
7
+ const options = typeof input === "string" ? { path: input } : input;
8
+ const key = normalizeSafeWorkspacePath(options.workspacePath || options.path || "");
9
+ const mount = typeof options.mount === "object" && options.mount && !("path" in options.mount) ? {
10
+ ...options.mount,
11
+ path: ""
12
+ } : options.mount ?? "";
13
+ return {
14
+ ...file(options),
15
+ cache: options.cache,
16
+ materialize: options.materialize,
17
+ mount,
18
+ probeKeys: options.probeKeys || [key],
19
+ sync: options.sync,
20
+ validate: options.validate
21
+ };
22
+ }
23
+ //#endregion
24
+ export { file_exports as n, file$1 as t };
@@ -0,0 +1,51 @@
1
+ import { a as matchesAny, c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
2
+ import { n as createSourceContext } from "./config--r5unwPc.js";
3
+ //#region src/loaders/files.ts
4
+ function shouldLoad(path, options) {
5
+ if (options.include && !matchesAny(path, options.include)) return false;
6
+ if (options.exclude && matchesAny(path, options.exclude)) return false;
7
+ return true;
8
+ }
9
+ function files(options = {}) {
10
+ return {
11
+ name: "files",
12
+ async load(ctx) {
13
+ const sourceContext = createSourceContext({
14
+ name: ctx.workspace,
15
+ rootDir: ctx.rootDir,
16
+ sourceRootDir: ctx.sourceRootDir
17
+ }, void 0, ctx.store);
18
+ for (const source of ctx.sources) {
19
+ await source.prepare?.(sourceContext);
20
+ for (const key of await source.getKeys(sourceContext)) {
21
+ const rawItem = await source.getItem(key, sourceContext);
22
+ const rawPath = normalizeWorkspacePath(rawItem.path || rawItem.key);
23
+ if (!shouldLoad(rawPath, options)) continue;
24
+ const transformed = options.transform ? await options.transform(rawItem) : rawItem;
25
+ const item = typeof transformed === "string" || transformed instanceof Uint8Array ? {
26
+ ...rawItem,
27
+ content: transformed
28
+ } : transformed;
29
+ const path = normalizeWorkspacePath(item.path || rawPath);
30
+ const content = item.content ?? (typeof item.data === "undefined" ? "" : JSON.stringify(item.data, null, 2));
31
+ const digest = ctx.generateDigest({
32
+ content,
33
+ metadata: item.metadata,
34
+ mediaType: item.mediaType
35
+ });
36
+ const metaKey = `loader:files:${source.key}:${path}:digest`;
37
+ if (await ctx.store.getMeta?.(metaKey) === digest && await ctx.store.stat(path)) continue;
38
+ await ctx.store.writeFile(path, {
39
+ path,
40
+ content,
41
+ mediaType: item.mediaType,
42
+ metadata: item.metadata
43
+ });
44
+ await ctx.store.setMeta?.(metaKey, digest);
45
+ }
46
+ }
47
+ }
48
+ };
49
+ }
50
+ //#endregion
51
+ export { files as t };
@@ -0,0 +1,194 @@
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { t as getActiveCloudflareBinding } from "./cloudflare-env-CKxUs2fa.js";
3
+ import { h as resolveGitHubTokenOption, s as processEnv } from "./shared-BRycRSbo.js";
4
+ import { github } from "@vite-hub/source/sources/github";
5
+ //#region src/env.ts
6
+ let viteLoadEnv;
7
+ async function resolveWorkspaceEnv(rootDir, name) {
8
+ return (await loadWorkspaceEnv(rootDir))?.[name];
9
+ }
10
+ async function loadWorkspaceEnv(rootDir) {
11
+ return await loadViteEnv(rootDir);
12
+ }
13
+ async function loadViteEnv(rootDir) {
14
+ if (viteLoadEnv === null) return;
15
+ if (!viteLoadEnv) try {
16
+ viteLoadEnv = (await import(
17
+ /* @vite-ignore */
18
+ "vite"
19
+ )).loadEnv;
20
+ } catch {
21
+ viteLoadEnv = null;
22
+ return;
23
+ }
24
+ return viteLoadEnv("", rootDir, "");
25
+ }
26
+ //#endregion
27
+ //#region src/sources/github.ts
28
+ var github_exports = /* @__PURE__ */ __exportAll({ github: () => github$1 });
29
+ const githubTokenEnvNames = [
30
+ "WORKSPACE_GITHUB_TOKEN",
31
+ "VITEHUB_WORKSPACE_GITHUB_TOKEN",
32
+ "GITHUB_TOKEN",
33
+ "GH_TOKEN"
34
+ ];
35
+ function github$1(input) {
36
+ if (typeof input === "function") return resolvableGitHubSource(input);
37
+ const resolvedOptions = { ...input };
38
+ const baseSource = github({
39
+ ...resolvedOptions,
40
+ auth: createGitHubAuthResolver(resolvedOptions.auth)
41
+ });
42
+ const sourceByRootAndToken = /* @__PURE__ */ new Map();
43
+ async function getSourceForRoot(rootDir) {
44
+ const token = await resolveGitHubAuth(resolvedOptions.auth, rootDir);
45
+ const cacheKey = `${rootDir}\0${token || ""}`;
46
+ const cachedSource = sourceByRootAndToken.get(cacheKey);
47
+ if (cachedSource) return cachedSource;
48
+ const source = github({
49
+ ...resolvedOptions,
50
+ auth: token
51
+ });
52
+ sourceByRootAndToken.set(cacheKey, source);
53
+ return source;
54
+ }
55
+ return {
56
+ ...baseSource,
57
+ cache: resolvedOptions.cache,
58
+ fingerprint: {
59
+ exclude: resolvedOptions.exclude,
60
+ include: resolvedOptions.include,
61
+ ref: resolvedOptions.ref,
62
+ repo: resolvedOptions.repo,
63
+ root: resolvedOptions.root
64
+ },
65
+ materialize: resolvedOptions.materialize,
66
+ mount: resolvedOptions.mount,
67
+ sync: resolvedOptions.sync,
68
+ validate: resolvedOptions.validate,
69
+ async prepare(ctx) {
70
+ await (await getSourceForRoot(ctx.rootDir)).prepare?.(ctx);
71
+ },
72
+ async getKeys(ctx) {
73
+ return await (await getSourceForRoot(ctx.rootDir)).getKeys(ctx);
74
+ },
75
+ async getItem(key, ctx) {
76
+ return await (await getSourceForRoot(ctx.rootDir)).getItem(key, ctx);
77
+ },
78
+ async getItems(ctx) {
79
+ const source = await getSourceForRoot(ctx.rootDir);
80
+ return await source.getItems?.(ctx) ?? await Promise.all((await source.getKeys(ctx)).map((key) => source.getItem(key, ctx)));
81
+ },
82
+ async getMeta(key, ctx) {
83
+ return await (await getSourceForRoot(ctx.rootDir)).getMeta?.(key, ctx);
84
+ },
85
+ async search(query, ctx) {
86
+ return await (await getSourceForRoot(ctx.rootDir)).search?.(query, ctx) ?? [];
87
+ }
88
+ };
89
+ }
90
+ function resolvableGitHubSource(resolve) {
91
+ return {
92
+ fingerprint: { sourceResolution: "github" },
93
+ materialize: "lazy",
94
+ async getKeys() {
95
+ return [];
96
+ },
97
+ async getItem(key) {
98
+ throw new Error(`[vitehub] github() resolver did not resolve before reading ${JSON.stringify(key)}.`);
99
+ },
100
+ async getItems() {
101
+ return [];
102
+ },
103
+ async search() {
104
+ return [];
105
+ },
106
+ async resolve(ctx) {
107
+ const options = await resolve(ctx);
108
+ return options ? github$1(githubResolutionDefaults(options, ctx)) : false;
109
+ }
110
+ };
111
+ }
112
+ function githubResolutionDefaults(options, ctx) {
113
+ const source = pullRequestSource(ctx.invocation.context.get("pullRequest"));
114
+ const repo = options.repo || source?.repo;
115
+ if (!repo) throw new Error("[vitehub] github() resolver requires repo or typed pullRequest source context.");
116
+ return {
117
+ ...options,
118
+ mount: options.mount ?? ctx.source.mountPath,
119
+ ref: options.ref ?? source?.ref,
120
+ repo
121
+ };
122
+ }
123
+ function pullRequestSource(value) {
124
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
125
+ const flatRef = value.headRef;
126
+ const directSource = value.source;
127
+ if (directSource && typeof directSource === "object" && !Array.isArray(directSource)) {
128
+ const ref = directSource.ref;
129
+ const repo = directSource.repo;
130
+ if (typeof repo === "string" && repo) {
131
+ const resolvedRef = typeof ref === "string" && ref ? ref : typeof flatRef === "string" && flatRef ? flatRef : void 0;
132
+ return {
133
+ ...resolvedRef ? { ref: resolvedRef } : {},
134
+ repo
135
+ };
136
+ }
137
+ }
138
+ const flatRepo = value.repository;
139
+ if (typeof flatRepo === "string" && flatRepo) return {
140
+ ...typeof flatRef === "string" && flatRef ? { ref: flatRef } : {},
141
+ repo: flatRepo
142
+ };
143
+ const pullRequest = value.pullRequest;
144
+ if (!pullRequest || typeof pullRequest !== "object" || Array.isArray(pullRequest)) return;
145
+ const source = pullRequest.source;
146
+ if (!source || typeof source !== "object" || Array.isArray(source)) return;
147
+ const ref = source.ref;
148
+ const repo = source.repo;
149
+ return {
150
+ ...typeof ref === "string" && ref ? { ref } : {},
151
+ ...typeof repo === "string" && repo ? { repo } : {}
152
+ };
153
+ }
154
+ function createGitHubAuthResolver(auth) {
155
+ if (auth === false) return false;
156
+ return () => {
157
+ return resolveExplicitGitHubAuth(auth) || getActiveCloudflareBinding("GITHUB_TOKEN") || processEnv(process.env, ...githubTokenEnvNames);
158
+ };
159
+ }
160
+ async function resolveGitHubAuth(auth, rootDir) {
161
+ if (auth === false) return false;
162
+ return resolveExplicitGitHubAuth(auth) || resolveGitHubTokenOption({}) || await resolveGitHubEnvFileToken(rootDir) || await resolveGitHubCliToken();
163
+ }
164
+ function resolveExplicitGitHubAuth(auth) {
165
+ if (auth === false) return void 0;
166
+ if (typeof auth === "function") return auth();
167
+ return typeof auth === "string" ? auth : void 0;
168
+ }
169
+ async function resolveGitHubEnvFileToken(rootDir) {
170
+ return processEnv(Object.fromEntries(await Promise.all(githubTokenEnvNames.map(async (name) => [name, await resolveWorkspaceEnv(rootDir, name)]))), ...githubTokenEnvNames);
171
+ }
172
+ async function resolveGitHubCliToken() {
173
+ try {
174
+ const { execFileSync } = await import("node:child_process");
175
+ return execFileSync("gh", [
176
+ "auth",
177
+ "token",
178
+ "--hostname",
179
+ "github.com"
180
+ ], {
181
+ encoding: "utf8",
182
+ stdio: [
183
+ "ignore",
184
+ "pipe",
185
+ "ignore"
186
+ ],
187
+ timeout: 2e3
188
+ }).trim() || void 0;
189
+ } catch {
190
+ return;
191
+ }
192
+ }
193
+ //#endregion
194
+ export { github_exports as n, github$1 as t };
@@ -0,0 +1,23 @@
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { glob } from "@vite-hub/source/sources/glob";
3
+ //#region src/sources/glob.ts
4
+ var glob_exports = /* @__PURE__ */ __exportAll({ glob: () => glob$1 });
5
+ function glob$1(options) {
6
+ return {
7
+ ...glob({
8
+ ...options,
9
+ keyCache: options.keyCache ?? !isLazySource(options)
10
+ }),
11
+ cache: options.cache,
12
+ materialize: options.materialize,
13
+ mount: options.mount,
14
+ sync: options.sync,
15
+ validate: options.validate
16
+ };
17
+ }
18
+ function isLazySource(options) {
19
+ if (options.materialize === "lazy") return true;
20
+ return typeof options.mount === "object" && options.mount?.materialize === "lazy";
21
+ }
22
+ //#endregion
23
+ export { glob_exports as n, glob$1 as t };