@lexibase/rdx-core 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  getDocsIndex,
3
- getSourceOptions,
4
- parseStaticDocument
5
- } from "../chunk-5RUC6AZX.js";
3
+ getSourceOptions
4
+ } from "../chunk-MR2RBNYL.js";
6
5
  import {
6
+ changelogPluginName,
7
7
  getContentSources,
8
- isFallbackPage
9
- } from "../chunk-SNNEXRLQ.js";
8
+ isFallbackPage,
9
+ parseStaticDocument,
10
+ readChangelog
11
+ } from "../chunk-F5XY2FG4.js";
10
12
  import {
11
13
  RdxDocumentLinkError,
12
14
  createDocumentLinkResolver
@@ -195,6 +197,7 @@ function checkDocumentation(project, options = {}) {
195
197
  documentRoute(source, page)
196
198
  ];
197
199
  const document = {
200
+ sourcePath: page.sourcePath,
198
201
  page,
199
202
  source,
200
203
  href: hrefs[0],
@@ -211,6 +214,36 @@ function checkDocumentation(project, options = {}) {
211
214
  }
212
215
  if (project.config.homepage?.enabled) roots.add("/");
213
216
  else redirects.set("/", "/docs");
217
+ const changelog = project.config.plugins.some(
218
+ ({ name }) => name === changelogPluginName
219
+ );
220
+ const releases = changelog ? readChangelog(project.rootDir, syntax) : [];
221
+ const changelogAnchors = /* @__PURE__ */ new Set();
222
+ let changelogHasUnknownAnchors = false;
223
+ const releaseChecks = releases.flatMap((release) => {
224
+ changelogAnchors.add(`v${release.version}`);
225
+ try {
226
+ const parsed = parse(release.content, release.sourcePath.endsWith(".md"));
227
+ for (const anchor of parsed.anchors) changelogAnchors.add(anchor);
228
+ changelogHasUnknownAnchors ||= parsed.dynamicIds;
229
+ return [{ release, parsed }];
230
+ } catch (error) {
231
+ changelogHasUnknownAnchors = true;
232
+ syntax(error, release.sourcePath, release.lineOffset);
233
+ return [];
234
+ }
235
+ });
236
+ if (changelog) {
237
+ routes.set("/changelog", {
238
+ sourcePath: path.join(project.rootDir, "changelog"),
239
+ parsed: {
240
+ anchors: changelogAnchors,
241
+ references: [],
242
+ dynamicIds: changelogHasUnknownAnchors
243
+ }
244
+ });
245
+ roots.add("/changelog/rss.xml");
246
+ }
214
247
  for (const document of documents) {
215
248
  if (failed.has(document.page.sourcePath)) continue;
216
249
  try {
@@ -236,31 +269,11 @@ function checkDocumentation(project, options = {}) {
236
269
  }
237
270
  throw new Error("The destination contains a redirect loop.");
238
271
  }
239
- for (const document of documents) {
240
- const parsed = document.parsed;
241
- if (!parsed) continue;
242
- const contentSource = isFallbackPage(
243
- project,
244
- document.source,
245
- document.page.sourcePath
246
- ) ? sources.find(
247
- (source) => source.id === document.source.id && source.docsDir === document.source.fallbackDocsDir && !source.fallbackDocsDir
248
- ) : document.source;
249
- const resolve = createDocumentLinkResolver({
250
- sourceRoot: getSourceOptions(project, contentSource).docsDir,
251
- sourcePath: document.page.sourcePath,
252
- routePrefix: contentSource.routePrefix,
253
- basePath: contentSource.basePath,
254
- virtualPaths: !!contentSource.fallbackDocsDir,
255
- documents: documents.filter((entry) => entry.source === contentSource).map((entry) => entry.page)
256
- });
257
- for (const reference of parsed.references) {
272
+ function checkReferences(references, sourcePath, href, lineOffset, resolve) {
273
+ for (const reference of references) {
258
274
  let code = reference.image ? "asset" : "page";
259
275
  try {
260
- const url = new URL(
261
- reference.href,
262
- `${origin}${contentSource === document.source ? document.href : documentRoute(contentSource, document.page)}`
263
- );
276
+ const url = new URL(reference.href, `${origin}${href}`);
264
277
  if (!["http:", "https:"].includes(url.protocol)) continue;
265
278
  if (url.origin !== origin) continue;
266
279
  if (!project.config.metadata.metadataBase && /^(?:[a-z][\w+.-]*:|\/\/)/i.test(reference.href))
@@ -273,7 +286,11 @@ function checkDocumentation(project, options = {}) {
273
286
  pathname = key(resolved);
274
287
  target = coreRoutes.get(pathname);
275
288
  } else {
276
- pathname = redirectRoute(key(url.href));
289
+ pathname = key(url.href);
290
+ const basePath = project.config.basePath;
291
+ if (basePath && /^(?:https?:|\/\/)/i.test(reference.href) && (pathname === basePath || pathname.startsWith(`${basePath}/`)))
292
+ pathname = pathname.slice(basePath.length) || "/";
293
+ pathname = redirectRoute(pathname);
277
294
  if (!reference.image) target = routes.get(pathname);
278
295
  }
279
296
  if (target) {
@@ -282,7 +299,7 @@ function checkDocumentation(project, options = {}) {
282
299
  const anchor = decodeURIComponent(url.hash.slice(1));
283
300
  if (target.parsed && !target.parsed.dynamicIds && !target.parsed.anchors.has(anchor))
284
301
  throw new Error(
285
- `Section "#${anchor}" does not exist in ${relativeFile(target.page.sourcePath)}.`
302
+ `Section "#${anchor}" does not exist in ${relativeFile(target.sourcePath)}.`
286
303
  );
287
304
  }
288
305
  continue;
@@ -296,15 +313,59 @@ function checkDocumentation(project, options = {}) {
296
313
  } catch (error) {
297
314
  const value = error instanceof RdxDocumentLinkError ? error.reason : error instanceof Error ? error.message : String(error);
298
315
  diagnostics.push({
299
- file: relativeFile(document.page.sourcePath),
300
- line: (reference.position?.start.line ?? 1) + document.lineOffset,
316
+ file: relativeFile(sourcePath),
317
+ line: (reference.position?.start.line ?? 1) + (reference.field ? 0 : lineOffset),
301
318
  column: reference.position?.start.column ?? 1,
302
319
  code,
303
- message: `"${reference.href}": ${value}`
320
+ message: `${reference.field ? `${reference.field} ` : ""}"${reference.href}": ${value}`
304
321
  });
305
322
  }
306
323
  }
307
324
  }
325
+ for (const document of documents) {
326
+ if (!document.parsed) continue;
327
+ const contentSource = isFallbackPage(
328
+ project,
329
+ document.source,
330
+ document.page.sourcePath
331
+ ) ? sources.find(
332
+ (source) => source.id === document.source.id && source.docsDir === document.source.fallbackDocsDir && !source.fallbackDocsDir
333
+ ) : document.source;
334
+ checkReferences(
335
+ document.parsed.references,
336
+ document.page.sourcePath,
337
+ contentSource === document.source ? document.href : documentRoute(contentSource, document.page),
338
+ document.lineOffset,
339
+ createDocumentLinkResolver({
340
+ sourceRoot: getSourceOptions(project, contentSource).docsDir,
341
+ sourcePath: document.page.sourcePath,
342
+ routePrefix: contentSource.routePrefix,
343
+ basePath: contentSource.basePath,
344
+ virtualPaths: !!contentSource.fallbackDocsDir,
345
+ documents: documents.filter((entry) => entry.source === contentSource).map((entry) => entry.page)
346
+ })
347
+ );
348
+ }
349
+ for (const { release, parsed } of releaseChecks) {
350
+ checkReferences(
351
+ [
352
+ ...release.links.map(({ href }, index) => ({
353
+ href,
354
+ image: false,
355
+ field: `links[${index}].href`
356
+ })),
357
+ ...parsed.references
358
+ ],
359
+ release.sourcePath,
360
+ "/changelog",
361
+ release.lineOffset,
362
+ createDocumentLinkResolver({
363
+ sourceRoot: project.rootDir,
364
+ sourcePath: release.sourcePath,
365
+ documents: []
366
+ })
367
+ );
368
+ }
308
369
  diagnostics.sort(
309
370
  (a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column
310
371
  );
@@ -314,7 +375,7 @@ function checkDocumentation(project, options = {}) {
314
375
  ).values()
315
376
  ];
316
377
  return {
317
- checkedPages: new Set(documents.map((document) => document.page.sourcePath)).size,
378
+ checkedPages: new Set(documents.map((document) => document.page.sourcePath)).size + releases.length,
318
379
  diagnostics: unique
319
380
  };
320
381
  }
@@ -1,16 +1,15 @@
1
+ import {
2
+ RdxConfigError,
3
+ boundedProjectPath,
4
+ inside,
5
+ resolveProjectPath
6
+ } from "./chunk-F5XY2FG4.js";
7
+
1
8
  // src/config/index.ts
2
- import path7 from "path";
9
+ import path6 from "path";
3
10
  import { existsSync, readFileSync, readdirSync, statSync } from "fs";
4
11
  import { bundledThemes } from "shiki/themes";
5
12
 
6
- // src/config/error.ts
7
- var RdxConfigError = class extends Error {
8
- constructor(message) {
9
- super(`Invalid rdx.config.ts: ${message}`);
10
- this.name = "RdxConfigError";
11
- }
12
- };
13
-
14
13
  // src/config/metadata.ts
15
14
  function validateMetadata(input) {
16
15
  function string(value, field) {
@@ -243,73 +242,18 @@ function resolveLocalization(input, language, rootDir, command) {
243
242
  return localization;
244
243
  }
245
244
 
246
- // src/config/paths.ts
245
+ // src/config/source-localization.ts
247
246
  import fs2 from "fs";
248
247
  import path2 from "path";
249
- function resolveProjectPath(rootDir, value, field) {
250
- if (typeof value !== "string" || !value.trim())
251
- throw new RdxConfigError(`${field} must be a non-empty string.`);
252
- const resolved = path2.resolve(
253
- /* turbopackIgnore: true */
254
- rootDir,
255
- value
256
- );
257
- const relative = path2.relative(rootDir, resolved);
258
- if (path2.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative))
259
- throw new RdxConfigError(
260
- `${field} must be a relative path inside the project.`
261
- );
262
- return resolved;
263
- }
264
- function inside(parent, child) {
265
- const relative = path2.relative(parent, child);
266
- return !relative || relative !== ".." && !relative.startsWith(`..${path2.sep}`) && !path2.isAbsolute(relative);
267
- }
268
- function boundedProjectPath(rootDir, value, field) {
269
- const target = resolveProjectPath(rootDir, value, field);
270
- const root = fs2.realpathSync(
271
- /* turbopackIgnore: true */
272
- rootDir
273
- );
274
- let parent = target;
275
- while (true) {
276
- try {
277
- fs2.lstatSync(
278
- /* turbopackIgnore: true */
279
- parent
280
- );
281
- break;
282
- } catch (error) {
283
- if (error.code !== "ENOENT") throw error;
284
- parent = path2.dirname(parent);
285
- }
286
- }
287
- const canonical = path2.resolve(
288
- fs2.realpathSync(
289
- /* turbopackIgnore: true */
290
- parent
291
- ),
292
- path2.relative(parent, target)
293
- );
294
- if (!inside(root, canonical))
295
- throw new RdxConfigError(
296
- `${field} must remain inside the project, including filesystem links.`
297
- );
298
- return canonical;
299
- }
300
-
301
- // src/config/source-localization.ts
302
- import fs3 from "fs";
303
- import path3 from "path";
304
248
  function readSnapshot(rootDir, source, current, validateContent = true) {
305
- const relative = path3.join(source.docsDir, ".rdx-locales.json");
249
+ const relative = path2.join(source.docsDir, ".rdx-locales.json");
306
250
  const filename = boundedProjectPath(
307
251
  rootDir,
308
252
  relative,
309
253
  "snapshot locale metadata"
310
254
  );
311
255
  try {
312
- if (!fs3.lstatSync(
256
+ if (!fs2.lstatSync(
313
257
  /* turbopackIgnore: true */
314
258
  filename
315
259
  ).isFile())
@@ -320,7 +264,7 @@ function readSnapshot(rootDir, source, current, validateContent = true) {
320
264
  }
321
265
  try {
322
266
  const value = JSON.parse(
323
- fs3.readFileSync(
267
+ fs2.readFileSync(
324
268
  /* turbopackIgnore: true */
325
269
  filename,
326
270
  "utf8"
@@ -372,11 +316,11 @@ function readSnapshot(rootDir, source, current, validateContent = true) {
372
316
  directory,
373
317
  "snapshot translation"
374
318
  );
375
- if (validateContent && fs3.existsSync(
319
+ if (validateContent && fs2.existsSync(
376
320
  /* turbopackIgnore: true */
377
321
  absolute
378
322
  )) {
379
- if (!fs3.statSync(
323
+ if (!fs2.statSync(
380
324
  /* turbopackIgnore: true */
381
325
  absolute
382
326
  ).isDirectory())
@@ -423,7 +367,7 @@ function hydrateSourceLocalizations(rootDir, sources, current, runtimeFiles) {
423
367
  docs: { [primary.code]: source.docsDir }
424
368
  };
425
369
  if (frozen)
426
- runtimeFiles.add(path3.join(source.docsDir, ".rdx-locales.json"));
370
+ runtimeFiles.add(path2.join(source.docsDir, ".rdx-locales.json"));
427
371
  }
428
372
  sources[index] = { ...source, localization: inventory };
429
373
  for (const locale of inventory.locales)
@@ -437,7 +381,7 @@ function hydrateSourceLocalizations(rootDir, sources, current, runtimeFiles) {
437
381
  );
438
382
  if (retained) {
439
383
  runtimeFiles.add(
440
- path3.join(source.previousSnapshot.docsDir, ".rdx-locales.json")
384
+ path2.join(source.previousSnapshot.docsDir, ".rdx-locales.json")
441
385
  );
442
386
  for (const locale of retained.locales)
443
387
  if (!languages.has(locale.code)) languages.set(locale.code, locale);
@@ -452,8 +396,8 @@ function hydrateSourceLocalizations(rootDir, sources, current, runtimeFiles) {
452
396
  }
453
397
 
454
398
  // src/config/snapshots.ts
455
- import fs4 from "fs";
456
- import path4 from "path";
399
+ import fs3 from "fs";
400
+ import path3 from "path";
457
401
  function collectSnapshotContributions(context, options) {
458
402
  const directories = [
459
403
  { sourceDir: options.sourceDir, snapshotDir: options.snapshotDir }
@@ -493,7 +437,7 @@ function collectSnapshotContributions(context, options) {
493
437
  entry.snapshotDir,
494
438
  "snapshot snapshotDir"
495
439
  );
496
- if (!fs4.statSync(
440
+ if (!fs3.statSync(
497
441
  /* turbopackIgnore: true */
498
442
  from
499
443
  ).isDirectory())
@@ -501,7 +445,7 @@ function collectSnapshotContributions(context, options) {
501
445
  `Snapshot source must be a directory: ${entry.sourceDir}`
502
446
  );
503
447
  try {
504
- fs4.lstatSync(
448
+ fs3.lstatSync(
505
449
  /* turbopackIgnore: true */
506
450
  to
507
451
  );
@@ -543,11 +487,11 @@ function collectSnapshotContributions(context, options) {
543
487
  "Snapshot files must have unique paths inside the new snapshot directories."
544
488
  );
545
489
  seen.add(filename);
546
- const copiedFile = path4.join(
490
+ const copiedFile = path3.join(
547
491
  directory.from,
548
- path4.relative(directory.to, filename)
492
+ path3.relative(directory.to, filename)
549
493
  );
550
- if (fs4.existsSync(
494
+ if (fs3.existsSync(
551
495
  /* turbopackIgnore: true */
552
496
  copiedFile
553
497
  ))
@@ -557,7 +501,7 @@ function collectSnapshotContributions(context, options) {
557
501
  return { filename, content: entry.content };
558
502
  });
559
503
  return {
560
- rootDir: fs4.realpathSync(
504
+ rootDir: fs3.realpathSync(
561
505
  /* turbopackIgnore: true */
562
506
  context.rootDir
563
507
  ),
@@ -567,13 +511,13 @@ function collectSnapshotContributions(context, options) {
567
511
  }
568
512
 
569
513
  // src/config/edit-page.ts
570
- import path5 from "path";
514
+ import path4 from "path";
571
515
  function getEditPageHref(project, source, sourcePath) {
572
516
  const editPage = project.config.editPage;
573
517
  if (!editPage || source?.id !== "current") return;
574
- const relative = path5.relative(project.rootDir, sourcePath);
575
- const segments = relative.split(path5.sep);
576
- if (!relative || path5.isAbsolute(relative) || segments[0] === "..") return;
518
+ const relative = path4.relative(project.rootDir, sourcePath);
519
+ const segments = relative.split(path4.sep);
520
+ if (!relative || path4.isAbsolute(relative) || segments[0] === "..") return;
577
521
  const url = new URL(editPage.baseUrl);
578
522
  url.pathname = `${url.pathname.replace(/\/+$/, "")}/${segments.map(encodeURIComponent).join("/")}`;
579
523
  return url.href;
@@ -581,15 +525,15 @@ function getEditPageHref(project, source, sourcePath) {
581
525
 
582
526
  // src/config/document-dates.ts
583
527
  import { execFileSync } from "child_process";
584
- import fs5 from "fs";
585
- import path6 from "path";
528
+ import fs4 from "fs";
529
+ import path5 from "path";
586
530
  var snapshotDatesFilename = "_rdx-last-updated.json";
587
531
  var datePattern = /^\d{4}-\d{2}-\d{2}$/;
588
532
  function relativeFile(root, file) {
589
- const relative = path6.relative(root, file);
590
- if (!relative || path6.isAbsolute(relative) || relative.split(path6.sep)[0] === "..")
533
+ const relative = path5.relative(root, file);
534
+ if (!relative || path5.isAbsolute(relative) || relative.split(path5.sep)[0] === "..")
591
535
  return;
592
- return relative.split(path6.sep).join("/");
536
+ return relative.split(path5.sep).join("/");
593
537
  }
594
538
  function createDocumentDateReader(root) {
595
539
  const git = (...args) => execFileSync("git", ["--literal-pathspecs", ...args], {
@@ -627,12 +571,12 @@ function createDocumentDateReader(root) {
627
571
  function collectSnapshotDocumentDates(directory, dateFor) {
628
572
  const dates = /* @__PURE__ */ Object.create(null);
629
573
  function visit(folder) {
630
- for (const entry of fs5.readdirSync(
574
+ for (const entry of fs4.readdirSync(
631
575
  /* turbopackIgnore: true */
632
576
  folder,
633
577
  { withFileTypes: true }
634
578
  ).sort((a, b) => a.name.localeCompare(b.name, "en"))) {
635
- const file = path6.join(folder, entry.name);
579
+ const file = path5.join(folder, entry.name);
636
580
  if (entry.isDirectory()) visit(file);
637
581
  else if (entry.isFile() && /\.mdx?$/.test(entry.name)) {
638
582
  const date = dateFor(file);
@@ -647,9 +591,9 @@ function getSnapshotDocumentDate(directory, file) {
647
591
  const relative = relativeFile(directory, file);
648
592
  if (!relative) return;
649
593
  try {
650
- const filename = path6.join(directory, snapshotDatesFilename);
594
+ const filename = path5.join(directory, snapshotDatesFilename);
651
595
  const dates = JSON.parse(
652
- fs5.readFileSync(
596
+ fs4.readFileSync(
653
597
  /* turbopackIgnore: true */
654
598
  filename,
655
599
  "utf8"
@@ -920,7 +864,7 @@ async function createRdxProject(input, {
920
864
  rootDir = process.cwd(),
921
865
  command = "runtime"
922
866
  } = {}) {
923
- rootDir = path7.resolve(
867
+ rootDir = path6.resolve(
924
868
  /* turbopackIgnore: true */
925
869
  rootDir
926
870
  );
@@ -969,9 +913,9 @@ async function createRdxProject(input, {
969
913
  `${field} must contain a TextMate grammar with scopeName and patterns.`
970
914
  );
971
915
  runtimeFiles.add(
972
- path7.relative(rootDir, resolveProjectPath(rootDir, filename, field))
916
+ path6.relative(rootDir, resolveProjectPath(rootDir, filename, field))
973
917
  );
974
- runtimeFiles.add(path7.relative(rootDir, resolved));
918
+ runtimeFiles.add(path6.relative(rootDir, resolved));
975
919
  return {
976
920
  ...grammar,
977
921
  name,
@@ -1035,7 +979,7 @@ async function createRdxProject(input, {
1035
979
  const field = `plugin "${plugin.name}" runtimeFiles`;
1036
980
  const filename = text(value, field);
1037
981
  const resolved = resolveProjectPath(rootDir, filename, field);
1038
- runtimeFiles.add(path7.relative(rootDir, resolved));
982
+ runtimeFiles.add(path6.relative(rootDir, resolved));
1039
983
  }
1040
984
  }
1041
985
  if (contribution.sources === void 0) continue;
@@ -1143,9 +1087,7 @@ async function createRdxProject(input, {
1143
1087
  }
1144
1088
 
1145
1089
  export {
1146
- RdxConfigError,
1147
1090
  normalizeLocalization,
1148
- resolveProjectPath,
1149
1091
  collectSnapshotContributions,
1150
1092
  getEditPageHref,
1151
1093
  snapshotDatesFilename,
@@ -0,0 +1,269 @@
1
+ // src/content/static-source.ts
2
+ import matter from "gray-matter";
3
+ function parseStaticDocument(source) {
4
+ const text = source.replace(/^\uFEFF/, "");
5
+ if (text.startsWith("---") && text[3] !== "-") {
6
+ const language = matter.language(text).name.toLowerCase();
7
+ if (language && !["yaml", "yml", "json"].includes(language))
8
+ throw new Error(
9
+ "rdx check accepts YAML or JSON frontmatter, without executing document code."
10
+ );
11
+ }
12
+ return matter(source, {});
13
+ }
14
+
15
+ // src/project/localization.ts
16
+ import path from "path";
17
+ function getLocalizedProject(project, locale) {
18
+ const selected = project.localization?.locales.find(
19
+ (entry) => entry.path === locale
20
+ );
21
+ if (!selected) throw new Error(`Unknown documentation language: ${locale}`);
22
+ return {
23
+ ...project,
24
+ locale: selected,
25
+ config: { ...project.config, lang: selected.code },
26
+ sources: project.sources.map((source) => {
27
+ const primary = source.localization?.docs[project.localization.defaultLocale] ?? source.fallbackDocsDir ?? source.docsDir;
28
+ const translated = source.localization?.docs[selected.code] ?? (!source.localization && !source.version && selected.folder ? `locale/${selected.folder}/docs` : void 0);
29
+ const isPrimary = selected.code === project.localization.defaultLocale;
30
+ return {
31
+ ...source,
32
+ docsDir: isPrimary ? primary : translated ?? primary,
33
+ fallbackDocsDir: isPrimary ? void 0 : primary,
34
+ fallbackOnly: !isPrimary && !translated,
35
+ basePath: `/${selected.path}/docs`
36
+ };
37
+ })
38
+ };
39
+ }
40
+ function getContentSources(project) {
41
+ return project.localization && !project.locale ? project.localization.locales.flatMap(
42
+ (locale) => getLocalizedProject(project, locale.path).sources
43
+ ) : project.sources;
44
+ }
45
+ function getDocsHref(project, source = project.sources[0], slug = "") {
46
+ const base = source.basePath ?? (project.localization ? `/${project.localization.locales.find((entry) => entry.code === project.localization.defaultLocale).path}/docs` : "/docs");
47
+ return [
48
+ base,
49
+ source.routePrefix,
50
+ ...slug.split("/").filter(Boolean).map(encodeURIComponent)
51
+ ].filter(Boolean).join("/");
52
+ }
53
+ function getLanguageLinks(project, source, slug = "") {
54
+ if (!project.localization) return [];
55
+ const visible = new Set(
56
+ (project.sources[0]?.localization?.locales ?? project.localization.locales).map((locale) => locale.code)
57
+ );
58
+ for (const locale of source.localization?.locales ?? [])
59
+ visible.add(locale.code);
60
+ if (project.locale) visible.add(project.locale.code);
61
+ return project.localization.locales.filter((locale) => visible.has(locale.code)).map((locale) => {
62
+ const view = getLocalizedProject(project, locale.path);
63
+ return {
64
+ code: locale.code,
65
+ label: source.localization?.locales.find(
66
+ (entry) => entry.code === locale.code
67
+ )?.label ?? locale.label,
68
+ href: getDocsHref(
69
+ view,
70
+ view.sources.find((entry) => entry.id === source.id),
71
+ slug
72
+ )
73
+ };
74
+ });
75
+ }
76
+ function isFallbackPage(project, source, sourcePath) {
77
+ return !!source.fallbackDocsDir && !path.relative(
78
+ path.resolve(project.rootDir, source.fallbackDocsDir),
79
+ sourcePath
80
+ ).startsWith("..");
81
+ }
82
+
83
+ // src/config/error.ts
84
+ var RdxConfigError = class extends Error {
85
+ constructor(message) {
86
+ super(`Invalid rdx.config.ts: ${message}`);
87
+ this.name = "RdxConfigError";
88
+ }
89
+ };
90
+
91
+ // src/config/paths.ts
92
+ import fs from "fs";
93
+ import path2 from "path";
94
+ function resolveProjectPath(rootDir, value, field) {
95
+ if (typeof value !== "string" || !value.trim())
96
+ throw new RdxConfigError(`${field} must be a non-empty string.`);
97
+ const resolved = path2.resolve(
98
+ /* turbopackIgnore: true */
99
+ rootDir,
100
+ value
101
+ );
102
+ const relative = path2.relative(rootDir, resolved);
103
+ if (path2.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative))
104
+ throw new RdxConfigError(
105
+ `${field} must be a relative path inside the project.`
106
+ );
107
+ return resolved;
108
+ }
109
+ function inside(parent, child) {
110
+ const relative = path2.relative(parent, child);
111
+ return !relative || relative !== ".." && !relative.startsWith(`..${path2.sep}`) && !path2.isAbsolute(relative);
112
+ }
113
+ function boundedProjectPath(rootDir, value, field) {
114
+ const target = resolveProjectPath(rootDir, value, field);
115
+ const root = fs.realpathSync(
116
+ /* turbopackIgnore: true */
117
+ rootDir
118
+ );
119
+ let parent = target;
120
+ while (true) {
121
+ try {
122
+ fs.lstatSync(
123
+ /* turbopackIgnore: true */
124
+ parent
125
+ );
126
+ break;
127
+ } catch (error) {
128
+ if (error.code !== "ENOENT") throw error;
129
+ parent = path2.dirname(parent);
130
+ }
131
+ }
132
+ const canonical = path2.resolve(
133
+ fs.realpathSync(
134
+ /* turbopackIgnore: true */
135
+ parent
136
+ ),
137
+ path2.relative(parent, target)
138
+ );
139
+ if (!inside(root, canonical))
140
+ throw new RdxConfigError(
141
+ `${field} must remain inside the project, including filesystem links.`
142
+ );
143
+ return canonical;
144
+ }
145
+
146
+ // src/config/changelog.ts
147
+ import fs2 from "fs";
148
+ import path3 from "path";
149
+ var changelogPluginName = "@lexibase/rdx-changelog";
150
+ function readLinks(value) {
151
+ if (value === void 0) return [];
152
+ if (!Array.isArray(value)) throw new Error("links must be a list");
153
+ return value.map((link, index) => {
154
+ const field = `links[${index}]`;
155
+ if (!link || typeof link !== "object" || Array.isArray(link))
156
+ throw new Error(`${field} must have a label and an href`);
157
+ const { label, href } = link;
158
+ if (typeof label !== "string" || !label.trim())
159
+ throw new Error(`${field}.label must be a non-empty string`);
160
+ if (typeof href !== "string" || /[\s\\]/.test(href) || !/^(?:\/(?!\/)|https?:\/\/)/i.test(href) || !URL.canParse(href, "https://rdx.invalid"))
161
+ throw new Error(
162
+ `${field}.href must be a root-relative path or HTTP(S) URL`
163
+ );
164
+ return { label: label.trim(), href };
165
+ });
166
+ }
167
+ function readBadges(value) {
168
+ if (value === void 0) return [];
169
+ const invalidBadge = "badge must use breaking, security, or deprecated, separated by commas";
170
+ if (typeof value !== "string") throw new Error(invalidBadge);
171
+ const badges = /* @__PURE__ */ new Set();
172
+ for (const item of value.split(",")) {
173
+ const badge = item.trim();
174
+ if (badge !== "breaking" && badge !== "security" && badge !== "deprecated")
175
+ throw new Error(invalidBadge);
176
+ badges.add(badge);
177
+ }
178
+ return [...badges];
179
+ }
180
+ function isChangelogVersion(version) {
181
+ return typeof version === "string" && /^\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?$/i.test(version) && version === version.trim();
182
+ }
183
+ function getChangelogDirectory(rootDir) {
184
+ return boundedProjectPath(rootDir, "changelog", "changelog/");
185
+ }
186
+ function getChangelogFiles(rootDir) {
187
+ const directory = getChangelogDirectory(rootDir);
188
+ let files;
189
+ try {
190
+ files = fs2.readdirSync(
191
+ /* turbopackIgnore: true */
192
+ directory,
193
+ {
194
+ withFileTypes: true
195
+ }
196
+ );
197
+ } catch (error) {
198
+ if (error.code === "ENOENT") return [];
199
+ throw error;
200
+ }
201
+ return files.filter((file) => file.isFile() && /\.mdx?$/.test(file.name)).sort((a, b) => a.name.localeCompare(b.name)).map(({ name }) => ({
202
+ filename: path3.join("changelog", name),
203
+ sourcePath: path3.join(directory, name)
204
+ }));
205
+ }
206
+ function readChangelog(rootDir, onError) {
207
+ const versions = /* @__PURE__ */ new Set();
208
+ return getChangelogFiles(rootDir).flatMap(({ filename, sourcePath }) => {
209
+ try {
210
+ const raw = fs2.readFileSync(
211
+ /* turbopackIgnore: true */
212
+ sourcePath,
213
+ "utf8"
214
+ );
215
+ const { content, data } = parseStaticDocument(raw);
216
+ const { title, version } = data;
217
+ const date = data.date instanceof Date ? data.date.toISOString().slice(0, 10) : data.date;
218
+ if (typeof title !== "string" || !title.trim())
219
+ throw new Error("title must be a non-empty string");
220
+ if (!isChangelogVersion(version))
221
+ throw new Error("version must be a release version such as 1.2.0");
222
+ if (typeof date !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(date) || Number.isNaN(Date.parse(date)) || new Date(date).toISOString().slice(0, 10) !== date)
223
+ throw new Error("date must be a valid date in YYYY-MM-DD format");
224
+ if (versions.has(version))
225
+ throw new Error(`duplicate version ${version}`);
226
+ const entry = {
227
+ title: title.trim(),
228
+ version,
229
+ date,
230
+ badges: readBadges(data.badge),
231
+ links: readLinks(data.links),
232
+ content,
233
+ lineOffset: (raw.slice(0, raw.length - content.length).match(/\n/g) ?? []).length,
234
+ filename,
235
+ sourcePath
236
+ };
237
+ versions.add(version);
238
+ return [entry];
239
+ } catch (error) {
240
+ if (onError) {
241
+ onError(error, sourcePath);
242
+ return [];
243
+ }
244
+ throw new Error(`${filename}: ${error.message}`, {
245
+ cause: error
246
+ });
247
+ }
248
+ }).sort(
249
+ (a, b) => b.date.localeCompare(a.date) || b.version.localeCompare(a.version, "en", { numeric: true })
250
+ );
251
+ }
252
+
253
+ export {
254
+ parseStaticDocument,
255
+ getLocalizedProject,
256
+ getContentSources,
257
+ getDocsHref,
258
+ getLanguageLinks,
259
+ isFallbackPage,
260
+ RdxConfigError,
261
+ resolveProjectPath,
262
+ inside,
263
+ boundedProjectPath,
264
+ changelogPluginName,
265
+ isChangelogVersion,
266
+ getChangelogDirectory,
267
+ getChangelogFiles,
268
+ readChangelog
269
+ };
@@ -1,3 +1,6 @@
1
+ import {
2
+ parseStaticDocument
3
+ } from "./chunk-F5XY2FG4.js";
1
4
  import {
2
5
  DEFAULT_POSITION,
3
6
  documentExtension,
@@ -5,24 +8,10 @@ import {
5
8
  slugFromRelativePath
6
9
  } from "./chunk-GR2GL7HT.js";
7
10
 
8
- // src/content/static-source.ts
9
- import matter from "gray-matter";
10
- function parseStaticDocument(source) {
11
- const text = source.replace(/^\uFEFF/, "");
12
- if (text.startsWith("---") && text[3] !== "-") {
13
- const language = matter.language(text).name.toLowerCase();
14
- if (language && !["yaml", "yml", "json"].includes(language))
15
- throw new Error(
16
- "rdx check accepts YAML or JSON frontmatter, without executing document code."
17
- );
18
- }
19
- return matter(source, {});
20
- }
21
-
22
11
  // src/content/index.ts
23
12
  import fs from "fs";
24
13
  import path from "path";
25
- import matter2 from "gray-matter";
14
+ import matter from "gray-matter";
26
15
  function getDocsRoot(docsDir = "docs") {
27
16
  return path.resolve(
28
17
  /* turbopackIgnore: true */
@@ -175,7 +164,7 @@ function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly } = {}, onError)
175
164
  filePath,
176
165
  "utf8"
177
166
  );
178
- const parsed = onError ? parseStaticDocument(raw) : matter2(raw);
167
+ const parsed = onError ? parseStaticDocument(raw) : matter(raw);
179
168
  frontmatter = isRecord(parsed.data) ? parsed.data : {};
180
169
  } catch (error) {
181
170
  if (!onError) throw error;
@@ -238,7 +227,7 @@ function getDocument(slug, { docsDir, fallbackDocsDir, fallbackOnly } = {}) {
238
227
  const sourcePath = candidates[0];
239
228
  if (!sourcePath)
240
229
  return fallbackDocsDir ? getDocument(slug, { docsDir: fallbackDocsDir }) : null;
241
- const parsed = matter2(
230
+ const parsed = matter(
242
231
  fs.readFileSync(
243
232
  /* turbopackIgnore: true */
244
233
  sourcePath,
@@ -302,7 +291,6 @@ function getProjectDocsPaths(project) {
302
291
  }
303
292
 
304
293
  export {
305
- parseStaticDocument,
306
294
  getDocsIndex,
307
295
  getDocsPaths,
308
296
  getDocument,
@@ -1,2 +1,2 @@
1
1
  import '@lexibase/rdx-types';
2
- export { R as RdxConfigError, h as collectSnapshotContributions, j as collectSnapshotDocumentDates, k as createDocumentDateReader, c as createRdxProject, d as defineConfig, g as getContentSources, l as getEditPageHref, m as getSnapshotDocumentDate, n as normalizeLocalization, r as resolveConfig, f as resolveProjectPath, s as snapshotDatesFilename } from '../index-CIBgPARs.js';
2
+ export { R as RdxConfigError, h as changelogPluginName, j as collectSnapshotContributions, k as collectSnapshotDocumentDates, l as createDocumentDateReader, c as createRdxProject, d as defineConfig, m as getChangelogDirectory, n as getChangelogFiles, g as getContentSources, o as getEditPageHref, p as getSnapshotDocumentDate, q as isChangelogVersion, s as normalizeLocalization, t as readChangelog, r as resolveConfig, f as resolveProjectPath, u as snapshotDatesFilename } from '../index-BI3YflHV.js';
@@ -1,5 +1,4 @@
1
1
  import {
2
- RdxConfigError,
3
2
  collectSnapshotContributions,
4
3
  collectSnapshotDocumentDates,
5
4
  createDocumentDateReader,
@@ -9,23 +8,34 @@ import {
9
8
  getSnapshotDocumentDate,
10
9
  normalizeLocalization,
11
10
  resolveConfig,
12
- resolveProjectPath,
13
11
  snapshotDatesFilename
14
- } from "../chunk-CRQU7OO4.js";
12
+ } from "../chunk-72FMWDD4.js";
15
13
  import {
16
- getContentSources
17
- } from "../chunk-SNNEXRLQ.js";
14
+ RdxConfigError,
15
+ changelogPluginName,
16
+ getChangelogDirectory,
17
+ getChangelogFiles,
18
+ getContentSources,
19
+ isChangelogVersion,
20
+ readChangelog,
21
+ resolveProjectPath
22
+ } from "../chunk-F5XY2FG4.js";
18
23
  export {
19
24
  RdxConfigError,
25
+ changelogPluginName,
20
26
  collectSnapshotContributions,
21
27
  collectSnapshotDocumentDates,
22
28
  createDocumentDateReader,
23
29
  createRdxProject,
24
30
  defineConfig,
31
+ getChangelogDirectory,
32
+ getChangelogFiles,
25
33
  getContentSources,
26
34
  getEditPageHref,
27
35
  getSnapshotDocumentDate,
36
+ isChangelogVersion,
28
37
  normalizeLocalization,
38
+ readChangelog,
29
39
  resolveConfig,
30
40
  resolveProjectPath,
31
41
  snapshotDatesFilename
@@ -4,6 +4,28 @@ declare class RdxConfigError extends Error {
4
4
  constructor(message: string);
5
5
  }
6
6
 
7
+ declare const changelogPluginName = "@lexibase/rdx-changelog";
8
+ declare function isChangelogVersion(version: unknown): version is string;
9
+ declare function getChangelogDirectory(rootDir: string): string;
10
+ declare function getChangelogFiles(rootDir: string): {
11
+ filename: string;
12
+ sourcePath: string;
13
+ }[];
14
+ declare function readChangelog(rootDir: string, onError?: (error: unknown, sourcePath: string) => void): {
15
+ title: string;
16
+ version: string;
17
+ date: string;
18
+ badges: ("breaking" | "security" | "deprecated")[];
19
+ links: {
20
+ label: string;
21
+ href: string;
22
+ }[];
23
+ content: string;
24
+ lineOffset: number;
25
+ filename: string;
26
+ sourcePath: string;
27
+ }[];
28
+
7
29
  /** Resolve project-owned paths without allowing traversal or filesystem roots. */
8
30
  declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
9
31
 
@@ -53,4 +75,4 @@ declare function createRdxProject(input: unknown, { rootDir, command, }?: {
53
75
  command?: string;
54
76
  }): Promise<RdxProject>;
55
77
 
56
- export { RdxConfigError as R, getDocsHref as a, getLanguageLinks as b, createRdxProject as c, defineConfig as d, getLocalizedProject as e, resolveProjectPath as f, getContentSources as g, collectSnapshotContributions as h, isFallbackPage as i, collectSnapshotDocumentDates as j, createDocumentDateReader as k, getEditPageHref as l, getSnapshotDocumentDate as m, normalizeLocalization as n, resolveConfig as r, snapshotDatesFilename as s };
78
+ export { RdxConfigError as R, getDocsHref as a, getLanguageLinks as b, createRdxProject as c, defineConfig as d, getLocalizedProject as e, resolveProjectPath as f, getContentSources as g, changelogPluginName as h, isFallbackPage as i, collectSnapshotContributions as j, collectSnapshotDocumentDates as k, createDocumentDateReader as l, getChangelogDirectory as m, getChangelogFiles as n, getEditPageHref as o, getSnapshotDocumentDate as p, isChangelogVersion as q, resolveConfig as r, normalizeLocalization as s, readChangelog as t, snapshotDatesFilename as u };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _lexibase_rdx_types from '@lexibase/rdx-types';
2
2
  import { RdxDocsOptions, RdxDocCategory, RdxDocument, RdxProject, RdxContentSource } from '@lexibase/rdx-types';
3
- export { R as RdxConfigError, c as createRdxProject, d as defineConfig, g as getContentSources, a as getDocsHref, b as getLanguageLinks, e as getLocalizedProject, i as isFallbackPage, r as resolveConfig, f as resolveProjectPath } from './index-CIBgPARs.js';
3
+ export { R as RdxConfigError, c as createRdxProject, d as defineConfig, g as getContentSources, a as getDocsHref, b as getLanguageLinks, e as getLocalizedProject, i as isFallbackPage, r as resolveConfig, f as resolveProjectPath } from './index-BI3YflHV.js';
4
4
  export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver } from './document-links-BQXyBubK.js';
5
5
 
6
6
  /**
package/dist/index.js CHANGED
@@ -5,21 +5,21 @@ import {
5
5
  getProjectDocsPaths,
6
6
  getSourceOptions,
7
7
  resolveDocsRoute
8
- } from "./chunk-5RUC6AZX.js";
8
+ } from "./chunk-MR2RBNYL.js";
9
9
  import {
10
- RdxConfigError,
11
10
  createRdxProject,
12
11
  defineConfig,
13
- resolveConfig,
14
- resolveProjectPath
15
- } from "./chunk-CRQU7OO4.js";
12
+ resolveConfig
13
+ } from "./chunk-72FMWDD4.js";
16
14
  import {
15
+ RdxConfigError,
17
16
  getContentSources,
18
17
  getDocsHref,
19
18
  getLanguageLinks,
20
19
  getLocalizedProject,
21
- isFallbackPage
22
- } from "./chunk-SNNEXRLQ.js";
20
+ isFallbackPage,
21
+ resolveProjectPath
22
+ } from "./chunk-F5XY2FG4.js";
23
23
  import {
24
24
  RdxDocumentLinkError,
25
25
  createDocumentLinkResolver
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexibase/rdx-core",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,75 +0,0 @@
1
- // src/project/localization.ts
2
- import path from "path";
3
- function getLocalizedProject(project, locale) {
4
- const selected = project.localization?.locales.find(
5
- (entry) => entry.path === locale
6
- );
7
- if (!selected) throw new Error(`Unknown documentation language: ${locale}`);
8
- return {
9
- ...project,
10
- locale: selected,
11
- config: { ...project.config, lang: selected.code },
12
- sources: project.sources.map((source) => {
13
- const primary = source.localization?.docs[project.localization.defaultLocale] ?? source.fallbackDocsDir ?? source.docsDir;
14
- const translated = source.localization?.docs[selected.code] ?? (!source.localization && !source.version && selected.folder ? `locale/${selected.folder}/docs` : void 0);
15
- const isPrimary = selected.code === project.localization.defaultLocale;
16
- return {
17
- ...source,
18
- docsDir: isPrimary ? primary : translated ?? primary,
19
- fallbackDocsDir: isPrimary ? void 0 : primary,
20
- fallbackOnly: !isPrimary && !translated,
21
- basePath: `/${selected.path}/docs`
22
- };
23
- })
24
- };
25
- }
26
- function getContentSources(project) {
27
- return project.localization && !project.locale ? project.localization.locales.flatMap(
28
- (locale) => getLocalizedProject(project, locale.path).sources
29
- ) : project.sources;
30
- }
31
- function getDocsHref(project, source = project.sources[0], slug = "") {
32
- const base = source.basePath ?? (project.localization ? `/${project.localization.locales.find((entry) => entry.code === project.localization.defaultLocale).path}/docs` : "/docs");
33
- return [
34
- base,
35
- source.routePrefix,
36
- ...slug.split("/").filter(Boolean).map(encodeURIComponent)
37
- ].filter(Boolean).join("/");
38
- }
39
- function getLanguageLinks(project, source, slug = "") {
40
- if (!project.localization) return [];
41
- const visible = new Set(
42
- (project.sources[0]?.localization?.locales ?? project.localization.locales).map((locale) => locale.code)
43
- );
44
- for (const locale of source.localization?.locales ?? [])
45
- visible.add(locale.code);
46
- if (project.locale) visible.add(project.locale.code);
47
- return project.localization.locales.filter((locale) => visible.has(locale.code)).map((locale) => {
48
- const view = getLocalizedProject(project, locale.path);
49
- return {
50
- code: locale.code,
51
- label: source.localization?.locales.find(
52
- (entry) => entry.code === locale.code
53
- )?.label ?? locale.label,
54
- href: getDocsHref(
55
- view,
56
- view.sources.find((entry) => entry.id === source.id),
57
- slug
58
- )
59
- };
60
- });
61
- }
62
- function isFallbackPage(project, source, sourcePath) {
63
- return !!source.fallbackDocsDir && !path.relative(
64
- path.resolve(project.rootDir, source.fallbackDocsDir),
65
- sourcePath
66
- ).startsWith("..");
67
- }
68
-
69
- export {
70
- getLocalizedProject,
71
- getContentSources,
72
- getDocsHref,
73
- getLanguageLinks,
74
- isFallbackPage
75
- };