@vite-hub/workspace 0.0.1 → 0.0.3

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 (95) hide show
  1. package/README.md +225 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
  3. package/dist/ai-nmHdzjCM.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/asset-registry-CaG9b7tf.js +19 -0
  7. package/dist/cloudflare.d.ts +18 -0
  8. package/dist/cloudflare.js +2 -0
  9. package/dist/collections/client.d.ts +39 -0
  10. package/dist/collections/client.js +137 -0
  11. package/dist/collections.d.ts +59 -0
  12. package/dist/collections.js +159 -0
  13. package/dist/config-3I1BnsdO.d.ts +28 -0
  14. package/dist/config-CDoyls2X.js +30 -0
  15. package/dist/config-CZLO0m9h.js +7811 -0
  16. package/dist/file-CHfsZpso.js +23 -0
  17. package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
  18. package/dist/github-CfA5vpJ5.js +189 -0
  19. package/dist/glob-D0vD_wRY.js +17 -0
  20. package/dist/host-CAnbugpI.js +370 -0
  21. package/dist/hosted-C1-tTTTf.js +581 -0
  22. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
  23. package/dist/hosted-vercel-blob.d.ts +15 -0
  24. package/dist/hosted-vercel-blob.js +2 -0
  25. package/dist/hosted.d.ts +18 -0
  26. package/dist/hosted.js +2 -0
  27. package/dist/index.d.ts +129 -102
  28. package/dist/index.js +477 -599
  29. package/dist/lifecycle-BYoa9hVb.js +176 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/mountx.d.ts +10 -0
  33. package/dist/mountx.js +143 -0
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-C3_elpEh.js} +142 -37
  40. package/dist/providers/github/store.d.ts +6 -0
  41. package/dist/providers/github/store.js +2 -0
  42. package/dist/publish.d.ts +3 -2
  43. package/dist/publish.js +48 -142
  44. package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
  45. package/dist/registry-CqyDTW9Y.js +74 -0
  46. package/dist/request-execution-u9mgUXKX.js +80 -0
  47. package/dist/runtime/assets.d.ts +2 -1
  48. package/dist/runtime/assets.js +5 -5
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -21
  52. package/dist/runtime/state.js +7 -4
  53. package/dist/runtime/workspace.d.ts +2 -0
  54. package/dist/runtime/workspace.js +2 -0
  55. package/dist/runtime-options-BsPSv5O7.js +13 -0
  56. package/dist/runtime.d.ts +38 -0
  57. package/dist/runtime.js +626 -0
  58. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  59. package/dist/server.d.ts +65 -0
  60. package/dist/server.js +355 -0
  61. package/dist/shared-jfogBrd5.js +273 -0
  62. package/dist/source-metadata.d.ts +2 -0
  63. package/dist/source-metadata.js +2 -0
  64. package/dist/state-TTqa3x3Y.d.ts +25 -0
  65. package/dist/store-Bs1SLh55.js +414 -0
  66. package/dist/sync-DiuDmSGk.js +269 -0
  67. package/dist/target-D4Bqb1eH.js +11 -0
  68. package/dist/test.d.ts +1 -1
  69. package/dist/test.js +1 -1
  70. package/dist/types-60Yn149G.d.ts +612 -0
  71. package/dist/use-CUFSnFCS.d.ts +86 -0
  72. package/dist/use-CsV3oIxH.js +336 -0
  73. package/dist/vite-tbfDxtlu.js +2191 -0
  74. package/dist/vite.d.ts +33 -5
  75. package/dist/vite.js +2 -131
  76. package/dist/workspace-66SKyiec.d.ts +6 -0
  77. package/dist/workspace-C4k92Ow8.js +1460 -0
  78. package/package.json +143 -62
  79. package/dist/asset-registry-CMuQbyvl.js +0 -14
  80. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  81. package/dist/config-CvS-7sre.js +0 -49
  82. package/dist/errors-BUL8SoFS.js +0 -21
  83. package/dist/lifecycle-uD82JeGh.js +0 -92
  84. package/dist/module-8LZUMEXC.js +0 -922
  85. package/dist/path-BVv9OXhg.js +0 -63
  86. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  87. package/dist/providers/cloudflare/artifacts-store.js +0 -384
  88. package/dist/providers/vercel/blob-store.d.ts +0 -6
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. package/dist/utils-BtAm_K5P.js +0 -51
  95. /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-CZLO0m9h.js";
4
+ import { n as createCurrentSnapshotFromStore } from "./store-Bs1SLh55.js";
5
+ import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
6
+ import { t as files } from "./files-QRV55OCx.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 { D as WorkspaceContent, I as WorkspaceLoader, rt as WorkspaceSourceItem } from "./types-CwNcWTdt.js";
1
+ import { Tt as WorkspaceSourceItem, Y as WorkspaceLoader, j as WorkspaceContent } from "./types-60Yn149G.js";
2
2
 
3
3
  //#region src/loaders/files.d.ts
4
4
  interface FilesLoaderOptions {
package/dist/loader.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as files } from "./files-DbsIjBya.js";
1
+ import { t as files } from "./files-QRV55OCx.js";
2
2
  //#region src/loaders/json.ts
3
3
  function json(options = {}) {
4
4
  return files({
@@ -0,0 +1,10 @@
1
+ import { ht as WorkspaceSession } from "./types-60Yn149G.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 ADDED
@@ -0,0 +1,143 @@
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 CHANGED
@@ -1,31 +1,2 @@
1
- import { V as WorkspaceModuleOptions, h as ResolvedWorkspaceModuleOptions } from "./types-CwNcWTdt.js";
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 { n as workspaceNitroModule, t as workspaceNitro } from "./module-8LZUMEXC.js";
2
- export { workspaceNitroModule as default, workspaceNitro };
1
+ import { t as createWorkspaceNitroConfig } from "./vite-tbfDxtlu.js";
2
+ export { createWorkspaceNitroConfig };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { nt as WorkspaceModuleOptions } from "./types-60Yn149G.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-tbfDxtlu.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 };