@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
package/dist/module-8LZUMEXC.js
DELETED
|
@@ -1,922 +0,0 @@
|
|
|
1
|
-
import { i as normalizeSafeWorkspacePath } from "./path-BVv9OXhg.js";
|
|
2
|
-
import { i as createMemoryWorkspaceStore, n as normalizeWorkspaceStoreOptions } from "./provider-BZuKAV4e.js";
|
|
3
|
-
import { n as syncWorkspaceDefinition } from "./lifecycle-uD82JeGh.js";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
|
-
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
8
|
-
import { pathToFileURL } from "node:url";
|
|
9
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
10
|
-
import { resolveModulePath } from "exsolve";
|
|
11
|
-
import { createJiti } from "jiti";
|
|
12
|
-
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
13
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
14
|
-
function normalizeWindowsPath(input = "") {
|
|
15
|
-
if (!input) return input;
|
|
16
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
17
|
-
}
|
|
18
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
19
|
-
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
20
|
-
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
21
|
-
function cwd() {
|
|
22
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
23
|
-
return "/";
|
|
24
|
-
}
|
|
25
|
-
const resolve$1 = function(...arguments_) {
|
|
26
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
27
|
-
let resolvedPath = "";
|
|
28
|
-
let resolvedAbsolute = false;
|
|
29
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
30
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
31
|
-
if (!path || path.length === 0) continue;
|
|
32
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
33
|
-
resolvedAbsolute = isAbsolute(path);
|
|
34
|
-
}
|
|
35
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
36
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
|
|
37
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
38
|
-
};
|
|
39
|
-
function normalizeString(path, allowAboveRoot) {
|
|
40
|
-
let res = "";
|
|
41
|
-
let lastSegmentLength = 0;
|
|
42
|
-
let lastSlash = -1;
|
|
43
|
-
let dots = 0;
|
|
44
|
-
let char = null;
|
|
45
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
46
|
-
if (index < path.length) char = path[index];
|
|
47
|
-
else if (char === "/") break;
|
|
48
|
-
else char = "/";
|
|
49
|
-
if (char === "/") {
|
|
50
|
-
if (lastSlash === index - 1 || dots === 1);
|
|
51
|
-
else if (dots === 2) {
|
|
52
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
53
|
-
if (res.length > 2) {
|
|
54
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
55
|
-
if (lastSlashIndex === -1) {
|
|
56
|
-
res = "";
|
|
57
|
-
lastSegmentLength = 0;
|
|
58
|
-
} else {
|
|
59
|
-
res = res.slice(0, lastSlashIndex);
|
|
60
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
61
|
-
}
|
|
62
|
-
lastSlash = index;
|
|
63
|
-
dots = 0;
|
|
64
|
-
continue;
|
|
65
|
-
} else if (res.length > 0) {
|
|
66
|
-
res = "";
|
|
67
|
-
lastSegmentLength = 0;
|
|
68
|
-
lastSlash = index;
|
|
69
|
-
dots = 0;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (allowAboveRoot) {
|
|
74
|
-
res += res.length > 0 ? "/.." : "..";
|
|
75
|
-
lastSegmentLength = 2;
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
79
|
-
else res = path.slice(lastSlash + 1, index);
|
|
80
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
81
|
-
}
|
|
82
|
-
lastSlash = index;
|
|
83
|
-
dots = 0;
|
|
84
|
-
} else if (char === "." && dots !== -1) ++dots;
|
|
85
|
-
else dots = -1;
|
|
86
|
-
}
|
|
87
|
-
return res;
|
|
88
|
-
}
|
|
89
|
-
const isAbsolute = function(p) {
|
|
90
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
91
|
-
};
|
|
92
|
-
const relative$1 = function(from, to) {
|
|
93
|
-
const _from = resolve$1(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
94
|
-
const _to = resolve$1(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
95
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
|
|
96
|
-
const _fromCopy = [..._from];
|
|
97
|
-
for (const segment of _fromCopy) {
|
|
98
|
-
if (_to[0] !== segment) break;
|
|
99
|
-
_from.shift();
|
|
100
|
-
_to.shift();
|
|
101
|
-
}
|
|
102
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
103
|
-
};
|
|
104
|
-
const dirname$1 = function(p) {
|
|
105
|
-
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
106
|
-
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
107
|
-
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
108
|
-
};
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region ../internal/src/build/paths.ts
|
|
111
|
-
function generatedDirSegments(productName) {
|
|
112
|
-
return [".vitehub", productName];
|
|
113
|
-
}
|
|
114
|
-
function createImportPath(fromFile, targetFile) {
|
|
115
|
-
const importPath = relative$1(realpathIfExists(dirname$1(fromFile)), realpathIfExists(targetFile));
|
|
116
|
-
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
117
|
-
}
|
|
118
|
-
function realpathIfExists(path) {
|
|
119
|
-
try {
|
|
120
|
-
return realpathSync.native(path);
|
|
121
|
-
} catch {
|
|
122
|
-
return resolve$1(path);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region ../internal/src/definition-catalog.ts
|
|
127
|
-
const sourceFilePattern = /\.(?:c|m)?[jt]s$/i;
|
|
128
|
-
const declarationFilePattern = /\.d\.(?:c|m)?[jt]s$/i;
|
|
129
|
-
const ignoredDirs = new Set([
|
|
130
|
-
"node_modules",
|
|
131
|
-
"dist",
|
|
132
|
-
".nitro",
|
|
133
|
-
".output",
|
|
134
|
-
".nuxt",
|
|
135
|
-
".vercel",
|
|
136
|
-
".git",
|
|
137
|
-
".vitehub"
|
|
138
|
-
]);
|
|
139
|
-
function createDirectoryDefinitionSource(source, scanDirs, subdir, options = {}) {
|
|
140
|
-
return {
|
|
141
|
-
...options,
|
|
142
|
-
kind: "directory",
|
|
143
|
-
scanDirs,
|
|
144
|
-
source,
|
|
145
|
-
subdir
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function createSuffixDefinitionSource(source, roots, pattern, normalizeName, options = {}) {
|
|
149
|
-
return {
|
|
150
|
-
...options,
|
|
151
|
-
kind: "suffix",
|
|
152
|
-
normalizeName,
|
|
153
|
-
pattern,
|
|
154
|
-
roots,
|
|
155
|
-
source
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function readDirEntries(root) {
|
|
159
|
-
try {
|
|
160
|
-
return readdirSync(root, { withFileTypes: true });
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if (error.code === "ENOENT") return [];
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function listMatchingFiles(root, predicate, options = {}) {
|
|
167
|
-
const files = [];
|
|
168
|
-
for (const entry of readDirEntries(root)) {
|
|
169
|
-
const absolute = resolve$1(root, entry.name);
|
|
170
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
171
|
-
if (entry.name.startsWith(".")) continue;
|
|
172
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
173
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
177
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
178
|
-
}
|
|
179
|
-
return files.sort();
|
|
180
|
-
}
|
|
181
|
-
function listSourceFiles(root, options = {}) {
|
|
182
|
-
return listMatchingFiles(root, (name) => sourceFilePattern.test(name) && !declarationFilePattern.test(name), options);
|
|
183
|
-
}
|
|
184
|
-
function normalizePathDefinitionName(rootDir, file) {
|
|
185
|
-
return relative$1(rootDir, file).replace(sourceFilePattern, "").replace(/\/index$/i, "");
|
|
186
|
-
}
|
|
187
|
-
function normalizeSuffixDefinitionName(rootDir, file, pattern, options = {}) {
|
|
188
|
-
const normalized = relative$1(rootDir, file).replace(pattern, "");
|
|
189
|
-
if (options.stripPrefix && normalized.startsWith(options.stripPrefix)) return normalized.slice(options.stripPrefix.length);
|
|
190
|
-
return normalized;
|
|
191
|
-
}
|
|
192
|
-
function sortDefinitions(definitions) {
|
|
193
|
-
return [...definitions.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
194
|
-
}
|
|
195
|
-
function registerDefinition(definitions, definition, sourceLabel) {
|
|
196
|
-
const existing = definitions.get(definition.name);
|
|
197
|
-
if (existing) throw new Error(`Duplicate ${sourceLabel} name "${definition.name}":\n - ${existing.handler}\n - ${definition.handler}`);
|
|
198
|
-
definitions.set(definition.name, definition);
|
|
199
|
-
}
|
|
200
|
-
function mergeDefinitions(feature, ...sources) {
|
|
201
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
202
|
-
for (const source of sources) {
|
|
203
|
-
if (!source) continue;
|
|
204
|
-
for (const definition of source) {
|
|
205
|
-
const existing = definitions.get(definition.name);
|
|
206
|
-
if (existing && existing.handler !== definition.handler) throw new Error(`Duplicate ${feature} name "${definition.name}" from multiple discovery sources:\n - ${existing.handler} (${existing.source ?? "unknown"})\n - ${definition.handler} (${definition.source ?? "unknown"})`);
|
|
207
|
-
if (!existing) definitions.set(definition.name, definition);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return sortDefinitions(definitions);
|
|
211
|
-
}
|
|
212
|
-
function createDefinition(source, file, name) {
|
|
213
|
-
if (source.createDefinition) return source.createDefinition({
|
|
214
|
-
file,
|
|
215
|
-
name
|
|
216
|
-
});
|
|
217
|
-
return {
|
|
218
|
-
handler: file,
|
|
219
|
-
name,
|
|
220
|
-
source: source.source
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function scanSuffixDefinitions(feature, source) {
|
|
224
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
225
|
-
for (const root of source.roots) for (const file of listMatchingFiles(root, (name) => source.pattern.test(name), { includeHidden: source.includeHidden })) {
|
|
226
|
-
const name = source.normalizeName(root, file);
|
|
227
|
-
if (!name) continue;
|
|
228
|
-
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
229
|
-
}
|
|
230
|
-
return sortDefinitions(definitions);
|
|
231
|
-
}
|
|
232
|
-
function scanDirectoryDefinitions(feature, source) {
|
|
233
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
234
|
-
for (const scanDir of source.scanDirs) {
|
|
235
|
-
const directory = resolve$1(scanDir, source.subdir);
|
|
236
|
-
for (const file of listSourceFiles(directory, { includeHidden: source.includeHidden })) {
|
|
237
|
-
const name = source.normalizeName ? source.normalizeName(directory, file) : normalizePathDefinitionName(directory, file);
|
|
238
|
-
if (!name) continue;
|
|
239
|
-
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return sortDefinitions(definitions);
|
|
243
|
-
}
|
|
244
|
-
function discoverDefinitions(feature, sources) {
|
|
245
|
-
return mergeDefinitions(feature, ...sources.map((source) => source.kind === "suffix" ? scanSuffixDefinitions(feature, source) : scanDirectoryDefinitions(feature, source)));
|
|
246
|
-
}
|
|
247
|
-
function createGeneratedDefinitionPath(rootDir, options) {
|
|
248
|
-
const segments = options.segments ?? generatedDirSegments(options.productName);
|
|
249
|
-
return resolve$1(...options.buildDir ? [
|
|
250
|
-
rootDir,
|
|
251
|
-
options.buildDir,
|
|
252
|
-
...segments,
|
|
253
|
-
options.fileName
|
|
254
|
-
] : [
|
|
255
|
-
rootDir,
|
|
256
|
-
...segments,
|
|
257
|
-
options.fileName
|
|
258
|
-
]);
|
|
259
|
-
}
|
|
260
|
-
function createNitroRuntimeFilePath(rootDir, options) {
|
|
261
|
-
return createGeneratedDefinitionPath(rootDir, options);
|
|
262
|
-
}
|
|
263
|
-
function applyNitroRuntimeAliases(nitro, aliases) {
|
|
264
|
-
nitro.options.alias ||= {};
|
|
265
|
-
Object.assign(nitro.options.alias, aliases);
|
|
266
|
-
}
|
|
267
|
-
function hookNitroRuntimeRegistryRefresh(nitro, refresh, onRefresh = () => {}) {
|
|
268
|
-
for (const hookName of ["build:before", "dev:reload"]) nitro.hooks.hook(hookName, async () => {
|
|
269
|
-
await onRefresh(await refresh(), hookName);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
async function writeFileIfChanged(file, contents) {
|
|
273
|
-
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
274
|
-
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
275
|
-
await writeFile(file, contents, "utf8");
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region ../internal/src/feature-bridge/hosting.ts
|
|
279
|
-
function normalizeHosting(hosting) {
|
|
280
|
-
const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
|
|
281
|
-
if (normalized === "cloudflare") return "cloudflare-module";
|
|
282
|
-
return normalized;
|
|
283
|
-
}
|
|
284
|
-
function detectHosting(target) {
|
|
285
|
-
return normalizeHosting(target.options.nitro?.preset || target.options.preset || detectPresetArg() || process.env.NITRO_PRESET || process.env.VITEHUB_HOSTING || "");
|
|
286
|
-
}
|
|
287
|
-
function detectPresetArg() {
|
|
288
|
-
const argv = process.argv || [];
|
|
289
|
-
for (let index = 0; index < argv.length; index++) {
|
|
290
|
-
const arg = argv[index];
|
|
291
|
-
if (arg === "--preset") return argv[index + 1] || "";
|
|
292
|
-
if (arg?.startsWith("--preset=")) return arg.slice(9);
|
|
293
|
-
}
|
|
294
|
-
return "";
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region ../internal/src/nitro.ts
|
|
298
|
-
function resolveRuntimeEntry$1(srcRelative, packageSubpath, importMetaUrl) {
|
|
299
|
-
return resolveModulePath(srcRelative, {
|
|
300
|
-
extensions: [".ts", ".mts"],
|
|
301
|
-
from: importMetaUrl,
|
|
302
|
-
try: true
|
|
303
|
-
}) ?? resolveModulePath(packageSubpath, {
|
|
304
|
-
extensions: [".js", ".mjs"],
|
|
305
|
-
from: importMetaUrl
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
function isPromiseLike(value) {
|
|
309
|
-
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
310
|
-
}
|
|
311
|
-
async function hasNamedVitePlugin(plugin, name) {
|
|
312
|
-
if (isPromiseLike(plugin)) return hasNamedVitePlugin(await plugin, name);
|
|
313
|
-
if (Array.isArray(plugin)) {
|
|
314
|
-
for (const entry of plugin) if (await hasNamedVitePlugin(entry, name)) return true;
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === name;
|
|
318
|
-
}
|
|
319
|
-
async function assertNoVitePlugin(vite, vitePluginName, integrationName) {
|
|
320
|
-
if (await hasNamedVitePlugin(vite?.plugins, vitePluginName)) throw new Error(`[vitehub] Do not configure ${vitePluginName} when using ${integrationName}.`);
|
|
321
|
-
}
|
|
322
|
-
async function assertNoVitePluginInNitro(nitro, vitePluginName, integrationName) {
|
|
323
|
-
await assertNoVitePlugin(nitro.options.vite, vitePluginName, integrationName);
|
|
324
|
-
}
|
|
325
|
-
function mergeNitroImportsPreset(current, preset) {
|
|
326
|
-
if (current === false) return current;
|
|
327
|
-
const existing = current || {};
|
|
328
|
-
const presets = Array.isArray(existing.presets) ? [...existing.presets] : [];
|
|
329
|
-
const found = presets.find((entry) => entry?.from === preset.from);
|
|
330
|
-
if (found && Array.isArray(found.imports)) {
|
|
331
|
-
const seen = new Set(found.imports);
|
|
332
|
-
found.imports.push(...preset.imports.filter((name) => !seen.has(name)));
|
|
333
|
-
} else if (!found) presets.push({
|
|
334
|
-
from: preset.from,
|
|
335
|
-
imports: [...preset.imports]
|
|
336
|
-
});
|
|
337
|
-
return {
|
|
338
|
-
...existing,
|
|
339
|
-
presets
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
//#endregion
|
|
343
|
-
//#region src/build/assets.ts
|
|
344
|
-
function shouldBundleWorkspaceAssets(assets, name) {
|
|
345
|
-
return assets === void 0 || assets === true || Array.isArray(assets) && assets.includes(name);
|
|
346
|
-
}
|
|
347
|
-
function assetModuleName(workspace, path, content) {
|
|
348
|
-
return `${createHash("sha256").update(`${workspace}\0${path}\0`).update(content).digest("hex").slice(0, 16)}.mjs`;
|
|
349
|
-
}
|
|
350
|
-
function serializeContent(content) {
|
|
351
|
-
if (typeof content === "string") return JSON.stringify(content);
|
|
352
|
-
return `new Uint8Array(${JSON.stringify([...content])})`;
|
|
353
|
-
}
|
|
354
|
-
const workspaceConfigLoader = createJiti(import.meta.url, { moduleCache: false });
|
|
355
|
-
async function importWorkspaceConfig(path) {
|
|
356
|
-
return await workspaceConfigLoader.import(path);
|
|
357
|
-
}
|
|
358
|
-
function runtimeAssetsModulePath() {
|
|
359
|
-
return resolveRuntimeEntry$1("../runtime/assets", "@vite-hub/workspace/internal/runtime/assets", import.meta.url);
|
|
360
|
-
}
|
|
361
|
-
async function collectWorkspaceStoreAssetBundle(name, store) {
|
|
362
|
-
const entries = (await store.glob("**/*")).filter((entry) => entry.type === "file");
|
|
363
|
-
const files = [];
|
|
364
|
-
for (const entry of entries) {
|
|
365
|
-
const path = normalizeSafeWorkspacePath(entry.path);
|
|
366
|
-
const file = await store.readFile(path);
|
|
367
|
-
if (file) files.push({
|
|
368
|
-
content: file.content,
|
|
369
|
-
mediaType: file.mediaType,
|
|
370
|
-
path
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
374
|
-
return {
|
|
375
|
-
files,
|
|
376
|
-
name
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
async function syncDiscoveredWorkspaceAssetBundles(definitions, rootDir, options) {
|
|
380
|
-
if (!options) return [];
|
|
381
|
-
const bundles = [];
|
|
382
|
-
for (const definition of definitions) {
|
|
383
|
-
if (!shouldBundleWorkspaceAssets(options.assets, definition.name)) continue;
|
|
384
|
-
const mod = await importWorkspaceConfig(definition.path);
|
|
385
|
-
if (!mod.default) throw new TypeError(`[vitehub] Workspace definition "${definition.name}" has no default export.`);
|
|
386
|
-
const store = createMemoryWorkspaceStore();
|
|
387
|
-
await syncWorkspaceDefinition({
|
|
388
|
-
...mod.default,
|
|
389
|
-
name: definition.name,
|
|
390
|
-
rootDir: mod.default.rootDir || rootDir,
|
|
391
|
-
sourceRootDir: mod.default.sourceRootDir ?? definition.sourceRootDir,
|
|
392
|
-
store
|
|
393
|
-
}, store);
|
|
394
|
-
bundles.push(await collectWorkspaceStoreAssetBundle(definition.name, store));
|
|
395
|
-
}
|
|
396
|
-
return bundles;
|
|
397
|
-
}
|
|
398
|
-
async function writeWorkspaceAssetsRegistry(registryFile, bundles) {
|
|
399
|
-
const modulesDir = join(dirname(registryFile), "modules");
|
|
400
|
-
await rm(modulesDir, {
|
|
401
|
-
force: true,
|
|
402
|
-
recursive: true
|
|
403
|
-
});
|
|
404
|
-
await mkdir(modulesDir, { recursive: true });
|
|
405
|
-
const modulePaths = /* @__PURE__ */ new Map();
|
|
406
|
-
for (const bundle of bundles) {
|
|
407
|
-
const workspaceDir = join(modulesDir, encodeURIComponent(bundle.name));
|
|
408
|
-
await mkdir(workspaceDir, { recursive: true });
|
|
409
|
-
for (const file of bundle.files) {
|
|
410
|
-
const modulePath = join(workspaceDir, assetModuleName(bundle.name, file.path, file.content));
|
|
411
|
-
await writeFile(modulePath, `export default ${serializeContent(file.content)}\n`, "utf8");
|
|
412
|
-
modulePaths.set(`${bundle.name}\0${file.path}`, modulePath);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
await mkdir(dirname(registryFile), { recursive: true });
|
|
416
|
-
const contents = createWorkspaceAssetsRegistryContents(registryFile, bundles, modulePaths);
|
|
417
|
-
await writeFile(registryFile, contents, "utf8");
|
|
418
|
-
return contents;
|
|
419
|
-
}
|
|
420
|
-
function createWorkspaceAssetsRegistryContents(registryFile, bundles, modulePaths = /* @__PURE__ */ new Map(), assetsModulePath = runtimeAssetsModulePath()) {
|
|
421
|
-
return [
|
|
422
|
-
`import { createWorkspaceAssets } from ${JSON.stringify(createImportPath(registryFile, assetsModulePath))}`,
|
|
423
|
-
"",
|
|
424
|
-
"const registry = {",
|
|
425
|
-
...bundles.map((bundle) => {
|
|
426
|
-
const entries = bundle.files.map((file) => {
|
|
427
|
-
const modulePath = modulePaths.get(`${bundle.name}\0${file.path}`);
|
|
428
|
-
const importPath = modulePath ? createImportPath(registryFile, modulePath) : pathToFileURL(file.path).href;
|
|
429
|
-
return ` ${JSON.stringify(file.path)}: { load: async () => (await import(${JSON.stringify(importPath)})).default, mediaType: ${JSON.stringify(file.mediaType)} },`;
|
|
430
|
-
});
|
|
431
|
-
return [
|
|
432
|
-
` ${JSON.stringify(bundle.name)}: createWorkspaceAssets({`,
|
|
433
|
-
...entries,
|
|
434
|
-
" }),"
|
|
435
|
-
].join("\n");
|
|
436
|
-
}),
|
|
437
|
-
"}",
|
|
438
|
-
"export default registry",
|
|
439
|
-
""
|
|
440
|
-
].join("\n");
|
|
441
|
-
}
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region src/build/workspace-config.ts
|
|
444
|
-
const workspaceSuffixPattern = /\.workspace\.(?:c|m)?[jt]s$/i;
|
|
445
|
-
const workspaceConfigPattern = /^config\.(?:c|m)?[jt]s$/i;
|
|
446
|
-
//#endregion
|
|
447
|
-
//#region src/build/discovery.ts
|
|
448
|
-
const configFileNameSet = new Set([
|
|
449
|
-
"config.ts",
|
|
450
|
-
"config.mts",
|
|
451
|
-
"config.cts",
|
|
452
|
-
"config.js",
|
|
453
|
-
"config.mjs",
|
|
454
|
-
"config.cjs"
|
|
455
|
-
]);
|
|
456
|
-
function stripComments(source) {
|
|
457
|
-
return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
458
|
-
}
|
|
459
|
-
function isAgentConfig(file) {
|
|
460
|
-
return /\bdefineAgent\s*\(/.test(stripComments(readFileSync(file, "utf8")));
|
|
461
|
-
}
|
|
462
|
-
function isWorkspaceAgentConfig(file) {
|
|
463
|
-
return /\bdefineAgent\s*\(\s*\{[\s\S]*?\bworkspace\s*:/.test(stripComments(readFileSync(file, "utf8")));
|
|
464
|
-
}
|
|
465
|
-
function collectDirectoriesWithConfig(root) {
|
|
466
|
-
const directories = /* @__PURE__ */ new Set();
|
|
467
|
-
const walk = (current) => {
|
|
468
|
-
let entries;
|
|
469
|
-
try {
|
|
470
|
-
entries = readdirSync(current, { withFileTypes: true });
|
|
471
|
-
} catch (error) {
|
|
472
|
-
if (error.code === "ENOENT") return;
|
|
473
|
-
throw error;
|
|
474
|
-
}
|
|
475
|
-
if (entries.some((entry) => entry.isFile() && configFileNameSet.has(entry.name))) directories.add(current.replace(/\\/g, "/"));
|
|
476
|
-
for (const entry of entries) {
|
|
477
|
-
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
478
|
-
walk(resolve(current, entry.name));
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
walk(root);
|
|
482
|
-
return directories;
|
|
483
|
-
}
|
|
484
|
-
function resolveWorkspaceSourceRoot(file) {
|
|
485
|
-
const directory = dirname(file);
|
|
486
|
-
const workspaceDirectory = resolve(directory, "workspace");
|
|
487
|
-
try {
|
|
488
|
-
return statSync(workspaceDirectory).isDirectory() ? workspaceDirectory : directory;
|
|
489
|
-
} catch (error) {
|
|
490
|
-
if (error.code === "ENOENT") return directory;
|
|
491
|
-
throw error;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function createWorkspaceDefinition(source, file, name) {
|
|
495
|
-
return {
|
|
496
|
-
handler: file,
|
|
497
|
-
name,
|
|
498
|
-
path: file,
|
|
499
|
-
source,
|
|
500
|
-
sourceRootDir: resolveWorkspaceSourceRoot(file)
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
function nitroWorkspaceSource(rootDir) {
|
|
504
|
-
const workspacesDir = resolve(rootDir, "server", "workspaces");
|
|
505
|
-
const agentsDir = resolve(rootDir, "server", "agents");
|
|
506
|
-
const directoryWorkspaceDirs = collectDirectoriesWithConfig(workspacesDir);
|
|
507
|
-
const normalizeDirectoryName = (workspacesRoot, file) => {
|
|
508
|
-
if (!workspaceConfigPattern.test(basename(file))) return;
|
|
509
|
-
const name = relative(workspacesRoot, dirname(file)).replace(/\\/g, "/");
|
|
510
|
-
return name && name !== "." ? name : void 0;
|
|
511
|
-
};
|
|
512
|
-
const isInsideDirectoryWorkspace = (file) => {
|
|
513
|
-
let current = dirname(file).replace(/\\/g, "/");
|
|
514
|
-
const stop = workspacesDir.replace(/\\/g, "/");
|
|
515
|
-
while (current.startsWith(stop) && current !== stop) {
|
|
516
|
-
if (directoryWorkspaceDirs.has(current)) return true;
|
|
517
|
-
current = dirname(current);
|
|
518
|
-
}
|
|
519
|
-
return false;
|
|
520
|
-
};
|
|
521
|
-
const normalizeFlatName = (workspacesRoot, file) => {
|
|
522
|
-
if (workspaceConfigPattern.test(basename(file))) return;
|
|
523
|
-
if (isInsideDirectoryWorkspace(file)) return;
|
|
524
|
-
return normalizePathDefinitionName(workspacesRoot, file);
|
|
525
|
-
};
|
|
526
|
-
return [
|
|
527
|
-
createDirectoryDefinitionSource("nitro-server-workspaces-directory-config", [resolve(rootDir, "server")], "workspaces", {
|
|
528
|
-
includeHidden: true,
|
|
529
|
-
normalizeName: normalizeDirectoryName,
|
|
530
|
-
createDefinition: ({ file, name }) => {
|
|
531
|
-
if (isAgentConfig(file)) throw new Error(`[vitehub] Workspace config "${file}" must use defineWorkspace(); defineAgent() belongs in server/agents/<name>/config.ts.`);
|
|
532
|
-
return createWorkspaceDefinition("nitro-server-workspaces-directory-config", file, name);
|
|
533
|
-
}
|
|
534
|
-
}),
|
|
535
|
-
createDirectoryDefinitionSource("nitro-server-agent-workspaces", [resolve(rootDir, "server")], "agents", {
|
|
536
|
-
includeHidden: true,
|
|
537
|
-
normalizeName(_agentsRoot, file) {
|
|
538
|
-
if (!workspaceConfigPattern.test(basename(file))) return;
|
|
539
|
-
if (!isWorkspaceAgentConfig(file)) return;
|
|
540
|
-
const name = relative(agentsDir, dirname(file)).replace(/\\/g, "/");
|
|
541
|
-
return name && name !== "." ? name : void 0;
|
|
542
|
-
},
|
|
543
|
-
createDefinition: ({ file, name }) => createWorkspaceDefinition("nitro-server-agent-workspaces", file, name)
|
|
544
|
-
}),
|
|
545
|
-
createDirectoryDefinitionSource("nitro-server-workspaces", [resolve(rootDir, "server")], "workspaces", {
|
|
546
|
-
normalizeName: normalizeFlatName,
|
|
547
|
-
createDefinition: ({ file, name }) => createWorkspaceDefinition("nitro-server-workspaces", file, name)
|
|
548
|
-
})
|
|
549
|
-
];
|
|
550
|
-
}
|
|
551
|
-
function viteWorkspaceSource(rootDir) {
|
|
552
|
-
return [createSuffixDefinitionSource("vite-workspace-suffix", [rootDir], workspaceSuffixPattern, (root, file) => normalizeSuffixDefinitionName(root, file, workspaceSuffixPattern, { stripPrefix: "src/" }), { createDefinition: ({ file, name }) => createWorkspaceDefinition("vite-workspace-suffix", file, name) })];
|
|
553
|
-
}
|
|
554
|
-
function discoverNitroWorkspaceDefinitions(rootDir) {
|
|
555
|
-
return discoverDefinitions("workspace", [...nitroWorkspaceSource(rootDir)]);
|
|
556
|
-
}
|
|
557
|
-
function discoverViteWorkspaceDefinitions(rootDir) {
|
|
558
|
-
return discoverDefinitions("workspace", [...viteWorkspaceSource(rootDir)]);
|
|
559
|
-
}
|
|
560
|
-
function createWorkspaceRegistryEntry(definition, importExpression) {
|
|
561
|
-
return [
|
|
562
|
-
` ${JSON.stringify(definition.name)}: async () => {`,
|
|
563
|
-
` const mod = await ${importExpression}`,
|
|
564
|
-
definition.sourceRootDir ? ` return { ...mod, default: { ...mod.default, sourceRootDir: mod.default.sourceRootDir ?? ${JSON.stringify(definition.sourceRootDir)} } }` : " return mod",
|
|
565
|
-
" },"
|
|
566
|
-
].join("\n");
|
|
567
|
-
}
|
|
568
|
-
function createWorkspaceRegistryContents(registryFile, definitions) {
|
|
569
|
-
const importExpression = (file) => {
|
|
570
|
-
const importPath = relative(resolve(registryFile, ".."), file);
|
|
571
|
-
return `import(${JSON.stringify(importPath.startsWith(".") ? importPath : `./${importPath}`)})`;
|
|
572
|
-
};
|
|
573
|
-
return [
|
|
574
|
-
"const registry = {",
|
|
575
|
-
...definitions.map((definition) => createWorkspaceRegistryEntry(definition, importExpression(definition.handler))),
|
|
576
|
-
"}",
|
|
577
|
-
"export default registry",
|
|
578
|
-
""
|
|
579
|
-
].join("\n");
|
|
580
|
-
}
|
|
581
|
-
function createWorkspaceVirtualRegistryContents(definitions) {
|
|
582
|
-
return [
|
|
583
|
-
"const registry = {",
|
|
584
|
-
...definitions.map((definition) => createWorkspaceRegistryEntry(definition, `import(${JSON.stringify(pathToFileURL(definition.path).href)})`)),
|
|
585
|
-
"}",
|
|
586
|
-
"export default registry",
|
|
587
|
-
""
|
|
588
|
-
].join("\n");
|
|
589
|
-
}
|
|
590
|
-
async function createWorkspaceManifest(definitions) {
|
|
591
|
-
return { workspaces: definitions.map((definition) => ({ name: definition.name })) };
|
|
592
|
-
}
|
|
593
|
-
//#endregion
|
|
594
|
-
//#region src/build/generated-types.ts
|
|
595
|
-
function createWorkspaceTypeAugmentation(definitions) {
|
|
596
|
-
const nameProperties = [...new Set(definitions.map((definition) => definition.name))].sort().map((name) => ` ${JSON.stringify(name)}: true`);
|
|
597
|
-
return [
|
|
598
|
-
"declare global {",
|
|
599
|
-
" interface ViteHubWorkspaceNameMap {",
|
|
600
|
-
...nameProperties.length ? nameProperties : [" __vitehub_no_workspaces__?: never"],
|
|
601
|
-
" }",
|
|
602
|
-
"",
|
|
603
|
-
" interface ViteHubWorkspaceAssetMap {",
|
|
604
|
-
" __vitehub_no_workspace_assets__?: never",
|
|
605
|
-
" }",
|
|
606
|
-
"}",
|
|
607
|
-
"",
|
|
608
|
-
"export {}",
|
|
609
|
-
""
|
|
610
|
-
].join("\n");
|
|
611
|
-
}
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region src/build/integration.ts
|
|
614
|
-
function workspaceAmbientTypesPath(root) {
|
|
615
|
-
return existsSync(resolve(root, "src")) ? resolve(root, "src", "vitehub-workspace.d.ts") : resolve(root, "vitehub-workspace.d.ts");
|
|
616
|
-
}
|
|
617
|
-
async function createWorkspaceBuildState(definitions) {
|
|
618
|
-
return {
|
|
619
|
-
manifest: await createWorkspaceManifest(definitions),
|
|
620
|
-
registryContents: createWorkspaceVirtualRegistryContents(definitions)
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
async function refreshWorkspaceAmbientTypes(root, definitions) {
|
|
624
|
-
await writeFileIfChanged(workspaceAmbientTypesPath(root), createWorkspaceTypeAugmentation(definitions));
|
|
625
|
-
}
|
|
626
|
-
async function refreshWorkspaceBuildState(root, definitions) {
|
|
627
|
-
const state = await createWorkspaceBuildState(definitions);
|
|
628
|
-
await refreshWorkspaceAmbientTypes(root, definitions);
|
|
629
|
-
return state;
|
|
630
|
-
}
|
|
631
|
-
async function writeWorkspaceRuntimeRegistry(registryFile, definitions) {
|
|
632
|
-
await mkdir(dirname(registryFile), { recursive: true });
|
|
633
|
-
await writeFile(registryFile, createWorkspaceRegistryContents(registryFile, definitions), "utf8");
|
|
634
|
-
return registryFile;
|
|
635
|
-
}
|
|
636
|
-
async function initializeWorkspaceAssetRegistry(assetsRegistryFile, _definitions = [], _rootDir = process.cwd()) {
|
|
637
|
-
await writeWorkspaceAssetsRegistry(assetsRegistryFile, []);
|
|
638
|
-
}
|
|
639
|
-
async function syncWorkspaceBuildAssets(definitions, rootDir, options, assetsRegistryFile) {
|
|
640
|
-
await writeWorkspaceAssetsRegistry(assetsRegistryFile, mergeWorkspaceAssetBundles(await syncDiscoveredWorkspaceAssetBundles(definitions, rootDir, options)));
|
|
641
|
-
}
|
|
642
|
-
function mergeWorkspaceAssetBundles(bundles) {
|
|
643
|
-
const merged = /* @__PURE__ */ new Map();
|
|
644
|
-
for (const bundle of bundles) {
|
|
645
|
-
const existing = merged.get(bundle.name);
|
|
646
|
-
if (!existing) {
|
|
647
|
-
merged.set(bundle.name, {
|
|
648
|
-
files: [...bundle.files],
|
|
649
|
-
name: bundle.name
|
|
650
|
-
});
|
|
651
|
-
continue;
|
|
652
|
-
}
|
|
653
|
-
const files = new Map(existing.files.map((file) => [file.path, file]));
|
|
654
|
-
for (const file of bundle.files) files.set(file.path, file);
|
|
655
|
-
existing.files = [...files.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
656
|
-
}
|
|
657
|
-
return [...merged.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
658
|
-
}
|
|
659
|
-
//#endregion
|
|
660
|
-
//#region ../internal/src/object.ts
|
|
661
|
-
function isPlainObject(value) {
|
|
662
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
663
|
-
}
|
|
664
|
-
//#endregion
|
|
665
|
-
//#region src/config.ts
|
|
666
|
-
function normalizeWorkspaceOptions(options, input = {}) {
|
|
667
|
-
if (options === false) return false;
|
|
668
|
-
if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`workspace` must be a plain object.");
|
|
669
|
-
const resolvedOptions = options || {};
|
|
670
|
-
const rootDir = input.rootDir || process.cwd();
|
|
671
|
-
const root = resolvedOptions.root || ".vitehub/workspaces";
|
|
672
|
-
return {
|
|
673
|
-
assets: resolvedOptions.assets,
|
|
674
|
-
root: resolve(rootDir, root),
|
|
675
|
-
store: normalizeWorkspaceStoreOptions(resolvedOptions.store, input) || { provider: "local" }
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
//#endregion
|
|
679
|
-
//#region src/integrations/cloudflare.ts
|
|
680
|
-
function configureCloudflareArtifacts(target, config) {
|
|
681
|
-
if (!config) return;
|
|
682
|
-
const store = config.store;
|
|
683
|
-
if (store.provider !== "cloudflare-artifacts") return;
|
|
684
|
-
target.cloudflare ||= {};
|
|
685
|
-
target.cloudflare.wrangler ||= {};
|
|
686
|
-
const wrangler = target.cloudflare.wrangler;
|
|
687
|
-
const artifacts = wrangler.artifacts ||= [];
|
|
688
|
-
if (!artifacts.some((existing) => existing.binding === store.binding)) artifacts.push({
|
|
689
|
-
binding: store.binding || "WORKSPACE_ARTIFACTS",
|
|
690
|
-
namespace: store.namespace || "vitehub"
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
//#endregion
|
|
694
|
-
//#region src/hosts/nitro/module.ts
|
|
695
|
-
const WORKSPACE_NITRO_IMPORTS_PRESET = {
|
|
696
|
-
from: "@vite-hub/workspace",
|
|
697
|
-
imports: ["defineWorkspace", "useWorkspace"]
|
|
698
|
-
};
|
|
699
|
-
const WORKSPACE_VITE_PLUGIN_NAME = "@vite-hub/workspace/vite";
|
|
700
|
-
function resolveRuntimeEntry(srcRelative, packageSubpath) {
|
|
701
|
-
return resolveRuntimeEntry$1(srcRelative, packageSubpath, import.meta.url);
|
|
702
|
-
}
|
|
703
|
-
function resolveDependency(specifier) {
|
|
704
|
-
return createRequire(import.meta.url).resolve(specifier);
|
|
705
|
-
}
|
|
706
|
-
function resolveShellDependency(specifier) {
|
|
707
|
-
return createRequire(resolveDependency("@vite-hub/shell/package.json")).resolve(specifier);
|
|
708
|
-
}
|
|
709
|
-
function resolveShellTransitiveDependency(parentSpecifier, specifier) {
|
|
710
|
-
return createRequire(resolveShellDependency(parentSpecifier)).resolve(specifier);
|
|
711
|
-
}
|
|
712
|
-
function resolveJustBashNestedDependency(parentSpecifier, specifier) {
|
|
713
|
-
return createRequire(resolveShellTransitiveDependency("just-bash", parentSpecifier)).resolve(specifier);
|
|
714
|
-
}
|
|
715
|
-
function resolveIsomorphicGitDependency(specifier) {
|
|
716
|
-
return createRequire(resolveDependency("isomorphic-git")).resolve(specifier);
|
|
717
|
-
}
|
|
718
|
-
function resolveIsomorphicGitEsmEntry() {
|
|
719
|
-
return resolve(dirname(resolveDependency("isomorphic-git")), "index.js");
|
|
720
|
-
}
|
|
721
|
-
function resolveIsomorphicGitHttpWebEsmEntry() {
|
|
722
|
-
return resolve(dirname(resolveDependency("isomorphic-git/http/web")), "index.js");
|
|
723
|
-
}
|
|
724
|
-
function registryPath(nitro) {
|
|
725
|
-
return createNitroRuntimeFilePath(nitro.options.rootDir, {
|
|
726
|
-
fileName: "registry.mjs",
|
|
727
|
-
segments: [
|
|
728
|
-
".vitehub",
|
|
729
|
-
"nitro-runtime",
|
|
730
|
-
"workspace"
|
|
731
|
-
]
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
function pluginPath(nitro) {
|
|
735
|
-
return createNitroRuntimeFilePath(nitro.options.rootDir, {
|
|
736
|
-
fileName: "plugin.mjs",
|
|
737
|
-
segments: [
|
|
738
|
-
".vitehub",
|
|
739
|
-
"nitro-runtime",
|
|
740
|
-
"workspace"
|
|
741
|
-
]
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
function assetsRegistryPath(nitro) {
|
|
745
|
-
return createNitroRuntimeFilePath(nitro.options.rootDir, {
|
|
746
|
-
fileName: "assets/registry.mjs",
|
|
747
|
-
segments: [
|
|
748
|
-
".vitehub",
|
|
749
|
-
"nitro-runtime",
|
|
750
|
-
"workspace"
|
|
751
|
-
]
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
function workspaceNitroConfigTypes(definitions) {
|
|
755
|
-
return `import type { ResolvedWorkspaceModuleOptions, WorkspaceModuleOptions } from "@vite-hub/workspace"
|
|
756
|
-
|
|
757
|
-
declare module "nitro/types" {
|
|
758
|
-
interface NitroConfig {
|
|
759
|
-
workspace?: false | WorkspaceModuleOptions
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
interface NitroOptions {
|
|
763
|
-
workspace?: false | WorkspaceModuleOptions
|
|
764
|
-
cloudflare?: { wrangler?: { artifacts?: Array<{ binding: string, namespace: string }> } }
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
interface NitroRuntimeConfig {
|
|
768
|
-
hosting?: string
|
|
769
|
-
workspace?: false | ResolvedWorkspaceModuleOptions
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
declare module "nitropack/types" {
|
|
774
|
-
interface NitroConfig {
|
|
775
|
-
workspace?: false | WorkspaceModuleOptions
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
interface NitroOptions {
|
|
779
|
-
workspace?: false | WorkspaceModuleOptions
|
|
780
|
-
cloudflare?: { wrangler?: { artifacts?: Array<{ binding: string, namespace: string }> } }
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
interface NitroRuntimeConfig {
|
|
784
|
-
hosting?: string
|
|
785
|
-
workspace?: false | ResolvedWorkspaceModuleOptions
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
${createWorkspaceTypeAugmentation(definitions)}
|
|
790
|
-
|
|
791
|
-
export {}
|
|
792
|
-
`;
|
|
793
|
-
}
|
|
794
|
-
function installNitroConfigTypes(nitro, getDefinitions) {
|
|
795
|
-
nitro.hooks.hook("types:extend", async (types) => {
|
|
796
|
-
const dtsPath = resolve(nitro.options.buildDir, "types", "vitehub-workspace-nitro.d.ts");
|
|
797
|
-
await writeFileIfChanged(dtsPath, workspaceNitroConfigTypes(getDefinitions()));
|
|
798
|
-
if (types.tsConfig) {
|
|
799
|
-
types.tsConfig.include ||= [];
|
|
800
|
-
types.tsConfig.include.push(dtsPath);
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
function createNitroPluginContents(file, registryFile, assetsRegistryFile, options) {
|
|
805
|
-
const provider = options && options.store.provider;
|
|
806
|
-
const imports = [
|
|
807
|
-
`import { definePlugin as defineNitroPlugin } from "nitro"`,
|
|
808
|
-
`import { useRuntimeConfig } from "nitro/runtime-config"`,
|
|
809
|
-
`import workspaceRegistry from ${JSON.stringify(createImportPath(file, registryFile))}`,
|
|
810
|
-
`import workspaceAssetsRegistry from ${JSON.stringify(createImportPath(file, assetsRegistryFile))}`,
|
|
811
|
-
`import { setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry } from ${JSON.stringify(createImportPath(file, resolveRuntimeEntry("../runtime/state", "@vite-hub/workspace/internal/runtime/state")))}`
|
|
812
|
-
];
|
|
813
|
-
if (provider === "cloudflare-artifacts") imports.push(`import { createCloudflareArtifactsWorkspaceStore } from ${JSON.stringify(createImportPath(file, resolveRuntimeEntry("../../providers/cloudflare/artifacts-store", "@vite-hub/workspace/internal/stores/cloudflare-artifacts")))}`);
|
|
814
|
-
else if (provider === "vercel-blob") imports.push(`import { createVercelBlobWorkspaceStore } from ${JSON.stringify(createImportPath(file, resolveRuntimeEntry("../../providers/vercel/blob-store", "@vite-hub/workspace/internal/stores/vercel-blob")))}`);
|
|
815
|
-
const loader = provider === "cloudflare-artifacts" ? [
|
|
816
|
-
" setWorkspaceHostedStoreLoader((store, workspaceName) => {",
|
|
817
|
-
" if (store.provider !== 'cloudflare-artifacts') throw new Error(`[vitehub] Unsupported workspace store for Cloudflare build: ${store.provider}`)",
|
|
818
|
-
" return createCloudflareArtifactsWorkspaceStore(store, workspaceName)",
|
|
819
|
-
" })"
|
|
820
|
-
] : provider === "vercel-blob" ? [
|
|
821
|
-
" setWorkspaceHostedStoreLoader((store, workspaceName) => {",
|
|
822
|
-
" if (store.provider !== 'vercel-blob') throw new Error(`[vitehub] Unsupported workspace store for Vercel build: ${store.provider}`)",
|
|
823
|
-
" return createVercelBlobWorkspaceStore(store, workspaceName)",
|
|
824
|
-
" })"
|
|
825
|
-
] : [" setWorkspaceHostedStoreLoader(undefined)"];
|
|
826
|
-
return [
|
|
827
|
-
...imports,
|
|
828
|
-
"",
|
|
829
|
-
"export default defineNitroPlugin(() => {",
|
|
830
|
-
" const runtimeConfig = useRuntimeConfig()",
|
|
831
|
-
" setWorkspaceRuntimeConfig(runtimeConfig.workspace || false)",
|
|
832
|
-
...loader,
|
|
833
|
-
" setWorkspaceRuntimeRegistry(workspaceRegistry)",
|
|
834
|
-
" setWorkspaceRuntimeAssetsRegistry(workspaceAssetsRegistry)",
|
|
835
|
-
"})",
|
|
836
|
-
""
|
|
837
|
-
].join("\n");
|
|
838
|
-
}
|
|
839
|
-
async function writePlugin(nitro, registryFile, assetsRegistryFile, options) {
|
|
840
|
-
const path = pluginPath(nitro);
|
|
841
|
-
await writeFileIfChanged(path, createNitroPluginContents(path, registryFile, assetsRegistryFile, options));
|
|
842
|
-
return path;
|
|
843
|
-
}
|
|
844
|
-
function applyWorkspaceRuntimeAliases(nitro, registryFile, assetsRegistryFile) {
|
|
845
|
-
applyNitroRuntimeAliases(nitro, {
|
|
846
|
-
"#vitehub-workspace-assets-registry": assetsRegistryFile,
|
|
847
|
-
"#vitehub-workspace-registry": registryFile
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
function workspaceNitro(options) {
|
|
851
|
-
return {
|
|
852
|
-
name: "@vite-hub/workspace",
|
|
853
|
-
async setup(nitroInput) {
|
|
854
|
-
const nitro = nitroInput;
|
|
855
|
-
await assertNoVitePluginInNitro(nitro, WORKSPACE_VITE_PLUGIN_NAME, "@vite-hub/workspace/nitro");
|
|
856
|
-
const isDev = nitro.options.dev || process.env.VITEHUB_WORKSPACE_DEV === "true";
|
|
857
|
-
const hosting = detectHosting(nitro);
|
|
858
|
-
const resolved = normalizeWorkspaceOptions(options ?? nitro.options.workspace, {
|
|
859
|
-
dev: isDev,
|
|
860
|
-
env: process.env,
|
|
861
|
-
hosting,
|
|
862
|
-
rootDir: nitro.options.rootDir
|
|
863
|
-
});
|
|
864
|
-
const runtimeConfig = nitro.options.runtimeConfig ||= {};
|
|
865
|
-
if (hosting) runtimeConfig.hosting ||= hosting;
|
|
866
|
-
runtimeConfig.workspace = resolved;
|
|
867
|
-
nitro.options.alias ||= {};
|
|
868
|
-
nitro.options.alias["@vite-hub/workspace/internal/runtime/state"] = resolveRuntimeEntry("../runtime/state", "@vite-hub/workspace/internal/runtime/state");
|
|
869
|
-
nitro.options.alias["@vite-hub/workspace/loader"] = resolveRuntimeEntry("../loader", "@vite-hub/workspace/loader");
|
|
870
|
-
nitro.options.alias["@vite-hub/workspace/publish"] = resolveRuntimeEntry("../publish", "@vite-hub/workspace/publish");
|
|
871
|
-
nitro.options.alias["@vite-hub/workspace/test"] = resolveRuntimeEntry("../test", "@vite-hub/workspace/test");
|
|
872
|
-
nitro.options.alias["@vite-hub/workspace"] = resolveRuntimeEntry("../index", "@vite-hub/workspace");
|
|
873
|
-
nitro.options.alias["isomorphic-git/http/web"] = resolveIsomorphicGitHttpWebEsmEntry();
|
|
874
|
-
nitro.options.alias["isomorphic-git"] = resolveIsomorphicGitEsmEntry();
|
|
875
|
-
for (const dependency of [
|
|
876
|
-
"async-lock",
|
|
877
|
-
"clean-git-ref",
|
|
878
|
-
"crc-32",
|
|
879
|
-
"diff3",
|
|
880
|
-
"ignore",
|
|
881
|
-
"inherits",
|
|
882
|
-
"minimisted",
|
|
883
|
-
"pako",
|
|
884
|
-
"pify",
|
|
885
|
-
"readable-stream",
|
|
886
|
-
"sha.js/sha1.js",
|
|
887
|
-
"simple-get"
|
|
888
|
-
]) nitro.options.alias[dependency] = resolveIsomorphicGitDependency(dependency);
|
|
889
|
-
for (const dependency of ["sprintf-js", "turndown"]) nitro.options.alias[dependency] = resolveShellTransitiveDependency("just-bash", dependency);
|
|
890
|
-
nitro.options.alias["@mixmark-io/domino"] = resolveJustBashNestedDependency("turndown", "@mixmark-io/domino");
|
|
891
|
-
let definitions = discoverNitroWorkspaceDefinitions(nitro.options.rootDir);
|
|
892
|
-
const registryFile = await writeWorkspaceRuntimeRegistry(registryPath(nitro), definitions);
|
|
893
|
-
const assetsRegistryFile = assetsRegistryPath(nitro);
|
|
894
|
-
await initializeWorkspaceAssetRegistry(assetsRegistryFile, definitions, nitro.options.rootDir);
|
|
895
|
-
const plugin = await writePlugin(nitro, registryFile, assetsRegistryFile, resolved);
|
|
896
|
-
applyWorkspaceRuntimeAliases(nitro, registryFile, assetsRegistryFile);
|
|
897
|
-
installNitroConfigTypes(nitro, () => definitions);
|
|
898
|
-
if (!(nitro.options._config?.imports === false)) nitro.options.imports = mergeNitroImportsPreset(nitro.options.imports === false ? {} : nitro.options.imports, WORKSPACE_NITRO_IMPORTS_PRESET);
|
|
899
|
-
nitro.options.plugins ||= [];
|
|
900
|
-
if (!nitro.options.plugins.includes(plugin)) nitro.options.plugins.push(plugin);
|
|
901
|
-
if (hosting.includes("cloudflare")) configureCloudflareArtifacts(nitro.options, resolved);
|
|
902
|
-
hookNitroRuntimeRegistryRefresh(nitro, async () => {
|
|
903
|
-
definitions = discoverNitroWorkspaceDefinitions(nitro.options.rootDir);
|
|
904
|
-
const nextPath = await writeWorkspaceRuntimeRegistry(registryPath(nitro), definitions);
|
|
905
|
-
return {
|
|
906
|
-
definitions,
|
|
907
|
-
registryFile: nextPath
|
|
908
|
-
};
|
|
909
|
-
}, async (runtimeFiles, hookName) => {
|
|
910
|
-
applyWorkspaceRuntimeAliases(nitro, runtimeFiles.registryFile, assetsRegistryFile);
|
|
911
|
-
if (hookName === "build:before") {
|
|
912
|
-
await syncWorkspaceBuildAssets(definitions, nitro.options.rootDir, resolved, assetsRegistryFile);
|
|
913
|
-
await writePlugin(nitro, runtimeFiles.registryFile, assetsRegistryFile, resolved);
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
nitro.logger.info(`@vite-hub/workspace enabled with ${definitions.length} workspace definition${definitions.length === 1 ? "" : "s"}`);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
const workspaceNitroModule = workspaceNitro();
|
|
921
|
-
//#endregion
|
|
922
|
-
export { refreshWorkspaceBuildState as a, workspaceSuffixPattern as c, initializeWorkspaceAssetRegistry as i, workspaceNitroModule as n, syncWorkspaceBuildAssets as o, normalizeWorkspaceOptions as r, discoverViteWorkspaceDefinitions as s, workspaceNitro as t };
|