Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rsdoctor native plugin #8930

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Jan 3, 2025

Summary

Relate to web-infra-dev/rsdoctor#689

This pull request introduces rspack.experiments.RsdoctorPlugin to improve build performance of the projects that use Rsdoctor.

This plugin will collect datas from module graph and chunk graph according features in the plugin options, and then transfer them to js side by plugin hooks.

The defination of plugin options is:

type RsdoctorPluginOptions = {
	moduleGraphFeatures?: boolean | Array<"graph" | "ids" | "sources">;
	chunkGraphFeatures?: boolean | Array<"graph" | "assets">;
};

If the features is set to true, it will collect all the data. And if it is set to false, it will not collect any data.

If the features is set to an array, it will collect the data according to the array.

  • graph means that needs to get the basic graph data.
  • other means that needs to get other data based on the graph data. If graph is not in the array, it will panic.

The data can be obtained by the following hooks:

type RsdoctorPluginHooks = {
 moduleGraph: liteTapable.AsyncSeriesBailHook<[JsRsdoctorModuleGraph], false | void>;
 chunkGraph: liteTapable.AsyncSeriesBailHook<[JsRsdoctorChunkGraph], false | void>;
 moduleIds: liteTapable.AsyncSeriesBailHook<[JsRsdoctorModuleIdsPatch], false | void>;
 moduleSources: liteTapable.AsyncSeriesBailHook<[JsRsdoctorModuleSourcesPatch], false | void>;
 assets: liteTapable.AsyncSeriesBailHook<[JsRsdoctorAssetPatch], false | void>;
};

This is a example of how to use the plugin and the hooks:

const { experiments: { RsdoctorPlugin } } = require("@rspack/core");

module.exports = {
  // ...
  plugins: [
    new RsdoctorPlugin({
      // RsdoctorPluginOptions...
    }),
    {
      apply(compiler) {
        compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
          const hooks = RsdoctorPlugin.getCompilationHooks(compilation);
          hooks.moduleGraph.tap("MyPlugin", (data) => {
            // handle module graph data...
          });
          hooks.moduleSources.tap("MyPlugin", (data) => {
            // handle module sources data...
          });
        });
      }
    },
  ]
};

This pull request introduces the integration of the rsdoctor plugin into the project. The changes span across multiple files to add the necessary configurations and hooks for the rsdoctor plugin.

Integration of rsdoctor Plugin:

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@LingyuCoder LingyuCoder requested a review from chenjiahan January 3, 2025 10:34
@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Jan 3, 2025
Copy link

netlify bot commented Jan 3, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 2c83723
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/678a48f692104f0008b2c9c1
😎 Deploy Preview https://deploy-preview-8930--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codspeed-hq bot commented Jan 3, 2025

CodSpeed Performance Report

Merging #8930 will not alter performance

Comparing feat/rsdoctor-native-plugin (2c83723) with main (c47c243)

🎉 Hooray! codspeed-node just leveled up to 4.0.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 3 untouched benchmarks

fn stage(&self) -> i32 {
self.stage
}
}
Copy link
Contributor Author

@LingyuCoder LingyuCoder Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we can move definations of the plugin hooks to the plugin folder

@LingyuCoder LingyuCoder marked this pull request as ready for review January 17, 2025 05:51
@LingyuCoder LingyuCoder force-pushed the feat/rsdoctor-native-plugin branch 2 times, most recently from 9b7b783 to c85ad4b Compare January 17, 2025 08:55
@LingyuCoder LingyuCoder force-pushed the feat/rsdoctor-native-plugin branch from c85ad4b to 2c83723 Compare January 17, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant