@lexibase/rdx-core 3.3.0 → 3.5.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.
- package/dist/check/index.js +125 -37
- package/dist/chunk-F5XY2FG4.js +269 -0
- package/dist/{chunk-GR2GL7HT.js → chunk-KRVOWYZS.js} +29 -0
- package/dist/{chunk-5RUC6AZX.js → chunk-LC6NZKLP.js} +65 -16
- package/dist/{chunk-CRQU7OO4.js → chunk-PJCL6IZD.js} +50 -100
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +19 -5
- package/dist/{document-links-BQXyBubK.d.ts → document-links-CuuelWKE.d.ts} +9 -1
- package/dist/{index-CIBgPARs.d.ts → index-Bf2lDSDI.d.ts} +25 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.js +13 -9
- package/dist/mdx/index.d.ts +2 -2
- package/dist/mdx/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-SNNEXRLQ.js +0 -75
package/dist/check/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
+
collectPageRedirects,
|
|
2
3
|
getDocsIndex,
|
|
3
|
-
getSourceOptions
|
|
4
|
-
|
|
5
|
-
} from "../chunk-5RUC6AZX.js";
|
|
4
|
+
getSourceOptions
|
|
5
|
+
} from "../chunk-LC6NZKLP.js";
|
|
6
6
|
import {
|
|
7
|
+
changelogPluginName,
|
|
7
8
|
getContentSources,
|
|
8
|
-
isFallbackPage
|
|
9
|
-
|
|
9
|
+
isFallbackPage,
|
|
10
|
+
parseStaticDocument,
|
|
11
|
+
readChangelog
|
|
12
|
+
} from "../chunk-F5XY2FG4.js";
|
|
10
13
|
import {
|
|
11
14
|
RdxDocumentLinkError,
|
|
12
|
-
createDocumentLinkResolver
|
|
13
|
-
|
|
15
|
+
createDocumentLinkResolver,
|
|
16
|
+
readDocumentLinkField
|
|
17
|
+
} from "../chunk-KRVOWYZS.js";
|
|
14
18
|
import {
|
|
15
19
|
headingText
|
|
16
20
|
} from "../chunk-FPBRKD4M.js";
|
|
@@ -94,6 +98,7 @@ function checkDocumentation(project, options = {}) {
|
|
|
94
98
|
const prefixes = [];
|
|
95
99
|
const redirects = new Map(Object.entries(options.redirects ?? {}));
|
|
96
100
|
const failed = /* @__PURE__ */ new Set();
|
|
101
|
+
const redirectSources = [];
|
|
97
102
|
const origin = project.config.metadata.metadataBase ? new URL(project.config.metadata.metadataBase).origin : "https://rdx.invalid";
|
|
98
103
|
const key = (href) => decodeURIComponent(new URL(href, origin).pathname).replace(/\/$/, "") || "/";
|
|
99
104
|
const rootFor = options.sourceRoute ?? sourceRoute;
|
|
@@ -150,6 +155,7 @@ function checkDocumentation(project, options = {}) {
|
|
|
150
155
|
}
|
|
151
156
|
for (const source of sources) {
|
|
152
157
|
if (source.redirectTo !== void 0) {
|
|
158
|
+
redirectSources.push({ source, root: rootFor(source), pages: [] });
|
|
153
159
|
const destination = sources.find(
|
|
154
160
|
(entry) => entry.routePrefix === source.redirectTo && entry.basePath === source.basePath
|
|
155
161
|
);
|
|
@@ -188,13 +194,21 @@ function checkDocumentation(project, options = {}) {
|
|
|
188
194
|
continue;
|
|
189
195
|
}
|
|
190
196
|
roots.add(key(rootFor(source)));
|
|
197
|
+
const redirectSource = {
|
|
198
|
+
source,
|
|
199
|
+
root: rootFor(source),
|
|
200
|
+
pages: []
|
|
201
|
+
};
|
|
202
|
+
redirectSources.push(redirectSource);
|
|
191
203
|
if (project.config.search)
|
|
192
204
|
roots.add(`/rdx-search/${source.routePrefix || "_"}`);
|
|
193
205
|
for (const page of pages) {
|
|
194
206
|
const hrefs = options.documentRoutes?.(source, page, pages) ?? [
|
|
195
207
|
documentRoute(source, page)
|
|
196
208
|
];
|
|
209
|
+
redirectSource.pages.push({ page, hrefs });
|
|
197
210
|
const document = {
|
|
211
|
+
sourcePath: page.sourcePath,
|
|
198
212
|
page,
|
|
199
213
|
source,
|
|
200
214
|
href: hrefs[0],
|
|
@@ -209,15 +223,61 @@ function checkDocumentation(project, options = {}) {
|
|
|
209
223
|
}
|
|
210
224
|
}
|
|
211
225
|
}
|
|
226
|
+
for (const redirect of collectPageRedirects(redirectSources, syntax)) {
|
|
227
|
+
redirects.set(key(redirect.source), redirect.destination);
|
|
228
|
+
}
|
|
212
229
|
if (project.config.homepage?.enabled) roots.add("/");
|
|
213
230
|
else redirects.set("/", "/docs");
|
|
231
|
+
const changelog = project.config.plugins.some(
|
|
232
|
+
({ name }) => name === changelogPluginName
|
|
233
|
+
);
|
|
234
|
+
const releases = changelog ? readChangelog(project.rootDir, syntax) : [];
|
|
235
|
+
const changelogAnchors = /* @__PURE__ */ new Set();
|
|
236
|
+
let changelogHasUnknownAnchors = false;
|
|
237
|
+
const releaseChecks = releases.flatMap((release) => {
|
|
238
|
+
changelogAnchors.add(`v${release.version}`);
|
|
239
|
+
try {
|
|
240
|
+
const parsed = parse(release.content, release.sourcePath.endsWith(".md"));
|
|
241
|
+
for (const anchor of parsed.anchors) changelogAnchors.add(anchor);
|
|
242
|
+
changelogHasUnknownAnchors ||= parsed.dynamicIds;
|
|
243
|
+
return [{ release, parsed }];
|
|
244
|
+
} catch (error) {
|
|
245
|
+
changelogHasUnknownAnchors = true;
|
|
246
|
+
syntax(error, release.sourcePath, release.lineOffset);
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (changelog) {
|
|
251
|
+
routes.set("/changelog", {
|
|
252
|
+
sourcePath: path.join(project.rootDir, "changelog"),
|
|
253
|
+
parsed: {
|
|
254
|
+
anchors: changelogAnchors,
|
|
255
|
+
references: [],
|
|
256
|
+
dynamicIds: changelogHasUnknownAnchors
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
roots.add("/changelog/rss.xml");
|
|
260
|
+
}
|
|
214
261
|
for (const document of documents) {
|
|
215
262
|
if (failed.has(document.page.sourcePath)) continue;
|
|
216
263
|
try {
|
|
217
264
|
const raw = fs.readFileSync(document.page.sourcePath, "utf8");
|
|
218
|
-
const content = parseStaticDocument(raw)
|
|
265
|
+
const { content, data } = parseStaticDocument(raw);
|
|
219
266
|
document.lineOffset = (raw.slice(0, raw.length - content.length).match(/\n/g) ?? []).length;
|
|
220
267
|
document.parsed = parse(content, document.page.sourcePath.endsWith(".md"));
|
|
268
|
+
for (const field of ["related", "prerequisites"]) {
|
|
269
|
+
try {
|
|
270
|
+
document.parsed.references.push(
|
|
271
|
+
...readDocumentLinkField(data[field], field).map((href, index) => ({
|
|
272
|
+
href,
|
|
273
|
+
image: false,
|
|
274
|
+
field: `${field}[${index}]`
|
|
275
|
+
}))
|
|
276
|
+
);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
syntax(error, document.page.sourcePath);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
221
281
|
} catch (error) {
|
|
222
282
|
syntax(error, document.page.sourcePath, document.lineOffset);
|
|
223
283
|
}
|
|
@@ -236,31 +296,11 @@ function checkDocumentation(project, options = {}) {
|
|
|
236
296
|
}
|
|
237
297
|
throw new Error("The destination contains a redirect loop.");
|
|
238
298
|
}
|
|
239
|
-
|
|
240
|
-
const
|
|
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) {
|
|
299
|
+
function checkReferences(references, sourcePath, href, lineOffset, resolve) {
|
|
300
|
+
for (const reference of references) {
|
|
258
301
|
let code = reference.image ? "asset" : "page";
|
|
259
302
|
try {
|
|
260
|
-
const url = new URL(
|
|
261
|
-
reference.href,
|
|
262
|
-
`${origin}${contentSource === document.source ? document.href : documentRoute(contentSource, document.page)}`
|
|
263
|
-
);
|
|
303
|
+
const url = new URL(reference.href, `${origin}${href}`);
|
|
264
304
|
if (!["http:", "https:"].includes(url.protocol)) continue;
|
|
265
305
|
if (url.origin !== origin) continue;
|
|
266
306
|
if (!project.config.metadata.metadataBase && /^(?:[a-z][\w+.-]*:|\/\/)/i.test(reference.href))
|
|
@@ -273,7 +313,11 @@ function checkDocumentation(project, options = {}) {
|
|
|
273
313
|
pathname = key(resolved);
|
|
274
314
|
target = coreRoutes.get(pathname);
|
|
275
315
|
} else {
|
|
276
|
-
pathname =
|
|
316
|
+
pathname = key(url.href);
|
|
317
|
+
const basePath = project.config.basePath;
|
|
318
|
+
if (basePath && /^(?:https?:|\/\/)/i.test(reference.href) && (pathname === basePath || pathname.startsWith(`${basePath}/`)))
|
|
319
|
+
pathname = pathname.slice(basePath.length) || "/";
|
|
320
|
+
pathname = redirectRoute(pathname);
|
|
277
321
|
if (!reference.image) target = routes.get(pathname);
|
|
278
322
|
}
|
|
279
323
|
if (target) {
|
|
@@ -282,7 +326,7 @@ function checkDocumentation(project, options = {}) {
|
|
|
282
326
|
const anchor = decodeURIComponent(url.hash.slice(1));
|
|
283
327
|
if (target.parsed && !target.parsed.dynamicIds && !target.parsed.anchors.has(anchor))
|
|
284
328
|
throw new Error(
|
|
285
|
-
`Section "#${anchor}" does not exist in ${relativeFile(target.
|
|
329
|
+
`Section "#${anchor}" does not exist in ${relativeFile(target.sourcePath)}.`
|
|
286
330
|
);
|
|
287
331
|
}
|
|
288
332
|
continue;
|
|
@@ -296,15 +340,59 @@ function checkDocumentation(project, options = {}) {
|
|
|
296
340
|
} catch (error) {
|
|
297
341
|
const value = error instanceof RdxDocumentLinkError ? error.reason : error instanceof Error ? error.message : String(error);
|
|
298
342
|
diagnostics.push({
|
|
299
|
-
file: relativeFile(
|
|
300
|
-
line: (reference.position?.start.line ?? 1) +
|
|
343
|
+
file: relativeFile(sourcePath),
|
|
344
|
+
line: (reference.position?.start.line ?? 1) + (reference.field ? 0 : lineOffset),
|
|
301
345
|
column: reference.position?.start.column ?? 1,
|
|
302
346
|
code,
|
|
303
|
-
message: `"${reference.href}": ${value}`
|
|
347
|
+
message: `${reference.field ? `${reference.field} ` : ""}"${reference.href}": ${value}`
|
|
304
348
|
});
|
|
305
349
|
}
|
|
306
350
|
}
|
|
307
351
|
}
|
|
352
|
+
for (const document of documents) {
|
|
353
|
+
if (!document.parsed) continue;
|
|
354
|
+
const contentSource = isFallbackPage(
|
|
355
|
+
project,
|
|
356
|
+
document.source,
|
|
357
|
+
document.page.sourcePath
|
|
358
|
+
) ? sources.find(
|
|
359
|
+
(source) => source.id === document.source.id && source.docsDir === document.source.fallbackDocsDir && !source.fallbackDocsDir
|
|
360
|
+
) : document.source;
|
|
361
|
+
checkReferences(
|
|
362
|
+
document.parsed.references,
|
|
363
|
+
document.page.sourcePath,
|
|
364
|
+
contentSource === document.source ? document.href : documentRoute(contentSource, document.page),
|
|
365
|
+
document.lineOffset,
|
|
366
|
+
createDocumentLinkResolver({
|
|
367
|
+
sourceRoot: getSourceOptions(project, contentSource).docsDir,
|
|
368
|
+
sourcePath: document.page.sourcePath,
|
|
369
|
+
routePrefix: contentSource.routePrefix,
|
|
370
|
+
basePath: contentSource.basePath,
|
|
371
|
+
virtualPaths: !!contentSource.fallbackDocsDir,
|
|
372
|
+
documents: documents.filter((entry) => entry.source === contentSource).map((entry) => entry.page)
|
|
373
|
+
})
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
for (const { release, parsed } of releaseChecks) {
|
|
377
|
+
checkReferences(
|
|
378
|
+
[
|
|
379
|
+
...release.links.map(({ href }, index) => ({
|
|
380
|
+
href,
|
|
381
|
+
image: false,
|
|
382
|
+
field: `links[${index}].href`
|
|
383
|
+
})),
|
|
384
|
+
...parsed.references
|
|
385
|
+
],
|
|
386
|
+
release.sourcePath,
|
|
387
|
+
"/changelog",
|
|
388
|
+
release.lineOffset,
|
|
389
|
+
createDocumentLinkResolver({
|
|
390
|
+
sourceRoot: project.rootDir,
|
|
391
|
+
sourcePath: release.sourcePath,
|
|
392
|
+
documents: []
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
}
|
|
308
396
|
diagnostics.sort(
|
|
309
397
|
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column
|
|
310
398
|
);
|
|
@@ -314,7 +402,7 @@ function checkDocumentation(project, options = {}) {
|
|
|
314
402
|
).values()
|
|
315
403
|
];
|
|
316
404
|
return {
|
|
317
|
-
checkedPages: new Set(documents.map((document) => document.page.sourcePath)).size,
|
|
405
|
+
checkedPages: new Set(documents.map((document) => document.page.sourcePath)).size + releases.length,
|
|
318
406
|
diagnostics: unique
|
|
319
407
|
};
|
|
320
408
|
}
|
|
@@ -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
|
+
};
|
|
@@ -22,6 +22,33 @@ var RdxDocumentLinkError = class extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
reason;
|
|
24
24
|
};
|
|
25
|
+
function readDocumentLinkField(value, field) {
|
|
26
|
+
if (value === void 0) return [];
|
|
27
|
+
if (!Array.isArray(value))
|
|
28
|
+
throw new Error(
|
|
29
|
+
`${field} must be an array of relative Markdown file paths.`
|
|
30
|
+
);
|
|
31
|
+
return value.map((entry, index) => {
|
|
32
|
+
if (typeof entry !== "string" || /^(?:[a-z][a-z\d+.-]*:|\/)/i.test(entry.trim()) || !/^[^?#\\]+\.mdx?$/.test(entry.trim()))
|
|
33
|
+
throw new Error(
|
|
34
|
+
`${field}[${index}] must be a relative .md or .mdx file path.`
|
|
35
|
+
);
|
|
36
|
+
return entry.trim();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function getRelatedDocumentLinks(value, options, currentSlug, hrefFor, field = "related") {
|
|
40
|
+
const paths = readDocumentLinkField(value, field);
|
|
41
|
+
if (!paths.length) return [];
|
|
42
|
+
const resolve = createDocumentLinkResolver({
|
|
43
|
+
...options,
|
|
44
|
+
documentHref: (slug) => slug
|
|
45
|
+
});
|
|
46
|
+
const pages = new Map(options.documents.map((page) => [page.slug, page]));
|
|
47
|
+
return [...new Set(paths.map(resolve))].flatMap((slug) => {
|
|
48
|
+
const page = pages.get(slug);
|
|
49
|
+
return page && page.slug !== currentSlug ? [{ href: hrefFor(page), label: page.navTitle ?? page.title }] : [];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
25
52
|
function createDocumentLinkResolver(options) {
|
|
26
53
|
const root = path2.resolve(options.sourceRoot);
|
|
27
54
|
const current = path2.resolve(options.sourcePath);
|
|
@@ -150,6 +177,8 @@ export {
|
|
|
150
177
|
orderedName,
|
|
151
178
|
slugFromRelativePath,
|
|
152
179
|
RdxDocumentLinkError,
|
|
180
|
+
readDocumentLinkField,
|
|
181
|
+
getRelatedDocumentLinks,
|
|
153
182
|
createDocumentLinkResolver,
|
|
154
183
|
remarkDocumentLinks
|
|
155
184
|
};
|