@docusaurus/plugin-rsdoctor 4.0.0-canary-6980 → 4.0.0-canary-6985

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@docusaurus/plugin-rsdoctor`
2
2
 
3
- [Rsdoctor](https://rsdoctor.dev/) plugin for Docusaurus.
3
+ [Rsdoctor](https://rsdoctor.rs/) plugin for Docusaurus.
4
4
 
5
5
  ## Usage
6
6
 
package/lib/index.js CHANGED
@@ -7,35 +7,41 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateOptions = void 0;
10
- const rspack_plugin_1 = require("@rsdoctor/rspack-plugin");
11
- const webpack_plugin_1 = require("@rsdoctor/webpack-plugin");
12
- function getRsdoctorPlugin(currentBundlerName) {
10
+ // Rsdoctor v2 only supports Rspack, Webpack sites keep using Rsdoctor v1
11
+ // Each Rsdoctor package is imported lazily, only for the current bundler
12
+ async function getCreateBundlerConfig({ currentBundlerName, rsdoctorOptions, }) {
13
13
  return currentBundlerName === 'rspack'
14
- ? rspack_plugin_1.RsdoctorRspackMultiplePlugin
15
- : // Cast fixes "error TS2321: Excessive stack depth"
16
- // This may be a temporary TS 7.0 issue?
17
- webpack_plugin_1.RsdoctorWebpackMultiplePlugin;
14
+ ? getCreateRspackConfig(rsdoctorOptions)
15
+ : getCreateWebpackConfig(rsdoctorOptions);
18
16
  }
19
- function createRsdoctorBundlerPlugin({ isServer, currentBundler, options, }) {
20
- const RsdoctorPlugin = getRsdoctorPlugin(currentBundler.name);
21
- return new RsdoctorPlugin({
22
- name: isServer ? 'server' : 'client',
23
- ...options.rsdoctorOptions,
17
+ async function getCreateRspackConfig(rsdoctorOptions) {
18
+ const { RsdoctorRspackPlugin, migrateRsdoctorOptions } = await import('@rsdoctor/core');
19
+ // Rsdoctor v1 options keep working, with a warning to migrate them
20
+ // A single instance applied to both compilers merges them in one report
21
+ const plugin = new RsdoctorRspackPlugin(migrateRsdoctorOptions(rsdoctorOptions));
22
+ return ({ name }) => ({
23
+ // Rsdoctor v2 names each compiler report after the compiler name
24
+ name,
25
+ plugins: [plugin],
26
+ });
27
+ }
28
+ async function getCreateWebpackConfig(rsdoctorOptions) {
29
+ const { RsdoctorWebpackMultiplePlugin } = await import('@rsdoctor/webpack-plugin');
30
+ return ({ name }) => ({
31
+ plugins: [
32
+ new RsdoctorWebpackMultiplePlugin({ name, ...rsdoctorOptions }),
33
+ ],
24
34
  });
25
35
  }
26
36
  exports.default = (async function pluginRsdoctor(context, options) {
37
+ const createBundlerConfig = await getCreateBundlerConfig({
38
+ currentBundlerName: context.currentBundler.name,
39
+ rsdoctorOptions: options.rsdoctorOptions,
40
+ });
27
41
  return {
28
42
  name: 'docusaurus-plugin-rsdoctor',
29
43
  configureWebpack: (__config, isServer) => {
30
- return {
31
- plugins: [
32
- createRsdoctorBundlerPlugin({
33
- isServer,
34
- currentBundler: context.currentBundler,
35
- options,
36
- }),
37
- ],
38
- };
44
+ return createBundlerConfig({ name: isServer ? 'server' : 'client' });
39
45
  },
40
46
  };
41
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-rsdoctor",
3
- "version": "4.0.0-canary-6980",
3
+ "version": "4.0.0-canary-6985",
4
4
  "description": "Rsdoctor plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,15 +14,15 @@
14
14
  },
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@docusaurus/core": "4.0.0-canary-6980",
18
- "@docusaurus/types": "4.0.0-canary-6980",
19
- "@docusaurus/utils-validation": "4.0.0-canary-6980",
20
- "@rsdoctor/rspack-plugin": "^1.6.3",
17
+ "@docusaurus/core": "4.0.0-canary-6985",
18
+ "@docusaurus/types": "4.0.0-canary-6985",
19
+ "@docusaurus/utils-validation": "4.0.0-canary-6985",
20
+ "@rsdoctor/core": "^2.0.0",
21
21
  "@rsdoctor/webpack-plugin": "^1.6.3",
22
22
  "tslib": "^2.8.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@docusaurus/module-type-aliases": "4.0.0-canary-6980"
25
+ "@docusaurus/module-type-aliases": "4.0.0-canary-6985"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^19.3.0",
package/src/index.ts CHANGED
@@ -5,60 +5,71 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import {RsdoctorRspackMultiplePlugin} from '@rsdoctor/rspack-plugin';
9
- import {RsdoctorWebpackMultiplePlugin} from '@rsdoctor/webpack-plugin';
10
8
  import type {ConfigureWebpackResult} from '@docusaurus/types/src/plugin';
11
9
  import type {CurrentBundler, LoadContext, Plugin} from '@docusaurus/types';
12
10
  import type {PluginOptions, Options} from './options';
13
11
 
14
- type RsdoctorPluginType = typeof RsdoctorRspackMultiplePlugin;
12
+ type BundlerConfig = ConfigureWebpackResult;
15
13
 
16
- function getRsdoctorPlugin(
17
- currentBundlerName: CurrentBundler['name'],
18
- ): RsdoctorPluginType {
19
- return currentBundlerName === 'rspack'
20
- ? RsdoctorRspackMultiplePlugin
21
- : // Cast fixes "error TS2321: Excessive stack depth"
22
- // This may be a temporary TS 7.0 issue?
23
- (RsdoctorWebpackMultiplePlugin as unknown as RsdoctorPluginType);
24
- }
14
+ type RsdoctorOptions = PluginOptions['rsdoctorOptions'];
15
+
16
+ type CreateBundlerConfig = (params: {name: string}) => BundlerConfig;
25
17
 
26
- function createRsdoctorBundlerPlugin({
27
- isServer,
28
- currentBundler,
29
- options,
18
+ // Rsdoctor v2 only supports Rspack, Webpack sites keep using Rsdoctor v1
19
+ // Each Rsdoctor package is imported lazily, only for the current bundler
20
+ async function getCreateBundlerConfig({
21
+ currentBundlerName,
22
+ rsdoctorOptions,
30
23
  }: {
31
- isServer: boolean;
32
- currentBundler: CurrentBundler;
33
- options: PluginOptions;
34
- }) {
35
- const RsdoctorPlugin = getRsdoctorPlugin(currentBundler.name);
24
+ currentBundlerName: CurrentBundler['name'];
25
+ rsdoctorOptions: RsdoctorOptions;
26
+ }): Promise<CreateBundlerConfig> {
27
+ return currentBundlerName === 'rspack'
28
+ ? getCreateRspackConfig(rsdoctorOptions)
29
+ : getCreateWebpackConfig(rsdoctorOptions);
30
+ }
36
31
 
37
- // Little type incompatibility?
38
- type WebpackPlugin = NonNullable<ConfigureWebpackResult['plugins']>[number];
32
+ async function getCreateRspackConfig(
33
+ rsdoctorOptions: RsdoctorOptions,
34
+ ): Promise<CreateBundlerConfig> {
35
+ const {RsdoctorRspackPlugin, migrateRsdoctorOptions} =
36
+ await import('@rsdoctor/core');
37
+ // Rsdoctor v1 options keep working, with a warning to migrate them
38
+ // A single instance applied to both compilers merges them in one report
39
+ const plugin = new RsdoctorRspackPlugin(
40
+ migrateRsdoctorOptions(rsdoctorOptions),
41
+ );
42
+ return ({name}) => ({
43
+ // Rsdoctor v2 names each compiler report after the compiler name
44
+ name,
45
+ plugins: [plugin] as unknown as BundlerConfig['plugins'],
46
+ });
47
+ }
39
48
 
40
- return new RsdoctorPlugin({
41
- name: isServer ? 'server' : 'client',
42
- ...options.rsdoctorOptions,
43
- }) as unknown as WebpackPlugin;
49
+ async function getCreateWebpackConfig(
50
+ rsdoctorOptions: RsdoctorOptions,
51
+ ): Promise<CreateBundlerConfig> {
52
+ const {RsdoctorWebpackMultiplePlugin} =
53
+ await import('@rsdoctor/webpack-plugin');
54
+ return ({name}) => ({
55
+ plugins: [
56
+ new RsdoctorWebpackMultiplePlugin({name, ...rsdoctorOptions}),
57
+ ] as unknown as BundlerConfig['plugins'],
58
+ });
44
59
  }
45
60
 
46
61
  export default (async function pluginRsdoctor(
47
62
  context: LoadContext,
48
63
  options: PluginOptions,
49
64
  ): Promise<Plugin | null> {
65
+ const createBundlerConfig = await getCreateBundlerConfig({
66
+ currentBundlerName: context.currentBundler.name,
67
+ rsdoctorOptions: options.rsdoctorOptions,
68
+ });
50
69
  return {
51
70
  name: 'docusaurus-plugin-rsdoctor',
52
71
  configureWebpack: (__config, isServer) => {
53
- return {
54
- plugins: [
55
- createRsdoctorBundlerPlugin({
56
- isServer,
57
- currentBundler: context.currentBundler,
58
- options,
59
- }),
60
- ],
61
- };
72
+ return createBundlerConfig({name: isServer ? 'server' : 'client'});
62
73
  },
63
74
  };
64
75
  });