@rspress/core 0.0.9 → 0.0.11
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.d.ts +1 -10
- package/dist/index.js +237 -264
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +0 -3
- package/dist/loader.js.map +1 -1
- package/dist/theme/bundle.css +96 -159
- package/dist/theme/bundle.d.ts +1 -1
- package/dist/theme/bundle.js +879 -802
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +15 -15
- package/src/theme-default/components/Aside/index.css +23 -0
- package/src/theme-default/components/Aside/index.tsx +7 -13
- package/src/theme-default/components/EditLink/index.module.scss +3 -3
- package/src/theme-default/components/EditLink/index.tsx +0 -5
- package/src/theme-default/components/HomeHero/index.module.scss +6 -0
- package/src/theme-default/components/HomeHero/index.tsx +4 -4
- package/src/theme-default/components/Nav/NavMenuGroup.tsx +43 -23
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +12 -4
- package/src/theme-default/components/Nav/index.module.scss +0 -1
- package/src/theme-default/components/Nav/index.tsx +4 -3
- package/src/theme-default/components/NavScreenMenuGroup/NavScreenMenuGroup.tsx +18 -7
- package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +1 -2
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +180 -0
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +61 -0
- package/src/theme-default/components/Sidebar/index.module.scss +22 -5
- package/src/theme-default/components/Sidebar/index.tsx +39 -248
- package/src/theme-default/components/Tabs/index.module.scss +11 -18
- package/src/theme-default/components/Tabs/index.tsx +1 -1
- package/src/theme-default/layout/DocLayout/index.module.scss +17 -18
- package/src/theme-default/layout/Layout/index.tsx +19 -7
- package/src/theme-default/logic/sideEffects.ts +3 -1
- package/src/theme-default/logic/useEditLink.ts +6 -3
- package/src/theme-default/logic/useLocaleSiteData.ts +1 -1
- package/src/theme-default/logic/useSidebarData.ts +1 -1
- package/src/theme-default/styles/{doc/code.css → code.css} +4 -1
- package/src/theme-default/styles/index.ts +1 -3
- package/src/theme-default/styles/vars.css +2 -2
- package/src/theme-default/assets/edit.svg +0 -1
- package/src/theme-default/styles/doc/container.css +0 -103
- package/src/theme-default/styles/doc/index.css +0 -6
- /package/dist/theme/{index.ts → index.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/node/dev.ts
|
|
2
2
|
import { removeLeadingSlash as removeLeadingSlash2 } from "@rspress/shared";
|
|
3
|
-
import
|
|
3
|
+
import { logger as logger3 } from "@rspress/shared/logger";
|
|
4
4
|
|
|
5
5
|
// src/node/createBuilder.ts
|
|
6
|
-
import
|
|
6
|
+
import path8 from "path";
|
|
7
7
|
import { createRequire as createRequire3 } from "module";
|
|
8
|
-
import
|
|
8
|
+
import fs8 from "@modern-js/utils/fs-extra";
|
|
9
|
+
import { RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2, isDebugMode, removeTrailingSlash } from "@rspress/shared";
|
|
9
10
|
import sirv from "sirv";
|
|
10
|
-
import fs9 from "@modern-js/utils/fs-extra";
|
|
11
11
|
|
|
12
12
|
// tailwind.config.ts
|
|
13
13
|
var tailwindConfig = {
|
|
@@ -96,85 +96,25 @@ var BODY_START_TAG = "<body";
|
|
|
96
96
|
var PUBLIC_DIR = "public";
|
|
97
97
|
var TEMP_DIR = path.join(process.cwd(), "node_modules", RSPRESS_TEMP_DIR);
|
|
98
98
|
|
|
99
|
-
// src/node/runtimeModule/
|
|
100
|
-
import {
|
|
101
|
-
import { addLeadingSlash } from "@rspress/shared";
|
|
102
|
-
|
|
103
|
-
// src/node/runtimeModule/RuntimeModulePlugin.ts
|
|
104
|
-
import path2 from "path";
|
|
105
|
-
import fs from "fs-extra";
|
|
106
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
107
|
-
if (privateCollection.has(obj)) {
|
|
108
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function _class_private_method_get(receiver, privateSet, fn) {
|
|
112
|
-
if (!privateSet.has(receiver)) {
|
|
113
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
114
|
-
}
|
|
115
|
-
return fn;
|
|
116
|
-
}
|
|
117
|
-
function _class_private_method_init(obj, privateSet) {
|
|
118
|
-
_check_private_redeclaration(obj, privateSet);
|
|
119
|
-
privateSet.add(obj);
|
|
120
|
-
}
|
|
121
|
-
function _define_property(obj, key, value) {
|
|
122
|
-
if (key in obj) {
|
|
123
|
-
Object.defineProperty(obj, key, {
|
|
124
|
-
value,
|
|
125
|
-
enumerable: true,
|
|
126
|
-
configurable: true,
|
|
127
|
-
writable: true
|
|
128
|
-
});
|
|
129
|
-
} else {
|
|
130
|
-
obj[key] = value;
|
|
131
|
-
}
|
|
132
|
-
return obj;
|
|
133
|
-
}
|
|
134
|
-
var _normalizePath = /* @__PURE__ */ new WeakSet();
|
|
135
|
-
var RuntimeModulesPlugin = class {
|
|
136
|
-
apply() {
|
|
137
|
-
Object.entries(this.staticModules).forEach(([path10, content]) => {
|
|
138
|
-
fs.writeFileSync(_class_private_method_get(this, _normalizePath, normalizePath).call(this, path10), content);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
writeModule(path10, content) {
|
|
142
|
-
const normalizedPath = _class_private_method_get(this, _normalizePath, normalizePath).call(this, path10);
|
|
143
|
-
this.staticModules[normalizedPath] = content;
|
|
144
|
-
fs.writeFileSync(normalizedPath, content);
|
|
145
|
-
}
|
|
146
|
-
constructor(staticModules) {
|
|
147
|
-
_class_private_method_init(this, _normalizePath);
|
|
148
|
-
_define_property(this, "staticModules", void 0);
|
|
149
|
-
this.staticModules = staticModules;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
function normalizePath(p) {
|
|
153
|
-
if (path2.isAbsolute(p)) {
|
|
154
|
-
return p;
|
|
155
|
-
} else {
|
|
156
|
-
return path2.join(process.cwd(), p);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
99
|
+
// src/node/runtimeModule/index.ts
|
|
100
|
+
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
159
101
|
|
|
160
102
|
// src/node/runtimeModule/routeData.ts
|
|
103
|
+
import { addLeadingSlash } from "@rspress/shared";
|
|
161
104
|
async function routeVMPlugin(context) {
|
|
162
|
-
const {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
[routeModulePathForSSR]: routeService2.generateRoutesCode(true)
|
|
168
|
-
});
|
|
169
|
-
return plugin;
|
|
105
|
+
const { routeService: routeService2 } = context;
|
|
106
|
+
return {
|
|
107
|
+
[RuntimeModuleID.RouteForClient]: routeService2.generateRoutesCode(false),
|
|
108
|
+
[RuntimeModuleID.RouteForSSR]: routeService2.generateRoutesCode(true)
|
|
109
|
+
};
|
|
170
110
|
}
|
|
171
111
|
|
|
172
112
|
// src/node/runtimeModule/siteData.ts
|
|
173
|
-
import
|
|
113
|
+
import path5 from "path";
|
|
174
114
|
import { withBase, MDX_REGEXP as MDX_REGEXP2, SEARCH_INDEX_NAME, addLeadingSlash as addLeadingSlash2, isExternalUrl, withoutBase } from "@rspress/shared";
|
|
175
115
|
import yamlFrontMatter from "yaml-front-matter";
|
|
176
116
|
import { htmlToText } from "html-to-text";
|
|
177
|
-
import
|
|
117
|
+
import fs3 from "@modern-js/utils/fs-extra";
|
|
178
118
|
import { compile } from "@modern-js/mdx-rs-binding";
|
|
179
119
|
|
|
180
120
|
// src/node/utils/applyReplaceRules.ts
|
|
@@ -188,13 +128,13 @@ function applyReplaceRules(code = "", replaceRules = []) {
|
|
|
188
128
|
|
|
189
129
|
// src/node/utils/normalizePath.ts
|
|
190
130
|
import os from "os";
|
|
191
|
-
import
|
|
131
|
+
import path2 from "path";
|
|
192
132
|
var isWindows = os.platform() === "win32";
|
|
193
133
|
function slash(p) {
|
|
194
134
|
return p.replace(/\\/g, "/");
|
|
195
135
|
}
|
|
196
|
-
function
|
|
197
|
-
return
|
|
136
|
+
function normalizePath(id) {
|
|
137
|
+
return path2.posix.normalize(isWindows ? slash(id) : id);
|
|
198
138
|
}
|
|
199
139
|
|
|
200
140
|
// src/node/utils/getPageKey.ts
|
|
@@ -216,27 +156,80 @@ var require2 = createRequire(import.meta.url);
|
|
|
216
156
|
var { logger } = require2("@modern-js/utils/logger");
|
|
217
157
|
|
|
218
158
|
// src/node/utils/detectReactVersion.ts
|
|
219
|
-
import
|
|
220
|
-
import
|
|
159
|
+
import path3 from "path";
|
|
160
|
+
import fs from "@modern-js/utils/fs-extra";
|
|
161
|
+
import { logger as logger2 } from "@rspress/shared/logger";
|
|
162
|
+
import enhancedResolve from "enhanced-resolve";
|
|
163
|
+
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
164
|
+
var DEFAULT_REACT_VERSION = 18;
|
|
165
|
+
async function detectReactVersion() {
|
|
166
|
+
const cwd = process.cwd();
|
|
167
|
+
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
168
|
+
if (await fs.pathExists(reactPath)) {
|
|
169
|
+
const reactPkg = await fs.readJson(path3.join(reactPath, "package.json"));
|
|
170
|
+
const version = Number(reactPkg.version.split(".")[0]);
|
|
171
|
+
return version;
|
|
172
|
+
} else {
|
|
173
|
+
return DEFAULT_REACT_VERSION;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function resolveReactAlias(reactVersion) {
|
|
177
|
+
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
178
|
+
const libPaths = [
|
|
179
|
+
"react",
|
|
180
|
+
"react/jsx-runtime",
|
|
181
|
+
"react/jsx-dev-runtime",
|
|
182
|
+
"react-dom",
|
|
183
|
+
"react-dom/server"
|
|
184
|
+
];
|
|
185
|
+
if (reactVersion === DEFAULT_REACT_VERSION) {
|
|
186
|
+
libPaths.push("react-dom/client");
|
|
187
|
+
}
|
|
188
|
+
const alias = {};
|
|
189
|
+
const resolver2 = ResolverFactory.createResolver({
|
|
190
|
+
fileSystem: new CachedInputFileSystem(fs),
|
|
191
|
+
extensions: [
|
|
192
|
+
".js"
|
|
193
|
+
],
|
|
194
|
+
alias
|
|
195
|
+
});
|
|
196
|
+
await Promise.all(libPaths.map(async (lib) => {
|
|
197
|
+
try {
|
|
198
|
+
alias[lib] = await new Promise((resolve, reject) => {
|
|
199
|
+
resolver2.resolve({
|
|
200
|
+
importer: basedir
|
|
201
|
+
}, basedir, lib, {}, (err, filePath) => {
|
|
202
|
+
if (err || filePath === false) {
|
|
203
|
+
return reject(err);
|
|
204
|
+
}
|
|
205
|
+
return resolve(filePath);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
} catch (e) {
|
|
209
|
+
console.log(e);
|
|
210
|
+
logger2.warn(`${lib} not found`);
|
|
211
|
+
}
|
|
212
|
+
}));
|
|
213
|
+
return alias;
|
|
214
|
+
}
|
|
221
215
|
|
|
222
216
|
// src/node/utils/flattenMdxContent.ts
|
|
223
217
|
import path4 from "path";
|
|
224
|
-
import
|
|
218
|
+
import enhancedResolve2 from "enhanced-resolve";
|
|
225
219
|
import fs2 from "@modern-js/utils/fs-extra";
|
|
226
220
|
import { createProcessor } from "@mdx-js/mdx";
|
|
227
221
|
import { MDX_REGEXP } from "@rspress/shared";
|
|
228
|
-
var { CachedInputFileSystem, ResolverFactory } =
|
|
222
|
+
var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFactory2 } = enhancedResolve2;
|
|
229
223
|
var processor = createProcessor();
|
|
230
224
|
var resolver;
|
|
231
225
|
var startFlatten = false;
|
|
232
226
|
async function resolveDepPath(importPath, importer, alias) {
|
|
233
227
|
if (!resolver) {
|
|
234
|
-
resolver =
|
|
235
|
-
fileSystem: new
|
|
228
|
+
resolver = ResolverFactory2.createResolver({
|
|
229
|
+
fileSystem: new CachedInputFileSystem2(fs2),
|
|
236
230
|
extensions: [
|
|
237
231
|
".mdx",
|
|
238
|
-
".md"
|
|
239
|
-
".js"
|
|
232
|
+
".md"
|
|
240
233
|
],
|
|
241
234
|
alias
|
|
242
235
|
});
|
|
@@ -259,8 +252,8 @@ async function resolveDepPath(importPath, importer, alias) {
|
|
|
259
252
|
async function flattenMdxContent(content, basePath, alias) {
|
|
260
253
|
let result = content;
|
|
261
254
|
if (!startFlatten) {
|
|
262
|
-
resolver =
|
|
263
|
-
fileSystem: new
|
|
255
|
+
resolver = ResolverFactory2.createResolver({
|
|
256
|
+
fileSystem: new CachedInputFileSystem2(fs2),
|
|
264
257
|
extensions: [
|
|
265
258
|
".mdx",
|
|
266
259
|
".md",
|
|
@@ -298,47 +291,11 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
298
291
|
return result;
|
|
299
292
|
}
|
|
300
293
|
|
|
301
|
-
// src/node/utils/detectReactVersion.ts
|
|
302
|
-
var DEFAULT_REACT_VERSION = 18;
|
|
303
|
-
async function detectReactVersion() {
|
|
304
|
-
const cwd = process.cwd();
|
|
305
|
-
const reactPath = path5.join(cwd, "node_modules", "react");
|
|
306
|
-
if (await fs3.pathExists(reactPath)) {
|
|
307
|
-
const reactPkg = await fs3.readJson(path5.join(reactPath, "package.json"));
|
|
308
|
-
const version = Number(reactPkg.version.split(".")[0]);
|
|
309
|
-
return version;
|
|
310
|
-
} else {
|
|
311
|
-
return DEFAULT_REACT_VERSION;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
async function resolveReactAlias(reactVersion) {
|
|
315
|
-
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
316
|
-
const libPaths = [
|
|
317
|
-
"react",
|
|
318
|
-
"react/jsx-runtime",
|
|
319
|
-
"react/jsx-dev-runtime",
|
|
320
|
-
"react-dom",
|
|
321
|
-
"react-dom/server"
|
|
322
|
-
];
|
|
323
|
-
if (reactVersion === DEFAULT_REACT_VERSION) {
|
|
324
|
-
libPaths.push("react-dom/client");
|
|
325
|
-
}
|
|
326
|
-
const alias = {};
|
|
327
|
-
await Promise.all(libPaths.map(async (lib) => {
|
|
328
|
-
try {
|
|
329
|
-
alias[lib] = await resolveDepPath(lib, basedir, {});
|
|
330
|
-
} catch (e) {
|
|
331
|
-
console.log(`warning: ${lib} not found`);
|
|
332
|
-
}
|
|
333
|
-
}));
|
|
334
|
-
return alias;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
294
|
// src/node/runtimeModule/i18n.ts
|
|
338
|
-
import { join
|
|
295
|
+
import { join } from "path";
|
|
339
296
|
import { createRequire as createRequire2 } from "module";
|
|
340
297
|
var require3 = createRequire2(import.meta.url);
|
|
341
|
-
var DEFAULT_I18N_SOURCE =
|
|
298
|
+
var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
|
|
342
299
|
function getI18nData(docConfig) {
|
|
343
300
|
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
344
301
|
try {
|
|
@@ -349,17 +306,15 @@ function getI18nData(docConfig) {
|
|
|
349
306
|
}
|
|
350
307
|
}
|
|
351
308
|
function i18nVMPlugin(context) {
|
|
352
|
-
const { config
|
|
309
|
+
const { config } = context;
|
|
353
310
|
const i18nData = getI18nData(config);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
311
|
+
return {
|
|
312
|
+
[RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData)}`
|
|
313
|
+
};
|
|
358
314
|
}
|
|
359
315
|
|
|
360
316
|
// src/node/runtimeModule/siteData.ts
|
|
361
317
|
var { loadFront } = yamlFrontMatter;
|
|
362
|
-
var pages;
|
|
363
318
|
function deletePriviteKey(obj) {
|
|
364
319
|
if (typeof obj !== "object" || obj === null) {
|
|
365
320
|
return obj;
|
|
@@ -374,7 +329,7 @@ function deletePriviteKey(obj) {
|
|
|
374
329
|
});
|
|
375
330
|
return newObj;
|
|
376
331
|
}
|
|
377
|
-
function normalizeThemeConfig(docConfig,
|
|
332
|
+
function normalizeThemeConfig(docConfig, pages = []) {
|
|
378
333
|
const { locales: siteLocales, base = "", lang, replaceRules = [] } = docConfig;
|
|
379
334
|
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
380
335
|
const { themeConfig } = docConfig;
|
|
@@ -410,7 +365,7 @@ function normalizeThemeConfig(docConfig, pages2 = []) {
|
|
|
410
365
|
}
|
|
411
366
|
if (typeof item === "string") {
|
|
412
367
|
const normalizedItem = normalizeLangPrefix(item, currentLang);
|
|
413
|
-
const page =
|
|
368
|
+
const page = pages.find((page2) => page2.routePath === withBase(normalizedItem, base));
|
|
414
369
|
return {
|
|
415
370
|
text: applyReplaceRules(page?.title || "", replaceRules),
|
|
416
371
|
link: normalizedItem
|
|
@@ -477,7 +432,7 @@ function normalizeThemeConfig(docConfig, pages2 = []) {
|
|
|
477
432
|
}
|
|
478
433
|
async function extractPageData(replaceRules, alias, domain, root, routeService2) {
|
|
479
434
|
return Promise.all(routeService2.getRoutes().filter((route) => MDX_REGEXP2.test(route.absolutePath)).map(async (route, index) => {
|
|
480
|
-
let content = await
|
|
435
|
+
let content = await fs3.readFile(route.absolutePath, "utf8");
|
|
481
436
|
const frontmatter = {
|
|
482
437
|
...loadFront(content)
|
|
483
438
|
};
|
|
@@ -565,21 +520,17 @@ ${item.text}#
|
|
|
565
520
|
__content: void 0
|
|
566
521
|
},
|
|
567
522
|
_filepath: route.absolutePath,
|
|
568
|
-
_relativePath:
|
|
523
|
+
_relativePath: path5.relative(root, route.absolutePath)
|
|
569
524
|
};
|
|
570
525
|
}));
|
|
571
526
|
}
|
|
572
527
|
async function siteDataVMPlugin(context) {
|
|
573
|
-
const {
|
|
574
|
-
const entryPath = join3(runtimeTempDir, `${RuntimeModuleID.SiteData}.mjs`);
|
|
575
|
-
const searchIndexHashPath = join3(runtimeTempDir, `${RuntimeModuleID.SearchIndexHash}.js`);
|
|
528
|
+
const { config, alias, userRoot, routeService: routeService2, pluginDriver } = context;
|
|
576
529
|
const userConfig = config;
|
|
577
530
|
const replaceRules = userConfig?.replaceRules || [];
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
await pluginDriver.modifySearchIndexData(pages);
|
|
582
|
-
}
|
|
531
|
+
const domain = userConfig?.search && userConfig?.search?.mode === "remote" ? userConfig?.search.domain ?? "" : "";
|
|
532
|
+
const pages = (await extractPageData(replaceRules, alias, domain, userRoot, routeService2)).filter(Boolean);
|
|
533
|
+
await pluginDriver.modifySearchIndexData(pages);
|
|
583
534
|
const pagesByLang = pages.reduce((acc, page) => {
|
|
584
535
|
if (!acc[page.lang]) {
|
|
585
536
|
acc[page.lang] = [];
|
|
@@ -595,8 +546,8 @@ async function siteDataVMPlugin(context) {
|
|
|
595
546
|
const stringfiedIndex = JSON.stringify(pagesByLang[lang].map(deletePriviteKey));
|
|
596
547
|
const indexHash = createHash(stringfiedIndex);
|
|
597
548
|
indexHashByLang[lang] = indexHash;
|
|
598
|
-
await
|
|
599
|
-
await
|
|
549
|
+
await fs3.ensureDir(TEMP_DIR);
|
|
550
|
+
await fs3.writeFile(path5.join(TEMP_DIR, `${SEARCH_INDEX_NAME}.${lang}.${indexHash}.json`), stringfiedIndex);
|
|
600
551
|
}));
|
|
601
552
|
await Promise.all(pages.map(async (pageData) => pluginDriver.extendPageData(pageData)));
|
|
602
553
|
const siteData = {
|
|
@@ -611,72 +562,86 @@ async function siteDataVMPlugin(context) {
|
|
|
611
562
|
mode: "local"
|
|
612
563
|
},
|
|
613
564
|
pages: pages.map((page) => {
|
|
614
|
-
const { content, id, domain, _filepath, ...rest } = page;
|
|
565
|
+
const { content, id, domain: domain2, _filepath, ...rest } = page;
|
|
615
566
|
return rest;
|
|
616
567
|
}),
|
|
617
568
|
markdown: {
|
|
618
569
|
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false
|
|
619
570
|
}
|
|
620
571
|
};
|
|
621
|
-
|
|
622
|
-
[
|
|
623
|
-
[
|
|
624
|
-
}
|
|
625
|
-
return plugin;
|
|
572
|
+
return {
|
|
573
|
+
[`${RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData)}`,
|
|
574
|
+
[RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByLang)}`
|
|
575
|
+
};
|
|
626
576
|
}
|
|
627
577
|
|
|
628
578
|
// src/node/runtimeModule/globalUIComponents.ts
|
|
629
|
-
import { join as join4 } from "path";
|
|
630
579
|
async function globalUIComponentsVMPlugin(context) {
|
|
631
|
-
const {
|
|
580
|
+
const { config, pluginDriver } = context;
|
|
632
581
|
let index = 0;
|
|
633
|
-
const modulePath = join4(runtimeTempDir, `${RuntimeModuleID.GlobalComponents}.js`);
|
|
634
582
|
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
635
|
-
const
|
|
583
|
+
const globalComponents = [
|
|
636
584
|
...config?.globalUIComponents || [],
|
|
637
585
|
...globalUIComponentsByPlugins
|
|
638
|
-
]
|
|
586
|
+
];
|
|
587
|
+
const moduleContent = globalComponents.map((source) => {
|
|
588
|
+
const name = `Comp_${index}`;
|
|
589
|
+
if (Array.isArray(source)) {
|
|
590
|
+
return `import ${name} from '${source[0]}';
|
|
591
|
+
const Props_${index++} = ${JSON.stringify(source[1])};
|
|
592
|
+
`;
|
|
593
|
+
} else {
|
|
594
|
+
index++;
|
|
595
|
+
return `import ${name} from '${source}';
|
|
596
|
+
`;
|
|
597
|
+
}
|
|
598
|
+
}).concat(`export default [${Array.from({
|
|
639
599
|
length: index
|
|
640
|
-
}, (_, i) =>
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
600
|
+
}, (_, i) => {
|
|
601
|
+
if (Array.isArray(globalComponents[i])) {
|
|
602
|
+
return `[${`Comp_${i}`}, Props_${i}]`;
|
|
603
|
+
} else {
|
|
604
|
+
return `Comp_${i}`;
|
|
605
|
+
}
|
|
606
|
+
}).join(", ")}];`).join("");
|
|
607
|
+
return {
|
|
608
|
+
[RuntimeModuleID.GlobalComponents]: moduleContent
|
|
609
|
+
};
|
|
644
610
|
}
|
|
645
611
|
|
|
646
612
|
// src/node/runtimeModule/globalStyles.ts
|
|
647
|
-
import
|
|
648
|
-
import fs5 from "@modern-js/utils/fs-extra";
|
|
613
|
+
import fs4 from "@modern-js/utils/fs-extra";
|
|
649
614
|
async function globalStylesVMPlugin(context) {
|
|
650
|
-
const {
|
|
651
|
-
const modulePath = join5(runtimeTempDir, `${RuntimeModuleID.GlobalStyles}.js`);
|
|
615
|
+
const { config, pluginDriver } = context;
|
|
652
616
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
617
|
+
if (config.globalStyles) {
|
|
618
|
+
const source = config.globalStyles;
|
|
619
|
+
const styleContent = await fs4.readFile(source, "utf-8");
|
|
620
|
+
const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
|
|
621
|
+
await fs4.writeFile(source, patchedStyleContent, "utf-8");
|
|
622
|
+
}
|
|
653
623
|
const moduleContent = (await Promise.all([
|
|
654
624
|
config?.globalStyles || "",
|
|
655
625
|
...globalStylesByPlugins
|
|
656
626
|
].filter((source) => source.length > 0).map(async (source) => {
|
|
657
|
-
const styleContent = await fs5.readFile(source, "utf-8");
|
|
658
|
-
const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
|
|
659
|
-
await fs5.writeFile(source, patchedStyleContent, "utf-8");
|
|
660
627
|
return `import ${JSON.stringify(source)};`;
|
|
661
628
|
}))).join("");
|
|
662
|
-
return
|
|
663
|
-
[
|
|
664
|
-
}
|
|
629
|
+
return {
|
|
630
|
+
[RuntimeModuleID.GlobalStyles]: moduleContent
|
|
631
|
+
};
|
|
665
632
|
}
|
|
666
633
|
|
|
667
634
|
// src/node/runtimeModule/searchHooks.ts
|
|
668
|
-
import
|
|
669
|
-
import fs6 from "@modern-js/utils/fs-extra";
|
|
635
|
+
import fs5 from "@modern-js/utils/fs-extra";
|
|
670
636
|
async function searchHookVMPlugin(context) {
|
|
671
637
|
const { config } = context;
|
|
672
638
|
let content = "export const onSearch = () => {}";
|
|
673
639
|
if (typeof config.search === "object" && typeof config.search.searchHooks === "string") {
|
|
674
|
-
content = await
|
|
640
|
+
content = await fs5.readFile(config.search.searchHooks, "utf-8");
|
|
675
641
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
});
|
|
642
|
+
return {
|
|
643
|
+
[`${RuntimeModuleID.SearchHooks}.ts`]: content
|
|
644
|
+
};
|
|
680
645
|
}
|
|
681
646
|
|
|
682
647
|
// src/node/runtimeModule/index.ts
|
|
@@ -712,13 +677,15 @@ function builderDocVMPlugin(factoryContext) {
|
|
|
712
677
|
setup(api) {
|
|
713
678
|
api.modifyBundlerChain(async (bundlerChain) => {
|
|
714
679
|
const alias = bundlerChain.resolve.alias.entries();
|
|
715
|
-
|
|
680
|
+
const runtimeModule = {};
|
|
716
681
|
for (const factory of runtimeModuleFactory) {
|
|
717
|
-
|
|
682
|
+
const moduleResult = await factory({
|
|
718
683
|
...factoryContext,
|
|
719
684
|
alias
|
|
720
|
-
})
|
|
685
|
+
});
|
|
686
|
+
Object.assign(runtimeModule, moduleResult);
|
|
721
687
|
}
|
|
688
|
+
bundlerChain.plugin(`rspress-runtime-module`).use(new RspackVirtualModulePlugin(runtimeModule, factoryContext.runtimeTempDir));
|
|
722
689
|
});
|
|
723
690
|
}
|
|
724
691
|
};
|
|
@@ -746,8 +713,8 @@ var runtimeModuleIDs = [
|
|
|
746
713
|
];
|
|
747
714
|
|
|
748
715
|
// src/node/searchIndex.ts
|
|
749
|
-
import
|
|
750
|
-
import
|
|
716
|
+
import path6, { join as join2 } from "path";
|
|
717
|
+
import fs6 from "@modern-js/utils/fs-extra";
|
|
751
718
|
import chalk from "@modern-js/utils/chalk";
|
|
752
719
|
import fetch from "node-fetch";
|
|
753
720
|
import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
|
|
@@ -756,19 +723,19 @@ async function writeSearchIndex(config) {
|
|
|
756
723
|
return;
|
|
757
724
|
}
|
|
758
725
|
const cwd = process.cwd();
|
|
759
|
-
const searchIndexFiles = await
|
|
760
|
-
const outDir = config?.outDir ??
|
|
726
|
+
const searchIndexFiles = await fs6.readdir(TEMP_DIR);
|
|
727
|
+
const outDir = config?.outDir ?? join2(cwd, OUTPUT_DIR);
|
|
761
728
|
let searchIndexData = "[]";
|
|
762
729
|
let scaning = false;
|
|
763
730
|
for (const searchIndexFile of searchIndexFiles) {
|
|
764
731
|
if (!searchIndexFile.includes(SEARCH_INDEX_NAME2) || !searchIndexFile.endsWith(".json")) {
|
|
765
732
|
continue;
|
|
766
733
|
}
|
|
767
|
-
const source =
|
|
768
|
-
const target =
|
|
769
|
-
const searchIndex = await
|
|
734
|
+
const source = join2(TEMP_DIR, searchIndexFile);
|
|
735
|
+
const target = join2(outDir, "static", searchIndexFile);
|
|
736
|
+
const searchIndex = await fs6.readFile(join2(TEMP_DIR, searchIndexFile), "utf-8");
|
|
770
737
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scaning ? "," : ""}${searchIndex.slice(1)}`;
|
|
771
|
-
await
|
|
738
|
+
await fs6.move(source, target, {
|
|
772
739
|
overwrite: true
|
|
773
740
|
});
|
|
774
741
|
scaning = true;
|
|
@@ -796,7 +763,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
796
763
|
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
797
764
|
res.setHeader("Content-Type", "application/json");
|
|
798
765
|
const searchIndexFile = req.url?.split("/").pop();
|
|
799
|
-
const searchIndex =
|
|
766
|
+
const searchIndex = fs6.readFileSync(path6.join(process.cwd(), config?.outDir || OUTPUT_DIR, "static", searchIndexFile), "utf-8");
|
|
800
767
|
res.end(searchIndex);
|
|
801
768
|
} else {
|
|
802
769
|
next?.();
|
|
@@ -805,10 +772,10 @@ function serveSearchIndexMiddleware(config) {
|
|
|
805
772
|
}
|
|
806
773
|
|
|
807
774
|
// src/node/route/RouteService.ts
|
|
808
|
-
import
|
|
809
|
-
import
|
|
775
|
+
import path7 from "path";
|
|
776
|
+
import fs7 from "@modern-js/utils/fs-extra";
|
|
810
777
|
import { withBase as withBase2 } from "@rspress/shared";
|
|
811
|
-
function
|
|
778
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
812
779
|
if (privateCollection.has(obj)) {
|
|
813
780
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
814
781
|
}
|
|
@@ -840,7 +807,7 @@ function _class_private_field_get(receiver, privateMap) {
|
|
|
840
807
|
return _class_apply_descriptor_get(receiver, descriptor);
|
|
841
808
|
}
|
|
842
809
|
function _class_private_field_init(obj, privateMap, value) {
|
|
843
|
-
|
|
810
|
+
_check_private_redeclaration(obj, privateMap);
|
|
844
811
|
privateMap.set(obj, value);
|
|
845
812
|
}
|
|
846
813
|
function _class_private_field_set(receiver, privateMap, value) {
|
|
@@ -848,17 +815,17 @@ function _class_private_field_set(receiver, privateMap, value) {
|
|
|
848
815
|
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
849
816
|
return value;
|
|
850
817
|
}
|
|
851
|
-
function
|
|
818
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
852
819
|
if (!privateSet.has(receiver)) {
|
|
853
820
|
throw new TypeError("attempted to get private field on non-instance");
|
|
854
821
|
}
|
|
855
822
|
return fn;
|
|
856
823
|
}
|
|
857
|
-
function
|
|
858
|
-
|
|
824
|
+
function _class_private_method_init(obj, privateSet) {
|
|
825
|
+
_check_private_redeclaration(obj, privateSet);
|
|
859
826
|
privateSet.add(obj);
|
|
860
827
|
}
|
|
861
|
-
function
|
|
828
|
+
function _define_property(obj, key, value) {
|
|
862
829
|
if (key in obj) {
|
|
863
830
|
Object.defineProperty(obj, key, {
|
|
864
831
|
value,
|
|
@@ -916,13 +883,13 @@ var RouteService = class {
|
|
|
916
883
|
]
|
|
917
884
|
}).sort();
|
|
918
885
|
files.forEach((filePath) => {
|
|
919
|
-
const fileRelativePath =
|
|
920
|
-
const lang =
|
|
886
|
+
const fileRelativePath = normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filePath));
|
|
887
|
+
const lang = _class_private_method_get(this, _getLang, getLang).call(this, fileRelativePath);
|
|
921
888
|
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
922
|
-
const absolutePath =
|
|
889
|
+
const absolutePath = path7.join(_class_private_field_get(this, _scanDir), fileRelativePath);
|
|
923
890
|
const routeInfo = {
|
|
924
891
|
routePath,
|
|
925
|
-
absolutePath:
|
|
892
|
+
absolutePath: normalizePath(absolutePath),
|
|
926
893
|
relativePath: fileRelativePath,
|
|
927
894
|
pageName: getPageKey(fileRelativePath),
|
|
928
895
|
lang
|
|
@@ -933,13 +900,13 @@ var RouteService = class {
|
|
|
933
900
|
await Promise.all(externalPages.map(async (route, index) => {
|
|
934
901
|
const { routePath, content, filepath } = route;
|
|
935
902
|
if (filepath) {
|
|
936
|
-
const routeInfo =
|
|
903
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
937
904
|
this.addRoute(routeInfo);
|
|
938
905
|
return;
|
|
939
906
|
}
|
|
940
907
|
if (content) {
|
|
941
|
-
const filepath2 = await
|
|
942
|
-
const routeInfo =
|
|
908
|
+
const filepath2 = await _class_private_method_get(this, _writeTempFile, writeTempFile).call(this, index, content);
|
|
909
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath2);
|
|
943
910
|
this.addRoute(routeInfo);
|
|
944
911
|
}
|
|
945
912
|
}));
|
|
@@ -948,8 +915,8 @@ var RouteService = class {
|
|
|
948
915
|
addRoute(routeInfo) {
|
|
949
916
|
const { routePath, absolutePath } = routeInfo;
|
|
950
917
|
if (this.routeData.has(routePath)) {
|
|
951
|
-
const preRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(
|
|
952
|
-
const currRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(
|
|
918
|
+
const preRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(path7.extname(this.routeData.get(routePath).absolutePath).slice(1));
|
|
919
|
+
const currRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(path7.extname(absolutePath).slice(1));
|
|
953
920
|
if (currRouteExtIndex !== -1 && (currRouteExtIndex < preRouteExtIndex || preRouteExtIndex === -1)) {
|
|
954
921
|
this.routeData.set(routePath, routeInfo);
|
|
955
922
|
}
|
|
@@ -958,7 +925,7 @@ var RouteService = class {
|
|
|
958
925
|
}
|
|
959
926
|
}
|
|
960
927
|
removeRoute(filePath) {
|
|
961
|
-
const fileRelativePath =
|
|
928
|
+
const fileRelativePath = path7.relative(_class_private_field_get(this, _scanDir), filePath);
|
|
962
929
|
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
963
930
|
this.routeData.delete(routePath);
|
|
964
931
|
}
|
|
@@ -992,10 +959,10 @@ ${this.getRoutes().map((route, index) => {
|
|
|
992
959
|
`;
|
|
993
960
|
}
|
|
994
961
|
constructor(scanDir, userConfig, tempDir, pluginDriver) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
962
|
+
_class_private_method_init(this, _writeTempFile);
|
|
963
|
+
_class_private_method_init(this, _getLang);
|
|
964
|
+
_class_private_method_init(this, _generateRouteInfo);
|
|
965
|
+
_define_property(this, "routeData", /* @__PURE__ */ new Map());
|
|
999
966
|
_class_private_field_init(this, _scanDir, {
|
|
1000
967
|
writable: true,
|
|
1001
968
|
value: void 0
|
|
@@ -1045,8 +1012,8 @@ ${this.getRoutes().map((route, index) => {
|
|
|
1045
1012
|
}
|
|
1046
1013
|
};
|
|
1047
1014
|
async function writeTempFile(index, content) {
|
|
1048
|
-
const tempFilePath =
|
|
1049
|
-
await
|
|
1015
|
+
const tempFilePath = path7.join(_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
1016
|
+
await fs7.writeFile(tempFilePath, content);
|
|
1050
1017
|
return tempFilePath;
|
|
1051
1018
|
}
|
|
1052
1019
|
function getLang(filepath) {
|
|
@@ -1055,10 +1022,10 @@ function getLang(filepath) {
|
|
|
1055
1022
|
function generateRouteInfo(routePath, filepath) {
|
|
1056
1023
|
return {
|
|
1057
1024
|
routePath: normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base)),
|
|
1058
|
-
absolutePath:
|
|
1059
|
-
relativePath:
|
|
1025
|
+
absolutePath: normalizePath(filepath),
|
|
1026
|
+
relativePath: normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filepath)),
|
|
1060
1027
|
pageName: getPageKey(routePath),
|
|
1061
|
-
lang:
|
|
1028
|
+
lang: _class_private_method_get(this, _getLang, getLang).call(this, filepath)
|
|
1062
1029
|
};
|
|
1063
1030
|
}
|
|
1064
1031
|
|
|
@@ -1073,17 +1040,17 @@ async function initRouteService(options) {
|
|
|
1073
1040
|
|
|
1074
1041
|
// src/node/createBuilder.ts
|
|
1075
1042
|
var require4 = createRequire3(import.meta.url);
|
|
1076
|
-
async function createInternalBuildConfig(userRoot, config, isSSR,
|
|
1043
|
+
async function createInternalBuildConfig(userRoot, config, isSSR, routeService2) {
|
|
1077
1044
|
const cwd = process.cwd();
|
|
1078
|
-
const { default:
|
|
1079
|
-
const CUSTOM_THEME_DIR = config?.themeDir ??
|
|
1045
|
+
const { default: fs10 } = await import("@modern-js/utils/fs-extra");
|
|
1046
|
+
const CUSTOM_THEME_DIR = config?.themeDir ?? path8.join(process.cwd(), "theme");
|
|
1080
1047
|
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1081
|
-
const DEFAULT_THEME_DIR = isDebugMode() ?
|
|
1082
|
-
const themeDir = await
|
|
1048
|
+
const DEFAULT_THEME_DIR = isDebugMode() ? path8.join(PACKAGE_ROOT, "src", "theme-default") : path8.join(PACKAGE_ROOT, "dist", "theme");
|
|
1049
|
+
const themeDir = await fs10.pathExists(CUSTOM_THEME_DIR) ? CUSTOM_THEME_DIR : DEFAULT_THEME_DIR;
|
|
1083
1050
|
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isSSR) ?? false;
|
|
1084
1051
|
const base = config?.base ?? "";
|
|
1085
|
-
const publicDir =
|
|
1086
|
-
const isPublicDirExist = await
|
|
1052
|
+
const publicDir = path8.join(userRoot, "public");
|
|
1053
|
+
const isPublicDirExist = await fs10.pathExists(publicDir);
|
|
1087
1054
|
const assetPrefix = isProduction() ? removeTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : "";
|
|
1088
1055
|
const enableMdxRs = config?.markdown?.experimentalMdxRs ?? false;
|
|
1089
1056
|
const reactVersion = await detectReactVersion();
|
|
@@ -1110,12 +1077,12 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1110
1077
|
},
|
|
1111
1078
|
html: {
|
|
1112
1079
|
favicon: config?.icon,
|
|
1113
|
-
template:
|
|
1080
|
+
template: path8.join(PACKAGE_ROOT, "index.html")
|
|
1114
1081
|
},
|
|
1115
1082
|
output: {
|
|
1116
1083
|
distPath: {
|
|
1117
1084
|
// `root` must be a relative path in Builder
|
|
1118
|
-
root:
|
|
1085
|
+
root: path8.isAbsolute(outDir) ? path8.relative(cwd, outDir) : outDir
|
|
1119
1086
|
},
|
|
1120
1087
|
// TODO: switch to 'usage' if Rspack supports it
|
|
1121
1088
|
polyfill: "entry",
|
|
@@ -1129,21 +1096,18 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1129
1096
|
source: {
|
|
1130
1097
|
alias: {
|
|
1131
1098
|
"@mdx-js/react": require4.resolve("@mdx-js/react"),
|
|
1132
|
-
"@/runtime":
|
|
1099
|
+
"@/runtime": path8.join(PACKAGE_ROOT, "dist", "runtime"),
|
|
1133
1100
|
"@theme": themeDir,
|
|
1101
|
+
"@/theme-default": DEFAULT_THEME_DIR,
|
|
1134
1102
|
"@rspress/core": PACKAGE_ROOT,
|
|
1135
1103
|
"react-lazy-with-preload": require4.resolve("react-lazy-with-preload"),
|
|
1136
|
-
...runtimeModuleIDs.reduce((acc, cur) => {
|
|
1137
|
-
acc[cur] = path9.join(runtimeTempDir, cur);
|
|
1138
|
-
return acc;
|
|
1139
|
-
}, {}),
|
|
1140
1104
|
...await resolveReactAlias(reactVersion)
|
|
1141
1105
|
},
|
|
1142
1106
|
include: [
|
|
1143
1107
|
PACKAGE_ROOT
|
|
1144
1108
|
],
|
|
1145
1109
|
define: {
|
|
1146
|
-
__ASSET_PREFIX__: JSON.stringify(assetPrefix),
|
|
1110
|
+
"process.env.__ASSET_PREFIX__": JSON.stringify(assetPrefix),
|
|
1147
1111
|
"process.env.__SSR__": JSON.stringify(isSSR),
|
|
1148
1112
|
"process.env.__IS_REACT_18__": JSON.stringify(reactVersion === 18),
|
|
1149
1113
|
"process.env.TEST": JSON.stringify(process.env.TEST)
|
|
@@ -1166,12 +1130,19 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1166
1130
|
config: {
|
|
1167
1131
|
...tailwindConfig,
|
|
1168
1132
|
content: [
|
|
1169
|
-
|
|
1133
|
+
path8.join(PACKAGE_ROOT, "src", "theme-default", "**/*")
|
|
1170
1134
|
]
|
|
1171
1135
|
}
|
|
1172
1136
|
}));
|
|
1173
1137
|
}
|
|
1174
1138
|
},
|
|
1139
|
+
rspack: {
|
|
1140
|
+
// This config can be removed after upgrading Rspack v0.4
|
|
1141
|
+
// https://github.com/web-infra-dev/rspack/issues/3096
|
|
1142
|
+
optimization: {
|
|
1143
|
+
chunkIds: "deterministic"
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1175
1146
|
bundlerChain(chain) {
|
|
1176
1147
|
chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(require4.resolve("../loader.cjs")).options({
|
|
1177
1148
|
config,
|
|
@@ -1189,19 +1160,20 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1189
1160
|
}
|
|
1190
1161
|
async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false, extraBuilderConfig) {
|
|
1191
1162
|
const cwd = process.cwd();
|
|
1192
|
-
const userRoot =
|
|
1163
|
+
const userRoot = path8.resolve(rootDir || config?.root || cwd);
|
|
1193
1164
|
const builderPlugins = config?.builderPlugins ?? [];
|
|
1194
|
-
const runtimeTempDir =
|
|
1195
|
-
|
|
1165
|
+
const runtimeTempDir = path8.join(RSPRESS_TEMP_DIR2, "runtime");
|
|
1166
|
+
const runtimeAbsTempDir = path8.join(cwd, "node_modules", runtimeTempDir);
|
|
1167
|
+
await fs8.ensureDir(runtimeAbsTempDir);
|
|
1196
1168
|
const routeService2 = await initRouteService({
|
|
1197
1169
|
config,
|
|
1198
|
-
runtimeTempDir,
|
|
1170
|
+
runtimeTempDir: runtimeAbsTempDir,
|
|
1199
1171
|
scanDir: userRoot,
|
|
1200
1172
|
pluginDriver
|
|
1201
1173
|
});
|
|
1202
1174
|
const { default: { createBuilder, mergeBuilderConfig } } = await import("@modern-js/builder");
|
|
1203
1175
|
const { default: { builderRspackProvider } } = await import("@modern-js/builder-rspack-provider");
|
|
1204
|
-
const internalBuilderConfig = await createInternalBuildConfig(userRoot, config, isSSR,
|
|
1176
|
+
const internalBuilderConfig = await createInternalBuildConfig(userRoot, config, isSSR, routeService2);
|
|
1205
1177
|
const builderProvider = builderRspackProvider({
|
|
1206
1178
|
builderConfig: mergeBuilderConfig(internalBuilderConfig, ...config?.plugins?.map((plugin) => plugin.builderConfig ?? {}) || [], config?.builderConfig || {}, extraBuilderConfig || {})
|
|
1207
1179
|
});
|
|
@@ -1227,7 +1199,8 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
|
|
|
1227
1199
|
}
|
|
1228
1200
|
|
|
1229
1201
|
// src/node/PluginDriver.ts
|
|
1230
|
-
|
|
1202
|
+
import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
|
|
1203
|
+
function _check_private_redeclaration2(obj, privateCollection) {
|
|
1231
1204
|
if (privateCollection.has(obj)) {
|
|
1232
1205
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
1233
1206
|
}
|
|
@@ -1259,7 +1232,7 @@ function _class_private_field_get2(receiver, privateMap) {
|
|
|
1259
1232
|
return _class_apply_descriptor_get2(receiver, descriptor);
|
|
1260
1233
|
}
|
|
1261
1234
|
function _class_private_field_init2(obj, privateMap, value) {
|
|
1262
|
-
|
|
1235
|
+
_check_private_redeclaration2(obj, privateMap);
|
|
1263
1236
|
privateMap.set(obj, value);
|
|
1264
1237
|
}
|
|
1265
1238
|
function _class_private_field_set2(receiver, privateMap, value) {
|
|
@@ -1285,12 +1258,13 @@ var PluginDriver = class {
|
|
|
1285
1258
|
}
|
|
1286
1259
|
if (mediumZoomConfig) {
|
|
1287
1260
|
const { pluginMediumZoom } = await import("@rspress/plugin-medium-zoom");
|
|
1288
|
-
this.addPlugin(pluginMediumZoom());
|
|
1261
|
+
this.addPlugin(pluginMediumZoom(typeof mediumZoomConfig === "object" ? mediumZoomConfig : void 0));
|
|
1289
1262
|
}
|
|
1290
1263
|
if (!haveNavSidebarConfig) {
|
|
1291
1264
|
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
1292
1265
|
this.addPlugin(pluginAutoNavSidebar());
|
|
1293
1266
|
}
|
|
1267
|
+
this.addPlugin(pluginContainerSyntax());
|
|
1294
1268
|
(config.plugins || []).forEach((plugin) => {
|
|
1295
1269
|
this.addPlugin(plugin);
|
|
1296
1270
|
});
|
|
@@ -1322,8 +1296,8 @@ var PluginDriver = class {
|
|
|
1322
1296
|
async afterBuild() {
|
|
1323
1297
|
return this._runParallelAsyncHook("afterBuild", _class_private_field_get2(this, _config) || {}, _class_private_field_get2(this, _isProd));
|
|
1324
1298
|
}
|
|
1325
|
-
async modifySearchIndexData(
|
|
1326
|
-
return this._runParallelAsyncHook("modifySearchIndexData",
|
|
1299
|
+
async modifySearchIndexData(pages) {
|
|
1300
|
+
return this._runParallelAsyncHook("modifySearchIndexData", pages);
|
|
1327
1301
|
}
|
|
1328
1302
|
async extendPageData(pageData) {
|
|
1329
1303
|
return this._runParallelAsyncHook("extendPageData", pageData);
|
|
@@ -1392,7 +1366,6 @@ async function dev(options) {
|
|
|
1392
1366
|
try {
|
|
1393
1367
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1394
1368
|
await pluginDriver.beforeBuild();
|
|
1395
|
-
await fs10.emptyDir(TEMP_DIR);
|
|
1396
1369
|
const builder = await createModernBuilder(docDirectory, modifiedConfig, pluginDriver, false, {});
|
|
1397
1370
|
const { server } = await builder.startDevServer({
|
|
1398
1371
|
printURLs: (urls) => {
|
|
@@ -1403,7 +1376,7 @@ async function dev(options) {
|
|
|
1403
1376
|
},
|
|
1404
1377
|
// We will support the following options in the future
|
|
1405
1378
|
getPortSilently: true,
|
|
1406
|
-
logger:
|
|
1379
|
+
logger: logger3
|
|
1407
1380
|
});
|
|
1408
1381
|
await pluginDriver.afterBuild();
|
|
1409
1382
|
return server;
|
|
@@ -1413,10 +1386,10 @@ async function dev(options) {
|
|
|
1413
1386
|
}
|
|
1414
1387
|
|
|
1415
1388
|
// src/node/build.ts
|
|
1416
|
-
import { dirname as dirname2, isAbsolute, join as
|
|
1389
|
+
import { dirname as dirname2, isAbsolute, join as join3 } from "path";
|
|
1417
1390
|
import { pathToFileURL } from "url";
|
|
1418
1391
|
import chalk2 from "@modern-js/utils/chalk";
|
|
1419
|
-
import
|
|
1392
|
+
import fs9 from "@modern-js/utils/fs-extra";
|
|
1420
1393
|
import { APPEARANCE_KEY, normalizeSlash, withBase as withBase3 } from "@rspress/shared";
|
|
1421
1394
|
var CHECK_DARK_LIGHT_SCRIPT = `
|
|
1422
1395
|
<script id="check-dark-light">
|
|
@@ -1455,10 +1428,10 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
|
|
|
1455
1428
|
logoPaths.push(logo.dark);
|
|
1456
1429
|
}
|
|
1457
1430
|
logoPaths.filter((p) => p.startsWith("/")).forEach((p) => {
|
|
1458
|
-
const normalize = (rawPath) => isAbsolute(rawPath) ? rawPath :
|
|
1459
|
-
const logoPath =
|
|
1460
|
-
const outputLogoPath =
|
|
1461
|
-
|
|
1431
|
+
const normalize = (rawPath) => isAbsolute(rawPath) ? rawPath : join3(appDirectory, rawPath);
|
|
1432
|
+
const logoPath = join3(normalize(docDirectory || config.root), PUBLIC_DIR, p);
|
|
1433
|
+
const outputLogoPath = join3(normalize(outputDir), p);
|
|
1434
|
+
fs9.copyFileSync(logoPath, outputLogoPath);
|
|
1462
1435
|
});
|
|
1463
1436
|
} finally {
|
|
1464
1437
|
await writeSearchIndex(config);
|
|
@@ -1467,10 +1440,10 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
|
|
|
1467
1440
|
async function renderPages(appDirectory, config, pluginDriver) {
|
|
1468
1441
|
logger.info("Rendering pages...");
|
|
1469
1442
|
const startTime = Date.now();
|
|
1470
|
-
const outputPath = config?.outDir ??
|
|
1471
|
-
const ssrBundlePath =
|
|
1443
|
+
const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
|
|
1444
|
+
const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
|
|
1472
1445
|
try {
|
|
1473
|
-
const { default:
|
|
1446
|
+
const { default: fs10 } = await import("@modern-js/utils/fs-extra");
|
|
1474
1447
|
let render = null;
|
|
1475
1448
|
try {
|
|
1476
1449
|
const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
|
|
@@ -1480,8 +1453,8 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1480
1453
|
}
|
|
1481
1454
|
const routes = routeService.getRoutes();
|
|
1482
1455
|
const base = config?.base ?? "";
|
|
1483
|
-
const htmlTemplatePath =
|
|
1484
|
-
const htmlTemplate = await
|
|
1456
|
+
const htmlTemplatePath = join3(outputPath, "html", "main", "index.html");
|
|
1457
|
+
const htmlTemplate = await fs10.readFile(htmlTemplatePath, "utf-8");
|
|
1485
1458
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
1486
1459
|
routePath: withBase3(route.path, base)
|
|
1487
1460
|
}));
|
|
@@ -1518,19 +1491,19 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1518
1491
|
if (helmet?.bodyAttributes) {
|
|
1519
1492
|
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${helmet?.bodyAttributes?.toString()}`);
|
|
1520
1493
|
}
|
|
1521
|
-
const normalizeHtmlFilePath = (
|
|
1494
|
+
const normalizeHtmlFilePath = (path9) => {
|
|
1522
1495
|
const normalizedBase = normalizeSlash(config?.base || "/");
|
|
1523
|
-
if (
|
|
1524
|
-
return `${
|
|
1496
|
+
if (path9.endsWith("/")) {
|
|
1497
|
+
return `${path9}index.html`.replace(normalizedBase, "");
|
|
1525
1498
|
}
|
|
1526
|
-
return `${
|
|
1499
|
+
return `${path9}.html`.replace(normalizedBase, "");
|
|
1527
1500
|
};
|
|
1528
1501
|
const fileName = normalizeHtmlFilePath(routePath);
|
|
1529
|
-
await
|
|
1530
|
-
await
|
|
1502
|
+
await fs10.ensureDir(join3(outputPath, dirname2(fileName)));
|
|
1503
|
+
await fs10.writeFile(join3(outputPath, fileName), html);
|
|
1531
1504
|
}));
|
|
1532
|
-
await
|
|
1533
|
-
await
|
|
1505
|
+
await fs10.remove(join3(outputPath, "ssr"));
|
|
1506
|
+
await fs10.remove(join3(outputPath, "html"));
|
|
1534
1507
|
const totalTime = Date.now() - startTime;
|
|
1535
1508
|
logger.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
|
|
1536
1509
|
} catch (e) {
|
|
@@ -1544,7 +1517,7 @@ async function build(options) {
|
|
|
1544
1517
|
await pluginDriver.init();
|
|
1545
1518
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1546
1519
|
await pluginDriver.beforeBuild();
|
|
1547
|
-
await
|
|
1520
|
+
await fs9.emptyDir(TEMP_DIR);
|
|
1548
1521
|
await bundle(appDirectory, docDirectory, modifiedConfig, pluginDriver);
|
|
1549
1522
|
await renderPages(appDirectory, modifiedConfig, pluginDriver);
|
|
1550
1523
|
await pluginDriver.afterBuild();
|