@rspress/core 0.0.13 → 0.1.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
@@ -115,7 +115,7 @@ import { withBase, MDX_REGEXP as MDX_REGEXP2, SEARCH_INDEX_NAME, addLeadingSlash
115
115
  import yamlFrontMatter from "yaml-front-matter";
116
116
  import { htmlToText } from "html-to-text";
117
117
  import fs3 from "@modern-js/utils/fs-extra";
118
- import { compile } from "@modern-js/mdx-rs-binding";
118
+ import { compile } from "@rspress/mdx-rs";
119
119
 
120
120
  // src/node/utils/applyReplaceRules.ts
121
121
  function applyReplaceRules(code = "", replaceRules = []) {
@@ -525,11 +525,11 @@ ${item.text}#
525
525
  }));
526
526
  }
527
527
  async function siteDataVMPlugin(context) {
528
- const { config, alias, userRoot, routeService: routeService2, pluginDriver } = context;
528
+ const { config, alias, userDocRoot, routeService: routeService2, pluginDriver } = context;
529
529
  const userConfig = config;
530
530
  const replaceRules = userConfig?.replaceRules || [];
531
531
  const domain = userConfig?.search && userConfig?.search?.mode === "remote" ? userConfig?.search.domain ?? "" : "";
532
- const pages = (await extractPageData(replaceRules, alias, domain, userRoot, routeService2)).filter(Boolean);
532
+ const pages = (await extractPageData(replaceRules, alias, domain, userDocRoot, routeService2)).filter(Boolean);
533
533
  await pluginDriver.modifySearchIndexData(pages);
534
534
  const pagesByLang = pages.reduce((acc, page) => {
535
535
  if (!acc[page.lang]) {
@@ -1040,7 +1040,7 @@ async function initRouteService(options) {
1040
1040
 
1041
1041
  // src/node/createBuilder.ts
1042
1042
  var require4 = createRequire3(import.meta.url);
1043
- async function createInternalBuildConfig(userRoot, config, isSSR, routeService2) {
1043
+ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeService2, pluginDriver) {
1044
1044
  const cwd = process.cwd();
1045
1045
  const { default: fs10 } = await import("@modern-js/utils/fs-extra");
1046
1046
  const CUSTOM_THEME_DIR = config?.themeDir ?? path8.join(process.cwd(), "theme");
@@ -1049,11 +1049,20 @@ async function createInternalBuildConfig(userRoot, config, isSSR, routeService2)
1049
1049
  const themeDir = await fs10.pathExists(CUSTOM_THEME_DIR) ? CUSTOM_THEME_DIR : DEFAULT_THEME_DIR;
1050
1050
  const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isSSR) ?? false;
1051
1051
  const base = config?.base ?? "";
1052
- const publicDir = path8.join(userRoot, "public");
1052
+ const publicDir = path8.join(userDocRoot, "public");
1053
1053
  const isPublicDirExist = await fs10.pathExists(publicDir);
1054
1054
  const assetPrefix = isProduction() ? removeTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : "";
1055
1055
  const enableMdxRs = config?.markdown?.experimentalMdxRs ?? false;
1056
1056
  const reactVersion = await detectReactVersion();
1057
+ const normalizeIcon = (icon) => {
1058
+ if (!icon) {
1059
+ return void 0;
1060
+ }
1061
+ if (path8.isAbsolute(icon)) {
1062
+ return path8.join(userDocRoot, PUBLIC_DIR, icon);
1063
+ }
1064
+ return icon;
1065
+ };
1057
1066
  const browserslist = {
1058
1067
  web: isProduction() ? [
1059
1068
  "chrome >= 61",
@@ -1076,7 +1085,7 @@ async function createInternalBuildConfig(userRoot, config, isSSR, routeService2)
1076
1085
  progressBar: false
1077
1086
  },
1078
1087
  html: {
1079
- favicon: config?.icon,
1088
+ favicon: normalizeIcon(config?.icon),
1080
1089
  template: path8.join(PACKAGE_ROOT, "index.html")
1081
1090
  },
1082
1091
  output: {
@@ -1113,6 +1122,10 @@ async function createInternalBuildConfig(userRoot, config, isSSR, routeService2)
1113
1122
  "process.env.TEST": JSON.stringify(process.env.TEST)
1114
1123
  }
1115
1124
  },
1125
+ performance: {
1126
+ // No need to print the server bundles size
1127
+ printFileSize: !isSSR
1128
+ },
1116
1129
  tools: {
1117
1130
  devServer: {
1118
1131
  // Serve static files
@@ -1146,10 +1159,11 @@ async function createInternalBuildConfig(userRoot, config, isSSR, routeService2)
1146
1159
  bundlerChain(chain) {
1147
1160
  chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(require4.resolve("../loader.cjs")).options({
1148
1161
  config,
1149
- docDirectory: userRoot,
1162
+ docDirectory: userDocRoot,
1150
1163
  checkDeadLinks,
1151
1164
  enableMdxRs,
1152
- routeService: routeService2
1165
+ routeService: routeService2,
1166
+ pluginDriver
1153
1167
  }).end().use("string-replace-loader").loader(require4.resolve("string-replace-loader")).options({
1154
1168
  multiple: config?.replaceRules || []
1155
1169
  });
@@ -1160,7 +1174,7 @@ async function createInternalBuildConfig(userRoot, config, isSSR, routeService2)
1160
1174
  }
1161
1175
  async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false, extraBuilderConfig) {
1162
1176
  const cwd = process.cwd();
1163
- const userRoot = path8.resolve(rootDir || config?.root || cwd);
1177
+ const userDocRoot = path8.resolve(rootDir || config?.root || cwd);
1164
1178
  const builderPlugins = config?.builderPlugins ?? [];
1165
1179
  const runtimeTempDir = path8.join(RSPRESS_TEMP_DIR2, "runtime");
1166
1180
  const runtimeAbsTempDir = path8.join(cwd, "node_modules", runtimeTempDir);
@@ -1168,12 +1182,12 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
1168
1182
  const routeService2 = await initRouteService({
1169
1183
  config,
1170
1184
  runtimeTempDir: runtimeAbsTempDir,
1171
- scanDir: userRoot,
1185
+ scanDir: userDocRoot,
1172
1186
  pluginDriver
1173
1187
  });
1174
1188
  const { default: { createBuilder, mergeBuilderConfig } } = await import("@modern-js/builder");
1175
1189
  const { default: { builderRspackProvider } } = await import("@modern-js/builder-rspack-provider");
1176
- const internalBuilderConfig = await createInternalBuildConfig(userRoot, config, isSSR, routeService2);
1190
+ const internalBuilderConfig = await createInternalBuildConfig(userDocRoot, config, isSSR, routeService2, pluginDriver);
1177
1191
  const builderProvider = builderRspackProvider({
1178
1192
  builderConfig: mergeBuilderConfig(internalBuilderConfig, ...config?.plugins?.map((plugin) => plugin.builderConfig ?? {}) || [], config?.builderConfig || {}, extraBuilderConfig || {})
1179
1193
  });
@@ -1186,7 +1200,7 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
1186
1200
  });
1187
1201
  builder.addPlugins([
1188
1202
  builderDocVMPlugin({
1189
- userRoot,
1203
+ userDocRoot,
1190
1204
  config,
1191
1205
  isSSR,
1192
1206
  runtimeTempDir,
@@ -1277,6 +1291,9 @@ var PluginDriver = class {
1277
1291
  _class_private_field_get2(this, _plugins).push(plugin);
1278
1292
  }
1279
1293
  }
1294
+ getPlugins() {
1295
+ return _class_private_field_get2(this, _plugins);
1296
+ }
1280
1297
  clearPlugins() {
1281
1298
  _class_private_field_set2(this, _plugins, []);
1282
1299
  }
@@ -1386,7 +1403,7 @@ async function dev(options) {
1386
1403
  }
1387
1404
 
1388
1405
  // src/node/build.ts
1389
- import { dirname as dirname2, isAbsolute, join as join3 } from "path";
1406
+ import { dirname as dirname2, join as join3 } from "path";
1390
1407
  import { pathToFileURL } from "url";
1391
1408
  import chalk2 from "@modern-js/utils/chalk";
1392
1409
  import fs9 from "@modern-js/utils/fs-extra";
@@ -1419,20 +1436,10 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
1419
1436
  clientBuilder.build(),
1420
1437
  ssrBuilder.build()
1421
1438
  ]);
1422
- const logoPaths = [];
1423
- const { logo } = config;
1424
- if (typeof logo === "string") {
1425
- logoPaths.push(logo);
1426
- } else if (typeof logo === "object") {
1427
- logoPaths.push(logo.light);
1428
- logoPaths.push(logo.dark);
1439
+ const publicDir = join3(docDirectory, PUBLIC_DIR);
1440
+ if (await fs9.pathExists(publicDir)) {
1441
+ await fs9.copy(publicDir, outputDir);
1429
1442
  }
1430
- logoPaths.filter((p) => p.startsWith("/")).forEach((p) => {
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);
1435
- });
1436
1443
  } finally {
1437
1444
  await writeSearchIndex(config);
1438
1445
  }