@vite-hub/workspace 0.6.1 → 0.8.0
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 +6 -6
- package/dist/{asset-registry-0CdRAjIV.js → asset-registry-DJyE42kr.js} +1 -1
- package/dist/blob-database.d.ts +1 -1
- package/dist/blob-database.js +6 -6
- package/dist/checkout.js +2 -2
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/{config-jo5QgE1w.js → config-Bze7OyvB.js} +15 -10
- package/dist/{config-DeA287c0.d.ts → config-DF6sqKXB.d.ts} +1 -1
- package/dist/durability.d.ts +1 -1
- package/dist/durability.js +2 -2
- package/dist/{error-diagnostics-B4me-ouV.js → error-diagnostics-CHgE8TQM.js} +16 -0
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{file-BrNAXQgY.js → file-DIBPXqbk.js} +1 -1
- package/dist/{file-metadata-Bpsvjw_X.js → file-metadata-Dqpldj0h.js} +7 -2
- package/dist/{files--z2dLC5z.js → files-DAJyo7TU.js} +2 -2
- package/dist/files.d.ts +5 -5
- package/dist/files.js +5 -5
- package/dist/{github-k--_LCrX.js → github-DcrnEGNN.js} +4 -4
- package/dist/{glob-BreFjNAV.js → glob-BIg9O4yY.js} +2 -2
- package/dist/{glob-BEutagp1.js → glob-YVshR7WP.js} +1 -1
- package/dist/{host-C8yZizfk.js → host-BT7EnmZf.js} +7 -7
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +464 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +917 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +13 -13
- package/dist/internal/path.js +108 -1
- package/dist/internal/workspace.d.ts +2 -3
- package/dist/internal/workspace.js +2 -2
- package/dist/{lifecycle-IReZfi0b.js → lifecycle-B0ucHUum.js} +8 -8
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-DeJnbOaw.js → mcp-resources-BDL0llKW.js} +2 -2
- package/dist/{memory-BlSRrBH1.js → memory-BCZl_ZsJ.js} +26 -4
- package/dist/{metadata-target-CaGLY4ay.js → metadata-target-mlHAv1p4.js} +59 -24
- package/dist/{object-CAK6UYR5.js → object-DNOrQSl5.js} +5 -1
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BALFFdKj.d.ts} +1 -0
- package/dist/{operations-BIaK_uYG.js → operations-D3mZArDi.js} +8 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +1341 -2
- package/dist/{path-Bb9OIc_F.js → path-DYHw5KNk.js} +11 -3
- package/dist/plugins-BYxsPDBH.d.ts +12 -0
- package/dist/{provider-CN14ewvx.js → provider-DZY1cLP5.js} +281 -87
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1994 -1
- package/dist/{registry-BbUg9vJB.js → registry-OonxXCbd.js} +3 -3
- package/dist/{registry-B0g19sdy.d.ts → registry-h1-cT-cE.d.ts} +1 -1
- package/dist/{registry-s2Ob9PeX.d.ts → registry-hnARUKNF.d.ts} +2 -2
- package/dist/replacement-CVZVsflC.js +76 -0
- package/dist/{request-scope-CXCI_wCb.js → request-scope-jH4H0Sbm.js} +3 -1
- package/dist/{rule-keys-BLEbi1h5.js → rule-keys-xMpiTLq1.js} +1 -1
- package/dist/{rules-BPDXypZV.js → rules-DYQCKYdt.js} +4 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -4
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +1 -1
- package/dist/runtime/request.js +1 -1
- package/dist/runtime/state.d.ts +17 -6
- package/dist/runtime/state.js +7 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +39 -24
- package/dist/{search-C_nVorq7.js → search-CG6UNOtn.js} +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +301 -1
- package/dist/{shared-C20Wh1mp.js → shared-DCAyMX8U.js} +68 -21
- package/dist/source-metadata.d.ts +2 -2
- package/dist/source-metadata.js +3 -3
- package/dist/{sync-BBfR4g5y.js → sync-DkpTCr9u.js} +5 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-Bel5IDmF.d.ts → types-BnSUug2v.d.ts} +13 -1
- package/dist/{use-CpphIBof.d.ts → use-CJ5rdIrW.d.ts} +1 -1
- package/dist/{use-D0DyTMxM.js → use-hLouCwGz.js} +15 -51
- package/dist/{use-tools-CAK10LTc.d.ts → use-tools-DFVqZwgc.d.ts} +2 -2
- package/dist/{use-tools-CHduR5k6.js → use-tools-NXEQt099.js} +4 -4
- package/dist/{utils-DXP9xfXo.js → utils-Bv1NBg8r.js} +5 -5
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +517 -121
- package/dist/{workspace-BOuxrZrP.d.ts → workspace-B6QreLJd.d.ts} +1 -1
- package/dist/{workspace-CLuPkyZR.js → workspace-Cz-5Ne1c.js} +340 -104
- package/dist/workspace-inspection-scanner-BlJ8bCAB.js +140 -0
- package/package.json +12 -12
- package/dist/errors-CnFDXxeJ.d.ts +0 -4
- package/dist/hosted-8BTKAtMX.js +0 -883
- package/dist/hosted-vercel-blob-B6kygYqn.js +0 -408
- package/dist/operations-DS1C4uXd.js +0 -1308
- package/dist/path-CuYE8-X6.js +0 -57
- package/dist/plugins-CLc32jvL.d.ts +0 -8
- package/dist/server-aa1a4rkV.js +0 -301
- package/dist/state-BdDfBtOR.d.ts +0 -17
- package/dist/store-cx3OqNTi.js +0 -1971
package/dist/vite.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { n as __exportAll$1, r as __toESM, t as __commonJSMin } from "./rolldown-runtime-DnNXxpGL.js";
|
|
2
|
-
import {
|
|
3
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
4
|
-
import { n as isRecordOrFunction, t as
|
|
5
|
-
import {
|
|
6
|
-
import { n as syncWorkspaceDefinition } from "./lifecycle-
|
|
7
|
-
import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config-
|
|
8
|
-
import {
|
|
9
|
-
import { t as createMemoryWorkspaceStore } from "./memory-
|
|
10
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { C as resolve$1, S as relative$1, _ as requireViteHubDevServerUrl, a as createNativePackageLoading, b as dirname$1, c as generatedViteHubWatchIgnoredAddition, d as publishViteHubDevServer, f as resolveViteHubProjectRoot, g as readViteHubDevTargetOption, h as fetchViteHubDevEndpoint, l as isProductionBuild, m as discoverViteHubDevServer, o as createNoExternalAddition, p as shouldSkipViteProviderBuild, r as VITEHUB_PROJECT_ROOT, s as createViteHubEnvImportAliases, t as callOperationFromCli, u as isServerEnvironment, v as redactInspectionText, workspaceOperations, x as isAbsolute$1, y as relativeDefinitionFile } from "./operations.js";
|
|
3
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
4
|
+
import { n as isRecord, r as isRecordOrFunction, t as isObject } from "./object-DNOrQSl5.js";
|
|
5
|
+
import { ensureWorkspaceDevToken, readWorkspaceDevToken, refreshWorkspaceDevToken, runWorkspaceDevCommand, t as isViteHubSecretEqual, validateWorkspaceDevToken, workspaceDevHeader, workspaceDevRoute, workspaceDevTokenHeader, workspaceDevTokenServerId } from "./server.js";
|
|
6
|
+
import { n as syncWorkspaceDefinition } from "./lifecycle-B0ucHUum.js";
|
|
7
|
+
import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config-Bze7OyvB.js";
|
|
8
|
+
import { normalizeSafeWorkspacePath } from "./internal/path.js";
|
|
9
|
+
import { t as createMemoryWorkspaceStore } from "./memory-BCZl_ZsJ.js";
|
|
10
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
|
|
11
11
|
import { assertNoSymlinks, checkoutFailure, conflictMarkerPatterns, folderOf, formatWorkspaceStatus, ignoredName, localCheckoutStatus, pullWorkspaces, pushWorkspaces, resolveWorkspaceConflicts, workspaceLockFile, workspaceStatus } from "./checkout.js";
|
|
12
|
-
import { n as isWorkspaceStore, r as normalizeWorkspaceStoreOptions } from "./provider-
|
|
13
|
-
import { c as workspaceRegistryLoadError, n as normalizeWorkspaceDefinition } from "./registry-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { n as isWorkspaceStore, r as normalizeWorkspaceStoreOptions } from "./provider-DZY1cLP5.js";
|
|
13
|
+
import { c as workspaceRegistryLoadError, n as normalizeWorkspaceDefinition } from "./registry-OonxXCbd.js";
|
|
14
|
+
import { installHostedWorkspaceRuntime } from "./hosted.js";
|
|
15
|
+
import { installHostedVercelBlobWorkspaceRuntime } from "./hosted-vercel-blob.js";
|
|
16
16
|
import { createRequire, isBuiltin } from "node:module";
|
|
17
17
|
import { formatRuntimeDiagnosticError } from "@vite-hub/runtime";
|
|
18
|
+
import { defineDiagnostics, formatDiagnostic } from "nostics";
|
|
18
19
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
19
20
|
import { createHash } from "node:crypto";
|
|
20
21
|
import { Minimatch } from "minimatch";
|
|
21
|
-
import { defineDiagnostics } from "nostics";
|
|
22
22
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
23
23
|
import { access, chmod, copyFile, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
24
24
|
import { tmpdir } from "node:os";
|
|
@@ -36,7 +36,7 @@ const workspaceConfigKeys = /* @__PURE__ */ new Set([
|
|
|
36
36
|
]);
|
|
37
37
|
function normalizeWorkspaceOptions(options, input = {}) {
|
|
38
38
|
if (options === false) return false;
|
|
39
|
-
if (typeof options !== "undefined" && !isRecord
|
|
39
|
+
if (typeof options !== "undefined" && !isRecord(options)) throw workspaceErrorDiagnostics.WORKSPACE_C0001({ message: "`workspace` must be a plain object." });
|
|
40
40
|
const resolvedOptions = options || {};
|
|
41
41
|
const unsupported = Object.keys(resolvedOptions).filter((key) => !workspaceConfigKeys.has(key));
|
|
42
42
|
if (unsupported.length) throw workspaceErrorDiagnostics.WORKSPACE_C0002({ message: `[vitehub] workspace config does not support option${unsupported.length === 1 ? "" : "s"}: ${unsupported.join(", ")}.` });
|
|
@@ -190,12 +190,32 @@ function mergeOwnedArrays(existing, value, arrays) {
|
|
|
190
190
|
const next = { ...value };
|
|
191
191
|
for (const [field, ownership] of Object.entries(arrays ?? {})) {
|
|
192
192
|
const incoming = Array.isArray(value[field]) ? value[field] : [];
|
|
193
|
-
const
|
|
193
|
+
const unowned = preserveUnownedKeyedArrayEntries(existing[field], ownership, incoming);
|
|
194
|
+
const merged = ownership.key !== void 0 && ownership.preserveOrder && Array.isArray(existing[field]) ? mergeOrderedEntries(existing[field], unowned, incoming, ownership.key) : [...unowned, ...incoming];
|
|
194
195
|
if (merged.length) next[field] = merged;
|
|
195
196
|
else delete next[field];
|
|
196
197
|
}
|
|
197
198
|
return next;
|
|
198
199
|
}
|
|
200
|
+
function mergeOrderedEntries(current, unowned, incoming, key) {
|
|
201
|
+
const preserved = new Set(unowned);
|
|
202
|
+
const replacements = new Map(incoming.flatMap((entry) => {
|
|
203
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
204
|
+
return identity === void 0 ? [] : [[identity, entry]];
|
|
205
|
+
}));
|
|
206
|
+
return [...current.flatMap((entry) => {
|
|
207
|
+
if (preserved.has(entry)) return [entry];
|
|
208
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
209
|
+
if (identity === void 0) return [];
|
|
210
|
+
const replacement = replacements.get(identity);
|
|
211
|
+
if (replacement === void 0) return [];
|
|
212
|
+
replacements.delete(identity);
|
|
213
|
+
return [replacement];
|
|
214
|
+
}), ...incoming.filter((entry) => {
|
|
215
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
216
|
+
return identity === void 0 || replacements.has(identity);
|
|
217
|
+
})];
|
|
218
|
+
}
|
|
199
219
|
async function persistProviderJsonRecord(file, value, removeIfEmpty) {
|
|
200
220
|
if (removeIfEmpty && !Object.keys(value).length) {
|
|
201
221
|
await rm(file, { force: true });
|
|
@@ -215,19 +235,31 @@ async function writeProviderOutputConfig(file, value, ownership = {}, options =
|
|
|
215
235
|
function mergeProviderOutputConfig(existing, value, ownership = {}) {
|
|
216
236
|
assertProviderJsonRecord(existing);
|
|
217
237
|
assertProviderJsonRecord(value);
|
|
218
|
-
|
|
238
|
+
const next = {
|
|
219
239
|
...deleteOwnedFields(existing, ownership),
|
|
220
240
|
...mergeOwnedArrays(existing, value, ownership.arrays)
|
|
221
241
|
};
|
|
242
|
+
for (const [field, childOwnership] of Object.entries(ownership.objects ?? {})) {
|
|
243
|
+
const current = existing[field];
|
|
244
|
+
const incoming = value[field];
|
|
245
|
+
const merged = mergeProviderOutputConfig(isProviderJsonRecord(current) ? current : {}, isProviderJsonRecord(incoming) ? incoming : {}, childOwnership);
|
|
246
|
+
if (Object.keys(merged).length) next[field] = merged;
|
|
247
|
+
else delete next[field];
|
|
248
|
+
}
|
|
249
|
+
return next;
|
|
222
250
|
}
|
|
223
251
|
function stringifyProviderOutputConfig(value) {
|
|
224
252
|
assertProviderJsonRecord(value);
|
|
225
253
|
return JSON.stringify(value, null, 2);
|
|
226
254
|
}
|
|
227
255
|
async function cleanProviderOutputConfig(file, ownership) {
|
|
228
|
-
if (!ownership.keys?.length && !Object.keys(ownership.arrays ?? {}).length) return;
|
|
256
|
+
if (!ownership.keys?.length && !Object.keys(ownership.arrays ?? {}).length && !Object.keys(ownership.objects ?? {}).length) return;
|
|
229
257
|
const existing = await readProviderJsonRecord(file);
|
|
230
258
|
if (!existing) return;
|
|
259
|
+
const next = cleanOwnedFields(existing, ownership);
|
|
260
|
+
if (next) await persistProviderJsonRecord(file, next, true);
|
|
261
|
+
}
|
|
262
|
+
function cleanOwnedFields(existing, ownership) {
|
|
231
263
|
const next = deleteOwnedFields(existing, ownership, true);
|
|
232
264
|
let changed = (ownership.keys ?? []).some((key) => key in existing);
|
|
233
265
|
for (const [field, arrayOwnership] of Object.entries(ownership.arrays ?? {})) {
|
|
@@ -239,8 +271,16 @@ async function cleanProviderOutputConfig(file, ownership) {
|
|
|
239
271
|
changed ||= retained.length > 0 || !Array.isArray(current) || preserved.length !== current.length || preserved.length === 0;
|
|
240
272
|
if (preserved.length) next[field] = preserved;
|
|
241
273
|
}
|
|
242
|
-
|
|
243
|
-
|
|
274
|
+
for (const [field, childOwnership] of Object.entries(ownership.objects ?? {})) {
|
|
275
|
+
const current = existing[field];
|
|
276
|
+
if (!isProviderJsonRecord(current)) continue;
|
|
277
|
+
const cleaned = cleanOwnedFields(current, childOwnership);
|
|
278
|
+
if (!cleaned) continue;
|
|
279
|
+
changed = true;
|
|
280
|
+
if (Object.keys(cleaned).length) next[field] = cleaned;
|
|
281
|
+
else delete next[field];
|
|
282
|
+
}
|
|
283
|
+
if (changed) return next;
|
|
244
284
|
}
|
|
245
285
|
// ../internal/src/build/user-entry.ts
|
|
246
286
|
function toSafeAppName(rootDir) {
|
|
@@ -350,9 +390,9 @@ function isFileResolution(resolved) {
|
|
|
350
390
|
}
|
|
351
391
|
function collectPackageExportCandidates(packageName, exportsValue, packageRelativePath) {
|
|
352
392
|
if (typeof exportsValue === "string") return normalizePathSeparators(exportsValue).replace(/^\.\//, "") === packageRelativePath ? [packageName] : [];
|
|
353
|
-
if (!Array.isArray(exportsValue) && !isRecord
|
|
393
|
+
if (!Array.isArray(exportsValue) && !isRecord(exportsValue)) return [];
|
|
354
394
|
const candidates = [];
|
|
355
|
-
const exportEntries = isRecord
|
|
395
|
+
const exportEntries = isRecord(exportsValue) && Object.keys(exportsValue).some((exportKey) => exportKey.startsWith(".")) ? Object.entries(exportsValue) : [[".", exportsValue]];
|
|
356
396
|
for (const [exportKey, target] of exportEntries) {
|
|
357
397
|
const targets = [target];
|
|
358
398
|
while (targets.length) {
|
|
@@ -369,7 +409,7 @@ function collectPackageExportCandidates(packageName, exportsValue, packageRelati
|
|
|
369
409
|
if (wildcard === void 0) continue;
|
|
370
410
|
candidates.push(`${packageName}${exportKey.slice(1).replace("*", wildcard)}`);
|
|
371
411
|
} else if (Array.isArray(value)) targets.push(...value);
|
|
372
|
-
else if (isRecord
|
|
412
|
+
else if (isRecord(value)) targets.push(...Object.values(value));
|
|
373
413
|
}
|
|
374
414
|
}
|
|
375
415
|
return candidates;
|
|
@@ -475,7 +515,7 @@ function createResolvedAliasPlugin(aliases, aliasResolveDir, workingDir, resolve
|
|
|
475
515
|
else if (resolutionScope) {
|
|
476
516
|
const packageRelativePath = normalizedSpecifier.slice(resolutionScope.length);
|
|
477
517
|
const parsedPackageJson = JSON.parse(await readFile(resolve(resolutionScope, "package.json"), "utf8"));
|
|
478
|
-
if (!isRecord
|
|
518
|
+
if (!isRecord(parsedPackageJson)) return;
|
|
479
519
|
const packageJson = parsedPackageJson;
|
|
480
520
|
if (packageJson.exports === void 0 && !alias.prefix) {
|
|
481
521
|
const resolvedCandidate = await resolveWithContext(alias.specifier);
|
|
@@ -1098,9 +1138,153 @@ async function copyRuntimePackageFiles(packageDir, targetDir) {
|
|
|
1098
1138
|
await unlessGone(() => copyFile(join(packageDir, path), target));
|
|
1099
1139
|
}
|
|
1100
1140
|
}
|
|
1141
|
+
// ../internal/src/source-files.ts
|
|
1142
|
+
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
1143
|
+
"node_modules",
|
|
1144
|
+
"dist",
|
|
1145
|
+
".output",
|
|
1146
|
+
".nuxt",
|
|
1147
|
+
".vercel",
|
|
1148
|
+
".git",
|
|
1149
|
+
".vitehub"
|
|
1150
|
+
]);
|
|
1151
|
+
const racyWindowNs = 2000000000n;
|
|
1152
|
+
const storeKey = Symbol.for("vite-hub.source-files.v1");
|
|
1153
|
+
function store() {
|
|
1154
|
+
const existing = Reflect.get(globalThis, storeKey);
|
|
1155
|
+
if (isStore(existing)) return existing;
|
|
1156
|
+
const created = {
|
|
1157
|
+
derived: /* @__PURE__ */ new Map(),
|
|
1158
|
+
texts: /* @__PURE__ */ new Map(),
|
|
1159
|
+
trees: /* @__PURE__ */ new Map()
|
|
1160
|
+
};
|
|
1161
|
+
Reflect.set(globalThis, storeKey, created);
|
|
1162
|
+
return created;
|
|
1163
|
+
}
|
|
1164
|
+
function isStore(value) {
|
|
1165
|
+
return typeof value === "object" && value !== null && "texts" in value && "trees" in value && "derived" in value;
|
|
1166
|
+
}
|
|
1167
|
+
function errorCode(error) {
|
|
1168
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
1169
|
+
}
|
|
1170
|
+
function statOrMissing(path) {
|
|
1171
|
+
try {
|
|
1172
|
+
return statSync(path, { bigint: true });
|
|
1173
|
+
} catch (error) {
|
|
1174
|
+
if (errorCode(error) === "ENOENT" || errorCode(error) === "ENOTDIR") return;
|
|
1175
|
+
throw error;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
function signature(stats) {
|
|
1179
|
+
return `${stats.ino}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}`;
|
|
1180
|
+
}
|
|
1181
|
+
function isSettled(stats) {
|
|
1182
|
+
const changed = stats.mtimeNs > stats.ctimeNs ? stats.mtimeNs : stats.ctimeNs;
|
|
1183
|
+
return BigInt(Date.now()) * 1000000n - changed > racyWindowNs;
|
|
1184
|
+
}
|
|
1185
|
+
function readDirEntries(root) {
|
|
1186
|
+
try {
|
|
1187
|
+
return readdirSync(root, { withFileTypes: true });
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
if (errorCode(error) === "ENOENT") return [];
|
|
1190
|
+
throw error;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
function walkTree(root, directories, files, nested = false) {
|
|
1194
|
+
const before = statOrMissing(root);
|
|
1195
|
+
let trusted = before !== void 0 && isSettled(before);
|
|
1196
|
+
if (before) directories.set(root, signature(before));
|
|
1197
|
+
if (nested && existsSync(resolve$1(root, ".git"))) return trusted;
|
|
1198
|
+
for (const entry of readDirEntries(root)) {
|
|
1199
|
+
const path = resolve$1(root, entry.name);
|
|
1200
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
1201
|
+
if (entry.name.startsWith(".") || ignoredDirs.has(entry.name)) continue;
|
|
1202
|
+
if (!walkTree(path, directories, files, true)) trusted = false;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
if (entry.isFile()) files.push({
|
|
1206
|
+
hidden: entry.name.startsWith("."),
|
|
1207
|
+
name: entry.name,
|
|
1208
|
+
path
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
return trusted;
|
|
1212
|
+
}
|
|
1213
|
+
function isCurrent(tree) {
|
|
1214
|
+
for (const [directory, stored] of tree.directories) {
|
|
1215
|
+
const stats = statOrMissing(directory);
|
|
1216
|
+
if (!stats || signature(stats) !== stored) return false;
|
|
1217
|
+
}
|
|
1218
|
+
return true;
|
|
1219
|
+
}
|
|
1220
|
+
function sourceTree(root) {
|
|
1221
|
+
const trees = store().trees;
|
|
1222
|
+
const cached = trees.get(root);
|
|
1223
|
+
if (cached && isCurrent(cached)) return cached;
|
|
1224
|
+
const directories = /* @__PURE__ */ new Map();
|
|
1225
|
+
const files = [];
|
|
1226
|
+
const trusted = walkTree(root, directories, files);
|
|
1227
|
+
files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
1228
|
+
const tree = {
|
|
1229
|
+
directories,
|
|
1230
|
+
files
|
|
1231
|
+
};
|
|
1232
|
+
if (trusted) trees.set(root, tree);
|
|
1233
|
+
else trees.delete(root);
|
|
1234
|
+
return tree;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* The files below `root` whose name matches `predicate`, sorted by path. The walk skips hidden folders, Git
|
|
1238
|
+
* repositories, and build output folders such as `node_modules`, `dist`, and `.vitehub`. Hidden files need
|
|
1239
|
+
* `includeHidden`. Symbolic links are skipped.
|
|
1240
|
+
*/
|
|
1241
|
+
function listSourceTreeFiles(root, predicate, options = {}) {
|
|
1242
|
+
const files = [];
|
|
1243
|
+
for (const file of sourceTree(resolve$1(root)).files) {
|
|
1244
|
+
if (file.hidden && !options.includeHidden) continue;
|
|
1245
|
+
if (predicate(file.name)) files.push(file.path);
|
|
1246
|
+
}
|
|
1247
|
+
return files;
|
|
1248
|
+
}
|
|
1249
|
+
/** The UTF-8 text of a source file. A file that did not change since the last read is not read again. */
|
|
1250
|
+
function readSourceText(file) {
|
|
1251
|
+
const path = resolve$1(file);
|
|
1252
|
+
const texts = store().texts;
|
|
1253
|
+
const stats = statOrMissing(path);
|
|
1254
|
+
if (!stats) return readFileSync(path, "utf8");
|
|
1255
|
+
const current = signature(stats);
|
|
1256
|
+
const cached = texts.get(path);
|
|
1257
|
+
if (cached?.trusted && cached.signature === current) return cached.text;
|
|
1258
|
+
const read = readFileSync(path, "utf8");
|
|
1259
|
+
const text = cached?.text === read ? cached.text : read;
|
|
1260
|
+
texts.set(path, {
|
|
1261
|
+
signature: current,
|
|
1262
|
+
text,
|
|
1263
|
+
trusted: isSettled(stats)
|
|
1264
|
+
});
|
|
1265
|
+
return text;
|
|
1266
|
+
}
|
|
1101
1267
|
// ../internal/src/build/provider-output-sources.ts
|
|
1102
|
-
|
|
1103
|
-
|
|
1268
|
+
const keptFailedProviderOutputArtifactDirs = /* @__PURE__ */ new Set();
|
|
1269
|
+
function failureText(failure) {
|
|
1270
|
+
return failure instanceof Error ? `${failure.message}\n${failure.stack ?? ""}` : String(failure);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Removes retained provider output after readers release it, tolerating transient filesystem contention. Pass the
|
|
1274
|
+
* build failure when a failed build discards its generation: with `VITEHUB_KEEP_FAILED_BUILD=1` the folder stays
|
|
1275
|
+
* for inspection.
|
|
1276
|
+
*/
|
|
1277
|
+
async function removeProviderOutputArtifactDir(path, failure) {
|
|
1278
|
+
if (failure !== void 0) {
|
|
1279
|
+
const shown = relative(process.cwd(), path) || path;
|
|
1280
|
+
if (/^(?:1|true)$/i.test(process.env.VITEHUB_KEEP_FAILED_BUILD ?? "")) {
|
|
1281
|
+
if (!existsSync(path)) return;
|
|
1282
|
+
if (!keptFailedProviderOutputArtifactDirs.has(path)) console.warn(`[vitehub] The build failed. ViteHub kept its provider sources in ${shown} so you can inspect them. Remove the folder when you are done.`);
|
|
1283
|
+
keptFailedProviderOutputArtifactDirs.add(path);
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (failureText(failure).includes(basename(path))) console.warn(`[vitehub] The build error names files in ${shown}, which ViteHub removes after a failed build. Set VITEHUB_KEEP_FAILED_BUILD=1 to keep them.`);
|
|
1287
|
+
}
|
|
1104
1288
|
await rm(path, {
|
|
1105
1289
|
force: true,
|
|
1106
1290
|
maxRetries: 5,
|
|
@@ -1512,17 +1696,17 @@ var ProviderOutputCatalog = class {
|
|
|
1512
1696
|
}
|
|
1513
1697
|
this.#restoreDeploymentContribution(entry);
|
|
1514
1698
|
}
|
|
1515
|
-
resetDeploymentContributions(generation) {
|
|
1699
|
+
resetDeploymentContributions(generation, failure) {
|
|
1516
1700
|
if (!generation) {
|
|
1517
1701
|
for (const reference of this.#deploymentGenerations) {
|
|
1518
1702
|
const current = reference.deref();
|
|
1519
1703
|
if (current) current.valid = false;
|
|
1520
1704
|
}
|
|
1521
1705
|
this.#deploymentGenerations.clear();
|
|
1522
|
-
for (const entries of this.#deploymentContributions.values()) for (const entry of entries) this.#queueDeploymentDiscard(entry);
|
|
1706
|
+
for (const entries of this.#deploymentContributions.values()) for (const entry of entries) this.#queueDeploymentDiscard(entry, failure);
|
|
1523
1707
|
for (const taken of this.#takenDeploymentContributions.values()) {
|
|
1524
|
-
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry);
|
|
1525
|
-
for (const fallback of taken.fallbacks) this.#queueDeploymentDiscard(fallback);
|
|
1708
|
+
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry, failure);
|
|
1709
|
+
for (const fallback of taken.fallbacks) this.#queueDeploymentDiscard(fallback, failure);
|
|
1526
1710
|
}
|
|
1527
1711
|
this.#deploymentContributions.clear();
|
|
1528
1712
|
this.#takenDeploymentContributions.clear();
|
|
@@ -1531,7 +1715,7 @@ var ProviderOutputCatalog = class {
|
|
|
1531
1715
|
generation.valid = false;
|
|
1532
1716
|
this.#deleteDeploymentGeneration(generation);
|
|
1533
1717
|
for (const [owner, entries] of this.#deploymentContributions) {
|
|
1534
|
-
for (const entry of entries) if (entry.generation === generation) this.#queueDeploymentDiscard(entry);
|
|
1718
|
+
for (const entry of entries) if (entry.generation === generation) this.#queueDeploymentDiscard(entry, failure);
|
|
1535
1719
|
const remaining = entries.filter((entry) => entry.generation !== generation);
|
|
1536
1720
|
if (remaining.length) this.#deploymentContributions.set(owner, remaining);
|
|
1537
1721
|
else this.#deploymentContributions.delete(owner);
|
|
@@ -1539,10 +1723,10 @@ var ProviderOutputCatalog = class {
|
|
|
1539
1723
|
for (const [contribution, taken] of this.#takenDeploymentContributions) {
|
|
1540
1724
|
const invalidatedFallbacks = taken.fallbacks.filter((entry) => entry.generation === generation);
|
|
1541
1725
|
taken.fallbacks = taken.fallbacks.filter((entry) => entry.generation !== generation);
|
|
1542
|
-
for (const fallback of invalidatedFallbacks) this.#queueDeploymentDiscard(fallback);
|
|
1726
|
+
for (const fallback of invalidatedFallbacks) this.#queueDeploymentDiscard(fallback, failure);
|
|
1543
1727
|
if (taken.entry.generation !== generation) continue;
|
|
1544
1728
|
this.#takenDeploymentContributions.delete(contribution);
|
|
1545
|
-
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry);
|
|
1729
|
+
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry, failure);
|
|
1546
1730
|
for (const fallback of taken.fallbacks) if (taken.committed) this.#queueDeploymentDiscard(fallback);
|
|
1547
1731
|
else this.#restoreDeploymentContribution(fallback);
|
|
1548
1732
|
}
|
|
@@ -1585,7 +1769,7 @@ var ProviderOutputCatalog = class {
|
|
|
1585
1769
|
const failure = (await Promise.allSettled(discarded)).find((result) => result.status === "rejected");
|
|
1586
1770
|
if (failure) throw failure.reason;
|
|
1587
1771
|
}
|
|
1588
|
-
async completeDeploymentContributions(contributions) {
|
|
1772
|
+
async completeDeploymentContributions(contributions, buildFailure) {
|
|
1589
1773
|
const discarded = this.#pendingDeploymentDiscards.splice(0);
|
|
1590
1774
|
const completedGenerations = /* @__PURE__ */ new Set();
|
|
1591
1775
|
for (const contribution of contributions) {
|
|
@@ -1595,7 +1779,7 @@ var ProviderOutputCatalog = class {
|
|
|
1595
1779
|
const entries = taken.entryDiscarded ? taken.fallbacks : [...taken.fallbacks, taken.entry];
|
|
1596
1780
|
for (const entry of entries) {
|
|
1597
1781
|
if (entry.generation) completedGenerations.add(entry.generation);
|
|
1598
|
-
if (entry.contribution.discard) discarded.push(entry.contribution.discard());
|
|
1782
|
+
if (entry.contribution.discard) discarded.push(entry.contribution.discard(entry === taken.entry ? buildFailure : void 0));
|
|
1599
1783
|
}
|
|
1600
1784
|
}
|
|
1601
1785
|
for (const generation of completedGenerations) this.#retireDeploymentGeneration(generation);
|
|
@@ -1639,9 +1823,9 @@ var ProviderOutputCatalog = class {
|
|
|
1639
1823
|
if (reference) this.#deploymentGenerations.delete(reference);
|
|
1640
1824
|
this.#deploymentGenerationRefs.delete(generation);
|
|
1641
1825
|
}
|
|
1642
|
-
#queueDeploymentDiscard(entry) {
|
|
1826
|
+
#queueDeploymentDiscard(entry, failure) {
|
|
1643
1827
|
if (!entry.contribution.discard) return;
|
|
1644
|
-
const discard = Promise.resolve().then(entry.contribution.discard);
|
|
1828
|
+
const discard = Promise.resolve().then(async () => await entry.contribution.discard?.(failure));
|
|
1645
1829
|
discard.catch(() => {});
|
|
1646
1830
|
this.#pendingDeploymentDiscards.push(discard);
|
|
1647
1831
|
}
|
|
@@ -2486,23 +2670,23 @@ async function resetProviderDeploymentOutputs(catalog, failure, generation) {
|
|
|
2486
2670
|
if (!catalog) return;
|
|
2487
2671
|
const completedReset = providerDeploymentOutputCompletedResets.get(catalog);
|
|
2488
2672
|
if (completedReset && failure !== void 0 && completedReset.failures.has(failure)) {
|
|
2489
|
-
if (generation) catalog.resetDeploymentContributions(generation);
|
|
2673
|
+
if (generation) catalog.resetDeploymentContributions(generation, failure);
|
|
2490
2674
|
await completedReset.promise;
|
|
2491
2675
|
return;
|
|
2492
2676
|
}
|
|
2493
2677
|
if (completedReset) providerDeploymentOutputCompletedResets.delete(catalog);
|
|
2494
|
-
if (generation) catalog.resetDeploymentContributions(generation);
|
|
2678
|
+
if (generation) catalog.resetDeploymentContributions(generation, failure);
|
|
2495
2679
|
const active = providerDeploymentOutputFinalizations.get(catalog);
|
|
2496
2680
|
if (active?.reset) {
|
|
2497
2681
|
if (failure !== void 0 && !active.reset.failures.has(failure)) {
|
|
2498
2682
|
active.reset.failures.add(failure);
|
|
2499
|
-
if (!generation) catalog.resetDeploymentContributions();
|
|
2683
|
+
if (!generation) catalog.resetDeploymentContributions(void 0, failure);
|
|
2500
2684
|
}
|
|
2501
2685
|
providerDeploymentOutputCompletedResets.set(catalog, active.reset);
|
|
2502
2686
|
await active.reset.promise;
|
|
2503
2687
|
return;
|
|
2504
2688
|
}
|
|
2505
|
-
if (!generation) catalog.resetDeploymentContributions();
|
|
2689
|
+
if (!generation) catalog.resetDeploymentContributions(void 0, failure);
|
|
2506
2690
|
if (active && (!generation || active.state.generations.has(generation))) {
|
|
2507
2691
|
active.state.rollback = true;
|
|
2508
2692
|
active.controller.abort(internalErrorDiagnostics.INTERNAL_B0039({ message: "Provider Output finalization reset" }));
|
|
@@ -2651,7 +2835,7 @@ async function finalizeProviderDeploymentOutputs(catalog, options = {}) {
|
|
|
2651
2835
|
await catalog.completeDeploymentContributions(contributions);
|
|
2652
2836
|
} catch (error) {
|
|
2653
2837
|
if (state.rollback) catalog.rollbackDeploymentContributions(contributions);
|
|
2654
|
-
else await catalog.completeDeploymentContributions(contributions);
|
|
2838
|
+
else await catalog.completeDeploymentContributions(contributions, error);
|
|
2655
2839
|
throw error;
|
|
2656
2840
|
} finally {
|
|
2657
2841
|
state.generations.clear();
|
|
@@ -2677,15 +2861,6 @@ async function finalizeProviderDeploymentOutputs(catalog, options = {}) {
|
|
|
2677
2861
|
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
2678
2862
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
2679
2863
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
2680
|
-
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
2681
|
-
"node_modules",
|
|
2682
|
-
"dist",
|
|
2683
|
-
".output",
|
|
2684
|
-
".nuxt",
|
|
2685
|
-
".vercel",
|
|
2686
|
-
".git",
|
|
2687
|
-
".vitehub"
|
|
2688
|
-
]);
|
|
2689
2864
|
function createDirectoryDefinitionSource(source, scanDirs, subdir, options = {}) {
|
|
2690
2865
|
return {
|
|
2691
2866
|
...options,
|
|
@@ -2705,32 +2880,8 @@ function createSuffixDefinitionSource(source, roots, pattern, normalizeName, opt
|
|
|
2705
2880
|
source
|
|
2706
2881
|
};
|
|
2707
2882
|
}
|
|
2708
|
-
function readDirEntries(root) {
|
|
2709
|
-
try {
|
|
2710
|
-
return readdirSync(root, { withFileTypes: true });
|
|
2711
|
-
} catch (error) {
|
|
2712
|
-
if (error.code === "ENOENT") return [];
|
|
2713
|
-
throw error;
|
|
2714
|
-
}
|
|
2715
|
-
}
|
|
2716
|
-
function isGitRepositoryDirectory(directory) {
|
|
2717
|
-
return existsSync(resolve$1(directory, ".git"));
|
|
2718
|
-
}
|
|
2719
2883
|
function listMatchingFiles(root, predicate, options = {}) {
|
|
2720
|
-
|
|
2721
|
-
for (const entry of readDirEntries(root)) {
|
|
2722
|
-
const absolute = resolve$1(root, entry.name);
|
|
2723
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
2724
|
-
if (isGitRepositoryDirectory(absolute)) continue;
|
|
2725
|
-
if (entry.name.startsWith(".")) continue;
|
|
2726
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
2727
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
2728
|
-
continue;
|
|
2729
|
-
}
|
|
2730
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
2731
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
2732
|
-
}
|
|
2733
|
-
return files.sort();
|
|
2884
|
+
return listSourceTreeFiles(root, predicate, options);
|
|
2734
2885
|
}
|
|
2735
2886
|
/** A module that a Definitions folder can hold: JavaScript or TypeScript, and not a declaration, test, or spec file. */
|
|
2736
2887
|
function isDefinitionSourceFile(name) {
|
|
@@ -3049,6 +3200,84 @@ function mergeNitroExternal(value, addition) {
|
|
|
3049
3200
|
if (typeof value === "function") return (source, importer, isResolved) => source === addition || Boolean(value(source, importer, isResolved));
|
|
3050
3201
|
return value;
|
|
3051
3202
|
}
|
|
3203
|
+
// ../internal/src/hints.ts
|
|
3204
|
+
/**
|
|
3205
|
+
* The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
|
|
3206
|
+
* about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
|
|
3207
|
+
* the file instead of the terminal.
|
|
3208
|
+
*/
|
|
3209
|
+
const viteHubHintsFile = ".vitehub/hints.json";
|
|
3210
|
+
const VITEHUB_NUXT_HINTS = "__vitehubNuxtHints";
|
|
3211
|
+
const runsKey = Symbol.for("vitehub.hints.runs");
|
|
3212
|
+
const shared = globalThis;
|
|
3213
|
+
const runs = shared[runsKey] ??= /* @__PURE__ */ new Map();
|
|
3214
|
+
const startedKey = Symbol.for("vitehub.hints.started");
|
|
3215
|
+
const startedShared = globalThis;
|
|
3216
|
+
const started = startedShared[startedKey] ??= /* @__PURE__ */ new WeakSet();
|
|
3217
|
+
/**
|
|
3218
|
+
* The report of the ViteHub project root, where the other generated files go. A Nuxt app with `srcDir: "app"` has its
|
|
3219
|
+
* Vite root in `app/`, one folder below.
|
|
3220
|
+
*/
|
|
3221
|
+
function hintsFile(config) {
|
|
3222
|
+
const projectRoot = Reflect.get(config, VITEHUB_PROJECT_ROOT);
|
|
3223
|
+
return resolve(typeof projectRoot === "string" ? projectRoot : resolveViteHubProjectRoot(config.root), viteHubHintsFile);
|
|
3224
|
+
}
|
|
3225
|
+
function startRun(config) {
|
|
3226
|
+
const file = hintsFile(config);
|
|
3227
|
+
const run = {
|
|
3228
|
+
file,
|
|
3229
|
+
report: {
|
|
3230
|
+
version: 1,
|
|
3231
|
+
command: config.command,
|
|
3232
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3233
|
+
hints: []
|
|
3234
|
+
},
|
|
3235
|
+
keys: /* @__PURE__ */ new Set()
|
|
3236
|
+
};
|
|
3237
|
+
runs.set(file, run);
|
|
3238
|
+
return run;
|
|
3239
|
+
}
|
|
3240
|
+
function write(run) {
|
|
3241
|
+
mkdirSync(dirname(run.file), { recursive: true });
|
|
3242
|
+
writeFileSync(run.file, `${JSON.stringify(run.report, null, 2)}\n`);
|
|
3243
|
+
}
|
|
3244
|
+
/**
|
|
3245
|
+
* Reports a hint from a Vite plugin hook, or from a Nitro or Nuxt hook of the same build: prints it once with its fix and docs link, and adds it to
|
|
3246
|
+
* {@link viteHubHintsFile}. Build the diagnostic from the package's nostics catalog, so its code has a docs page.
|
|
3247
|
+
*/
|
|
3248
|
+
function reportViteHubHint(config, diagnostic) {
|
|
3249
|
+
if (skipHints(config)) return;
|
|
3250
|
+
const nuxt = config[VITEHUB_NUXT_HINTS];
|
|
3251
|
+
if (typeof nuxt === "function") return nuxt(diagnostic);
|
|
3252
|
+
const run = runs.get(hintsFile(config)) ?? startRun(config);
|
|
3253
|
+
const hint = {
|
|
3254
|
+
code: diagnostic.code,
|
|
3255
|
+
why: diagnostic.why,
|
|
3256
|
+
...diagnostic.fix ? { fix: diagnostic.fix } : {},
|
|
3257
|
+
...diagnostic.docs ? { docs: diagnostic.docs } : {},
|
|
3258
|
+
...diagnostic.sources?.length ? { sources: diagnostic.sources } : {}
|
|
3259
|
+
};
|
|
3260
|
+
const key = JSON.stringify([hint.code, hint.sources ?? []]);
|
|
3261
|
+
if (run.keys.has(key)) return;
|
|
3262
|
+
run.keys.add(key);
|
|
3263
|
+
run.report.hints.push(hint);
|
|
3264
|
+
write(run);
|
|
3265
|
+
(config.logger ?? console).warn(formatDiagnostic(diagnostic));
|
|
3266
|
+
}
|
|
3267
|
+
function skipHints(config) {
|
|
3268
|
+
return !config.command || Reflect.get(config, "__vitehubPrepare") === true || Reflect.get(config, "vitehubCliDiscovery") === true;
|
|
3269
|
+
}
|
|
3270
|
+
/**
|
|
3271
|
+
* Starts the hints of a build or dev server: writes an empty {@link viteHubHintsFile}, so a run without hints does not
|
|
3272
|
+
* leave the hints of an earlier run in place. Every plugin that reports hints calls it from `configResolved`, so a
|
|
3273
|
+
* package used without `vitehub()` starts its own run. Nuxt uses the app instance as owner so its Vite builds and
|
|
3274
|
+
* separate Nitro build share one report; replay, prepare and discovery never reset it.
|
|
3275
|
+
*/
|
|
3276
|
+
function startViteHubHints(config, owner = config) {
|
|
3277
|
+
if (skipHints(config) || config["__vitehubNuxtHints"] || started.has(owner)) return;
|
|
3278
|
+
started.add(owner);
|
|
3279
|
+
write(startRun(config));
|
|
3280
|
+
}
|
|
3052
3281
|
/** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
|
|
3053
3282
|
function hostFromNitroPreset(value) {
|
|
3054
3283
|
const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
|
|
@@ -18337,7 +18566,7 @@ var binding_default = defineComarkPlugin((opts = {}) => {
|
|
|
18337
18566
|
markdownItPlugins: [((md) => markdownItInlineBinding(md, opts))]
|
|
18338
18567
|
};
|
|
18339
18568
|
});
|
|
18340
|
-
// ../markdown-template/dist/prepare-
|
|
18569
|
+
// ../markdown-template/dist/prepare-CBQsr2Jb.js
|
|
18341
18570
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
18342
18571
|
const markdownTemplateErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
18343
18572
|
docsBase: "https://vitehub.dev/docs/markdown-template/diagnostics",
|
|
@@ -18360,7 +18589,15 @@ const markdownTemplateErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
18360
18589
|
},
|
|
18361
18590
|
MARKDOWN_TEMPLATE_BINDING_OUTSIDE_DATA: {
|
|
18362
18591
|
why: ({ path }) => `The binding "${path}" does not start with \`data.\`. A template reads each value from \`data\`, so "${path}" is never defined.`,
|
|
18363
|
-
fix: "Start each binding with `data.`: write `{{ data.name }}` in place of `{{ name }}`, and `:href=\"data.url\"` in place of `:href=\"url\"`. Pass the same values in `data`."
|
|
18592
|
+
fix: "Start each binding with `data.`: write `{{ data.name }}` in place of `{{ name }}`, and `:href=\"data.url\"` in place of `:href=\"url\"`. Pass the same values in `data`. Inside `::each`, a binding can also start with the item name, such as `{{ file.name }}`."
|
|
18593
|
+
},
|
|
18594
|
+
MARKDOWN_TEMPLATE_EACH_ITEMS: {
|
|
18595
|
+
why: ({ path, found }) => `The \`::each\` items "${path}" ${found}, so the block has no list to repeat.`,
|
|
18596
|
+
fix: "Bind `:items` to a `data.<path>` that holds an array, such as `::each{:items=\"data.files\" as=\"file\"}`. Pass an empty array to render nothing."
|
|
18597
|
+
},
|
|
18598
|
+
MARKDOWN_TEMPLATE_EACH_PROPS: {
|
|
18599
|
+
why: ({ detail }) => detail,
|
|
18600
|
+
fix: "Give `::each` a bound `:items` prop and an optional `as` name, such as `::each{:items=\"data.files\" as=\"file\"}`. The name is a plain identifier other than `data`, `frontmatter`, `meta`, and `props`. Without `as`, the name is `item`. To repeat table rows, put the whole table, with its header, inside `::each`."
|
|
18364
18601
|
},
|
|
18365
18602
|
MARKDOWN_TEMPLATE_R0011: {
|
|
18366
18603
|
...dynamicError,
|
|
@@ -18471,10 +18708,16 @@ const bindingRoots = /* @__PURE__ */ new Set([
|
|
|
18471
18708
|
"meta",
|
|
18472
18709
|
"props"
|
|
18473
18710
|
]);
|
|
18474
|
-
/** Rejects a bound path that starts with no known name, such as `{{ name }}` from templates before `data.` paths. */
|
|
18475
|
-
function assertBindingRoot(value) {
|
|
18711
|
+
/** Rejects a bound path that starts with no known name, such as `{{ name }}` from templates before `data.` paths. `inScope` accepts the item names of the enclosing `::each` blocks. */
|
|
18712
|
+
function assertBindingRoot(value, inScope = () => false) {
|
|
18476
18713
|
const root = bindingRoot(value);
|
|
18477
|
-
if (root !== void 0 && !bindingRoots.has(root)) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_BINDING_OUTSIDE_DATA({ path: value });
|
|
18714
|
+
if (root !== void 0 && !bindingRoots.has(root) && !inScope(root)) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_BINDING_OUTSIDE_DATA({ path: value });
|
|
18715
|
+
}
|
|
18716
|
+
function isBindingRoot(name) {
|
|
18717
|
+
return bindingRoots.has(name);
|
|
18718
|
+
}
|
|
18719
|
+
function renderDataScope(renderData) {
|
|
18720
|
+
return (root) => Object.hasOwn(renderData, root);
|
|
18478
18721
|
}
|
|
18479
18722
|
function resolveTemplateAttributes(attributes, renderData) {
|
|
18480
18723
|
const values = Object.create(null);
|
|
@@ -18482,7 +18725,7 @@ function resolveTemplateAttributes(attributes, renderData) {
|
|
|
18482
18725
|
for (const [key, value] of Object.entries(attributes)) {
|
|
18483
18726
|
if (!key.startsWith(":") || typeof value !== "string") continue;
|
|
18484
18727
|
if (isJsonLiteral(value)) continue;
|
|
18485
|
-
assertBindingRoot(value);
|
|
18728
|
+
assertBindingRoot(value, renderDataScope(renderData));
|
|
18486
18729
|
const alias = `binding${Object.keys(values).length}`;
|
|
18487
18730
|
values[alias] = pathValue(renderData, value.split("."))?.value;
|
|
18488
18731
|
rewritten[key] = `props.${alias}`;
|
|
@@ -18652,7 +18895,7 @@ function validateBranches(template) {
|
|
|
18652
18895
|
}
|
|
18653
18896
|
if (stack.some((entry) => entry.tag === "if" || entry.tag === "else-if" || entry.tag === "else")) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_R0029({ message: "[vitehub] Markdown template if block is missing a closing :: line." });
|
|
18654
18897
|
}
|
|
18655
|
-
// ../markdown-template/dist/render-
|
|
18898
|
+
// ../markdown-template/dist/render-DF2Uc0-H.js
|
|
18656
18899
|
const ordered = (compare) => (value, expected) => (typeof value === "number" && typeof expected === "number" || typeof value === "string" && typeof expected === "string") && compare(value, expected);
|
|
18657
18900
|
const comparisons = {
|
|
18658
18901
|
eq: (value, expected) => value === expected,
|
|
@@ -18746,13 +18989,28 @@ const svgUrlAttributes = /* @__PURE__ */ new Set([
|
|
|
18746
18989
|
"image",
|
|
18747
18990
|
"use"
|
|
18748
18991
|
]);
|
|
18992
|
+
const rejectSplitEachTable = {
|
|
18993
|
+
name: "vitehub:each-table",
|
|
18994
|
+
markdownItPost({ tokens }) {
|
|
18995
|
+
for (const [index, token] of tokens.entries()) {
|
|
18996
|
+
if (token.type !== "table_open" || !token.map) continue;
|
|
18997
|
+
let close = index + 1;
|
|
18998
|
+
while (close < tokens.length && tokens[close]?.type !== "table_close") close++;
|
|
18999
|
+
if (tokens[close - 1]?.type !== "thead_close") continue;
|
|
19000
|
+
const each = tokens[close + 1];
|
|
19001
|
+
const paragraph = tokens[close + 2];
|
|
19002
|
+
const row = tokens[close + 3];
|
|
19003
|
+
if (each?.type === "mdc_block_open" && each.tag === "each" && each.map?.[0] === token.map[1] && paragraph?.type === "paragraph_open" && paragraph.map?.[0] === token.map[1] + 1 && row?.type === "inline" && /^\|(?:[^\\|\n]|\\.)*\|/.test(row.content.trimStart())) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_EACH_PROPS({ detail: "A table row inside `::each` cannot join a table header outside it. Put the whole table, with its header, inside `::each`." });
|
|
19004
|
+
}
|
|
19005
|
+
}
|
|
19006
|
+
};
|
|
18749
19007
|
async function renderMarkdownTemplate(template, options = {}) {
|
|
18750
19008
|
return await renderMarkdownTemplateInternal(template, options);
|
|
18751
19009
|
}
|
|
18752
19010
|
async function renderMarkdownTemplateInternal(template, options = {}) {
|
|
18753
19011
|
if (typeof template !== "string") throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_R0014({ message: "[vitehub] Markdown template must be a string." });
|
|
18754
19012
|
const prepared = await prepareTemplate(template);
|
|
18755
|
-
const parseOptions = templateParserOptions(options.plugins);
|
|
19013
|
+
const parseOptions = templateParserOptions([...options.plugins ?? [], rejectSplitEachTable]);
|
|
18756
19014
|
const tree = await parseMarkdown(prepared.template, parseOptions);
|
|
18757
19015
|
const bindingPositions = /* @__PURE__ */ new WeakMap();
|
|
18758
19016
|
const data = snapshotTemplateData(options.data ?? {});
|
|
@@ -18781,14 +19039,50 @@ async function renderMarkdownTemplateInternal(template, options = {}) {
|
|
|
18781
19039
|
};
|
|
18782
19040
|
return prepared.restore((await renderMarkdown(tree, { components: {
|
|
18783
19041
|
Binding: async (node, state, parent) => {
|
|
18784
|
-
if (typeof node[1][":value"] === "string") assertBindingRoot(node[1][":value"]);
|
|
18785
|
-
|
|
18786
|
-
|
|
19042
|
+
if (typeof node[1][":value"] === "string") assertBindingRoot(node[1][":value"], renderDataScope(renderData(state)));
|
|
19043
|
+
const index = parent && bindingIndex(node, parent, bindingPositions);
|
|
19044
|
+
rejectLinkDestinationBinding(node, parent, index);
|
|
19045
|
+
const value = resolveScalarTemplateBinding(node[1], renderData(state));
|
|
19046
|
+
if (state.context.link !== true && !(parent?.[1].$?.html === 1 && parent[1].$?.block === 1) && isAutolinkUrl(value) && isStandaloneBinding(parent, index)) return `<${value}>`;
|
|
19047
|
+
return state.one(value, state, parent, true);
|
|
18787
19048
|
},
|
|
18788
19049
|
If: async (node, state, parent) => {
|
|
18789
19050
|
const { branches, after } = conditionalBranches(node);
|
|
18790
19051
|
return await renderNodes([...branches.find((branch) => branch[0] === "else" || matchesCondition(branch[1], renderData(state), options.validateConditionPath))?.slice(2) ?? [], ...after], state, parent);
|
|
18791
19052
|
},
|
|
19053
|
+
Each: async (node, state, parent) => {
|
|
19054
|
+
if (node[1].$?.html === 1) return await renderAuthoredHtml(node, state, parent, "markdown");
|
|
19055
|
+
const name = eachItemName(node[1]);
|
|
19056
|
+
const path = String(node[1][":items"]);
|
|
19057
|
+
const items = resolveTemplateAttributes({ ":items": node[1][":items"] }, renderData(state)).items;
|
|
19058
|
+
if (!Array.isArray(items)) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_EACH_ITEMS({
|
|
19059
|
+
path,
|
|
19060
|
+
found: items === void 0 || items === null ? "is not defined" : "is not an array"
|
|
19061
|
+
});
|
|
19062
|
+
const children = node.slice(2);
|
|
19063
|
+
const [first] = children;
|
|
19064
|
+
const singleTable = children.length === 1 && Array.isArray(first) && first[0] === "table" && first[1].$?.html !== 1;
|
|
19065
|
+
let rendered = "";
|
|
19066
|
+
let end = "";
|
|
19067
|
+
for (let index = 0; index < items.length; index++) {
|
|
19068
|
+
const raw = await renderNodes(children, {
|
|
19069
|
+
...state,
|
|
19070
|
+
renderData: {
|
|
19071
|
+
...state.renderData,
|
|
19072
|
+
[name]: items[index]
|
|
19073
|
+
}
|
|
19074
|
+
}, parent);
|
|
19075
|
+
const block = raw.replace(/^\n+|\n+$/g, "");
|
|
19076
|
+
if (!block) continue;
|
|
19077
|
+
end = /\n*$/.exec(raw)[0];
|
|
19078
|
+
if (!rendered) rendered = block;
|
|
19079
|
+
else if (singleTable) {
|
|
19080
|
+
const rows = block.split("\n").slice(2).join("\n");
|
|
19081
|
+
if (rows) rendered += `\n${rows}`;
|
|
19082
|
+
} else rendered = joinRepeatedBlocks(rendered, block);
|
|
19083
|
+
}
|
|
19084
|
+
return rendered + end;
|
|
19085
|
+
},
|
|
18792
19086
|
Else: unexpectedBranch,
|
|
18793
19087
|
ElseIf: unexpectedBranch,
|
|
18794
19088
|
Insert: async (node, state, parent) => {
|
|
@@ -18815,8 +19109,8 @@ async function renderMarkdownTemplateInternal(template, options = {}) {
|
|
|
18815
19109
|
rejectBoundEventHandlers(node[1]);
|
|
18816
19110
|
const sanitized = authoredHtml ? await sanitizeUrlAttributes("a", props, node[1]) : props;
|
|
18817
19111
|
const href = Object.hasOwn(node[1], ":href") ? await safeLinkDestination(resolveScalarTemplateBinding({ ":value": node[1][":href"] }, renderData(state)), String(node[1][":href"])) : authoredHtml ? sanitized.href : void 0;
|
|
18818
|
-
if (href === void 0) return await
|
|
18819
|
-
return await
|
|
19112
|
+
if (href === void 0) return await renderLink(node, state, parent);
|
|
19113
|
+
return await renderLink([
|
|
18820
19114
|
node[0],
|
|
18821
19115
|
{
|
|
18822
19116
|
...sanitized,
|
|
@@ -18836,8 +19130,18 @@ async function renderMarkdownTemplateInternal(template, options = {}) {
|
|
|
18836
19130
|
}
|
|
18837
19131
|
} })).trim());
|
|
18838
19132
|
}
|
|
18839
|
-
function
|
|
18840
|
-
|
|
19133
|
+
function isAutolinkUrl(value) {
|
|
19134
|
+
return /^(?:(?:https?|ftp):\/\/|mailto:)[^\s<>\\|]+$/i.test(value) && URL.canParse(value);
|
|
19135
|
+
}
|
|
19136
|
+
async function renderLink(node, state, parent) {
|
|
19137
|
+
const revert = state.applyContext({ link: true });
|
|
19138
|
+
try {
|
|
19139
|
+
return await state.handlers.a(node, state, parent);
|
|
19140
|
+
} finally {
|
|
19141
|
+
state.applyContext(revert);
|
|
19142
|
+
}
|
|
19143
|
+
}
|
|
19144
|
+
function bindingIndex(node, parent, positions) {
|
|
18841
19145
|
let indexes = positions.get(parent);
|
|
18842
19146
|
if (!indexes) {
|
|
18843
19147
|
indexes = /* @__PURE__ */ new Map();
|
|
@@ -18847,8 +19151,22 @@ function rejectLinkDestinationBinding(node, parent, positions) {
|
|
|
18847
19151
|
}
|
|
18848
19152
|
positions.set(parent, indexes);
|
|
18849
19153
|
}
|
|
18850
|
-
|
|
18851
|
-
|
|
19154
|
+
return indexes.get(node);
|
|
19155
|
+
}
|
|
19156
|
+
function isStandaloneBinding(parent, index) {
|
|
19157
|
+
if (!parent) return true;
|
|
19158
|
+
if (index === void 0) return false;
|
|
19159
|
+
const before = index > 2 ? parent[index - 1] : void 0;
|
|
19160
|
+
if (before !== void 0 && !(typeof before === "string" && /[\s([{"'“‘]$/.test(before)) && !(Array.isArray(before) && before[0] === "br")) return false;
|
|
19161
|
+
const after = parent[index + 1];
|
|
19162
|
+
if (after === void 0 || Array.isArray(after) && after[0] === "br") return true;
|
|
19163
|
+
if (typeof after !== "string") return false;
|
|
19164
|
+
const boundary = /^[.,!?;:)\]}'"”’]*(\s|$)/.exec(after);
|
|
19165
|
+
const next = parent[index + 2];
|
|
19166
|
+
return boundary !== null && (boundary[1] !== "" || next === void 0 || Array.isArray(next) && next[0] === "br");
|
|
19167
|
+
}
|
|
19168
|
+
function rejectLinkDestinationBinding(node, parent, index) {
|
|
19169
|
+
if (!parent || index === void 0 || index < 3) return;
|
|
18852
19170
|
const before = parent[index - 1];
|
|
18853
19171
|
const after = parent[index + 1];
|
|
18854
19172
|
if (typeof before !== "string" || typeof after !== "string") return;
|
|
@@ -18920,6 +19238,18 @@ async function renderNodes(nodes, state, parent) {
|
|
|
18920
19238
|
for (const node of nodes) rendered += await state.one(node, state, parent, !rendered || rendered.endsWith("\n"));
|
|
18921
19239
|
return rendered;
|
|
18922
19240
|
}
|
|
19241
|
+
const listStart = /^(?:[-*+]|\d+[.)])[\t ]/;
|
|
19242
|
+
function joinRepeatedBlocks(before, block) {
|
|
19243
|
+
const lastBlock = before.split(/\n{2,}/).filter((chunk) => !/^[\t ]/.test(chunk)).at(-1) ?? "";
|
|
19244
|
+
return `${before}${listStart.test(lastBlock) && listStart.test(block) ? "\n" : "\n\n"}${block}`;
|
|
19245
|
+
}
|
|
19246
|
+
function eachItemName(attributes) {
|
|
19247
|
+
if (typeof attributes[":items"] !== "string") throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_EACH_PROPS({ detail: Object.hasOwn(attributes, "items") ? "The `::each` items prop must be bound: write `:items` in place of `items`." : "`::each` needs a bound `:items` prop." });
|
|
19248
|
+
for (const key of Object.keys(attributes)) if (key !== "$" && key !== ":items" && key !== "as") throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_EACH_PROPS({ detail: `\`::each\` does not accept the "${key}" prop.` });
|
|
19249
|
+
const name = attributes.as ?? "item";
|
|
19250
|
+
if (typeof name !== "string" || !/^[A-Za-z_]\w*$/.test(name) || isBindingRoot(name)) throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_EACH_PROPS({ detail: `The \`::each\` name "${String(name)}" is not a plain identifier, or it is a reserved name.` });
|
|
19251
|
+
return name;
|
|
19252
|
+
}
|
|
18923
19253
|
const unexpectedBranch = (node) => {
|
|
18924
19254
|
throw markdownTemplateErrorDiagnostics.MARKDOWN_TEMPLATE_R0015({ message: `[vitehub] Markdown template ${node[0]} block must follow an if block.` });
|
|
18925
19255
|
};
|
|
@@ -18970,7 +19300,7 @@ async function flattenPlugins(value, plugins, seen) {
|
|
|
18970
19300
|
for (const item of value) await flattenPlugins(item, plugins, seen);
|
|
18971
19301
|
return;
|
|
18972
19302
|
}
|
|
18973
|
-
if (!isRecord
|
|
19303
|
+
if (!isRecord(value) || seen.has(value)) return;
|
|
18974
19304
|
seen.add(value);
|
|
18975
19305
|
if (isThenable(value)) {
|
|
18976
19306
|
await flattenPlugins(await value, plugins, seen);
|
|
@@ -19002,7 +19332,7 @@ async function collectContributions(plugins, options) {
|
|
|
19002
19332
|
for (const plugin of candidates) {
|
|
19003
19333
|
if (!Object.hasOwn(plugin, "vitehub")) continue;
|
|
19004
19334
|
const metadata = Reflect.get(plugin, "vitehub");
|
|
19005
|
-
if (!isRecord
|
|
19335
|
+
if (!isRecord(metadata) || !Object.hasOwn(metadata, options.key)) continue;
|
|
19006
19336
|
const source = metadata[options.key];
|
|
19007
19337
|
const pluginName = Reflect.get(plugin, "name");
|
|
19008
19338
|
const contributor = isNonEmptyString(pluginName) ? pluginName : unnamedPlugin;
|
|
@@ -19030,12 +19360,12 @@ async function collectContributions(plugins, options) {
|
|
|
19030
19360
|
return [...collected.values()].map(({ contribution }) => contribution).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
19031
19361
|
}
|
|
19032
19362
|
function readContribution(entry, plugin, options, fail) {
|
|
19033
|
-
if (!isRecord
|
|
19363
|
+
if (!isRecord(entry)) return fail("expected { name, definition: { module, export? }, reason? }.");
|
|
19034
19364
|
const { definition, name, reason } = entry;
|
|
19035
19365
|
if (!isNonEmptyString(name) || name.trim() !== name) return fail("`name` must be a non-empty string without surrounding whitespace.");
|
|
19036
19366
|
const nameProblem = options.checkName?.(name);
|
|
19037
19367
|
if (nameProblem) return fail(`${options.kind} ${JSON.stringify(name)}: ${nameProblem}`);
|
|
19038
|
-
if (!isRecord
|
|
19368
|
+
if (!isRecord(definition)) return fail(`${options.kind} ${JSON.stringify(name)} needs \`definition: { module, export? }\`.`);
|
|
19039
19369
|
if (!isNonEmptyString(definition.module)) return fail(`\`definition.module\` of ${options.kind} ${JSON.stringify(name)} must be a non-empty string.`);
|
|
19040
19370
|
let module;
|
|
19041
19371
|
try {
|
|
@@ -19104,10 +19434,10 @@ function stripComments(source) {
|
|
|
19104
19434
|
return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
19105
19435
|
}
|
|
19106
19436
|
function isAgentConfig(file) {
|
|
19107
|
-
return /\bdefineAgent\s*\(/.test(stripComments(
|
|
19437
|
+
return /\bdefineAgent\s*\(/.test(stripComments(readSourceText(file)));
|
|
19108
19438
|
}
|
|
19109
19439
|
function isWorkspaceAgentDefinition(file) {
|
|
19110
|
-
return /\bdefineAgent\s*\(\s*\{[\s\S]*?\bworkspace\s*:/.test(stripComments(
|
|
19440
|
+
return /\bdefineAgent\s*\(\s*\{[\s\S]*?\bworkspace\s*:/.test(stripComments(readSourceText(file)));
|
|
19111
19441
|
}
|
|
19112
19442
|
function collectDirectoriesWithConfig(root) {
|
|
19113
19443
|
const directories = /* @__PURE__ */ new Set();
|
|
@@ -20302,7 +20632,7 @@ async function readWorkspaceDiscovery(parsed, context, fetchImpl) {
|
|
|
20302
20632
|
});
|
|
20303
20633
|
if (!server) return;
|
|
20304
20634
|
const { discovery, url } = server;
|
|
20305
|
-
if (!(Array.isArray(discovery.workspaces) ? discovery.workspaces.flatMap((workspace) => isRecord
|
|
20635
|
+
if (!(Array.isArray(discovery.workspaces) ? discovery.workspaces.flatMap((workspace) => isRecord(workspace) && typeof workspace.name === "string" ? [workspace.name] : []) : []).includes(parsed.workspace)) {
|
|
20306
20636
|
context.stderr.write(`Unknown Workspace Dev target: ${parsed.workspace}\n`);
|
|
20307
20637
|
return;
|
|
20308
20638
|
}
|
|
@@ -20425,6 +20755,48 @@ function workspaceDefinitionKind(definition) {
|
|
|
20425
20755
|
if (definition.source === "vite-plugin-contribution") return "Contributed Workspace Definition";
|
|
20426
20756
|
return "Workspace Definition";
|
|
20427
20757
|
}
|
|
20758
|
+
function namedWorkspaceExport(module, name) {
|
|
20759
|
+
for (const statement of module.program.body) {
|
|
20760
|
+
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
20761
|
+
const declaration = statement.declaration;
|
|
20762
|
+
if (declaration?.type !== "VariableDeclaration" || declaration.kind !== "const") continue;
|
|
20763
|
+
for (const binding of declaration.declarations) if (binding.id.type === "Identifier" && binding.id.name === name) return binding.init ?? void 0;
|
|
20764
|
+
}
|
|
20765
|
+
}
|
|
20766
|
+
async function declaredSources(file, exportName = "default") {
|
|
20767
|
+
if (!isAbsolute(file)) return;
|
|
20768
|
+
let source;
|
|
20769
|
+
try {
|
|
20770
|
+
source = readFileSync(file, "utf8");
|
|
20771
|
+
} catch {
|
|
20772
|
+
return;
|
|
20773
|
+
}
|
|
20774
|
+
const { argumentExpression, defaultExportExpression, objectProperties, scanModule, unwrapExpression } = await import("./workspace-inspection-scanner-BlJ8bCAB.js").then((n) => n.t);
|
|
20775
|
+
const module = scanModule(source, file);
|
|
20776
|
+
if (module.errors.length) return;
|
|
20777
|
+
const exported = exportName === "default" ? defaultExportExpression(module) : namedWorkspaceExport(module, exportName);
|
|
20778
|
+
const call = exported && unwrapExpression(exported);
|
|
20779
|
+
if (call?.type !== "CallExpression" || call.callee.type !== "Identifier" || call.callee.name !== "defineWorkspace") return;
|
|
20780
|
+
const options = argumentExpression(call.arguments[0]);
|
|
20781
|
+
if (options?.type !== "ObjectExpression") return "set at runtime";
|
|
20782
|
+
const property = objectProperties(options).findLast(({ key }) => key === "sources" || key === void 0);
|
|
20783
|
+
if (!property) return;
|
|
20784
|
+
if (property.key === void 0 || property.value?.type !== "ObjectExpression") return "set at runtime";
|
|
20785
|
+
const names = /* @__PURE__ */ new Map();
|
|
20786
|
+
for (const { key, value } of objectProperties(property.value)) {
|
|
20787
|
+
if (key === void 0) return "set at runtime";
|
|
20788
|
+
const loader = value?.type === "CallExpression" && value.callee.type === "Identifier" ? value.callee.name : void 0;
|
|
20789
|
+
names.set(key, loader ? `${key} (${loader})` : key);
|
|
20790
|
+
}
|
|
20791
|
+
return names.size ? [...names.values()].join(", ") : "none";
|
|
20792
|
+
}
|
|
20793
|
+
async function sourcesField(definition) {
|
|
20794
|
+
const value = await declaredSources(definition.handler, definition.export);
|
|
20795
|
+
return value ? [{
|
|
20796
|
+
label: "Sources",
|
|
20797
|
+
value
|
|
20798
|
+
}] : [];
|
|
20799
|
+
}
|
|
20428
20800
|
/** Lists Workspace Definitions, Agent workspaces, and contributed Workspaces as serializable inspection summaries. */
|
|
20429
20801
|
async function inspectWorkspaceDefinitions(options) {
|
|
20430
20802
|
const contributions = await collectWorkspaceContributions(options.plugins, {
|
|
@@ -20433,11 +20805,12 @@ async function inspectWorkspaceDefinitions(options) {
|
|
|
20433
20805
|
root: options.rootDir,
|
|
20434
20806
|
serverDirs: options.serverDirs
|
|
20435
20807
|
});
|
|
20436
|
-
|
|
20808
|
+
const definitions = discoverViteWorkspaceDefinitions(options.rootDir, {
|
|
20437
20809
|
contributions,
|
|
20438
20810
|
serverDirs: options.serverDirs,
|
|
20439
20811
|
serverRootDir: options.serverRootDir
|
|
20440
|
-
})
|
|
20812
|
+
});
|
|
20813
|
+
return Promise.all(definitions.map(async (definition) => ({
|
|
20441
20814
|
fields: [
|
|
20442
20815
|
{
|
|
20443
20816
|
label: "Kind",
|
|
@@ -20457,13 +20830,14 @@ async function inspectWorkspaceDefinitions(options) {
|
|
|
20457
20830
|
}] : [],
|
|
20458
20831
|
...definition.sourceRootDir ? [{
|
|
20459
20832
|
label: "Source root",
|
|
20460
|
-
value: relativeDefinitionFile(options.projectRoot, definition.sourceRootDir)
|
|
20461
|
-
}] : []
|
|
20833
|
+
value: relativeDefinitionFile(options.projectRoot, definition.sourceRootDir) || "."
|
|
20834
|
+
}] : [],
|
|
20835
|
+
...await sourcesField(definition)
|
|
20462
20836
|
],
|
|
20463
20837
|
file: isAbsolute(definition.handler) ? relativeDefinitionFile(options.projectRoot, definition.handler) : definition.handler,
|
|
20464
20838
|
name: definition.name,
|
|
20465
20839
|
source: definition.source || "workspace"
|
|
20466
|
-
}));
|
|
20840
|
+
})));
|
|
20467
20841
|
}
|
|
20468
20842
|
/** Console section that lists discovered Workspace Definitions. `vitehub inspect definitions` reads the same data. */
|
|
20469
20843
|
const workspaceConsoleSection = {
|
|
@@ -20547,10 +20921,10 @@ function vercelFunctionRuntimePackages() {
|
|
|
20547
20921
|
}];
|
|
20548
20922
|
}
|
|
20549
20923
|
function hasCloudflareArtifactBinding(value) {
|
|
20550
|
-
return
|
|
20924
|
+
return isObject(value) && typeof value.binding === "string";
|
|
20551
20925
|
}
|
|
20552
20926
|
function configuredCloudflareArtifacts(wranglerConfig) {
|
|
20553
|
-
if (!
|
|
20927
|
+
if (!isObject(wranglerConfig) || !Array.isArray(wranglerConfig.artifacts)) return [];
|
|
20554
20928
|
return wranglerConfig.artifacts.filter(hasCloudflareArtifactBinding);
|
|
20555
20929
|
}
|
|
20556
20930
|
function createCloudflareArtifactsWranglerConfig(configs) {
|
|
@@ -20605,7 +20979,7 @@ async function readStaticWorkspaceStore(file, loader, exportedName = "default")
|
|
|
20605
20979
|
if (!properties) return;
|
|
20606
20980
|
const storeProperty = properties.findLast((property) => (property.key?.name ?? property.key?.value) === "store");
|
|
20607
20981
|
if (!storeProperty) {
|
|
20608
|
-
staticStore = {};
|
|
20982
|
+
staticStore = { usage: "default" };
|
|
20609
20983
|
return;
|
|
20610
20984
|
}
|
|
20611
20985
|
if (storeProperty.type !== "ObjectProperty") return;
|
|
@@ -20616,6 +20990,10 @@ async function readStaticWorkspaceStore(file, loader, exportedName = "default")
|
|
|
20616
20990
|
}
|
|
20617
20991
|
const storeProperties = babelStaticObjectProperties(store);
|
|
20618
20992
|
if (!storeProperties) return;
|
|
20993
|
+
if (storeProperties.length === 0) {
|
|
20994
|
+
staticStore = { usage: "implicit" };
|
|
20995
|
+
return;
|
|
20996
|
+
}
|
|
20619
20997
|
const readFile = storeProperties.findLast((property) => (property.key?.name ?? property.key?.value) === "readFile");
|
|
20620
20998
|
if (readFile) {
|
|
20621
20999
|
if (readFile.type === "ObjectMethod" && readFile.kind === "method") staticStore = {};
|
|
@@ -20649,6 +21027,7 @@ async function resolveDefinitionCloudflareArtifactsConfigs(definitions, rootDir,
|
|
|
20649
21027
|
message: `[vitehub] Workspace "${definition.name}" sets a store that may need a Cloudflare Artifacts binding, but the build cannot load ${definitionFile} to read it: ${error instanceof Error ? error.message : String(error)}`
|
|
20650
21028
|
});
|
|
20651
21029
|
options.storeUsage?.add("unknown");
|
|
21030
|
+
if (store.usage) options.storeUsage?.add(store.usage);
|
|
20652
21031
|
if (store.driver === "github") options.storeUsage?.add("github");
|
|
20653
21032
|
continue;
|
|
20654
21033
|
}
|
|
@@ -20656,6 +21035,7 @@ async function resolveDefinitionCloudflareArtifactsConfigs(definitions, rootDir,
|
|
|
20656
21035
|
const workspace = normalizeWorkspaceDefinition(definition.name, loaded);
|
|
20657
21036
|
if (!workspace.store) options.storeUsage?.add("default");
|
|
20658
21037
|
if (!workspace.store || isWorkspaceStore(workspace.store)) continue;
|
|
21038
|
+
if (isImplicitWorkspaceStore(workspace.store)) options.storeUsage?.add("implicit");
|
|
20659
21039
|
const config = normalizeWorkspaceOptions({ store: workspace.store }, {
|
|
20660
21040
|
dev: false,
|
|
20661
21041
|
env: options.env || process.env,
|
|
@@ -20679,6 +21059,9 @@ async function resolveDefinitionCloudflareArtifactsConfigs(definitions, rootDir,
|
|
|
20679
21059
|
function definitionsToLoad(definitions, command, hosting) {
|
|
20680
21060
|
return command !== "serve" || getHostingProvider(hosting) === "cloudflare" ? definitions : [];
|
|
20681
21061
|
}
|
|
21062
|
+
function isImplicitWorkspaceStore(store) {
|
|
21063
|
+
return !store || !isWorkspaceStore(store) && store.driver === void 0 && !store.root;
|
|
21064
|
+
}
|
|
20682
21065
|
async function resolveCloudflareArtifactsConfigs(config, definitions, rootDir, options = {}) {
|
|
20683
21066
|
return [...config.store.driver === "cloudflare" ? [config] : [], ...await resolveDefinitionCloudflareArtifactsConfigs(definitions, rootDir, options)];
|
|
20684
21067
|
}
|
|
@@ -20744,11 +21127,8 @@ async function collectPluginWorkspaceContributions(plugins, roots, serverDirs) {
|
|
|
20744
21127
|
serverDirs
|
|
20745
21128
|
});
|
|
20746
21129
|
}
|
|
20747
|
-
function isRecord(value) {
|
|
20748
|
-
return typeof value === "object" && value !== null;
|
|
20749
|
-
}
|
|
20750
21130
|
function isWorkspaceRegistry(value) {
|
|
20751
|
-
return
|
|
21131
|
+
return isObject(value) && Object.values(value).every((item) => typeof item === "function");
|
|
20752
21132
|
}
|
|
20753
21133
|
function workspaceDefinitionLoaderAliases(aliases) {
|
|
20754
21134
|
if (!Array.isArray(aliases)) return aliases;
|
|
@@ -20772,7 +21152,7 @@ function resolveNitroHostedStoreProviders(config, definitionCount, storeUsage) {
|
|
|
20772
21152
|
if (storeUsage.has("unknown")) return new Set(hostedWorkspaceStoreDrivers);
|
|
20773
21153
|
const providers = new Set(configProvider ? [configProvider] : []);
|
|
20774
21154
|
for (const usage of storeUsage) {
|
|
20775
|
-
if (usage === "unknown") continue;
|
|
21155
|
+
if (usage === "unknown" || usage === "implicit") continue;
|
|
20776
21156
|
if (usage === "default") {
|
|
20777
21157
|
if (!config) providers.add("vercel");
|
|
20778
21158
|
continue;
|
|
@@ -20865,7 +21245,7 @@ async function handleWorkspaceDevRequest(server, req, workspaces, tokenOptions,
|
|
|
20865
21245
|
} catch {
|
|
20866
21246
|
return new Response("Malformed Workspace Dev payload.", { status: 400 });
|
|
20867
21247
|
}
|
|
20868
|
-
const command =
|
|
21248
|
+
const command = isObject(body) && isObject(body.workspaceCommand) ? body.workspaceCommand : void 0;
|
|
20869
21249
|
if (!command || typeof command.workspace !== "string" || typeof command.command !== "string") return new Response("Missing Workspace Dev command.", { status: 400 });
|
|
20870
21250
|
if (!await validateWorkspaceDevToken(server.config.root, req.headers, tokenOptions)) return new Response("Forbidden Workspace Dev token.", { status: 403 });
|
|
20871
21251
|
const mod = await server.ssrLoadModule(WORKSPACE_REGISTRY_ID);
|
|
@@ -20888,7 +21268,7 @@ async function handleWorkspaceDevRequest(server, req, workspaces, tokenOptions,
|
|
|
20888
21268
|
...args ? { args } : {},
|
|
20889
21269
|
command: command.command,
|
|
20890
21270
|
host,
|
|
20891
|
-
...
|
|
21271
|
+
...isObject(definition) ? { definition: normalizeWorkspaceDefinition(command.workspace, definition) } : {},
|
|
20892
21272
|
...paths?.length ? { paths } : {},
|
|
20893
21273
|
...timeout ? { timeout } : {},
|
|
20894
21274
|
workspace: command.workspace
|
|
@@ -20902,7 +21282,7 @@ async function handleWorkspaceDevRequest(server, req, workspaces, tokenOptions,
|
|
|
20902
21282
|
}
|
|
20903
21283
|
function hasNitroPlugin(value) {
|
|
20904
21284
|
if (Array.isArray(value)) return value.some(hasNitroPlugin);
|
|
20905
|
-
return
|
|
21285
|
+
return isObject(value) && typeof value.name === "string" && value.name.startsWith("nitro:");
|
|
20906
21286
|
}
|
|
20907
21287
|
function hasNitroConfig(config) {
|
|
20908
21288
|
return "nitro" in config || hasNitroPlugin(config.plugins);
|
|
@@ -20914,7 +21294,7 @@ function shouldInstallNitroWorkspacePlugin(config, options, normalized, definiti
|
|
|
20914
21294
|
return isHostedWorkspaceStore(normalized.store) || hasExplicitWorkspaceRuntimeOptions(options) || hasNitroConfig(config) && definitions.length > 0;
|
|
20915
21295
|
}
|
|
20916
21296
|
function mergeNitroWorkspaceConfig(value, root, dev) {
|
|
20917
|
-
const kit = createNitroServerKit(
|
|
21297
|
+
const kit = createNitroServerKit(isObject(value) ? { ...value } : {});
|
|
20918
21298
|
const pluginFile = resolve(root, generatedNitroWorkspacePlugin);
|
|
20919
21299
|
kit.addPlugin(pluginFile, dev ? "start" : "end");
|
|
20920
21300
|
if (!dev) {
|
|
@@ -20959,7 +21339,7 @@ function configureCloudflareNitroRuntime(nitro) {
|
|
|
20959
21339
|
nitro.cloudflare ??= {};
|
|
20960
21340
|
nitro.cloudflare.wrangler ??= {};
|
|
20961
21341
|
nitro.cloudflare.nodeCompat = true;
|
|
20962
|
-
const rollupConfig =
|
|
21342
|
+
const rollupConfig = isObject(nitro.rollupConfig) ? { ...nitro.rollupConfig } : {};
|
|
20963
21343
|
nitro.rollupConfig = {
|
|
20964
21344
|
...rollupConfig,
|
|
20965
21345
|
external: mergeNitroExternal(rollupConfig.external, "cloudflare:workers")
|
|
@@ -20980,7 +21360,7 @@ function renderRuntimeValue(value, depth = 0) {
|
|
|
20980
21360
|
const closingIndent = " ".repeat(depth);
|
|
20981
21361
|
return `[\n${value.map((item) => `${indent}${renderRuntimeValue(item, depth + 1)}`).join(",\n")}\n${closingIndent}]`;
|
|
20982
21362
|
}
|
|
20983
|
-
if (
|
|
21363
|
+
if (isObject(value)) {
|
|
20984
21364
|
const entries = Object.entries(value).filter(([, entry]) => entry !== void 0);
|
|
20985
21365
|
if (!entries.length) return "{}";
|
|
20986
21366
|
const indent = " ".repeat(depth + 1);
|
|
@@ -21143,6 +21523,8 @@ function hubWorkspace(options) {
|
|
|
21143
21523
|
let serverDirs;
|
|
21144
21524
|
let contributions = [];
|
|
21145
21525
|
let hasArtifacts = false;
|
|
21526
|
+
let workerMemoryNotice = false;
|
|
21527
|
+
let nitroPreset;
|
|
21146
21528
|
async function refreshManifest(roots) {
|
|
21147
21529
|
const definitions = discoverDefinitions(roots, serverDirs, contributions);
|
|
21148
21530
|
const state = await refreshWorkspaceBuildState(roots.projectRoot, definitions);
|
|
@@ -21168,7 +21550,10 @@ function hubWorkspace(options) {
|
|
|
21168
21550
|
}
|
|
21169
21551
|
return {
|
|
21170
21552
|
name: "@vite-hub/workspace/vite",
|
|
21171
|
-
nitro:
|
|
21553
|
+
nitro: { setup(nitro) {
|
|
21554
|
+
if (nitro.options.preset !== "nitro-prerender") nitroPreset = nitro.options.preset;
|
|
21555
|
+
packageLoading.nitro.setup(nitro);
|
|
21556
|
+
} },
|
|
21172
21557
|
enforce: "pre",
|
|
21173
21558
|
[setWorkspacePluginHosting](value) {
|
|
21174
21559
|
hosting = value;
|
|
@@ -21176,6 +21561,8 @@ function hubWorkspace(options) {
|
|
|
21176
21561
|
api: { getWorkspaces: () => manifest.workspaces },
|
|
21177
21562
|
async config(config, env) {
|
|
21178
21563
|
hasArtifacts = false;
|
|
21564
|
+
workerMemoryNotice = false;
|
|
21565
|
+
nitroPreset = void 0;
|
|
21179
21566
|
serverDirs = config["__vitehubServerDirs"] ?? serverDirs;
|
|
21180
21567
|
const workspaceOptions = publicOptions;
|
|
21181
21568
|
const roots = resolveWorkspacePluginRoots(config.root || process.cwd(), workspaceOptions);
|
|
@@ -21211,6 +21598,13 @@ function hubWorkspace(options) {
|
|
|
21211
21598
|
});
|
|
21212
21599
|
if (normalized.store.driver !== "github" && storeUsage?.has("github")) assertGitHubStoreAvailable?.();
|
|
21213
21600
|
hasArtifacts = artifacts.length > 0;
|
|
21601
|
+
const implicitModuleStore = isImplicitWorkspaceStore(workspaceOptions ? workspaceOptions.store : void 0) && (!runtimeConfig || runtimeConfig.store.driver === "memory");
|
|
21602
|
+
workerMemoryNotice = env?.command === "build" && (Boolean(storeUsage?.has("implicit")) || implicitModuleStore && (definitions.length === 0 || Boolean(storeUsage?.has("default"))));
|
|
21603
|
+
if (workerMemoryNotice && getHostingProvider(resolvedHosting) === "cloudflare" && typeof Reflect.get(config, "__vitehubNuxtHints") === "function") reportViteHubHint({
|
|
21604
|
+
...config,
|
|
21605
|
+
command: "build",
|
|
21606
|
+
root: roots.viteRoot
|
|
21607
|
+
}, workspaceErrorDiagnostics.WORKSPACE_STORE_IN_WORKER_MEMORY());
|
|
21214
21608
|
const usesCloudflareRuntime = hasArtifacts || getHostingProvider(resolvedHosting) === "cloudflare";
|
|
21215
21609
|
await writeNitroWorkspacePlugin(roots.projectRoot, runtimeConfig, runtimeOptions, definitions, usesCloudflareRuntime, definitionOverrides, storeUsage);
|
|
21216
21610
|
const nitro = mergeNitroWorkspaceConfig(config.nitro, roots.projectRoot, env?.command === "serve");
|
|
@@ -21234,6 +21628,7 @@ function hubWorkspace(options) {
|
|
|
21234
21628
|
return viteConfig;
|
|
21235
21629
|
},
|
|
21236
21630
|
async configResolved(config) {
|
|
21631
|
+
startViteHubHints(config);
|
|
21237
21632
|
resolved = config;
|
|
21238
21633
|
providerOutput = useProviderOutputCatalog(config);
|
|
21239
21634
|
const workspaceOptions = publicOptions;
|
|
@@ -21253,6 +21648,7 @@ function hubWorkspace(options) {
|
|
|
21253
21648
|
rootDir: roots.projectRoot
|
|
21254
21649
|
});
|
|
21255
21650
|
if (resolvedOptions) contributions = await collectPluginWorkspaceContributions(config.plugins, roots, serverDirs);
|
|
21651
|
+
if (workerMemoryNotice && config.command === "build" && getHostingProvider(nitroPreset ?? resolvedHosting) === "cloudflare" && !Reflect.get(config, "__vitehubNuxtHints")) reportViteHubHint(config, workspaceErrorDiagnostics.WORKSPACE_STORE_IN_WORKER_MEMORY());
|
|
21256
21652
|
assetsRegistryFile = resolve(roots.projectRoot, workspaceAssetsRegistryPath);
|
|
21257
21653
|
await initializeWorkspaceAssetRegistry(assetsRegistryFile);
|
|
21258
21654
|
await refreshManifest(roots);
|
|
@@ -21440,4 +21836,4 @@ function hubWorkspace(options) {
|
|
|
21440
21836
|
}
|
|
21441
21837
|
};
|
|
21442
21838
|
}
|
|
21443
|
-
export { collectWorkspaceContributions, createWorkspaceNitroConfig, discoverViteWorkspaceDefinitions, hubWorkspace, inspectWorkspaceDefinitions, workspaceConsoleSection };
|
|
21839
|
+
export { collectWorkspaceContributions, createWorkspaceNitroConfig, discoverViteWorkspaceDefinitions, hubWorkspace, inspectWorkspaceDefinitions, moduleLanguage as t, workspaceConsoleSection };
|