@module-federation/rspress-plugin 0.23.0 → 0.24.0

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.
@@ -1,17 +1,17 @@
1
- import external_path_default from "path";
2
- import external_fs_extra_default from "fs-extra";
3
1
  import { pluginModuleFederation } from "@module-federation/rsbuild-plugin";
4
2
  import { BUILD_002, buildDescMap, getShortErrorMsg } from "@module-federation/error-codes";
5
3
  import { createLogger, createModuleFederationConfig } from "@module-federation/sdk";
6
4
  import promises_default from "node:fs/promises";
7
5
  import external_node_path_default from "node:path";
6
+ import "node:crypto";
8
7
  import { load } from "cheerio";
9
8
  import { htmlToText } from "html-to-text";
10
9
  import { groupBy } from "lodash-es";
10
+ import { SEARCH_INDEX_NAME } from "@rspress/shared";
11
+ import external_path_default from "path";
11
12
  import external_fs_default from "fs";
12
13
  const logger = createLogger('[ Module Federation Rspress Plugin ]');
13
14
  const src_logger = logger;
14
- const SEARCH_INDEX_NAME = 'search_index';
15
15
  function findSearchIndexPaths(outputDir) {
16
16
  const staticDir = external_path_default.join(outputDir, 'static');
17
17
  if (!external_fs_default.existsSync(staticDir)) return;
@@ -44,16 +44,14 @@ function generateTocFromHtml(html) {
44
44
  const replaceHtmlExt = (filepath)=>filepath.replace(external_node_path_default.extname(filepath), '.html');
45
45
  async function extractPageDataFromHtml(routes, options) {
46
46
  return Promise.all(routes.map(async (route)=>{
47
- const { domain, searchCodeBlocks, outputDir, defaultLang } = options;
47
+ const { searchCodeBlocks, outputDir, defaultLang } = options;
48
48
  const defaultIndexInfo = {
49
49
  title: '',
50
50
  content: '',
51
- _html: '',
52
51
  _flattenContent: '',
53
52
  routePath: route.routePath,
54
53
  lang: route.lang,
55
54
  toc: [],
56
- domain,
57
55
  frontmatter: {},
58
56
  version: route.version,
59
57
  _filepath: route.absolutePath,
@@ -116,8 +114,7 @@ async function extractPageDataFromHtml(routes, options) {
116
114
  ...defaultIndexInfo,
117
115
  title,
118
116
  toc,
119
- content,
120
- _html: html
117
+ content
121
118
  };
122
119
  }));
123
120
  }
@@ -158,48 +155,6 @@ async function rebuildSearchIndexByHtml(routes, options) {
158
155
  }));
159
156
  }
160
157
  const isDev = ()=>'development' === process.env.NODE_ENV;
161
- function replaceEntryWithBootstrapEntry(bundlerConfig) {
162
- const { entry } = bundlerConfig;
163
- if (!entry) {
164
- src_logger.error('No entry found!');
165
- process.exit(1);
166
- }
167
- if ('function' == typeof entry) {
168
- src_logger.error('Not support entry function!');
169
- process.exit(1);
170
- }
171
- const replaceWithAsyncEntry = (entries, entryName)=>{
172
- const entryPath = external_path_default.resolve(process.cwd(), `node_modules/.federation/${entryName}-bootstrap.js`);
173
- external_fs_extra_default.ensureDirSync(external_path_default.dirname(entryPath));
174
- if ('string' == typeof entries) {
175
- external_fs_extra_default.writeFileSync(entryPath, `const entry = import ('${entries}');
176
- const render = entry.then(({render})=>(render));
177
- const routes = entry.then(({routes})=>(routes));
178
- export {
179
- render,
180
- routes
181
- };`);
182
- return entryPath;
183
- }
184
- external_fs_extra_default.writeFileSync(entryPath, `const entry = import ('${entries.slice(-1)[0]}');
185
- const render = entry.then(({render})=>(render));
186
- const routes = entry.then(({routes})=>(routes));
187
- export {
188
- render,
189
- routes
190
- };`);
191
- return entries.slice(0, -1).concat(entryPath);
192
- };
193
- if ('object' == typeof entry && !Array.isArray(entry)) return void Object.keys(entry).forEach((entryName)=>{
194
- const entryValue = entry[entryName];
195
- if (!Array.isArray(entryValue)) {
196
- src_logger.error(`Not support entry ${typeof entryValue}!`);
197
- process.exit(1);
198
- }
199
- entry[entryName] = replaceWithAsyncEntry(entryValue, `${entryName}${bundlerConfig.name ? `-${bundlerConfig.name}` : ''}`);
200
- });
201
- bundlerConfig.entry = replaceWithAsyncEntry(entry, bundlerConfig.name || 'index');
202
- }
203
158
  function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
204
159
  const { autoShared = true, rebuildSearchIndex = true } = rspressOptions || {};
205
160
  if (autoShared) mfConfig.shared = {
@@ -223,12 +178,14 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
223
178
  singleton: true,
224
179
  requiredVersion: false
225
180
  },
226
- '@rspress/runtime': {
181
+ '@rspress/core/runtime': {
227
182
  singleton: true,
228
183
  requiredVersion: false
229
184
  },
230
185
  ...mfConfig.shared
231
186
  };
187
+ mfConfig.experiments ||= {};
188
+ mfConfig.experiments.asyncStartup = true;
232
189
  let enableSSG = false;
233
190
  let outputDir = '';
234
191
  let routes = [];
@@ -237,11 +194,6 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
237
194
  async config (config) {
238
195
  if (!isDev() && false !== config.ssg) enableSSG = true;
239
196
  config.builderConfig ||= {};
240
- config.builderConfig.dev ||= {};
241
- if (isDev() && void 0 === config.builderConfig.dev.lazyCompilation) {
242
- src_logger.warn('lazyCompilation is not fully supported for module federation, set lazyCompilation to false');
243
- config.builderConfig.dev.lazyCompilation = false;
244
- }
245
197
  config.builderConfig.plugins ||= [];
246
198
  config.builderConfig.plugins.push(pluginModuleFederation(mfConfig, {
247
199
  target: enableSSG ? 'dual' : 'web',
@@ -254,7 +206,6 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
254
206
  plugins: [],
255
207
  tools: {
256
208
  rspack (config) {
257
- replaceEntryWithBootstrapEntry(config);
258
209
  if ('node' === config.name) {
259
210
  if (('/' === config.output.publicPath || 'auto' === config.output.publicPath) && mfConfig.exposes) {
260
211
  src_logger.error(getShortErrorMsg(BUILD_002, buildDescMap, {
@@ -278,8 +229,8 @@ function plugin_pluginModuleFederation(mfConfig, rspressOptions) {
278
229
  }
279
230
  const searchConfig = config?.search || {};
280
231
  const replaceRules = config?.replaceRules || [];
281
- const domain = searchConfig?.mode === 'remote' ? searchConfig.domain ?? '' : '';
282
- const versioned = searchConfig && 'remote' !== searchConfig.mode && searchConfig.versioned;
232
+ const domain = '';
233
+ const versioned = searchConfig && searchConfig.versioned;
283
234
  const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
284
235
  await rebuildSearchIndexByHtml(routes, {
285
236
  outputDir,
@@ -1,5 +1,5 @@
1
1
  import type { moduleFederationPlugin } from '@module-federation/sdk';
2
- import type { RspressPlugin } from '@rspress/shared';
2
+ import type { RspressPlugin } from '@rspress/core';
3
3
  type RspressPluginOptions = {
4
4
  autoShared?: boolean;
5
5
  rebuildSearchIndex?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/rspress-plugin",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "type": "module",
5
5
  "description": "Module Federation plugin for Rspress",
6
6
  "keywords": [
@@ -23,15 +23,15 @@
23
23
  "author": "hanric <hanric.zhang@gmail.com>",
24
24
  "exports": {
25
25
  ".": {
26
- "types": "./dist/esm/packages/rspress-plugin/src/plugin.d.ts",
27
- "import": "./dist/esm/index.js"
26
+ "types": "./dist/plugin.d.ts",
27
+ "import": "./dist/index.js"
28
28
  }
29
29
  },
30
- "module": "./dist/esm/index.js",
31
- "types": "./dist/esm/packages/rspress-plugin/src/plugin.d.ts",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/plugin.d.ts",
32
32
  "devDependencies": {
33
33
  "@rslib/core": "^0.9.2",
34
- "@rspress/shared": "2.0.0-beta.16",
34
+ "@rspress/core": "2.0.1",
35
35
  "@types/html-to-text": "^9.0.4",
36
36
  "@types/lodash-es": "^4.17.12",
37
37
  "@types/react": "^18.3.11"
@@ -41,14 +41,17 @@
41
41
  "fs-extra": "11.3.0",
42
42
  "html-to-text": "^9.0.5",
43
43
  "lodash-es": "^4.17.21",
44
- "@module-federation/enhanced": "0.23.0",
45
- "@module-federation/rsbuild-plugin": "0.23.0",
46
- "@module-federation/sdk": "0.23.0",
47
- "@module-federation/error-codes": "0.23.0"
44
+ "@rspress/shared": "2.0.1",
45
+ "@module-federation/sdk": "0.24.0",
46
+ "@module-federation/enhanced": "0.24.0",
47
+ "@module-federation/rsbuild-plugin": "0.24.0",
48
+ "@module-federation/error-codes": "0.24.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@rspress/core": "^2.0.1"
48
52
  },
49
53
  "scripts": {
50
54
  "build": "rslib build",
51
- "dev": "rslib mf-dev",
52
55
  "build:watch": "rslib build --watch"
53
56
  }
54
57
  }