@nuasite/cms-sidecar 0.70.2 → 0.70.4

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.
@@ -23202,54 +23202,57 @@ function parseSource(source) {
23202
23202
  return null;
23203
23203
  }
23204
23204
  }
23205
- var CONTENT_CONFIG_PATHS = ["src/content/config.ts", "src/content.config.ts"];
23206
- var UNREAD_CONTENT_CONFIG_PATHS = [
23205
+ var ASTRO_CONTENT_CONFIG_ORDER = [
23207
23206
  "src/content.config.mjs",
23208
23207
  "src/content.config.js",
23209
23208
  "src/content.config.mts",
23210
- "src/content/config.mjs",
23209
+ "src/content.config.ts",
23210
+ "src/content/config.ts",
23211
23211
  "src/content/config.js",
23212
+ "src/content/config.mjs",
23212
23213
  "src/content/config.mts"
23213
23214
  ];
23214
- async function classifyEmptyContentConfig(fs3) {
23215
- let found = false;
23216
- for (const configPath of CONTENT_CONFIG_PATHS) {
23217
- try {
23218
- await fs3.stat(configPath);
23219
- } catch {
23220
- continue;
23221
- }
23222
- found = true;
23223
- if (parseSource(await fs3.readFile(configPath)) === null) {
23224
- return "unparseable";
23225
- }
23215
+ var CONTENT_CONFIG_PATHS = ASTRO_CONTENT_CONFIG_ORDER.filter((configPath) => configPath.endsWith(".ts"));
23216
+ var READ_CONTENT_CONFIG_PATHS = new Set(CONTENT_CONFIG_PATHS);
23217
+ var UNREAD_CONTENT_CONFIG_PATHS = ASTRO_CONTENT_CONFIG_ORDER.filter((configPath) => !READ_CONTENT_CONFIG_PATHS.has(configPath));
23218
+ var inSrcDir = (configPath, srcDir) => `${srcDir}${configPath.slice("src".length)}`;
23219
+ async function findLoadedContentConfig(fs3, srcDir = "src") {
23220
+ for (const configPath of ASTRO_CONTENT_CONFIG_ORDER) {
23221
+ const file = inSrcDir(configPath, srcDir);
23222
+ if (await fs3.exists(file))
23223
+ return { file, read: READ_CONTENT_CONFIG_PATHS.has(configPath), legacy: configPath.startsWith("src/content/") };
23226
23224
  }
23227
- return found ? "no-collections" : "missing";
23225
+ return null;
23226
+ }
23227
+ async function classifyEmptyContentConfig(fs3, srcDir = "src") {
23228
+ const loaded = await findLoadedContentConfig(fs3, srcDir);
23229
+ if (loaded === null)
23230
+ return "missing";
23231
+ if (!loaded.read)
23232
+ return "unread";
23233
+ return parseSource(await fs3.readFile(loaded.file)) === null ? "unparseable" : "no-collections";
23228
23234
  }
23229
- async function parseContentConfig(fs3, cache) {
23230
- return (await readContentConfig(fs3, cache)).parsed;
23235
+ async function parseContentConfig(fs3, cache, srcDir = "src") {
23236
+ return (await readContentConfig(fs3, cache, srcDir)).parsed;
23231
23237
  }
23232
- async function readContentConfig(fs3, cache) {
23233
- let unparsed;
23238
+ async function readContentConfig(fs3, cache, srcDir = "src") {
23234
23239
  for (const configPath of CONTENT_CONFIG_PATHS) {
23240
+ const file = inSrcDir(configPath, srcDir);
23235
23241
  let stat;
23236
23242
  try {
23237
- stat = await fs3.stat(configPath);
23243
+ stat = await fs3.stat(file);
23238
23244
  } catch {
23239
23245
  continue;
23240
23246
  }
23241
- let cached = cache.get(configPath);
23247
+ let cached = cache.get(file);
23242
23248
  if (!cached || cached.mtimeMs !== stat.mtimeMs) {
23243
- const content = await fs3.readFile(configPath);
23249
+ const content = await fs3.readFile(file);
23244
23250
  cached = { mtimeMs: stat.mtimeMs, ...readConfigSource(content) };
23245
- cache.set(configPath, cached);
23251
+ cache.set(file, cached);
23246
23252
  }
23247
- if (cached.parsed.size > 0)
23248
- return cached;
23249
- if (!unparsed && (cached.declared.length > 0 || cached.exportsCollections))
23250
- unparsed = cached;
23253
+ return cached;
23251
23254
  }
23252
- return unparsed ?? { parsed: new Map, declared: [], partial: false, exportsCollections: false };
23255
+ return { parsed: new Map, declared: [], partial: false, exportsCollections: false };
23253
23256
  }
23254
23257
  function readConfigSource(source) {
23255
23258
  const result = new Map;
@@ -24295,9 +24298,284 @@ function dropNestedDerivedFrom(collectionName, path3, fields) {
24295
24298
  dropNestedDerivedFrom(collectionName, fieldPath, field.fields);
24296
24299
  }
24297
24300
  }
24301
+
24302
+ // ../cms-core/src/project-config-ast.ts
24303
+ var import_parser4 = __toESM(require_lib(), 1);
24304
+ import path4 from "path";
24305
+
24306
+ // ../cms-core/src/base-path.ts
24307
+ import path3 from "path";
24308
+ function normalizeBasePath(basePath) {
24309
+ return path3.normalize(basePath.replace(/^\.[/\\]+/, "")).replace(/[/\\]+$/, "");
24310
+ }
24311
+
24312
+ // ../cms-core/src/project-config-ast.ts
24313
+ var EMPTY_CONFIG = { listStyles: [] };
24314
+ function parseSource2(source) {
24315
+ try {
24316
+ return import_parser4.parse(source, {
24317
+ sourceType: "module",
24318
+ plugins: ["typescript"],
24319
+ errorRecovery: true
24320
+ });
24321
+ } catch {
24322
+ return null;
24323
+ }
24324
+ }
24325
+ function collectBindings2(ast) {
24326
+ const bindings = new Map;
24327
+ for (const stmt of ast.program.body) {
24328
+ const varDecl = stmt.type === "ExportNamedDeclaration" && stmt.declaration?.type === "VariableDeclaration" ? stmt.declaration : stmt.type === "VariableDeclaration" ? stmt : null;
24329
+ if (!varDecl)
24330
+ continue;
24331
+ for (const decl of varDecl.declarations) {
24332
+ if (decl.id.type === "Identifier" && decl.init)
24333
+ bindings.set(decl.id.name, decl.init);
24334
+ }
24335
+ }
24336
+ return bindings;
24337
+ }
24338
+ function withoutTypeWrappers(node) {
24339
+ let current = node;
24340
+ while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion") {
24341
+ current = current.expression;
24342
+ }
24343
+ return current;
24344
+ }
24345
+ function resolveExpression2(node, bindings, visited = new Set) {
24346
+ let current = withoutTypeWrappers(node);
24347
+ while (current.type === "Identifier") {
24348
+ if (visited.has(current.name))
24349
+ return current;
24350
+ visited.add(current.name);
24351
+ const next = bindings.get(current.name);
24352
+ if (!next)
24353
+ return current;
24354
+ current = withoutTypeWrappers(next);
24355
+ }
24356
+ return current;
24357
+ }
24358
+ function propertyKeyName2(key) {
24359
+ if (key.type === "Identifier")
24360
+ return key.name;
24361
+ if (key.type === "StringLiteral")
24362
+ return key.value;
24363
+ return null;
24364
+ }
24365
+ function objectPropertyValue(node, keyName, bindings) {
24366
+ for (const prop of node.properties) {
24367
+ if (prop.type !== "ObjectProperty")
24368
+ continue;
24369
+ if (propertyKeyName2(prop.key) !== keyName)
24370
+ continue;
24371
+ return resolveExpression2(prop.value, bindings);
24372
+ }
24373
+ return null;
24374
+ }
24375
+ function objectAtPath(root, keys, bindings) {
24376
+ let current = root;
24377
+ for (const key of keys) {
24378
+ const value = objectPropertyValue(current, key, bindings);
24379
+ if (!value || value.type !== "ObjectExpression")
24380
+ return null;
24381
+ current = value;
24382
+ }
24383
+ return current;
24384
+ }
24385
+ function staticString2(node, bindings) {
24386
+ const resolved = resolveExpression2(node, bindings);
24387
+ if (resolved.type === "StringLiteral")
24388
+ return resolved.value;
24389
+ if (resolved.type === "TemplateLiteral" && resolved.expressions.length === 0) {
24390
+ return resolved.quasis[0]?.value.cooked ?? resolved.quasis[0]?.value.raw;
24391
+ }
24392
+ return;
24393
+ }
24394
+ function parseListStyle(node, bindings) {
24395
+ const resolved = resolveExpression2(node, bindings);
24396
+ if (resolved.type !== "ObjectExpression")
24397
+ return null;
24398
+ const labelNode = objectPropertyValue(resolved, "label", bindings);
24399
+ const classNode = objectPropertyValue(resolved, "class", bindings);
24400
+ if (!labelNode || !classNode)
24401
+ return null;
24402
+ const label = staticString2(labelNode, bindings);
24403
+ const className = staticString2(classNode, bindings);
24404
+ if (label === undefined || className === undefined)
24405
+ return null;
24406
+ return { label, class: className };
24407
+ }
24408
+ function parseListStyles(node, bindings) {
24409
+ const styles = [];
24410
+ for (const element of node.elements) {
24411
+ if (!element || element.type === "SpreadElement")
24412
+ continue;
24413
+ const style = parseListStyle(element, bindings);
24414
+ if (style)
24415
+ styles.push(style);
24416
+ }
24417
+ return styles;
24418
+ }
24419
+ function configObjectFromDefaultExport(ast, bindings) {
24420
+ for (const stmt of ast.program.body) {
24421
+ if (stmt.type !== "ExportDefaultDeclaration")
24422
+ continue;
24423
+ const declaration = resolveExpression2(stmt.declaration, bindings);
24424
+ if (declaration.type === "ObjectExpression")
24425
+ return declaration;
24426
+ if (declaration.type === "CallExpression") {
24427
+ const firstArg = declaration.arguments[0];
24428
+ if (!firstArg || firstArg.type === "SpreadElement")
24429
+ return null;
24430
+ const resolvedArg = resolveExpression2(firstArg, bindings);
24431
+ if (resolvedArg.type === "ObjectExpression")
24432
+ return resolvedArg;
24433
+ }
24434
+ }
24435
+ return null;
24436
+ }
24437
+ var CMS_INTEGRATION_OPTIONS_PATH = {
24438
+ "@nuasite/cms": [],
24439
+ "@nuasite/nua": ["cms"],
24440
+ "@nuasite/nua/integration": ["cms"]
24441
+ };
24442
+ function collectCmsIntegrationImports(ast) {
24443
+ const imports = new Map;
24444
+ for (const stmt of ast.program.body) {
24445
+ if (stmt.type !== "ImportDeclaration")
24446
+ continue;
24447
+ const optionsPath = CMS_INTEGRATION_OPTIONS_PATH[stmt.source.value];
24448
+ if (!optionsPath)
24449
+ continue;
24450
+ for (const specifier of stmt.specifiers) {
24451
+ const importedName2 = specifier.type === "ImportDefaultSpecifier" ? "default" : specifier.type === "ImportSpecifier" ? propertyKeyName2(specifier.imported) : null;
24452
+ if (importedName2 === "default" || importedName2 === "nua" && optionsPath.length > 0)
24453
+ imports.set(specifier.local.name, optionsPath);
24454
+ }
24455
+ }
24456
+ return imports;
24457
+ }
24458
+ function defaultExportWrapper(ast, bindings) {
24459
+ const exported = ast.program.body.find((stmt) => stmt.type === "ExportDefaultDeclaration");
24460
+ const declaration = exported?.type === "ExportDefaultDeclaration" ? resolveExpression2(exported.declaration, bindings) : null;
24461
+ if (declaration?.type !== "CallExpression")
24462
+ return "astro";
24463
+ const callee = withoutTypeWrappers(declaration.callee);
24464
+ if (callee.type !== "Identifier")
24465
+ return "unknown";
24466
+ for (const stmt of ast.program.body) {
24467
+ if (stmt.type !== "ImportDeclaration" || !stmt.specifiers.some((specifier) => specifier.local.name === callee.name))
24468
+ continue;
24469
+ if (stmt.source.value === "@nuasite/nua/config")
24470
+ return "nua";
24471
+ if (stmt.source.value === "astro/config")
24472
+ return "astro";
24473
+ }
24474
+ return "unknown";
24475
+ }
24476
+ function nuaCmsInstance(cms, bindings) {
24477
+ if (cms?.type === "BooleanLiteral" && !cms.value)
24478
+ return;
24479
+ return cms?.type === "ObjectExpression" ? objectAtPath(cms, ["cmsConfig"], bindings) : null;
24480
+ }
24481
+ function wrapperCmsInstance(ast, configObject, bindings) {
24482
+ const wrapper = defaultExportWrapper(ast, bindings);
24483
+ if (wrapper === "astro")
24484
+ return;
24485
+ const nua = objectPropertyValue(configObject, "nua", bindings);
24486
+ const cms = nua?.type === "ObjectExpression" ? objectPropertyValue(nua, "cms", bindings) : null;
24487
+ if (wrapper === "unknown") {
24488
+ return cms?.type === "ObjectExpression" ? nuaCmsInstance(cms, bindings) : undefined;
24489
+ }
24490
+ if (nua?.type === "BooleanLiteral" && !nua.value)
24491
+ return;
24492
+ return nuaCmsInstance(cms, bindings);
24493
+ }
24494
+ function effectiveCmsConfig(ast, configObject, bindings) {
24495
+ let fromNua = wrapperCmsInstance(ast, configObject, bindings);
24496
+ let fromCms;
24497
+ const integrations = objectPropertyValue(configObject, "integrations", bindings);
24498
+ const integrationImports = collectCmsIntegrationImports(ast);
24499
+ for (const element of integrations?.type === "ArrayExpression" ? integrations.elements : []) {
24500
+ if (!element || element.type === "SpreadElement")
24501
+ continue;
24502
+ const call = resolveExpression2(element, bindings);
24503
+ const callee = call.type === "CallExpression" ? withoutTypeWrappers(call.callee) : null;
24504
+ if (call.type !== "CallExpression" || callee?.type !== "Identifier")
24505
+ continue;
24506
+ const optionsPath = integrationImports.get(callee.name);
24507
+ if (!optionsPath)
24508
+ continue;
24509
+ const firstArg = call.arguments[0];
24510
+ const options = firstArg && firstArg.type !== "SpreadElement" ? resolveExpression2(firstArg, bindings) : null;
24511
+ const optionsObject = options?.type === "ObjectExpression" ? options : null;
24512
+ if (optionsPath.length === 0) {
24513
+ fromCms = optionsObject && objectAtPath(optionsObject, ["cmsConfig"], bindings);
24514
+ } else if (fromNua === undefined) {
24515
+ fromNua = nuaCmsInstance(optionsObject && objectPropertyValue(optionsObject, "cms", bindings), bindings);
24516
+ }
24517
+ }
24518
+ return fromNua !== undefined ? fromNua : fromCms ?? null;
24519
+ }
24520
+ function parseConfigListStyles(cmsConfig, bindings) {
24521
+ const listStylesNode = cmsConfig ? objectPropertyValue(cmsConfig, "listStyles", bindings) : null;
24522
+ return listStylesNode?.type === "ArrayExpression" ? parseListStyles(listStylesNode, bindings) : [];
24523
+ }
24524
+ function staticStringOf(object, key, bindings) {
24525
+ const node = object ? objectPropertyValue(object, key, bindings) : null;
24526
+ return node && staticString2(node, bindings) || undefined;
24527
+ }
24528
+ function parseLocale(cmsConfig, configObject, bindings) {
24529
+ return staticStringOf(cmsConfig, "locale", bindings) ?? staticStringOf(objectAtPath(configObject, ["i18n"], bindings), "defaultLocale", bindings);
24530
+ }
24531
+ function parseProjectCmsConfigSource(source) {
24532
+ const ast = parseSource2(source);
24533
+ if (!ast)
24534
+ return EMPTY_CONFIG;
24535
+ const bindings = collectBindings2(ast);
24536
+ const configObject = configObjectFromDefaultExport(ast, bindings);
24537
+ if (!configObject)
24538
+ return EMPTY_CONFIG;
24539
+ const cmsConfig = effectiveCmsConfig(ast, configObject, bindings);
24540
+ const locale = parseLocale(cmsConfig, configObject, bindings);
24541
+ return { listStyles: parseConfigListStyles(cmsConfig, bindings), ...locale ? { locale } : {} };
24542
+ }
24543
+ var ASTRO_CONFIG_FILES = ["astro.config.mjs", "astro.config.js", "astro.config.ts", "astro.config.mts"];
24544
+ async function readAstroConfigSource(fs3) {
24545
+ for (const file of ASTRO_CONFIG_FILES) {
24546
+ try {
24547
+ return await fs3.readFile(file);
24548
+ } catch {
24549
+ continue;
24550
+ }
24551
+ }
24552
+ return null;
24553
+ }
24554
+ async function parseProjectCmsConfig(fs3) {
24555
+ const source = await readAstroConfigSource(fs3);
24556
+ return source === null ? EMPTY_CONFIG : parseProjectCmsConfigSource(source);
24557
+ }
24558
+ async function readAstroSrcDir(fs3) {
24559
+ const source = await readAstroConfigSource(fs3);
24560
+ return source === null ? "src" : astroSrcDirOf(source);
24561
+ }
24562
+ function astroSrcDirOf(source) {
24563
+ const roots = configOptionMentions(source, "root");
24564
+ const srcDirs = configOptionMentions(source, "srcDir");
24565
+ if (roots === null || srcDirs === null)
24566
+ return null;
24567
+ if (roots.some((root) => root === null || normalizeBasePath(root) !== "."))
24568
+ return null;
24569
+ if (srcDirs.length === 0)
24570
+ return "src";
24571
+ const [srcDir, ...others] = srcDirs.map((literal) => literal === null ? null : normalizeBasePath(literal));
24572
+ if (srcDir === null || srcDir === undefined || others.some((other) => other !== srcDir))
24573
+ return null;
24574
+ return path4.isAbsolute(srcDir) || srcDir.startsWith("..") ? null : srcDir;
24575
+ }
24298
24576
  // ../cms-core/src/collection-scanner.ts
24299
24577
  var import_yaml2 = __toESM(require_dist(), 1);
24300
- import path3 from "path";
24578
+ import path5 from "path";
24301
24579
  var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}/;
24302
24580
  var URL_PATTERN = /^(https?:\/\/|\/)/;
24303
24581
  var IMAGE_EXTENSIONS = /\.(jpg|jpeg|png|gif|webp|svg|avif)$/i;
@@ -24570,7 +24848,7 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
24570
24848
  return {
24571
24849
  name: collectionName,
24572
24850
  label,
24573
- path: path3.join(contentDir, collectionName),
24851
+ path: path5.join(contentDir, collectionName),
24574
24852
  entryCount,
24575
24853
  fields,
24576
24854
  fileExtension: "md",
@@ -24579,10 +24857,10 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
24579
24857
  };
24580
24858
  }
24581
24859
  function getCollectionSourceBasePath(basePath, collectionName, contentDir) {
24582
- const defaultCollectionPath = path3.join(contentDir, collectionName);
24860
+ const defaultCollectionPath = path5.join(contentDir, collectionName);
24583
24861
  const normalizedBasePath = normalizeBasePath(basePath);
24584
- if (normalizedBasePath === path3.normalize(defaultCollectionPath)) {
24585
- return path3.join(contentDir, collectionName);
24862
+ if (normalizedBasePath === path5.normalize(defaultCollectionPath)) {
24863
+ return path5.join(contentDir, collectionName);
24586
24864
  }
24587
24865
  return normalizedBasePath;
24588
24866
  }
@@ -24596,13 +24874,13 @@ async function buildCollectionDefinition(fs3, basePath, sources, collectionName,
24596
24874
  const allDirectives = {};
24597
24875
  const entryInfos = [];
24598
24876
  let hasDraft = false;
24599
- const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path3.join(basePath, s.relPath)).catch(() => null)));
24877
+ const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path5.join(basePath, s.relPath)).catch(() => null)));
24600
24878
  for (let i = 0;i < sources.length; i++) {
24601
24879
  const source = sources[i];
24602
24880
  const content = fileContents[i];
24603
24881
  if (content === null)
24604
24882
  continue;
24605
- const parsed = parseFrontmatter(content, path3.join(basePath, source.relPath), frontmatterMemo);
24883
+ const parsed = parseFrontmatter(content, path5.join(basePath, source.relPath), frontmatterMemo);
24606
24884
  const frontmatter = parsed?.data ?? null;
24607
24885
  for (const [key, value] of Object.entries(parsed?.directives ?? {})) {
24608
24886
  if (!allDirectives[key]) {
@@ -24611,7 +24889,7 @@ async function buildCollectionDefinition(fs3, basePath, sources, collectionName,
24611
24889
  }
24612
24890
  const entryInfo = {
24613
24891
  slug: source.slug,
24614
- sourcePath: path3.join(sourceBasePath, source.relPath)
24892
+ sourcePath: path5.join(sourceBasePath, source.relPath)
24615
24893
  };
24616
24894
  if (frontmatter) {
24617
24895
  const title = deriveEntryTitle(frontmatter);
@@ -24645,7 +24923,7 @@ async function buildDataCollectionDefinition(fs3, basePath, sources, collectionN
24645
24923
  const fieldMap = new Map;
24646
24924
  const entryInfos = [];
24647
24925
  const ext = sources.some((s) => s.relPath.endsWith(".json")) ? "json" : sources.some((s) => s.relPath.endsWith(".yaml")) ? "yaml" : "yml";
24648
- const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path3.join(basePath, s.relPath)).catch(() => null)));
24926
+ const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path5.join(basePath, s.relPath)).catch(() => null)));
24649
24927
  for (let i = 0;i < sources.length; i++) {
24650
24928
  const source = sources[i];
24651
24929
  const raw = fileContents[i];
@@ -24663,7 +24941,7 @@ async function buildDataCollectionDefinition(fs3, basePath, sources, collectionN
24663
24941
  entryInfos.push({
24664
24942
  slug: source.slug,
24665
24943
  title,
24666
- sourcePath: path3.join(sourceBasePath, source.relPath),
24944
+ sourcePath: path5.join(sourceBasePath, source.relPath),
24667
24945
  data
24668
24946
  });
24669
24947
  collectFieldObservations(fieldMap, data, sources.length);
@@ -24694,8 +24972,8 @@ async function scanCollection(fs3, collectionPath, collectionName, contentDir, f
24694
24972
  if (takenSlugs.has(dir.name))
24695
24973
  return null;
24696
24974
  for (const ext of ["md", "mdx"]) {
24697
- const relPath = path3.join(dir.name, `index.${ext}`);
24698
- if (await fs3.exists(path3.join(collectionPath, relPath))) {
24975
+ const relPath = path5.join(dir.name, `index.${ext}`);
24976
+ if (await fs3.exists(path5.join(collectionPath, relPath))) {
24699
24977
  return { slug: dir.name, relPath };
24700
24978
  }
24701
24979
  }
@@ -24711,8 +24989,8 @@ async function scanCollection(fs3, collectionPath, collectionName, contentDir, f
24711
24989
  }
24712
24990
  async function globLoaderFiles(fs3, baseRel, pattern, options) {
24713
24991
  const isPrivate = (relToBase) => relToBase.split("/").some((seg) => seg.startsWith("_") || seg.startsWith("."));
24714
- const matches = await fs3.glob(path3.join(baseRel, pattern), { ...options, skipDirectory: (dir) => isPrivate(path3.relative(baseRel, dir)) });
24715
- return matches.map((rel) => path3.relative(baseRel, rel)).filter((relToBase) => !isPrivate(relToBase));
24992
+ const matches = await fs3.glob(path5.join(baseRel, pattern), { ...options, skipDirectory: (dir) => isPrivate(path5.relative(baseRel, dir)) });
24993
+ return matches.map((rel) => path5.relative(baseRel, rel)).filter((relToBase) => !isPrivate(relToBase));
24716
24994
  }
24717
24995
  async function scanGlobCollection(fs3, collectionName, baseRel, pattern, contentDir, frontmatterMemo) {
24718
24996
  const rels = await globLoaderFiles(fs3, baseRel, pattern);
@@ -25081,8 +25359,8 @@ async function scanDataCollection(fs3, collectionPath, collectionName, contentDi
25081
25359
  if (takenSlugs.has(dir.name))
25082
25360
  return null;
25083
25361
  for (const indexExt of ["json", "yaml", "yml"]) {
25084
- const relPath = path3.join(dir.name, `index.${indexExt}`);
25085
- if (await fs3.exists(path3.join(collectionPath, relPath))) {
25362
+ const relPath = path5.join(dir.name, `index.${indexExt}`);
25363
+ if (await fs3.exists(path5.join(collectionPath, relPath))) {
25086
25364
  return { slug: dir.name, relPath };
25087
25365
  }
25088
25366
  }
@@ -25094,9 +25372,6 @@ async function scanDataCollection(fs3, collectionPath, collectionName, contentDi
25094
25372
  }
25095
25373
  return await buildDataCollectionDefinition(fs3, collectionPath, sources, collectionName, contentDir);
25096
25374
  }
25097
- function normalizeBasePath(basePath) {
25098
- return path3.normalize(basePath.replace(/^\.[/\\]+/, "")).replace(/[/\\]+$/, "");
25099
- }
25100
25375
  var WHOLE_DIRECTORY_PATTERN = /^(?:\*\*[/\\])*\*(?:\.(?:\{([^{}/\\]*)\}|([A-Za-z0-9]+)))?$/;
25101
25376
  function patternCoversWholeCollection(pattern, definition) {
25102
25377
  const match = pattern.trim().replace(/^\.[/\\]+/, "").match(WHOLE_DIRECTORY_PATTERN);
@@ -25106,7 +25381,7 @@ function patternCoversWholeCollection(pattern, definition) {
25106
25381
  if (braceGroup === undefined && singleExtension === undefined)
25107
25382
  return true;
25108
25383
  const patternExtensions = new Set((braceGroup !== undefined ? braceGroup.split(",") : [singleExtension]).map((ext) => ext.trim().replace(/^\./, "").toLowerCase()).filter(Boolean));
25109
- const scannedExtensions = new Set((definition.entries ?? []).map((entry) => path3.extname(entry.sourcePath).slice(1).toLowerCase()).filter(Boolean));
25384
+ const scannedExtensions = new Set((definition.entries ?? []).map((entry) => path5.extname(entry.sourcePath).slice(1).toLowerCase()).filter(Boolean));
25110
25385
  if (scannedExtensions.size === 0)
25111
25386
  return false;
25112
25387
  for (const ext of scannedExtensions) {
@@ -25122,14 +25397,14 @@ async function scanCollections(fs3, contentDir = "src/content", parseCache = new
25122
25397
  const entries = await fs3.list(contentDir);
25123
25398
  const scanPromises = entries.filter((entry) => entry.isDirectory && !entry.name.startsWith("_") && !entry.name.startsWith(".")).map(async (entry) => {
25124
25399
  try {
25125
- const collectionPath = path3.join(contentDir, entry.name);
25400
+ const collectionPath = path5.join(contentDir, entry.name);
25126
25401
  const definition = await scanCollection(fs3, collectionPath, entry.name, contentDir, frontmatterMemo) ?? await scanDataCollection(fs3, collectionPath, entry.name, contentDir);
25127
25402
  if (definition) {
25128
25403
  collections[entry.name] = definition;
25129
25404
  }
25130
25405
  } catch (error) {
25131
25406
  console.warn(`[cms] Skipping collection "${entry.name}" \u2014 scan failed:`, error);
25132
- failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base: path3.join(contentDir, entry.name) });
25407
+ failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base: path5.join(contentDir, entry.name) });
25133
25408
  }
25134
25409
  });
25135
25410
  await Promise.all(scanPromises);
@@ -25214,7 +25489,7 @@ function readsAsRelativeDirectory(base) {
25214
25489
  return false;
25215
25490
  try {
25216
25491
  const asUrl = decodeURIComponent(new URL(base, "file:///project-root/").pathname).replace(/\/{2,}/g, "/").replace(/\/+$/, "");
25217
- const asPath = normalizeBasePath(base).split(path3.sep).join("/");
25492
+ const asPath = normalizeBasePath(base).split(path5.sep).join("/");
25218
25493
  return asUrl === (asPath === "." ? "/project-root" : `/project-root/${asPath}`);
25219
25494
  } catch {
25220
25495
  return false;
@@ -25223,7 +25498,7 @@ function readsAsRelativeDirectory(base) {
25223
25498
  function declaredLocation(declaration, contentDir) {
25224
25499
  const location = {};
25225
25500
  if (declaration.noLoader)
25226
- location.base = path3.join(contentDir, declaration.name);
25501
+ location.base = path5.join(contentDir, declaration.name);
25227
25502
  if (declaration.loaderBase !== undefined)
25228
25503
  location.base = normalizeBasePath(declaration.loaderBase);
25229
25504
  if (declaration.loaderPattern !== undefined)
@@ -25234,13 +25509,13 @@ function declaredLocation(declaration, contentDir) {
25234
25509
  }
25235
25510
  async function contentDirectoryFiles(fs3, directory, entryFile) {
25236
25511
  const files = await globLoaderFiles(fs3, directory, "**/*", { followSymlinks: true, maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT });
25237
- return files.filter((file) => entryFile.test(file)).map((file) => path3.join(directory, file));
25512
+ return files.filter((file) => entryFile.test(file)).map((file) => path5.join(directory, file));
25238
25513
  }
25239
25514
  async function declaredEntryFiles(fs3, contentDir, declaration) {
25240
25515
  if (declaration.noLoader) {
25241
25516
  if (!readsAsRelativeDirectory(declaration.name))
25242
25517
  return null;
25243
- return { exact: true, files: await contentDirectoryFiles(fs3, path3.join(contentDir, declaration.name), ENTRY_FILE) };
25518
+ return { exact: true, files: await contentDirectoryFiles(fs3, path5.join(contentDir, declaration.name), ENTRY_FILE) };
25244
25519
  }
25245
25520
  const declaredBase = declaration.loaderBase;
25246
25521
  if (declaredBase === undefined || !readsAsRelativeDirectory(declaredBase))
@@ -25250,14 +25525,14 @@ async function declaredEntryFiles(fs3, contentDir, declaration) {
25250
25525
  const patterns = pattern !== undefined ? [pattern] : declaration.loaderPatterns;
25251
25526
  if (patterns === undefined)
25252
25527
  return null;
25253
- const exact = pattern !== undefined && !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(path3.posix.normalize(pattern));
25528
+ const exact = pattern !== undefined && !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(path5.posix.normalize(pattern));
25254
25529
  if (!exact && (base === "." || patterns.some((one) => LEAVES_THE_BASE.test(one))))
25255
25530
  return null;
25256
- const matches = await fs3.glob(path3.join(base, exact ? pattern : "**/*"), {
25531
+ const matches = await fs3.glob(path5.join(base, exact ? pattern : "**/*"), {
25257
25532
  followSymlinks: true,
25258
25533
  maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT
25259
25534
  });
25260
- const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one, path3.relative(base, file))));
25535
+ const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one, path5.relative(base, file))));
25261
25536
  return { exact, files };
25262
25537
  }
25263
25538
  function mayTakeDotPath(pattern, file) {
@@ -25273,37 +25548,14 @@ function mayTakeDotPath(pattern, file) {
25273
25548
  const takesDot = (part) => /[[(]/.test(blurred ? pattern : part);
25274
25549
  return (!dotFile || takesDot(pattern.slice(cut + 1))) && (!dotDirectory || takesDot(pattern.slice(0, Math.max(cut, 0))));
25275
25550
  }
25276
- var ASTRO_CONFIG_PATHS = ["astro.config.mjs", "astro.config.js", "astro.config.ts", "astro.config.mts"];
25277
- async function customSrcDir(fs3) {
25278
- for (const configPath of ASTRO_CONFIG_PATHS) {
25279
- const source = await fs3.readFile(configPath).catch(() => null);
25280
- if (source === null)
25281
- continue;
25282
- const roots = configOptionMentions(source, "root");
25283
- const srcDirs = configOptionMentions(source, "srcDir");
25284
- if (roots === null || srcDirs === null)
25285
- return null;
25286
- if (roots.some((root) => root === null || normalizeBasePath(root) !== "."))
25287
- return null;
25288
- if (srcDirs.length === 0)
25289
- return;
25290
- const [srcDir, ...others] = srcDirs.map((literal) => literal === null ? null : normalizeBasePath(literal));
25291
- if (srcDir === null || srcDir === undefined || others.some((other) => other !== srcDir))
25292
- return null;
25293
- if (srcDir === "src")
25294
- return;
25295
- return path3.isAbsolute(srcDir) || srcDir.startsWith("..") ? null : srcDir;
25296
- }
25297
- return;
25298
- }
25299
25551
  async function contentConfigStatus(fs3, config) {
25300
25552
  const configPaths = [...CONTENT_CONFIG_PATHS, ...UNREAD_CONTENT_CONFIG_PATHS];
25301
- const srcDir = await customSrcDir(fs3);
25553
+ const srcDir = await readAstroSrcDir(fs3);
25302
25554
  if (srcDir === null)
25303
25555
  return "unreadable";
25304
- if (srcDir !== undefined) {
25556
+ if (srcDir !== "src") {
25305
25557
  for (const configPath of configPaths) {
25306
- if (await fs3.exists(path3.join(srcDir, path3.relative("src", configPath))))
25558
+ if (await fs3.exists(path5.join(srcDir, path5.relative("src", configPath))))
25307
25559
  return "unreadable";
25308
25560
  }
25309
25561
  }
@@ -25327,7 +25579,7 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25327
25579
  const listed = new Set;
25328
25580
  for (const definition of Object.values(collections)) {
25329
25581
  for (const entry of definition.entries ?? [])
25330
- listed.add(path3.normalize(entry.sourcePath));
25582
+ listed.add(path5.normalize(entry.sourcePath));
25331
25583
  if ((definition.entries?.length ?? 0) >= definition.entryCount)
25332
25584
  continue;
25333
25585
  const declaration = declaredByName.get(definition.name);
@@ -25357,7 +25609,7 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25357
25609
  }
25358
25610
  if (loads === null) {
25359
25611
  unresolved.set(name, { name, reason: "unsupported-loader", ...location });
25360
- } else if (!loads.files.every((file) => listed.has(path3.normalize(file)))) {
25612
+ } else if (!loads.files.every((file) => listed.has(path5.normalize(file)))) {
25361
25613
  unresolved.set(name, { name, reason: loads.exact ? "unlisted-entries" : "unsupported-loader", ...location });
25362
25614
  }
25363
25615
  }
@@ -25366,11 +25618,11 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25366
25618
  for (const name of contentDirectories) {
25367
25619
  if (declaredByName.has(name) || unresolved.has(name) || failedScans.has(name))
25368
25620
  continue;
25369
- const directory = path3.join(contentDir, name);
25621
+ const directory = path5.join(contentDir, name);
25370
25622
  const files = await contentDirectoryFiles(fs3, directory, MARKDOWN_FILE).catch(() => null);
25371
25623
  if (files === null)
25372
25624
  unresolved.set(name, { name, reason: "scan-failed", base: directory });
25373
- else if (!files.every((file) => listed.has(path3.normalize(file))))
25625
+ else if (!files.every((file) => listed.has(path5.normalize(file))))
25374
25626
  unresolved.set(name, { name, reason: "unlisted-entries", base: directory });
25375
25627
  }
25376
25628
  }
@@ -25405,8 +25657,8 @@ function warnOnPathnameCollisions(collections) {
25405
25657
  }
25406
25658
  }
25407
25659
  // ../cms-core/src/component-registry.ts
25408
- var import_parser4 = __toESM(require_lib(), 1);
25409
- import path4 from "path";
25660
+ var import_parser5 = __toESM(require_lib(), 1);
25661
+ import path6 from "path";
25410
25662
  async function scanComponentDefinitions(fs3, componentDirs = ["src/components"]) {
25411
25663
  const components = {};
25412
25664
  for (const dir of componentDirs) {
@@ -25427,7 +25679,7 @@ async function scanDirectory(fs3, relativePath, components) {
25427
25679
  }
25428
25680
  async function parseComponent(fs3, relativePath, components) {
25429
25681
  const content = await fs3.readFile(relativePath);
25430
- const componentName = path4.basename(relativePath, ".astro");
25682
+ const componentName = path6.basename(relativePath, ".astro");
25431
25683
  const props = extractProps(content);
25432
25684
  const slots = extractSlots(content);
25433
25685
  const description = extractDescription(content);
@@ -25448,7 +25700,7 @@ ${propsContent}
25448
25700
  }`;
25449
25701
  let ast;
25450
25702
  try {
25451
- ast = import_parser4.parse(synthetic, {
25703
+ ast = import_parser5.parse(synthetic, {
25452
25704
  sourceType: "module",
25453
25705
  plugins: ["typescript"],
25454
25706
  errorRecovery: true
@@ -25665,9 +25917,9 @@ class CmsCommitConflictError extends Error {
25665
25917
  function digestBytes(content) {
25666
25918
  return `sha256:${createHash("sha256").update(content).digest("hex")}`;
25667
25919
  }
25668
- function normalize(path5) {
25920
+ function normalize(path7) {
25669
25921
  const segments = [];
25670
- for (const segment of path5.split("/")) {
25922
+ for (const segment of path7.split("/")) {
25671
25923
  if (segment === "" || segment === ".")
25672
25924
  continue;
25673
25925
  if (segment === ".." && segments.length > 0 && segments.at(-1) !== "..")
@@ -25677,67 +25929,67 @@ function normalize(path5) {
25677
25929
  }
25678
25930
  return segments.join("/");
25679
25931
  }
25680
- function isBelow(path5, dir) {
25681
- return dir === "" || path5.startsWith(`${dir}/`);
25932
+ function isBelow(path7, dir) {
25933
+ return dir === "" || path7.startsWith(`${dir}/`);
25682
25934
  }
25683
- function missing(path5) {
25684
- return Object.assign(new Error(`ENOENT: no such file, '${path5}'`), { code: "ENOENT" });
25935
+ function missing(path7) {
25936
+ return Object.assign(new Error(`ENOENT: no such file, '${path7}'`), { code: "ENOENT" });
25685
25937
  }
25686
25938
  function createStagedFileSystem(base) {
25687
25939
  const reads = new Map;
25688
25940
  const staged = new Map;
25689
25941
  const encoder = new TextEncoder;
25690
25942
  const decoder = new TextDecoder;
25691
- function observe(path5, version) {
25692
- const recorded = reads.get(path5);
25943
+ function observe(path7, version) {
25944
+ const recorded = reads.get(path7);
25693
25945
  if (recorded === undefined || recorded.kind === "present" && version.kind === "content")
25694
- reads.set(path5, version);
25946
+ reads.set(path7, version);
25695
25947
  }
25696
- async function observeBeforeChange(path5) {
25697
- if (staged.has(path5))
25948
+ async function observeBeforeChange(path7) {
25949
+ if (staged.has(path7))
25698
25950
  return;
25699
- const recorded = reads.get(path5);
25951
+ const recorded = reads.get(path7);
25700
25952
  if (recorded !== undefined && recorded.kind !== "present")
25701
25953
  return;
25702
- observe(path5, await versionOf(base, path5));
25954
+ observe(path7, await versionOf(base, path7));
25703
25955
  }
25704
25956
  async function readBytes(rawPath) {
25705
- const path5 = normalize(rawPath);
25706
- const change = staged.get(path5);
25957
+ const path7 = normalize(rawPath);
25958
+ const change = staged.get(path7);
25707
25959
  if (change === null)
25708
- throw missing(path5);
25960
+ throw missing(path7);
25709
25961
  if (change !== undefined)
25710
25962
  return change.content.slice();
25711
25963
  try {
25712
- const content = await base.readBytes(path5);
25713
- observe(path5, { kind: "content", digest: digestBytes(content) });
25964
+ const content = await base.readBytes(path7);
25965
+ observe(path7, { kind: "content", digest: digestBytes(content) });
25714
25966
  return content;
25715
25967
  } catch (error) {
25716
- if (!await base.exists(path5))
25717
- observe(path5, { kind: "absent" });
25968
+ if (!await base.exists(path7))
25969
+ observe(path7, { kind: "absent" });
25718
25970
  throw error;
25719
25971
  }
25720
25972
  }
25721
25973
  async function write(rawPath, content) {
25722
- const path5 = normalize(rawPath);
25723
- await observeBeforeChange(path5);
25724
- staged.set(path5, { content: content.slice(), mtimeMs: Date.now() });
25974
+ const path7 = normalize(rawPath);
25975
+ await observeBeforeChange(path7);
25976
+ staged.set(path7, { content: content.slice(), mtimeMs: Date.now() });
25725
25977
  }
25726
25978
  async function remove(rawPath) {
25727
- const path5 = normalize(rawPath);
25728
- await observeBeforeChange(path5);
25729
- staged.set(path5, null);
25979
+ const path7 = normalize(rawPath);
25980
+ await observeBeforeChange(path7);
25981
+ staged.set(path7, null);
25730
25982
  }
25731
25983
  function stagedBelow(dir) {
25732
- return [...staged].filter(([path5, change]) => change !== null && isBelow(path5, dir)).map(([path5]) => path5);
25984
+ return [...staged].filter(([path7, change]) => change !== null && isBelow(path7, dir)).map(([path7]) => path7);
25733
25985
  }
25734
25986
  return {
25735
- async readFile(path5) {
25736
- return decoder.decode(await readBytes(path5));
25987
+ async readFile(path7) {
25988
+ return decoder.decode(await readBytes(path7));
25737
25989
  },
25738
25990
  readBytes,
25739
- writeFile(path5, content) {
25740
- return write(path5, encoder.encode(content));
25991
+ writeFile(path7, content) {
25992
+ return write(path7, encoder.encode(content));
25741
25993
  },
25742
25994
  writeBytes: write,
25743
25995
  async rename(from, to) {
@@ -25747,23 +25999,23 @@ function createStagedFileSystem(base) {
25747
25999
  },
25748
26000
  remove,
25749
26001
  async exists(rawPath) {
25750
- const path5 = normalize(rawPath);
25751
- const change = staged.get(path5);
26002
+ const path7 = normalize(rawPath);
26003
+ const change = staged.get(path7);
25752
26004
  if (change !== undefined)
25753
26005
  return change !== null;
25754
- if (stagedBelow(path5).length > 0)
26006
+ if (stagedBelow(path7).length > 0)
25755
26007
  return true;
25756
- const exists = await base.exists(path5);
25757
- observe(path5, exists ? { kind: "present" } : { kind: "absent" });
26008
+ const exists = await base.exists(path7);
26009
+ observe(path7, exists ? { kind: "present" } : { kind: "absent" });
25758
26010
  return exists;
25759
26011
  },
25760
26012
  async list(rawDir) {
25761
26013
  const dir = normalize(rawDir);
25762
26014
  const entries = new Map((await base.list(dir)).map((entry) => [entry.name, entry.isDirectory]));
25763
- for (const [path5, change] of staged) {
25764
- if (!isBelow(path5, dir))
26015
+ for (const [path7, change] of staged) {
26016
+ if (!isBelow(path7, dir))
25765
26017
  continue;
25766
- const rest = dir === "" ? path5 : path5.slice(dir.length + 1);
26018
+ const rest = dir === "" ? path7 : path7.slice(dir.length + 1);
25767
26019
  const [name, ...deeper] = rest.split("/");
25768
26020
  if (name === undefined)
25769
26021
  continue;
@@ -25781,36 +26033,36 @@ function createStagedFileSystem(base) {
25781
26033
  async glob(pattern, options) {
25782
26034
  const matcher = globToRegExp(pattern);
25783
26035
  const files = new Set(await base.glob(pattern, options));
25784
- for (const [path5, change] of staged) {
26036
+ for (const [path7, change] of staged) {
25785
26037
  if (change === null)
25786
- files.delete(path5);
25787
- else if (matcher.test(path5))
25788
- files.add(path5);
26038
+ files.delete(path7);
26039
+ else if (matcher.test(path7))
26040
+ files.add(path7);
25789
26041
  }
25790
26042
  return [...files];
25791
26043
  },
25792
26044
  async stat(rawPath) {
25793
- const path5 = normalize(rawPath);
25794
- const change = staged.get(path5);
26045
+ const path7 = normalize(rawPath);
26046
+ const change = staged.get(path7);
25795
26047
  if (change === null)
25796
- throw missing(path5);
26048
+ throw missing(path7);
25797
26049
  if (change !== undefined)
25798
26050
  return { mtimeMs: change.mtimeMs, size: change.content.byteLength };
25799
- const stat = await base.stat(path5);
25800
- observe(path5, { kind: "present" });
26051
+ const stat = await base.stat(path7);
26052
+ observe(path7, { kind: "present" });
25801
26053
  return stat;
25802
26054
  },
25803
26055
  changeset() {
25804
- const changes = [...staged].map(([path5, change]) => change === null ? { kind: "remove", path: path5 } : { kind: "write", path: path5, content: change.content });
26056
+ const changes = [...staged].map(([path7, change]) => change === null ? { kind: "remove", path: path7 } : { kind: "write", path: path7, content: change.content });
25805
26057
  return { reads: new Map(reads), changes };
25806
26058
  }
25807
26059
  };
25808
26060
  }
25809
- async function versionOf(fs3, path5) {
25810
- if (!await fs3.exists(path5))
26061
+ async function versionOf(fs3, path7) {
26062
+ if (!await fs3.exists(path7))
25811
26063
  return { kind: "absent" };
25812
26064
  try {
25813
- return { kind: "content", digest: digestBytes(await fs3.readBytes(path5)) };
26065
+ return { kind: "content", digest: digestBytes(await fs3.readBytes(path7)) };
25814
26066
  } catch {
25815
26067
  return { kind: "present" };
25816
26068
  }
@@ -25818,7 +26070,7 @@ async function versionOf(fs3, path5) {
25818
26070
 
25819
26071
  // ../cms-core/src/handlers/entry-ops.ts
25820
26072
  var import_yaml3 = __toESM(require_dist(), 1);
25821
- import path5 from "path";
26073
+ import path7 from "path";
25822
26074
  var MARKDOWN_EXTENSIONS = ["md", "mdx"];
25823
26075
  function fileExtension(filePath) {
25824
26076
  const idx = filePath.lastIndexOf(".");
@@ -25839,12 +26091,12 @@ async function resolveEntryPath(deps, collection, slug) {
25839
26091
  const base = await resolveCollectionDir(deps, collection);
25840
26092
  const flatExts = ["md", "mdx", "json", "yaml", "yml"];
25841
26093
  for (const ext of flatExts) {
25842
- const candidate = path5.posix.join(base, `${slug}.${ext}`);
26094
+ const candidate = path7.posix.join(base, `${slug}.${ext}`);
25843
26095
  if (await deps.fs.exists(candidate))
25844
26096
  return candidate;
25845
26097
  }
25846
26098
  for (const ext of MARKDOWN_EXTENSIONS) {
25847
- const candidate = path5.posix.join(base, slug, `index.${ext}`);
26099
+ const candidate = path7.posix.join(base, slug, `index.${ext}`);
25848
26100
  if (await deps.fs.exists(candidate))
25849
26101
  return candidate;
25850
26102
  }
@@ -26010,7 +26262,7 @@ async function inferLayoutFromExistingEntries(deps, collection) {
26010
26262
  if (flatSlugs.has(dir.name))
26011
26263
  return false;
26012
26264
  for (const ext of MARKDOWN_EXTENSIONS) {
26013
- if (await deps.fs.exists(path5.posix.join(collectionPath, dir.name, `index.${ext}`)))
26265
+ if (await deps.fs.exists(path7.posix.join(collectionPath, dir.name, `index.${ext}`)))
26014
26266
  return true;
26015
26267
  }
26016
26268
  return false;
@@ -26112,7 +26364,7 @@ async function createEntry(deps, input) {
26112
26364
  const isData = ext === "json" || ext === "yaml" || ext === "yml";
26113
26365
  const layout = isData ? "flat" : await detectCollectionMarkdownLayout(deps, collection);
26114
26366
  const collectionDir = await resolveCollectionDir(deps, collection);
26115
- const sourcePath = layout === "index" ? path5.posix.join(collectionDir, normalizedSlug, `index.${ext}`) : path5.posix.join(collectionDir, `${normalizedSlug}.${ext}`);
26367
+ const sourcePath = layout === "index" ? path7.posix.join(collectionDir, normalizedSlug, `index.${ext}`) : path7.posix.join(collectionDir, `${normalizedSlug}.${ext}`);
26116
26368
  let fileContent;
26117
26369
  if (isData) {
26118
26370
  fileContent = ext === "json" ? JSON.stringify({ ...resolved }, null, 2) + `
@@ -26904,7 +27156,7 @@ async function scanDirectory2(fs3, currentDir, baseDir, relativeToRoot, excludeD
26904
27156
  }
26905
27157
  // ../cms-core/src/media/s3.ts
26906
27158
  import { randomUUID as randomUUID2 } from "crypto";
26907
- import path6 from "path";
27159
+ import path8 from "path";
26908
27160
  function normalizeFolder(folder) {
26909
27161
  return (folder ?? "").split("/").filter(Boolean).join("/");
26910
27162
  }
@@ -26971,7 +27223,7 @@ function createS3StorageAdapter(options) {
26971
27223
  id: key,
26972
27224
  url: getUrl(key),
26973
27225
  filename,
26974
- contentType: mimeFromExt(path6.extname(key).toLowerCase()),
27226
+ contentType: mimeFromExt(path8.extname(key).toLowerCase()),
26975
27227
  uploadedAt: obj.LastModified?.toISOString(),
26976
27228
  folder: folder || undefined
26977
27229
  };
@@ -27137,251 +27389,6 @@ async function listFilteredMedia(list, options, maxScanned = MAX_SCANNED) {
27137
27389
  position = next;
27138
27390
  }
27139
27391
  }
27140
- // ../cms-core/src/project-config-ast.ts
27141
- var import_parser5 = __toESM(require_lib(), 1);
27142
- var EMPTY_CONFIG = { listStyles: [] };
27143
- function parseSource2(source) {
27144
- try {
27145
- return import_parser5.parse(source, {
27146
- sourceType: "module",
27147
- plugins: ["typescript"],
27148
- errorRecovery: true
27149
- });
27150
- } catch {
27151
- return null;
27152
- }
27153
- }
27154
- function collectBindings2(ast) {
27155
- const bindings = new Map;
27156
- for (const stmt of ast.program.body) {
27157
- const varDecl = stmt.type === "ExportNamedDeclaration" && stmt.declaration?.type === "VariableDeclaration" ? stmt.declaration : stmt.type === "VariableDeclaration" ? stmt : null;
27158
- if (!varDecl)
27159
- continue;
27160
- for (const decl of varDecl.declarations) {
27161
- if (decl.id.type === "Identifier" && decl.init)
27162
- bindings.set(decl.id.name, decl.init);
27163
- }
27164
- }
27165
- return bindings;
27166
- }
27167
- function withoutTypeWrappers(node) {
27168
- let current = node;
27169
- while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion") {
27170
- current = current.expression;
27171
- }
27172
- return current;
27173
- }
27174
- function resolveExpression2(node, bindings, visited = new Set) {
27175
- let current = withoutTypeWrappers(node);
27176
- while (current.type === "Identifier") {
27177
- if (visited.has(current.name))
27178
- return current;
27179
- visited.add(current.name);
27180
- const next = bindings.get(current.name);
27181
- if (!next)
27182
- return current;
27183
- current = withoutTypeWrappers(next);
27184
- }
27185
- return current;
27186
- }
27187
- function propertyKeyName2(key) {
27188
- if (key.type === "Identifier")
27189
- return key.name;
27190
- if (key.type === "StringLiteral")
27191
- return key.value;
27192
- return null;
27193
- }
27194
- function objectPropertyValue(node, keyName, bindings) {
27195
- for (const prop of node.properties) {
27196
- if (prop.type !== "ObjectProperty")
27197
- continue;
27198
- if (propertyKeyName2(prop.key) !== keyName)
27199
- continue;
27200
- return resolveExpression2(prop.value, bindings);
27201
- }
27202
- return null;
27203
- }
27204
- function objectAtPath(root, keys, bindings) {
27205
- let current = root;
27206
- for (const key of keys) {
27207
- const value = objectPropertyValue(current, key, bindings);
27208
- if (!value || value.type !== "ObjectExpression")
27209
- return null;
27210
- current = value;
27211
- }
27212
- return current;
27213
- }
27214
- function staticString2(node, bindings) {
27215
- const resolved = resolveExpression2(node, bindings);
27216
- if (resolved.type === "StringLiteral")
27217
- return resolved.value;
27218
- if (resolved.type === "TemplateLiteral" && resolved.expressions.length === 0) {
27219
- return resolved.quasis[0]?.value.cooked ?? resolved.quasis[0]?.value.raw;
27220
- }
27221
- return;
27222
- }
27223
- function parseListStyle(node, bindings) {
27224
- const resolved = resolveExpression2(node, bindings);
27225
- if (resolved.type !== "ObjectExpression")
27226
- return null;
27227
- const labelNode = objectPropertyValue(resolved, "label", bindings);
27228
- const classNode = objectPropertyValue(resolved, "class", bindings);
27229
- if (!labelNode || !classNode)
27230
- return null;
27231
- const label = staticString2(labelNode, bindings);
27232
- const className = staticString2(classNode, bindings);
27233
- if (label === undefined || className === undefined)
27234
- return null;
27235
- return { label, class: className };
27236
- }
27237
- function parseListStyles(node, bindings) {
27238
- const styles = [];
27239
- for (const element of node.elements) {
27240
- if (!element || element.type === "SpreadElement")
27241
- continue;
27242
- const style = parseListStyle(element, bindings);
27243
- if (style)
27244
- styles.push(style);
27245
- }
27246
- return styles;
27247
- }
27248
- function configObjectFromDefaultExport(ast, bindings) {
27249
- for (const stmt of ast.program.body) {
27250
- if (stmt.type !== "ExportDefaultDeclaration")
27251
- continue;
27252
- const declaration = resolveExpression2(stmt.declaration, bindings);
27253
- if (declaration.type === "ObjectExpression")
27254
- return declaration;
27255
- if (declaration.type === "CallExpression") {
27256
- const firstArg = declaration.arguments[0];
27257
- if (!firstArg || firstArg.type === "SpreadElement")
27258
- return null;
27259
- const resolvedArg = resolveExpression2(firstArg, bindings);
27260
- if (resolvedArg.type === "ObjectExpression")
27261
- return resolvedArg;
27262
- }
27263
- }
27264
- return null;
27265
- }
27266
- var CMS_INTEGRATION_OPTIONS_PATH = {
27267
- "@nuasite/cms": [],
27268
- "@nuasite/nua": ["cms"],
27269
- "@nuasite/nua/integration": ["cms"]
27270
- };
27271
- function collectCmsIntegrationImports(ast) {
27272
- const imports = new Map;
27273
- for (const stmt of ast.program.body) {
27274
- if (stmt.type !== "ImportDeclaration")
27275
- continue;
27276
- const optionsPath = CMS_INTEGRATION_OPTIONS_PATH[stmt.source.value];
27277
- if (!optionsPath)
27278
- continue;
27279
- for (const specifier of stmt.specifiers) {
27280
- const importedName2 = specifier.type === "ImportDefaultSpecifier" ? "default" : specifier.type === "ImportSpecifier" ? propertyKeyName2(specifier.imported) : null;
27281
- if (importedName2 === "default" || importedName2 === "nua" && optionsPath.length > 0)
27282
- imports.set(specifier.local.name, optionsPath);
27283
- }
27284
- }
27285
- return imports;
27286
- }
27287
- function defaultExportWrapper(ast, bindings) {
27288
- const exported = ast.program.body.find((stmt) => stmt.type === "ExportDefaultDeclaration");
27289
- const declaration = exported?.type === "ExportDefaultDeclaration" ? resolveExpression2(exported.declaration, bindings) : null;
27290
- if (declaration?.type !== "CallExpression")
27291
- return "astro";
27292
- const callee = withoutTypeWrappers(declaration.callee);
27293
- if (callee.type !== "Identifier")
27294
- return "unknown";
27295
- for (const stmt of ast.program.body) {
27296
- if (stmt.type !== "ImportDeclaration" || !stmt.specifiers.some((specifier) => specifier.local.name === callee.name))
27297
- continue;
27298
- if (stmt.source.value === "@nuasite/nua/config")
27299
- return "nua";
27300
- if (stmt.source.value === "astro/config")
27301
- return "astro";
27302
- }
27303
- return "unknown";
27304
- }
27305
- function nuaCmsInstance(cms, bindings) {
27306
- if (cms?.type === "BooleanLiteral" && !cms.value)
27307
- return;
27308
- return cms?.type === "ObjectExpression" ? objectAtPath(cms, ["cmsConfig"], bindings) : null;
27309
- }
27310
- function wrapperCmsInstance(ast, configObject, bindings) {
27311
- const wrapper = defaultExportWrapper(ast, bindings);
27312
- if (wrapper === "astro")
27313
- return;
27314
- const nua = objectPropertyValue(configObject, "nua", bindings);
27315
- const cms = nua?.type === "ObjectExpression" ? objectPropertyValue(nua, "cms", bindings) : null;
27316
- if (wrapper === "unknown") {
27317
- return cms?.type === "ObjectExpression" ? nuaCmsInstance(cms, bindings) : undefined;
27318
- }
27319
- if (nua?.type === "BooleanLiteral" && !nua.value)
27320
- return;
27321
- return nuaCmsInstance(cms, bindings);
27322
- }
27323
- function effectiveCmsConfig(ast, configObject, bindings) {
27324
- let fromNua = wrapperCmsInstance(ast, configObject, bindings);
27325
- let fromCms;
27326
- const integrations = objectPropertyValue(configObject, "integrations", bindings);
27327
- const integrationImports = collectCmsIntegrationImports(ast);
27328
- for (const element of integrations?.type === "ArrayExpression" ? integrations.elements : []) {
27329
- if (!element || element.type === "SpreadElement")
27330
- continue;
27331
- const call = resolveExpression2(element, bindings);
27332
- const callee = call.type === "CallExpression" ? withoutTypeWrappers(call.callee) : null;
27333
- if (call.type !== "CallExpression" || callee?.type !== "Identifier")
27334
- continue;
27335
- const optionsPath = integrationImports.get(callee.name);
27336
- if (!optionsPath)
27337
- continue;
27338
- const firstArg = call.arguments[0];
27339
- const options = firstArg && firstArg.type !== "SpreadElement" ? resolveExpression2(firstArg, bindings) : null;
27340
- const optionsObject = options?.type === "ObjectExpression" ? options : null;
27341
- if (optionsPath.length === 0) {
27342
- fromCms = optionsObject && objectAtPath(optionsObject, ["cmsConfig"], bindings);
27343
- } else if (fromNua === undefined) {
27344
- fromNua = nuaCmsInstance(optionsObject && objectPropertyValue(optionsObject, "cms", bindings), bindings);
27345
- }
27346
- }
27347
- return fromNua !== undefined ? fromNua : fromCms ?? null;
27348
- }
27349
- function parseConfigListStyles(cmsConfig, bindings) {
27350
- const listStylesNode = cmsConfig ? objectPropertyValue(cmsConfig, "listStyles", bindings) : null;
27351
- return listStylesNode?.type === "ArrayExpression" ? parseListStyles(listStylesNode, bindings) : [];
27352
- }
27353
- function staticStringOf(object, key, bindings) {
27354
- const node = object ? objectPropertyValue(object, key, bindings) : null;
27355
- return node && staticString2(node, bindings) || undefined;
27356
- }
27357
- function parseLocale(cmsConfig, configObject, bindings) {
27358
- return staticStringOf(cmsConfig, "locale", bindings) ?? staticStringOf(objectAtPath(configObject, ["i18n"], bindings), "defaultLocale", bindings);
27359
- }
27360
- function parseProjectCmsConfigSource(source) {
27361
- const ast = parseSource2(source);
27362
- if (!ast)
27363
- return EMPTY_CONFIG;
27364
- const bindings = collectBindings2(ast);
27365
- const configObject = configObjectFromDefaultExport(ast, bindings);
27366
- if (!configObject)
27367
- return EMPTY_CONFIG;
27368
- const cmsConfig = effectiveCmsConfig(ast, configObject, bindings);
27369
- const locale = parseLocale(cmsConfig, configObject, bindings);
27370
- return { listStyles: parseConfigListStyles(cmsConfig, bindings), ...locale ? { locale } : {} };
27371
- }
27372
- var ASTRO_CONFIG_FILES = ["astro.config.ts", "astro.config.mts", "astro.config.mjs", "astro.config.js"];
27373
- async function parseProjectCmsConfig(fs3) {
27374
- for (const file of ASTRO_CONFIG_FILES) {
27375
- let source;
27376
- try {
27377
- source = await fs3.readFile(file);
27378
- } catch {
27379
- continue;
27380
- }
27381
- return parseProjectCmsConfigSource(source);
27382
- }
27383
- return EMPTY_CONFIG;
27384
- }
27385
27392
  // ../cms-core/src/route-map.ts
27386
27393
  var ROUTE_MAP_PATH = ".astro/integrations/_nuasite_cms/routes.json";
27387
27394
  var ROUTE_MAP_VERSION = 1;
@@ -27390,10 +27397,10 @@ function normalizeSiteBase(base) {
27390
27397
  return trimmed === "" ? "" : trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
27391
27398
  }
27392
27399
  function sitePathname(pathname, site) {
27393
- const path7 = `${site.base}${pathname === "/" ? "" : pathname.replace(/\/+$/, "")}`;
27394
- if (path7 === "")
27400
+ const path9 = `${site.base}${pathname === "/" ? "" : pathname.replace(/\/+$/, "")}`;
27401
+ if (path9 === "")
27395
27402
  return "/";
27396
- return site.trailingSlash === "always" ? `${path7}/` : path7;
27403
+ return site.trailingSlash === "always" ? `${path9}/` : path9;
27397
27404
  }
27398
27405
  function parseRouteMap(json) {
27399
27406
  let data;
@@ -27453,7 +27460,7 @@ function scanRouteCollections(source) {
27453
27460
  // src/cli.ts
27454
27461
  import fs3 from "fs";
27455
27462
  import { createRequire } from "module";
27456
- import path7 from "path";
27463
+ import path9 from "path";
27457
27464
 
27458
27465
  // src/media-from-env.ts
27459
27466
  var VALID_KINDS = ["contember", "s3", "local", "none"];
@@ -28473,16 +28480,16 @@ function createServer(opts) {
28473
28480
  function resolveCoreVersion() {
28474
28481
  try {
28475
28482
  const require2 = createRequire(import.meta.url);
28476
- let dir = path7.dirname(require2.resolve("@nuasite/cms-core"));
28483
+ let dir = path9.dirname(require2.resolve("@nuasite/cms-core"));
28477
28484
  for (;; ) {
28478
- const pkgPath = path7.join(dir, "package.json");
28485
+ const pkgPath = path9.join(dir, "package.json");
28479
28486
  if (fs3.existsSync(pkgPath)) {
28480
28487
  const parsed = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
28481
28488
  if (parsed && typeof parsed === "object" && "name" in parsed && parsed.name === "@nuasite/cms-core" && "version" in parsed && typeof parsed.version === "string") {
28482
28489
  return parsed.version;
28483
28490
  }
28484
28491
  }
28485
- const parent = path7.dirname(dir);
28492
+ const parent = path9.dirname(dir);
28486
28493
  if (parent === dir)
28487
28494
  break;
28488
28495
  dir = parent;
@@ -28508,7 +28515,7 @@ function parseServeArgs(args) {
28508
28515
  throw new Error("serve requires a valid --port <0-65535>");
28509
28516
  }
28510
28517
  const rawRoot = readFlag(args, "root");
28511
- const root = path7.resolve(rawRoot ?? process.cwd());
28518
+ const root = path9.resolve(rawRoot ?? process.cwd());
28512
28519
  const contentDir = readFlag(args, "content-dir");
28513
28520
  return { port, root, contentDir };
28514
28521
  }