@rspress/core 1.11.2 → 1.12.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
@@ -66,7 +66,7 @@ var require_package = __commonJS({
66
66
  "package.json"(exports, module) {
67
67
  module.exports = {
68
68
  name: "@rspress/core",
69
- version: "1.11.2",
69
+ version: "1.12.1",
70
70
  description: "The Rspress Documentation Framework",
71
71
  bugs: "https://github.com/web-infra-dev/rspress/issues",
72
72
  repository: {
@@ -90,6 +90,7 @@ var require_package = __commonJS({
90
90
  "./theme": {
91
91
  default: "./theme.ts"
92
92
  },
93
+ "./theme.css": "./theme.css",
93
94
  "./runtime": {
94
95
  default: "./runtime.ts"
95
96
  }
@@ -121,7 +122,7 @@ var require_package = __commonJS({
121
122
  "@mdx-js/loader": "2.2.1",
122
123
  "@mdx-js/mdx": "2.2.1",
123
124
  "@mdx-js/react": "2.2.1",
124
- "@modern-js/utils": "2.46.1",
125
+ "@modern-js/utils": "2.47.0",
125
126
  "@rsbuild/core": "0.4.0",
126
127
  "@rsbuild/plugin-react": "0.4.0",
127
128
  "@rsbuild/plugin-svgr": "0.4.0",
@@ -171,9 +172,9 @@ var require_package = __commonJS({
171
172
  },
172
173
  devDependencies: {
173
174
  tailwindcss: "^3.2.7",
174
- "@modern-js/plugin-tailwindcss": "2.46.1",
175
- "@modern-js/tsconfig": "2.46.1",
176
- "@modern-js/types": "2.46.1",
175
+ "@modern-js/plugin-tailwindcss": "2.47.0",
176
+ "@modern-js/tsconfig": "2.47.0",
177
+ "@modern-js/types": "2.47.0",
177
178
  "@types/body-scroll-lock": "^3.1.0",
178
179
  "@types/fs-extra": "^9.0.13",
179
180
  "@types/hast": "^2.3.4",
@@ -231,80 +232,10 @@ import {
231
232
  removeLeadingSlash as removeLeadingSlash2,
232
233
  MDX_REGEXP as MDX_REGEXP3,
233
234
  RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2,
234
- isDebugMode,
235
235
  removeTrailingSlash
236
236
  } from "@rspress/shared";
237
237
  import fs8 from "@rspress/shared/fs-extra";
238
238
 
239
- // tailwind.config.ts
240
- var tailwindConfig = {
241
- content: [],
242
- darkMode: "class",
243
- theme: {
244
- backgroundColor: (ctx) => ({
245
- ...ctx.theme("colors"),
246
- white: "var(--rp-c-bg)",
247
- soft: "var(--rp-c-bg-soft)",
248
- mute: "var(--rp-c-bg-mute)"
249
- }),
250
- extend: {
251
- borderRadius: {
252
- "4xl": "2rem"
253
- },
254
- breakpoints: {
255
- xs: "640px",
256
- sm: "768px",
257
- md: "960px",
258
- lg: "1280px"
259
- },
260
- maxWidth: {
261
- "60": "15rem"
262
- },
263
- maxHeight: {
264
- "60": "15rem"
265
- },
266
- colors: {
267
- brand: {
268
- DEFAULT: "var(--rp-c-brand)",
269
- light: "var(--rp-c-brand-light)",
270
- dark: "var(--rp-c-brand-dark)",
271
- lighter: "var(--rp-c-brand-lighter)",
272
- darker: "var(--rp-c-brand-darker)"
273
- },
274
- text: {
275
- 1: "var(--rp-c-text-1)",
276
- 2: "var(--rp-c-text-2)",
277
- 3: "var(--rp-c-text-3)",
278
- 4: "var(--rp-c-text-4)"
279
- },
280
- divider: {
281
- DEFAULT: "var(--rp-c-divider)",
282
- light: "var(--rp-c-divider-light)",
283
- dark: "var(--rp-c-divider-dark)"
284
- },
285
- gray: {
286
- light: {
287
- 1: "var(--rp-c-gray-light-1)",
288
- 2: "var(--rp-c-gray-light-2)",
289
- 3: "var(--rp-c-gray-light-3)",
290
- 4: "var(--rp-c-gray-light-4)",
291
- 5: "var(--rp-c-gray-light-5)"
292
- }
293
- },
294
- dark: {
295
- light: {
296
- 1: "var(--rp-c-dark-light-1)",
297
- 2: "var(--rp-c-dark-light-2)",
298
- 3: "var(--rp-c-dark-light-3)",
299
- 4: "var(--rp-c-dark-light-4)",
300
- 5: "var(--rp-c-dark-light-5)"
301
- }
302
- }
303
- }
304
- }
305
- }
306
- };
307
-
308
239
  // src/node/constants.ts
309
240
  import path from "path";
310
241
  import { fileURLToPath } from "url";
@@ -361,7 +292,8 @@ import {
361
292
  withBase,
362
293
  addLeadingSlash as addLeadingSlash2,
363
294
  isExternalUrl,
364
- withoutBase
295
+ withoutBase,
296
+ slash
365
297
  } from "@rspress/shared";
366
298
 
367
299
  // src/node/utils/applyReplaceRules.ts
@@ -409,11 +341,12 @@ function normalizeThemeConfig(docConfig, pages = []) {
409
341
  const locales = siteLocales ?? (themeConfig?.locales || []);
410
342
  const i18nTextData = getI18nData(docConfig);
411
343
  const normalizeLinkPrefix = (link = "", currentLang = "") => {
412
- if (!currentLang || !link || withoutBase(link, base).startsWith(`/${currentLang}`) || isExternalUrl(link) || // In multi version case, we have got the complete link prefix in `plugin-auto-nav-sidebar` and does not need to add the lang prefix
344
+ const normalizedLink = slash(link);
345
+ if (!currentLang || !link || withoutBase(normalizedLink, base).startsWith(`/${currentLang}`) || isExternalUrl(normalizedLink) || // In multi version case, we have got the complete link prefix in `plugin-auto-nav-sidebar` and does not need to add the lang prefix
413
346
  hasMultiVersion) {
414
- return link;
347
+ return normalizedLink;
415
348
  }
416
- return lang === currentLang ? link : `/${currentLang}${addLeadingSlash2(link)}`;
349
+ return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash2(normalizedLink)}`;
417
350
  };
418
351
  const getI18nText = (key = "", currentLang = "") => {
419
352
  const text = i18nTextData[key]?.[currentLang];
@@ -427,6 +360,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
427
360
  const normalizeSidebarItem = (item) => {
428
361
  if (typeof item === "object" && "items" in item) {
429
362
  return {
363
+ ...item,
430
364
  text: applyReplaceRules(
431
365
  getI18nText(item.text, currentLang),
432
366
  replaceRules
@@ -450,10 +384,12 @@ function normalizeThemeConfig(docConfig, pages = []) {
450
384
  );
451
385
  return {
452
386
  text: applyReplaceRules(page?.title || "", replaceRules),
453
- link: normalizedItem
387
+ link: normalizedItem,
388
+ _fileKey: page._relativePath.replace(/\.mdx?$/, "")
454
389
  };
455
390
  }
456
391
  return {
392
+ ...item,
457
393
  text: applyReplaceRules(
458
394
  getI18nText(item.text, currentLang),
459
395
  replaceRules
@@ -553,11 +489,11 @@ import { loadFrontMatter } from "@rspress/shared/node-utils";
553
489
  import os from "os";
554
490
  import path2 from "path";
555
491
  var isWindows = os.platform() === "win32";
556
- function slash(p) {
492
+ function slash2(p) {
557
493
  return p.replace(/\\/g, "/");
558
494
  }
559
495
  function normalizePath(id) {
560
- return path2.posix.normalize(isWindows ? slash(id) : id);
496
+ return path2.posix.normalize(isWindows ? slash2(id) : id);
561
497
  }
562
498
 
563
499
  // src/node/utils/getPageKey.ts
@@ -679,6 +615,9 @@ async function resolveDepPath(importPath, importer, alias) {
679
615
  return resolveResult;
680
616
  }
681
617
  async function flattenMdxContent(content, basePath, alias) {
618
+ if (!importStatementRegex.test(content)) {
619
+ return content;
620
+ }
682
621
  let result = content;
683
622
  if (!startFlatten) {
684
623
  resolver = ResolverFactory2.createResolver({
@@ -695,7 +634,6 @@ async function flattenMdxContent(content, basePath, alias) {
695
634
  return content;
696
635
  }
697
636
  const importNodes = ast.children.filter((node) => node.type === "mdxjsEsm").map((node) => {
698
- result = result.replace(node.value, "");
699
637
  return node.data?.estree?.body || [];
700
638
  }).flat().filter((node) => node.type === "ImportDeclaration");
701
639
  for (const importNode of importNodes) {
@@ -1089,6 +1027,7 @@ function rsbuildPluginDocVM(factoryContext) {
1089
1027
  runtimeModule[key] = modulesByPlugin[key];
1090
1028
  });
1091
1029
  bundlerChain.plugin(`rspress-runtime-module`).use(
1030
+ // @ts-expect-error
1092
1031
  new RspackVirtualModulePlugin(
1093
1032
  runtimeModule,
1094
1033
  factoryContext.runtimeTempDir
@@ -1511,23 +1450,6 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
1511
1450
  printFileSize: !isSSR
1512
1451
  },
1513
1452
  tools: {
1514
- postcss(config2) {
1515
- if (isDebugMode()) {
1516
- try {
1517
- config2.postcssOptions.plugins.push(
1518
- __require("tailwindcss")({
1519
- config: {
1520
- ...tailwindConfig,
1521
- content: [
1522
- path10.join(PACKAGE_ROOT, "src", "theme-default", "**/*")
1523
- ]
1524
- }
1525
- })
1526
- );
1527
- } catch (e) {
1528
- }
1529
- }
1530
- },
1531
1453
  bundlerChain(chain, { CHAIN_ID }) {
1532
1454
  const swcLoaderOptions = chain.module.rule(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.SWC).get("options");
1533
1455
  chain.module.rule("MDX").type("javascript/auto").test(MDX_REGEXP3).oneOf("MDXCompile").use("builtin:swc-loader").loader("builtin:swc-loader").options(swcLoaderOptions).end().use("mdx-loader").loader(__require.resolve("../loader.cjs")).options({
@@ -1579,7 +1501,7 @@ async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRs
1579
1501
  const rsbuild = await createRsbuild({
1580
1502
  rsbuildConfig: mergeRsbuildConfig2(
1581
1503
  internalRsbuildConfig,
1582
- ...config?.plugins?.map((plugin) => plugin.builderConfig ?? {}) || [],
1504
+ ...pluginDriver.getPlugins()?.map((plugin) => plugin.builderConfig ?? {}) || [],
1583
1505
  config?.builderConfig || {},
1584
1506
  extraRsbuildConfig || {}
1585
1507
  )
@@ -1603,6 +1525,7 @@ async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRs
1603
1525
  }
1604
1526
 
1605
1527
  // src/node/PluginDriver.ts
1528
+ import { isDebugMode } from "@rspress/shared";
1606
1529
  import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
1607
1530
  var _config, _plugins, _isProd;
1608
1531
  var PluginDriver = class {
@@ -1639,6 +1562,18 @@ var PluginDriver = class {
1639
1562
  this.addPlugin(pluginAutoNavSidebar());
1640
1563
  }
1641
1564
  this.addPlugin(pluginContainerSyntax());
1565
+ if (isDebugMode()) {
1566
+ const SourceBuildPlugin = await import(
1567
+ // @ts-expect-error need moduleResolution: Node16, NodeNext or Bundler to get type declerations work
1568
+ "@rspress/theme-default/node/source-build-plugin.js"
1569
+ ).then(
1570
+ (r) => r.SourceBuildPlugin,
1571
+ () => null
1572
+ );
1573
+ if (SourceBuildPlugin) {
1574
+ this.addPlugin(SourceBuildPlugin());
1575
+ }
1576
+ }
1642
1577
  (config.plugins || []).forEach((plugin) => {
1643
1578
  this.addPlugin(plugin);
1644
1579
  });