@nuasite/cms-sidecar 0.70.3 → 0.70.5

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,7 +23202,6 @@ 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
23205
  var ASTRO_CONTENT_CONFIG_ORDER = [
23207
23206
  "src/content.config.mjs",
23208
23207
  "src/content.config.js",
@@ -23213,55 +23212,47 @@ var ASTRO_CONTENT_CONFIG_ORDER = [
23213
23212
  "src/content/config.mjs",
23214
23213
  "src/content/config.mts"
23215
23214
  ];
23215
+ var CONTENT_CONFIG_PATHS = ASTRO_CONTENT_CONFIG_ORDER.filter((configPath) => configPath.endsWith(".ts"));
23216
23216
  var READ_CONTENT_CONFIG_PATHS = new Set(CONTENT_CONFIG_PATHS);
23217
23217
  var UNREAD_CONTENT_CONFIG_PATHS = ASTRO_CONTENT_CONFIG_ORDER.filter((configPath) => !READ_CONTENT_CONFIG_PATHS.has(configPath));
23218
- async function findLoadedContentConfig(fs3) {
23218
+ var inSrcDir = (configPath, srcDir) => `${srcDir}${configPath.slice("src".length)}`;
23219
+ async function findLoadedContentConfig(fs3, srcDir = "src") {
23219
23220
  for (const configPath of ASTRO_CONTENT_CONFIG_ORDER) {
23220
- if (await fs3.exists(configPath))
23221
- return configPath;
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/") };
23222
23224
  }
23223
23225
  return null;
23224
23226
  }
23225
- var isReadContentConfig = (configPath) => READ_CONTENT_CONFIG_PATHS.has(configPath);
23226
- async function classifyEmptyContentConfig(fs3) {
23227
- const loaded = await findLoadedContentConfig(fs3);
23227
+ async function classifyEmptyContentConfig(fs3, srcDir = "src") {
23228
+ const loaded = await findLoadedContentConfig(fs3, srcDir);
23228
23229
  if (loaded === null)
23229
23230
  return "missing";
23230
- if (!isReadContentConfig(loaded))
23231
+ if (!loaded.read)
23231
23232
  return "unread";
23232
- for (const configPath of CONTENT_CONFIG_PATHS) {
23233
- if (!await fs3.exists(configPath))
23234
- continue;
23235
- if (parseSource(await fs3.readFile(configPath)) === null) {
23236
- return "unparseable";
23237
- }
23238
- }
23239
- return "no-collections";
23233
+ return parseSource(await fs3.readFile(loaded.file)) === null ? "unparseable" : "no-collections";
23240
23234
  }
23241
- async function parseContentConfig(fs3, cache) {
23242
- return (await readContentConfig(fs3, cache)).parsed;
23235
+ async function parseContentConfig(fs3, cache, srcDir = "src") {
23236
+ return (await readContentConfig(fs3, cache, srcDir)).parsed;
23243
23237
  }
23244
- async function readContentConfig(fs3, cache) {
23245
- let unparsed;
23238
+ async function readContentConfig(fs3, cache, srcDir = "src") {
23246
23239
  for (const configPath of CONTENT_CONFIG_PATHS) {
23240
+ const file = inSrcDir(configPath, srcDir);
23247
23241
  let stat;
23248
23242
  try {
23249
- stat = await fs3.stat(configPath);
23243
+ stat = await fs3.stat(file);
23250
23244
  } catch {
23251
23245
  continue;
23252
23246
  }
23253
- let cached = cache.get(configPath);
23247
+ let cached = cache.get(file);
23254
23248
  if (!cached || cached.mtimeMs !== stat.mtimeMs) {
23255
- const content = await fs3.readFile(configPath);
23249
+ const content = await fs3.readFile(file);
23256
23250
  cached = { mtimeMs: stat.mtimeMs, ...readConfigSource(content) };
23257
- cache.set(configPath, cached);
23251
+ cache.set(file, cached);
23258
23252
  }
23259
- if (cached.parsed.size > 0)
23260
- return cached;
23261
- if (!unparsed && (cached.declared.length > 0 || cached.exportsCollections))
23262
- unparsed = cached;
23253
+ return cached;
23263
23254
  }
23264
- return unparsed ?? { parsed: new Map, declared: [], partial: false, exportsCollections: false };
23255
+ return { parsed: new Map, declared: [], partial: false, exportsCollections: false };
23265
23256
  }
23266
23257
  function readConfigSource(source) {
23267
23258
  const result = new Map;
@@ -24307,9 +24298,284 @@ function dropNestedDerivedFrom(collectionName, path3, fields) {
24307
24298
  dropNestedDerivedFrom(collectionName, fieldPath, field.fields);
24308
24299
  }
24309
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
+ }
24310
24576
  // ../cms-core/src/collection-scanner.ts
24311
24577
  var import_yaml2 = __toESM(require_dist(), 1);
24312
- import path3 from "path";
24578
+ import path5 from "path";
24313
24579
  var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}/;
24314
24580
  var URL_PATTERN = /^(https?:\/\/|\/)/;
24315
24581
  var IMAGE_EXTENSIONS = /\.(jpg|jpeg|png|gif|webp|svg|avif)$/i;
@@ -24582,7 +24848,7 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
24582
24848
  return {
24583
24849
  name: collectionName,
24584
24850
  label,
24585
- path: path3.join(contentDir, collectionName),
24851
+ path: path5.join(contentDir, collectionName),
24586
24852
  entryCount,
24587
24853
  fields,
24588
24854
  fileExtension: "md",
@@ -24591,10 +24857,10 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
24591
24857
  };
24592
24858
  }
24593
24859
  function getCollectionSourceBasePath(basePath, collectionName, contentDir) {
24594
- const defaultCollectionPath = path3.join(contentDir, collectionName);
24860
+ const defaultCollectionPath = path5.join(contentDir, collectionName);
24595
24861
  const normalizedBasePath = normalizeBasePath(basePath);
24596
- if (normalizedBasePath === path3.normalize(defaultCollectionPath)) {
24597
- return path3.join(contentDir, collectionName);
24862
+ if (normalizedBasePath === path5.normalize(defaultCollectionPath)) {
24863
+ return path5.join(contentDir, collectionName);
24598
24864
  }
24599
24865
  return normalizedBasePath;
24600
24866
  }
@@ -24608,13 +24874,13 @@ async function buildCollectionDefinition(fs3, basePath, sources, collectionName,
24608
24874
  const allDirectives = {};
24609
24875
  const entryInfos = [];
24610
24876
  let hasDraft = false;
24611
- 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)));
24612
24878
  for (let i = 0;i < sources.length; i++) {
24613
24879
  const source = sources[i];
24614
24880
  const content = fileContents[i];
24615
24881
  if (content === null)
24616
24882
  continue;
24617
- const parsed = parseFrontmatter(content, path3.join(basePath, source.relPath), frontmatterMemo);
24883
+ const parsed = parseFrontmatter(content, path5.join(basePath, source.relPath), frontmatterMemo);
24618
24884
  const frontmatter = parsed?.data ?? null;
24619
24885
  for (const [key, value] of Object.entries(parsed?.directives ?? {})) {
24620
24886
  if (!allDirectives[key]) {
@@ -24623,7 +24889,7 @@ async function buildCollectionDefinition(fs3, basePath, sources, collectionName,
24623
24889
  }
24624
24890
  const entryInfo = {
24625
24891
  slug: source.slug,
24626
- sourcePath: path3.join(sourceBasePath, source.relPath)
24892
+ sourcePath: path5.join(sourceBasePath, source.relPath)
24627
24893
  };
24628
24894
  if (frontmatter) {
24629
24895
  const title = deriveEntryTitle(frontmatter);
@@ -24657,7 +24923,7 @@ async function buildDataCollectionDefinition(fs3, basePath, sources, collectionN
24657
24923
  const fieldMap = new Map;
24658
24924
  const entryInfos = [];
24659
24925
  const ext = sources.some((s) => s.relPath.endsWith(".json")) ? "json" : sources.some((s) => s.relPath.endsWith(".yaml")) ? "yaml" : "yml";
24660
- 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)));
24661
24927
  for (let i = 0;i < sources.length; i++) {
24662
24928
  const source = sources[i];
24663
24929
  const raw = fileContents[i];
@@ -24675,7 +24941,7 @@ async function buildDataCollectionDefinition(fs3, basePath, sources, collectionN
24675
24941
  entryInfos.push({
24676
24942
  slug: source.slug,
24677
24943
  title,
24678
- sourcePath: path3.join(sourceBasePath, source.relPath),
24944
+ sourcePath: path5.join(sourceBasePath, source.relPath),
24679
24945
  data
24680
24946
  });
24681
24947
  collectFieldObservations(fieldMap, data, sources.length);
@@ -24706,8 +24972,8 @@ async function scanCollection(fs3, collectionPath, collectionName, contentDir, f
24706
24972
  if (takenSlugs.has(dir.name))
24707
24973
  return null;
24708
24974
  for (const ext of ["md", "mdx"]) {
24709
- const relPath = path3.join(dir.name, `index.${ext}`);
24710
- 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))) {
24711
24977
  return { slug: dir.name, relPath };
24712
24978
  }
24713
24979
  }
@@ -24721,10 +24987,12 @@ async function scanCollection(fs3, collectionPath, collectionName, contentDir, f
24721
24987
  return null;
24722
24988
  return await buildCollectionDefinition(fs3, collectionPath, sources, collectionName, contentDir, frontmatterMemo);
24723
24989
  }
24990
+ function isPrivateEntryPath(relToBase) {
24991
+ return relToBase.split("/").some((seg) => seg.startsWith("_") || seg.startsWith("."));
24992
+ }
24724
24993
  async function globLoaderFiles(fs3, baseRel, pattern, options) {
24725
- const isPrivate = (relToBase) => relToBase.split("/").some((seg) => seg.startsWith("_") || seg.startsWith("."));
24726
- const matches = await fs3.glob(path3.join(baseRel, pattern), { ...options, skipDirectory: (dir) => isPrivate(path3.relative(baseRel, dir)) });
24727
- return matches.map((rel) => path3.relative(baseRel, rel)).filter((relToBase) => !isPrivate(relToBase));
24994
+ const matches = await fs3.glob(path5.join(baseRel, pattern), { ...options, skipDirectory: (dir) => isPrivateEntryPath(path5.relative(baseRel, dir)) });
24995
+ return matches.map((rel) => path5.relative(baseRel, rel)).filter((relToBase) => !isPrivateEntryPath(relToBase));
24728
24996
  }
24729
24997
  async function scanGlobCollection(fs3, collectionName, baseRel, pattern, contentDir, frontmatterMemo) {
24730
24998
  const rels = await globLoaderFiles(fs3, baseRel, pattern);
@@ -24736,7 +25004,36 @@ async function scanGlobCollection(fs3, collectionName, baseRel, pattern, content
24736
25004
  if (dataSources.length > 0) {
24737
25005
  return await buildDataCollectionDefinition(fs3, baseRel, dataSources, collectionName, contentDir);
24738
25006
  }
24739
- return null;
25007
+ if (!portRunsLoaderPattern(pattern))
25008
+ return null;
25009
+ const fileExtension = entryExtensionOfPattern(pattern);
25010
+ if (!fileExtension)
25011
+ return null;
25012
+ const isData = fileExtension === "json" || fileExtension === "yaml" || fileExtension === "yml";
25013
+ if (!loadsCreatedEntry(pattern, fileExtension, isData))
25014
+ return null;
25015
+ return assembleCollectionDefinition(collectionName, contentDir, new Map, [], 0, {
25016
+ path: getCollectionSourceBasePath(baseRel, collectionName, contentDir),
25017
+ fileExtension,
25018
+ ...isData ? { type: "data" } : {}
25019
+ });
25020
+ }
25021
+ function loadsCreatedEntry(pattern, fileExtension, isData) {
25022
+ const matcher = globToRegExp(path5.posix.normalize(pattern));
25023
+ const indexLayout = !isData && isIndexStyleGlobPattern(pattern);
25024
+ return ["entry", "x-1"].every((slug) => matcher.test(indexLayout ? `${slug}/index.${fileExtension}` : `${slug}.${fileExtension}`));
25025
+ }
25026
+ function isIndexStyleGlobPattern(pattern) {
25027
+ return pattern.includes("index.{") || pattern.includes("*/index") || pattern.includes("**/index");
25028
+ }
25029
+ var PATTERN_ENTRY_EXTENSIONS = ["md", "mdx", "json", "yaml", "yml"];
25030
+ function entryExtensionOfPattern(pattern) {
25031
+ const fileName = pattern.slice(pattern.lastIndexOf("/") + 1);
25032
+ const match = fileName.match(/\.(?:\{([^{}]*)\}|([A-Za-z0-9]+))$/);
25033
+ if (!match)
25034
+ return "md";
25035
+ const named = new Set((match[1] ?? match[2] ?? "").split(",").map((ext) => ext.trim().replace(/^\./, "")));
25036
+ return PATTERN_ENTRY_EXTENSIONS.find((ext) => named.has(ext)) ?? null;
24740
25037
  }
24741
25038
  function applyParsedConfig(collections, parsed) {
24742
25039
  for (const [collectionName, parsedColl] of parsed) {
@@ -25093,8 +25390,8 @@ async function scanDataCollection(fs3, collectionPath, collectionName, contentDi
25093
25390
  if (takenSlugs.has(dir.name))
25094
25391
  return null;
25095
25392
  for (const indexExt of ["json", "yaml", "yml"]) {
25096
- const relPath = path3.join(dir.name, `index.${indexExt}`);
25097
- if (await fs3.exists(path3.join(collectionPath, relPath))) {
25393
+ const relPath = path5.join(dir.name, `index.${indexExt}`);
25394
+ if (await fs3.exists(path5.join(collectionPath, relPath))) {
25098
25395
  return { slug: dir.name, relPath };
25099
25396
  }
25100
25397
  }
@@ -25106,9 +25403,6 @@ async function scanDataCollection(fs3, collectionPath, collectionName, contentDi
25106
25403
  }
25107
25404
  return await buildDataCollectionDefinition(fs3, collectionPath, sources, collectionName, contentDir);
25108
25405
  }
25109
- function normalizeBasePath(basePath) {
25110
- return path3.normalize(basePath.replace(/^\.[/\\]+/, "")).replace(/[/\\]+$/, "");
25111
- }
25112
25406
  var WHOLE_DIRECTORY_PATTERN = /^(?:\*\*[/\\])*\*(?:\.(?:\{([^{}/\\]*)\}|([A-Za-z0-9]+)))?$/;
25113
25407
  function patternCoversWholeCollection(pattern, definition) {
25114
25408
  const match = pattern.trim().replace(/^\.[/\\]+/, "").match(WHOLE_DIRECTORY_PATTERN);
@@ -25118,7 +25412,7 @@ function patternCoversWholeCollection(pattern, definition) {
25118
25412
  if (braceGroup === undefined && singleExtension === undefined)
25119
25413
  return true;
25120
25414
  const patternExtensions = new Set((braceGroup !== undefined ? braceGroup.split(",") : [singleExtension]).map((ext) => ext.trim().replace(/^\./, "").toLowerCase()).filter(Boolean));
25121
- const scannedExtensions = new Set((definition.entries ?? []).map((entry) => path3.extname(entry.sourcePath).slice(1).toLowerCase()).filter(Boolean));
25415
+ const scannedExtensions = new Set((definition.entries ?? []).map((entry) => path5.extname(entry.sourcePath).slice(1).toLowerCase()).filter(Boolean));
25122
25416
  if (scannedExtensions.size === 0)
25123
25417
  return false;
25124
25418
  for (const ext of scannedExtensions) {
@@ -25134,14 +25428,14 @@ async function scanCollections(fs3, contentDir = "src/content", parseCache = new
25134
25428
  const entries = await fs3.list(contentDir);
25135
25429
  const scanPromises = entries.filter((entry) => entry.isDirectory && !entry.name.startsWith("_") && !entry.name.startsWith(".")).map(async (entry) => {
25136
25430
  try {
25137
- const collectionPath = path3.join(contentDir, entry.name);
25431
+ const collectionPath = path5.join(contentDir, entry.name);
25138
25432
  const definition = await scanCollection(fs3, collectionPath, entry.name, contentDir, frontmatterMemo) ?? await scanDataCollection(fs3, collectionPath, entry.name, contentDir);
25139
25433
  if (definition) {
25140
25434
  collections[entry.name] = definition;
25141
25435
  }
25142
25436
  } catch (error) {
25143
25437
  console.warn(`[cms] Skipping collection "${entry.name}" \u2014 scan failed:`, error);
25144
- failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base: path3.join(contentDir, entry.name) });
25438
+ failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base: path5.join(contentDir, entry.name) });
25145
25439
  }
25146
25440
  });
25147
25441
  await Promise.all(scanPromises);
@@ -25217,6 +25511,9 @@ function collectionScanReport(collections) {
25217
25511
  return scanReports.get(collections);
25218
25512
  }
25219
25513
  var UNSUPPORTED_GLOB_SYNTAX = /[[\]()\\|]|\}\+|\{[^}]*(?:\{|\.\.|[*?]|,,)|\{,|,\}|\{[^,}]*\}|(?:^|[/{},])\.\.(?:[/{},]|$)|\/$|^(?:\.\/)+!|.\/\*\*$/;
25514
+ function portRunsLoaderPattern(pattern) {
25515
+ return !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(path5.posix.normalize(pattern));
25516
+ }
25220
25517
  var LEAVES_THE_BASE = /(?:^|[/{},])\.\.(?:[/{},]|$)/;
25221
25518
  var REPORT_LINKED_DIRECTORY_LIMIT = 20000;
25222
25519
  var ENTRY_FILE = /\.(?:md|mdx|mdoc|markdown|mdown|mkdn|mkd|mdwn|json|ya?ml|toml)$/i;
@@ -25226,7 +25523,7 @@ function readsAsRelativeDirectory(base) {
25226
25523
  return false;
25227
25524
  try {
25228
25525
  const asUrl = decodeURIComponent(new URL(base, "file:///project-root/").pathname).replace(/\/{2,}/g, "/").replace(/\/+$/, "");
25229
- const asPath = normalizeBasePath(base).split(path3.sep).join("/");
25526
+ const asPath = normalizeBasePath(base).split(path5.sep).join("/");
25230
25527
  return asUrl === (asPath === "." ? "/project-root" : `/project-root/${asPath}`);
25231
25528
  } catch {
25232
25529
  return false;
@@ -25235,7 +25532,7 @@ function readsAsRelativeDirectory(base) {
25235
25532
  function declaredLocation(declaration, contentDir) {
25236
25533
  const location = {};
25237
25534
  if (declaration.noLoader)
25238
- location.base = path3.join(contentDir, declaration.name);
25535
+ location.base = path5.join(contentDir, declaration.name);
25239
25536
  if (declaration.loaderBase !== undefined)
25240
25537
  location.base = normalizeBasePath(declaration.loaderBase);
25241
25538
  if (declaration.loaderPattern !== undefined)
@@ -25246,13 +25543,13 @@ function declaredLocation(declaration, contentDir) {
25246
25543
  }
25247
25544
  async function contentDirectoryFiles(fs3, directory, entryFile) {
25248
25545
  const files = await globLoaderFiles(fs3, directory, "**/*", { followSymlinks: true, maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT });
25249
- return files.filter((file) => entryFile.test(file)).map((file) => path3.join(directory, file));
25546
+ return files.filter((file) => entryFile.test(file)).map((file) => path5.join(directory, file));
25250
25547
  }
25251
25548
  async function declaredEntryFiles(fs3, contentDir, declaration) {
25252
25549
  if (declaration.noLoader) {
25253
25550
  if (!readsAsRelativeDirectory(declaration.name))
25254
25551
  return null;
25255
- return { exact: true, files: await contentDirectoryFiles(fs3, path3.join(contentDir, declaration.name), ENTRY_FILE) };
25552
+ return { exact: true, files: await contentDirectoryFiles(fs3, path5.join(contentDir, declaration.name), ENTRY_FILE) };
25256
25553
  }
25257
25554
  const declaredBase = declaration.loaderBase;
25258
25555
  if (declaredBase === undefined || !readsAsRelativeDirectory(declaredBase))
@@ -25262,14 +25559,14 @@ async function declaredEntryFiles(fs3, contentDir, declaration) {
25262
25559
  const patterns = pattern !== undefined ? [pattern] : declaration.loaderPatterns;
25263
25560
  if (patterns === undefined)
25264
25561
  return null;
25265
- const exact = pattern !== undefined && !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(path3.posix.normalize(pattern));
25562
+ const exact = pattern !== undefined && portRunsLoaderPattern(pattern);
25266
25563
  if (!exact && (base === "." || patterns.some((one) => LEAVES_THE_BASE.test(one))))
25267
25564
  return null;
25268
- const matches = await fs3.glob(path3.join(base, exact ? pattern : "**/*"), {
25565
+ const matches = await fs3.glob(path5.join(base, exact ? pattern : "**/*"), {
25269
25566
  followSymlinks: true,
25270
25567
  maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT
25271
25568
  });
25272
- const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one, path3.relative(base, file))));
25569
+ const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one, path5.relative(base, file))));
25273
25570
  return { exact, files };
25274
25571
  }
25275
25572
  function mayTakeDotPath(pattern, file) {
@@ -25280,42 +25577,19 @@ function mayTakeDotPath(pattern, file) {
25280
25577
  return true;
25281
25578
  if (/(?:^|[/{},|!\\])\.[^./]|[{,}|][*?]/.test(pattern))
25282
25579
  return true;
25283
- const cut = pattern.lastIndexOf("/");
25284
- const blurred = /[{(][^})]*\//.test(pattern);
25285
- const takesDot = (part) => /[[(]/.test(blurred ? pattern : part);
25286
- return (!dotFile || takesDot(pattern.slice(cut + 1))) && (!dotDirectory || takesDot(pattern.slice(0, Math.max(cut, 0))));
25287
- }
25288
- var ASTRO_CONFIG_PATHS = ["astro.config.mjs", "astro.config.js", "astro.config.ts", "astro.config.mts"];
25289
- async function customSrcDir(fs3) {
25290
- for (const configPath of ASTRO_CONFIG_PATHS) {
25291
- const source = await fs3.readFile(configPath).catch(() => null);
25292
- if (source === null)
25293
- continue;
25294
- const roots = configOptionMentions(source, "root");
25295
- const srcDirs = configOptionMentions(source, "srcDir");
25296
- if (roots === null || srcDirs === null)
25297
- return null;
25298
- if (roots.some((root) => root === null || normalizeBasePath(root) !== "."))
25299
- return null;
25300
- if (srcDirs.length === 0)
25301
- return;
25302
- const [srcDir, ...others] = srcDirs.map((literal) => literal === null ? null : normalizeBasePath(literal));
25303
- if (srcDir === null || srcDir === undefined || others.some((other) => other !== srcDir))
25304
- return null;
25305
- if (srcDir === "src")
25306
- return;
25307
- return path3.isAbsolute(srcDir) || srcDir.startsWith("..") ? null : srcDir;
25308
- }
25309
- return;
25580
+ const cut = pattern.lastIndexOf("/");
25581
+ const blurred = /[{(][^})]*\//.test(pattern);
25582
+ const takesDot = (part) => /[[(]/.test(blurred ? pattern : part);
25583
+ return (!dotFile || takesDot(pattern.slice(cut + 1))) && (!dotDirectory || takesDot(pattern.slice(0, Math.max(cut, 0))));
25310
25584
  }
25311
25585
  async function contentConfigStatus(fs3, config) {
25312
25586
  const configPaths = [...CONTENT_CONFIG_PATHS, ...UNREAD_CONTENT_CONFIG_PATHS];
25313
- const srcDir = await customSrcDir(fs3);
25587
+ const srcDir = await readAstroSrcDir(fs3);
25314
25588
  if (srcDir === null)
25315
25589
  return "unreadable";
25316
- if (srcDir !== undefined) {
25590
+ if (srcDir !== "src") {
25317
25591
  for (const configPath of configPaths) {
25318
- if (await fs3.exists(path3.join(srcDir, path3.relative("src", configPath))))
25592
+ if (await fs3.exists(path5.join(srcDir, path5.relative("src", configPath))))
25319
25593
  return "unreadable";
25320
25594
  }
25321
25595
  }
@@ -25339,7 +25613,7 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25339
25613
  const listed = new Set;
25340
25614
  for (const definition of Object.values(collections)) {
25341
25615
  for (const entry of definition.entries ?? [])
25342
- listed.add(path3.normalize(entry.sourcePath));
25616
+ listed.add(path5.normalize(entry.sourcePath));
25343
25617
  if ((definition.entries?.length ?? 0) >= definition.entryCount)
25344
25618
  continue;
25345
25619
  const declaration = declaredByName.get(definition.name);
@@ -25369,7 +25643,7 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25369
25643
  }
25370
25644
  if (loads === null) {
25371
25645
  unresolved.set(name, { name, reason: "unsupported-loader", ...location });
25372
- } else if (!loads.files.every((file) => listed.has(path3.normalize(file)))) {
25646
+ } else if (!loads.files.every((file) => listed.has(path5.normalize(file)))) {
25373
25647
  unresolved.set(name, { name, reason: loads.exact ? "unlisted-entries" : "unsupported-loader", ...location });
25374
25648
  }
25375
25649
  }
@@ -25378,11 +25652,11 @@ async function buildScanReport(fs3, contentDir, collections, config, failedScans
25378
25652
  for (const name of contentDirectories) {
25379
25653
  if (declaredByName.has(name) || unresolved.has(name) || failedScans.has(name))
25380
25654
  continue;
25381
- const directory = path3.join(contentDir, name);
25655
+ const directory = path5.join(contentDir, name);
25382
25656
  const files = await contentDirectoryFiles(fs3, directory, MARKDOWN_FILE).catch(() => null);
25383
25657
  if (files === null)
25384
25658
  unresolved.set(name, { name, reason: "scan-failed", base: directory });
25385
- else if (!files.every((file) => listed.has(path3.normalize(file))))
25659
+ else if (!files.every((file) => listed.has(path5.normalize(file))))
25386
25660
  unresolved.set(name, { name, reason: "unlisted-entries", base: directory });
25387
25661
  }
25388
25662
  }
@@ -25417,8 +25691,8 @@ function warnOnPathnameCollisions(collections) {
25417
25691
  }
25418
25692
  }
25419
25693
  // ../cms-core/src/component-registry.ts
25420
- var import_parser4 = __toESM(require_lib(), 1);
25421
- import path4 from "path";
25694
+ var import_parser5 = __toESM(require_lib(), 1);
25695
+ import path6 from "path";
25422
25696
  async function scanComponentDefinitions(fs3, componentDirs = ["src/components"]) {
25423
25697
  const components = {};
25424
25698
  for (const dir of componentDirs) {
@@ -25439,7 +25713,7 @@ async function scanDirectory(fs3, relativePath, components) {
25439
25713
  }
25440
25714
  async function parseComponent(fs3, relativePath, components) {
25441
25715
  const content = await fs3.readFile(relativePath);
25442
- const componentName = path4.basename(relativePath, ".astro");
25716
+ const componentName = path6.basename(relativePath, ".astro");
25443
25717
  const props = extractProps(content);
25444
25718
  const slots = extractSlots(content);
25445
25719
  const description = extractDescription(content);
@@ -25460,7 +25734,7 @@ ${propsContent}
25460
25734
  }`;
25461
25735
  let ast;
25462
25736
  try {
25463
- ast = import_parser4.parse(synthetic, {
25737
+ ast = import_parser5.parse(synthetic, {
25464
25738
  sourceType: "module",
25465
25739
  plugins: ["typescript"],
25466
25740
  errorRecovery: true
@@ -25677,9 +25951,9 @@ class CmsCommitConflictError extends Error {
25677
25951
  function digestBytes(content) {
25678
25952
  return `sha256:${createHash("sha256").update(content).digest("hex")}`;
25679
25953
  }
25680
- function normalize(path5) {
25954
+ function normalize(path7) {
25681
25955
  const segments = [];
25682
- for (const segment of path5.split("/")) {
25956
+ for (const segment of path7.split("/")) {
25683
25957
  if (segment === "" || segment === ".")
25684
25958
  continue;
25685
25959
  if (segment === ".." && segments.length > 0 && segments.at(-1) !== "..")
@@ -25689,67 +25963,67 @@ function normalize(path5) {
25689
25963
  }
25690
25964
  return segments.join("/");
25691
25965
  }
25692
- function isBelow(path5, dir) {
25693
- return dir === "" || path5.startsWith(`${dir}/`);
25966
+ function isBelow(path7, dir) {
25967
+ return dir === "" || path7.startsWith(`${dir}/`);
25694
25968
  }
25695
- function missing(path5) {
25696
- return Object.assign(new Error(`ENOENT: no such file, '${path5}'`), { code: "ENOENT" });
25969
+ function missing(path7) {
25970
+ return Object.assign(new Error(`ENOENT: no such file, '${path7}'`), { code: "ENOENT" });
25697
25971
  }
25698
25972
  function createStagedFileSystem(base) {
25699
25973
  const reads = new Map;
25700
25974
  const staged = new Map;
25701
25975
  const encoder = new TextEncoder;
25702
25976
  const decoder = new TextDecoder;
25703
- function observe(path5, version) {
25704
- const recorded = reads.get(path5);
25977
+ function observe(path7, version) {
25978
+ const recorded = reads.get(path7);
25705
25979
  if (recorded === undefined || recorded.kind === "present" && version.kind === "content")
25706
- reads.set(path5, version);
25980
+ reads.set(path7, version);
25707
25981
  }
25708
- async function observeBeforeChange(path5) {
25709
- if (staged.has(path5))
25982
+ async function observeBeforeChange(path7) {
25983
+ if (staged.has(path7))
25710
25984
  return;
25711
- const recorded = reads.get(path5);
25985
+ const recorded = reads.get(path7);
25712
25986
  if (recorded !== undefined && recorded.kind !== "present")
25713
25987
  return;
25714
- observe(path5, await versionOf(base, path5));
25988
+ observe(path7, await versionOf(base, path7));
25715
25989
  }
25716
25990
  async function readBytes(rawPath) {
25717
- const path5 = normalize(rawPath);
25718
- const change = staged.get(path5);
25991
+ const path7 = normalize(rawPath);
25992
+ const change = staged.get(path7);
25719
25993
  if (change === null)
25720
- throw missing(path5);
25994
+ throw missing(path7);
25721
25995
  if (change !== undefined)
25722
25996
  return change.content.slice();
25723
25997
  try {
25724
- const content = await base.readBytes(path5);
25725
- observe(path5, { kind: "content", digest: digestBytes(content) });
25998
+ const content = await base.readBytes(path7);
25999
+ observe(path7, { kind: "content", digest: digestBytes(content) });
25726
26000
  return content;
25727
26001
  } catch (error) {
25728
- if (!await base.exists(path5))
25729
- observe(path5, { kind: "absent" });
26002
+ if (!await base.exists(path7))
26003
+ observe(path7, { kind: "absent" });
25730
26004
  throw error;
25731
26005
  }
25732
26006
  }
25733
26007
  async function write(rawPath, content) {
25734
- const path5 = normalize(rawPath);
25735
- await observeBeforeChange(path5);
25736
- staged.set(path5, { content: content.slice(), mtimeMs: Date.now() });
26008
+ const path7 = normalize(rawPath);
26009
+ await observeBeforeChange(path7);
26010
+ staged.set(path7, { content: content.slice(), mtimeMs: Date.now() });
25737
26011
  }
25738
26012
  async function remove(rawPath) {
25739
- const path5 = normalize(rawPath);
25740
- await observeBeforeChange(path5);
25741
- staged.set(path5, null);
26013
+ const path7 = normalize(rawPath);
26014
+ await observeBeforeChange(path7);
26015
+ staged.set(path7, null);
25742
26016
  }
25743
26017
  function stagedBelow(dir) {
25744
- return [...staged].filter(([path5, change]) => change !== null && isBelow(path5, dir)).map(([path5]) => path5);
26018
+ return [...staged].filter(([path7, change]) => change !== null && isBelow(path7, dir)).map(([path7]) => path7);
25745
26019
  }
25746
26020
  return {
25747
- async readFile(path5) {
25748
- return decoder.decode(await readBytes(path5));
26021
+ async readFile(path7) {
26022
+ return decoder.decode(await readBytes(path7));
25749
26023
  },
25750
26024
  readBytes,
25751
- writeFile(path5, content) {
25752
- return write(path5, encoder.encode(content));
26025
+ writeFile(path7, content) {
26026
+ return write(path7, encoder.encode(content));
25753
26027
  },
25754
26028
  writeBytes: write,
25755
26029
  async rename(from, to) {
@@ -25759,23 +26033,23 @@ function createStagedFileSystem(base) {
25759
26033
  },
25760
26034
  remove,
25761
26035
  async exists(rawPath) {
25762
- const path5 = normalize(rawPath);
25763
- const change = staged.get(path5);
26036
+ const path7 = normalize(rawPath);
26037
+ const change = staged.get(path7);
25764
26038
  if (change !== undefined)
25765
26039
  return change !== null;
25766
- if (stagedBelow(path5).length > 0)
26040
+ if (stagedBelow(path7).length > 0)
25767
26041
  return true;
25768
- const exists = await base.exists(path5);
25769
- observe(path5, exists ? { kind: "present" } : { kind: "absent" });
26042
+ const exists = await base.exists(path7);
26043
+ observe(path7, exists ? { kind: "present" } : { kind: "absent" });
25770
26044
  return exists;
25771
26045
  },
25772
26046
  async list(rawDir) {
25773
26047
  const dir = normalize(rawDir);
25774
26048
  const entries = new Map((await base.list(dir)).map((entry) => [entry.name, entry.isDirectory]));
25775
- for (const [path5, change] of staged) {
25776
- if (!isBelow(path5, dir))
26049
+ for (const [path7, change] of staged) {
26050
+ if (!isBelow(path7, dir))
25777
26051
  continue;
25778
- const rest = dir === "" ? path5 : path5.slice(dir.length + 1);
26052
+ const rest = dir === "" ? path7 : path7.slice(dir.length + 1);
25779
26053
  const [name, ...deeper] = rest.split("/");
25780
26054
  if (name === undefined)
25781
26055
  continue;
@@ -25793,36 +26067,36 @@ function createStagedFileSystem(base) {
25793
26067
  async glob(pattern, options) {
25794
26068
  const matcher = globToRegExp(pattern);
25795
26069
  const files = new Set(await base.glob(pattern, options));
25796
- for (const [path5, change] of staged) {
26070
+ for (const [path7, change] of staged) {
25797
26071
  if (change === null)
25798
- files.delete(path5);
25799
- else if (matcher.test(path5))
25800
- files.add(path5);
26072
+ files.delete(path7);
26073
+ else if (matcher.test(path7))
26074
+ files.add(path7);
25801
26075
  }
25802
26076
  return [...files];
25803
26077
  },
25804
26078
  async stat(rawPath) {
25805
- const path5 = normalize(rawPath);
25806
- const change = staged.get(path5);
26079
+ const path7 = normalize(rawPath);
26080
+ const change = staged.get(path7);
25807
26081
  if (change === null)
25808
- throw missing(path5);
26082
+ throw missing(path7);
25809
26083
  if (change !== undefined)
25810
26084
  return { mtimeMs: change.mtimeMs, size: change.content.byteLength };
25811
- const stat = await base.stat(path5);
25812
- observe(path5, { kind: "present" });
26085
+ const stat = await base.stat(path7);
26086
+ observe(path7, { kind: "present" });
25813
26087
  return stat;
25814
26088
  },
25815
26089
  changeset() {
25816
- const changes = [...staged].map(([path5, change]) => change === null ? { kind: "remove", path: path5 } : { kind: "write", path: path5, content: change.content });
26090
+ const changes = [...staged].map(([path7, change]) => change === null ? { kind: "remove", path: path7 } : { kind: "write", path: path7, content: change.content });
25817
26091
  return { reads: new Map(reads), changes };
25818
26092
  }
25819
26093
  };
25820
26094
  }
25821
- async function versionOf(fs3, path5) {
25822
- if (!await fs3.exists(path5))
26095
+ async function versionOf(fs3, path7) {
26096
+ if (!await fs3.exists(path7))
25823
26097
  return { kind: "absent" };
25824
26098
  try {
25825
- return { kind: "content", digest: digestBytes(await fs3.readBytes(path5)) };
26099
+ return { kind: "content", digest: digestBytes(await fs3.readBytes(path7)) };
25826
26100
  } catch {
25827
26101
  return { kind: "present" };
25828
26102
  }
@@ -25830,7 +26104,7 @@ async function versionOf(fs3, path5) {
25830
26104
 
25831
26105
  // ../cms-core/src/handlers/entry-ops.ts
25832
26106
  var import_yaml3 = __toESM(require_dist(), 1);
25833
- import path5 from "path";
26107
+ import path7 from "path";
25834
26108
  var MARKDOWN_EXTENSIONS = ["md", "mdx"];
25835
26109
  function fileExtension(filePath) {
25836
26110
  const idx = filePath.lastIndexOf(".");
@@ -25851,12 +26125,12 @@ async function resolveEntryPath(deps, collection, slug) {
25851
26125
  const base = await resolveCollectionDir(deps, collection);
25852
26126
  const flatExts = ["md", "mdx", "json", "yaml", "yml"];
25853
26127
  for (const ext of flatExts) {
25854
- const candidate = path5.posix.join(base, `${slug}.${ext}`);
26128
+ const candidate = path7.posix.join(base, `${slug}.${ext}`);
25855
26129
  if (await deps.fs.exists(candidate))
25856
26130
  return candidate;
25857
26131
  }
25858
26132
  for (const ext of MARKDOWN_EXTENSIONS) {
25859
- const candidate = path5.posix.join(base, slug, `index.${ext}`);
26133
+ const candidate = path7.posix.join(base, slug, `index.${ext}`);
25860
26134
  if (await deps.fs.exists(candidate))
25861
26135
  return candidate;
25862
26136
  }
@@ -26006,13 +26280,14 @@ async function inferLayoutFromExistingEntries(deps, collection) {
26006
26280
  const dirEntries = await deps.fs.list(collectionPath);
26007
26281
  if (dirEntries.length === 0)
26008
26282
  return null;
26283
+ const loads = await loaderPatternTest(deps, collection);
26009
26284
  let flatCount = 0;
26010
26285
  const flatSlugs = new Set;
26011
26286
  for (const entry of dirEntries) {
26012
26287
  if (entry.isDirectory)
26013
26288
  continue;
26014
26289
  const match = entry.name.match(/^(.+)\.(md|mdx)$/);
26015
- if (!match)
26290
+ if (!match || !loads(entry.name))
26016
26291
  continue;
26017
26292
  flatCount++;
26018
26293
  flatSlugs.add(match[1]);
@@ -26022,7 +26297,8 @@ async function inferLayoutFromExistingEntries(deps, collection) {
26022
26297
  if (flatSlugs.has(dir.name))
26023
26298
  return false;
26024
26299
  for (const ext of MARKDOWN_EXTENSIONS) {
26025
- if (await deps.fs.exists(path5.posix.join(collectionPath, dir.name, `index.${ext}`)))
26300
+ const relPath = path7.posix.join(dir.name, `index.${ext}`);
26301
+ if (loads(relPath) && await deps.fs.exists(path7.posix.join(collectionPath, relPath)))
26026
26302
  return true;
26027
26303
  }
26028
26304
  return false;
@@ -26034,6 +26310,13 @@ async function inferLayoutFromExistingEntries(deps, collection) {
26034
26310
  return "flat";
26035
26311
  return null;
26036
26312
  }
26313
+ async function loaderPatternTest(deps, collection) {
26314
+ const pattern = (await parseContentConfig(deps.fs, deps.parseCache)).get(collection)?.loaderPattern;
26315
+ if (!pattern || !portRunsLoaderPattern(pattern))
26316
+ return () => true;
26317
+ const matcher = globToRegExp(path7.posix.normalize(pattern));
26318
+ return (relPath) => !isPrivateEntryPath(relPath) && matcher.test(relPath);
26319
+ }
26037
26320
  async function inferLayoutFromContentConfig(deps, collection) {
26038
26321
  const parsed = await parseContentConfig(deps.fs, deps.parseCache);
26039
26322
  const pattern = parsed.get(collection)?.loaderPattern;
@@ -26041,9 +26324,6 @@ async function inferLayoutFromContentConfig(deps, collection) {
26041
26324
  return null;
26042
26325
  return isIndexStyleGlobPattern(pattern) ? "index" : "flat";
26043
26326
  }
26044
- function isIndexStyleGlobPattern(pattern) {
26045
- return pattern.includes("index.{") || pattern.includes("*/index") || pattern.includes("**/index");
26046
- }
26047
26327
  async function applyDerivedFields(deps, collection, frontmatter, patch) {
26048
26328
  const parsed = await parseContentConfig(deps.fs, deps.parseCache);
26049
26329
  const parsedCollection = parsed.get(collection);
@@ -26124,7 +26404,7 @@ async function createEntry(deps, input) {
26124
26404
  const isData = ext === "json" || ext === "yaml" || ext === "yml";
26125
26405
  const layout = isData ? "flat" : await detectCollectionMarkdownLayout(deps, collection);
26126
26406
  const collectionDir = await resolveCollectionDir(deps, collection);
26127
- const sourcePath = layout === "index" ? path5.posix.join(collectionDir, normalizedSlug, `index.${ext}`) : path5.posix.join(collectionDir, `${normalizedSlug}.${ext}`);
26407
+ const sourcePath = layout === "index" ? path7.posix.join(collectionDir, normalizedSlug, `index.${ext}`) : path7.posix.join(collectionDir, `${normalizedSlug}.${ext}`);
26128
26408
  let fileContent;
26129
26409
  if (isData) {
26130
26410
  fileContent = ext === "json" ? JSON.stringify({ ...resolved }, null, 2) + `
@@ -26916,7 +27196,7 @@ async function scanDirectory2(fs3, currentDir, baseDir, relativeToRoot, excludeD
26916
27196
  }
26917
27197
  // ../cms-core/src/media/s3.ts
26918
27198
  import { randomUUID as randomUUID2 } from "crypto";
26919
- import path6 from "path";
27199
+ import path8 from "path";
26920
27200
  function normalizeFolder(folder) {
26921
27201
  return (folder ?? "").split("/").filter(Boolean).join("/");
26922
27202
  }
@@ -26983,7 +27263,7 @@ function createS3StorageAdapter(options) {
26983
27263
  id: key,
26984
27264
  url: getUrl(key),
26985
27265
  filename,
26986
- contentType: mimeFromExt(path6.extname(key).toLowerCase()),
27266
+ contentType: mimeFromExt(path8.extname(key).toLowerCase()),
26987
27267
  uploadedAt: obj.LastModified?.toISOString(),
26988
27268
  folder: folder || undefined
26989
27269
  };
@@ -27149,251 +27429,6 @@ async function listFilteredMedia(list, options, maxScanned = MAX_SCANNED) {
27149
27429
  position = next;
27150
27430
  }
27151
27431
  }
27152
- // ../cms-core/src/project-config-ast.ts
27153
- var import_parser5 = __toESM(require_lib(), 1);
27154
- var EMPTY_CONFIG = { listStyles: [] };
27155
- function parseSource2(source) {
27156
- try {
27157
- return import_parser5.parse(source, {
27158
- sourceType: "module",
27159
- plugins: ["typescript"],
27160
- errorRecovery: true
27161
- });
27162
- } catch {
27163
- return null;
27164
- }
27165
- }
27166
- function collectBindings2(ast) {
27167
- const bindings = new Map;
27168
- for (const stmt of ast.program.body) {
27169
- const varDecl = stmt.type === "ExportNamedDeclaration" && stmt.declaration?.type === "VariableDeclaration" ? stmt.declaration : stmt.type === "VariableDeclaration" ? stmt : null;
27170
- if (!varDecl)
27171
- continue;
27172
- for (const decl of varDecl.declarations) {
27173
- if (decl.id.type === "Identifier" && decl.init)
27174
- bindings.set(decl.id.name, decl.init);
27175
- }
27176
- }
27177
- return bindings;
27178
- }
27179
- function withoutTypeWrappers(node) {
27180
- let current = node;
27181
- while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion") {
27182
- current = current.expression;
27183
- }
27184
- return current;
27185
- }
27186
- function resolveExpression2(node, bindings, visited = new Set) {
27187
- let current = withoutTypeWrappers(node);
27188
- while (current.type === "Identifier") {
27189
- if (visited.has(current.name))
27190
- return current;
27191
- visited.add(current.name);
27192
- const next = bindings.get(current.name);
27193
- if (!next)
27194
- return current;
27195
- current = withoutTypeWrappers(next);
27196
- }
27197
- return current;
27198
- }
27199
- function propertyKeyName2(key) {
27200
- if (key.type === "Identifier")
27201
- return key.name;
27202
- if (key.type === "StringLiteral")
27203
- return key.value;
27204
- return null;
27205
- }
27206
- function objectPropertyValue(node, keyName, bindings) {
27207
- for (const prop of node.properties) {
27208
- if (prop.type !== "ObjectProperty")
27209
- continue;
27210
- if (propertyKeyName2(prop.key) !== keyName)
27211
- continue;
27212
- return resolveExpression2(prop.value, bindings);
27213
- }
27214
- return null;
27215
- }
27216
- function objectAtPath(root, keys, bindings) {
27217
- let current = root;
27218
- for (const key of keys) {
27219
- const value = objectPropertyValue(current, key, bindings);
27220
- if (!value || value.type !== "ObjectExpression")
27221
- return null;
27222
- current = value;
27223
- }
27224
- return current;
27225
- }
27226
- function staticString2(node, bindings) {
27227
- const resolved = resolveExpression2(node, bindings);
27228
- if (resolved.type === "StringLiteral")
27229
- return resolved.value;
27230
- if (resolved.type === "TemplateLiteral" && resolved.expressions.length === 0) {
27231
- return resolved.quasis[0]?.value.cooked ?? resolved.quasis[0]?.value.raw;
27232
- }
27233
- return;
27234
- }
27235
- function parseListStyle(node, bindings) {
27236
- const resolved = resolveExpression2(node, bindings);
27237
- if (resolved.type !== "ObjectExpression")
27238
- return null;
27239
- const labelNode = objectPropertyValue(resolved, "label", bindings);
27240
- const classNode = objectPropertyValue(resolved, "class", bindings);
27241
- if (!labelNode || !classNode)
27242
- return null;
27243
- const label = staticString2(labelNode, bindings);
27244
- const className = staticString2(classNode, bindings);
27245
- if (label === undefined || className === undefined)
27246
- return null;
27247
- return { label, class: className };
27248
- }
27249
- function parseListStyles(node, bindings) {
27250
- const styles = [];
27251
- for (const element of node.elements) {
27252
- if (!element || element.type === "SpreadElement")
27253
- continue;
27254
- const style = parseListStyle(element, bindings);
27255
- if (style)
27256
- styles.push(style);
27257
- }
27258
- return styles;
27259
- }
27260
- function configObjectFromDefaultExport(ast, bindings) {
27261
- for (const stmt of ast.program.body) {
27262
- if (stmt.type !== "ExportDefaultDeclaration")
27263
- continue;
27264
- const declaration = resolveExpression2(stmt.declaration, bindings);
27265
- if (declaration.type === "ObjectExpression")
27266
- return declaration;
27267
- if (declaration.type === "CallExpression") {
27268
- const firstArg = declaration.arguments[0];
27269
- if (!firstArg || firstArg.type === "SpreadElement")
27270
- return null;
27271
- const resolvedArg = resolveExpression2(firstArg, bindings);
27272
- if (resolvedArg.type === "ObjectExpression")
27273
- return resolvedArg;
27274
- }
27275
- }
27276
- return null;
27277
- }
27278
- var CMS_INTEGRATION_OPTIONS_PATH = {
27279
- "@nuasite/cms": [],
27280
- "@nuasite/nua": ["cms"],
27281
- "@nuasite/nua/integration": ["cms"]
27282
- };
27283
- function collectCmsIntegrationImports(ast) {
27284
- const imports = new Map;
27285
- for (const stmt of ast.program.body) {
27286
- if (stmt.type !== "ImportDeclaration")
27287
- continue;
27288
- const optionsPath = CMS_INTEGRATION_OPTIONS_PATH[stmt.source.value];
27289
- if (!optionsPath)
27290
- continue;
27291
- for (const specifier of stmt.specifiers) {
27292
- const importedName2 = specifier.type === "ImportDefaultSpecifier" ? "default" : specifier.type === "ImportSpecifier" ? propertyKeyName2(specifier.imported) : null;
27293
- if (importedName2 === "default" || importedName2 === "nua" && optionsPath.length > 0)
27294
- imports.set(specifier.local.name, optionsPath);
27295
- }
27296
- }
27297
- return imports;
27298
- }
27299
- function defaultExportWrapper(ast, bindings) {
27300
- const exported = ast.program.body.find((stmt) => stmt.type === "ExportDefaultDeclaration");
27301
- const declaration = exported?.type === "ExportDefaultDeclaration" ? resolveExpression2(exported.declaration, bindings) : null;
27302
- if (declaration?.type !== "CallExpression")
27303
- return "astro";
27304
- const callee = withoutTypeWrappers(declaration.callee);
27305
- if (callee.type !== "Identifier")
27306
- return "unknown";
27307
- for (const stmt of ast.program.body) {
27308
- if (stmt.type !== "ImportDeclaration" || !stmt.specifiers.some((specifier) => specifier.local.name === callee.name))
27309
- continue;
27310
- if (stmt.source.value === "@nuasite/nua/config")
27311
- return "nua";
27312
- if (stmt.source.value === "astro/config")
27313
- return "astro";
27314
- }
27315
- return "unknown";
27316
- }
27317
- function nuaCmsInstance(cms, bindings) {
27318
- if (cms?.type === "BooleanLiteral" && !cms.value)
27319
- return;
27320
- return cms?.type === "ObjectExpression" ? objectAtPath(cms, ["cmsConfig"], bindings) : null;
27321
- }
27322
- function wrapperCmsInstance(ast, configObject, bindings) {
27323
- const wrapper = defaultExportWrapper(ast, bindings);
27324
- if (wrapper === "astro")
27325
- return;
27326
- const nua = objectPropertyValue(configObject, "nua", bindings);
27327
- const cms = nua?.type === "ObjectExpression" ? objectPropertyValue(nua, "cms", bindings) : null;
27328
- if (wrapper === "unknown") {
27329
- return cms?.type === "ObjectExpression" ? nuaCmsInstance(cms, bindings) : undefined;
27330
- }
27331
- if (nua?.type === "BooleanLiteral" && !nua.value)
27332
- return;
27333
- return nuaCmsInstance(cms, bindings);
27334
- }
27335
- function effectiveCmsConfig(ast, configObject, bindings) {
27336
- let fromNua = wrapperCmsInstance(ast, configObject, bindings);
27337
- let fromCms;
27338
- const integrations = objectPropertyValue(configObject, "integrations", bindings);
27339
- const integrationImports = collectCmsIntegrationImports(ast);
27340
- for (const element of integrations?.type === "ArrayExpression" ? integrations.elements : []) {
27341
- if (!element || element.type === "SpreadElement")
27342
- continue;
27343
- const call = resolveExpression2(element, bindings);
27344
- const callee = call.type === "CallExpression" ? withoutTypeWrappers(call.callee) : null;
27345
- if (call.type !== "CallExpression" || callee?.type !== "Identifier")
27346
- continue;
27347
- const optionsPath = integrationImports.get(callee.name);
27348
- if (!optionsPath)
27349
- continue;
27350
- const firstArg = call.arguments[0];
27351
- const options = firstArg && firstArg.type !== "SpreadElement" ? resolveExpression2(firstArg, bindings) : null;
27352
- const optionsObject = options?.type === "ObjectExpression" ? options : null;
27353
- if (optionsPath.length === 0) {
27354
- fromCms = optionsObject && objectAtPath(optionsObject, ["cmsConfig"], bindings);
27355
- } else if (fromNua === undefined) {
27356
- fromNua = nuaCmsInstance(optionsObject && objectPropertyValue(optionsObject, "cms", bindings), bindings);
27357
- }
27358
- }
27359
- return fromNua !== undefined ? fromNua : fromCms ?? null;
27360
- }
27361
- function parseConfigListStyles(cmsConfig, bindings) {
27362
- const listStylesNode = cmsConfig ? objectPropertyValue(cmsConfig, "listStyles", bindings) : null;
27363
- return listStylesNode?.type === "ArrayExpression" ? parseListStyles(listStylesNode, bindings) : [];
27364
- }
27365
- function staticStringOf(object, key, bindings) {
27366
- const node = object ? objectPropertyValue(object, key, bindings) : null;
27367
- return node && staticString2(node, bindings) || undefined;
27368
- }
27369
- function parseLocale(cmsConfig, configObject, bindings) {
27370
- return staticStringOf(cmsConfig, "locale", bindings) ?? staticStringOf(objectAtPath(configObject, ["i18n"], bindings), "defaultLocale", bindings);
27371
- }
27372
- function parseProjectCmsConfigSource(source) {
27373
- const ast = parseSource2(source);
27374
- if (!ast)
27375
- return EMPTY_CONFIG;
27376
- const bindings = collectBindings2(ast);
27377
- const configObject = configObjectFromDefaultExport(ast, bindings);
27378
- if (!configObject)
27379
- return EMPTY_CONFIG;
27380
- const cmsConfig = effectiveCmsConfig(ast, configObject, bindings);
27381
- const locale = parseLocale(cmsConfig, configObject, bindings);
27382
- return { listStyles: parseConfigListStyles(cmsConfig, bindings), ...locale ? { locale } : {} };
27383
- }
27384
- var ASTRO_CONFIG_FILES = ["astro.config.ts", "astro.config.mts", "astro.config.mjs", "astro.config.js"];
27385
- async function parseProjectCmsConfig(fs3) {
27386
- for (const file of ASTRO_CONFIG_FILES) {
27387
- let source;
27388
- try {
27389
- source = await fs3.readFile(file);
27390
- } catch {
27391
- continue;
27392
- }
27393
- return parseProjectCmsConfigSource(source);
27394
- }
27395
- return EMPTY_CONFIG;
27396
- }
27397
27432
  // ../cms-core/src/route-map.ts
27398
27433
  var ROUTE_MAP_PATH = ".astro/integrations/_nuasite_cms/routes.json";
27399
27434
  var ROUTE_MAP_VERSION = 1;
@@ -27402,10 +27437,10 @@ function normalizeSiteBase(base) {
27402
27437
  return trimmed === "" ? "" : trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
27403
27438
  }
27404
27439
  function sitePathname(pathname, site) {
27405
- const path7 = `${site.base}${pathname === "/" ? "" : pathname.replace(/\/+$/, "")}`;
27406
- if (path7 === "")
27440
+ const path9 = `${site.base}${pathname === "/" ? "" : pathname.replace(/\/+$/, "")}`;
27441
+ if (path9 === "")
27407
27442
  return "/";
27408
- return site.trailingSlash === "always" ? `${path7}/` : path7;
27443
+ return site.trailingSlash === "always" ? `${path9}/` : path9;
27409
27444
  }
27410
27445
  function parseRouteMap(json) {
27411
27446
  let data;
@@ -27465,7 +27500,7 @@ function scanRouteCollections(source) {
27465
27500
  // src/cli.ts
27466
27501
  import fs3 from "fs";
27467
27502
  import { createRequire } from "module";
27468
- import path7 from "path";
27503
+ import path9 from "path";
27469
27504
 
27470
27505
  // src/media-from-env.ts
27471
27506
  var VALID_KINDS = ["contember", "s3", "local", "none"];
@@ -28485,16 +28520,16 @@ function createServer(opts) {
28485
28520
  function resolveCoreVersion() {
28486
28521
  try {
28487
28522
  const require2 = createRequire(import.meta.url);
28488
- let dir = path7.dirname(require2.resolve("@nuasite/cms-core"));
28523
+ let dir = path9.dirname(require2.resolve("@nuasite/cms-core"));
28489
28524
  for (;; ) {
28490
- const pkgPath = path7.join(dir, "package.json");
28525
+ const pkgPath = path9.join(dir, "package.json");
28491
28526
  if (fs3.existsSync(pkgPath)) {
28492
28527
  const parsed = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
28493
28528
  if (parsed && typeof parsed === "object" && "name" in parsed && parsed.name === "@nuasite/cms-core" && "version" in parsed && typeof parsed.version === "string") {
28494
28529
  return parsed.version;
28495
28530
  }
28496
28531
  }
28497
- const parent = path7.dirname(dir);
28532
+ const parent = path9.dirname(dir);
28498
28533
  if (parent === dir)
28499
28534
  break;
28500
28535
  dir = parent;
@@ -28520,7 +28555,7 @@ function parseServeArgs(args) {
28520
28555
  throw new Error("serve requires a valid --port <0-65535>");
28521
28556
  }
28522
28557
  const rawRoot = readFlag(args, "root");
28523
- const root = path7.resolve(rawRoot ?? process.cwd());
28558
+ const root = path9.resolve(rawRoot ?? process.cwd());
28524
28559
  const contentDir = readFlag(args, "content-dir");
28525
28560
  return { port, root, contentDir };
28526
28561
  }