@lexibase/rdx-core 1.0.0-beta.7 → 1.0.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-X6YRBB2W.js} +174 -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 +8 -4
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,132 @@
|
|
|
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
|
+
"authors",
|
|
52
|
+
"keywords",
|
|
53
|
+
"icons",
|
|
54
|
+
"manifest",
|
|
55
|
+
"robots",
|
|
56
|
+
"openGraph",
|
|
57
|
+
"twitter"
|
|
58
|
+
]);
|
|
59
|
+
if (metadata.metadataBase !== void 0)
|
|
60
|
+
url(metadata.metadataBase, "metadata.metadataBase");
|
|
61
|
+
string(metadata.applicationName, "metadata.applicationName");
|
|
62
|
+
if (metadata.manifest !== void 0)
|
|
63
|
+
url(metadata.manifest, "metadata.manifest", true);
|
|
64
|
+
if (metadata.keywords !== void 0)
|
|
65
|
+
array(metadata.keywords, "metadata.keywords", string);
|
|
66
|
+
if (metadata.authors !== void 0)
|
|
67
|
+
array(metadata.authors, "metadata.authors", (value, field) => {
|
|
68
|
+
const author = object2(value, field, ["name", "url"]);
|
|
69
|
+
string(author.name, `${field}.name`);
|
|
70
|
+
if (author.url !== void 0) url(author.url, `${field}.url`);
|
|
71
|
+
});
|
|
72
|
+
if (metadata.icons !== void 0) {
|
|
73
|
+
const icons = object2(metadata.icons, "metadata.icons", [
|
|
74
|
+
"icon",
|
|
75
|
+
"shortcut",
|
|
76
|
+
"apple"
|
|
77
|
+
]);
|
|
78
|
+
for (const [key, value] of Object.entries(icons)) {
|
|
79
|
+
if (value === void 0) continue;
|
|
80
|
+
const field = `metadata.icons.${key}`;
|
|
81
|
+
if (key === "icon" && Array.isArray(value))
|
|
82
|
+
array(value, field, (item, field2) => {
|
|
83
|
+
const icon = object2(item, field2, ["url", "sizes", "type"]);
|
|
84
|
+
url(icon.url, `${field2}.url`, true);
|
|
85
|
+
for (const key2 of ["sizes", "type"])
|
|
86
|
+
if (icon[key2] !== void 0) string(icon[key2], `${field2}.${key2}`);
|
|
87
|
+
});
|
|
88
|
+
else url(value, field, true);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (metadata.robots !== void 0) {
|
|
92
|
+
const robots = object2(metadata.robots, "metadata.robots", [
|
|
93
|
+
"index",
|
|
94
|
+
"follow"
|
|
95
|
+
]);
|
|
96
|
+
for (const [key, value] of Object.entries(robots))
|
|
97
|
+
if (value !== void 0 && typeof value !== "boolean")
|
|
98
|
+
throw new RdxConfigError(`metadata.robots.${key} must be a boolean.`);
|
|
99
|
+
}
|
|
100
|
+
for (const key of ["openGraph", "twitter"]) {
|
|
101
|
+
if (metadata[key] === void 0) continue;
|
|
102
|
+
const field = `metadata.${key}`;
|
|
103
|
+
const social = object2(
|
|
104
|
+
metadata[key],
|
|
105
|
+
field,
|
|
106
|
+
key === "openGraph" ? ["title", "description", "siteName", "locale", "type", "images"] : ["title", "description", "card", "site", "creator", "images"]
|
|
107
|
+
);
|
|
108
|
+
for (const [name, value] of Object.entries(social)) {
|
|
109
|
+
if (name === "images" || value === void 0) continue;
|
|
110
|
+
string(value, `${field}.${name}`);
|
|
111
|
+
if (name === "type" && value !== "website" || name === "card" && !["summary", "summary_large_image"].includes(value))
|
|
112
|
+
throw new RdxConfigError(`${field}.${name} has an unsupported value.`);
|
|
113
|
+
}
|
|
114
|
+
if (social.images !== void 0)
|
|
115
|
+
array(social.images, `${field}.images`, (value, field2) => {
|
|
116
|
+
if (key === "twitter") return url(value, field2, true);
|
|
117
|
+
const image = object2(value, field2, ["url", "width", "height", "alt"]);
|
|
118
|
+
url(image.url, `${field2}.url`, true);
|
|
119
|
+
if (image.alt !== void 0) string(image.alt, `${field2}.alt`);
|
|
120
|
+
for (const dimension of ["width", "height"])
|
|
121
|
+
if (image[dimension] !== void 0 && (typeof image[dimension] !== "number" || !Number.isInteger(image[dimension]) || image[dimension] <= 0))
|
|
122
|
+
throw new RdxConfigError(
|
|
123
|
+
`${field2}.${dimension} must be a positive integer.`
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/config/index.ts
|
|
10
130
|
function record(value) {
|
|
11
131
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
132
|
}
|
|
@@ -40,7 +160,11 @@ function keys(value, allowed, field) {
|
|
|
40
160
|
}
|
|
41
161
|
function resolveProjectPath(rootDir, value, field) {
|
|
42
162
|
text(value, field);
|
|
43
|
-
const resolved = path.resolve(
|
|
163
|
+
const resolved = path.resolve(
|
|
164
|
+
/* turbopackIgnore: true */
|
|
165
|
+
rootDir,
|
|
166
|
+
value
|
|
167
|
+
);
|
|
44
168
|
const relative = path.relative(rootDir, resolved);
|
|
45
169
|
if (path.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
46
170
|
throw new RdxConfigError(
|
|
@@ -51,13 +175,20 @@ function resolveProjectPath(rootDir, value, field) {
|
|
|
51
175
|
}
|
|
52
176
|
function resolveConfig(input) {
|
|
53
177
|
const config = object(input, "default export");
|
|
178
|
+
if ("title" in config)
|
|
179
|
+
throw new RdxConfigError(
|
|
180
|
+
"title has been removed. Set the site name in metadata.applicationName instead."
|
|
181
|
+
);
|
|
182
|
+
if ("docsDir" in config)
|
|
183
|
+
throw new RdxConfigError(
|
|
184
|
+
"docsDir is not configurable. Live documentation must be stored in docs/."
|
|
185
|
+
);
|
|
54
186
|
keys(
|
|
55
187
|
config,
|
|
56
188
|
[
|
|
57
|
-
"title",
|
|
58
189
|
"description",
|
|
190
|
+
"metadata",
|
|
59
191
|
"lang",
|
|
60
|
-
"docsDir",
|
|
61
192
|
"theme",
|
|
62
193
|
"navbar",
|
|
63
194
|
"plugins",
|
|
@@ -67,7 +198,6 @@ function resolveConfig(input) {
|
|
|
67
198
|
],
|
|
68
199
|
""
|
|
69
200
|
);
|
|
70
|
-
text(config.title, "title");
|
|
71
201
|
if (config.search !== void 0 && typeof config.search !== "boolean")
|
|
72
202
|
throw new RdxConfigError("search must be a boolean.");
|
|
73
203
|
if (config.TOC !== void 0 && typeof config.TOC !== "boolean")
|
|
@@ -75,7 +205,7 @@ function resolveConfig(input) {
|
|
|
75
205
|
if (config.description !== void 0)
|
|
76
206
|
text(config.description, "description", true);
|
|
77
207
|
if (config.lang !== void 0) text(config.lang, "lang");
|
|
78
|
-
|
|
208
|
+
validateMetadata(config.metadata);
|
|
79
209
|
if (config.homepage !== void 0) {
|
|
80
210
|
const homepage = object(config.homepage, "homepage");
|
|
81
211
|
keys(
|
|
@@ -181,7 +311,6 @@ function resolveConfig(input) {
|
|
|
181
311
|
search: typed.search ?? false,
|
|
182
312
|
description: typed.description ?? "",
|
|
183
313
|
lang: typed.lang ?? "en",
|
|
184
|
-
docsDir: typed.docsDir ?? "docs",
|
|
185
314
|
theme: { defaultTheme: typed.theme?.defaultTheme ?? "system" },
|
|
186
315
|
plugins: typed.plugins ?? []
|
|
187
316
|
};
|
|
@@ -194,18 +323,26 @@ async function createRdxProject(input, {
|
|
|
194
323
|
rootDir = process.cwd(),
|
|
195
324
|
command = "runtime"
|
|
196
325
|
} = {}) {
|
|
197
|
-
rootDir = path.resolve(
|
|
326
|
+
rootDir = path.resolve(
|
|
327
|
+
/* turbopackIgnore: true */
|
|
328
|
+
rootDir
|
|
329
|
+
);
|
|
198
330
|
const config = resolveConfig(input);
|
|
199
|
-
const docsRoot = resolveProjectPath(
|
|
331
|
+
const docsRoot = resolveProjectPath(
|
|
332
|
+
rootDir,
|
|
333
|
+
"docs",
|
|
334
|
+
"documentation directory"
|
|
335
|
+
);
|
|
200
336
|
const sources = [
|
|
201
337
|
{
|
|
202
338
|
id: "current",
|
|
203
339
|
label: "Current",
|
|
204
|
-
docsDir:
|
|
340
|
+
docsDir: "docs",
|
|
205
341
|
routePrefix: ""
|
|
206
342
|
}
|
|
207
343
|
];
|
|
208
344
|
const commands = [];
|
|
345
|
+
const runtimeFiles = /* @__PURE__ */ new Set();
|
|
209
346
|
const commandNames = /* @__PURE__ */ new Set([
|
|
210
347
|
"dev",
|
|
211
348
|
"build",
|
|
@@ -241,6 +378,18 @@ async function createRdxProject(input, {
|
|
|
241
378
|
}
|
|
242
379
|
if (result === void 0) continue;
|
|
243
380
|
const contribution = object(result, `plugin "${plugin.name}" setup result`);
|
|
381
|
+
if (contribution.runtimeFiles !== void 0) {
|
|
382
|
+
if (!Array.isArray(contribution.runtimeFiles))
|
|
383
|
+
throw new RdxConfigError(
|
|
384
|
+
`plugin "${plugin.name}" runtimeFiles must be an array.`
|
|
385
|
+
);
|
|
386
|
+
for (const value of contribution.runtimeFiles) {
|
|
387
|
+
const field = `plugin "${plugin.name}" runtimeFiles`;
|
|
388
|
+
const filename = text(value, field);
|
|
389
|
+
const resolved = resolveProjectPath(rootDir, filename, field);
|
|
390
|
+
runtimeFiles.add(path.relative(rootDir, resolved));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
244
393
|
if (contribution.sources === void 0) continue;
|
|
245
394
|
if (!Array.isArray(contribution.sources))
|
|
246
395
|
throw new RdxConfigError(
|
|
@@ -266,7 +415,21 @@ async function createRdxProject(input, {
|
|
|
266
415
|
`duplicate content source id or route prefix: ${id}.`
|
|
267
416
|
);
|
|
268
417
|
}
|
|
269
|
-
if (existsSync(
|
|
418
|
+
if (existsSync(
|
|
419
|
+
/* turbopackIgnore: true */
|
|
420
|
+
path.join(
|
|
421
|
+
/* turbopackIgnore: true */
|
|
422
|
+
docsRoot,
|
|
423
|
+
prefix
|
|
424
|
+
)
|
|
425
|
+
) || existsSync(
|
|
426
|
+
/* turbopackIgnore: true */
|
|
427
|
+
path.join(
|
|
428
|
+
/* turbopackIgnore: true */
|
|
429
|
+
docsRoot,
|
|
430
|
+
`${prefix}.mdx`
|
|
431
|
+
)
|
|
432
|
+
)) {
|
|
270
433
|
throw new RdxConfigError(
|
|
271
434
|
`content source ${id} conflicts with live documentation at /docs/${prefix}.`
|
|
272
435
|
);
|
|
@@ -276,7 +439,7 @@ async function createRdxProject(input, {
|
|
|
276
439
|
sources.push(source);
|
|
277
440
|
}
|
|
278
441
|
}
|
|
279
|
-
return { rootDir, config, sources, commands };
|
|
442
|
+
return { rootDir, config, sources, commands, runtimeFiles: [...runtimeFiles] };
|
|
280
443
|
}
|
|
281
444
|
|
|
282
445
|
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-X6YRBB2W.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.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Content indexing and document utilities for RDX documentation projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -49,15 +49,19 @@
|
|
|
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.0.0
|
|
52
|
+
"@lexibase/rdx-types": "1.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^22.15.3",
|
|
56
56
|
"@types/react": "19.3.0",
|
|
57
|
-
"@rdx/
|
|
58
|
-
"@rdx/
|
|
57
|
+
"@rdx/eslint-config": "1.0.0",
|
|
58
|
+
"@rdx/typescript-config": "1.0.0"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": "^22.18.0 || ^24.11.0"
|
|
59
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"
|