From 890871e4a8d52f846a24e464abe0a7408e0a0d8d Mon Sep 17 00:00:00 2001 From: yifancong Date: Mon, 2 Dec 2024 10:56:39 +0800 Subject: [PATCH 1/2] fix(multi-plugin): fix multi-plugin options error (#608) --- .changeset/strong-games-beam.md | 7 +++ .../plugins/multi-plugin-brief.test.ts | 56 +++++++++++++++++++ e2e/cases/doctor-webpack/test-utils.ts | 36 +++++++++++- e2e/playwright.config.ts | 1 + packages/rspack-plugin/src/multiple.ts | 13 ++++- packages/sdk/src/sdk/multiple/controller.ts | 2 + packages/sdk/src/sdk/multiple/slave.ts | 3 + packages/sdk/src/sdk/sdk/index.ts | 2 +- packages/webpack-plugin/src/multiple.ts | 12 +++- 9 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 .changeset/strong-games-beam.md create mode 100644 e2e/cases/doctor-webpack/plugins/multi-plugin-brief.test.ts diff --git a/.changeset/strong-games-beam.md b/.changeset/strong-games-beam.md new file mode 100644 index 00000000..1aeb9cac --- /dev/null +++ b/.changeset/strong-games-beam.md @@ -0,0 +1,7 @@ +--- +'@rsdoctor/webpack-plugin': patch +'@rsdoctor/rspack-plugin': patch +'@rsdoctor/sdk': patch +--- + +fix(multi-plugin): fix multi-plugin options error diff --git a/e2e/cases/doctor-webpack/plugins/multi-plugin-brief.test.ts b/e2e/cases/doctor-webpack/plugins/multi-plugin-brief.test.ts new file mode 100644 index 00000000..163e0a4e --- /dev/null +++ b/e2e/cases/doctor-webpack/plugins/multi-plugin-brief.test.ts @@ -0,0 +1,56 @@ +import { expect, test } from '@playwright/test'; +import { getSDK } from '@rsdoctor/core/plugins'; +import { compileByWebpack5 } from '@scripts/test-helper'; +import path from 'path'; +import { Compiler } from 'webpack'; +import { createRsdoctorMultiPlugin } from '../test-utils'; + +async function webpack(tapName: string, compile: typeof compileByWebpack5) { + const file = path.resolve(__dirname, '../fixtures/a.js'); + const loader = path.resolve(__dirname, '../fixtures/loaders/comment.js'); + const res = await compile(file, { + module: { + rules: [ + { + test: /\.js/, + use: loader, + }, + ], + }, + plugins: [ + createRsdoctorMultiPlugin({ + mode: 'brief', + brief: { + reportHtmlName: '111.html', + writeDataJson: false, + }, + }), + { + name: tapName, + apply(compiler: Compiler) { + compiler.hooks.done.tapPromise(tapName, async () => { + // nothing + }); + compiler.hooks.thisCompilation.tap(tapName, (compilation) => { + compilation.hooks.seal.tap(tapName, () => { + return 'seal end'; + }); + }); + }, + }, + ], + }); + return res; +} + +test('rsdoctor webpack5 multi-plugins options tests', async () => { + const tapName = 'Foo'; + await webpack(tapName, compileByWebpack5); + const sdk = getSDK(); + expect(sdk.type).toBe(0); + expect(sdk.extraConfig?.mode).toBe('brief'); + expect(sdk.extraConfig?.brief).toMatchObject({ + reportHtmlName: '111.html', + writeDataJson: false, + }); +}); diff --git a/e2e/cases/doctor-webpack/test-utils.ts b/e2e/cases/doctor-webpack/test-utils.ts index 39be0b85..67f32c3d 100644 --- a/e2e/cases/doctor-webpack/test-utils.ts +++ b/e2e/cases/doctor-webpack/test-utils.ts @@ -1,5 +1,8 @@ import { RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types'; -import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin'; +import { + RsdoctorWebpackPlugin, + RsdoctorWebpackMultiplePlugin, +} from '@rsdoctor/webpack-plugin'; import { Linter } from '@rsdoctor/types'; import { File } from '@rsdoctor/utils/build'; import { tmpdir } from 'os'; @@ -35,3 +38,34 @@ export function createRsdoctorPlugin( return plugin; } + +export function createRsdoctorMultiPlugin( + options: RsdoctorWebpackPluginOptions = {}, +) { + const plugin = new RsdoctorWebpackMultiplePlugin({ + ...options, + disableClientServer: + typeof options.disableClientServer === 'boolean' + ? options.disableClientServer + : true, + }); + + const outdir = path.resolve( + tmpdir(), + `./${Date.now()}/web_doctor_webpack_plugin_test`, + ); + + plugin.sdk.hooks.afterSaveManifest.tapPromise( + { name: 'REMOVE_TMP_DIR', stage: -9999 }, + async () => { + plugin.sdk.setOutputDir(outdir); + try { + await File.fse.remove(plugin.sdk.outputDir); + } catch (e) { + console.error(e); + } + }, + ); + + return plugin; +} diff --git a/e2e/playwright.config.ts b/e2e/playwright.config.ts index 353f9164..cdfb8e00 100644 --- a/e2e/playwright.config.ts +++ b/e2e/playwright.config.ts @@ -2,4 +2,5 @@ import { defineConfig } from '@playwright/test'; export default defineConfig({ testMatch: ['/cases/**/**.test.ts'], + timeout: 60000, }); diff --git a/packages/rspack-plugin/src/multiple.ts b/packages/rspack-plugin/src/multiple.ts index 7d581875..11440976 100644 --- a/packages/rspack-plugin/src/multiple.ts +++ b/packages/rspack-plugin/src/multiple.ts @@ -3,6 +3,7 @@ import type { Linter } from '@rsdoctor/types'; import type { RsdoctorMultiplePluginOptions } from '@rsdoctor/core'; import { RsdoctorRspackPlugin } from './plugin'; +import { normalizeUserConfig } from '@rsdoctor/core/plugins'; let globalController: RsdoctorSDKController | undefined; @@ -22,17 +23,25 @@ export class RsdoctorRspackMultiplePlugin< return controller; })(); + const normallizedOptions = normalizeUserConfig(options); + const instance = controller.createSlave({ name: options.name || 'Builder', stage: options.stage, - extraConfig: { disableTOSUpload: options.disableTOSUpload || false }, + extraConfig: { + disableTOSUpload: normallizedOptions.disableTOSUpload || false, + innerClientPath: normallizedOptions.innerClientPath, + printLog: normallizedOptions.printLog, + mode: normallizedOptions.mode ? normallizedOptions.mode : undefined, + brief: normallizedOptions.brief, + }, + type: normallizedOptions.reportCodeType, }); super({ ...options, sdkInstance: instance, }); - this.controller = controller; } } diff --git a/packages/sdk/src/sdk/multiple/controller.ts b/packages/sdk/src/sdk/multiple/controller.ts index db4a85b0..6a3e5d7d 100644 --- a/packages/sdk/src/sdk/multiple/controller.ts +++ b/packages/sdk/src/sdk/multiple/controller.ts @@ -42,12 +42,14 @@ export class RsdoctorSDKController { name, stage, extraConfig, + type, }: Omit[0], 'controller'>) { const slave = new RsdoctorPrimarySDK({ name, stage, controller: this, extraConfig, + type, }); this.slaves.push(slave); // sort by stage after create slave sdk. diff --git a/packages/sdk/src/sdk/multiple/slave.ts b/packages/sdk/src/sdk/multiple/slave.ts index e4d20f39..8b7f196a 100644 --- a/packages/sdk/src/sdk/multiple/slave.ts +++ b/packages/sdk/src/sdk/multiple/slave.ts @@ -16,6 +16,7 @@ interface RsdoctorSlaveSDKOptions { stage?: number; extraConfig?: SDK.SDKOptionsType; controller: RsdoctorSDKController; + type: SDK.ToDataType; } export class RsdoctorPrimarySDK extends RsdoctorSDK { @@ -34,6 +35,7 @@ export class RsdoctorPrimarySDK extends RsdoctorSDK { stage, controller, extraConfig, + type, }: RsdoctorSlaveSDKOptions) { super({ name, root: controller.root }); @@ -45,6 +47,7 @@ export class RsdoctorPrimarySDK extends RsdoctorSDK { this.extraConfig = extraConfig; this.parent = controller; this.server = new RsdoctorSlaveServer(this, port); + this.type = type; this.setName(name); this.clearSwitch(); } diff --git a/packages/sdk/src/sdk/sdk/index.ts b/packages/sdk/src/sdk/sdk/index.ts index b756c661..ba96d76b 100644 --- a/packages/sdk/src/sdk/sdk/index.ts +++ b/packages/sdk/src/sdk/sdk/index.ts @@ -25,7 +25,7 @@ export class RsdoctorSDK< public extraConfig: SDK.SDKOptionsType | undefined; - private type: SDK.ToDataType; + public type: SDK.ToDataType; private _summary: SDK.SummaryData = { costs: [] }; diff --git a/packages/webpack-plugin/src/multiple.ts b/packages/webpack-plugin/src/multiple.ts index 3ea9b118..ad783ed2 100644 --- a/packages/webpack-plugin/src/multiple.ts +++ b/packages/webpack-plugin/src/multiple.ts @@ -3,6 +3,7 @@ import type { Linter } from '@rsdoctor/types'; import type { RsdoctorMultiplePluginOptions } from '@rsdoctor/core'; import { RsdoctorWebpackPlugin } from './plugin'; +import { normalizeUserConfig } from '@rsdoctor/core/plugins'; let globalController: RsdoctorSDKController | undefined; @@ -22,10 +23,19 @@ export class RsdoctorWebpackMultiplePlugin< return controller; })(); + const normallizedOptions = normalizeUserConfig(options); + const instance = controller.createSlave({ name: options.name || 'Builder', stage: options.stage, - extraConfig: { disableTOSUpload: options.disableTOSUpload || false }, + extraConfig: { + disableTOSUpload: normallizedOptions.disableTOSUpload || false, + innerClientPath: normallizedOptions.innerClientPath, + printLog: normallizedOptions.printLog, + mode: normallizedOptions.mode ? normallizedOptions.mode : undefined, + brief: normallizedOptions.brief, + }, + type: normallizedOptions.reportCodeType, }); super({ From 9753c1406c3456654fa7e6697fe14cb7062e6d44 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:44:17 +0800 Subject: [PATCH 2/2] chore(deps): update dependency @rsbuild/plugin-type-check to ^1.1.0 (#614) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- packages/client/package.json | 2 +- pnpm-lock.yaml | 39 ++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/client/package.json b/packages/client/package.json index b60b0b33..1c09d913 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -32,7 +32,7 @@ "@rsbuild/plugin-node-polyfill": "^1.2.0", "@rsbuild/plugin-react": "^1.0.7", "@rsbuild/plugin-sass": "^1.1.1", - "@rsbuild/plugin-type-check": "^1.0.1", + "@rsbuild/plugin-type-check": "^1.1.0", "@rsdoctor/components": "workspace:*", "@rsdoctor/types": "workspace:*", "@types/node": "^16", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f04aa5d..d1577be4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -529,8 +529,8 @@ importers: specifier: ^1.1.1 version: 1.1.1(@rsbuild/core@1.1.6) '@rsbuild/plugin-type-check': - specifier: ^1.0.1 - version: 1.0.1(@rsbuild/core@1.1.6)(typescript@5.5.4) + specifier: ^1.1.0 + version: 1.1.0(@rsbuild/core@1.1.6)(@rspack/core@1.1.4)(typescript@5.5.4) '@rsdoctor/components': specifier: workspace:* version: link:../components @@ -4206,7 +4206,7 @@ packages: dependencies: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.24.8 - '@babel/helper-validator-option': 7.25.9 + '@babel/helper-validator-option': 7.24.8 '@babel/plugin-syntax-jsx': 7.24.7(@babel/core@7.26.0) '@babel/plugin-transform-modules-commonjs': 7.24.8(@babel/core@7.26.0) '@babel/plugin-transform-typescript': 7.25.2(@babel/core@7.26.0) @@ -7557,26 +7557,22 @@ packages: - webpack-cli dev: true - /@rsbuild/plugin-type-check@1.0.1(@rsbuild/core@1.1.6)(typescript@5.5.4): - resolution: {integrity: sha512-BahXAJNq4kWtL2dINUlrOL9UCN1t8c/qf5RW8JXx2HSSasfKPJGJ1BVfieMcIaFa/t8/QdafcwoxY1WKPTlSMg==} + /@rsbuild/plugin-type-check@1.1.0(@rsbuild/core@1.1.6)(@rspack/core@1.1.4)(typescript@5.5.4): + resolution: {integrity: sha512-9W/TxibRe7L6i4JnsIDRJfkvypPZQqCLO/jrAp+Liv4SCo9BVmbk/Rmpj+hfo2gjyewobk0AVi4/YQ5wOP7GSQ==} peerDependencies: - '@rsbuild/core': 1.x || ^1.0.1-beta.0 + '@rsbuild/core': 1.x peerDependenciesMeta: '@rsbuild/core': optional: true dependencies: '@rsbuild/core': 1.1.6 deepmerge: 4.3.1 - fork-ts-checker-webpack-plugin: 9.0.2(typescript@5.5.4)(webpack@5.95.0) json5: 2.2.3 reduce-configs: 1.0.0 - webpack: 5.95.0 + ts-checker-rspack-plugin: 1.0.1(@rspack/core@1.1.4)(typescript@5.5.4) transitivePeerDependencies: - - '@swc/core' - - esbuild + - '@rspack/core' - typescript - - uglify-js - - webpack-cli dev: true /@rsbuild/plugin-typed-css-modules@1.0.2(@rsbuild/core@1.0.19): @@ -12578,7 +12574,7 @@ packages: semver: 7.6.3 tapable: 2.2.1 typescript: 5.5.4 - webpack: 5.95.0 + webpack: 5.95.0(esbuild@0.17.19) dev: true /form-data@4.0.0: @@ -19425,6 +19421,23 @@ packages: /trough@2.2.0: resolution: {integrity: sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw==} + /ts-checker-rspack-plugin@1.0.1(@rspack/core@1.1.4)(typescript@5.5.4): + resolution: {integrity: sha512-u+RgBXBr6RHCJ+nJtA3A6MG3oDt20faU8DryX+H3HPhhU+cCnrGY304vmwOsQLJmoMWDk7/xkkbz2j9pC0aX1Q==} + engines: {node: '>=16.0.0'} + peerDependencies: + '@rspack/core': ^1.0.0 + typescript: '>=3.8.0' + dependencies: + '@babel/code-frame': 7.25.7 + '@rspack/core': 1.1.4(@swc/helpers@0.5.15) + '@rspack/lite-tapable': 1.0.1 + chokidar: 3.6.0 + memfs: 4.14.0 + minimatch: 9.0.5 + picocolors: 1.1.1 + typescript: 5.5.4 + dev: true + /ts-deepmerge@7.0.0: resolution: {integrity: sha512-WZ/iAJrKDhdINv1WG6KZIGHrZDar6VfhftG1QJFpVbOYZMYJLJOvZOo1amictRXVdBXZIgBHKswMTXzElngprA==} engines: {node: '>=14.13.1'}