@rspress/core 1.0.0-beta.0 → 1.0.0-beta.1
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
CHANGED
|
@@ -4,7 +4,7 @@ import { logger as logger3 } from "@rspress/shared/logger";
|
|
|
4
4
|
|
|
5
5
|
// src/node/createBuilder.ts
|
|
6
6
|
import path8 from "path";
|
|
7
|
-
import { createRequire as
|
|
7
|
+
import { createRequire as createRequire2 } from "module";
|
|
8
8
|
import fs8 from "@modern-js/utils/fs-extra";
|
|
9
9
|
import { RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2, isDebugMode, removeTrailingSlash } from "@rspress/shared";
|
|
10
10
|
import sirv from "sirv";
|
|
@@ -150,15 +150,10 @@ function createHash(str) {
|
|
|
150
150
|
return createHashFunc("sha256").update(str).digest("hex").slice(0, 8);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
// src/node/utils/logger.ts
|
|
154
|
-
import { createRequire } from "module";
|
|
155
|
-
var require2 = createRequire(import.meta.url);
|
|
156
|
-
var { logger } = require2("@modern-js/utils/logger");
|
|
157
|
-
|
|
158
153
|
// src/node/utils/detectReactVersion.ts
|
|
159
154
|
import path3 from "path";
|
|
160
155
|
import fs from "@modern-js/utils/fs-extra";
|
|
161
|
-
import { logger
|
|
156
|
+
import { logger } from "@rspress/shared/logger";
|
|
162
157
|
import enhancedResolve from "enhanced-resolve";
|
|
163
158
|
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
164
159
|
var DEFAULT_REACT_VERSION = 18;
|
|
@@ -207,7 +202,7 @@ async function resolveReactAlias(reactVersion) {
|
|
|
207
202
|
});
|
|
208
203
|
} catch (e) {
|
|
209
204
|
console.log(e);
|
|
210
|
-
|
|
205
|
+
logger.warn(`${lib} not found`);
|
|
211
206
|
}
|
|
212
207
|
}));
|
|
213
208
|
return alias;
|
|
@@ -293,13 +288,13 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
293
288
|
|
|
294
289
|
// src/node/runtimeModule/i18n.ts
|
|
295
290
|
import { join } from "path";
|
|
296
|
-
import { createRequire
|
|
297
|
-
var
|
|
291
|
+
import { createRequire } from "module";
|
|
292
|
+
var require2 = createRequire(import.meta.url);
|
|
298
293
|
var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
|
|
299
294
|
function getI18nData(docConfig) {
|
|
300
295
|
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
301
296
|
try {
|
|
302
|
-
const i18nSource =
|
|
297
|
+
const i18nSource = require2(i18nSourcePath);
|
|
303
298
|
return i18nSource;
|
|
304
299
|
} catch (e) {
|
|
305
300
|
return {};
|
|
@@ -647,7 +642,7 @@ async function searchHookVMPlugin(context) {
|
|
|
647
642
|
content = await fs5.readFile(config.search.searchHooks, "utf-8");
|
|
648
643
|
}
|
|
649
644
|
return {
|
|
650
|
-
[
|
|
645
|
+
[RuntimeModuleID.SearchHooks]: content
|
|
651
646
|
};
|
|
652
647
|
}
|
|
653
648
|
|
|
@@ -725,6 +720,7 @@ import fs6 from "@modern-js/utils/fs-extra";
|
|
|
725
720
|
import chalk from "@modern-js/utils/chalk";
|
|
726
721
|
import fetch from "node-fetch";
|
|
727
722
|
import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
|
|
723
|
+
import { logger as logger2 } from "@rspress/shared/logger";
|
|
728
724
|
async function writeSearchIndex(config) {
|
|
729
725
|
if (config?.search === false) {
|
|
730
726
|
return;
|
|
@@ -757,9 +753,9 @@ async function writeSearchIndex(config) {
|
|
|
757
753
|
"Content-Type": "application/json"
|
|
758
754
|
}
|
|
759
755
|
});
|
|
760
|
-
|
|
756
|
+
logger2.info(chalk.green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
|
|
761
757
|
} catch (e) {
|
|
762
|
-
|
|
758
|
+
logger2.info(chalk.red(`[doc-tools] Upload search index \`${indexName}\` failed:
|
|
763
759
|
${e}`));
|
|
764
760
|
}
|
|
765
761
|
}
|
|
@@ -1076,7 +1072,7 @@ async function initRouteService(options) {
|
|
|
1076
1072
|
}
|
|
1077
1073
|
|
|
1078
1074
|
// src/node/createBuilder.ts
|
|
1079
|
-
var
|
|
1075
|
+
var require3 = createRequire2(import.meta.url);
|
|
1080
1076
|
async function createInternalBuildConfig(userDocRoot, config, isSSR, routeService2, pluginDriver) {
|
|
1081
1077
|
const cwd = process.cwd();
|
|
1082
1078
|
const { default: fs10 } = await import("@modern-js/utils/fs-extra");
|
|
@@ -1141,12 +1137,12 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
|
|
|
1141
1137
|
},
|
|
1142
1138
|
source: {
|
|
1143
1139
|
alias: {
|
|
1144
|
-
"@mdx-js/react":
|
|
1140
|
+
"@mdx-js/react": require3.resolve("@mdx-js/react"),
|
|
1145
1141
|
"@/runtime": path8.join(PACKAGE_ROOT, "dist", "runtime"),
|
|
1146
1142
|
"@theme": themeDir,
|
|
1147
1143
|
"@/theme-default": DEFAULT_THEME_DIR,
|
|
1148
1144
|
"@rspress/core": PACKAGE_ROOT,
|
|
1149
|
-
"react-lazy-with-preload":
|
|
1145
|
+
"react-lazy-with-preload": require3.resolve("react-lazy-with-preload"),
|
|
1150
1146
|
...await resolveReactAlias(reactVersion)
|
|
1151
1147
|
},
|
|
1152
1148
|
include: [
|
|
@@ -1176,7 +1172,7 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
|
|
|
1176
1172
|
},
|
|
1177
1173
|
postcss(config2) {
|
|
1178
1174
|
if (isDebugMode()) {
|
|
1179
|
-
config2.postcssOptions.plugins.push(
|
|
1175
|
+
config2.postcssOptions.plugins.push(require3("tailwindcss")({
|
|
1180
1176
|
config: {
|
|
1181
1177
|
...tailwindConfig,
|
|
1182
1178
|
content: [
|
|
@@ -1194,14 +1190,14 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
|
|
|
1194
1190
|
}
|
|
1195
1191
|
},
|
|
1196
1192
|
bundlerChain(chain) {
|
|
1197
|
-
chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(
|
|
1193
|
+
chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(require3.resolve("../loader.cjs")).options({
|
|
1198
1194
|
config,
|
|
1199
1195
|
docDirectory: userDocRoot,
|
|
1200
1196
|
checkDeadLinks,
|
|
1201
1197
|
enableMdxRs,
|
|
1202
1198
|
routeService: routeService2,
|
|
1203
1199
|
pluginDriver
|
|
1204
|
-
}).end().use("string-replace-loader").loader(
|
|
1200
|
+
}).end().use("string-replace-loader").loader(require3.resolve("string-replace-loader")).options({
|
|
1205
1201
|
multiple: config?.replaceRules || []
|
|
1206
1202
|
});
|
|
1207
1203
|
chain.resolve.extensions.prepend(".md").prepend(".mdx").prepend(".mjs");
|
|
@@ -1446,6 +1442,7 @@ import { pathToFileURL } from "url";
|
|
|
1446
1442
|
import chalk2 from "@modern-js/utils/chalk";
|
|
1447
1443
|
import fs9 from "@modern-js/utils/fs-extra";
|
|
1448
1444
|
import { APPEARANCE_KEY, normalizeSlash, withBase as withBase3 } from "@rspress/shared";
|
|
1445
|
+
import { logger as logger4 } from "@rspress/shared/logger";
|
|
1449
1446
|
var CHECK_DARK_LIGHT_SCRIPT = `
|
|
1450
1447
|
<script id="check-dark-light">
|
|
1451
1448
|
;(() => {
|
|
@@ -1483,7 +1480,7 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
|
|
|
1483
1480
|
}
|
|
1484
1481
|
}
|
|
1485
1482
|
async function renderPages(appDirectory, config, pluginDriver) {
|
|
1486
|
-
|
|
1483
|
+
logger4.info("Rendering pages...");
|
|
1487
1484
|
const startTime = Date.now();
|
|
1488
1485
|
const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
|
|
1489
1486
|
const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
|
|
@@ -1494,8 +1491,8 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1494
1491
|
const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
|
|
1495
1492
|
({ render } = ssrExports);
|
|
1496
1493
|
} catch (e) {
|
|
1497
|
-
|
|
1498
|
-
|
|
1494
|
+
logger4.error(e);
|
|
1495
|
+
logger4.warn(`Failed to load SSR bundle: ${ssrBundlePath}, fallback to CSR.`);
|
|
1499
1496
|
}
|
|
1500
1497
|
const routes = routeService.getRoutes();
|
|
1501
1498
|
const base = config?.base ?? "";
|
|
@@ -1519,7 +1516,7 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1519
1516
|
try {
|
|
1520
1517
|
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1521
1518
|
} catch (e) {
|
|
1522
|
-
|
|
1519
|
+
logger4.warn(`page "${routePath}" render error: ${e.message}, fallback to CSR.`);
|
|
1523
1520
|
}
|
|
1524
1521
|
}
|
|
1525
1522
|
const { helmet } = helmetContext.context;
|
|
@@ -1551,9 +1548,9 @@ async function renderPages(appDirectory, config, pluginDriver) {
|
|
|
1551
1548
|
await fs10.remove(join3(outputPath, "ssr"));
|
|
1552
1549
|
await fs10.remove(join3(outputPath, "html"));
|
|
1553
1550
|
const totalTime = Date.now() - startTime;
|
|
1554
|
-
|
|
1551
|
+
logger4.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
|
|
1555
1552
|
} catch (e) {
|
|
1556
|
-
|
|
1553
|
+
logger4.error(`Pages render error: ${e.stack}`);
|
|
1557
1554
|
throw e;
|
|
1558
1555
|
}
|
|
1559
1556
|
}
|