@rspress/core 0.0.9 → 0.0.10
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 +189 -234
- package/dist/index.js.map +1 -1
- package/dist/loader.js +1 -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 +930 -926
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +14 -13
- 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/index.module.scss +0 -1
- package/src/theme-default/components/Nav/index.tsx +3 -3
- 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 +60 -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 +0 -1
- package/src/theme-default/logic/sideEffects.ts +3 -1
- package/src/theme-default/logic/useEditLink.ts +6 -3
- 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,14 @@
|
|
|
1
1
|
// src/node/dev.ts
|
|
2
2
|
import { removeLeadingSlash as removeLeadingSlash2 } from "@rspress/shared";
|
|
3
|
-
import
|
|
3
|
+
import fs9 from "@modern-js/utils/fs-extra";
|
|
4
|
+
import { logger as logger3 } from "@rspress/shared/logger";
|
|
4
5
|
|
|
5
6
|
// src/node/createBuilder.ts
|
|
6
|
-
import
|
|
7
|
+
import path8 from "path";
|
|
7
8
|
import { createRequire as createRequire3 } from "module";
|
|
8
9
|
import { isDebugMode, removeTrailingSlash } from "@rspress/shared";
|
|
9
10
|
import sirv from "sirv";
|
|
10
|
-
import
|
|
11
|
+
import fs8 from "@modern-js/utils/fs-extra";
|
|
11
12
|
|
|
12
13
|
// tailwind.config.ts
|
|
13
14
|
var tailwindConfig = {
|
|
@@ -97,85 +98,25 @@ var PUBLIC_DIR = "public";
|
|
|
97
98
|
var TEMP_DIR = path.join(process.cwd(), "node_modules", RSPRESS_TEMP_DIR);
|
|
98
99
|
|
|
99
100
|
// src/node/runtimeModule/routeData.ts
|
|
100
|
-
import { join } from "path";
|
|
101
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
|
-
}
|
|
159
|
-
|
|
160
|
-
// src/node/runtimeModule/routeData.ts
|
|
102
|
+
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
161
103
|
async function routeVMPlugin(context) {
|
|
162
|
-
const {
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
[routeModulePathForClient]: routeService2.generateRoutesCode(false),
|
|
167
|
-
[routeModulePathForSSR]: routeService2.generateRoutesCode(true)
|
|
104
|
+
const { routeService: routeService2 } = context;
|
|
105
|
+
const plugin = new RspackVirtualModulePlugin({
|
|
106
|
+
[RuntimeModuleID.RouteForClient]: routeService2.generateRoutesCode(false),
|
|
107
|
+
[RuntimeModuleID.RouteForSSR]: routeService2.generateRoutesCode(true)
|
|
168
108
|
});
|
|
169
109
|
return plugin;
|
|
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";
|
|
119
|
+
import { RspackVirtualModulePlugin as RspackVirtualModulePlugin3 } from "rspack-plugin-virtual-module";
|
|
179
120
|
|
|
180
121
|
// src/node/utils/applyReplaceRules.ts
|
|
181
122
|
function applyReplaceRules(code = "", replaceRules = []) {
|
|
@@ -188,13 +129,13 @@ function applyReplaceRules(code = "", replaceRules = []) {
|
|
|
188
129
|
|
|
189
130
|
// src/node/utils/normalizePath.ts
|
|
190
131
|
import os from "os";
|
|
191
|
-
import
|
|
132
|
+
import path2 from "path";
|
|
192
133
|
var isWindows = os.platform() === "win32";
|
|
193
134
|
function slash(p) {
|
|
194
135
|
return p.replace(/\\/g, "/");
|
|
195
136
|
}
|
|
196
|
-
function
|
|
197
|
-
return
|
|
137
|
+
function normalizePath(id) {
|
|
138
|
+
return path2.posix.normalize(isWindows ? slash(id) : id);
|
|
198
139
|
}
|
|
199
140
|
|
|
200
141
|
// src/node/utils/getPageKey.ts
|
|
@@ -216,27 +157,80 @@ var require2 = createRequire(import.meta.url);
|
|
|
216
157
|
var { logger } = require2("@modern-js/utils/logger");
|
|
217
158
|
|
|
218
159
|
// src/node/utils/detectReactVersion.ts
|
|
219
|
-
import
|
|
220
|
-
import
|
|
160
|
+
import path3 from "path";
|
|
161
|
+
import fs from "@modern-js/utils/fs-extra";
|
|
162
|
+
import { logger as logger2 } from "@rspress/shared/logger";
|
|
163
|
+
import enhancedResolve from "enhanced-resolve";
|
|
164
|
+
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
165
|
+
var DEFAULT_REACT_VERSION = 18;
|
|
166
|
+
async function detectReactVersion() {
|
|
167
|
+
const cwd = process.cwd();
|
|
168
|
+
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
169
|
+
if (await fs.pathExists(reactPath)) {
|
|
170
|
+
const reactPkg = await fs.readJson(path3.join(reactPath, "package.json"));
|
|
171
|
+
const version = Number(reactPkg.version.split(".")[0]);
|
|
172
|
+
return version;
|
|
173
|
+
} else {
|
|
174
|
+
return DEFAULT_REACT_VERSION;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function resolveReactAlias(reactVersion) {
|
|
178
|
+
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
179
|
+
const libPaths = [
|
|
180
|
+
"react",
|
|
181
|
+
"react/jsx-runtime",
|
|
182
|
+
"react/jsx-dev-runtime",
|
|
183
|
+
"react-dom",
|
|
184
|
+
"react-dom/server"
|
|
185
|
+
];
|
|
186
|
+
if (reactVersion === DEFAULT_REACT_VERSION) {
|
|
187
|
+
libPaths.push("react-dom/client");
|
|
188
|
+
}
|
|
189
|
+
const alias = {};
|
|
190
|
+
const resolver2 = ResolverFactory.createResolver({
|
|
191
|
+
fileSystem: new CachedInputFileSystem(fs),
|
|
192
|
+
extensions: [
|
|
193
|
+
".js"
|
|
194
|
+
],
|
|
195
|
+
alias
|
|
196
|
+
});
|
|
197
|
+
await Promise.all(libPaths.map(async (lib) => {
|
|
198
|
+
try {
|
|
199
|
+
alias[lib] = await new Promise((resolve, reject) => {
|
|
200
|
+
resolver2.resolve({
|
|
201
|
+
importer: basedir
|
|
202
|
+
}, basedir, lib, {}, (err, filePath) => {
|
|
203
|
+
if (err || filePath === false) {
|
|
204
|
+
return reject(err);
|
|
205
|
+
}
|
|
206
|
+
return resolve(filePath);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.log(e);
|
|
211
|
+
logger2.warn(`${lib} not found`);
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
return alias;
|
|
215
|
+
}
|
|
221
216
|
|
|
222
217
|
// src/node/utils/flattenMdxContent.ts
|
|
223
218
|
import path4 from "path";
|
|
224
|
-
import
|
|
219
|
+
import enhancedResolve2 from "enhanced-resolve";
|
|
225
220
|
import fs2 from "@modern-js/utils/fs-extra";
|
|
226
221
|
import { createProcessor } from "@mdx-js/mdx";
|
|
227
222
|
import { MDX_REGEXP } from "@rspress/shared";
|
|
228
|
-
var { CachedInputFileSystem, ResolverFactory } =
|
|
223
|
+
var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFactory2 } = enhancedResolve2;
|
|
229
224
|
var processor = createProcessor();
|
|
230
225
|
var resolver;
|
|
231
226
|
var startFlatten = false;
|
|
232
227
|
async function resolveDepPath(importPath, importer, alias) {
|
|
233
228
|
if (!resolver) {
|
|
234
|
-
resolver =
|
|
235
|
-
fileSystem: new
|
|
229
|
+
resolver = ResolverFactory2.createResolver({
|
|
230
|
+
fileSystem: new CachedInputFileSystem2(fs2),
|
|
236
231
|
extensions: [
|
|
237
232
|
".mdx",
|
|
238
|
-
".md"
|
|
239
|
-
".js"
|
|
233
|
+
".md"
|
|
240
234
|
],
|
|
241
235
|
alias
|
|
242
236
|
});
|
|
@@ -259,8 +253,8 @@ async function resolveDepPath(importPath, importer, alias) {
|
|
|
259
253
|
async function flattenMdxContent(content, basePath, alias) {
|
|
260
254
|
let result = content;
|
|
261
255
|
if (!startFlatten) {
|
|
262
|
-
resolver =
|
|
263
|
-
fileSystem: new
|
|
256
|
+
resolver = ResolverFactory2.createResolver({
|
|
257
|
+
fileSystem: new CachedInputFileSystem2(fs2),
|
|
264
258
|
extensions: [
|
|
265
259
|
".mdx",
|
|
266
260
|
".md",
|
|
@@ -298,47 +292,12 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
298
292
|
return result;
|
|
299
293
|
}
|
|
300
294
|
|
|
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
295
|
// src/node/runtimeModule/i18n.ts
|
|
338
|
-
import { join
|
|
296
|
+
import { join } from "path";
|
|
339
297
|
import { createRequire as createRequire2 } from "module";
|
|
298
|
+
import { RspackVirtualModulePlugin as RspackVirtualModulePlugin2 } from "rspack-plugin-virtual-module";
|
|
340
299
|
var require3 = createRequire2(import.meta.url);
|
|
341
|
-
var DEFAULT_I18N_SOURCE =
|
|
300
|
+
var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
|
|
342
301
|
function getI18nData(docConfig) {
|
|
343
302
|
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
344
303
|
try {
|
|
@@ -349,11 +308,10 @@ function getI18nData(docConfig) {
|
|
|
349
308
|
}
|
|
350
309
|
}
|
|
351
310
|
function i18nVMPlugin(context) {
|
|
352
|
-
const { config
|
|
311
|
+
const { config } = context;
|
|
353
312
|
const i18nData = getI18nData(config);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
[modulePath]: `export default ${JSON.stringify(i18nData)}`
|
|
313
|
+
return new RspackVirtualModulePlugin2({
|
|
314
|
+
[RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData)}`
|
|
357
315
|
});
|
|
358
316
|
}
|
|
359
317
|
|
|
@@ -477,7 +435,7 @@ function normalizeThemeConfig(docConfig, pages2 = []) {
|
|
|
477
435
|
}
|
|
478
436
|
async function extractPageData(replaceRules, alias, domain, root, routeService2) {
|
|
479
437
|
return Promise.all(routeService2.getRoutes().filter((route) => MDX_REGEXP2.test(route.absolutePath)).map(async (route, index) => {
|
|
480
|
-
let content = await
|
|
438
|
+
let content = await fs3.readFile(route.absolutePath, "utf8");
|
|
481
439
|
const frontmatter = {
|
|
482
440
|
...loadFront(content)
|
|
483
441
|
};
|
|
@@ -565,14 +523,12 @@ ${item.text}#
|
|
|
565
523
|
__content: void 0
|
|
566
524
|
},
|
|
567
525
|
_filepath: route.absolutePath,
|
|
568
|
-
_relativePath:
|
|
526
|
+
_relativePath: path5.relative(root, route.absolutePath)
|
|
569
527
|
};
|
|
570
528
|
}));
|
|
571
529
|
}
|
|
572
530
|
async function siteDataVMPlugin(context) {
|
|
573
|
-
const {
|
|
574
|
-
const entryPath = join3(runtimeTempDir, `${RuntimeModuleID.SiteData}.mjs`);
|
|
575
|
-
const searchIndexHashPath = join3(runtimeTempDir, `${RuntimeModuleID.SearchIndexHash}.js`);
|
|
531
|
+
const { config, alias, userRoot, routeService: routeService2, pluginDriver } = context;
|
|
576
532
|
const userConfig = config;
|
|
577
533
|
const replaceRules = userConfig?.replaceRules || [];
|
|
578
534
|
if (!pages) {
|
|
@@ -595,8 +551,8 @@ async function siteDataVMPlugin(context) {
|
|
|
595
551
|
const stringfiedIndex = JSON.stringify(pagesByLang[lang].map(deletePriviteKey));
|
|
596
552
|
const indexHash = createHash(stringfiedIndex);
|
|
597
553
|
indexHashByLang[lang] = indexHash;
|
|
598
|
-
await
|
|
599
|
-
await
|
|
554
|
+
await fs3.ensureDir(TEMP_DIR);
|
|
555
|
+
await fs3.writeFile(path5.join(TEMP_DIR, `${SEARCH_INDEX_NAME}.${lang}.${indexHash}.json`), stringfiedIndex);
|
|
600
556
|
}));
|
|
601
557
|
await Promise.all(pages.map(async (pageData) => pluginDriver.extendPageData(pageData)));
|
|
602
558
|
const siteData = {
|
|
@@ -618,19 +574,18 @@ async function siteDataVMPlugin(context) {
|
|
|
618
574
|
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false
|
|
619
575
|
}
|
|
620
576
|
};
|
|
621
|
-
const plugin = new
|
|
622
|
-
[
|
|
623
|
-
[
|
|
577
|
+
const plugin = new RspackVirtualModulePlugin3({
|
|
578
|
+
[`${RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData)}`,
|
|
579
|
+
[RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByLang)}`
|
|
624
580
|
});
|
|
625
581
|
return plugin;
|
|
626
582
|
}
|
|
627
583
|
|
|
628
584
|
// src/node/runtimeModule/globalUIComponents.ts
|
|
629
|
-
import {
|
|
585
|
+
import { RspackVirtualModulePlugin as RspackVirtualModulePlugin4 } from "rspack-plugin-virtual-module";
|
|
630
586
|
async function globalUIComponentsVMPlugin(context) {
|
|
631
|
-
const {
|
|
587
|
+
const { config, pluginDriver } = context;
|
|
632
588
|
let index = 0;
|
|
633
|
-
const modulePath = join4(runtimeTempDir, `${RuntimeModuleID.GlobalComponents}.js`);
|
|
634
589
|
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
635
590
|
const moduleContent = [
|
|
636
591
|
...config?.globalUIComponents || [],
|
|
@@ -638,44 +593,45 @@ async function globalUIComponentsVMPlugin(context) {
|
|
|
638
593
|
].map((source) => `import Comp_${index++} from ${JSON.stringify(source)};`).concat(`export default [${Array.from({
|
|
639
594
|
length: index
|
|
640
595
|
}, (_, i) => `Comp_${i}`).join(", ")}];`).join("");
|
|
641
|
-
return new
|
|
642
|
-
[
|
|
596
|
+
return new RspackVirtualModulePlugin4({
|
|
597
|
+
[RuntimeModuleID.GlobalComponents]: moduleContent
|
|
643
598
|
});
|
|
644
599
|
}
|
|
645
600
|
|
|
646
601
|
// src/node/runtimeModule/globalStyles.ts
|
|
647
|
-
import
|
|
648
|
-
import
|
|
602
|
+
import fs4 from "@modern-js/utils/fs-extra";
|
|
603
|
+
import { RspackVirtualModulePlugin as RspackVirtualModulePlugin5 } from "rspack-plugin-virtual-module";
|
|
649
604
|
async function globalStylesVMPlugin(context) {
|
|
650
|
-
const {
|
|
651
|
-
const modulePath = join5(runtimeTempDir, `${RuntimeModuleID.GlobalStyles}.js`);
|
|
605
|
+
const { config, pluginDriver } = context;
|
|
652
606
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
607
|
+
if (config.globalStyles) {
|
|
608
|
+
const source = config.globalStyles;
|
|
609
|
+
const styleContent = await fs4.readFile(source, "utf-8");
|
|
610
|
+
const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
|
|
611
|
+
await fs4.writeFile(source, patchedStyleContent, "utf-8");
|
|
612
|
+
}
|
|
653
613
|
const moduleContent = (await Promise.all([
|
|
654
614
|
config?.globalStyles || "",
|
|
655
615
|
...globalStylesByPlugins
|
|
656
616
|
].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
617
|
return `import ${JSON.stringify(source)};`;
|
|
661
618
|
}))).join("");
|
|
662
|
-
return new
|
|
663
|
-
[
|
|
619
|
+
return new RspackVirtualModulePlugin5({
|
|
620
|
+
[RuntimeModuleID.GlobalStyles]: moduleContent
|
|
664
621
|
});
|
|
665
622
|
}
|
|
666
623
|
|
|
667
624
|
// src/node/runtimeModule/searchHooks.ts
|
|
668
|
-
import
|
|
669
|
-
import
|
|
625
|
+
import fs5 from "@modern-js/utils/fs-extra";
|
|
626
|
+
import { RspackVirtualModulePlugin as RspackVirtualModulePlugin6 } from "rspack-plugin-virtual-module";
|
|
670
627
|
async function searchHookVMPlugin(context) {
|
|
671
628
|
const { config } = context;
|
|
672
629
|
let content = "export const onSearch = () => {}";
|
|
673
630
|
if (typeof config.search === "object" && typeof config.search.searchHooks === "string") {
|
|
674
|
-
content = await
|
|
631
|
+
content = await fs5.readFile(config.search.searchHooks, "utf-8");
|
|
675
632
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
[modulePath]: content
|
|
633
|
+
return new RspackVirtualModulePlugin6({
|
|
634
|
+
[`${RuntimeModuleID.SearchHooks}.ts`]: content
|
|
679
635
|
});
|
|
680
636
|
}
|
|
681
637
|
|
|
@@ -746,8 +702,8 @@ var runtimeModuleIDs = [
|
|
|
746
702
|
];
|
|
747
703
|
|
|
748
704
|
// src/node/searchIndex.ts
|
|
749
|
-
import
|
|
750
|
-
import
|
|
705
|
+
import path6, { join as join2 } from "path";
|
|
706
|
+
import fs6 from "@modern-js/utils/fs-extra";
|
|
751
707
|
import chalk from "@modern-js/utils/chalk";
|
|
752
708
|
import fetch from "node-fetch";
|
|
753
709
|
import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
|
|
@@ -756,19 +712,19 @@ async function writeSearchIndex(config) {
|
|
|
756
712
|
return;
|
|
757
713
|
}
|
|
758
714
|
const cwd = process.cwd();
|
|
759
|
-
const searchIndexFiles = await
|
|
760
|
-
const outDir = config?.outDir ??
|
|
715
|
+
const searchIndexFiles = await fs6.readdir(TEMP_DIR);
|
|
716
|
+
const outDir = config?.outDir ?? join2(cwd, OUTPUT_DIR);
|
|
761
717
|
let searchIndexData = "[]";
|
|
762
718
|
let scaning = false;
|
|
763
719
|
for (const searchIndexFile of searchIndexFiles) {
|
|
764
720
|
if (!searchIndexFile.includes(SEARCH_INDEX_NAME2) || !searchIndexFile.endsWith(".json")) {
|
|
765
721
|
continue;
|
|
766
722
|
}
|
|
767
|
-
const source =
|
|
768
|
-
const target =
|
|
769
|
-
const searchIndex = await
|
|
723
|
+
const source = join2(TEMP_DIR, searchIndexFile);
|
|
724
|
+
const target = join2(outDir, "static", searchIndexFile);
|
|
725
|
+
const searchIndex = await fs6.readFile(join2(TEMP_DIR, searchIndexFile), "utf-8");
|
|
770
726
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scaning ? "," : ""}${searchIndex.slice(1)}`;
|
|
771
|
-
await
|
|
727
|
+
await fs6.move(source, target, {
|
|
772
728
|
overwrite: true
|
|
773
729
|
});
|
|
774
730
|
scaning = true;
|
|
@@ -796,7 +752,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
796
752
|
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
797
753
|
res.setHeader("Content-Type", "application/json");
|
|
798
754
|
const searchIndexFile = req.url?.split("/").pop();
|
|
799
|
-
const searchIndex =
|
|
755
|
+
const searchIndex = fs6.readFileSync(path6.join(process.cwd(), config?.outDir || OUTPUT_DIR, "static", searchIndexFile), "utf-8");
|
|
800
756
|
res.end(searchIndex);
|
|
801
757
|
} else {
|
|
802
758
|
next?.();
|
|
@@ -805,10 +761,10 @@ function serveSearchIndexMiddleware(config) {
|
|
|
805
761
|
}
|
|
806
762
|
|
|
807
763
|
// src/node/route/RouteService.ts
|
|
808
|
-
import
|
|
809
|
-
import
|
|
764
|
+
import path7 from "path";
|
|
765
|
+
import fs7 from "@modern-js/utils/fs-extra";
|
|
810
766
|
import { withBase as withBase2 } from "@rspress/shared";
|
|
811
|
-
function
|
|
767
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
812
768
|
if (privateCollection.has(obj)) {
|
|
813
769
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
814
770
|
}
|
|
@@ -840,7 +796,7 @@ function _class_private_field_get(receiver, privateMap) {
|
|
|
840
796
|
return _class_apply_descriptor_get(receiver, descriptor);
|
|
841
797
|
}
|
|
842
798
|
function _class_private_field_init(obj, privateMap, value) {
|
|
843
|
-
|
|
799
|
+
_check_private_redeclaration(obj, privateMap);
|
|
844
800
|
privateMap.set(obj, value);
|
|
845
801
|
}
|
|
846
802
|
function _class_private_field_set(receiver, privateMap, value) {
|
|
@@ -848,17 +804,17 @@ function _class_private_field_set(receiver, privateMap, value) {
|
|
|
848
804
|
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
849
805
|
return value;
|
|
850
806
|
}
|
|
851
|
-
function
|
|
807
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
852
808
|
if (!privateSet.has(receiver)) {
|
|
853
809
|
throw new TypeError("attempted to get private field on non-instance");
|
|
854
810
|
}
|
|
855
811
|
return fn;
|
|
856
812
|
}
|
|
857
|
-
function
|
|
858
|
-
|
|
813
|
+
function _class_private_method_init(obj, privateSet) {
|
|
814
|
+
_check_private_redeclaration(obj, privateSet);
|
|
859
815
|
privateSet.add(obj);
|
|
860
816
|
}
|
|
861
|
-
function
|
|
817
|
+
function _define_property(obj, key, value) {
|
|
862
818
|
if (key in obj) {
|
|
863
819
|
Object.defineProperty(obj, key, {
|
|
864
820
|
value,
|
|
@@ -916,13 +872,13 @@ var RouteService = class {
|
|
|
916
872
|
]
|
|
917
873
|
}).sort();
|
|
918
874
|
files.forEach((filePath) => {
|
|
919
|
-
const fileRelativePath =
|
|
920
|
-
const lang =
|
|
875
|
+
const fileRelativePath = normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filePath));
|
|
876
|
+
const lang = _class_private_method_get(this, _getLang, getLang).call(this, fileRelativePath);
|
|
921
877
|
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
922
|
-
const absolutePath =
|
|
878
|
+
const absolutePath = path7.join(_class_private_field_get(this, _scanDir), fileRelativePath);
|
|
923
879
|
const routeInfo = {
|
|
924
880
|
routePath,
|
|
925
|
-
absolutePath:
|
|
881
|
+
absolutePath: normalizePath(absolutePath),
|
|
926
882
|
relativePath: fileRelativePath,
|
|
927
883
|
pageName: getPageKey(fileRelativePath),
|
|
928
884
|
lang
|
|
@@ -933,13 +889,13 @@ var RouteService = class {
|
|
|
933
889
|
await Promise.all(externalPages.map(async (route, index) => {
|
|
934
890
|
const { routePath, content, filepath } = route;
|
|
935
891
|
if (filepath) {
|
|
936
|
-
const routeInfo =
|
|
892
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
937
893
|
this.addRoute(routeInfo);
|
|
938
894
|
return;
|
|
939
895
|
}
|
|
940
896
|
if (content) {
|
|
941
|
-
const filepath2 = await
|
|
942
|
-
const routeInfo =
|
|
897
|
+
const filepath2 = await _class_private_method_get(this, _writeTempFile, writeTempFile).call(this, index, content);
|
|
898
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath2);
|
|
943
899
|
this.addRoute(routeInfo);
|
|
944
900
|
}
|
|
945
901
|
}));
|
|
@@ -948,8 +904,8 @@ var RouteService = class {
|
|
|
948
904
|
addRoute(routeInfo) {
|
|
949
905
|
const { routePath, absolutePath } = routeInfo;
|
|
950
906
|
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(
|
|
907
|
+
const preRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(path7.extname(this.routeData.get(routePath).absolutePath).slice(1));
|
|
908
|
+
const currRouteExtIndex = _class_private_field_get(this, _extensions).indexOf(path7.extname(absolutePath).slice(1));
|
|
953
909
|
if (currRouteExtIndex !== -1 && (currRouteExtIndex < preRouteExtIndex || preRouteExtIndex === -1)) {
|
|
954
910
|
this.routeData.set(routePath, routeInfo);
|
|
955
911
|
}
|
|
@@ -958,7 +914,7 @@ var RouteService = class {
|
|
|
958
914
|
}
|
|
959
915
|
}
|
|
960
916
|
removeRoute(filePath) {
|
|
961
|
-
const fileRelativePath =
|
|
917
|
+
const fileRelativePath = path7.relative(_class_private_field_get(this, _scanDir), filePath);
|
|
962
918
|
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
963
919
|
this.routeData.delete(routePath);
|
|
964
920
|
}
|
|
@@ -992,10 +948,10 @@ ${this.getRoutes().map((route, index) => {
|
|
|
992
948
|
`;
|
|
993
949
|
}
|
|
994
950
|
constructor(scanDir, userConfig, tempDir, pluginDriver) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
951
|
+
_class_private_method_init(this, _writeTempFile);
|
|
952
|
+
_class_private_method_init(this, _getLang);
|
|
953
|
+
_class_private_method_init(this, _generateRouteInfo);
|
|
954
|
+
_define_property(this, "routeData", /* @__PURE__ */ new Map());
|
|
999
955
|
_class_private_field_init(this, _scanDir, {
|
|
1000
956
|
writable: true,
|
|
1001
957
|
value: void 0
|
|
@@ -1045,8 +1001,8 @@ ${this.getRoutes().map((route, index) => {
|
|
|
1045
1001
|
}
|
|
1046
1002
|
};
|
|
1047
1003
|
async function writeTempFile(index, content) {
|
|
1048
|
-
const tempFilePath =
|
|
1049
|
-
await
|
|
1004
|
+
const tempFilePath = path7.join(_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
1005
|
+
await fs7.writeFile(tempFilePath, content);
|
|
1050
1006
|
return tempFilePath;
|
|
1051
1007
|
}
|
|
1052
1008
|
function getLang(filepath) {
|
|
@@ -1055,10 +1011,10 @@ function getLang(filepath) {
|
|
|
1055
1011
|
function generateRouteInfo(routePath, filepath) {
|
|
1056
1012
|
return {
|
|
1057
1013
|
routePath: normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base)),
|
|
1058
|
-
absolutePath:
|
|
1059
|
-
relativePath:
|
|
1014
|
+
absolutePath: normalizePath(filepath),
|
|
1015
|
+
relativePath: normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filepath)),
|
|
1060
1016
|
pageName: getPageKey(routePath),
|
|
1061
|
-
lang:
|
|
1017
|
+
lang: _class_private_method_get(this, _getLang, getLang).call(this, filepath)
|
|
1062
1018
|
};
|
|
1063
1019
|
}
|
|
1064
1020
|
|
|
@@ -1075,15 +1031,15 @@ async function initRouteService(options) {
|
|
|
1075
1031
|
var require4 = createRequire3(import.meta.url);
|
|
1076
1032
|
async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir, routeService2) {
|
|
1077
1033
|
const cwd = process.cwd();
|
|
1078
|
-
const { default:
|
|
1079
|
-
const CUSTOM_THEME_DIR = config?.themeDir ??
|
|
1034
|
+
const { default: fs11 } = await import("@modern-js/utils/fs-extra");
|
|
1035
|
+
const CUSTOM_THEME_DIR = config?.themeDir ?? path8.join(process.cwd(), "theme");
|
|
1080
1036
|
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1081
|
-
const DEFAULT_THEME_DIR = isDebugMode() ?
|
|
1082
|
-
const themeDir = await
|
|
1037
|
+
const DEFAULT_THEME_DIR = isDebugMode() ? path8.join(PACKAGE_ROOT, "src", "theme-default") : path8.join(PACKAGE_ROOT, "dist", "theme");
|
|
1038
|
+
const themeDir = await fs11.pathExists(CUSTOM_THEME_DIR) ? CUSTOM_THEME_DIR : DEFAULT_THEME_DIR;
|
|
1083
1039
|
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isSSR) ?? false;
|
|
1084
1040
|
const base = config?.base ?? "";
|
|
1085
|
-
const publicDir =
|
|
1086
|
-
const isPublicDirExist = await
|
|
1041
|
+
const publicDir = path8.join(userRoot, "public");
|
|
1042
|
+
const isPublicDirExist = await fs11.pathExists(publicDir);
|
|
1087
1043
|
const assetPrefix = isProduction() ? removeTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : "";
|
|
1088
1044
|
const enableMdxRs = config?.markdown?.experimentalMdxRs ?? false;
|
|
1089
1045
|
const reactVersion = await detectReactVersion();
|
|
@@ -1110,12 +1066,12 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1110
1066
|
},
|
|
1111
1067
|
html: {
|
|
1112
1068
|
favicon: config?.icon,
|
|
1113
|
-
template:
|
|
1069
|
+
template: path8.join(PACKAGE_ROOT, "index.html")
|
|
1114
1070
|
},
|
|
1115
1071
|
output: {
|
|
1116
1072
|
distPath: {
|
|
1117
1073
|
// `root` must be a relative path in Builder
|
|
1118
|
-
root:
|
|
1074
|
+
root: path8.isAbsolute(outDir) ? path8.relative(cwd, outDir) : outDir
|
|
1119
1075
|
},
|
|
1120
1076
|
// TODO: switch to 'usage' if Rspack supports it
|
|
1121
1077
|
polyfill: "entry",
|
|
@@ -1129,21 +1085,18 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1129
1085
|
source: {
|
|
1130
1086
|
alias: {
|
|
1131
1087
|
"@mdx-js/react": require4.resolve("@mdx-js/react"),
|
|
1132
|
-
"@/runtime":
|
|
1088
|
+
"@/runtime": path8.join(PACKAGE_ROOT, "dist", "runtime"),
|
|
1133
1089
|
"@theme": themeDir,
|
|
1090
|
+
"@/theme-default": DEFAULT_THEME_DIR,
|
|
1134
1091
|
"@rspress/core": PACKAGE_ROOT,
|
|
1135
1092
|
"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
1093
|
...await resolveReactAlias(reactVersion)
|
|
1141
1094
|
},
|
|
1142
1095
|
include: [
|
|
1143
1096
|
PACKAGE_ROOT
|
|
1144
1097
|
],
|
|
1145
1098
|
define: {
|
|
1146
|
-
__ASSET_PREFIX__: JSON.stringify(assetPrefix),
|
|
1099
|
+
"process.env.__ASSET_PREFIX__": JSON.stringify(assetPrefix),
|
|
1147
1100
|
"process.env.__SSR__": JSON.stringify(isSSR),
|
|
1148
1101
|
"process.env.__IS_REACT_18__": JSON.stringify(reactVersion === 18),
|
|
1149
1102
|
"process.env.TEST": JSON.stringify(process.env.TEST)
|
|
@@ -1166,7 +1119,7 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1166
1119
|
config: {
|
|
1167
1120
|
...tailwindConfig,
|
|
1168
1121
|
content: [
|
|
1169
|
-
|
|
1122
|
+
path8.join(PACKAGE_ROOT, "src", "theme-default", "**/*")
|
|
1170
1123
|
]
|
|
1171
1124
|
}
|
|
1172
1125
|
}));
|
|
@@ -1189,10 +1142,10 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
|
|
|
1189
1142
|
}
|
|
1190
1143
|
async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false, extraBuilderConfig) {
|
|
1191
1144
|
const cwd = process.cwd();
|
|
1192
|
-
const userRoot =
|
|
1145
|
+
const userRoot = path8.resolve(rootDir || config?.root || cwd);
|
|
1193
1146
|
const builderPlugins = config?.builderPlugins ?? [];
|
|
1194
|
-
const runtimeTempDir =
|
|
1195
|
-
await
|
|
1147
|
+
const runtimeTempDir = path8.join(TEMP_DIR, "runtime");
|
|
1148
|
+
await fs8.ensureDir(runtimeTempDir);
|
|
1196
1149
|
const routeService2 = await initRouteService({
|
|
1197
1150
|
config,
|
|
1198
1151
|
runtimeTempDir,
|
|
@@ -1227,7 +1180,8 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
|
|
|
1227
1180
|
}
|
|
1228
1181
|
|
|
1229
1182
|
// src/node/PluginDriver.ts
|
|
1230
|
-
|
|
1183
|
+
import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
|
|
1184
|
+
function _check_private_redeclaration2(obj, privateCollection) {
|
|
1231
1185
|
if (privateCollection.has(obj)) {
|
|
1232
1186
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
1233
1187
|
}
|
|
@@ -1259,7 +1213,7 @@ function _class_private_field_get2(receiver, privateMap) {
|
|
|
1259
1213
|
return _class_apply_descriptor_get2(receiver, descriptor);
|
|
1260
1214
|
}
|
|
1261
1215
|
function _class_private_field_init2(obj, privateMap, value) {
|
|
1262
|
-
|
|
1216
|
+
_check_private_redeclaration2(obj, privateMap);
|
|
1263
1217
|
privateMap.set(obj, value);
|
|
1264
1218
|
}
|
|
1265
1219
|
function _class_private_field_set2(receiver, privateMap, value) {
|
|
@@ -1291,6 +1245,7 @@ var PluginDriver = class {
|
|
|
1291
1245
|
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
1292
1246
|
this.addPlugin(pluginAutoNavSidebar());
|
|
1293
1247
|
}
|
|
1248
|
+
this.addPlugin(pluginContainerSyntax());
|
|
1294
1249
|
(config.plugins || []).forEach((plugin) => {
|
|
1295
1250
|
this.addPlugin(plugin);
|
|
1296
1251
|
});
|
|
@@ -1392,7 +1347,7 @@ async function dev(options) {
|
|
|
1392
1347
|
try {
|
|
1393
1348
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1394
1349
|
await pluginDriver.beforeBuild();
|
|
1395
|
-
await
|
|
1350
|
+
await fs9.emptyDir(TEMP_DIR);
|
|
1396
1351
|
const builder = await createModernBuilder(docDirectory, modifiedConfig, pluginDriver, false, {});
|
|
1397
1352
|
const { server } = await builder.startDevServer({
|
|
1398
1353
|
printURLs: (urls) => {
|
|
@@ -1403,7 +1358,7 @@ async function dev(options) {
|
|
|
1403
1358
|
},
|
|
1404
1359
|
// We will support the following options in the future
|
|
1405
1360
|
getPortSilently: true,
|
|
1406
|
-
logger:
|
|
1361
|
+
logger: logger3
|
|
1407
1362
|
});
|
|
1408
1363
|
await pluginDriver.afterBuild();
|
|
1409
1364
|
return server;
|
|
@@ -1413,10 +1368,10 @@ async function dev(options) {
|
|
|
1413
1368
|
}
|
|
1414
1369
|
|
|
1415
1370
|
// src/node/build.ts
|
|
1416
|
-
import { dirname as dirname2, isAbsolute, join as
|
|
1371
|
+
import { dirname as dirname2, isAbsolute, join as join3 } from "path";
|
|
1417
1372
|
import { pathToFileURL } from "url";
|
|
1418
1373
|
import chalk2 from "@modern-js/utils/chalk";
|
|
1419
|
-
import
|
|
1374
|
+
import fs10 from "@modern-js/utils/fs-extra";
|
|
1420
1375
|
import { APPEARANCE_KEY, normalizeSlash, withBase as withBase3 } from "@rspress/shared";
|
|
1421
1376
|
var CHECK_DARK_LIGHT_SCRIPT = `
|
|
1422
1377
|
<script id="check-dark-light">
|
|
@@ -1455,10 +1410,10 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
|
|
|
1455
1410
|
logoPaths.push(logo.dark);
|
|
1456
1411
|
}
|
|
1457
1412
|
logoPaths.filter((p) => p.startsWith("/")).forEach((p) => {
|
|
1458
|
-
const normalize = (rawPath) => isAbsolute(rawPath) ? rawPath :
|
|
1459
|
-
const logoPath =
|
|
1460
|
-
const outputLogoPath =
|
|
1461
|
-
|
|
1413
|
+
const normalize = (rawPath) => isAbsolute(rawPath) ? rawPath : join3(appDirectory, rawPath);
|
|
1414
|
+
const logoPath = join3(normalize(docDirectory || config.root), PUBLIC_DIR, p);
|
|
1415
|
+
const outputLogoPath = join3(normalize(outputDir), p);
|
|
1416
|
+
fs10.copyFileSync(logoPath, outputLogoPath);
|
|
1462
1417
|
});
|
|
1463
1418
|
} finally {
|
|
1464
1419
|
await writeSearchIndex(config);
|
|
@@ -1467,10 +1422,10 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
|
|
|
1467
1422
|
async function renderPages(appDirectory, config, pluginDriver) {
|
|
1468
1423
|
logger.info("Rendering pages...");
|
|
1469
1424
|
const startTime = Date.now();
|
|
1470
|
-
const outputPath = config?.outDir ??
|
|
1471
|
-
const ssrBundlePath =
|
|
1425
|
+
const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
|
|
1426
|
+
const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
|
|
1472
1427
|
try {
|
|
1473
|
-
const { default:
|
|
1428
|
+
const { default: fs11 } = await import("@modern-js/utils/fs-extra");
|
|
1474
1429
|
let render = null;
|
|
1475
1430
|
try {
|
|
1476
1431
|
const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
|
|
@@ -1480,8 +1435,8 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1480
1435
|
}
|
|
1481
1436
|
const routes = routeService.getRoutes();
|
|
1482
1437
|
const base = config?.base ?? "";
|
|
1483
|
-
const htmlTemplatePath =
|
|
1484
|
-
const htmlTemplate = await
|
|
1438
|
+
const htmlTemplatePath = join3(outputPath, "html", "main", "index.html");
|
|
1439
|
+
const htmlTemplate = await fs11.readFile(htmlTemplatePath, "utf-8");
|
|
1485
1440
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
1486
1441
|
routePath: withBase3(route.path, base)
|
|
1487
1442
|
}));
|
|
@@ -1518,19 +1473,19 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1518
1473
|
if (helmet?.bodyAttributes) {
|
|
1519
1474
|
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${helmet?.bodyAttributes?.toString()}`);
|
|
1520
1475
|
}
|
|
1521
|
-
const normalizeHtmlFilePath = (
|
|
1476
|
+
const normalizeHtmlFilePath = (path9) => {
|
|
1522
1477
|
const normalizedBase = normalizeSlash(config?.base || "/");
|
|
1523
|
-
if (
|
|
1524
|
-
return `${
|
|
1478
|
+
if (path9.endsWith("/")) {
|
|
1479
|
+
return `${path9}index.html`.replace(normalizedBase, "");
|
|
1525
1480
|
}
|
|
1526
|
-
return `${
|
|
1481
|
+
return `${path9}.html`.replace(normalizedBase, "");
|
|
1527
1482
|
};
|
|
1528
1483
|
const fileName = normalizeHtmlFilePath(routePath);
|
|
1529
|
-
await
|
|
1530
|
-
await
|
|
1484
|
+
await fs11.ensureDir(join3(outputPath, dirname2(fileName)));
|
|
1485
|
+
await fs11.writeFile(join3(outputPath, fileName), html);
|
|
1531
1486
|
}));
|
|
1532
|
-
await
|
|
1533
|
-
await
|
|
1487
|
+
await fs11.remove(join3(outputPath, "ssr"));
|
|
1488
|
+
await fs11.remove(join3(outputPath, "html"));
|
|
1534
1489
|
const totalTime = Date.now() - startTime;
|
|
1535
1490
|
logger.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
|
|
1536
1491
|
} catch (e) {
|
|
@@ -1544,7 +1499,7 @@ async function build(options) {
|
|
|
1544
1499
|
await pluginDriver.init();
|
|
1545
1500
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1546
1501
|
await pluginDriver.beforeBuild();
|
|
1547
|
-
await
|
|
1502
|
+
await fs10.emptyDir(TEMP_DIR);
|
|
1548
1503
|
await bundle(appDirectory, docDirectory, modifiedConfig, pluginDriver);
|
|
1549
1504
|
await renderPages(appDirectory, modifiedConfig, pluginDriver);
|
|
1550
1505
|
await pluginDriver.afterBuild();
|