@lexibase/rdx-core 1.4.0 → 2.1.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,16 +1,2 @@
1
- import { RdxProject, RDXConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
2
-
3
- declare class RdxConfigError extends Error {
4
- constructor(message: string);
5
- }
6
-
7
- /** Resolve project-owned paths without allowing traversal or filesystem roots. */
8
- declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
9
- declare function resolveConfig(input: unknown): ResolvedRdxConfig;
10
- declare function defineConfig(config: RDXConfig): RDXConfig;
11
- declare function createRdxProject(input: unknown, { rootDir, command, }?: {
12
- rootDir?: string;
13
- command?: string;
14
- }): Promise<RdxProject>;
15
-
16
- export { RdxConfigError, createRdxProject, defineConfig, resolveConfig, resolveProjectPath };
1
+ import '@lexibase/rdx-types';
2
+ export { R as RdxConfigError, h as collectSnapshotContributions, c as createRdxProject, d as defineConfig, g as getContentSources, n as normalizeLocalization, r as resolveConfig, f as resolveProjectPath } from '../index-DjuvW7o_.js';
@@ -1,14 +1,22 @@
1
1
  import {
2
2
  RdxConfigError,
3
+ collectSnapshotContributions,
3
4
  createRdxProject,
4
5
  defineConfig,
6
+ normalizeLocalization,
5
7
  resolveConfig,
6
8
  resolveProjectPath
7
- } from "../chunk-75BDBF5N.js";
9
+ } from "../chunk-WDWRIRH2.js";
10
+ import {
11
+ getContentSources
12
+ } from "../chunk-SNNEXRLQ.js";
8
13
  export {
9
14
  RdxConfigError,
15
+ collectSnapshotContributions,
10
16
  createRdxProject,
11
17
  defineConfig,
18
+ getContentSources,
19
+ normalizeLocalization,
12
20
  resolveConfig,
13
21
  resolveProjectPath
14
22
  };
@@ -2,12 +2,16 @@ interface DocumentLinkOptions {
2
2
  sourceRoot: string;
3
3
  sourcePath: string;
4
4
  routePrefix?: string;
5
+ basePath?: string;
6
+ /** Resolve missing translated files against the effective primary inventory. */
7
+ virtualPaths?: boolean;
5
8
  documents: readonly {
6
9
  sourcePath: string;
7
10
  slug: string;
8
11
  }[];
9
12
  }
10
13
  declare class RdxDocumentLinkError extends Error {
14
+ readonly reason: string;
11
15
  constructor(sourcePath: string, href: string, reason: string);
12
16
  }
13
17
  /** Resolve only explicit relative MDX links within the current content source. */
@@ -0,0 +1,49 @@
1
+ import { RdxLocalization, RdxPluginContext, RdxProject, RdxContentSource, RDXConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
2
+
3
+ declare class RdxConfigError extends Error {
4
+ constructor(message: string);
5
+ }
6
+
7
+ /** Resolve project-owned paths without allowing traversal or filesystem roots. */
8
+ declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
9
+
10
+ /** Validate language identities without depending on live filesystem trees. */
11
+ declare function normalizeLocalization(input: unknown, language: string): RdxLocalization;
12
+
13
+ /** Gather and validate every participant before the first destination is reserved. */
14
+ declare function collectSnapshotContributions(context: RdxPluginContext, options: {
15
+ version: string;
16
+ snapshotDir: string;
17
+ sourceDir: string;
18
+ }): {
19
+ rootDir: string;
20
+ directories: {
21
+ from: string;
22
+ to: string;
23
+ }[];
24
+ files: {
25
+ filename: string;
26
+ content: string;
27
+ }[];
28
+ };
29
+
30
+ /** Select a language without mutating the shared project or rerunning plugin hooks. */
31
+ declare function getLocalizedProject(project: RdxProject, locale: string): RdxProject;
32
+ declare function getContentSources(project: RdxProject): RdxContentSource[];
33
+ declare function getDocsHref(project: RdxProject, source?: RdxContentSource, slug?: string): string;
34
+ /** Navbar language links retain both the page and the selected edition. */
35
+ declare function getLanguageLinks(project: RdxProject, source: RdxContentSource, slug?: string): {
36
+ code: string;
37
+ label: string;
38
+ href: string;
39
+ }[];
40
+ declare function isFallbackPage(project: RdxProject, source: RdxContentSource, sourcePath: string): boolean;
41
+
42
+ declare function resolveConfig(input: unknown): ResolvedRdxConfig;
43
+ declare function defineConfig(config: RDXConfig): RDXConfig;
44
+ declare function createRdxProject(input: unknown, { rootDir, command, }?: {
45
+ rootDir?: string;
46
+ command?: string;
47
+ }): Promise<RdxProject>;
48
+
49
+ 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, normalizeLocalization as n, resolveConfig as r };
package/dist/index.d.ts CHANGED
@@ -1,18 +1,22 @@
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 { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver } from './document-links-BtWSWs2x.js';
4
- export { RdxConfigError, createRdxProject, defineConfig, resolveConfig, resolveProjectPath } from './config/index.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-DjuvW7o_.js';
4
+ export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver } from './document-links-Dr4JVYuN.js';
5
5
 
6
6
  /**
7
7
  * Reads the documentation tree from the user's project. The URL slug always
8
8
  * preserves the full path, so `guides/intro.mdx` and `api/intro.mdx` never
9
9
  * collide.
10
+ * With onError, static readers collect per-file failures and retain fallback
11
+ * route metadata. Default callers keep the existing fail-fast behavior.
10
12
  */
11
- declare function getDocsIndex({ docsDir, }?: RdxDocsOptions): RdxDocCategory[];
13
+ declare function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly }?: RdxDocsOptions, onError?: (error: unknown, sourcePath: string) => void): RdxDocCategory[];
12
14
  declare function getDocsPaths(options?: RdxDocsOptions): string[];
13
- declare function getDocument(slug: string, { docsDir }?: RdxDocsOptions): RdxDocument | null;
15
+ declare function getDocument(slug: string, { docsDir, fallbackDocsDir, fallbackOnly }?: RdxDocsOptions): RdxDocument | null;
14
16
 
15
17
  declare function getSourceOptions(project: RdxProject, source: RdxContentSource): {
18
+ fallbackDocsDir?: string | undefined;
19
+ fallbackOnly?: boolean | undefined;
16
20
  docsDir: string;
17
21
  };
18
22
  /** Match plugin routes before looking up pages in the live documentation. */
package/dist/index.js CHANGED
@@ -1,192 +1,45 @@
1
+ import {
2
+ getDocsIndex,
3
+ getDocsPaths,
4
+ getDocument,
5
+ getProjectDocsPaths,
6
+ getSourceOptions,
7
+ resolveDocsRoute
8
+ } from "./chunk-CGOXC3S6.js";
1
9
  import {
2
10
  RdxConfigError,
3
11
  createRdxProject,
4
12
  defineConfig,
5
13
  resolveConfig,
6
14
  resolveProjectPath
7
- } from "./chunk-75BDBF5N.js";
15
+ } from "./chunk-WDWRIRH2.js";
16
+ import {
17
+ getContentSources,
18
+ getDocsHref,
19
+ getLanguageLinks,
20
+ getLocalizedProject,
21
+ isFallbackPage
22
+ } from "./chunk-SNNEXRLQ.js";
8
23
  import {
9
24
  RdxDocumentLinkError,
10
25
  createDocumentLinkResolver
11
- } from "./chunk-Z6GCGXVC.js";
12
-
13
- // src/content/index.ts
14
- import fs from "fs";
15
- import path from "path";
16
- import matter from "gray-matter";
17
- var MDX_EXTENSION = ".mdx";
18
- var DEFAULT_POSITION = Number.MAX_SAFE_INTEGER;
19
- function getDocsRoot(docsDir = "docs") {
20
- return path.resolve(
21
- /* turbopackIgnore: true */
22
- process.cwd(),
23
- docsDir
24
- );
25
- }
26
- function toTitle(value) {
27
- return value.replace(/[-_]/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
28
- }
29
- function isRecord(value) {
30
- return typeof value === "object" && value !== null;
31
- }
32
- function stringValue(value, fallback) {
33
- return typeof value === "string" && value.trim() ? value : fallback;
34
- }
35
- function numberValue(value, fallback = DEFAULT_POSITION) {
36
- return typeof value === "number" && Number.isFinite(value) ? value : fallback;
37
- }
38
- function readCategoryMeta(categoryPath, fallbackTitle) {
39
- const metaPath = path.join(categoryPath, "_category.json");
40
- if (!fs.existsSync(metaPath)) {
41
- return { title: fallbackTitle, position: DEFAULT_POSITION };
42
- }
43
- try {
44
- const parsed = JSON.parse(fs.readFileSync(metaPath, "utf8"));
45
- if (!isRecord(parsed)) {
46
- return { title: fallbackTitle, position: DEFAULT_POSITION };
47
- }
48
- return {
49
- title: stringValue(parsed.title, fallbackTitle),
50
- position: numberValue(parsed.sidebar_position)
51
- };
52
- } catch {
53
- return { title: fallbackTitle, position: DEFAULT_POSITION };
54
- }
55
- }
56
- function findMdxFiles(directory) {
57
- const entries = fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
58
- return entries.flatMap((entry) => {
59
- const entryPath = path.join(directory, entry.name);
60
- if (entry.isDirectory()) return findMdxFiles(entryPath);
61
- if (entry.isFile() && entry.name.endsWith(MDX_EXTENSION)) return [entryPath];
62
- return [];
63
- });
64
- }
65
- function slugFromRelativePath(relativePath) {
66
- return relativePath.split(path.sep).join("/").replace(/\.mdx$/, "");
67
- }
68
- function isSafeSlug(slug) {
69
- if (path.isAbsolute(slug) || slug.includes("\\")) return false;
70
- return slug.split("/").every((segment) => segment && segment !== "." && segment !== "..");
71
- }
72
- function getDocsIndex({
73
- docsDir
74
- } = {}) {
75
- const docsRoot = getDocsRoot(docsDir);
76
- if (!fs.existsSync(docsRoot)) return [];
77
- const categories = /* @__PURE__ */ new Map();
78
- for (const filePath of findMdxFiles(docsRoot)) {
79
- const relativePath = path.relative(docsRoot, filePath);
80
- const pathParts = relativePath.split(path.sep);
81
- const categoryId = pathParts.length > 1 ? pathParts[0] ?? "_root" : "_root";
82
- const categoryPath = categoryId === "_root" ? docsRoot : path.join(docsRoot, categoryId);
83
- const fallbackCategoryTitle = categoryId === "_root" ? "Overview" : toTitle(categoryId);
84
- let category = categories.get(categoryId);
85
- if (!category) {
86
- const meta = readCategoryMeta(categoryPath, fallbackCategoryTitle);
87
- const createdCategory = {
88
- id: categoryId,
89
- title: meta.title,
90
- position: meta.position,
91
- pages: [],
92
- categoryPath
93
- };
94
- categories.set(categoryId, createdCategory);
95
- category = createdCategory;
96
- }
97
- const source = fs.readFileSync(filePath, "utf8");
98
- const parsed = matter(source);
99
- const frontmatter = isRecord(parsed.data) ? parsed.data : {};
100
- const slug = slugFromRelativePath(relativePath);
101
- const fallbackTitle = toTitle(path.basename(slug));
102
- category.pages.push({
103
- slug,
104
- title: stringValue(frontmatter.title, fallbackTitle),
105
- description: stringValue(frontmatter.description, ""),
106
- position: numberValue(frontmatter.link_position),
107
- sourcePath: filePath
108
- });
109
- }
110
- return [...categories.values()].map(({ categoryPath: _categoryPath, ...category }) => ({
111
- ...category,
112
- pages: category.pages.sort(
113
- (first, second) => first.position - second.position || first.slug.localeCompare(second.slug)
114
- )
115
- })).sort(
116
- (first, second) => first.position - second.position || first.title.localeCompare(second.title)
117
- );
118
- }
119
- function getDocsPaths(options) {
120
- return getDocsIndex(options).flatMap(
121
- (category) => category.pages.map((page) => page.slug)
122
- );
123
- }
124
- function getDocument(slug, { docsDir } = {}) {
125
- if (!isSafeSlug(slug)) return null;
126
- const docsRoot = getDocsRoot(docsDir);
127
- const sourcePath = path.resolve(docsRoot, `${slug}${MDX_EXTENSION}`);
128
- const relativePath = path.relative(docsRoot, sourcePath);
129
- if (relativePath.startsWith("..") || path.isAbsolute(relativePath))
130
- return null;
131
- if (!fs.existsSync(sourcePath)) return null;
132
- const parsed = matter(fs.readFileSync(sourcePath, "utf8"));
133
- return {
134
- slug,
135
- sourcePath,
136
- content: parsed.content,
137
- frontmatter: isRecord(parsed.data) ? parsed.data : {}
138
- };
139
- }
140
-
141
- // src/project/index.ts
142
- import path2 from "path";
143
- function getSourceOptions(project, source) {
144
- return { docsDir: path2.resolve(project.rootDir, source.docsDir) };
145
- }
146
- function resolveDocsRoute(project, segments = []) {
147
- const source = project.sources.find(
148
- (entry) => entry.routePrefix && entry.routePrefix === segments[0]
149
- ) ?? project.sources[0];
150
- const options = getSourceOptions(project, source);
151
- const slug = (source.routePrefix ? segments.slice(1) : segments).join("/") || getDocsPaths(options)[0];
152
- return {
153
- source,
154
- slug,
155
- document: slug ? getDocument(slug, options) : null,
156
- categories: getDocsIndex(options)
157
- };
158
- }
159
- function getProjectDocsPaths(project) {
160
- const paths = /* @__PURE__ */ new Set();
161
- for (const source of project.sources) {
162
- if (source.redirectTo !== void 0) continue;
163
- for (const slug of getDocsPaths(getSourceOptions(project, source))) {
164
- const route = [source.routePrefix, slug].filter(Boolean).join("/");
165
- if (paths.has(route))
166
- throw new Error(`Conflicting documentation route: /docs/${route}`);
167
- if (!source.routePrefix && project.sources.some(
168
- (other) => other.routePrefix === slug.split("/")[0]
169
- )) {
170
- throw new Error(
171
- `Live documentation route /docs/${slug} conflicts with a plugin content source.`
172
- );
173
- }
174
- paths.add(route);
175
- }
176
- }
177
- return [...paths];
178
- }
26
+ } from "./chunk-LCBSNAUH.js";
179
27
  export {
180
28
  RdxConfigError,
181
29
  RdxDocumentLinkError,
182
30
  createDocumentLinkResolver,
183
31
  createRdxProject,
184
32
  defineConfig,
33
+ getContentSources,
34
+ getDocsHref,
185
35
  getDocsIndex,
186
36
  getDocsPaths,
187
37
  getDocument,
38
+ getLanguageLinks,
39
+ getLocalizedProject,
188
40
  getProjectDocsPaths,
189
41
  getSourceOptions,
42
+ isFallbackPage,
190
43
  resolveConfig,
191
44
  resolveDocsRoute,
192
45
  resolveProjectPath
@@ -1,4 +1,4 @@
1
- export { D as DocumentLinkOptions, r as remarkDocumentLinks } from '../document-links-BtWSWs2x.js';
1
+ export { D as DocumentLinkOptions, r as remarkDocumentLinks } from '../document-links-Dr4JVYuN.js';
2
2
  export { default as rehypeDocumentationHeadings } from 'rehype-slug';
3
3
  import rehypeShiki from '@shikijs/rehype';
4
4
  import remarkDirective from 'remark-directive';
package/dist/mdx/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkDocumentLinks
3
- } from "../chunk-Z6GCGXVC.js";
3
+ } from "../chunk-LCBSNAUH.js";
4
4
  import {
5
5
  remarkDocumentationComponents
6
6
  } from "../chunk-J7VCQHSL.js";
@@ -1,3 +1,6 @@
1
+ import {
2
+ headingText
3
+ } from "../chunk-FPBRKD4M.js";
1
4
  import {
2
5
  remarkDocumentationComponents
3
6
  } from "../chunk-J7VCQHSL.js";
@@ -35,11 +38,6 @@ function text(node) {
35
38
  function plain(value) {
36
39
  return value.replace(/\s+/g, " ").trim();
37
40
  }
38
- function headingText(node) {
39
- if (["image", "imageReference", "break"].includes(node.type)) return "";
40
- if (node.children) return node.children.map(headingText).join("");
41
- return text(node);
42
- }
43
41
  function buildSearchIndex(documents) {
44
42
  const entries = [];
45
43
  for (const document of documents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexibase/rdx-core",
3
- "version": "1.4.0",
3
+ "version": "2.1.0",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,6 +19,10 @@
19
19
  "types": "./dist/mdx/index.d.ts",
20
20
  "import": "./dist/mdx/index.js"
21
21
  },
22
+ "./check": {
23
+ "types": "./dist/check/index.d.ts",
24
+ "import": "./dist/check/index.js"
25
+ },
22
26
  "./search": {
23
27
  "types": "./dist/search/index.d.ts",
24
28
  "import": "./dist/search/index.js"
@@ -50,20 +54,20 @@
50
54
  "remark-mdx": "^3.1.1",
51
55
  "remark-parse": "^11.0.0",
52
56
  "unified": "^11.0.5",
53
- "@lexibase/rdx-types": "1.2.0"
57
+ "@lexibase/rdx-types": "2.1.0"
54
58
  },
55
59
  "devDependencies": {
56
60
  "@types/node": "^22.15.3",
57
61
  "@types/react": "19.3.0",
58
- "@rdx/eslint-config": "1.0.0",
59
- "@rdx/typescript-config": "1.0.0"
62
+ "@rdx/typescript-config": "1.0.0",
63
+ "@rdx/eslint-config": "1.0.0"
60
64
  },
61
65
  "engines": {
62
66
  "node": "^22.18.0 || ^24.11.0"
63
67
  },
64
68
  "scripts": {
65
- "dev": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts --format esm --dts --watch --external @lexibase/rdx-types --external gray-matter",
66
- "build": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter",
69
+ "dev": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts src/check/index.ts --format esm --dts --watch --external @lexibase/rdx-types --external gray-matter",
70
+ "build": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts src/check/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter",
67
71
  "check-types": "tsc --noEmit",
68
72
  "test": "node --test tests/*.test.mjs"
69
73
  }