@lexibase/rdx-core 3.5.1 → 3.6.1
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.
- package/dist/check/index.d.ts +6 -1
- package/dist/check/index.js +245 -37
- package/dist/{chunk-4S2NYHNB.js → chunk-EY2T3I2T.js} +4 -4
- package/dist/{chunk-KRVOWYZS.js → chunk-T27TQEAY.js} +7 -4
- package/dist/{document-links-CuuelWKE.d.ts → document-links-UCwHmYXf.d.ts} +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/mdx/index.d.ts +2 -2
- package/dist/mdx/index.js +1 -1
- package/package.json +8 -8
package/dist/check/index.d.ts
CHANGED
|
@@ -6,10 +6,15 @@ type DocumentationDiagnostic = {
|
|
|
6
6
|
column: number;
|
|
7
7
|
code: 'page' | 'anchor' | 'asset' | 'syntax';
|
|
8
8
|
message: string;
|
|
9
|
+
suggestion?: string;
|
|
10
|
+
};
|
|
11
|
+
type DocumentationWarning = Omit<DocumentationDiagnostic, 'code'> & {
|
|
12
|
+
code: 'unlinked' | 'redirected-link';
|
|
9
13
|
};
|
|
10
14
|
type DocumentationCheck = {
|
|
11
15
|
checkedPages: number;
|
|
12
16
|
diagnostics: DocumentationDiagnostic[];
|
|
17
|
+
warnings?: DocumentationWarning[];
|
|
13
18
|
};
|
|
14
19
|
/** Host adapters can describe aliases without changing the project's authoring API. */
|
|
15
20
|
type DocumentationCheckOptions = {
|
|
@@ -19,7 +24,7 @@ type DocumentationCheckOptions = {
|
|
|
19
24
|
};
|
|
20
25
|
/** Read static MDX only. Never build Next, evaluate document JS or request URLs. */
|
|
21
26
|
declare function checkDocumentation(project: RdxProject, options?: DocumentationCheckOptions): DocumentationCheck;
|
|
22
|
-
declare function formatDocumentationCheck(report: DocumentationCheck): string;
|
|
27
|
+
declare function formatDocumentationCheck(report: DocumentationCheck, exceededWarningLimit?: number, knownWarningCount?: number): string;
|
|
23
28
|
|
|
24
29
|
export { checkDocumentation, formatDocumentationCheck };
|
|
25
30
|
export type { DocumentationCheck, DocumentationCheckOptions, DocumentationDiagnostic };
|
package/dist/check/index.js
CHANGED
|
@@ -2,25 +2,25 @@ import {
|
|
|
2
2
|
collectPageRedirects,
|
|
3
3
|
getDocsIndex,
|
|
4
4
|
getSourceOptions
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-EY2T3I2T.js";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
changelogPluginName,
|
|
8
|
+
getContentSources,
|
|
9
|
+
isFallbackPage,
|
|
10
|
+
parseStaticDocument,
|
|
11
|
+
readChangelog
|
|
12
|
+
} from "../chunk-OOKOB72A.js";
|
|
9
13
|
import {
|
|
10
14
|
RdxDocumentLinkError,
|
|
11
15
|
createDocumentLinkResolver,
|
|
12
16
|
readDocumentLinkField
|
|
13
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-T27TQEAY.js";
|
|
18
|
+
import {
|
|
19
|
+
headingText
|
|
20
|
+
} from "../chunk-FPBRKD4M.js";
|
|
14
21
|
import {
|
|
15
22
|
remarkDocumentationComponents
|
|
16
23
|
} from "../chunk-6WNFE2QG.js";
|
|
17
|
-
import {
|
|
18
|
-
changelogPluginName,
|
|
19
|
-
getContentSources,
|
|
20
|
-
isFallbackPage,
|
|
21
|
-
parseStaticDocument,
|
|
22
|
-
readChangelog
|
|
23
|
-
} from "../chunk-OOKOB72A.js";
|
|
24
24
|
|
|
25
25
|
// src/check/index.ts
|
|
26
26
|
import fs from "fs";
|
|
@@ -30,6 +30,44 @@ import remarkGfm from "remark-gfm";
|
|
|
30
30
|
import remarkMdx from "remark-mdx";
|
|
31
31
|
import remarkParse from "remark-parse";
|
|
32
32
|
import { unified } from "unified";
|
|
33
|
+
|
|
34
|
+
// src/check/suggestions.ts
|
|
35
|
+
function editDistance(first, second) {
|
|
36
|
+
let row = Array.from({ length: second.length + 1 }, (_, index) => index);
|
|
37
|
+
for (let i = 0; i < first.length; i++) {
|
|
38
|
+
const next = [i + 1];
|
|
39
|
+
for (let j = 0; j < second.length; j++)
|
|
40
|
+
next.push(
|
|
41
|
+
Math.min(
|
|
42
|
+
next[j] + 1,
|
|
43
|
+
row[j + 1] + 1,
|
|
44
|
+
row[j] + Number(first[i] !== second[j])
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
row = next;
|
|
48
|
+
}
|
|
49
|
+
return row[second.length];
|
|
50
|
+
}
|
|
51
|
+
function closestMatch(value, candidates, name) {
|
|
52
|
+
if (!value || value.length > 120) return;
|
|
53
|
+
const limit = value.length < 4 ? 0 : value.length < 9 ? 1 : 2;
|
|
54
|
+
let best;
|
|
55
|
+
let bestDistance = limit + 1;
|
|
56
|
+
for (const candidate of candidates) {
|
|
57
|
+
const label = name(candidate);
|
|
58
|
+
if (Math.abs(label.length - value.length) > limit) continue;
|
|
59
|
+
const distance = editDistance(value.toLowerCase(), label.toLowerCase());
|
|
60
|
+
if (distance < bestDistance) {
|
|
61
|
+
best = candidate;
|
|
62
|
+
bestDistance = distance;
|
|
63
|
+
} else if (distance === bestDistance) {
|
|
64
|
+
best = void 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return best;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/check/index.ts
|
|
33
71
|
var parser = unified().use(remarkParse).use(remarkGfm).use(remarkMdx).use(remarkDocumentationComponents);
|
|
34
72
|
var markdownParser = unified().use(remarkParse).use(remarkGfm).use(remarkDocumentationComponents);
|
|
35
73
|
var sourceRoute = (source) => [source.basePath ?? "/docs", source.routePrefix].filter(Boolean).join("/");
|
|
@@ -91,12 +129,16 @@ function parse(content, markdown) {
|
|
|
91
129
|
}
|
|
92
130
|
function checkDocumentation(project, options = {}) {
|
|
93
131
|
const diagnostics = [];
|
|
132
|
+
const warnings = [];
|
|
94
133
|
const documents = [];
|
|
134
|
+
const entryPages = /* @__PURE__ */ new Set();
|
|
135
|
+
const referencedPages = /* @__PURE__ */ new Set();
|
|
95
136
|
const routes = /* @__PURE__ */ new Map();
|
|
96
137
|
const coreRoutes = /* @__PURE__ */ new Map();
|
|
97
138
|
const roots = /* @__PURE__ */ new Set(["/robots.txt", "/sitemap.xml"]);
|
|
98
139
|
const prefixes = [];
|
|
99
140
|
const redirects = new Map(Object.entries(options.redirects ?? {}));
|
|
141
|
+
const pageRedirects = /* @__PURE__ */ new Set();
|
|
100
142
|
const failed = /* @__PURE__ */ new Set();
|
|
101
143
|
const redirectSources = [];
|
|
102
144
|
const origin = project.config.metadata.metadataBase ? new URL(project.config.metadata.metadataBase).origin : "https://rdx.invalid";
|
|
@@ -113,34 +155,65 @@ function checkDocumentation(project, options = {}) {
|
|
|
113
155
|
message: value.message ?? String(error)
|
|
114
156
|
});
|
|
115
157
|
}
|
|
116
|
-
|
|
158
|
+
const publicRoot = path.resolve(project.rootDir, "public");
|
|
159
|
+
const publicDirectories = /* @__PURE__ */ new Map();
|
|
160
|
+
function findPublicFile(pathname) {
|
|
117
161
|
if (pathname.includes("\\") || pathname.includes("\0"))
|
|
118
162
|
throw new Error("Use a valid URL with forward slashes.");
|
|
119
|
-
const publicRoot = path.resolve(project.rootDir, "public");
|
|
120
163
|
const asset = path.resolve(publicRoot, `.${pathname}`);
|
|
121
164
|
const relative = path.relative(publicRoot, asset);
|
|
122
165
|
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
123
166
|
throw new Error("The destination escapes public/.");
|
|
124
|
-
let exists = false;
|
|
125
167
|
try {
|
|
126
|
-
|
|
168
|
+
const segments = [];
|
|
169
|
+
let directory = publicRoot;
|
|
170
|
+
for (const segment of relative.split(path.sep)) {
|
|
171
|
+
let entries = publicDirectories.get(directory);
|
|
172
|
+
if (!entries) {
|
|
173
|
+
entries = new Set(fs.readdirSync(directory));
|
|
174
|
+
publicDirectories.set(directory, entries);
|
|
175
|
+
}
|
|
176
|
+
let name = segment;
|
|
177
|
+
if (!entries.has(segment)) {
|
|
178
|
+
const folded = segment.toLowerCase();
|
|
179
|
+
const matches = [...entries].filter(
|
|
180
|
+
(entry) => entry.toLowerCase() === folded
|
|
181
|
+
);
|
|
182
|
+
if (matches.length !== 1) return;
|
|
183
|
+
name = matches[0];
|
|
184
|
+
}
|
|
185
|
+
segments.push(name);
|
|
186
|
+
directory = path.join(directory, name);
|
|
187
|
+
}
|
|
188
|
+
if (fs.statSync(directory).isFile())
|
|
189
|
+
return {
|
|
190
|
+
correctedPath: segments.join(path.sep) === relative ? void 0 : `/${segments.map(encodeURIComponent).join("/")}`
|
|
191
|
+
};
|
|
127
192
|
} catch {
|
|
128
193
|
}
|
|
129
|
-
return exists;
|
|
130
194
|
}
|
|
195
|
+
const caseMismatch = "The path must match the capitalization on disk in public/.";
|
|
131
196
|
const logo = project.config.navbar?.logo;
|
|
132
197
|
if (typeof logo === "string") {
|
|
198
|
+
let suggestion;
|
|
133
199
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
200
|
+
const url = new URL(logo, origin);
|
|
201
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
202
|
+
const asset = findPublicFile(pathname);
|
|
203
|
+
if (!asset)
|
|
136
204
|
throw new Error(`Local file "${pathname}" does not exist in public/.`);
|
|
205
|
+
if (asset.correctedPath) {
|
|
206
|
+
suggestion = `${asset.correctedPath}${url.search}${url.hash}`;
|
|
207
|
+
throw new Error(caseMismatch);
|
|
208
|
+
}
|
|
137
209
|
} catch (error) {
|
|
138
210
|
diagnostics.push({
|
|
139
211
|
file: "rdx.config.ts",
|
|
140
212
|
line: 1,
|
|
141
213
|
column: 1,
|
|
142
214
|
code: "asset",
|
|
143
|
-
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}
|
|
215
|
+
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}`,
|
|
216
|
+
...suggestion ? { suggestion } : {}
|
|
144
217
|
});
|
|
145
218
|
}
|
|
146
219
|
}
|
|
@@ -218,13 +291,16 @@ function checkDocumentation(project, options = {}) {
|
|
|
218
291
|
for (const href of hrefs) routes.set(key(href), document);
|
|
219
292
|
coreRoutes.set(key(documentRoute(source, page)), document);
|
|
220
293
|
if (page === pages[0]) {
|
|
294
|
+
entryPages.add(document);
|
|
221
295
|
routes.set(key(rootFor(source)), document);
|
|
222
296
|
if (source === project.sources[0]) routes.set("/docs", document);
|
|
223
297
|
}
|
|
224
298
|
}
|
|
225
299
|
}
|
|
226
300
|
for (const redirect of collectPageRedirects(redirectSources, syntax)) {
|
|
227
|
-
|
|
301
|
+
const former = key(redirect.source);
|
|
302
|
+
pageRedirects.add(former);
|
|
303
|
+
redirects.set(former, redirect.destination);
|
|
228
304
|
}
|
|
229
305
|
if (project.config.homepage?.enabled) roots.add("/");
|
|
230
306
|
else redirects.set("/", "/docs");
|
|
@@ -284,21 +360,55 @@ function checkDocumentation(project, options = {}) {
|
|
|
284
360
|
}
|
|
285
361
|
function redirectRoute(pathname) {
|
|
286
362
|
const seen = /* @__PURE__ */ new Set();
|
|
363
|
+
let throughPageRedirect = false;
|
|
287
364
|
while (!seen.has(pathname)) {
|
|
288
365
|
seen.add(pathname);
|
|
289
366
|
const exact = redirects.get(pathname);
|
|
367
|
+
throughPageRedirect ||= pageRedirects.has(pathname);
|
|
290
368
|
const prefix = prefixes.find(
|
|
291
369
|
([from]) => pathname === from || pathname.startsWith(`${from}/`)
|
|
292
370
|
);
|
|
293
371
|
const next = exact ? key(exact) : prefix ? prefix[1] + pathname.slice(prefix[0].length) : pathname;
|
|
294
|
-
if (next === pathname) return pathname;
|
|
372
|
+
if (next === pathname) return { pathname, throughPageRedirect };
|
|
295
373
|
pathname = next;
|
|
296
374
|
}
|
|
297
375
|
throw new Error("The destination contains a redirect loop.");
|
|
298
376
|
}
|
|
299
|
-
function
|
|
377
|
+
function matchesFragment(document, hash) {
|
|
378
|
+
return !hash || document.parsed?.anchors.has(decodeURIComponent(hash.slice(1)));
|
|
379
|
+
}
|
|
380
|
+
function suggestFileLink(url, href, sourcePath, source, resolve) {
|
|
381
|
+
const filename = decodeURIComponent(href.split(/[?#]/, 1)[0]);
|
|
382
|
+
const target = closestMatch(
|
|
383
|
+
path.posix.parse(filename).name,
|
|
384
|
+
documents.filter(
|
|
385
|
+
(document) => document.source === source && document.parsed
|
|
386
|
+
),
|
|
387
|
+
(document) => path.parse(document.sourcePath).name
|
|
388
|
+
);
|
|
389
|
+
if (!target || !matchesFragment(target, url.hash)) return;
|
|
390
|
+
const destination = isFallbackPage(project, source, target.sourcePath) ? path.join(
|
|
391
|
+
getSourceOptions(project, source).docsDir,
|
|
392
|
+
target.page.slug + path.extname(target.sourcePath)
|
|
393
|
+
) : target.sourcePath;
|
|
394
|
+
const relative = path.relative(path.dirname(sourcePath), destination).split(path.sep).map(encodeURIComponent).join("/");
|
|
395
|
+
const candidate = `${relative.startsWith("../") ? "" : "./"}${relative}${url.search}${url.hash}`;
|
|
396
|
+
try {
|
|
397
|
+
if (coreRoutes.get(key(resolve(candidate))) === target) return candidate;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
if (!(error instanceof RdxDocumentLinkError)) throw error;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function checkReferences(references, sourcePath, href, lineOffset, resolve, contentSource) {
|
|
300
403
|
for (const reference of references) {
|
|
404
|
+
const location = {
|
|
405
|
+
file: relativeFile(sourcePath),
|
|
406
|
+
line: (reference.position?.start.line ?? 1) + (reference.field ? 0 : lineOffset),
|
|
407
|
+
column: reference.position?.start.column ?? 1
|
|
408
|
+
};
|
|
409
|
+
const label = `${reference.field ? `${reference.field} ` : ""}"${reference.href}"`;
|
|
301
410
|
let code = reference.image ? "asset" : "page";
|
|
411
|
+
let suggestion;
|
|
302
412
|
try {
|
|
303
413
|
const url = new URL(reference.href, `${origin}${href}`);
|
|
304
414
|
if (!["http:", "https:"].includes(url.protocol)) continue;
|
|
@@ -307,9 +417,23 @@ function checkDocumentation(project, options = {}) {
|
|
|
307
417
|
continue;
|
|
308
418
|
let target;
|
|
309
419
|
let pathname;
|
|
420
|
+
let throughPageRedirect = false;
|
|
310
421
|
const explicitDocument = !reference.image && !/^(?:[a-z][\w+.-]*:|\/|#|\?)/i.test(reference.href) && /\.mdx?(?:[?#]|$)/.test(decodeURIComponent(reference.href));
|
|
311
422
|
if (explicitDocument) {
|
|
312
|
-
|
|
423
|
+
let resolved;
|
|
424
|
+
try {
|
|
425
|
+
resolved = resolve(reference.href);
|
|
426
|
+
} catch (error) {
|
|
427
|
+
if (error instanceof RdxDocumentLinkError && error.missing && contentSource)
|
|
428
|
+
suggestion = suggestFileLink(
|
|
429
|
+
url,
|
|
430
|
+
reference.href,
|
|
431
|
+
sourcePath,
|
|
432
|
+
contentSource,
|
|
433
|
+
resolve
|
|
434
|
+
);
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
313
437
|
pathname = key(resolved);
|
|
314
438
|
target = coreRoutes.get(pathname);
|
|
315
439
|
} else {
|
|
@@ -317,34 +441,82 @@ function checkDocumentation(project, options = {}) {
|
|
|
317
441
|
const basePath = project.config.basePath;
|
|
318
442
|
if (basePath && /^(?:https?:|\/\/)/i.test(reference.href) && (pathname === basePath || pathname.startsWith(`${basePath}/`)))
|
|
319
443
|
pathname = pathname.slice(basePath.length) || "/";
|
|
320
|
-
|
|
444
|
+
const redirected = redirectRoute(pathname);
|
|
445
|
+
pathname = redirected.pathname;
|
|
446
|
+
throughPageRedirect = redirected.throughPageRedirect;
|
|
321
447
|
if (!reference.image) target = routes.get(pathname);
|
|
322
448
|
}
|
|
323
449
|
if (target) {
|
|
324
450
|
if (url.hash) {
|
|
325
451
|
code = "anchor";
|
|
326
452
|
const anchor = decodeURIComponent(url.hash.slice(1));
|
|
327
|
-
if (target.parsed && !target.parsed.dynamicIds && !target.parsed.anchors.has(anchor))
|
|
453
|
+
if (target.parsed && !target.parsed.dynamicIds && !target.parsed.anchors.has(anchor)) {
|
|
454
|
+
const match = closestMatch(
|
|
455
|
+
anchor,
|
|
456
|
+
target.parsed.anchors,
|
|
457
|
+
(id) => id
|
|
458
|
+
);
|
|
459
|
+
if (match)
|
|
460
|
+
suggestion = `${reference.href.split("#", 1)[0]}#${encodeURIComponent(match)}`;
|
|
328
461
|
throw new Error(
|
|
329
462
|
`Section "#${anchor}" does not exist in ${relativeFile(target.sourcePath)}.`
|
|
330
463
|
);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if ("page" in target) {
|
|
467
|
+
if (target.sourcePath !== sourcePath) referencedPages.add(target);
|
|
468
|
+
if (throughPageRedirect) {
|
|
469
|
+
const absolute = /^(?:https?:|\/\/)/i.test(reference.href);
|
|
470
|
+
const destination = `${absolute ? origin + (project.config.basePath ?? "") : ""}${target.href}${url.search}${url.hash}`;
|
|
471
|
+
warnings.push({
|
|
472
|
+
...location,
|
|
473
|
+
code: "redirected-link",
|
|
474
|
+
message: `${label} redirects to "${destination}".`,
|
|
475
|
+
suggestion: destination
|
|
476
|
+
});
|
|
477
|
+
}
|
|
331
478
|
}
|
|
332
479
|
continue;
|
|
333
480
|
}
|
|
334
481
|
if (!reference.image && roots.has(pathname)) continue;
|
|
335
482
|
code = reference.image || !/^\/(?:[^/]+\/)?docs(?:\/|$)/.test(pathname) ? "asset" : "page";
|
|
336
|
-
|
|
483
|
+
const asset = findPublicFile(pathname);
|
|
484
|
+
if (asset?.correctedPath) {
|
|
485
|
+
code = "asset";
|
|
486
|
+
const absolute = /^(?:https?:|\/\/)/i.test(reference.href);
|
|
487
|
+
const basePath = project.config.basePath;
|
|
488
|
+
const prefix = absolute && basePath && url.pathname.startsWith(`${basePath}/`) ? basePath : "";
|
|
489
|
+
suggestion = `${absolute ? url.origin : ""}${prefix}${asset.correctedPath}${url.search}${url.hash}`;
|
|
490
|
+
throw new Error(caseMismatch);
|
|
491
|
+
}
|
|
492
|
+
if (!asset) {
|
|
493
|
+
if (code === "page") {
|
|
494
|
+
const edition = redirectSources.filter(({ root }) => pathname.startsWith(`${key(root)}/`)).sort((a, b) => b.root.length - a.root.length)[0];
|
|
495
|
+
const match = edition && closestMatch(
|
|
496
|
+
path.posix.basename(pathname),
|
|
497
|
+
documents.filter(
|
|
498
|
+
(document) => document.source === edition.source && document.parsed && path.posix.dirname(key(document.href)) === path.posix.dirname(pathname)
|
|
499
|
+
),
|
|
500
|
+
(document) => path.posix.basename(key(document.href))
|
|
501
|
+
);
|
|
502
|
+
if (match && routes.get(key(match.href)) === match && (!url.hash || match.parsed?.anchors.has(
|
|
503
|
+
decodeURIComponent(url.hash.slice(1))
|
|
504
|
+
))) {
|
|
505
|
+
const absolute = /^(?:https?:|\/\/)/i.test(reference.href);
|
|
506
|
+
suggestion = `${absolute ? origin + (project.config.basePath ?? "") : ""}${match.href}${url.search}${url.hash}`;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
337
509
|
throw new Error(
|
|
338
510
|
code === "page" ? `Documentation page "${pathname}" does not exist.` : `Local file "${pathname}" does not exist in public/.`
|
|
339
511
|
);
|
|
512
|
+
}
|
|
340
513
|
} catch (error) {
|
|
341
514
|
const value = error instanceof RdxDocumentLinkError ? error.reason : error instanceof Error ? error.message : String(error);
|
|
342
515
|
diagnostics.push({
|
|
343
|
-
|
|
344
|
-
line: (reference.position?.start.line ?? 1) + (reference.field ? 0 : lineOffset),
|
|
345
|
-
column: reference.position?.start.column ?? 1,
|
|
516
|
+
...location,
|
|
346
517
|
code,
|
|
347
|
-
message: `${
|
|
518
|
+
message: `${label}: ${value}`,
|
|
519
|
+
...suggestion ? { suggestion } : {}
|
|
348
520
|
});
|
|
349
521
|
}
|
|
350
522
|
}
|
|
@@ -370,7 +542,8 @@ function checkDocumentation(project, options = {}) {
|
|
|
370
542
|
basePath: contentSource.basePath,
|
|
371
543
|
virtualPaths: !!contentSource.fallbackDocsDir,
|
|
372
544
|
documents: documents.filter((entry) => entry.source === contentSource).map((entry) => entry.page)
|
|
373
|
-
})
|
|
545
|
+
}),
|
|
546
|
+
contentSource
|
|
374
547
|
);
|
|
375
548
|
}
|
|
376
549
|
for (const { release, parsed } of releaseChecks) {
|
|
@@ -401,17 +574,52 @@ function checkDocumentation(project, options = {}) {
|
|
|
401
574
|
diagnostics.map((diagnostic) => [JSON.stringify(diagnostic), diagnostic])
|
|
402
575
|
).values()
|
|
403
576
|
];
|
|
577
|
+
const unlinked = documents.filter(
|
|
578
|
+
(document) => document.parsed && document.source.badge !== "Archived" && !entryPages.has(document) && !referencedPages.has(document) && !isFallbackPage(project, document.source, document.page.sourcePath)
|
|
579
|
+
).map(({ page, href }) => ({
|
|
580
|
+
file: relativeFile(page.sourcePath),
|
|
581
|
+
line: 1,
|
|
582
|
+
column: 1,
|
|
583
|
+
code: "unlinked",
|
|
584
|
+
message: `No inbound content links to ${href}. Link to this page from a relevant document or release note.`
|
|
585
|
+
}));
|
|
586
|
+
const uniqueWarnings = [
|
|
587
|
+
...new Map(
|
|
588
|
+
[...warnings, ...unlinked].map((warning) => [
|
|
589
|
+
JSON.stringify(warning),
|
|
590
|
+
warning
|
|
591
|
+
])
|
|
592
|
+
).values()
|
|
593
|
+
].sort(
|
|
594
|
+
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.message.localeCompare(b.message)
|
|
595
|
+
);
|
|
404
596
|
return {
|
|
405
597
|
checkedPages: new Set(documents.map((document) => document.page.sourcePath)).size + releases.length,
|
|
406
|
-
diagnostics: unique
|
|
598
|
+
diagnostics: unique,
|
|
599
|
+
...uniqueWarnings.length ? { warnings: uniqueWarnings } : {}
|
|
407
600
|
};
|
|
408
601
|
}
|
|
409
|
-
function formatDocumentationCheck(report) {
|
|
410
|
-
const lines = report.diagnostics.
|
|
411
|
-
|
|
412
|
-
)
|
|
602
|
+
function formatDocumentationCheck(report, exceededWarningLimit, knownWarningCount) {
|
|
603
|
+
const lines = report.diagnostics.flatMap((entry) => [
|
|
604
|
+
`${entry.file}:${entry.line}:${entry.column} [${entry.code}] ${entry.message}`,
|
|
605
|
+
...entry.suggestion ? [` Did you mean ${JSON.stringify(entry.suggestion)}?`] : []
|
|
606
|
+
]);
|
|
607
|
+
for (const warning of report.warnings ?? [])
|
|
608
|
+
lines.push(
|
|
609
|
+
`${warning.file}:${warning.line}:${warning.column} [warning: ${warning.code}] ${warning.message}`
|
|
610
|
+
);
|
|
611
|
+
const displayedWarningCount = report.warnings?.length ?? 0;
|
|
612
|
+
const warningCount = displayedWarningCount + (knownWarningCount ?? 0);
|
|
613
|
+
if (exceededWarningLimit !== void 0)
|
|
614
|
+
lines.push(`Warning limit exceeded (maximum ${exceededWarningLimit}).`);
|
|
615
|
+
const baselineExceeded = knownWarningCount !== void 0 && displayedWarningCount > 0;
|
|
616
|
+
if (knownWarningCount !== void 0)
|
|
617
|
+
lines.push(
|
|
618
|
+
`Warning baseline: ${knownWarningCount} known, ${displayedWarningCount} new.`
|
|
619
|
+
);
|
|
620
|
+
const failed = report.diagnostics.length > 0 || exceededWarningLimit !== void 0 || baselineExceeded;
|
|
413
621
|
lines.push(
|
|
414
|
-
`RDX check ${
|
|
622
|
+
`RDX check ${failed ? "failed" : "passed"}: ${report.checkedPages} ${report.checkedPages === 1 ? "page" : "pages"} checked, ${report.diagnostics.length} ${report.diagnostics.length === 1 ? "problem" : "problems"}${warningCount ? `, ${warningCount} ${warningCount === 1 ? "warning" : "warnings"}` : ""}.`
|
|
415
623
|
);
|
|
416
624
|
return lines.join("\n");
|
|
417
625
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseStaticDocument
|
|
3
|
+
} from "./chunk-OOKOB72A.js";
|
|
1
4
|
import {
|
|
2
5
|
DEFAULT_POSITION,
|
|
3
6
|
documentExtension,
|
|
4
7
|
orderedName,
|
|
5
8
|
slugFromRelativePath
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
parseStaticDocument
|
|
9
|
-
} from "./chunk-OOKOB72A.js";
|
|
9
|
+
} from "./chunk-T27TQEAY.js";
|
|
10
10
|
|
|
11
11
|
// src/content/page-redirects.ts
|
|
12
12
|
function readRedirectFrom(value) {
|
|
@@ -15,12 +15,14 @@ function slugFromRelativePath(relativePath) {
|
|
|
15
15
|
|
|
16
16
|
// src/content/document-links.ts
|
|
17
17
|
var RdxDocumentLinkError = class extends Error {
|
|
18
|
-
constructor(sourcePath, href, reason) {
|
|
18
|
+
constructor(sourcePath, href, reason, missing = false) {
|
|
19
19
|
super(`[RDX] Invalid document link "${href}" in ${sourcePath}: ${reason}`);
|
|
20
20
|
this.reason = reason;
|
|
21
|
+
this.missing = missing;
|
|
21
22
|
this.name = "RdxDocumentLinkError";
|
|
22
23
|
}
|
|
23
24
|
reason;
|
|
25
|
+
missing;
|
|
24
26
|
};
|
|
25
27
|
function readDocumentLinkField(value, field) {
|
|
26
28
|
if (value === void 0) return [];
|
|
@@ -87,8 +89,8 @@ function createDocumentLinkResolver(options) {
|
|
|
87
89
|
return href;
|
|
88
90
|
}
|
|
89
91
|
if (!/\.mdx?$/.test(decoded)) return href;
|
|
90
|
-
const fail = (reason) => {
|
|
91
|
-
throw new RdxDocumentLinkError(current, href, reason);
|
|
92
|
+
const fail = (reason, missing = false) => {
|
|
93
|
+
throw new RdxDocumentLinkError(current, href, reason, missing);
|
|
92
94
|
};
|
|
93
95
|
if (path2.isAbsolute(decoded) || decoded.includes("\\") || decoded.includes("\0"))
|
|
94
96
|
fail("use forward-slash relative paths without null characters.");
|
|
@@ -102,7 +104,8 @@ function createDocumentLinkResolver(options) {
|
|
|
102
104
|
`${slugFromRelativePath(relative)}${path2.extname(relative)}`
|
|
103
105
|
)
|
|
104
106
|
) : void 0) ?? fail(
|
|
105
|
-
`"${relative}" does not exist in this documentation source${options.routePrefix ? ` (${options.routePrefix})` : ""}
|
|
107
|
+
`"${relative}" does not exist in this documentation source${options.routePrefix ? ` (${options.routePrefix})` : ""}.`,
|
|
108
|
+
true
|
|
106
109
|
);
|
|
107
110
|
if ((routeCounts.get(slug) ?? 0) > 1)
|
|
108
111
|
fail("the destination has an ambiguous documentation route.");
|
|
@@ -17,7 +17,8 @@ interface DocumentLinkOptions {
|
|
|
17
17
|
}
|
|
18
18
|
declare class RdxDocumentLinkError extends Error {
|
|
19
19
|
readonly reason: string;
|
|
20
|
-
|
|
20
|
+
readonly missing: boolean;
|
|
21
|
+
constructor(sourcePath: string, href: string, reason: string, missing?: boolean);
|
|
21
22
|
}
|
|
22
23
|
declare function getRelatedDocumentLinks(value: unknown, options: Omit<DocumentLinkOptions, 'documents'> & {
|
|
23
24
|
documents: readonly RdxDocPage[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _lexibase_rdx_types from '@lexibase/rdx-types';
|
|
2
2
|
import { RdxDocsOptions, RdxDocCategory, RdxDocument, RdxContentSource, RdxDocPage, RdxProject } from '@lexibase/rdx-types';
|
|
3
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-Bf2lDSDI.js';
|
|
4
|
-
export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver, g as getRelatedDocumentLinks } from './document-links-
|
|
4
|
+
export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver, g as getRelatedDocumentLinks } from './document-links-UCwHmYXf.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Reads the documentation tree from the user's project. The URL slug always
|
package/dist/index.js
CHANGED
|
@@ -6,12 +6,7 @@ import {
|
|
|
6
6
|
getProjectDocsPaths,
|
|
7
7
|
getSourceOptions,
|
|
8
8
|
resolveDocsRoute
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import {
|
|
11
|
-
RdxDocumentLinkError,
|
|
12
|
-
createDocumentLinkResolver,
|
|
13
|
-
getRelatedDocumentLinks
|
|
14
|
-
} from "./chunk-KRVOWYZS.js";
|
|
9
|
+
} from "./chunk-EY2T3I2T.js";
|
|
15
10
|
import {
|
|
16
11
|
createRdxProject,
|
|
17
12
|
defineConfig,
|
|
@@ -26,6 +21,11 @@ import {
|
|
|
26
21
|
isFallbackPage,
|
|
27
22
|
resolveProjectPath
|
|
28
23
|
} from "./chunk-OOKOB72A.js";
|
|
24
|
+
import {
|
|
25
|
+
RdxDocumentLinkError,
|
|
26
|
+
createDocumentLinkResolver,
|
|
27
|
+
getRelatedDocumentLinks
|
|
28
|
+
} from "./chunk-T27TQEAY.js";
|
|
29
29
|
|
|
30
30
|
// src/content/base-path.ts
|
|
31
31
|
function withBasePath(href, basePath) {
|
package/dist/mdx/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DocumentLinkOptions } from '../document-links-
|
|
2
|
-
export { r as remarkDocumentLinks } from '../document-links-
|
|
1
|
+
import { D as DocumentLinkOptions } from '../document-links-UCwHmYXf.js';
|
|
2
|
+
export { r as remarkDocumentLinks } from '../document-links-UCwHmYXf.js';
|
|
3
3
|
export { default as rehypeDocumentationHeadings } from 'rehype-slug';
|
|
4
4
|
import rehypeShiki from '@shikijs/rehype';
|
|
5
5
|
import { RdxProject, RDXConfig } from '@lexibase/rdx-types';
|
package/dist/mdx/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexibase/rdx-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "Content indexing and document utilities for RDX documentation projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/lexibase/rdx#readme",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@
|
|
48
|
+
"@lexibase/rdx-types": "2.8.0",
|
|
49
|
+
"@shikijs/rehype": "^4.6.0",
|
|
49
50
|
"github-slugger": "^2.0.0",
|
|
50
51
|
"gray-matter": "^4.0.3",
|
|
51
52
|
"rehype-slug": "^6.0.0",
|
|
@@ -54,15 +55,14 @@
|
|
|
54
55
|
"remark-mdx": "^3.1.1",
|
|
55
56
|
"remark-parse": "^11.0.0",
|
|
56
57
|
"remark-stringify": "^11.0.0",
|
|
57
|
-
"shiki": "^4.
|
|
58
|
-
"unified": "^11.0.5"
|
|
59
|
-
"@lexibase/rdx-types": "2.8.0"
|
|
58
|
+
"shiki": "^4.6.0",
|
|
59
|
+
"unified": "^11.0.5"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@types/node": "^22.15.3",
|
|
63
|
-
"@types/react": "19.3.0",
|
|
64
62
|
"@rdx/eslint-config": "1.0.0",
|
|
65
|
-
"@rdx/typescript-config": "1.0.0"
|
|
63
|
+
"@rdx/typescript-config": "1.0.0",
|
|
64
|
+
"@types/node": "^22.15.3",
|
|
65
|
+
"@types/react": "19.3.0"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": "^22.18.0 || ^24.11.0"
|