@vite-hub/source 0.1.0 → 0.3.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.
Files changed (48) hide show
  1. package/README.md +83 -49
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +30 -4
  4. package/dist/{collection-B_4w_J8h.d.ts → collection-B8sgxw5-.d.ts} +52 -19
  5. package/dist/collection-C0Rvrx3p.js +297 -0
  6. package/dist/drizzle.d.ts +11 -4
  7. package/dist/drizzle.js +6 -8
  8. package/dist/error-diagnostics-ClQKdi7c.js +194 -0
  9. package/dist/github-D5S0dEZe.js +1312 -0
  10. package/dist/{glob-BmFqTvJY.js → glob-DmdMVqjx.js} +1 -2
  11. package/dist/index.d.ts +186 -55
  12. package/dist/index.js +152 -207
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/mcp.d.ts +1 -1
  15. package/dist/mcp.js +25 -140
  16. package/dist/object-CtSHeGQO.js +17 -0
  17. package/dist/{path-BS8rYm0n.js → path-DFlSryRA.js} +32 -2
  18. package/dist/root-DJNmqCEW.js +11 -0
  19. package/dist/server.d.ts +7 -244
  20. package/dist/server.js +38 -45
  21. package/dist/{types-BigOktIj.d.ts → types-Ln-FxVFn.d.ts} +6 -1
  22. package/dist/vite.d.ts +77 -10
  23. package/dist/vite.js +619 -713
  24. package/package.json +25 -47
  25. package/dist/auth-B-tX_rp0.js +0 -1426
  26. package/dist/client-BwstxtdY.js +0 -8280
  27. package/dist/collection-cursor-WzV1Jd6v.js +0 -124
  28. package/dist/error-diagnostics-X0kuFjBT.js +0 -51
  29. package/dist/file-BX0FSvgE.js +0 -60
  30. package/dist/file-DadN9dbN.d.ts +0 -19
  31. package/dist/file.d.ts +0 -2
  32. package/dist/file.js +0 -2
  33. package/dist/files.d.ts +0 -15
  34. package/dist/files.js +0 -38
  35. package/dist/github.d.ts +0 -20
  36. package/dist/github.js +0 -1332
  37. package/dist/glob.d.ts +0 -23
  38. package/dist/glob.js +0 -2
  39. package/dist/markdown.d.ts +0 -5
  40. package/dist/markdown.js +0 -10
  41. package/dist/mrmime-40h5OOIp.js +0 -448
  42. package/dist/path-DOBpV8ol.js +0 -32
  43. package/dist/sse-D9gqqNPj.js +0 -448
  44. package/dist/streamableHttp-BL-E7pl5.js +0 -509
  45. package/dist/types-CoWcW8oz.js +0 -7590
  46. package/tsconfig.vite.json +0 -6
  47. package/types/source/fallback.d.ts +0 -1
  48. package/types/source/index.d.ts +0 -1
package/dist/vite.js CHANGED
@@ -1,13 +1,19 @@
1
1
  import { t as collectionRoutePath } from "./collection-route-BplWPxHR.js";
2
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
3
- import { i as resolveGlobInput, r as globFilePath, t as collectGlobFiles } from "./glob-BmFqTvJY.js";
4
- import { tmpdir } from "node:os";
2
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
3
+ import { r as isRecordOrFunction } from "./object-CtSHeGQO.js";
4
+ import { i as resolveGlobInput, r as globFilePath, t as collectGlobFiles } from "./glob-DmdMVqjx.js";
5
+ import { t as invariant } from "./invariant-DolT9EEx.js";
6
+ import { formatDiagnostic } from "nostics";
5
7
  import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
6
8
  import { basename, dirname, extname, isAbsolute, join, parse, relative, resolve } from "node:path";
7
9
  import { pathToFileURL } from "node:url";
8
- import { statSync } from "node:fs";
9
- import { findExportNames } from "mlly";
10
+ import { mkdirSync, statSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
10
12
  import { parseSync } from "vite";
13
+ import { randomUUID } from "node:crypto";
14
+ import { once } from "node:events";
15
+ import { createServer } from "node:http";
16
+ import { gzipSync } from "node:zlib";
11
17
  //#region ../internal/src/build/vite.ts
12
18
  const projectRootDirectoryMarkers = [
13
19
  ["server", "agents"],
@@ -26,6 +32,8 @@ const projectRootFileMarkers = [
26
32
  ["nuxt.config.mjs"]
27
33
  ];
28
34
  const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
35
+ /** The application's mount path, which can differ from Nuxt's Vite asset base. */
36
+ const VITEHUB_APP_BASE_URL = "__vitehubAppBaseURL";
29
37
  /**
30
38
  * Server directories that ViteHub scans for Definitions. The first entry is the application.
31
39
  * Later entries are Nuxt layers in Nuxt priority order.
@@ -78,38 +86,6 @@ function hasProjectRootFileMarker(root, markers) {
78
86
  return false;
79
87
  }
80
88
  //#endregion
81
- //#region ../internal/src/nitro-kit.ts
82
- function cloneArray(value) {
83
- return Array.isArray(value) ? [...value] : [];
84
- }
85
- function isRecord(value) {
86
- return Object(value) === value && !Array.isArray(value);
87
- }
88
- function sameHandler(left, right) {
89
- return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
90
- }
91
- /** Create a Nitro 3 configuration builder for generated ViteHub output. */
92
- function createNitroServerKit(value = {}) {
93
- const config = isRecord(value) ? { ...value } : {};
94
- const handlers = cloneArray(config.handlers);
95
- const plugins = cloneArray(config.plugins);
96
- config.handlers = handlers;
97
- config.plugins = plugins;
98
- return {
99
- config,
100
- addHandler(handler, position = "end") {
101
- if (handlers.some((candidate) => isRecord(candidate) && sameHandler(candidate, handler))) return;
102
- if (position === "start") handlers.unshift({ ...handler });
103
- else handlers.push({ ...handler });
104
- },
105
- addPlugin(plugin, position = "end") {
106
- if (plugins.includes(plugin)) return;
107
- if (position === "start") plugins.unshift(plugin);
108
- else plugins.push(plugin);
109
- }
110
- };
111
- }
112
- //#endregion
113
89
  //#region ../internal/src/build/scan-module.ts
114
90
  /**
115
91
  * Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
@@ -139,6 +115,18 @@ function scanModule(source, file = "module.ts") {
139
115
  source
140
116
  };
141
117
  }
118
+ /** Lists the names that a module exports. A default export reads as `default`. Type-only exports are left out. */
119
+ function exportNames(source, file = "module.ts") {
120
+ const { module } = parseSync(file, source, {
121
+ lang: languageOf(file),
122
+ sourceType: "module"
123
+ });
124
+ return module.staticExports.flatMap((statement) => statement.entries).flatMap((entry) => {
125
+ if (entry.isType) return [];
126
+ if (entry.exportName.kind === "Default") return ["default"];
127
+ return entry.exportName.name === null ? [] : [entry.exportName.name];
128
+ });
129
+ }
142
130
  function isNode$1(value) {
143
131
  return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
144
132
  }
@@ -271,6 +259,178 @@ function staticString(node) {
271
259
  return typeof value === "string" ? value : void 0;
272
260
  }
273
261
  //#endregion
262
+ //#region ../internal/src/hints.ts
263
+ /**
264
+ * The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
265
+ * about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
266
+ * the file instead of the terminal.
267
+ */
268
+ const viteHubHintsFile = ".vitehub/hints.json";
269
+ const runsKey = Symbol.for("vitehub.hints.runs");
270
+ const shared = globalThis;
271
+ const runs = shared[runsKey] ??= /* @__PURE__ */ new Map();
272
+ const startedKey = Symbol.for("vitehub.hints.started");
273
+ const startedShared = globalThis;
274
+ const started = startedShared[startedKey] ??= /* @__PURE__ */ new WeakSet();
275
+ /**
276
+ * The report of the ViteHub project root, where the other generated files go. A Nuxt app with `srcDir: "app"` has its
277
+ * Vite root in `app/`, one folder below.
278
+ */
279
+ function hintsFile(config) {
280
+ const projectRoot = Reflect.get(config, VITEHUB_PROJECT_ROOT);
281
+ return resolve(typeof projectRoot === "string" ? projectRoot : resolveViteHubProjectRoot(config.root), viteHubHintsFile);
282
+ }
283
+ function startRun(config) {
284
+ const file = hintsFile(config);
285
+ const run = {
286
+ file,
287
+ report: {
288
+ version: 1,
289
+ command: config.command,
290
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
291
+ hints: []
292
+ },
293
+ keys: /* @__PURE__ */ new Set()
294
+ };
295
+ runs.set(file, run);
296
+ return run;
297
+ }
298
+ function write(run) {
299
+ mkdirSync(dirname(run.file), { recursive: true });
300
+ writeFileSync(run.file, `${JSON.stringify(run.report, null, 2)}\n`);
301
+ }
302
+ /**
303
+ * Reports a hint from a Vite plugin hook: prints it once with its fix and docs link, and adds it to
304
+ * {@link viteHubHintsFile}. Build the diagnostic from the package's nostics catalog, so its code has a docs page.
305
+ */
306
+ function reportViteHubHint(config, diagnostic) {
307
+ const run = runs.get(hintsFile(config)) ?? startRun(config);
308
+ const hint = {
309
+ code: diagnostic.code,
310
+ why: diagnostic.why,
311
+ ...diagnostic.fix ? { fix: diagnostic.fix } : {},
312
+ ...diagnostic.docs ? { docs: diagnostic.docs } : {},
313
+ ...diagnostic.sources?.length ? { sources: diagnostic.sources } : {}
314
+ };
315
+ const key = JSON.stringify([hint.code, hint.sources ?? []]);
316
+ if (run.keys.has(key)) return;
317
+ run.keys.add(key);
318
+ run.report.hints.push(hint);
319
+ write(run);
320
+ config.logger.warn(formatDiagnostic(diagnostic));
321
+ }
322
+ /**
323
+ * Starts the hints of a build or dev server: writes an empty {@link viteHubHintsFile}, so a run without hints does not
324
+ * leave the hints of an earlier run in place. Every plugin that reports hints calls it from `configResolved`, so a
325
+ * package used without `vitehub()` starts its own run. The first call for a resolved config starts the run, and the
326
+ * calls of other plugins of the same build keep it.
327
+ */
328
+ function startViteHubHints(config) {
329
+ if (started.has(config)) return;
330
+ started.add(config);
331
+ write(startRun(config));
332
+ }
333
+ //#endregion
334
+ //#region ../internal/src/nitro-kit.ts
335
+ function cloneArray(value) {
336
+ return Array.isArray(value) ? [...value] : [];
337
+ }
338
+ function sameHandler(left, right) {
339
+ return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
340
+ }
341
+ /** Create a Nitro 3 configuration builder for generated ViteHub output. */
342
+ function createNitroServerKit(value = {}) {
343
+ const config = isRecordOrFunction(value) ? { ...value } : {};
344
+ const handlers = cloneArray(config.handlers);
345
+ const plugins = cloneArray(config.plugins);
346
+ config.handlers = handlers;
347
+ config.plugins = plugins;
348
+ return {
349
+ config,
350
+ addHandler(handler, position = "end") {
351
+ if (handlers.some((candidate) => isRecordOrFunction(candidate) && sameHandler(candidate, handler))) return;
352
+ if (position === "start") handlers.unshift({ ...handler });
353
+ else handlers.push({ ...handler });
354
+ },
355
+ addPlugin(plugin, position = "end") {
356
+ if (plugins.includes(plugin)) return;
357
+ if (position === "start") plugins.unshift(plugin);
358
+ else plugins.push(plugin);
359
+ }
360
+ };
361
+ }
362
+ //#endregion
363
+ //#region src/internal/content-types-writer.ts
364
+ const installed = /* @__PURE__ */ new WeakMap();
365
+ /** Keep writes in the Nitro host, including when its runtime runs in workerd. */
366
+ function installContentTypesWriter(host, plugin) {
367
+ if (!host.options?.dev) return Promise.resolve();
368
+ const previous = installed.get(host);
369
+ if (previous) return previous;
370
+ const installation = startWriter(host, plugin);
371
+ installed.set(host, installation);
372
+ return installation;
373
+ }
374
+ async function startWriter(host, plugin) {
375
+ const file = resolve(dirname(plugin), "../types/content.d.ts");
376
+ const path = `/${randomUUID()}`;
377
+ const server = createServer((request, response) => {
378
+ if (request.method !== "POST" || request.url !== path || request.headers.origin) {
379
+ response.writeHead(403).end();
380
+ return;
381
+ }
382
+ (async () => {
383
+ request.setEncoding("utf8");
384
+ let declarations = "";
385
+ for await (const chunk of request) {
386
+ declarations += String(chunk);
387
+ if (declarations.length > 16777216) {
388
+ response.writeHead(413).end();
389
+ return;
390
+ }
391
+ }
392
+ if (await readFile(file, "utf8").catch(() => void 0) !== declarations) {
393
+ await mkdir(dirname(file), { recursive: true });
394
+ await writeFile(file, declarations, "utf8");
395
+ }
396
+ response.writeHead(204).end();
397
+ })().catch(() => response.writeHead(500).end());
398
+ });
399
+ server.listen(0, "127.0.0.1");
400
+ await once(server, "listening");
401
+ server.unref();
402
+ let closing;
403
+ host.hooks.hook("close", () => closing ??= new Promise((resolve, reject) => {
404
+ server.close((error) => error ? reject(error) : resolve());
405
+ server.closeAllConnections();
406
+ }));
407
+ const address = server.address();
408
+ invariant(address && typeof address !== "string", "the Content types writer listens on a TCP host and port, so it has a TCP address");
409
+ host.options.runtimeConfig ??= {};
410
+ host.options.runtimeConfig.vitehubContentTypesWriter = `http://127.0.0.1:${address.port}${path}`;
411
+ }
412
+ //#endregion
413
+ //#region src/internal/content-types-plugin.injected.ts
414
+ /**
415
+ * Source of the generated Nitro plugin that writes the types of `content.get()`, `content.list()`, and
416
+ * `content.query()` in development. `importBase` and `contentModule` are JSON string literals of import paths. The
417
+ * text runs in the app server, not here, so its error stays plain.
418
+ */
419
+ function renderContentTypesPlugin(importBase, contentModule) {
420
+ return [
421
+ `import { defineContentTypesPlugin } from ${importBase}`,
422
+ "import { useRuntimeConfig } from \"nitro/runtime-config\"",
423
+ "",
424
+ "// A production build drops this branch, so the server does not load Content at startup.",
425
+ "const write = async (declarations) => {",
426
+ " const response = await fetch(useRuntimeConfig().vitehubContentTypesWriter, { method: \"POST\", body: declarations })",
427
+ " if (!response.ok) throw new Error(`Content types writer returned ${response.status}`)",
428
+ "}",
429
+ `export default import.meta.dev ? defineContentTypesPlugin(async () => (await import(${contentModule})).default, write, { moduleName: ${importBase} }) : () => {}`,
430
+ ""
431
+ ].join("\n");
432
+ }
433
+ //#endregion
274
434
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
275
435
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
276
436
  function normalizeWindowsPath(input = "") {
@@ -372,14 +532,46 @@ new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\
372
532
  new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
373
533
  //#endregion
374
534
  //#region src/internal/collection-discovery.ts
375
- /** The initializers of top-level `const`, `let`, and `var` declarations named `name`. */
535
+ /** The initializers of top-level `const`, `let`, and `var` declarations named `name`, with their declaration kind. */
376
536
  function declarationInitializers(module, name, exportedOnly) {
377
537
  return module.program.body.flatMap((statement) => {
378
538
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : exportedOnly ? void 0 : statement;
379
539
  if (declaration?.type !== "VariableDeclaration") return [];
380
- return declaration.declarations.flatMap((declarator) => declarator.id.type === "Identifier" && declarator.id.name === name && declarator.init ? [declarator.init] : []);
540
+ return declaration.declarations.flatMap((declarator) => declarator.id.type === "Identifier" && declarator.id.name === name && declarator.init ? [{
541
+ init: declarator.init,
542
+ constant: declaration.kind === "const"
543
+ }] : []);
381
544
  });
382
545
  }
546
+ const viteHubSourceSpecifier = /^(?:@vite-hub\/source|vite-hub\/source)(?:\/|$)/;
547
+ /** Checks binding targets, including nested destructuring, without treating property keys or defaults as bindings. */
548
+ function bindsCollectionFactory(binding) {
549
+ switch (binding.type) {
550
+ case "Identifier": return binding.name === "defineCollection";
551
+ case "ObjectPattern": return binding.properties.some((property) => bindsCollectionFactory(property.type === "RestElement" ? property.argument : property.value));
552
+ case "ArrayPattern": return binding.elements.some((element) => element !== null && bindsCollectionFactory(element));
553
+ case "AssignmentPattern": return bindsCollectionFactory(binding.left);
554
+ case "RestElement": return bindsCollectionFactory(binding.argument);
555
+ default: return false;
556
+ }
557
+ }
558
+ /**
559
+ * True when `defineCollection` in this module is ViteHub's factory: imported from a ViteHub Source entry, or not
560
+ * declared in the module at all (an auto-import). A local function or an import from elsewhere with that name can
561
+ * return any Collection, so its options say nothing about the route.
562
+ */
563
+ function callsViteHubFactory(module) {
564
+ for (const statement of module.program.body) {
565
+ if (statement.type === "ImportDeclaration") {
566
+ if (statement.specifiers.some((specifier) => specifier.local.name === "defineCollection")) return statement.importKind !== "type" && viteHubSourceSpecifier.test(statement.source.value);
567
+ continue;
568
+ }
569
+ const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement;
570
+ if ((declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") && declaration.id?.name === "defineCollection") return false;
571
+ if (declaration?.type === "VariableDeclaration" && declaration.declarations.some((declarator) => bindsCollectionFactory(declarator.id))) return false;
572
+ }
573
+ return true;
574
+ }
383
575
  /** The local binding that `export { local as exportName }` exports, without a module source. */
384
576
  function exportedLocalName(module, exportName) {
385
577
  for (const statement of module.program.body) {
@@ -392,11 +584,16 @@ function exportedLocalName(module, exportName) {
392
584
  * such as a conditional, has no known call: the scanner cannot know which branch runs.
393
585
  */
394
586
  function findCollectionDefinitionCall(source, exportName, file) {
395
- const module = scanModule(source, file);
587
+ const module = scanModule(source, `${file}.ts`);
396
588
  const calls = findCalls(module, ["defineCollection"]);
397
- const callIn = (initializer) => {
398
- const matches = calls.filter((call) => call.start >= initializer.start && call.end <= initializer.end);
399
- return matches.length === 1 ? matches[0] : void 0;
589
+ const factory = callsViteHubFactory(module);
590
+ const callIn = ({ init, constant }) => {
591
+ const matches = calls.filter((call) => call.start >= init.start && call.end <= init.end);
592
+ const [call] = matches;
593
+ return matches.length === 1 && call ? {
594
+ call,
595
+ exported: factory && constant && unwrapExpression(init) === call
596
+ } : void 0;
400
597
  };
401
598
  for (const initializer of declarationInitializers(module, exportName, true)) {
402
599
  const call = callIn(initializer);
@@ -409,11 +606,27 @@ function findCollectionDefinitionCall(source, exportName, file) {
409
606
  if (call) return call;
410
607
  }
411
608
  }
412
- function collectionRouteDisabled(call) {
413
- if (!call) return false;
414
- const options = argumentExpression(call.arguments[1] ?? call.arguments[0]);
415
- const route = options?.type === "ObjectExpression" ? findProperty(options, "route")?.value : void 0;
416
- return route !== void 0 && staticValue(route) === false;
609
+ /**
610
+ * True only for a literal `route: false` in the options of the exported `defineCollection()` call. A spread or a
611
+ * computed key after it can set `route` again when the module runs, so the route stays. Any other form keeps the route,
612
+ * and `defineCollectionHandler()` answers 404 at request time when the Collection has `route: false`.
613
+ */
614
+ function collectionRouteDisabled(definition) {
615
+ if (!definition?.exported) return false;
616
+ const options = argumentExpression(definition.call.arguments[1] ?? definition.call.arguments[0]);
617
+ if (options?.type !== "ObjectExpression") return false;
618
+ const properties = objectProperties(options);
619
+ const index = properties.findLastIndex((property) => property.key === "route");
620
+ const route = properties[index]?.value;
621
+ return route !== void 0 && staticValue(route) === false && properties.slice(index + 1).every((property) => property.key !== void 0);
622
+ }
623
+ /** Whether the module exports `exportName`, and whether that Collection gets a generated route. */
624
+ function inspectCollectionSource(file, source, exportName) {
625
+ const exported = exportNames(source, `${file}.ts`).includes(exportName);
626
+ return {
627
+ exported,
628
+ routeEnabled: exported && !collectionRouteDisabled(findCollectionDefinitionCall(source, exportName, file))
629
+ };
417
630
  }
418
631
  async function collectCollectionFiles(directory) {
419
632
  let entries;
@@ -442,10 +655,10 @@ async function discoverCollections(options) {
442
655
  if (!/^[A-Z_$][\w$]*$/i.test(exportName)) throw sourceErrorDiagnostics.SOURCE_B0003({ message: `[vitehub] Collection file ${JSON.stringify(relative(options.projectRoot, file))} must use a valid JavaScript identifier as its filename.` });
443
656
  const name = relative(directory, file).slice(0, -extension.length).replaceAll("\\", "/");
444
657
  const source = await readFile(file, "utf8");
445
- if (!findExportNames(source).includes(exportName)) throw sourceErrorDiagnostics.SOURCE_B0004({ message: `[vitehub] Collection file ${JSON.stringify(relative(options.projectRoot, file))} must export a Collection named ${JSON.stringify(exportName)} to match its filename.` });
658
+ if (!exportNames(source, `${file}.ts`).includes(exportName)) throw sourceErrorDiagnostics.SOURCE_B0004({ message: `[vitehub] Collection file ${JSON.stringify(relative(options.projectRoot, file))} must export a Collection named ${JSON.stringify(exportName)} to match its filename.` });
446
659
  const definition = findCollectionDefinitionCall(source, exportName, file);
447
660
  return {
448
- definition,
661
+ definition: definition?.call,
449
662
  exportName,
450
663
  file,
451
664
  name,
@@ -674,6 +887,7 @@ function definitionFields(collection) {
674
887
  value: dynamic
675
888
  }];
676
889
  const authorize = readMember(options, "authorize");
890
+ const access = readMember(options, "access");
677
891
  fields.push({
678
892
  label: "Transform",
679
893
  value: readMember(options, "transform") ? "Yes" : "No"
@@ -682,6 +896,10 @@ function definitionFields(collection) {
682
896
  label: "Authorize",
683
897
  value: !authorize.method && staticValue(authorize.value) === true ? "Signed-in session" : isFunction(authorize) ? "Callback" : dynamic
684
898
  });
899
+ if (access) fields.push({
900
+ label: "Access",
901
+ value: staticValue(access.value) === "public" ? "Public" : dynamic
902
+ });
685
903
  return fields;
686
904
  }
687
905
  function summarizeCollection(projectRoot, collection) {
@@ -713,7 +931,7 @@ async function inspectCollectionDefinitions(options) {
713
931
  const BUNDLED_GLOB_ID = "\0vitehub-source-glob:";
714
932
  /** Matches those ids, for Rolldown's hook filters. */
715
933
  const BUNDLED_GLOB_ID_PATTERN = /^\0vitehub-source-glob:/;
716
- const GLOB_MODULE = /^(?:@vite-hub|vite-hub)\/source\/glob$/;
934
+ const GLOB_MODULE = /^(?:@vite-hub|vite-hub)\/source$/;
717
935
  const OPTION_KEYS = /* @__PURE__ */ new Set([
718
936
  "cwd",
719
937
  "dot",
@@ -766,7 +984,7 @@ function findGlobCalls(program) {
766
984
  if (typeof source !== "string" || !GLOB_MODULE.test(source)) continue;
767
985
  for (const specifier of statement.specifiers) {
768
986
  const name = specifier.imported?.name ?? specifier.imported?.value;
769
- if (specifier.type === "ImportSpecifier" && name === "glob") imported.set(specifier.local.name, source.replace(/\/glob$/, "/files"));
987
+ if (specifier.type === "ImportSpecifier" && name === "glob") imported.set(specifier.local.name, source);
770
988
  }
771
989
  }
772
990
  if (imported.size === 0) return [];
@@ -820,23 +1038,36 @@ async function collectBundledGlob(input, rootDir) {
820
1038
  watched
821
1039
  };
822
1040
  }
823
- const utf8 = new TextDecoder("utf-8", { fatal: true });
824
- /** One file in the generated module: text stays readable, anything else is base64. Both load as bytes, as glob() reads them. */
825
- function fileExpression(bytes) {
826
- try {
827
- const text = utf8.decode(bytes);
828
- if (!text.includes("\0")) return `text(${JSON.stringify(text)})`;
829
- } catch {}
830
- return `bytes(${JSON.stringify(Buffer.from(bytes).toString("base64"))})`;
831
- }
832
- /** The generated module: the matched files, served through files(). */
1041
+ /**
1042
+ * The generated module: the matched files, served through files(). Their bytes are one gzip blob in base64, and each
1043
+ * key reads its range of the blob, which the server inflates on the first read. A host compiles a short string
1044
+ * instead of every file as JavaScript when the server starts. Cloudflare Workers compile every module of the bundle
1045
+ * when an isolate starts (https://github.com/cloudflare/workerd/issues/8442).
1046
+ */
833
1047
  function renderBundledGlob(filesModule, entries, prefix) {
834
- const lines = Object.entries(entries).map(([key, bytes]) => ` ${JSON.stringify(key)}: ${fileExpression(bytes)},`);
1048
+ const lines = [];
1049
+ let offset = 0;
1050
+ for (const [key, bytes] of Object.entries(entries)) {
1051
+ lines.push(` ${JSON.stringify(key)}: file(${offset}, ${offset + bytes.length}),`);
1052
+ offset += bytes.length;
1053
+ }
1054
+ const packed = gzipSync(Buffer.concat(Object.values(entries)), { level: 9 }).toString("base64");
835
1055
  return [
836
1056
  `import { files } from ${JSON.stringify(filesModule)}`,
837
- `const encoder = new TextEncoder()`,
838
- `const text = value => encoder.encode(value)`,
839
- `const bytes = value => Uint8Array.from(atob(value), character => character.charCodeAt(0))`,
1057
+ `let unpacked`,
1058
+ `async function unpack(base64) {`,
1059
+ ` const zlib = globalThis.process?.getBuiltinModule?.("node:zlib")`,
1060
+ ` const buffer = globalThis.process?.getBuiltinModule?.("node:buffer")`,
1061
+ ` if (zlib && buffer) {`,
1062
+ ` const bytes = zlib.gunzipSync(buffer.Buffer.from(base64, "base64"))`,
1063
+ ` return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)`,
1064
+ ` }`,
1065
+ ` const binary = atob(base64)`,
1066
+ ` const gzip = new Uint8Array(binary.length)`,
1067
+ ` for (let index = 0; index < binary.length; index++) gzip[index] = binary.charCodeAt(index)`,
1068
+ ` return new Uint8Array(await new Response(new Response(gzip).body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer())`,
1069
+ `}`,
1070
+ `const file = (start, end) => async () => (await (unpacked ??= unpack(${JSON.stringify(packed)}))).slice(start, end)`,
840
1071
  `export default files({`,
841
1072
  ...lines,
842
1073
  `}${prefix ? `, { prefix: ${JSON.stringify(prefix)} }` : ""})`,
@@ -855,12 +1086,21 @@ async function loadBundledGlob(id, rootDir) {
855
1086
  //#endregion
856
1087
  //#region src/vite.ts
857
1088
  const collectionTypesEntry = ".vitehub/types/source/collections.d.ts";
858
- const collectionTypesPackageEntry = ".vitehub/types/source/vitehub-source-registry.d.ts";
1089
+ const retiredCollectionTypesWrapper = ".vitehub/types/source/vitehub-source-registry.d.ts";
859
1090
  const collectionRoutesDirectory = ".vitehub/source/routes";
860
1091
  const contentRouteEntry = ".vitehub/content/route.mjs";
861
1092
  const contentPreviewEntry = ".vitehub/content/preview.mjs";
862
1093
  const contentSitemapEntry = ".vitehub/content/sitemap.mjs";
863
1094
  const contentRobotsEntry = ".vitehub/content/robots.mjs";
1095
+ const contentMarkdownEntry = ".vitehub/content/markdown.mjs";
1096
+ const contentRssEntry = ".vitehub/content/rss.mjs";
1097
+ const contentMcpEntry = ".vitehub/content/mcp.mjs";
1098
+ const contentLlmsEntry = ".vitehub/content/llms.mjs";
1099
+ const contentSqliteEntry = ".vitehub/content/sqlite.mjs";
1100
+ const contentGitHubWebhookEntry = ".vitehub/content/github-webhook.mjs";
1101
+ const contentPreviewRoutesEntry = ".vitehub/content/preview-routes.mjs";
1102
+ const contentTypesPluginEntry = ".vitehub/content/types.mjs";
1103
+ const contentTypesEntry = ".vitehub/types/content.d.ts";
864
1104
  const authServerModuleId = "#vitehub/auth/server";
865
1105
  const initialHostRefreshRetryDelay = 25;
866
1106
  const maximumHostRefreshRetryDelay = 1e3;
@@ -876,11 +1116,16 @@ async function snapshotGeneratedSourceArtifacts(projectRoot) {
876
1116
  const files = /* @__PURE__ */ new Map();
877
1117
  const fixedEntries = [
878
1118
  collectionTypesEntry,
879
- collectionTypesPackageEntry,
880
1119
  contentRouteEntry,
881
1120
  contentPreviewEntry,
882
1121
  contentSitemapEntry,
883
- contentRobotsEntry
1122
+ contentRobotsEntry,
1123
+ contentMarkdownEntry,
1124
+ contentRssEntry,
1125
+ contentLlmsEntry,
1126
+ contentSqliteEntry,
1127
+ contentTypesPluginEntry,
1128
+ contentTypesEntry
884
1129
  ];
885
1130
  for (const entry of fixedEntries) {
886
1131
  const path = resolve(projectRoot, entry);
@@ -906,11 +1151,16 @@ async function restoreGeneratedSourceArtifacts(projectRoot, snapshot) {
906
1151
  });
907
1152
  for (const entry of [
908
1153
  collectionTypesEntry,
909
- collectionTypesPackageEntry,
910
1154
  contentRouteEntry,
911
1155
  contentPreviewEntry,
912
1156
  contentSitemapEntry,
913
- contentRobotsEntry
1157
+ contentRobotsEntry,
1158
+ contentMarkdownEntry,
1159
+ contentRssEntry,
1160
+ contentLlmsEntry,
1161
+ contentSqliteEntry,
1162
+ contentTypesPluginEntry,
1163
+ contentTypesEntry
914
1164
  ]) {
915
1165
  const path = resolve(projectRoot, entry);
916
1166
  if (!snapshot.files.has(path)) await rm(path, { force: true });
@@ -924,22 +1174,24 @@ function methodsOverlap(left, right) {
924
1174
  return !left || !right || left.toLowerCase() === right.toLowerCase();
925
1175
  }
926
1176
  function generatedRouteOwner(handler) {
927
- return handler.route === "/api/content/**" || handler.route === "/sitemap.xml" || handler.route === "/robots.txt" ? "Content" : "Collection";
1177
+ return handler.middleware || handler.route === "/api/content/**" || handler.route === "/_vitehub/content/github" || handler.route === "/sitemap.xml" || handler.route === "/robots.txt" || handler.route === "/rss.xml" || handler.route === "/mcp" ? "Content" : "Collection";
928
1178
  }
929
1179
  function generatedRouteDescription(handler) {
930
1180
  return handler.method ? `${handler.method.toUpperCase()} handler` : "handler";
931
1181
  }
932
1182
  function assertGeneratedRoutes(nitro, generatedHandlers) {
933
1183
  for (const generatedHandler of generatedHandlers) {
934
- if (generatedHandler.plugin) continue;
1184
+ if (generatedHandler.plugin || generatedHandler.middleware) continue;
935
1185
  if (nitro.scannedHandlers.some((candidate) => !candidate.middleware && candidate.route === generatedHandler.route && methodsOverlap(candidate.method, generatedHandler.method))) throw sourceErrorDiagnostics.SOURCE_B0001({ message: `[vitehub] Generated ${generatedRouteOwner(generatedHandler)} route ${JSON.stringify(generatedHandler.route)} conflicts with an existing ${generatedRouteDescription(generatedHandler)}. Remove the matching server route.` });
936
1186
  }
937
1187
  }
938
1188
  function generatedRouteGuard(generatedHandlers) {
939
1189
  return {
940
1190
  name: "vite-hub/generated-route-guard",
941
- setup(nitro) {
1191
+ async setup(nitro) {
942
1192
  nitro.hooks.hook("build:before", () => assertGeneratedRoutes(nitro, generatedHandlers));
1193
+ const typesPlugin = generatedHandlers.find((handler) => handler.plugin && handler.handler.replaceAll("\\", "/").endsWith(`/${contentTypesPluginEntry}`));
1194
+ if (typesPlugin) await installContentTypesWriter(nitro, typesPlugin.handler);
943
1195
  }
944
1196
  };
945
1197
  }
@@ -951,14 +1203,22 @@ function mergeGeneratedSourceNitroConfig(value, generatedHandlers) {
951
1203
  const handlers = kit.config.handlers;
952
1204
  for (const handler of generatedHandlers) {
953
1205
  if (handler.plugin) {
954
- kit.addPlugin(handler.handler);
1206
+ kit.addPlugin(handler.handler, handler.position);
955
1207
  continue;
956
1208
  }
957
1209
  if (handlers.some((candidate) => candidate.handler === handler.handler && candidate.route === handler.route && candidate.method?.toLowerCase() === handler.method?.toLowerCase())) continue;
958
- if (handlers.some((candidate) => !candidate.middleware && candidate.route === handler.route && methodsOverlap(candidate.method, handler.method))) throw sourceErrorDiagnostics.SOURCE_B0002({ message: `[vitehub] Generated ${generatedRouteOwner(handler)} route ${JSON.stringify(handler.route)} conflicts with an existing ${generatedRouteDescription(handler)}. Remove the matching server route.` });
1210
+ const duplicate = handler.middleware ? void 0 : handlers.find((candidate) => !candidate.middleware && candidate.route === handler.route && methodsOverlap(candidate.method, handler.method));
1211
+ if (duplicate && handler.route === "/mcp") {
1212
+ const other = duplicate.handler.replaceAll("\\", "/").includes("/.vitehub/nitro/mcp/") ? "the app MCP server of vitehub({ mcp })" : `the handler ${duplicate.handler}`;
1213
+ throw sourceErrorDiagnostics.SOURCE_B0010({
1214
+ route: handler.route,
1215
+ other
1216
+ });
1217
+ }
1218
+ if (duplicate) throw sourceErrorDiagnostics.SOURCE_B0002({ message: `[vitehub] Generated ${generatedRouteOwner(handler)} route ${JSON.stringify(handler.route)} conflicts with an existing ${generatedRouteDescription(handler)}. Remove the matching server route.` });
959
1219
  kit.addHandler({
960
1220
  ...handler,
961
- lazy: true
1221
+ lazy: handler.lazy ?? true
962
1222
  });
963
1223
  }
964
1224
  const modules = Array.isArray(nitro.modules) ? [...nitro.modules] : [];
@@ -972,568 +1232,9 @@ function toRuntimeModuleSpecifier(file) {
972
1232
  function toTypeModuleSpecifier(file) {
973
1233
  return file.replaceAll("\\", "/");
974
1234
  }
975
- /** Inspect route metadata without importing Collection modules or evaluating loaders. */
976
- function collectionRouteEnabled(file, source, exportName) {
977
- const parsed = parseSync(file, source, { lang: "ts" });
978
- if (parsed.errors.length) throw new TypeError(`[vitehub] Cannot parse Collection ${file}: ${parsed.errors[0].message}`);
979
- const moduleScope = { bindings: /* @__PURE__ */ new Map() };
980
- const scopes = /* @__PURE__ */ new WeakMap();
981
- const bindPattern = (node, scope, init) => {
982
- if (!node) return;
983
- if (node.type === "Identifier" && node.name) scope.bindings.set(node.name, { init });
984
- else if (node.type === "RestElement") bindPattern(node.argument, scope);
985
- else if (node.type === "AssignmentPattern") bindPattern(node.left, scope, {
986
- type: "AssignmentPattern",
987
- left: init ?? void 0,
988
- right: node.right
989
- });
990
- else if (node.type === "ArrayPattern") for (const element of node.elements ?? []) bindPattern(element, scope);
991
- else if (node.type === "ObjectPattern") for (const property of node.properties ?? []) {
992
- const member = {
993
- type: "MemberExpression",
994
- object: init ?? void 0,
995
- property: property.key,
996
- computed: property.computed
997
- };
998
- scopes.set(member, scope);
999
- bindPattern(property.type === "RestElement" ? property.argument : property.value, scope, property.type === "RestElement" ? void 0 : member);
1000
- }
1001
- };
1002
- const indexScopes = (node, parent, functionScope) => {
1003
- const isFunction = [
1004
- "ArrowFunctionExpression",
1005
- "FunctionExpression",
1006
- "FunctionDeclaration"
1007
- ].includes(node.type ?? "");
1008
- if ((node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") && node.id?.name) parent.bindings.set(node.id.name, { init: node.type === "FunctionDeclaration" ? node : void 0 });
1009
- const scope = isFunction || [
1010
- "BlockStatement",
1011
- "CatchClause",
1012
- "ForStatement",
1013
- "ForInStatement",
1014
- "ForOfStatement",
1015
- "SwitchStatement"
1016
- ].includes(node.type ?? "") ? {
1017
- bindings: /* @__PURE__ */ new Map(),
1018
- parent
1019
- } : parent;
1020
- const nextFunctionScope = isFunction ? scope : functionScope;
1021
- scopes.set(node, scope);
1022
- if (isFunction) {
1023
- for (const param of node.params ?? []) bindPattern(param, scope);
1024
- if (node.type === "FunctionExpression") bindPattern(node.id, scope);
1025
- }
1026
- if (node.type === "CatchClause") bindPattern(node.param, scope);
1027
- if (node.type === "VariableDeclaration") for (const item of node.declarations ?? []) {
1028
- const target = node.kind === "var" ? functionScope : scope;
1029
- bindPattern(item.id, target, item.init);
1030
- }
1031
- for (const child of Object.values(node)) if (Array.isArray(child)) {
1032
- for (const item of child) if (item) indexScopes(item, scope, nextFunctionScope);
1033
- } else if (child && typeof child === "object") indexScopes(child, scope, nextFunctionScope);
1034
- };
1035
- indexScopes(parsed.program, moduleScope, moduleScope);
1036
- const bindingFor = (node) => {
1037
- for (let scope = scopes.get(node); scope; scope = scope.parent) if (node.name && scope.bindings.has(node.name)) return scope.bindings.get(node.name);
1038
- };
1039
- const indexedWrites = [];
1040
- const indexWrites = (node, fn, guards = []) => {
1041
- if ([
1042
- "ArrowFunctionExpression",
1043
- "FunctionExpression",
1044
- "FunctionDeclaration"
1045
- ].includes(node.type ?? "")) {
1046
- fn = node;
1047
- guards = [];
1048
- }
1049
- if (node.type === "IfStatement" || node.type === "ConditionalExpression") {
1050
- if (node.consequent) indexWrites(node.consequent, fn, [...guards, {
1051
- test: node.test,
1052
- truthy: true
1053
- }]);
1054
- if (node.alternate) indexWrites(node.alternate, fn, [...guards, {
1055
- test: node.test,
1056
- truthy: false
1057
- }]);
1058
- return;
1059
- }
1060
- if (node.type === "LogicalExpression") {
1061
- if (node.left) indexWrites(node.left, fn, guards);
1062
- if (node.right) indexWrites(node.right, fn, [...guards, {
1063
- test: node.operator === "??" ? void 0 : node.left,
1064
- truthy: node.operator === "&&"
1065
- }]);
1066
- return;
1067
- }
1068
- if ([
1069
- "ForStatement",
1070
- "ForInStatement",
1071
- "ForOfStatement",
1072
- "WhileStatement",
1073
- "DoWhileStatement",
1074
- "SwitchStatement",
1075
- "TryStatement"
1076
- ].includes(node.type ?? "")) guards = [...guards, {
1077
- test: void 0,
1078
- truthy: true
1079
- }];
1080
- if (node.type === "UnaryExpression" && node.operator === "delete" && node.argument?.type === "MemberExpression") {
1081
- const target = node.argument.object;
1082
- const binding = target?.type === "Identifier" ? bindingFor(target) : void 0;
1083
- if (binding) {
1084
- const write = {
1085
- node,
1086
- fn,
1087
- guards
1088
- };
1089
- (binding.writes ??= []).push(write);
1090
- indexedWrites.push(write);
1091
- }
1092
- }
1093
- if (node.type === "AssignmentExpression") {
1094
- const target = node.left?.type === "MemberExpression" ? node.left.object : node.left;
1095
- const binding = target?.type === "Identifier" ? bindingFor(target) : void 0;
1096
- if (binding) {
1097
- const write = {
1098
- node,
1099
- fn,
1100
- guards
1101
- };
1102
- (binding.writes ??= []).push(write);
1103
- indexedWrites.push(write);
1104
- }
1105
- }
1106
- for (const child of Object.values(node)) if (Array.isArray(child)) {
1107
- for (const item of child) if (item) {
1108
- indexWrites(item, fn, guards);
1109
- if (item.type === "ReturnStatement" || item.type === "ThrowStatement") break;
1110
- }
1111
- } else if (child && typeof child === "object") indexWrites(child, fn, guards);
1112
- };
1113
- indexWrites(parsed.program);
1114
- let readPosition = Infinity;
1115
- const activeFunctions = /* @__PURE__ */ new Set();
1116
- const executedFunctions = /* @__PURE__ */ new Set();
1117
- const parameterValues = /* @__PURE__ */ new Map();
1118
- let routeEffectState;
1119
- const snapshotExecution = () => ({
1120
- activeFunctions: new Set(activeFunctions),
1121
- executedFunctions: new Set(executedFunctions),
1122
- parameterValues: new Map(parameterValues),
1123
- readPosition,
1124
- routeEffectState
1125
- });
1126
- const restoreExecution = (snapshot) => {
1127
- activeFunctions.clear();
1128
- for (const fn of snapshot.activeFunctions) activeFunctions.add(fn);
1129
- executedFunctions.clear();
1130
- for (const fn of snapshot.executedFunctions) executedFunctions.add(fn);
1131
- parameterValues.clear();
1132
- for (const [binding, value] of snapshot.parameterValues) parameterValues.set(binding, value);
1133
- readPosition = snapshot.readPosition;
1134
- routeEffectState = snapshot.routeEffectState;
1135
- };
1136
- let exported = moduleScope.bindings.get(exportName);
1137
- for (const statement of parsed.program.body) {
1138
- if (statement.type !== "ImportDeclaration") continue;
1139
- for (const specifier of statement.specifiers ?? []) {
1140
- const imported = specifier.type === "ImportSpecifier" ? specifier.imported : void 0;
1141
- const name = imported?.type === "Identifier" ? imported.name : imported?.value;
1142
- moduleScope.bindings.set(specifier.local.name, { init: { type: name === "defineCollection" ? "CollectionFactory" : specifier.type === "ImportNamespaceSpecifier" ? "CollectionNamespace" : "UnknownImport" } });
1143
- }
1144
- }
1145
- for (const statement of parsed.program.body) if (statement.type === "ExportNamedDeclaration") {
1146
- for (const specifier of statement.specifiers) if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === exportName && specifier.local.type === "Identifier") exported = moduleScope.bindings.get(specifier.local.name);
1147
- }
1148
- const unwrap = (node, seen = /* @__PURE__ */ new Set()) => {
1149
- if (node?.type === "AssignmentPattern") {
1150
- const value = unwrap(node.left, new Set(seen));
1151
- return !node.left || value?.type === "Literal" && value.value === void 0 ? unwrap(node.right, seen) : value;
1152
- }
1153
- if (node?.type === "Identifier" && node.name !== void 0) {
1154
- const declaration = bindingFor(node);
1155
- if (!declaration) return node.name === "undefined" ? {
1156
- type: "Literal",
1157
- value: void 0
1158
- } : void 0;
1159
- let init = parameterValues.has(declaration) ? parameterValues.get(declaration) : declaration.init;
1160
- for (const write of declaration.writes ?? []) {
1161
- const state = writeState(write);
1162
- if (write.node.left?.type === "Identifier" && state !== "skip") init = state === "known" && write.node.operator === "=" ? write.node.right : void 0;
1163
- }
1164
- if (!init) return void 0;
1165
- if (seen.has(declaration)) throw new TypeError(`[vitehub] Circular Collection options in ${file}.`);
1166
- seen.add(declaration);
1167
- return unwrap(init, seen);
1168
- }
1169
- if (node?.type === "UnaryExpression" && node.operator === "!") {
1170
- const value = unwrap(node.argument, new Set(seen));
1171
- return value?.type === "Literal" ? {
1172
- type: "Literal",
1173
- value: !Boolean(value.value)
1174
- } : node;
1175
- }
1176
- if (node?.type === "UnaryExpression" && node.operator === "void") return {
1177
- type: "Literal",
1178
- value: void 0
1179
- };
1180
- if (node && [
1181
- "TSAsExpression",
1182
- "TSSatisfiesExpression",
1183
- "TSNonNullExpression",
1184
- "ParenthesizedExpression"
1185
- ].includes(node.type ?? "")) return unwrap(node.expression, seen);
1186
- if (node?.type === "MemberExpression") {
1187
- const object = unwrap(node.object, seen);
1188
- const key = node.computed ? staticString(node.property) : node.property?.name;
1189
- if (object?.type !== "ObjectExpression" || key === void 0) return void 0;
1190
- let result = {
1191
- type: "Literal",
1192
- value: void 0
1193
- };
1194
- for (const property of object.properties ?? []) {
1195
- if (property.type === "SpreadElement") return void 0;
1196
- if ((property.computed ? staticString(property.key) : property.key?.name ?? property.key?.value) === key) result = unwrap(property.value, new Set(seen));
1197
- }
1198
- return result;
1199
- }
1200
- return node ?? void 0;
1201
- };
1202
- const writeState = (write) => {
1203
- if ((write.node.start ?? Infinity) >= readPosition) return "skip";
1204
- const previousPosition = readPosition;
1205
- let state = "known";
1206
- for (const guard of write.guards) {
1207
- if (!write.fn && !write.replayed) readPosition = guard.test?.start ?? write.node.start ?? readPosition;
1208
- const test = unwrap(guard.test);
1209
- if (test?.type !== "Literal") state = "unknown";
1210
- else if (Boolean(test.value) !== guard.truthy) {
1211
- readPosition = previousPosition;
1212
- return "skip";
1213
- }
1214
- }
1215
- if (write.fn && !activeFunctions.has(write.fn)) {
1216
- if (!executedFunctions.has(write.fn)) {
1217
- readPosition = previousPosition;
1218
- return "skip";
1219
- }
1220
- const right = unwrap(write.node.right);
1221
- readPosition = previousPosition;
1222
- if (right?.type === "Literal" && (right.value === void 0 || right.value === true || right.value === false)) return "known";
1223
- return "unknown";
1224
- }
1225
- readPosition = previousPosition;
1226
- return state;
1227
- };
1228
- const staticString = (node, seen = /* @__PURE__ */ new Set()) => {
1229
- const value = unwrap(node, seen);
1230
- if (!value) return void 0;
1231
- if (value.type === "Literal" && String(value.value) === value.value) return value.value;
1232
- if (value.type === "TemplateLiteral") {
1233
- const quasis = value.quasis ?? [];
1234
- const expressions = value.expressions ?? [];
1235
- if (quasis.length !== expressions.length + 1) return void 0;
1236
- let result = "";
1237
- for (let index = 0; index < quasis.length; index++) {
1238
- result += quasis[index]?.value?.cooked ?? quasis[index]?.value?.raw ?? "";
1239
- if (index < expressions.length) {
1240
- const expression = staticString(expressions[index], new Set(seen));
1241
- if (expression === void 0) return void 0;
1242
- result += expression;
1243
- }
1244
- }
1245
- return result;
1246
- }
1247
- if (value.type === "BinaryExpression" && value.operator === "+") {
1248
- const left = staticString(value.left, new Set(seen));
1249
- const right = staticString(value.right, new Set(seen));
1250
- return left !== void 0 && right !== void 0 ? left + right : void 0;
1251
- }
1252
- };
1253
- const routeValue = (value) => {
1254
- if (value?.type === "Literal" && (value.value === true || value.value === false)) return {
1255
- present: true,
1256
- value: value.value
1257
- };
1258
- if (value?.type === "Literal" && value.value === void 0) return {
1259
- present: true,
1260
- value: true
1261
- };
1262
- return {
1263
- present: true,
1264
- value: value?.type === "Literal" ? true : false
1265
- };
1266
- };
1267
- const staticObjectRoute = (node, seen = /* @__PURE__ */ new Set()) => {
1268
- if (node?.type === "CallExpression" && node.callee?.type === "MemberExpression" && !node.callee.computed && node.callee.object?.type === "Identifier" && node.callee.object.name === "Object" && node.callee.property?.name === "assign") {
1269
- let merged = { present: false };
1270
- for (const argument of node.arguments ?? []) {
1271
- const current = staticObjectRoute(argument, new Set(seen));
1272
- if (current?.present) merged = current;
1273
- else if (current === void 0) merged = {
1274
- present: true,
1275
- value: false
1276
- };
1277
- }
1278
- return merged;
1279
- }
1280
- const object = unwrap(node, seen);
1281
- if (object?.type !== "ObjectExpression") return void 0;
1282
- let route = { present: false };
1283
- for (const property of object.properties ?? []) {
1284
- if (property.type === "SpreadElement") {
1285
- const spreadRoute = staticObjectRoute(property.argument, new Set(seen));
1286
- if (spreadRoute?.present) route = spreadRoute;
1287
- else if (spreadRoute === void 0) route = {
1288
- present: true,
1289
- value: false
1290
- };
1291
- continue;
1292
- }
1293
- if ((property.computed ? staticString(property.key) : property.key?.name ?? property.key?.value) !== "route") continue;
1294
- const value = unwrap(property.value);
1295
- route = routeValue(value);
1296
- }
1297
- if (node?.type === "Identifier") for (const write of bindingFor(node)?.writes ?? []) {
1298
- const state = writeState(write);
1299
- if (write.node.left?.type !== "MemberExpression" || state === "skip") continue;
1300
- if ((write.node.left.computed ? staticString(write.node.left.property) : write.node.left.property?.name) === "route") {
1301
- if (write.node.type === "UnaryExpression") route = {
1302
- present: true,
1303
- value: true
1304
- };
1305
- else route = routeValue(state === "known" && write.node.operator === "=" ? unwrap(write.node.right) : void 0);
1306
- }
1307
- }
1308
- if (node?.type === "Identifier") {
1309
- const init = bindingFor(node)?.init;
1310
- if (init?.type === "Identifier") for (const write of bindingFor(init)?.writes ?? []) {
1311
- const state = writeState(write);
1312
- if (write.node.left?.type !== "MemberExpression" || state === "skip") continue;
1313
- if ((write.node.left.computed ? staticString(write.node.left.property) : write.node.left.property?.name) === "route") route = write.node.type === "UnaryExpression" ? {
1314
- present: true,
1315
- value: true
1316
- } : routeValue(state === "known" ? unwrap(write.node.right) : void 0);
1317
- }
1318
- }
1319
- if (node?.type === "Identifier") {
1320
- const alias = unwrap(node);
1321
- if (alias && alias !== node && alias.type === "Identifier") for (const write of bindingFor(alias)?.writes ?? []) {
1322
- const state = writeState(write);
1323
- if (write.node.left?.type === "MemberExpression" && state !== "skip") {
1324
- if ((write.node.left.computed ? staticString(write.node.left.property) : write.node.left.property?.name) === "route") route = write.node.type === "UnaryExpression" ? {
1325
- present: true,
1326
- value: true
1327
- } : routeValue(state === "known" ? unwrap(write.node.right) : void 0);
1328
- }
1329
- }
1330
- }
1331
- if (route.present) routeEffectState = route.value !== false;
1332
- return route;
1333
- };
1334
- const routeWritesFor = (functions) => {
1335
- const writes = [];
1336
- for (const write of indexedWrites) if (write.fn && functions.has(write.fn)) {
1337
- const left = write.node.left;
1338
- if ((left?.type === "MemberExpression" ? left.computed ? staticString(left.property) : left.property?.name : void 0) === "route") writes.push(write);
1339
- }
1340
- return writes;
1341
- };
1342
- const branchRouteEffect = (functions) => {
1343
- const values = routeWritesFor(functions).map((write) => write.node.type === "UnaryExpression" ? true : unwrap(write.node.right)).map((value) => value === true ? true : value?.type === "Literal" ? value.value : void 0);
1344
- if (values.some((value) => value === false)) return false;
1345
- if (values.some((value) => value === true || value === void 0)) return true;
1346
- };
1347
- const findRoute = (node, active = /* @__PURE__ */ new Set()) => {
1348
- const value = unwrap(node);
1349
- if (!value || active.has(value)) return void 0;
1350
- const next = new Set(active).add(value);
1351
- if (value.type === "ConditionalExpression") {
1352
- const test = unwrap(value.test);
1353
- if (test?.type === "Literal") return findRoute(test.value ? value.consequent : value.alternate, next);
1354
- const branchSnapshot = snapshotExecution();
1355
- routeEffectState = void 0;
1356
- const consequent = findRoute(value.consequent, new Set(next));
1357
- const consequentState = snapshotExecution();
1358
- const consequentEffect = consequentState.routeEffectState;
1359
- restoreExecution(branchSnapshot);
1360
- routeEffectState = void 0;
1361
- const alternate = findRoute(value.alternate, new Set(next));
1362
- const alternateState = snapshotExecution();
1363
- const alternateEffect = alternateState.routeEffectState;
1364
- restoreExecution(branchSnapshot);
1365
- for (const fn of consequentState.executedFunctions) if (alternateState.executedFunctions.has(fn)) executedFunctions.add(fn);
1366
- const consequentBranchEffect = consequentEffect ?? branchRouteEffect(consequentState.executedFunctions);
1367
- const alternateBranchEffect = alternateEffect ?? branchRouteEffect(alternateState.executedFunctions);
1368
- if (consequentBranchEffect === false && alternateBranchEffect === false) {
1369
- for (const fn of [...consequentState.executedFunctions, ...alternateState.executedFunctions]) if (routeWritesFor(/* @__PURE__ */ new Set([fn])).length > 0) executedFunctions.add(fn);
1370
- routeEffectState = false;
1371
- return false;
1372
- }
1373
- if (consequent !== void 0 && consequent === alternate) return consequent;
1374
- if (consequentEffect !== void 0 && consequentEffect === alternateEffect) {
1375
- routeEffectState = consequentEffect;
1376
- return consequentEffect;
1377
- }
1378
- return;
1379
- }
1380
- if (value.type === "IfStatement") {
1381
- const test = unwrap(value.test);
1382
- if (test?.type === "Literal") return findRoute(test.value ? value.consequent : value.alternate, next);
1383
- const branchSnapshot = snapshotExecution();
1384
- routeEffectState = void 0;
1385
- const consequent = findRoute(value.consequent, new Set(next));
1386
- const consequentState = snapshotExecution();
1387
- const consequentEffect = consequentState.routeEffectState ?? branchRouteEffect(consequentState.executedFunctions);
1388
- restoreExecution(branchSnapshot);
1389
- routeEffectState = void 0;
1390
- const alternate = value.alternate ? findRoute(value.alternate, new Set(next)) : void 0;
1391
- const alternateState = snapshotExecution();
1392
- const alternateEffect = alternateState.routeEffectState ?? branchRouteEffect(alternateState.executedFunctions);
1393
- restoreExecution(branchSnapshot);
1394
- if (consequentEffect === false && alternateEffect === false) {
1395
- for (const fn of [...consequentState.executedFunctions, ...alternateState.executedFunctions]) if (routeWritesFor(/* @__PURE__ */ new Set([fn])).length > 0) executedFunctions.add(fn);
1396
- routeEffectState = false;
1397
- } else if (consequentEffect !== void 0 && consequentEffect === alternateEffect) routeEffectState = consequentEffect;
1398
- return consequent !== void 0 && alternate !== void 0 && consequent === alternate ? consequent : consequentEffect !== void 0 && consequentEffect === alternateEffect ? consequentEffect : void 0;
1399
- }
1400
- if (value.type === "ExpressionStatement") return findRoute(value.expression, next);
1401
- if (value.type === "VariableDeclaration") {
1402
- let result;
1403
- for (const declaration of value.declarations ?? []) {
1404
- if (!declaration.init) continue;
1405
- const candidate = findRoute(declaration.init, next);
1406
- if (candidate !== void 0) result = candidate;
1407
- }
1408
- return result;
1409
- }
1410
- if (value.type === "ObjectExpression") return staticObjectRoute(value)?.value !== false;
1411
- if (value.type === "CallExpression") {
1412
- const args = value.arguments ?? [];
1413
- const callee = value.callee ?? value.expression;
1414
- const isCollectionCall = unwrap(callee)?.type === "CollectionFactory" || callee?.type === "Identifier" && callee.name === "defineCollection" && !bindingFor(callee);
1415
- const isNamespaceCollectionCall = callee?.type === "MemberExpression" && unwrap(callee.object)?.type === "CollectionNamespace" && (callee.computed ? staticString(callee.property) : callee.property?.name) === "defineCollection";
1416
- if (isCollectionCall || isNamespaceCollectionCall) {
1417
- const previousPosition = readPosition;
1418
- readPosition = value.start ?? readPosition;
1419
- const route = staticObjectRoute(args.length > 1 ? args[1] : args[0]);
1420
- readPosition = previousPosition;
1421
- return route?.value !== false;
1422
- }
1423
- if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.object.name === "Object" && [
1424
- "freeze",
1425
- "seal",
1426
- "preventExtensions"
1427
- ].includes(callee.property?.name ?? "")) return findRoute(args[0], next);
1428
- const fn = unwrap(callee);
1429
- if (!fn || ![
1430
- "ArrowFunctionExpression",
1431
- "FunctionExpression",
1432
- "FunctionDeclaration"
1433
- ].includes(fn.type ?? "")) return void 0;
1434
- const previousPosition = readPosition;
1435
- readPosition = value.start ?? readPosition;
1436
- const previousValues = new Map(parameterValues);
1437
- for (const [index, param] of (fn.params ?? []).entries()) {
1438
- const binding = bindingFor(param.type === "AssignmentPattern" ? param.left : param);
1439
- if (!binding) continue;
1440
- const argument = args[index];
1441
- const value = unwrap(argument);
1442
- if (argument && !(value?.type === "Literal" && value.value === void 0 && param.type === "AssignmentPattern")) parameterValues.set(binding, argument);
1443
- else if (param.type === "AssignmentPattern") parameterValues.delete(binding);
1444
- else parameterValues.set(binding, {
1445
- type: "Literal",
1446
- value: void 0
1447
- });
1448
- }
1449
- activeFunctions.add(fn);
1450
- executedFunctions.add(fn);
1451
- const result = findRoute(Array.isArray(fn.body) ? void 0 : fn.body, next);
1452
- for (const [index, param] of (fn.params ?? []).entries()) {
1453
- const parameter = bindingFor(param.type === "AssignmentPattern" ? param.left : param);
1454
- const argument = args[index];
1455
- const target = argument?.type === "Identifier" ? bindingFor(argument) : void 0;
1456
- if (!parameter || !target) continue;
1457
- for (const write of parameter.writes ?? []) {
1458
- if (write.node.left?.type !== "MemberExpression") continue;
1459
- if ((write.node.left.computed ? staticString(write.node.left.property) : write.node.left.property?.name) !== "route") continue;
1460
- const replay = {
1461
- ...write,
1462
- fn: void 0,
1463
- replayed: true
1464
- };
1465
- (target.writes ??= []).push(replay);
1466
- indexedWrites.push(replay);
1467
- }
1468
- }
1469
- activeFunctions.delete(fn);
1470
- parameterValues.clear();
1471
- for (const [binding, argument] of previousValues) parameterValues.set(binding, argument);
1472
- readPosition = previousPosition;
1473
- return result;
1474
- }
1475
- if (value.type === "BlockStatement") {
1476
- const hasReturn = (candidate) => {
1477
- if (!candidate) return false;
1478
- if (candidate.type === "ReturnStatement") return true;
1479
- for (const child of Object.values(candidate)) if (Array.isArray(child)) {
1480
- if (child.some((item) => item && typeof item === "object" && hasReturn(item))) return true;
1481
- } else if (child && typeof child === "object" && hasReturn(child)) return true;
1482
- return false;
1483
- };
1484
- for (const statement of Array.isArray(value.body) ? value.body : []) {
1485
- if (statement.type === "ReturnStatement") return findRoute(statement.argument ?? statement.expression, next);
1486
- if (statement.type === "IfStatement") {
1487
- const result = findRoute(statement, next);
1488
- if (result !== void 0) return result;
1489
- if (hasReturn(statement.consequent) || hasReturn(statement.alternate)) return void 0;
1490
- continue;
1491
- }
1492
- if (statement.type === "ExpressionStatement" && statement.expression) findRoute(statement.expression, next);
1493
- if (statement.type === "VariableDeclaration") {
1494
- for (const declaration of statement.declarations ?? []) if (declaration.init) findRoute(declaration.init, next);
1495
- }
1496
- }
1497
- }
1498
- };
1499
- const exportStart = exported?.init?.start ?? Infinity;
1500
- for (const statement of parsed.program.body) {
1501
- if ((statement.start ?? Infinity) >= exportStart) continue;
1502
- findRoute(statement);
1503
- }
1504
- return findRoute(exported?.init) ?? true;
1505
- }
1506
- async function discoverSourceCollections(options) {
1507
- const serverDirs = options.serverDirs === void 0 ? [resolve(options.projectRoot, "server")] : options.serverDirs.map((directory) => resolve(options.projectRoot, directory));
1508
- const collections = (await Promise.all(serverDirs.map(async (serverDir) => {
1509
- const directory = resolve(serverDir, "collections");
1510
- return await Promise.all((await collectCollectionFiles(directory)).sort().map(async (file) => {
1511
- const extension = extname(file);
1512
- const exportName = basename(file, extension);
1513
- if (!/^[A-Z_$][\w$]*$/i.test(exportName)) throw sourceErrorDiagnostics.SOURCE_B0003({ message: `[vitehub] Collection file ${JSON.stringify(relative(options.projectRoot, file))} must use a valid JavaScript identifier as its filename.` });
1514
- const name = relative(directory, file).slice(0, -extension.length).replaceAll("\\", "/");
1515
- const source = await readFile(file, "utf8");
1516
- if (!findExportNames(source).includes(exportName)) throw sourceErrorDiagnostics.SOURCE_B0004({ message: `[vitehub] Collection file ${JSON.stringify(relative(options.projectRoot, file))} must export a Collection named ${JSON.stringify(exportName)} to match its filename.` });
1517
- return {
1518
- exportName,
1519
- file,
1520
- name,
1521
- routeEnabled: collectionRouteEnabled(file, source, exportName)
1522
- };
1523
- }));
1524
- }))).flat().sort((left, right) => left.name.localeCompare(right.name));
1525
- const generatedPaths = /* @__PURE__ */ new Map();
1526
- for (const collection of collections) {
1527
- const generatedPath = `${collection.name}.mjs`.toLowerCase();
1528
- const previous = generatedPaths.get(generatedPath);
1529
- if (previous?.name === collection.name) throw sourceErrorDiagnostics.SOURCE_B0005({ message: `[vitehub] Collection name ${JSON.stringify(collection.name)} is defined in more than one server directory.` });
1530
- if (previous) {
1531
- const [firstName, secondName] = [previous.name, collection.name].sort();
1532
- throw sourceErrorDiagnostics.SOURCE_B0006({ message: `[vitehub] Collection names ${JSON.stringify(firstName)} and ${JSON.stringify(secondName)} generate the same route module on case-insensitive filesystems.` });
1533
- }
1534
- generatedPaths.set(generatedPath, collection);
1535
- }
1536
- return collections;
1235
+ /** Inspects the named Collection export without running application code. The docs snippet check calls it. */
1236
+ function inspectCollectionModule(file, source, exportName) {
1237
+ return inspectCollectionSource(file, source, exportName);
1537
1238
  }
1538
1239
  async function writeFileIfChanged(path, contents) {
1539
1240
  let current;
@@ -1548,20 +1249,16 @@ async function writeFileIfChanged(path, contents) {
1548
1249
  }
1549
1250
  async function writeCollectionArtifacts(options, collections) {
1550
1251
  const output = resolve(options.projectRoot, collectionTypesEntry);
1551
- const packageOutput = resolve(options.projectRoot, collectionTypesPackageEntry);
1552
1252
  const routesDirectory = resolve(options.projectRoot, collectionRoutesDirectory);
1253
+ await rm(resolve(options.projectRoot, retiredCollectionTypesWrapper), { force: true });
1553
1254
  if (collections.length === 0) {
1554
- await Promise.all([
1555
- rm(output, { force: true }),
1556
- rm(packageOutput, { force: true }),
1557
- rm(routesDirectory, {
1558
- force: true,
1559
- recursive: true
1560
- })
1561
- ]);
1255
+ await Promise.all([rm(output, { force: true }), rm(routesDirectory, {
1256
+ force: true,
1257
+ recursive: true
1258
+ })]);
1562
1259
  return [];
1563
1260
  }
1564
- const routedCollections = collections.filter((collection) => collection.routeEnabled);
1261
+ const routedCollections = collections.filter((collection) => collection.route);
1565
1262
  await writeFileIfChanged(output, [
1566
1263
  "declare global {",
1567
1264
  " interface ViteHubCollectionMap {",
@@ -1572,7 +1269,6 @@ async function writeCollectionArtifacts(options, collections) {
1572
1269
  "export {}",
1573
1270
  ""
1574
1271
  ].join("\n"));
1575
- await writeFileIfChanged(packageOutput, "/// <reference path=\"./collections.d.ts\" />\n");
1576
1272
  const expectedRoutes = new Set(routedCollections.map(({ name }) => resolve(routesDirectory, `${name}.mjs`)));
1577
1273
  const existingRoutes = await collectCollectionFiles(routesDirectory);
1578
1274
  await Promise.all(existingRoutes.filter((file) => !expectedRoutes.has(file)).map((file) => rm(file, { force: true })));
@@ -1594,7 +1290,7 @@ async function writeCollectionArtifacts(options, collections) {
1594
1290
  }));
1595
1291
  }
1596
1292
  /**
1597
- * Find the `server/content.{ts,js}` file that exports the application Content runtime as `content`. Returns undefined when
1293
+ * Find the `server/content.{ts,js}` file whose default export is the application Content runtime. Returns undefined when
1598
1294
  * the project has none. The generated `/api/content/**` route and the Console content editor import the same file.
1599
1295
  */
1600
1296
  async function findContentEntry(options) {
@@ -1614,7 +1310,12 @@ async function findContentEntry(options) {
1614
1310
  if (candidates.length > 1) throw sourceErrorDiagnostics.SOURCE_B0007({ message: "[vitehub] Content is defined in more than one server directory." });
1615
1311
  const file = candidates[0];
1616
1312
  if (!file) return;
1617
- if (!findExportNames(await readFile(file, "utf8")).includes("content")) throw sourceErrorDiagnostics.SOURCE_B0008({ message: `[vitehub] Content file ${JSON.stringify(relative(options.projectRoot, file))} must export a Comark Content instance named "content".` });
1313
+ const exports = exportNames(await readFile(file, "utf8"), file);
1314
+ if (!exports.includes("default")) {
1315
+ const name = JSON.stringify(relative(options.projectRoot, file));
1316
+ if (exports.includes("content")) throw sourceErrorDiagnostics.SOURCE_B0009({ message: `[vitehub] Content file ${name} exports \`content\` by name. Content is now the default export: \`export default defineContent({ ... })\`.` });
1317
+ throw sourceErrorDiagnostics.SOURCE_B0008({ message: `[vitehub] Content file ${name} must default-export the result of defineContent(): \`export default defineContent({ ... })\`.` });
1318
+ }
1618
1319
  return file;
1619
1320
  }
1620
1321
  const contentModules = /* @__PURE__ */ new Set(["vite-hub/content", "@vite-hub/content"]);
@@ -1641,17 +1342,38 @@ function unwrapAst(node) {
1641
1342
  return current;
1642
1343
  }
1643
1344
  /**
1644
- * Read the `defineContent()` call that initializes the `content` export. Collections count as present unless the call
1345
+ * Read the `defineContent()` call that the default export holds. Collections count as present unless the call
1645
1346
  * provably has no non-empty `collections` object. SEO routes count only when the call has a `seo` option: a literal
1646
- * `sitemap` or `robots` that is not `false`, or a `seo` value that discovery cannot follow.
1347
+ * `sitemap`, `robots`, `markdown`, `rss`, `mcp`, or `llms` that is not `false`, or a `seo` value that discovery cannot follow.
1647
1348
  */
1648
1349
  function inspectContentModule(program, contentImportBase) {
1350
+ return {
1351
+ ...inspectContentOptions(program, contentImportBase),
1352
+ sqlite: importsContentSqlite(program, contentImportBase),
1353
+ github: importsGitHubSource(program)
1354
+ };
1355
+ }
1356
+ const sourceModules = /* @__PURE__ */ new Set(["vite-hub/source", "@vite-hub/source"]);
1357
+ function importsGitHubSource(program) {
1358
+ return (isAstNode(program) ? astNodes(program.body) : []).some((statement) => statement.type === "ImportDeclaration" && isAstNode(statement.source) && sourceModules.has(String(statement.source.value)) && astNodes(statement.specifiers).some((specifier) => specifier.type === "ImportSpecifier" && astName(specifier.imported) === "github"));
1359
+ }
1360
+ function importsContentSqlite(program, contentImportBase) {
1361
+ const bases = contentImportBase ? /* @__PURE__ */ new Set([...contentModules, contentImportBase]) : contentModules;
1362
+ const modules = new Set([...bases].map((base) => `${base}/sqlite`));
1363
+ return (isAstNode(program) ? astNodes(program.body) : []).some((statement) => statement.type === "ImportDeclaration" && isAstNode(statement.source) && modules.has(String(statement.source.value)));
1364
+ }
1365
+ function inspectContentOptions(program, contentImportBase) {
1649
1366
  const maybe = {
1650
1367
  route: true,
1651
1368
  collections: true,
1652
1369
  sitemap: false,
1653
1370
  robots: false,
1654
- live: true
1371
+ markdown: false,
1372
+ rss: false,
1373
+ mcp: false,
1374
+ llms: false,
1375
+ live: true,
1376
+ previews: false
1655
1377
  };
1656
1378
  const body = isAstNode(program) ? astNodes(program.body) : [];
1657
1379
  const constants = /* @__PURE__ */ new Map();
@@ -1675,12 +1397,15 @@ function inspectContentModule(program, contentImportBase) {
1675
1397
  const declaration = exported ? statement.declaration : statement;
1676
1398
  if (isAstNode(declaration) && declaration.type === "VariableDeclaration") for (const declarator of astNodes(declaration.declarations)) {
1677
1399
  const local = astName(declarator.id);
1678
- if (!local) continue;
1679
- if (declaration.kind === "const") constants.set(local, declarator.init);
1680
- if (exported && local === "content") contentInit = declarator.init;
1400
+ if (local && declaration.kind === "const") constants.set(local, declarator.init);
1401
+ }
1402
+ if (statement.type === "ExportDefaultDeclaration") {
1403
+ const value = unwrapAst(statement.declaration);
1404
+ if (isAstNode(value) && value.type === "Identifier") contentLocal = astName(value);
1405
+ else contentInit = statement.declaration;
1681
1406
  }
1682
1407
  if (exported && !statement.source) {
1683
- for (const specifier of astNodes(statement.specifiers)) if (astName(specifier.exported) === "content") contentLocal = astName(specifier.local);
1408
+ for (const specifier of astNodes(statement.specifiers)) if (astName(specifier.exported) === "default") contentLocal = astName(specifier.local);
1684
1409
  }
1685
1410
  }
1686
1411
  if (contentInit === void 0 && contentLocal) contentInit = constants.get(contentLocal);
@@ -1718,7 +1443,12 @@ function inspectContentModule(program, contentImportBase) {
1718
1443
  collections: false,
1719
1444
  sitemap: false,
1720
1445
  robots: false,
1721
- live: true
1446
+ markdown: false,
1447
+ rss: false,
1448
+ mcp: false,
1449
+ llms: false,
1450
+ live: true,
1451
+ previews: false
1722
1452
  };
1723
1453
  const options = rest.length ? void 0 : properties(resolveNode(argument));
1724
1454
  if (!options) return {
@@ -1726,16 +1456,27 @@ function inspectContentModule(program, contentImportBase) {
1726
1456
  collections: true,
1727
1457
  sitemap: true,
1728
1458
  robots: true,
1729
- live: true
1459
+ markdown: true,
1460
+ rss: true,
1461
+ mcp: "unknown",
1462
+ llms: true,
1463
+ live: true,
1464
+ previews: true
1730
1465
  };
1731
1466
  const route = resolveNode(options.get("route"));
1732
1467
  const live = unwrapAst(options.get("live"));
1468
+ const previews = resolveNode(options.get("previews"));
1733
1469
  const features = {
1734
1470
  route: !(isAstNode(route) && route.type === "Literal" && route.value === false),
1735
1471
  collections: false,
1736
1472
  sitemap: false,
1737
1473
  robots: false,
1738
- live: !(isAstNode(live) && live.type === "Literal" && live.value === false)
1474
+ markdown: false,
1475
+ rss: false,
1476
+ mcp: false,
1477
+ llms: false,
1478
+ live: !(isAstNode(live) && live.type === "Literal" && live.value === false),
1479
+ previews: options.has("previews") && !(isAstNode(previews) && previews.type === "Literal" && previews.value === false)
1739
1480
  };
1740
1481
  if (options.has("collections")) {
1741
1482
  const value = resolveNode(options.get("collections"));
@@ -1746,13 +1487,26 @@ function inspectContentModule(program, contentImportBase) {
1746
1487
  if (!seo) return {
1747
1488
  ...features,
1748
1489
  sitemap: true,
1749
- robots: true
1490
+ robots: true,
1491
+ markdown: true,
1492
+ rss: true,
1493
+ mcp: "unknown",
1494
+ llms: true
1750
1495
  };
1751
- for (const key of ["sitemap", "robots"]) {
1496
+ for (const key of [
1497
+ "sitemap",
1498
+ "robots",
1499
+ "markdown",
1500
+ "rss",
1501
+ "mcp",
1502
+ "llms"
1503
+ ]) {
1752
1504
  if (!seo.has(key)) continue;
1753
- const value = unwrapAst(seo.get(key));
1754
- features[key] = !(isAstNode(value) && value.type === "Literal" && value.value === false);
1505
+ const value = key === "mcp" ? resolveNode(seo.get(key)) : unwrapAst(seo.get(key));
1506
+ if (key === "mcp" && (!isAstNode(value) || value.type !== "Literal" && value.type !== "ObjectExpression")) features.mcp = "unknown";
1507
+ else features[key] = !(isAstNode(value) && value.type === "Literal" && value.value === false);
1755
1508
  }
1509
+ if (features.llms) features.markdown = true;
1756
1510
  }
1757
1511
  return features;
1758
1512
  }
@@ -1767,7 +1521,14 @@ async function inspectContentEntry(file, contentImportBase) {
1767
1521
  collections: true,
1768
1522
  sitemap: false,
1769
1523
  robots: false,
1770
- live: true
1524
+ markdown: false,
1525
+ rss: false,
1526
+ mcp: false,
1527
+ llms: false,
1528
+ live: true,
1529
+ previews: false,
1530
+ sqlite: false,
1531
+ github: false
1771
1532
  };
1772
1533
  }
1773
1534
  }
@@ -1776,73 +1537,204 @@ async function writeContentArtifact(options, file) {
1776
1537
  const preview = resolve(options.projectRoot, contentPreviewEntry);
1777
1538
  const sitemap = resolve(options.projectRoot, contentSitemapEntry);
1778
1539
  const robots = resolve(options.projectRoot, contentRobotsEntry);
1540
+ const markdown = resolve(options.projectRoot, contentMarkdownEntry);
1541
+ const rss = resolve(options.projectRoot, contentRssEntry);
1542
+ const mcp = resolve(options.projectRoot, contentMcpEntry);
1543
+ const llms = resolve(options.projectRoot, contentLlmsEntry);
1544
+ const sqlite = resolve(options.projectRoot, contentSqliteEntry);
1545
+ const githubWebhook = resolve(options.projectRoot, contentGitHubWebhookEntry);
1546
+ const previewRoutes = resolve(options.projectRoot, contentPreviewRoutesEntry);
1547
+ const typesPlugin = resolve(options.projectRoot, contentTypesPluginEntry);
1548
+ const types = resolve(options.projectRoot, contentTypesEntry);
1779
1549
  if (!file) {
1780
1550
  await Promise.all([
1781
1551
  output,
1782
1552
  preview,
1783
1553
  sitemap,
1784
- robots
1554
+ robots,
1555
+ markdown,
1556
+ rss,
1557
+ mcp,
1558
+ llms,
1559
+ sqlite,
1560
+ githubWebhook,
1561
+ previewRoutes,
1562
+ typesPlugin,
1563
+ types
1785
1564
  ].map((path) => rm(path, { force: true })));
1786
1565
  return [];
1787
1566
  }
1788
1567
  const importBase = JSON.stringify(options.contentImportBase ?? "@vite-hub/content");
1789
1568
  const contentModule = JSON.stringify(toRuntimeModuleSpecifier(file));
1790
- const features = await inspectContentEntry(file, options.contentImportBase ?? "@vite-hub/content");
1569
+ const features = {
1570
+ ...await inspectContentEntry(file, options.contentImportBase ?? "@vite-hub/content"),
1571
+ ...options.appSeo?.sitemap ? { sitemap: false } : {},
1572
+ ...options.appSeo?.robots ? { robots: false } : {}
1573
+ };
1574
+ const sessionUser = (useAuth) => `async request => (await ${useAuth}(request).api.getSession({ headers: request.headers }))?.user ?? null`;
1575
+ const authImport = options.auth ? [`import { useAuth } from ${JSON.stringify(authServerModuleId)}`] : [];
1576
+ const readerOptions = options.auth ? `, { user: ${sessionUser("useAuth")} }` : "";
1577
+ const lazyUser = options.auth ? `user: ${sessionUser(`(await import(${JSON.stringify(authServerModuleId)})).useAuth`)}` : "";
1791
1578
  if (features.route) await writeFileIfChanged(output, [
1792
1579
  `import { defineContentHandler } from ${importBase}`,
1793
- `import { content } from ${contentModule}`,
1580
+ ...authImport,
1581
+ `import content from ${contentModule}`,
1794
1582
  "",
1795
- "export default defineContentHandler(content)",
1583
+ `export default defineContentHandler(content${readerOptions})`,
1796
1584
  ""
1797
1585
  ].join("\n"));
1798
1586
  else await rm(output, { force: true });
1587
+ const handlers = [];
1799
1588
  await writeFileIfChanged(preview, [
1800
- `import { defineContentPreviewPlugin } from ${importBase}`,
1801
- `import { content } from ${contentModule}`,
1589
+ `import { defineContentPreviewPlugin } from ${JSON.stringify(`${options.contentImportBase ?? "@vite-hub/content"}/preview`)}`,
1802
1590
  "",
1803
- "export default defineContentPreviewPlugin(content)",
1591
+ `export default defineContentPreviewPlugin(() => import(${contentModule}).then(module => module.default))`,
1804
1592
  ""
1805
1593
  ].join("\n"));
1806
- const handlers = [{
1594
+ handlers.push({
1807
1595
  handler: preview,
1808
1596
  plugin: true
1809
- }];
1597
+ });
1598
+ if (features.sqlite) {
1599
+ await writeFileIfChanged(sqlite, [
1600
+ `import { sqlite } from ${JSON.stringify(`${options.contentImportBase ?? "@vite-hub/content"}/sqlite`)}`,
1601
+ "",
1602
+ "// Returning the import keeps it in the bundle. A bare import is dropped, because the packages have no side effects.",
1603
+ "export default () => sqlite",
1604
+ ""
1605
+ ].join("\n"));
1606
+ handlers.push({
1607
+ handler: sqlite,
1608
+ plugin: true
1609
+ });
1610
+ } else await rm(sqlite, { force: true });
1611
+ await writeFileIfChanged(typesPlugin, renderContentTypesPlugin(importBase, contentModule));
1612
+ handlers.push({
1613
+ handler: typesPlugin,
1614
+ plugin: true
1615
+ });
1616
+ if (!await readFile(types, "utf8").then(() => true, () => false)) await writeFileIfChanged(types, "export {}\n");
1810
1617
  if (features.route) handlers.push({
1811
1618
  handler: output,
1812
1619
  route: "/api/content/**"
1813
1620
  });
1814
- for (const [enabled, path, helper, route] of [[
1815
- features.sitemap,
1816
- sitemap,
1817
- "defineContentSitemapHandler",
1818
- "/sitemap.xml"
1819
- ], [
1820
- features.robots,
1821
- robots,
1822
- "defineContentRobotsHandler",
1823
- "/robots.txt"
1824
- ]]) {
1621
+ if (features.github) {
1622
+ await writeFileIfChanged(githubWebhook, [
1623
+ `import { defineContentGitHubWebhookHandler } from ${importBase}`,
1624
+ `import content from ${contentModule}`,
1625
+ "",
1626
+ "export default defineContentGitHubWebhookHandler(content)",
1627
+ ""
1628
+ ].join("\n"));
1629
+ handlers.push({
1630
+ handler: githubWebhook,
1631
+ method: "post",
1632
+ route: "/_vitehub/content/github"
1633
+ });
1634
+ } else await rm(githubWebhook, { force: true });
1635
+ if (features.previews) {
1636
+ await writeFileIfChanged(previewRoutes, [
1637
+ `import { defineContentPreviewRoutesPlugin } from ${JSON.stringify(`${options.contentImportBase ?? "@vite-hub/content"}/preview`)}`,
1638
+ "import { useRuntimeConfig } from \"nitro/runtime-config\"",
1639
+ "",
1640
+ `export default defineContentPreviewRoutesPlugin(() => import(${contentModule}).then(module => module.default), { app: useRuntimeConfig().app${lazyUser ? `, ${lazyUser}` : ""} })`,
1641
+ ""
1642
+ ].join("\n"));
1643
+ handlers.push({
1644
+ handler: previewRoutes,
1645
+ plugin: true,
1646
+ position: "start"
1647
+ });
1648
+ } else await rm(previewRoutes, { force: true });
1649
+ for (const [enabled, path, helper, routes] of [
1650
+ [
1651
+ features.sitemap,
1652
+ sitemap,
1653
+ "defineContentSitemapHandler",
1654
+ ["/sitemap.xml"]
1655
+ ],
1656
+ [
1657
+ features.robots,
1658
+ robots,
1659
+ "defineContentRobotsHandler",
1660
+ ["/robots.txt"]
1661
+ ],
1662
+ [
1663
+ features.rss,
1664
+ rss,
1665
+ "defineContentRssHandler",
1666
+ ["/rss.xml"]
1667
+ ],
1668
+ [
1669
+ features.mcp,
1670
+ mcp,
1671
+ "defineContentMcpHandler",
1672
+ ["/mcp"]
1673
+ ],
1674
+ [
1675
+ features.llms,
1676
+ llms,
1677
+ "defineContentLlmsHandler",
1678
+ [
1679
+ "/llms.txt",
1680
+ "/llms-full.txt",
1681
+ "/:locale/llms-full.txt",
1682
+ "/sitemap.md"
1683
+ ]
1684
+ ]
1685
+ ]) {
1825
1686
  if (!enabled) {
1826
1687
  await rm(path, { force: true });
1827
1688
  continue;
1828
1689
  }
1690
+ const conditionalMcp = routes[0] === "/mcp" && enabled === "unknown";
1691
+ const helperOptions = helper === "defineContentRobotsHandler" ? "" : readerOptions;
1829
1692
  await writeFileIfChanged(path, [
1830
1693
  `import { ${helper} } from ${importBase}`,
1831
- `import { content } from ${contentModule}`,
1694
+ ...helperOptions ? authImport : [],
1695
+ `import content from ${contentModule}`,
1832
1696
  "",
1833
- `export default ${helper}(content)`,
1697
+ ...conditionalMcp ? [
1698
+ `const handler = ${helper}(content${helperOptions})`,
1699
+ "export default async event => {",
1700
+ " if (!content.seo?.mcp) return",
1701
+ " return await handler.fetch(event.req)",
1702
+ "}"
1703
+ ] : [`export default ${helper}(content${helperOptions})`],
1834
1704
  ""
1835
1705
  ].join("\n"));
1836
- handlers.push({
1706
+ for (const route of routes) handlers.push(conditionalMcp ? {
1707
+ handler: path,
1708
+ middleware: true,
1709
+ route
1710
+ } : route === "/mcp" ? {
1711
+ handler: path,
1712
+ route
1713
+ } : {
1837
1714
  handler: path,
1838
1715
  method: "get",
1839
1716
  route
1840
1717
  });
1841
1718
  }
1719
+ if (features.markdown) {
1720
+ await writeFileIfChanged(markdown, [
1721
+ `import { defineContentMarkdownHandler } from ${JSON.stringify(`${options.contentImportBase ?? "@vite-hub/content"}/markdown`)}`,
1722
+ `import { serverFetch } from "nitro"`,
1723
+ "",
1724
+ `export default defineContentMarkdownHandler(() => import(${contentModule}).then(module => module.default), { render: request => serverFetch(request)${lazyUser ? `, ${lazyUser}` : ""} })`,
1725
+ ""
1726
+ ].join("\n"));
1727
+ handlers.push({
1728
+ handler: markdown,
1729
+ middleware: true,
1730
+ lazy: false,
1731
+ route: "/**"
1732
+ });
1733
+ } else await rm(markdown, { force: true });
1842
1734
  return handlers;
1843
1735
  }
1844
1736
  async function prepareSourceArtifacts(options) {
1845
- const [collections, content] = await Promise.all([discoverSourceCollections(options), findContentEntry(options)]);
1737
+ const [collections, content] = await Promise.all([discoverCollections(options), findContentEntry(options)]);
1846
1738
  return {
1847
1739
  handlers: [...await writeCollectionArtifacts(options, collections), ...await writeContentArtifact(options, content)].sort((left, right) => (left.route ?? "").localeCompare(right.route ?? "")),
1848
1740
  ...content ? { content: { handler: content } } : {}
@@ -1851,7 +1743,10 @@ async function prepareSourceArtifacts(options) {
1851
1743
  async function prepareSourceGeneration(options) {
1852
1744
  return (await prepareSourceArtifacts(options)).handlers;
1853
1745
  }
1854
- function applicationBaseURL(base) {
1746
+ /** Nuxt serves Vite assets from `/_nuxt/`, so its Vite `base` is not the app base. `vite-hub/nuxt` passes the app base. */
1747
+ function applicationBaseURL(config) {
1748
+ const configured = Reflect.get(config, VITEHUB_APP_BASE_URL);
1749
+ const base = typeof configured === "string" ? configured : config.base;
1855
1750
  return base?.startsWith("/") && !base.startsWith("//") ? base : "/";
1856
1751
  }
1857
1752
  async function generatedHandlerKey(handlers) {
@@ -1866,7 +1761,7 @@ function generatedSourceNitroContribution(value, generatedHandlers) {
1866
1761
  const merged = mergeGeneratedSourceNitroConfig(existing, generatedHandlers);
1867
1762
  const handlers = merged.handlers?.slice(Array.isArray(existing.handlers) ? existing.handlers.length : 0);
1868
1763
  const modules = merged.modules?.slice(Array.isArray(existing.modules) ? existing.modules.length : 0);
1869
- const plugins = merged.plugins?.slice(Array.isArray(existing.plugins) ? existing.plugins.length : 0);
1764
+ const plugins = merged.plugins?.filter((plugin) => !existing.plugins?.includes(plugin));
1870
1765
  if (!handlers?.length && !modules?.length && !plugins?.length) return;
1871
1766
  const contribution = {};
1872
1767
  if (handlers?.length) contribution.handlers = handlers;
@@ -1900,21 +1795,20 @@ function hubSource(options = {}) {
1900
1795
  };
1901
1796
  const configurationTransitionByRoot = /* @__PURE__ */ new Map();
1902
1797
  let legacyServerBuild = false;
1798
+ let resolvedConfig;
1903
1799
  const generatedHandlersListeners = /* @__PURE__ */ new Set();
1904
- const prepareSources = (input, configuredAuth) => {
1800
+ const prepareSources = (input) => {
1905
1801
  const root = resolve(input.projectRoot);
1906
1802
  const previousPreparation = sourcePreparationByRoot.get(root) ?? Promise.resolve();
1907
1803
  const runPreparation = () => {
1908
- const configuredState = configuredStateByRoot.get(root);
1909
- const resolvedConfiguredAuth = configuredAuth === void 0 ? configuredState?.configuredAuth : configuredAuth;
1910
1804
  const auth = typeof options.auth === "function" ? options.auth({
1911
- configuredAuth: resolvedConfiguredAuth,
1912
1805
  projectRoot: root,
1913
1806
  serverDirs: input.serverDirs
1914
- }) : options.auth && resolvedConfiguredAuth !== false && Boolean(refreshAuthByRoot.get(root)?.());
1807
+ }) : options.auth && Boolean(refreshAuthByRoot.get(root)?.());
1915
1808
  return prepareSourceArtifacts({
1916
1809
  ...input,
1917
1810
  auth,
1811
+ ...options.appSeo ? { appSeo: options.appSeo } : {},
1918
1812
  importBase: options.importBase,
1919
1813
  contentImportBase: options.contentImportBase
1920
1814
  }).then(({ content, handlers }) => {
@@ -1986,16 +1880,26 @@ function hubSource(options = {}) {
1986
1880
  transform: {
1987
1881
  filter: {
1988
1882
  id: { exclude: /\/node_modules\// },
1989
- code: "source/glob"
1883
+ code: /\bvite-hub\/source["'`]/
1990
1884
  },
1991
- handler(code, _id, options) {
1885
+ handler(code, id, options) {
1992
1886
  const environment = this.environment?.config;
1993
1887
  if (!(environment ? environment.consumer === "server" : options?.ssr === true && legacyServerBuild) || environment && environment.command !== "build") return;
1994
1888
  const calls = findGlobCalls(this.parse(code));
1995
- for (const call of calls.filter((call) => call.input === void 0)) this.warn({
1996
- message: "[vitehub] glob() here takes options that are not literals, so the build cannot bundle its files. It reads them from disk at runtime, which hosts such as Cloudflare Workers do not have.",
1997
- pos: call.start
1998
- });
1889
+ for (const call of calls.filter((call) => call.input === void 0)) {
1890
+ const hint = sourceErrorDiagnostics.SOURCE_GLOB_OPTIONS_NOT_LITERAL();
1891
+ const config = environment ?? resolvedConfig;
1892
+ if (!config) {
1893
+ this.warn({
1894
+ message: `[vitehub] ${hint.why}`,
1895
+ pos: call.start
1896
+ });
1897
+ continue;
1898
+ }
1899
+ const lines = code.slice(0, call.start).split("\n");
1900
+ hint.sources = [`${relative(config.root, id)}:${lines.length}:${lines.at(-1).length + 1}`];
1901
+ reportViteHubHint(config, hint);
1902
+ }
1999
1903
  if (calls.some((call) => call.input !== void 0)) return {
2000
1904
  code: rewriteGlobCalls(code, calls),
2001
1905
  map: null
@@ -2015,10 +1919,10 @@ function hubSource(options = {}) {
2015
1919
  }] }) },
2016
1920
  nitro: {
2017
1921
  name: "@vite-hub/source/generated-routes",
2018
- setup(nitro) {
1922
+ async setup(nitro) {
2019
1923
  nitroHost = nitro;
2020
1924
  nitroHostContribution = void 0;
2021
- generatedRouteGuard(nitroHandlers).setup(nitro);
1925
+ await generatedRouteGuard(nitroHandlers).setup(nitro);
2022
1926
  }
2023
1927
  },
2024
1928
  async config(config, env) {
@@ -2038,17 +1942,16 @@ function hubSource(options = {}) {
2038
1942
  const handlers = await prepareSources({
2039
1943
  projectRoot,
2040
1944
  serverDirs
2041
- }, viteConfig.auth === false ? false : viteConfig.auth ? true : void 0);
1945
+ });
2042
1946
  const handlerKey = await generatedHandlerKey(handlers);
2043
1947
  const nitro = generatedSourceNitroContribution(viteConfig.nitro, handlers);
2044
1948
  configuredStateByRoot.set(projectRoot, {
2045
- configuredAuth: viteConfig.auth === false ? false : viteConfig.auth ? true : void 0,
2046
1949
  handlerKey,
2047
1950
  nitroContribution: nitro,
2048
1951
  serverDirs: serverDirs?.slice()
2049
1952
  });
2050
1953
  const contribution = {
2051
- define: { __VITEHUB_APP_BASE_URL__: JSON.stringify(applicationBaseURL(viteConfig.base)) },
1954
+ define: { __VITEHUB_APP_BASE_URL__: JSON.stringify(applicationBaseURL(viteConfig)) },
2052
1955
  ...nitro ? { nitro } : {}
2053
1956
  };
2054
1957
  previousLifecycle?.close();
@@ -2073,6 +1976,8 @@ function hubSource(options = {}) {
2073
1976
  return transition;
2074
1977
  },
2075
1978
  async configResolved(config) {
1979
+ startViteHubHints(config);
1980
+ resolvedConfig = config;
2076
1981
  const viteConfig = config;
2077
1982
  const projectRoot = viteConfig["__vitehubProjectRoot"] ? resolve(viteConfig[VITEHUB_PROJECT_ROOT]) : resolveViteHubProjectRoot(config.root);
2078
1983
  latestProjectRoot = projectRoot;
@@ -2082,7 +1987,7 @@ function hubSource(options = {}) {
2082
1987
  if (refreshAuth instanceof Function) refreshAuthByRoot.set(projectRoot, () => refreshAuth());
2083
1988
  else refreshAuthByRoot.delete(projectRoot);
2084
1989
  viteConfig.define ??= {};
2085
- viteConfig.define.__VITEHUB_APP_BASE_URL__ = JSON.stringify(applicationBaseURL(config.base));
1990
+ viteConfig.define.__VITEHUB_APP_BASE_URL__ = JSON.stringify(applicationBaseURL(config));
2086
1991
  const previousTransition = configurationTransitionByRoot.get(projectRoot) ?? Promise.resolve();
2087
1992
  const runTransition = async () => {
2088
1993
  const configuredState = configuredStateByRoot.get(projectRoot);
@@ -2090,7 +1995,7 @@ function hubSource(options = {}) {
2090
1995
  const handlers = await prepareSources({
2091
1996
  projectRoot,
2092
1997
  serverDirs
2093
- }, viteConfig.auth === false ? false : viteConfig.auth ? true : void 0);
1998
+ });
2094
1999
  const handlerKey = await generatedHandlerKey(handlers);
2095
2000
  if (nitroHost && !viteConfig["__vitehubNitroConfigContext"]) {
2096
2001
  assertGeneratedRoutes(nitroHost, handlers);
@@ -2102,10 +2007,11 @@ function hubSource(options = {}) {
2102
2007
  nitroHost.options.handlers = nitro.handlers;
2103
2008
  nitroHost.options.plugins = nitro.plugins;
2104
2009
  nitroHandlers.splice(0, nitroHandlers.length, ...handlers);
2010
+ const typesPlugin = handlers.find((handler) => handler.plugin && handler.handler.replaceAll("\\", "/").endsWith(`/${contentTypesPluginEntry}`));
2011
+ if (typesPlugin) await installContentTypesWriter(nitroHost, typesPlugin.handler);
2105
2012
  nitroHost.routing.sync();
2106
2013
  }
2107
2014
  configuredStateByRoot.set(projectRoot, {
2108
- configuredAuth: viteConfig.auth === false ? false : viteConfig.auth ? true : void 0,
2109
2015
  handlerKey,
2110
2016
  nitroContribution: configuredState?.nitroContribution,
2111
2017
  serverDirs: serverDirs?.slice()
@@ -2281,4 +2187,4 @@ function hubSource(options = {}) {
2281
2187
  };
2282
2188
  }
2283
2189
  //#endregion
2284
- export { findContentEntry, hubSource, inspectCollectionDefinitions, inspectContentEntry, inspectContentModule, mergeGeneratedSourceNitroConfig, prepareSourceGeneration, toRuntimeModuleSpecifier, toTypeModuleSpecifier };
2190
+ export { findContentEntry, hubSource, inspectCollectionDefinitions, inspectCollectionModule, inspectContentEntry, inspectContentModule, mergeGeneratedSourceNitroConfig, prepareSourceGeneration, toRuntimeModuleSpecifier, toTypeModuleSpecifier };