@rspress/core 1.13.2 → 1.15.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/index.js +33 -47
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +2 -2
- package/dist/loader.js +42 -27
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +22 -22
- package/package.json +15 -23
- package/src/runtime/App.tsx +24 -22
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
"package.json"(exports, module) {
|
|
67
67
|
module.exports = {
|
|
68
68
|
name: "@rspress/core",
|
|
69
|
-
version: "1.
|
|
69
|
+
version: "1.15.0",
|
|
70
70
|
description: "The Rspress Documentation Framework",
|
|
71
71
|
bugs: "https://github.com/web-infra-dev/rspress/issues",
|
|
72
72
|
repository: {
|
|
@@ -113,25 +113,20 @@ var require_package = __commonJS({
|
|
|
113
113
|
engines: {
|
|
114
114
|
node: ">=14.17.6"
|
|
115
115
|
},
|
|
116
|
-
eslintIgnore: [
|
|
117
|
-
"node_modules/",
|
|
118
|
-
"dist/"
|
|
119
|
-
],
|
|
120
116
|
dependencies: {
|
|
121
117
|
"@loadable/component": "5.15.2",
|
|
122
118
|
"@mdx-js/loader": "2.2.1",
|
|
123
119
|
"@mdx-js/mdx": "2.2.1",
|
|
124
120
|
"@mdx-js/react": "2.2.1",
|
|
125
|
-
"@modern-js/utils": "2.48.
|
|
126
|
-
"@rsbuild/core": "0.4.
|
|
127
|
-
"@rsbuild/plugin-react": "0.4.
|
|
128
|
-
"@rsbuild/plugin-svgr": "0.4.0",
|
|
121
|
+
"@modern-js/utils": "2.48.1",
|
|
122
|
+
"@rsbuild/core": "0.4.11",
|
|
123
|
+
"@rsbuild/plugin-react": "0.4.11",
|
|
129
124
|
"@rspress/theme-default": "workspace:*",
|
|
130
125
|
"@rspress/runtime": "workspace:*",
|
|
131
126
|
"@rspress/plugin-medium-zoom": "workspace:*",
|
|
132
127
|
"@rspress/plugin-last-updated": "workspace:*",
|
|
133
128
|
"@rspress/plugin-auto-nav-sidebar": "workspace:*",
|
|
134
|
-
"@rspress/mdx-rs": "0.
|
|
129
|
+
"@rspress/mdx-rs": "0.5.0",
|
|
135
130
|
"@rspress/plugin-container-syntax": "workspace:*",
|
|
136
131
|
"@rspress/shared": "workspace:*",
|
|
137
132
|
"body-scroll-lock": "4.0.0-beta.0",
|
|
@@ -172,9 +167,9 @@ var require_package = __commonJS({
|
|
|
172
167
|
},
|
|
173
168
|
devDependencies: {
|
|
174
169
|
tailwindcss: "^3.2.7",
|
|
175
|
-
"@modern-js/plugin-tailwindcss": "2.48.
|
|
176
|
-
"@modern-js/tsconfig": "2.48.
|
|
177
|
-
"@modern-js/types": "2.48.
|
|
170
|
+
"@modern-js/plugin-tailwindcss": "2.48.1",
|
|
171
|
+
"@modern-js/tsconfig": "2.48.1",
|
|
172
|
+
"@modern-js/types": "2.48.1",
|
|
178
173
|
"@types/body-scroll-lock": "^3.1.0",
|
|
179
174
|
"@types/fs-extra": "^9.0.13",
|
|
180
175
|
"@types/hast": "^2.3.4",
|
|
@@ -187,9 +182,6 @@ var require_package = __commonJS({
|
|
|
187
182
|
"@types/react": "^18",
|
|
188
183
|
"@types/react-dom": "^18",
|
|
189
184
|
"@types/yaml-front-matter": "^4.1.0",
|
|
190
|
-
husky: "^8",
|
|
191
|
-
"lint-staged": "~13.1.0",
|
|
192
|
-
"@biomejs/biome": "1.5.2",
|
|
193
185
|
rimraf: "^3.0.2",
|
|
194
186
|
typescript: "^5",
|
|
195
187
|
vite: "^4.0.5",
|
|
@@ -358,6 +350,9 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
358
350
|
return {};
|
|
359
351
|
}
|
|
360
352
|
const normalizeSidebarItem = (item) => {
|
|
353
|
+
if (typeof item === "object" && ("dividerType" in item || "sectionHeaderText" in item)) {
|
|
354
|
+
return item;
|
|
355
|
+
}
|
|
361
356
|
if (typeof item === "object" && "items" in item) {
|
|
362
357
|
return {
|
|
363
358
|
...item,
|
|
@@ -374,9 +369,6 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
374
369
|
})
|
|
375
370
|
};
|
|
376
371
|
}
|
|
377
|
-
if (typeof item === "object" && "dividerType" in item) {
|
|
378
|
-
return item;
|
|
379
|
-
}
|
|
380
372
|
if (typeof item === "string") {
|
|
381
373
|
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
382
374
|
const page = pages.find(
|
|
@@ -523,9 +515,8 @@ async function detectReactVersion() {
|
|
|
523
515
|
const reactPkg = await fs.readJson(path3.join(reactPath, "package.json"));
|
|
524
516
|
const version = Number(reactPkg.version.split(".")[0]);
|
|
525
517
|
return version;
|
|
526
|
-
} else {
|
|
527
|
-
return DEFAULT_REACT_VERSION;
|
|
528
518
|
}
|
|
519
|
+
return DEFAULT_REACT_VERSION;
|
|
529
520
|
}
|
|
530
521
|
async function resolveReactAlias(reactVersion) {
|
|
531
522
|
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
@@ -615,9 +606,10 @@ async function resolveDepPath(importPath, importer, alias) {
|
|
|
615
606
|
return resolveResult;
|
|
616
607
|
}
|
|
617
608
|
async function flattenMdxContent(content, basePath, alias) {
|
|
609
|
+
const deps = [];
|
|
618
610
|
const regex = new RegExp(importStatementRegex);
|
|
619
611
|
if (!regex.test(content)) {
|
|
620
|
-
return content;
|
|
612
|
+
return { flattenContent: content, deps };
|
|
621
613
|
}
|
|
622
614
|
let result = content;
|
|
623
615
|
if (!startFlatten) {
|
|
@@ -632,7 +624,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
632
624
|
try {
|
|
633
625
|
ast = processor.parse(content);
|
|
634
626
|
} catch (e) {
|
|
635
|
-
return content;
|
|
627
|
+
return { flattenContent: content, deps };
|
|
636
628
|
}
|
|
637
629
|
const importNodes = ast.children.filter((node) => node.type === "mdxjsEsm").map((node) => {
|
|
638
630
|
return node.data?.estree?.body || [];
|
|
@@ -652,18 +644,15 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
652
644
|
}
|
|
653
645
|
if (MDX_REGEXP.test(absoluteImportPath)) {
|
|
654
646
|
const importedContent = fs2.readFileSync(absoluteImportPath, "utf-8");
|
|
655
|
-
const replacedValue = await flattenMdxContent(
|
|
656
|
-
importedContent,
|
|
657
|
-
absoluteImportPath,
|
|
658
|
-
alias
|
|
659
|
-
);
|
|
647
|
+
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
660
648
|
result = result.replace(
|
|
661
649
|
new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`),
|
|
662
650
|
""
|
|
663
651
|
).replace(new RegExp(`<${id}\\s*/>`, "g"), () => replacedValue);
|
|
652
|
+
deps.push(...subDeps, absoluteImportPath);
|
|
664
653
|
}
|
|
665
654
|
}
|
|
666
|
-
return result;
|
|
655
|
+
return { flattenContent: result, deps };
|
|
667
656
|
}
|
|
668
657
|
|
|
669
658
|
// src/node/runtimeModule/siteData/extractPageData.ts
|
|
@@ -697,7 +686,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2)
|
|
|
697
686
|
frontmatter[key] = applyReplaceRules(frontmatter[key], replaceRules);
|
|
698
687
|
}
|
|
699
688
|
});
|
|
700
|
-
const flattenContent = await flattenMdxContent(
|
|
689
|
+
const { flattenContent } = await flattenMdxContent(
|
|
701
690
|
applyReplaceRules(strippedFrontMatter, replaceRules),
|
|
702
691
|
route.absolutePath,
|
|
703
692
|
alias
|
|
@@ -858,7 +847,7 @@ async function siteDataVMPlugin(context) {
|
|
|
858
847
|
search: userConfig?.search ?? { mode: "local" },
|
|
859
848
|
pages: pages.map((page) => {
|
|
860
849
|
const { content, id, domain: domain2, _filepath, ...rest } = page;
|
|
861
|
-
return rest;
|
|
850
|
+
return isProduction() ? rest : { ...rest, _filepath };
|
|
862
851
|
}),
|
|
863
852
|
markdown: {
|
|
864
853
|
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
@@ -890,19 +879,17 @@ async function globalUIComponentsVMPlugin(context) {
|
|
|
890
879
|
if (Array.isArray(source)) {
|
|
891
880
|
return `import ${name} from ${JSON.stringify(source[0])};
|
|
892
881
|
const Props_${index++} = ${JSON.stringify(source[1])};
|
|
893
|
-
`;
|
|
894
|
-
} else {
|
|
895
|
-
index++;
|
|
896
|
-
return `import ${name} from ${JSON.stringify(source)};
|
|
897
882
|
`;
|
|
898
883
|
}
|
|
884
|
+
index++;
|
|
885
|
+
return `import ${name} from ${JSON.stringify(source)};
|
|
886
|
+
`;
|
|
899
887
|
}).concat(
|
|
900
888
|
`export default [${Array.from({ length: index }, (_, i) => {
|
|
901
889
|
if (Array.isArray(globalComponents[i])) {
|
|
902
890
|
return `[${`Comp_${i}`}, Props_${i}]`;
|
|
903
|
-
} else {
|
|
904
|
-
return `Comp_${i}`;
|
|
905
891
|
}
|
|
892
|
+
return `Comp_${i}`;
|
|
906
893
|
}).join(", ")}];`
|
|
907
894
|
).join("");
|
|
908
895
|
return {
|
|
@@ -1030,7 +1017,7 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1030
1017
|
}
|
|
1031
1018
|
runtimeModule[key] = modulesByPlugin[key];
|
|
1032
1019
|
});
|
|
1033
|
-
bundlerChain.plugin(
|
|
1020
|
+
bundlerChain.plugin("rspress-runtime-module").use(
|
|
1034
1021
|
// @ts-expect-error
|
|
1035
1022
|
new RspackVirtualModulePlugin(
|
|
1036
1023
|
runtimeModule,
|
|
@@ -1365,9 +1352,14 @@ async function initRouteService(options) {
|
|
|
1365
1352
|
}
|
|
1366
1353
|
|
|
1367
1354
|
// src/node/utils/detectCustomIcon.ts
|
|
1355
|
+
import { existsSync } from "fs";
|
|
1368
1356
|
import path10 from "path";
|
|
1369
1357
|
var detectCustomIcon = async (customThemeDir) => {
|
|
1370
1358
|
const assetsDir = path10.join(customThemeDir, "assets");
|
|
1359
|
+
const alias = {};
|
|
1360
|
+
if (!existsSync(assetsDir)) {
|
|
1361
|
+
return alias;
|
|
1362
|
+
}
|
|
1371
1363
|
const globby = (await import(
|
|
1372
1364
|
// @ts-expect-error
|
|
1373
1365
|
// eslint-disable-next-line node/file-extension-in-import
|
|
@@ -1376,7 +1368,6 @@ var detectCustomIcon = async (customThemeDir) => {
|
|
|
1376
1368
|
const files = await globby("*.svg", {
|
|
1377
1369
|
cwd: assetsDir
|
|
1378
1370
|
});
|
|
1379
|
-
const alias = {};
|
|
1380
1371
|
files.forEach((file) => {
|
|
1381
1372
|
const name = path10.basename(file, ".svg");
|
|
1382
1373
|
alias[`@theme-assets/${name}`] = path10.join(assetsDir, file);
|
|
@@ -1529,7 +1520,6 @@ async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRs
|
|
|
1529
1520
|
default: { createRsbuild, mergeRsbuildConfig: mergeRsbuildConfig2 }
|
|
1530
1521
|
} = await import("@rsbuild/core");
|
|
1531
1522
|
const { pluginReact } = await import("@rsbuild/plugin-react");
|
|
1532
|
-
const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
|
|
1533
1523
|
const internalRsbuildConfig = await createInternalBuildConfig(
|
|
1534
1524
|
userDocRoot,
|
|
1535
1525
|
config,
|
|
@@ -1555,9 +1545,6 @@ async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRs
|
|
|
1555
1545
|
pluginDriver
|
|
1556
1546
|
}),
|
|
1557
1547
|
pluginReact(),
|
|
1558
|
-
pluginSvgr({
|
|
1559
|
-
svgDefaultExport: "component"
|
|
1560
|
-
}),
|
|
1561
1548
|
...builderPlugins
|
|
1562
1549
|
]);
|
|
1563
1550
|
return rsbuild;
|
|
@@ -1618,14 +1605,13 @@ var PluginDriver = class {
|
|
|
1618
1605
|
});
|
|
1619
1606
|
}
|
|
1620
1607
|
addPlugin(plugin) {
|
|
1621
|
-
const
|
|
1608
|
+
const existedIndex = __privateGet(this, _plugins).findIndex(
|
|
1622
1609
|
(item) => item.name === plugin.name
|
|
1623
1610
|
);
|
|
1624
|
-
if (
|
|
1611
|
+
if (existedIndex !== -1) {
|
|
1625
1612
|
throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
1626
|
-
} else {
|
|
1627
|
-
__privateGet(this, _plugins).push(plugin);
|
|
1628
1613
|
}
|
|
1614
|
+
__privateGet(this, _plugins).push(plugin);
|
|
1629
1615
|
}
|
|
1630
1616
|
getPlugins() {
|
|
1631
1617
|
return __privateGet(this, _plugins);
|