From 7b0d48b6c3d91f488744970fd37241b6d4fdaf5a Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 1 Jun 2026 22:16:45 +0800 Subject: [PATCH] fix: narrow default node_modules exclude --- README.md | 4 ++-- src/options.ts | 4 ++-- test/fixtures/contains-node_modules-name/index.js | 3 +++ test/test.spec.ts | 10 ++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/contains-node_modules-name/index.js diff --git a/README.md b/README.md index ea5bfba..4ce32c1 100644 --- a/README.md +++ b/README.md @@ -119,13 +119,13 @@ new ReactRefreshPlugin({ ### exclude - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition) -- Default: `/node_modules/` +- Default: `/[\\/]node_modules[\\/]/` Exclude files from being processed by the plugin. The value is the same as the [rule.exclude](https://rspack.rs/config/module-rules#rulesexclude) option in Rspack. ```js new ReactRefreshPlugin({ - exclude: [/node_modules/, /some-other-module/], + exclude: [/[\\/]node_modules[\\/]/, /some-other-module/], }); ``` diff --git a/src/options.ts b/src/options.ts index 6203c5f..77e8967 100644 --- a/src/options.ts +++ b/src/options.ts @@ -21,7 +21,7 @@ export type PluginOptions = { /** * Exclude files from being processed by the plugin. * The value is the same as the `rule.exclude` option in Rspack. - * @default /node_modules/ + * @default /[\\/]node_modules[\\/]/ * @see https://rspack.rs/config/module-rules#rulesexclude */ exclude?: RuleSetCondition | null; @@ -95,7 +95,7 @@ export function normalizeOptions( options: PluginOptions, ): NormalizedPluginOptions { d(options, 'test', /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/); - d(options, 'exclude', /node_modules/i); + d(options, 'exclude', /[\\/]node_modules[\\/]/); d(options, 'library'); d(options, 'forceEnable', false); d(options, 'injectLoader', true); diff --git a/test/fixtures/contains-node_modules-name/index.js b/test/fixtures/contains-node_modules-name/index.js new file mode 100644 index 0000000..eab7ff4 --- /dev/null +++ b/test/fixtures/contains-node_modules-name/index.js @@ -0,0 +1,3 @@ +import 'foo'; + +export default 'contains-node_modules-name'; diff --git a/test/test.spec.ts b/test/test.spec.ts index 8c66906..13d0d65 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -160,6 +160,16 @@ describe('react-refresh-rspack-plugin', () => { expect(fixture).toContain('function $RefreshReg$'); }); + it('should include paths that only contain node_modules in the name', async () => { + const { + outputs: { fixture }, + } = await compileWithReactRefresh( + path.join(import.meta.dirname, 'fixtures/contains-node_modules-name'), + {}, + ); + expect(fixture).toContain('function $RefreshReg$'); + }); + it('should add library to make sure work in Micro-Frontend', async () => { const { outputs: { reactRefresh },