@module-federation/rspress-plugin 0.0.0-next-20250724024905 → 0.0.0-next-20250724110701

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/esm/index.js CHANGED
@@ -8,7 +8,6 @@ import external_node_path_default from "node:path";
8
8
  import { load } from "cheerio";
9
9
  import { htmlToText } from "html-to-text";
10
10
  import { groupBy } from "lodash-es";
11
- import external_turndown_default from "turndown";
12
11
  import external_fs_default from "fs";
13
12
  const logger = createLogger('[ Module Federation Rspress Plugin ]');
14
13
  const src_logger = logger;
@@ -20,10 +19,6 @@ function findSearchIndexPaths(outputDir) {
20
19
  const searchIndexFiles = files.filter((file)=>file.startsWith(SEARCH_INDEX_NAME) && file.endsWith('.json') && external_fs_default.statSync(external_path_default.join(staticDir, file)).isFile());
21
20
  if (searchIndexFiles) return searchIndexFiles.map((searchIndexFile)=>external_path_default.join(staticDir, searchIndexFile));
22
21
  }
23
- function findMarkdownFilePath(outputDir, defaultLang, route) {
24
- const filepath = external_path_default.join(outputDir, route.relativePath.replace(new RegExp(`^${defaultLang}/`), ''));
25
- return filepath.replace(external_path_default.extname(filepath), '.md');
26
- }
27
22
  function generateTocFromHtml(html) {
28
23
  const $ = load(html);
29
24
  const headings = $('h1, h2, h3, h4, h5, h6');
@@ -47,22 +42,8 @@ function generateTocFromHtml(html) {
47
42
  };
48
43
  }
49
44
  const replaceHtmlExt = (filepath)=>filepath.replace(external_node_path_default.extname(filepath), '.html');
50
- const getRouteId = (route)=>route.absolutePath;
51
- async function getRouteHtmlMap(routesMap, options) {
52
- const routeHtmlMap = {};
53
- await Promise.all(Object.entries(routesMap).map(async ([routeId, route])=>{
54
- const { outputDir, defaultLang } = options;
55
- const htmlPath = replaceHtmlExt(external_node_path_default.join(outputDir, route.lang === defaultLang ? route.relativePath.replace(route.lang, '') : route.relativePath));
56
- const content = await promises_default.readFile(htmlPath, 'utf-8');
57
- routeHtmlMap[routeId] = {
58
- filepath: htmlPath,
59
- content
60
- };
61
- }));
62
- return routeHtmlMap;
63
- }
64
- async function extractPageDataFromHtml(routesMap, routeHtmlMap, options) {
65
- return Promise.all(Object.entries(routesMap).map(async ([routeId, route])=>{
45
+ async function extractPageDataFromHtml(routes, options) {
46
+ return Promise.all(routes.map(async (route)=>{
66
47
  const { domain, searchCodeBlocks, outputDir, defaultLang } = options;
67
48
  const defaultIndexInfo = {
68
49
  title: '',
@@ -78,8 +59,8 @@ async function extractPageDataFromHtml(routesMap, routeHtmlMap, options) {
78
59
  _filepath: route.absolutePath,
79
60
  _relativePath: ''
80
61
  };
81
- const html = routeHtmlMap[routeId].content;
82
- if (!html) throw new Error(`html not found for route "${routeId}"`);
62
+ const htmlPath = replaceHtmlExt(external_node_path_default.join(outputDir, route.lang === defaultLang ? route.relativePath.replace(route.lang, '') : route.relativePath));
63
+ const html = await promises_default.readFile(htmlPath, 'utf-8');
83
64
  let { toc: rawToc, title } = generateTocFromHtml(html);
84
65
  let content = html;
85
66
  content = htmlToText(html, {
@@ -148,14 +129,14 @@ function deletePrivateField(obj) {
148
129
  for(const key in newObj)if (key.startsWith('_')) delete newObj[key];
149
130
  return newObj;
150
131
  }
151
- async function rebuildSearchIndexByHtml(routesMap, routeHtmlMap, options) {
132
+ async function rebuildSearchIndexByHtml(routes, options) {
152
133
  const { versioned, outputDir } = options;
153
134
  const searchFilePaths = findSearchIndexPaths(outputDir);
154
135
  if (!searchFilePaths) {
155
136
  src_logger.error('Cannot find search index files!');
156
137
  process.exit(1);
157
138
  }
158
- const pages = await extractPageDataFromHtml(routesMap, routeHtmlMap, options);
139
+ const pages = await extractPageDataFromHtml(routes, options);
159
140
  const groupedPages = groupBy(pages, (page)=>{
160
141
  if (page.frontmatter?.pageType === 'home') return 'noindex';
161
142
  const version = versioned ? page.version : '';
@@ -176,20 +157,6 @@ async function rebuildSearchIndexByHtml(routesMap, routeHtmlMap, options) {
176
157
  await promises_default.writeFile(searchFilePath, stringifiedIndex);
177
158
  }));
178
159
  }
179
- async function rebuildLLMsMDFilesByHtml(routesMap, routeHtmlMap, options) {
180
- const { outputDir, defaultLang } = options;
181
- const turndownService = new external_turndown_default();
182
- await Promise.all(Object.entries(routeHtmlMap).map(async ([routeId, routeHtml])=>{
183
- try {
184
- const { content } = routeHtml;
185
- const markdown = turndownService.turndown(content);
186
- const mdFilePath = findMarkdownFilePath(outputDir, defaultLang, routesMap[routeId]);
187
- await promises_default.writeFile(mdFilePath, markdown);
188
- } catch (e) {
189
- src_logger.error(`rebuildLLMsMDFilesByHtml ${routeId} error:${e}`);
190
- }
191
- }));
192
- }
193
160
  const isDev = ()=>'development' === process.env.NODE_ENV;
194
161
  function replaceEntryWithBootstrapEntry(bundlerConfig) {
195
162
  const { entry } = bundlerConfig;
@@ -234,7 +201,7 @@ function replaceEntryWithBootstrapEntry(bundlerConfig) {
234
201
  bundlerConfig.entry = replaceWithAsyncEntry(entry, bundlerConfig.name || 'index');
235
202
  }
236
203
  function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
237
- const { autoShared = true, rebuildSearchIndex = true, rebuildLLMsMDFiles = true } = rspressOptions || {};
204
+ const { autoShared = true, rebuildSearchIndex = true } = rspressOptions || {};
238
205
  if (autoShared) mfConfig.shared = {
239
206
  react: {
240
207
  singleton: true,
@@ -264,7 +231,7 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
264
231
  };
265
232
  let enableSSG = false;
266
233
  let outputDir = '';
267
- let routesMap = {};
234
+ let routes = [];
268
235
  return {
269
236
  name: 'plugin-module-federation',
270
237
  async config (config) {
@@ -301,15 +268,12 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
301
268
  }
302
269
  },
303
270
  routeGenerated (routeMetaArr) {
304
- routesMap = routeMetaArr.reduce((prev, cur)=>{
305
- prev[getRouteId(cur)] = cur;
306
- return prev;
307
- }, {});
271
+ routes = routeMetaArr;
308
272
  },
309
273
  async afterBuild (config) {
310
- if (!mfConfig.remotes || isDev() || !rebuildSearchIndex || !rebuildLLMsMDFiles) return;
274
+ if (!mfConfig.remotes || isDev() || !rebuildSearchIndex) return;
311
275
  if (!enableSSG) {
312
- src_logger.error('rebuildSearchIndex and rebuildLLMsMDFiles are only supported for ssg');
276
+ src_logger.error('rebuildSearchIndex is only supported for ssg');
313
277
  process.exit(1);
314
278
  }
315
279
  const searchConfig = config?.search || {};
@@ -317,7 +281,7 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
317
281
  const domain = searchConfig?.mode === 'remote' ? searchConfig.domain ?? '' : '';
318
282
  const versioned = searchConfig && 'remote' !== searchConfig.mode && searchConfig.versioned;
319
283
  const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
320
- const routeHtmlMap = await getRouteHtmlMap(routesMap, {
284
+ await rebuildSearchIndexByHtml(routes, {
321
285
  outputDir,
322
286
  versioned,
323
287
  replaceRules,
@@ -325,22 +289,7 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
325
289
  searchCodeBlocks,
326
290
  defaultLang: config.lang || 'en'
327
291
  });
328
- const rebuildOptions = {
329
- outputDir,
330
- versioned,
331
- replaceRules,
332
- domain,
333
- searchCodeBlocks,
334
- defaultLang: config.lang || 'en'
335
- };
336
- if (rebuildSearchIndex) {
337
- await rebuildSearchIndexByHtml(routesMap, routeHtmlMap, rebuildOptions);
338
- src_logger.info('rebuildSearchIndex success!');
339
- }
340
- if (rebuildLLMsMDFiles && config.plugins?.find((p)=>'@rspress/plugin-llms' === p.name)) {
341
- await rebuildLLMsMDFilesByHtml(routesMap, routeHtmlMap, rebuildOptions);
342
- src_logger.info('rebuildLLMsMDFiles success!');
343
- }
292
+ src_logger.info('rebuildSearchIndex success!');
344
293
  }
345
294
  };
346
295
  }
@@ -0,0 +1 @@
1
+ export declare function findSearchIndexPaths(outputDir: string): string[] | undefined;
@@ -3,7 +3,6 @@ import type { RspressPlugin } from '@rspress/shared';
3
3
  type RspressPluginOptions = {
4
4
  autoShared?: boolean;
5
5
  rebuildSearchIndex?: boolean;
6
- rebuildLLMsMDFiles?: boolean;
7
6
  };
8
7
  export declare function pluginModuleFederation(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, rspressOptions?: RspressPluginOptions): RspressPlugin;
9
8
  export { createModuleFederationConfig } from '@module-federation/sdk';
@@ -0,0 +1,10 @@
1
+ import type { RouteMeta, ReplaceRule } from '@rspress/shared';
2
+ export type RebuildSearchIndexByHtmlOptions = {
3
+ domain: string;
4
+ searchCodeBlocks: boolean;
5
+ replaceRules: ReplaceRule[];
6
+ versioned?: boolean;
7
+ outputDir: string;
8
+ defaultLang: string;
9
+ };
10
+ export declare function rebuildSearchIndexByHtml(routes: RouteMeta[], options: RebuildSearchIndexByHtmlOptions): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/rspress-plugin",
3
- "version": "0.0.0-next-20250724024905",
3
+ "version": "0.0.0-next-20250724110701",
4
4
  "type": "module",
5
5
  "description": "Module Federation plugin for Rspress",
6
6
  "keywords": [
@@ -34,19 +34,17 @@
34
34
  "@rspress/shared": "2.0.0-beta.16",
35
35
  "@types/html-to-text": "^9.0.4",
36
36
  "@types/lodash-es": "^4.17.12",
37
- "@types/react": "^18.3.11",
38
- "@types/turndown": "5.0.5 "
37
+ "@types/react": "^18.3.11"
39
38
  },
40
39
  "dependencies": {
41
40
  "cheerio": "1.0.0-rc.12",
42
41
  "fs-extra": "11.3.0",
43
42
  "html-to-text": "^9.0.5",
44
43
  "lodash-es": "^4.17.21",
45
- "turndown": "7.2.0",
46
- "@module-federation/sdk": "0.0.0-next-20250724024905",
47
- "@module-federation/enhanced": "0.0.0-next-20250724024905",
48
- "@module-federation/rsbuild-plugin": "0.0.0-next-20250724024905",
49
- "@module-federation/error-codes": "0.0.0-next-20250724024905"
44
+ "@module-federation/sdk": "0.0.0-next-20250724110701",
45
+ "@module-federation/enhanced": "0.0.0-next-20250724110701",
46
+ "@module-federation/rsbuild-plugin": "0.0.0-next-20250724110701",
47
+ "@module-federation/error-codes": "0.0.0-next-20250724110701"
50
48
  },
51
49
  "scripts": {
52
50
  "build": "rslib build",
@@ -1,3 +0,0 @@
1
- import type { RouteMeta } from '@rspress/shared';
2
- export declare function findSearchIndexPaths(outputDir: string): string[] | undefined;
3
- export declare function findMarkdownFilePath(outputDir: string, defaultLang: string, route: RouteMeta): string;
@@ -1,20 +0,0 @@
1
- import type { RouteMeta, ReplaceRule } from '@rspress/shared';
2
- interface RouteHtmlMap {
3
- [routeId: string]: {
4
- filepath: string;
5
- content: string;
6
- };
7
- }
8
- export type RebuildOptions = {
9
- domain: string;
10
- searchCodeBlocks: boolean;
11
- replaceRules: ReplaceRule[];
12
- versioned?: boolean;
13
- outputDir: string;
14
- defaultLang: string;
15
- };
16
- export declare const getRouteId: (route: RouteMeta) => string;
17
- export declare function getRouteHtmlMap(routesMap: Record<string, RouteMeta>, options: RebuildOptions): Promise<RouteHtmlMap>;
18
- export declare function rebuildSearchIndexByHtml(routesMap: Record<string, RouteMeta>, routeHtmlMap: RouteHtmlMap, options: RebuildOptions): Promise<void>;
19
- export declare function rebuildLLMsMDFilesByHtml(routesMap: Record<string, RouteMeta>, routeHtmlMap: RouteHtmlMap, options: RebuildOptions): Promise<void>;
20
- export {};