For AI agents: the complete documentation index is available at https://rsdoctor.rs/llms.txt, the full documentation bundle is available at https://rsdoctor.rs/llms-full.txt, and this page is available as Markdown at https://rsdoctor.rs/guide/rules/upload-data.md.
close
  • English
  • Data upload

    To perform data upload, you need to use the interface of custom extension rules. Please refer to Custom Extension Rules for more information.

    The same approach can collect and upload build data. The check function can be asynchronous, so Rsdoctor waits for the upload to finish. Replace the example URL with your endpoint:

    // src/rules/upload-data.ts
    import { defineRule } from '@rsdoctor/core';
    
    export const UploadData = defineRule(() => ({
      meta: {
        category: 'bundle',
        severity: 'Warn',
        title: 'upload-data',
      },
      async check({ chunkGraph, moduleGraph }) {
        const response = await fetch('https://example.com/api/build-metrics', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            assetCount: chunkGraph.getAssets().length,
            moduleCount: moduleGraph.getModules().length,
          }),
        });
        if (!response.ok) throw new Error(`Upload failed: ${response.status}`);
      },
    }));
    // rsbuild.config.ts
    import { RsdoctorRspackPlugin } from '@rsdoctor/core';
    import { UploadData } from './rules/upload-data';
    
    export default {
      tools: {
        bundlerChain: (chain) => {
          chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
            {
              linter: {
                level: 'Warn',
                extends: [UploadData],
              },
            },
          ]);
        },
      },
    };