diff --git a/.changeset/three-baboons-hunt.md b/.changeset/three-baboons-hunt.md new file mode 100644 index 0000000000..1909b6f51b --- /dev/null +++ b/.changeset/three-baboons-hunt.md @@ -0,0 +1,23 @@ +--- +"@lynx-js/rspeedy": patch +--- + +Enable native Rsdoctor plugin by default. + +Set `tools.rsdoctor.experiments.enableNativePlugin` to `false` to use the old JS plugin. + +```js +import { defineConfig } from '@lynx-js/rspeedy'; + +export default defineConfig({ + tools: { + rsdoctor: { + experiments: { + enableNativePlugin: false, + }, + }, + }, +}); +``` + +See [Rsdoctor - 1.0](https://rsdoctor.dev/blog/release/release-note-1_0#-faster-analysis) for more details. diff --git a/packages/rspeedy/core/src/config/defaults.ts b/packages/rspeedy/core/src/config/defaults.ts index b717d8baf5..e387826ea1 100644 --- a/packages/rspeedy/core/src/config/defaults.ts +++ b/packages/rspeedy/core/src/config/defaults.ts @@ -8,14 +8,22 @@ import type { Filename } from './output/filename.js' import type { Config } from './index.js' export function applyDefaultRspeedyConfig(config: Config): Config { - const ret = mergeRsbuildConfig(config, { + const ret = mergeRsbuildConfig({ output: { // We are applying the default filename to the config // since some plugin(e.g.: `@lynx-js/qrcode-rsbuild-plugin`) will read // from the `output.filename.bundle` field. filename: getFilename(config.output?.filename), }, - }) + + tools: { + rsdoctor: { + experiments: { + enableNativePlugin: true, + }, + }, + }, + }, config) return ret } diff --git a/packages/rspeedy/core/test/config/tools/tools.test-d.ts b/packages/rspeedy/core/test/config/tools/tools.test-d.ts index 3f94af0835..36d61d7472 100644 --- a/packages/rspeedy/core/test/config/tools/tools.test-d.ts +++ b/packages/rspeedy/core/test/config/tools/tools.test-d.ts @@ -160,6 +160,28 @@ describe('Config - Tools', () => { }) }) + test('tools.rsdoctor', () => { + assertType({ + rsdoctor: {}, + }) + + assertType({ + rsdoctor: { + experiments: { + enableNativePlugin: true, + }, + }, + }) + + assertType({ + rsdoctor: { + experiments: { + enableNativePlugin: false, + }, + }, + }) + }) + test('tools.rspack', () => { // Object assertType({ diff --git a/packages/rspeedy/core/test/plugins/output.plugin.test.ts b/packages/rspeedy/core/test/plugins/output.plugin.test.ts index 39ca93dfb7..b654932295 100644 --- a/packages/rspeedy/core/test/plugins/output.plugin.test.ts +++ b/packages/rspeedy/core/test/plugins/output.plugin.test.ts @@ -698,12 +698,7 @@ describe('Plugins - Output', () => { await rsbuild.unwrapConfig() expect(rsbuild.getRspeedyConfig().output?.filename).toMatchInlineSnapshot( - ` - { - "bundle": "static/bundle/[name].bundle", - "template": "static/bundle/[name].bundle", - } - `, + `"static/bundle/[name].bundle"`, ) }) @@ -758,7 +753,7 @@ describe('Plugins - Output', () => { .toMatchInlineSnapshot(` { "bundle": "[name].bundle", - "template": "[name].bundle", + "template": "[name].template", } `) }) diff --git a/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts b/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts index 5a22a49d51..b84a8fb71c 100644 --- a/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts +++ b/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts @@ -29,6 +29,33 @@ describe('Plugins - Rsdoctor', () => { }) expect(options.supports.banner).toBe(true) + + expect(options.experiments?.enableNativePlugin).toBe(true) + }) + + test('experiments.enableNativePlugin: false', async () => { + vi.stubEnv('RSDOCTOR', 'true') + + const { createStubRspeedy } = await import('../createStubRspeedy.js') + + const rsbuild = await createStubRspeedy({ + tools: { + rsdoctor: { + experiments: { + enableNativePlugin: false, + }, + }, + }, + }) + + const compiler = await rsbuild.createCompiler() + + const { options } = compiler.options.plugins.find( + (plugin) => (typeof plugin === 'object' + && plugin?.['isRsdoctorPlugin'] === true), + ) as RsdoctorRspackPlugin<[]> + + expect(options.experiments?.enableNativePlugin).toBe(false) }) test('linter.rules.ecma-version-check', async () => {