@lexibase/rdx-core 1.0.0-beta.7 → 1.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.
- package/README.md +8 -1
- package/dist/{chunk-IPSIYQDQ.js → chunk-ZX6IDGQW.js} +179 -11
- package/dist/config/index.d.ts +3 -2
- package/dist/config/index.js +1 -1
- package/dist/index.js +6 -2
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
# `@
|
|
1
|
+
# `@lexibase/rdx-core`
|
|
2
2
|
|
|
3
3
|
Content RDX core.
|
|
4
|
+
|
|
5
|
+
Plugin setup may return `runtimeFiles: string[]` alongside `sources`. Each entry
|
|
6
|
+
names a project-relative file required when serving documentation, such as a
|
|
7
|
+
custom version manifest. Paths cannot be absolute, escape the project or name
|
|
8
|
+
the project root. Entries are deduplicated in `RdxProject.runtimeFiles`.
|
|
9
|
+
The Next adapter validates and explicitly includes these files in production
|
|
10
|
+
traces; undeclared unrelated files are not automatically deployment assets.
|
|
@@ -1,12 +1,137 @@
|
|
|
1
1
|
// src/config/index.ts
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
|
+
|
|
5
|
+
// src/config/error.ts
|
|
4
6
|
var RdxConfigError = class extends Error {
|
|
5
7
|
constructor(message) {
|
|
6
8
|
super(`Invalid rdx.config.ts: ${message}`);
|
|
7
9
|
this.name = "RdxConfigError";
|
|
8
10
|
}
|
|
9
11
|
};
|
|
12
|
+
|
|
13
|
+
// src/config/metadata.ts
|
|
14
|
+
function validateMetadata(input) {
|
|
15
|
+
function string(value, field) {
|
|
16
|
+
if (typeof value !== "string" || !value.trim())
|
|
17
|
+
throw new RdxConfigError(`${field} must be a non-empty string.`);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function url(value, field, relative = false) {
|
|
21
|
+
const source = string(value, field);
|
|
22
|
+
try {
|
|
23
|
+
if (/[\s\\]/.test(source)) throw new Error();
|
|
24
|
+
if (relative && /^\/(?!\/)/.test(source)) return;
|
|
25
|
+
const parsed = new URL(source);
|
|
26
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
27
|
+
throw new Error();
|
|
28
|
+
} catch {
|
|
29
|
+
throw new RdxConfigError(
|
|
30
|
+
`${field} must be ${relative ? "a root-relative path or " : ""}an absolute http(s) URL.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function object2(value, field, allowed) {
|
|
35
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
36
|
+
throw new RdxConfigError(`${field} must be an object.`);
|
|
37
|
+
const result = value;
|
|
38
|
+
for (const key of Object.keys(result))
|
|
39
|
+
if (!allowed.includes(key))
|
|
40
|
+
throw new RdxConfigError(`unknown option ${field}.${key}.`);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function array(value, field, validate) {
|
|
44
|
+
if (!Array.isArray(value))
|
|
45
|
+
throw new RdxConfigError(`${field} must be an array.`);
|
|
46
|
+
value.forEach((item, index) => validate(item, `${field}[${index}]`));
|
|
47
|
+
}
|
|
48
|
+
const metadata = object2(input, "metadata", [
|
|
49
|
+
"metadataBase",
|
|
50
|
+
"applicationName",
|
|
51
|
+
"since",
|
|
52
|
+
"authors",
|
|
53
|
+
"keywords",
|
|
54
|
+
"icons",
|
|
55
|
+
"manifest",
|
|
56
|
+
"robots",
|
|
57
|
+
"openGraph",
|
|
58
|
+
"twitter"
|
|
59
|
+
]);
|
|
60
|
+
if (metadata.metadataBase !== void 0)
|
|
61
|
+
url(metadata.metadataBase, "metadata.metadataBase");
|
|
62
|
+
string(metadata.applicationName, "metadata.applicationName");
|
|
63
|
+
if (metadata.since !== void 0 && (typeof metadata.since !== "number" || !Number.isInteger(metadata.since) || metadata.since < 1 || metadata.since > (/* @__PURE__ */ new Date()).getFullYear()))
|
|
64
|
+
throw new RdxConfigError(
|
|
65
|
+
"metadata.since must be a positive integer no later than the current year."
|
|
66
|
+
);
|
|
67
|
+
if (metadata.manifest !== void 0)
|
|
68
|
+
url(metadata.manifest, "metadata.manifest", true);
|
|
69
|
+
if (metadata.keywords !== void 0)
|
|
70
|
+
array(metadata.keywords, "metadata.keywords", string);
|
|
71
|
+
if (metadata.authors !== void 0)
|
|
72
|
+
array(metadata.authors, "metadata.authors", (value, field) => {
|
|
73
|
+
const author = object2(value, field, ["name", "url"]);
|
|
74
|
+
string(author.name, `${field}.name`);
|
|
75
|
+
if (author.url !== void 0) url(author.url, `${field}.url`);
|
|
76
|
+
});
|
|
77
|
+
if (metadata.icons !== void 0) {
|
|
78
|
+
const icons = object2(metadata.icons, "metadata.icons", [
|
|
79
|
+
"icon",
|
|
80
|
+
"shortcut",
|
|
81
|
+
"apple"
|
|
82
|
+
]);
|
|
83
|
+
for (const [key, value] of Object.entries(icons)) {
|
|
84
|
+
if (value === void 0) continue;
|
|
85
|
+
const field = `metadata.icons.${key}`;
|
|
86
|
+
if (key === "icon" && Array.isArray(value))
|
|
87
|
+
array(value, field, (item, field2) => {
|
|
88
|
+
const icon = object2(item, field2, ["url", "sizes", "type"]);
|
|
89
|
+
url(icon.url, `${field2}.url`, true);
|
|
90
|
+
for (const key2 of ["sizes", "type"])
|
|
91
|
+
if (icon[key2] !== void 0) string(icon[key2], `${field2}.${key2}`);
|
|
92
|
+
});
|
|
93
|
+
else url(value, field, true);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (metadata.robots !== void 0) {
|
|
97
|
+
const robots = object2(metadata.robots, "metadata.robots", [
|
|
98
|
+
"index",
|
|
99
|
+
"follow"
|
|
100
|
+
]);
|
|
101
|
+
for (const [key, value] of Object.entries(robots))
|
|
102
|
+
if (value !== void 0 && typeof value !== "boolean")
|
|
103
|
+
throw new RdxConfigError(`metadata.robots.${key} must be a boolean.`);
|
|
104
|
+
}
|
|
105
|
+
for (const key of ["openGraph", "twitter"]) {
|
|
106
|
+
if (metadata[key] === void 0) continue;
|
|
107
|
+
const field = `metadata.${key}`;
|
|
108
|
+
const social = object2(
|
|
109
|
+
metadata[key],
|
|
110
|
+
field,
|
|
111
|
+
key === "openGraph" ? ["title", "description", "siteName", "locale", "type", "images"] : ["title", "description", "card", "site", "creator", "images"]
|
|
112
|
+
);
|
|
113
|
+
for (const [name, value] of Object.entries(social)) {
|
|
114
|
+
if (name === "images" || value === void 0) continue;
|
|
115
|
+
string(value, `${field}.${name}`);
|
|
116
|
+
if (name === "type" && value !== "website" || name === "card" && !["summary", "summary_large_image"].includes(value))
|
|
117
|
+
throw new RdxConfigError(`${field}.${name} has an unsupported value.`);
|
|
118
|
+
}
|
|
119
|
+
if (social.images !== void 0)
|
|
120
|
+
array(social.images, `${field}.images`, (value, field2) => {
|
|
121
|
+
if (key === "twitter") return url(value, field2, true);
|
|
122
|
+
const image = object2(value, field2, ["url", "width", "height", "alt"]);
|
|
123
|
+
url(image.url, `${field2}.url`, true);
|
|
124
|
+
if (image.alt !== void 0) string(image.alt, `${field2}.alt`);
|
|
125
|
+
for (const dimension of ["width", "height"])
|
|
126
|
+
if (image[dimension] !== void 0 && (typeof image[dimension] !== "number" || !Number.isInteger(image[dimension]) || image[dimension] <= 0))
|
|
127
|
+
throw new RdxConfigError(
|
|
128
|
+
`${field2}.${dimension} must be a positive integer.`
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/config/index.ts
|
|
10
135
|
function record(value) {
|
|
11
136
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
137
|
}
|
|
@@ -40,7 +165,11 @@ function keys(value, allowed, field) {
|
|
|
40
165
|
}
|
|
41
166
|
function resolveProjectPath(rootDir, value, field) {
|
|
42
167
|
text(value, field);
|
|
43
|
-
const resolved = path.resolve(
|
|
168
|
+
const resolved = path.resolve(
|
|
169
|
+
/* turbopackIgnore: true */
|
|
170
|
+
rootDir,
|
|
171
|
+
value
|
|
172
|
+
);
|
|
44
173
|
const relative = path.relative(rootDir, resolved);
|
|
45
174
|
if (path.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
46
175
|
throw new RdxConfigError(
|
|
@@ -51,13 +180,20 @@ function resolveProjectPath(rootDir, value, field) {
|
|
|
51
180
|
}
|
|
52
181
|
function resolveConfig(input) {
|
|
53
182
|
const config = object(input, "default export");
|
|
183
|
+
if ("title" in config)
|
|
184
|
+
throw new RdxConfigError(
|
|
185
|
+
"title has been removed. Set the site name in metadata.applicationName instead."
|
|
186
|
+
);
|
|
187
|
+
if ("docsDir" in config)
|
|
188
|
+
throw new RdxConfigError(
|
|
189
|
+
"docsDir is not configurable. Live documentation must be stored in docs/."
|
|
190
|
+
);
|
|
54
191
|
keys(
|
|
55
192
|
config,
|
|
56
193
|
[
|
|
57
|
-
"title",
|
|
58
194
|
"description",
|
|
195
|
+
"metadata",
|
|
59
196
|
"lang",
|
|
60
|
-
"docsDir",
|
|
61
197
|
"theme",
|
|
62
198
|
"navbar",
|
|
63
199
|
"plugins",
|
|
@@ -67,7 +203,6 @@ function resolveConfig(input) {
|
|
|
67
203
|
],
|
|
68
204
|
""
|
|
69
205
|
);
|
|
70
|
-
text(config.title, "title");
|
|
71
206
|
if (config.search !== void 0 && typeof config.search !== "boolean")
|
|
72
207
|
throw new RdxConfigError("search must be a boolean.");
|
|
73
208
|
if (config.TOC !== void 0 && typeof config.TOC !== "boolean")
|
|
@@ -75,7 +210,7 @@ function resolveConfig(input) {
|
|
|
75
210
|
if (config.description !== void 0)
|
|
76
211
|
text(config.description, "description", true);
|
|
77
212
|
if (config.lang !== void 0) text(config.lang, "lang");
|
|
78
|
-
|
|
213
|
+
validateMetadata(config.metadata);
|
|
79
214
|
if (config.homepage !== void 0) {
|
|
80
215
|
const homepage = object(config.homepage, "homepage");
|
|
81
216
|
keys(
|
|
@@ -181,7 +316,6 @@ function resolveConfig(input) {
|
|
|
181
316
|
search: typed.search ?? false,
|
|
182
317
|
description: typed.description ?? "",
|
|
183
318
|
lang: typed.lang ?? "en",
|
|
184
|
-
docsDir: typed.docsDir ?? "docs",
|
|
185
319
|
theme: { defaultTheme: typed.theme?.defaultTheme ?? "system" },
|
|
186
320
|
plugins: typed.plugins ?? []
|
|
187
321
|
};
|
|
@@ -194,18 +328,26 @@ async function createRdxProject(input, {
|
|
|
194
328
|
rootDir = process.cwd(),
|
|
195
329
|
command = "runtime"
|
|
196
330
|
} = {}) {
|
|
197
|
-
rootDir = path.resolve(
|
|
331
|
+
rootDir = path.resolve(
|
|
332
|
+
/* turbopackIgnore: true */
|
|
333
|
+
rootDir
|
|
334
|
+
);
|
|
198
335
|
const config = resolveConfig(input);
|
|
199
|
-
const docsRoot = resolveProjectPath(
|
|
336
|
+
const docsRoot = resolveProjectPath(
|
|
337
|
+
rootDir,
|
|
338
|
+
"docs",
|
|
339
|
+
"documentation directory"
|
|
340
|
+
);
|
|
200
341
|
const sources = [
|
|
201
342
|
{
|
|
202
343
|
id: "current",
|
|
203
344
|
label: "Current",
|
|
204
|
-
docsDir:
|
|
345
|
+
docsDir: "docs",
|
|
205
346
|
routePrefix: ""
|
|
206
347
|
}
|
|
207
348
|
];
|
|
208
349
|
const commands = [];
|
|
350
|
+
const runtimeFiles = /* @__PURE__ */ new Set();
|
|
209
351
|
const commandNames = /* @__PURE__ */ new Set([
|
|
210
352
|
"dev",
|
|
211
353
|
"build",
|
|
@@ -241,6 +383,18 @@ async function createRdxProject(input, {
|
|
|
241
383
|
}
|
|
242
384
|
if (result === void 0) continue;
|
|
243
385
|
const contribution = object(result, `plugin "${plugin.name}" setup result`);
|
|
386
|
+
if (contribution.runtimeFiles !== void 0) {
|
|
387
|
+
if (!Array.isArray(contribution.runtimeFiles))
|
|
388
|
+
throw new RdxConfigError(
|
|
389
|
+
`plugin "${plugin.name}" runtimeFiles must be an array.`
|
|
390
|
+
);
|
|
391
|
+
for (const value of contribution.runtimeFiles) {
|
|
392
|
+
const field = `plugin "${plugin.name}" runtimeFiles`;
|
|
393
|
+
const filename = text(value, field);
|
|
394
|
+
const resolved = resolveProjectPath(rootDir, filename, field);
|
|
395
|
+
runtimeFiles.add(path.relative(rootDir, resolved));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
244
398
|
if (contribution.sources === void 0) continue;
|
|
245
399
|
if (!Array.isArray(contribution.sources))
|
|
246
400
|
throw new RdxConfigError(
|
|
@@ -266,7 +420,21 @@ async function createRdxProject(input, {
|
|
|
266
420
|
`duplicate content source id or route prefix: ${id}.`
|
|
267
421
|
);
|
|
268
422
|
}
|
|
269
|
-
if (existsSync(
|
|
423
|
+
if (existsSync(
|
|
424
|
+
/* turbopackIgnore: true */
|
|
425
|
+
path.join(
|
|
426
|
+
/* turbopackIgnore: true */
|
|
427
|
+
docsRoot,
|
|
428
|
+
prefix
|
|
429
|
+
)
|
|
430
|
+
) || existsSync(
|
|
431
|
+
/* turbopackIgnore: true */
|
|
432
|
+
path.join(
|
|
433
|
+
/* turbopackIgnore: true */
|
|
434
|
+
docsRoot,
|
|
435
|
+
`${prefix}.mdx`
|
|
436
|
+
)
|
|
437
|
+
)) {
|
|
270
438
|
throw new RdxConfigError(
|
|
271
439
|
`content source ${id} conflicts with live documentation at /docs/${prefix}.`
|
|
272
440
|
);
|
|
@@ -276,7 +444,7 @@ async function createRdxProject(input, {
|
|
|
276
444
|
sources.push(source);
|
|
277
445
|
}
|
|
278
446
|
}
|
|
279
|
-
return { rootDir, config, sources, commands };
|
|
447
|
+
return { rootDir, config, sources, commands, runtimeFiles: [...runtimeFiles] };
|
|
280
448
|
}
|
|
281
449
|
|
|
282
450
|
export {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { RdxProject,
|
|
1
|
+
import { RdxProject, RDXConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
|
|
2
2
|
|
|
3
3
|
declare class RdxConfigError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
5
5
|
}
|
|
6
|
+
|
|
6
7
|
/** Resolve project-owned paths without allowing traversal or filesystem roots. */
|
|
7
8
|
declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
|
|
8
9
|
declare function resolveConfig(input: unknown): ResolvedRdxConfig;
|
|
9
|
-
declare function defineConfig(config:
|
|
10
|
+
declare function defineConfig(config: RDXConfig): RDXConfig;
|
|
10
11
|
declare function createRdxProject(input: unknown, { rootDir, command, }?: {
|
|
11
12
|
rootDir?: string;
|
|
12
13
|
command?: string;
|
package/dist/config/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
defineConfig,
|
|
5
5
|
resolveConfig,
|
|
6
6
|
resolveProjectPath
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ZX6IDGQW.js";
|
|
8
8
|
import {
|
|
9
9
|
RdxDocumentLinkError,
|
|
10
10
|
createDocumentLinkResolver
|
|
@@ -17,7 +17,11 @@ import matter from "gray-matter";
|
|
|
17
17
|
var MDX_EXTENSION = ".mdx";
|
|
18
18
|
var DEFAULT_POSITION = Number.MAX_SAFE_INTEGER;
|
|
19
19
|
function getDocsRoot(docsDir = "docs") {
|
|
20
|
-
return path.resolve(
|
|
20
|
+
return path.resolve(
|
|
21
|
+
/* turbopackIgnore: true */
|
|
22
|
+
process.cwd(),
|
|
23
|
+
docsDir
|
|
24
|
+
);
|
|
21
25
|
}
|
|
22
26
|
function toTitle(value) {
|
|
23
27
|
return value.replace(/[-_]/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexibase/rdx-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Content indexing and document utilities for RDX documentation projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@shikijs/rehype": "^4.5.0",
|
|
50
50
|
"gray-matter": "^4.0.3",
|
|
51
51
|
"rehype-slug": "^6.0.0",
|
|
52
|
-
"@lexibase/rdx-types": "1.
|
|
52
|
+
"@lexibase/rdx-types": "1.1.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^22.15.3",
|
|
@@ -57,7 +57,11 @@
|
|
|
57
57
|
"@rdx/typescript-config": "1.0.0",
|
|
58
58
|
"@rdx/eslint-config": "1.0.0"
|
|
59
59
|
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": "^22.18.0 || ^24.11.0"
|
|
62
|
+
},
|
|
60
63
|
"scripts": {
|
|
64
|
+
"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",
|
|
61
65
|
"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",
|
|
62
66
|
"check-types": "tsc --noEmit",
|
|
63
67
|
"test": "node --test tests/*.test.mjs"
|