@lexibase/rdx-core 3.6.0 → 3.6.2
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 +84 -15
- package/package.json +1 -1
package/dist/check/index.js
CHANGED
|
@@ -77,7 +77,7 @@ function walk(node, visit) {
|
|
|
77
77
|
visit(node);
|
|
78
78
|
for (const child of node.children ?? []) walk(child, visit);
|
|
79
79
|
}
|
|
80
|
-
function parse(content, markdown) {
|
|
80
|
+
function parse(content, markdown, duplicateAnchor) {
|
|
81
81
|
const processor = markdown ? markdownParser : parser;
|
|
82
82
|
const tree = processor.runSync(processor.parse(content), {
|
|
83
83
|
value: content
|
|
@@ -92,7 +92,17 @@ function parse(content, markdown) {
|
|
|
92
92
|
definitions.set(identifier(node.identifier), node.url);
|
|
93
93
|
});
|
|
94
94
|
walk(tree, (node) => {
|
|
95
|
-
|
|
95
|
+
const nodeAnchors = /* @__PURE__ */ new Set();
|
|
96
|
+
if (node.type === "heading")
|
|
97
|
+
nodeAnchors.add(slugger.slug(headingText(node)));
|
|
98
|
+
for (const attribute of node.attributes ?? []) {
|
|
99
|
+
if (typeof attribute.value === "string" && (attribute.name === "id" || node.name === "a" && attribute.name === "name"))
|
|
100
|
+
nodeAnchors.add(attribute.value);
|
|
101
|
+
}
|
|
102
|
+
for (const id of nodeAnchors) {
|
|
103
|
+
if (anchors.has(id)) duplicateAnchor(id, node.position);
|
|
104
|
+
anchors.add(id);
|
|
105
|
+
}
|
|
96
106
|
if (node.type === "link" || node.type === "image") {
|
|
97
107
|
if (typeof node.url === "string")
|
|
98
108
|
references.push({
|
|
@@ -113,8 +123,8 @@ function parse(content, markdown) {
|
|
|
113
123
|
if (!node.type.startsWith("mdxJsx")) return;
|
|
114
124
|
for (const attribute of node.attributes ?? []) {
|
|
115
125
|
if (attribute.name === "id" || node.name === "a" && attribute.name === "name") {
|
|
116
|
-
if (typeof attribute.value
|
|
117
|
-
|
|
126
|
+
if (attribute.value && typeof attribute.value !== "string")
|
|
127
|
+
dynamicIds = true;
|
|
118
128
|
}
|
|
119
129
|
if ((node.name === "a" && attribute.name === "href" || node.name === "img" && attribute.name === "src") && typeof attribute.value === "string") {
|
|
120
130
|
references.push({
|
|
@@ -155,34 +165,76 @@ function checkDocumentation(project, options = {}) {
|
|
|
155
165
|
message: value.message ?? String(error)
|
|
156
166
|
});
|
|
157
167
|
}
|
|
158
|
-
function
|
|
168
|
+
function parseDocument(content, file, offset) {
|
|
169
|
+
return parse(content, file.endsWith(".md"), (id, position) => {
|
|
170
|
+
diagnostics.push({
|
|
171
|
+
file: relativeFile(file),
|
|
172
|
+
line: (position?.start.line ?? 1) + offset,
|
|
173
|
+
column: position?.start.column ?? 1,
|
|
174
|
+
code: "anchor",
|
|
175
|
+
message: `Duplicate section ID "${id}". Use a unique ID for each destination on this page.`
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const publicRoot = path.resolve(project.rootDir, "public");
|
|
180
|
+
const publicDirectories = /* @__PURE__ */ new Map();
|
|
181
|
+
function findPublicFile(pathname) {
|
|
159
182
|
if (pathname.includes("\\") || pathname.includes("\0"))
|
|
160
183
|
throw new Error("Use a valid URL with forward slashes.");
|
|
161
|
-
const publicRoot = path.resolve(project.rootDir, "public");
|
|
162
184
|
const asset = path.resolve(publicRoot, `.${pathname}`);
|
|
163
185
|
const relative = path.relative(publicRoot, asset);
|
|
164
186
|
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
165
187
|
throw new Error("The destination escapes public/.");
|
|
166
|
-
let exists = false;
|
|
167
188
|
try {
|
|
168
|
-
|
|
189
|
+
const segments = [];
|
|
190
|
+
let directory = publicRoot;
|
|
191
|
+
for (const segment of relative.split(path.sep)) {
|
|
192
|
+
let entries = publicDirectories.get(directory);
|
|
193
|
+
if (!entries) {
|
|
194
|
+
entries = new Set(fs.readdirSync(directory));
|
|
195
|
+
publicDirectories.set(directory, entries);
|
|
196
|
+
}
|
|
197
|
+
let name = segment;
|
|
198
|
+
if (!entries.has(segment)) {
|
|
199
|
+
const folded = segment.toLowerCase();
|
|
200
|
+
const matches = [...entries].filter(
|
|
201
|
+
(entry) => entry.toLowerCase() === folded
|
|
202
|
+
);
|
|
203
|
+
if (matches.length !== 1) return;
|
|
204
|
+
name = matches[0];
|
|
205
|
+
}
|
|
206
|
+
segments.push(name);
|
|
207
|
+
directory = path.join(directory, name);
|
|
208
|
+
}
|
|
209
|
+
if (fs.statSync(directory).isFile())
|
|
210
|
+
return {
|
|
211
|
+
correctedPath: segments.join(path.sep) === relative ? void 0 : `/${segments.map(encodeURIComponent).join("/")}`
|
|
212
|
+
};
|
|
169
213
|
} catch {
|
|
170
214
|
}
|
|
171
|
-
return exists;
|
|
172
215
|
}
|
|
216
|
+
const caseMismatch = "The path must match the capitalization on disk in public/.";
|
|
173
217
|
const logo = project.config.navbar?.logo;
|
|
174
218
|
if (typeof logo === "string") {
|
|
219
|
+
let suggestion;
|
|
175
220
|
try {
|
|
176
|
-
const
|
|
177
|
-
|
|
221
|
+
const url = new URL(logo, origin);
|
|
222
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
223
|
+
const asset = findPublicFile(pathname);
|
|
224
|
+
if (!asset)
|
|
178
225
|
throw new Error(`Local file "${pathname}" does not exist in public/.`);
|
|
226
|
+
if (asset.correctedPath) {
|
|
227
|
+
suggestion = `${asset.correctedPath}${url.search}${url.hash}`;
|
|
228
|
+
throw new Error(caseMismatch);
|
|
229
|
+
}
|
|
179
230
|
} catch (error) {
|
|
180
231
|
diagnostics.push({
|
|
181
232
|
file: "rdx.config.ts",
|
|
182
233
|
line: 1,
|
|
183
234
|
column: 1,
|
|
184
235
|
code: "asset",
|
|
185
|
-
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}
|
|
236
|
+
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}`,
|
|
237
|
+
...suggestion ? { suggestion } : {}
|
|
186
238
|
});
|
|
187
239
|
}
|
|
188
240
|
}
|
|
@@ -282,7 +334,11 @@ function checkDocumentation(project, options = {}) {
|
|
|
282
334
|
const releaseChecks = releases.flatMap((release) => {
|
|
283
335
|
changelogAnchors.add(`v${release.version}`);
|
|
284
336
|
try {
|
|
285
|
-
const parsed =
|
|
337
|
+
const parsed = parseDocument(
|
|
338
|
+
release.content,
|
|
339
|
+
release.sourcePath,
|
|
340
|
+
release.lineOffset
|
|
341
|
+
);
|
|
286
342
|
for (const anchor of parsed.anchors) changelogAnchors.add(anchor);
|
|
287
343
|
changelogHasUnknownAnchors ||= parsed.dynamicIds;
|
|
288
344
|
return [{ release, parsed }];
|
|
@@ -309,7 +365,11 @@ function checkDocumentation(project, options = {}) {
|
|
|
309
365
|
const raw = fs.readFileSync(document.page.sourcePath, "utf8");
|
|
310
366
|
const { content, data } = parseStaticDocument(raw);
|
|
311
367
|
document.lineOffset = (raw.slice(0, raw.length - content.length).match(/\n/g) ?? []).length;
|
|
312
|
-
document.parsed =
|
|
368
|
+
document.parsed = parseDocument(
|
|
369
|
+
content,
|
|
370
|
+
document.page.sourcePath,
|
|
371
|
+
document.lineOffset
|
|
372
|
+
);
|
|
313
373
|
for (const field of ["related", "prerequisites"]) {
|
|
314
374
|
try {
|
|
315
375
|
document.parsed.references.push(
|
|
@@ -449,7 +509,16 @@ function checkDocumentation(project, options = {}) {
|
|
|
449
509
|
}
|
|
450
510
|
if (!reference.image && roots.has(pathname)) continue;
|
|
451
511
|
code = reference.image || !/^\/(?:[^/]+\/)?docs(?:\/|$)/.test(pathname) ? "asset" : "page";
|
|
452
|
-
|
|
512
|
+
const asset = findPublicFile(pathname);
|
|
513
|
+
if (asset?.correctedPath) {
|
|
514
|
+
code = "asset";
|
|
515
|
+
const absolute = /^(?:https?:|\/\/)/i.test(reference.href);
|
|
516
|
+
const basePath = project.config.basePath;
|
|
517
|
+
const prefix = absolute && basePath && url.pathname.startsWith(`${basePath}/`) ? basePath : "";
|
|
518
|
+
suggestion = `${absolute ? url.origin : ""}${prefix}${asset.correctedPath}${url.search}${url.hash}`;
|
|
519
|
+
throw new Error(caseMismatch);
|
|
520
|
+
}
|
|
521
|
+
if (!asset) {
|
|
453
522
|
if (code === "page") {
|
|
454
523
|
const edition = redirectSources.filter(({ root }) => pathname.startsWith(`${key(root)}/`)).sort((a, b) => b.root.length - a.root.length)[0];
|
|
455
524
|
const match = edition && closestMatch(
|