@rspress/core 1.42.0 → 1.43.0-canary-20240224

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/193.js CHANGED
@@ -5,8 +5,6 @@ export const ids = [
5
5
  ];
6
6
  export const modules = {
7
7
  "./package.json": function(module) {
8
- module.exports = {
9
- version: "1.42.0"
10
- };
8
+ module.exports = JSON.parse('{"version":"1.43.0-canary-20240224"}');
11
9
  }
12
10
  };
package/dist/index.js CHANGED
@@ -8,6 +8,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__ from "@rsb
8
8
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__ from "@rsbuild/plugin-sass";
10
10
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
12
+ import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
11
13
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
12
14
  import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
13
15
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
@@ -22,8 +24,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
22
24
  import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
23
25
  import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
24
26
  import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
25
- import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
26
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
27
27
  export * from "@rspress/shared";
28
28
  var __webpack_modules__ = {};
29
29
  var __webpack_module_cache__ = {};
@@ -330,6 +330,48 @@ const BODY_START_TAG = '<body';
330
330
  const DEFAULT_TITLE = 'Rspress';
331
331
  const PUBLIC_DIR = 'public';
332
332
  const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
333
+ async function pathExists(path) {
334
+ try {
335
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
336
+ return true;
337
+ } catch {
338
+ return false;
339
+ }
340
+ }
341
+ async function readJson(path) {
342
+ const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
343
+ return JSON.parse(raw);
344
+ }
345
+ const THEME_DEFAULT_EXPORT_PATTERN = /export default \{(.*?)\}/m;
346
+ async function hintThemeBreakingChange(customThemeDir) {
347
+ const fileList = [
348
+ 'index.ts',
349
+ 'index.tsx',
350
+ 'index.js',
351
+ 'index.mjs'
352
+ ];
353
+ let useDefaultExportFilePath;
354
+ for (const file of fileList){
355
+ const filePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(customThemeDir, file);
356
+ if (await pathExists(filePath)) {
357
+ const content = await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.readFile)(filePath, {
358
+ encoding: 'utf-8'
359
+ });
360
+ if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
361
+ }
362
+ }
363
+ if (useDefaultExportFilePath) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`[Rspress] Theme breaking change: The theme/index is now using namedExports instead of defaultExports, please update your config file in ${useDefaultExportFilePath}`, __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red(`
364
+ - import Theme from '@rspress/theme-default';
365
+ - export default {
366
+ - ...Theme,
367
+ - Layout,
368
+ - };
369
+ - export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green(`+ import { Layout } from '@rspress/theme-default';
370
+
371
+ + export { Layout };
372
+ + export * from 'rspress/theme';
373
+ `));
374
+ }
333
375
  const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
334
376
  function slash(p) {
335
377
  return p.replace(/\\/g, '/');
@@ -804,14 +846,20 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
804
846
  applyReplaceRulesToNestedObject(frontmatter, replaceRules);
805
847
  const { flattenContent } = await flattenMdxContent(applyReplaceRules(strippedFrontMatter, replaceRules), route.absolutePath, alias);
806
848
  content = flattenContent.replace(importStatementRegex, '');
807
- const { html, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
849
+ const { html: rawHtml, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
808
850
  value: content,
809
851
  filepath: route.absolutePath,
810
852
  development: 'production' !== process.env.NODE_ENV,
811
853
  root
812
854
  });
813
855
  if (!(null == title ? void 0 : title.length) && !frontmatter && !(null === (_frontmatter_title = frontmatter.title) || void 0 === _frontmatter_title ? void 0 : _frontmatter_title.length)) return null;
814
- content = (0, __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__.htmlToText)(String(html), {
856
+ function encodeHtml(html) {
857
+ return html.replace(/<code>([\s\S]*?)<\/\s?code>/gm, function(_match, innerContent) {
858
+ return `<code>${innerContent.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code>`;
859
+ });
860
+ }
861
+ const html = encodeHtml(String(rawHtml));
862
+ content = (0, __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__.htmlToText)(html, {
815
863
  wordwrap: 80,
816
864
  selectors: [
817
865
  {
@@ -1211,18 +1259,6 @@ function serveSearchIndexMiddleware(config) {
1211
1259
  } else null == next || next();
1212
1260
  };
1213
1261
  }
1214
- async function pathExists(path) {
1215
- try {
1216
- await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
1217
- return true;
1218
- } catch {
1219
- return false;
1220
- }
1221
- }
1222
- async function readJson(path) {
1223
- const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
1224
- return JSON.parse(raw);
1225
- }
1226
1262
  const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
1227
1263
  const DEFAULT_REACT_VERSION = 18;
1228
1264
  async function detectReactVersion() {
@@ -1338,6 +1374,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1338
1374
  if (__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR, icon);
1339
1375
  return icon;
1340
1376
  };
1377
+ await hintThemeBreakingChange(CUSTOM_THEME_DIR);
1341
1378
  const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
1342
1379
  detectCustomIcon(CUSTOM_THEME_DIR),
1343
1380
  resolveReactAlias(reactVersion, false),
@@ -92,7 +92,7 @@ function App({ helmetContext }) {
92
92
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__.HelmetProvider, {
93
93
  context: helmetContext,
94
94
  children: [
95
- /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__["default"].Layout, {}),
95
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Layout, {}),
96
96
  !hideGlobalUIComponents && __WEBPACK_EXTERNAL_MODULE_virtual_global_components_43dbb356__["default"].map((componentInfo, index)=>{
97
97
  if (Array.isArray(componentInfo)) {
98
98
  const [component, props] = componentInfo;
@@ -1,16 +1,13 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
2
1
  import * as __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__ from "react-dom";
3
2
  import * as __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__ from "react-dom/client";
4
3
  import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
5
4
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
6
5
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
10
10
  var __webpack_modules__ = {
11
- "@theme": function(module) {
12
- module.exports = __WEBPACK_EXTERNAL_MODULE__theme_75e53063__;
13
- },
14
11
  "react-dom": function(module) {
15
12
  module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__;
16
13
  },
@@ -29,14 +26,13 @@ function __webpack_require__(moduleId) {
29
26
  return module.exports;
30
27
  }
31
28
  const enableSSG = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].ssg;
32
- const { default: Theme, useThemeState } = __webpack_require__("@theme");
33
29
  async function renderInBrowser() {
34
30
  const container = document.getElementById('root');
35
31
  const enhancedApp = async ()=>{
36
32
  const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)(window.location.pathname);
37
33
  return function() {
38
34
  const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
39
- const [theme, setTheme] = useThemeState();
35
+ const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
40
36
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
41
37
  value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
42
38
  theme,
@@ -72,6 +68,6 @@ async function renderInBrowser() {
72
68
  }
73
69
  }
74
70
  renderInBrowser().then(()=>{
75
- Theme.setup();
71
+ (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.setup)();
76
72
  });
77
73
  export { renderInBrowser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "1.42.0",
3
+ "version": "1.43.0-canary-20240224",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -78,13 +78,13 @@
78
78
  "unified": "^10.1.2",
79
79
  "unist-util-visit": "^4.1.2",
80
80
  "unist-util-visit-children": "^3.0.0",
81
- "@rspress/plugin-auto-nav-sidebar": "1.42.0",
82
- "@rspress/plugin-container-syntax": "1.42.0",
83
- "@rspress/plugin-last-updated": "1.42.0",
84
- "@rspress/plugin-medium-zoom": "1.42.0",
85
- "@rspress/runtime": "1.42.0",
86
- "@rspress/shared": "1.42.0",
87
- "@rspress/theme-default": "1.42.0"
81
+ "@rspress/plugin-auto-nav-sidebar": "1.43.0-canary-20240224",
82
+ "@rspress/plugin-last-updated": "1.43.0-canary-20240224",
83
+ "@rspress/runtime": "1.43.0-canary-20240224",
84
+ "@rspress/plugin-medium-zoom": "1.43.0-canary-20240224",
85
+ "@rspress/plugin-container-syntax": "1.43.0-canary-20240224",
86
+ "@rspress/shared": "1.43.0-canary-20240224",
87
+ "@rspress/theme-default": "1.43.0-canary-20240224"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@microsoft/api-extractor": "^7.49.2",
@@ -10,7 +10,7 @@ import {
10
10
  type PageData,
11
11
  cleanUrl,
12
12
  } from '@rspress/shared';
13
- import Theme from '@theme';
13
+ import { Layout } from '@theme';
14
14
  import React, { useContext, useLayoutEffect } from 'react';
15
15
  import { HelmetProvider } from 'react-helmet-async';
16
16
  import globalComponents from 'virtual-global-components';
@@ -150,7 +150,7 @@ export function App({ helmetContext }: { helmetContext?: object }) {
150
150
 
151
151
  return (
152
152
  <HelmetProvider context={helmetContext}>
153
- <Theme.Layout />
153
+ <Layout />
154
154
  {
155
155
  // Global UI
156
156
  !hideGlobalUIComponents &&
@@ -1,5 +1,6 @@
1
1
  import { BrowserRouter, DataContext, ThemeContext } from '@rspress/runtime';
2
2
  import { isProduction } from '@rspress/shared';
3
+ import { setup, useThemeState } from '@theme';
3
4
  import { useMemo, useState } from 'react';
4
5
  import siteData from 'virtual-site-data';
5
6
  import { App, initPageData } from './App';
@@ -7,7 +8,6 @@ import { App, initPageData } from './App';
7
8
  const enableSSG = siteData.ssg;
8
9
 
9
10
  // eslint-disable-next-line import/no-commonjs
10
- const { default: Theme, useThemeState } = require('@theme');
11
11
 
12
12
  export async function renderInBrowser() {
13
13
  const container = document.getElementById('root')!;
@@ -52,5 +52,5 @@ export async function renderInBrowser() {
52
52
  }
53
53
 
54
54
  renderInBrowser().then(() => {
55
- Theme.setup();
55
+ setup();
56
56
  });
package/theme.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from '@rspress/theme-default';
2
- export { default } from '@rspress/theme-default';