Skip to content

Commit

Permalink
fix: change the check rule of the rsdoctor plugin
Browse files Browse the repository at this point in the history
fix: rsdoctor plugin

fix: rsdoctor plugin

feat: support add plugins for specified environment (#2986)

Co-authored-by: neverland <[email protected]>

Update packages/core/src/plugins/rsdoctor.ts

Co-authored-by: neverland <[email protected]>

Update packages/core/src/plugins/rsdoctor.ts

Co-authored-by: neverland <[email protected]>

Update packages/core/src/plugins/rsdoctor.ts

Co-authored-by: neverland <[email protected]>

fix: modify the criteria for verifying the Rsdoctor plugin.
  • Loading branch information
easy1090 committed Jul 23, 2024
1 parent 2137b39 commit 5743aac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/plugins/rsdoctor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Configuration } from '@rspack/core';
import color from 'picocolors';
import { logger } from '../logger';
import type { BundlerPluginInstance, RsbuildPlugin } from '../types';
Expand All @@ -7,15 +8,19 @@ type RsdoctorExports = {
RsdoctorWebpackPlugin: { new (): BundlerPluginInstance };
};

type MaybeRsdoctorPlugin = Configuration['plugins'] & { isRsdoctorPlugin?: boolean };

export const pluginRsdoctor = (): RsbuildPlugin => ({
name: 'rsbuild:rsdoctor',

setup(api) {
api.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
// If Rsdoctor isn't enabled, skip this plugin.
if (process.env.RSDOCTOR !== 'true') {
return;
}

// Add Rsdoctor plugin to start analysis.
const isRspack = api.context.bundlerType === 'rspack';
const packageName = isRspack
? '@rsdoctor/rspack-plugin'
Expand Down Expand Up @@ -45,9 +50,12 @@ export const pluginRsdoctor = (): RsbuildPlugin => ({

let isAutoRegister = false;

const isRsdoctorPlugin = (plugin: MaybeRsdoctorPlugin) => plugin?.isRsdoctorPlugin === true;

for (const config of bundlerConfigs) {
const registered = config.plugins?.some(
(plugin) => plugin?.constructor?.name === pluginName,
// If user has added the Rsdoctor plugin to the config file, it will return.
const registered = config.plugins?.some(
(plugin) => isRsdoctorPlugin(plugin as unknown as MaybeRsdoctorPlugin) || plugin?.constructor?.name === pluginName,
);

if (registered) {
Expand Down

0 comments on commit 5743aac

Please sign in to comment.