From 9e08ff14e448711b63cce7eb9fe70a2f97a43579 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 28 Feb 2026 15:43:50 +0800 Subject: [PATCH 1/2] fix: remove require webpack --- src/server.ts | 13 ++++----- tests/e2e/api.test.js | 6 ++-- tests/e2e/history-api-fallback.test.js | 4 +-- tests/e2e/hot-and-live-reload.test.js | 2 +- tests/e2e/overlay.test.js | 2 +- tests/e2e/server.test.js | 28 +++++++++---------- tests/e2e/setup-exit-signals.test.js | 6 ++-- tests/e2e/static-directory.test.js | 2 +- tests/e2e/stats.test.js | 2 +- tests/e2e/watch-files.test.js | 2 +- tests/e2e/web-socket-communication.test.js | 2 +- .../webpack.config.js | 4 +-- .../webpack.config.js | 4 +-- tests/helpers/html-generator-plugin.js | 4 +-- .../trusted-types-html-generator-plugin.js | 6 ++-- 15 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/server.ts b/src/server.ts index 69d3748..fa19d36 100644 --- a/src/server.ts +++ b/src/server.ts @@ -577,11 +577,9 @@ class Server< additionalEntries.push(clientHotEntry); } - const webpack = compiler.webpack || require('webpack'); - // use a hook to add entries if available for (const additionalEntry of additionalEntries) { - new webpack.EntryPlugin(compiler.context, additionalEntry, { + new compiler.rspack.EntryPlugin(compiler.context, additionalEntry, { name: undefined, }).apply(compiler); } @@ -1521,9 +1519,9 @@ class Server< this.addAdditionalEntries(compiler); - const webpack = compiler.webpack || require('webpack'); + const { ProvidePlugin, HotModuleReplacementPlugin } = compiler.rspack; - new webpack.ProvidePlugin({ + new ProvidePlugin({ __webpack_dev_server_client__: this.getClientTransport() as | string | string[], @@ -1532,8 +1530,7 @@ class Server< if (this.options.hot) { const HMRPluginExists = compiler.options.plugins.find( (plugin) => - plugin && - plugin.constructor === webpack.HotModuleReplacementPlugin, + plugin && plugin.constructor === HotModuleReplacementPlugin, ); if (HMRPluginExists) { @@ -1542,7 +1539,7 @@ class Server< ); } else { // Apply the HMR plugin - const plugin = new webpack.HotModuleReplacementPlugin(); + const plugin = new HotModuleReplacementPlugin(); plugin.apply(compiler); } diff --git a/tests/e2e/api.test.js b/tests/e2e/api.test.js index 565ae94..d900a9e 100644 --- a/tests/e2e/api.test.js +++ b/tests/e2e/api.test.js @@ -17,7 +17,7 @@ describe('API', () => { beforeEach(async () => { // this is important - it clears the cache - rstest.resetModules(); + rs.resetModules(); process.env = { ...OLD_ENV }; @@ -307,7 +307,7 @@ describe('API', () => { }); it('should use the default `noop` callback when invalidate is called without any callback', async () => { - const callback = rstest.fn(); + const callback = rs.fn(); server.invalidate(); server.middleware.context.callbacks[0] = callback; @@ -326,7 +326,7 @@ describe('API', () => { }); it('should use the provided `callback` function', async () => { - const callback = rstest.fn(); + const callback = rs.fn(); server.invalidate(callback); diff --git a/tests/e2e/history-api-fallback.test.js b/tests/e2e/history-api-fallback.test.js index 78515bb..15161ff 100644 --- a/tests/e2e/history-api-fallback.test.js +++ b/tests/e2e/history-api-fallback.test.js @@ -436,7 +436,7 @@ describe('historyApiFallback option', () => { let consoleSpy; beforeEach(async () => { - consoleSpy = rstest.spyOn(global.console, 'log'); + consoleSpy = rs.spyOn(global.console, 'log'); compiler = webpack(config); @@ -512,7 +512,7 @@ describe('historyApiFallback option', () => { let consoleSpy; beforeEach(async () => { - consoleSpy = rstest.spyOn(global.console, 'log'); + consoleSpy = rs.spyOn(global.console, 'log'); compiler = webpack(config); diff --git a/tests/e2e/hot-and-live-reload.test.js b/tests/e2e/hot-and-live-reload.test.js index 3e6d8fc..81a65b6 100644 --- a/tests/e2e/hot-and-live-reload.test.js +++ b/tests/e2e/hot-and-live-reload.test.js @@ -711,7 +711,7 @@ describe('hot and live reload', () => { // plugins: [...config.plugins, new webpack.HotModuleReplacementPlugin()], // }); -// loggerWarnSpy = rstest.fn(); +// loggerWarnSpy = rs.fn(); // getInfrastructureLoggerSpy = rstest // .spyOn(compiler, "getInfrastructureLogger") diff --git a/tests/e2e/overlay.test.js b/tests/e2e/overlay.test.js index 86c3f74..1ae4900 100644 --- a/tests/e2e/overlay.test.js +++ b/tests/e2e/overlay.test.js @@ -69,7 +69,7 @@ let prettierHTML; let prettierCSS; describe('overlay', () => { - const mockLaunchEditorCb = rstest.fn(); + const mockLaunchEditorCb = rs.fn(); rs.doMockRequire('launch-editor', () => mockLaunchEditorCb); beforeAll(async () => { diff --git a/tests/e2e/server.test.js b/tests/e2e/server.test.js index 7f4a91a..0a6a6ad 100644 --- a/tests/e2e/server.test.js +++ b/tests/e2e/server.test.js @@ -285,7 +285,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -368,7 +368,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -459,7 +459,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -548,7 +548,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -646,7 +646,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -721,7 +721,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -800,7 +800,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -873,7 +873,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -956,7 +956,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -1047,7 +1047,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -1143,7 +1143,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -1225,7 +1225,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(https, 'createServer'); + createServerSpy = rs.spyOn(https, 'createServer'); server = new Server( { @@ -1291,7 +1291,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(spdy, 'createServer'); + createServerSpy = rs.spyOn(spdy, 'createServer'); server = new Server( { @@ -1372,7 +1372,7 @@ describe('server option', () => { beforeEach(async () => { compiler = webpack(config); - createServerSpy = rstest.spyOn(customHTTP, 'createServer'); + createServerSpy = rs.spyOn(customHTTP, 'createServer'); server = new Server( { diff --git a/tests/e2e/setup-exit-signals.test.js b/tests/e2e/setup-exit-signals.test.js index f8b3192..96f15bd 100644 --- a/tests/e2e/setup-exit-signals.test.js +++ b/tests/e2e/setup-exit-signals.test.js @@ -39,7 +39,7 @@ describe('setupExitSignals option', () => { consoleMessages = []; doExit = false; - exitSpy = rstest.spyOn(process, 'exit').mockImplementation(() => { + exitSpy = rs.spyOn(process, 'exit').mockImplementation(() => { doExit = true; }); @@ -47,10 +47,10 @@ describe('setupExitSignals option', () => { .spyOn(process.stdin, 'resume') .mockImplementation(() => {}); - stopCallbackSpy = rstest.spyOn(server, 'stopCallback'); + stopCallbackSpy = rs.spyOn(server, 'stopCallback'); if (server.compiler.close) { - closeCallbackSpy = rstest.spyOn(server.compiler, 'close'); + closeCallbackSpy = rs.spyOn(server.compiler, 'close'); } }); diff --git a/tests/e2e/static-directory.test.js b/tests/e2e/static-directory.test.js index d92c35c..e10bc3b 100644 --- a/tests/e2e/static-directory.test.js +++ b/tests/e2e/static-directory.test.js @@ -673,7 +673,7 @@ describe('static.directory option', () => { beforeEach(async () => { // This is a somewhat weird test, but it is important that we mock // the PWD here, and test if /other.html in our "fake" PWD really is not requested. - rstest.spyOn(process, 'cwd').mockImplementation(() => publicDirectory); + rs.spyOn(process, 'cwd').mockImplementation(() => publicDirectory); compiler = webpack(config); diff --git a/tests/e2e/stats.test.js b/tests/e2e/stats.test.js index 96ebb0a..1745d95 100644 --- a/tests/e2e/stats.test.js +++ b/tests/e2e/stats.test.js @@ -5,7 +5,7 @@ const HTMLGeneratorPlugin = require('../helpers/html-generator-plugin'); const runBrowser = require('../helpers/run-browser'); const port = require('../helpers/ports-map').stats; -global.console.log = rstest.fn(); +global.console.log = rs.fn(); describe('stats', () => { const cases = [ diff --git a/tests/e2e/watch-files.test.js b/tests/e2e/watch-files.test.js index c9dc06e..6f6a27c 100644 --- a/tests/e2e/watch-files.test.js +++ b/tests/e2e/watch-files.test.js @@ -554,7 +554,7 @@ describe('watchFiles option', () => { describe('should work with options', () => { const file = path.join(watchDir, 'assets/example.txt'); - const chokidarMock = rstest.spyOn(chokidar, 'watch'); + const chokidarMock = rs.spyOn(chokidar, 'watch'); const optionCases = [ { diff --git a/tests/e2e/web-socket-communication.test.js b/tests/e2e/web-socket-communication.test.js index bca9e5b..3443109 100644 --- a/tests/e2e/web-socket-communication.test.js +++ b/tests/e2e/web-socket-communication.test.js @@ -6,7 +6,7 @@ const config = require('../fixtures/client-config/webpack.config'); const runBrowser = require('../helpers/run-browser'); const port = require('../helpers/ports-map')['web-socket-communication']; -rstest.setConfig({ testTimeout: 60_000 }); +rs.setConfig({ testTimeout: 60_000 }); describe('web socket communication', () => { const webSocketServers = ['ws', 'sockjs']; diff --git a/tests/fixtures/lazy-compilation-multiple-entries/webpack.config.js b/tests/fixtures/lazy-compilation-multiple-entries/webpack.config.js index 75fdaf2..a75cc16 100644 --- a/tests/fixtures/lazy-compilation-multiple-entries/webpack.config.js +++ b/tests/fixtures/lazy-compilation-multiple-entries/webpack.config.js @@ -52,13 +52,13 @@ module.exports = { const twoFilename = 'test-two.html'; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { - const { RawSource } = compiler.webpack.sources; + const { RawSource } = compiler.rspack.sources; compilation.hooks.processAssets.tap( { name: pluginName, stage: - compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, }, () => { const oneSource = new RawSource(oneHTMLContent); diff --git a/tests/fixtures/lazy-compilation-single-entry/webpack.config.js b/tests/fixtures/lazy-compilation-single-entry/webpack.config.js index e21fa10..d9d7e24 100644 --- a/tests/fixtures/lazy-compilation-single-entry/webpack.config.js +++ b/tests/fixtures/lazy-compilation-single-entry/webpack.config.js @@ -37,13 +37,13 @@ module.exports = { const filename = 'test.html'; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { - const { RawSource } = compiler.webpack.sources; + const { RawSource } = compiler.rspack.sources; compilation.hooks.processAssets.tap( { name: pluginName, stage: - compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, }, () => { const source = new RawSource(HTMLContent); diff --git a/tests/helpers/html-generator-plugin.js b/tests/helpers/html-generator-plugin.js index 8d0483c..fc5261b 100644 --- a/tests/helpers/html-generator-plugin.js +++ b/tests/helpers/html-generator-plugin.js @@ -45,12 +45,12 @@ module.exports = class HTMLGeneratorPlugin { const pluginName = 'html-generator-plugin'; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { - const { RawSource } = compiler.webpack.sources; + const { RawSource } = compiler.rspack.sources; compilation.hooks.processAssets.tap( { name: pluginName, - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, }, () => { const indexSource = new RawSource(HTMLContentForIndex); diff --git a/tests/helpers/trusted-types-html-generator-plugin.js b/tests/helpers/trusted-types-html-generator-plugin.js index 0a80580..54e121b 100644 --- a/tests/helpers/trusted-types-html-generator-plugin.js +++ b/tests/helpers/trusted-types-html-generator-plugin.js @@ -39,13 +39,13 @@ module.exports = class HTMLGeneratorPlugin { const pluginName = 'html-generator-plugin'; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { - if (compiler.webpack) { - const { RawSource } = compiler.webpack.sources; + if (compiler.rspack) { + const { RawSource } = compiler.rspack.sources; compilation.hooks.processAssets.tap( { name: pluginName, - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, }, () => { const indexSource = new RawSource(HTMLContentForIndex); From a18d876e0afcaf482ba38c42014a425b2d054112 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 28 Feb 2026 15:49:16 +0800 Subject: [PATCH 2/2] fix --- tests/e2e/hot-and-live-reload.test.js | 2 +- tests/e2e/setup-exit-signals.test.js | 2 +- tests/e2e/static-directory.test.js | 2 +- tests/e2e/static-public-path.test.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/e2e/hot-and-live-reload.test.js b/tests/e2e/hot-and-live-reload.test.js index 81a65b6..735fb77 100644 --- a/tests/e2e/hot-and-live-reload.test.js +++ b/tests/e2e/hot-and-live-reload.test.js @@ -713,7 +713,7 @@ describe('hot and live reload', () => { // loggerWarnSpy = rs.fn(); -// getInfrastructureLoggerSpy = rstest +// getInfrastructureLoggerSpy = rs // .spyOn(compiler, "getInfrastructureLogger") // .mockImplementation(() => { // return { diff --git a/tests/e2e/setup-exit-signals.test.js b/tests/e2e/setup-exit-signals.test.js index 96f15bd..71304b4 100644 --- a/tests/e2e/setup-exit-signals.test.js +++ b/tests/e2e/setup-exit-signals.test.js @@ -43,7 +43,7 @@ describe('setupExitSignals option', () => { doExit = true; }); - stdinResumeSpy = rstest + stdinResumeSpy = rs .spyOn(process.stdin, 'resume') .mockImplementation(() => {}); diff --git a/tests/e2e/static-directory.test.js b/tests/e2e/static-directory.test.js index e10bc3b..51aac34 100644 --- a/tests/e2e/static-directory.test.js +++ b/tests/e2e/static-directory.test.js @@ -609,7 +609,7 @@ describe('static.directory option', () => { let consoleMessages; beforeEach(async () => { - cwdSpy = rstest + cwdSpy = rs .spyOn(process, 'cwd') .mockImplementation(() => path.resolve(staticDirectory)); compiler = webpack(config); diff --git a/tests/e2e/static-public-path.test.js b/tests/e2e/static-public-path.test.js index 841ac87..6ba3612 100644 --- a/tests/e2e/static-public-path.test.js +++ b/tests/e2e/static-public-path.test.js @@ -485,7 +485,7 @@ describe('static.publicPath option', () => { let consoleMessages; beforeEach(async () => { - cwdSpy = rstest + cwdSpy = rs .spyOn(process, 'cwd') .mockImplementation(() => staticDirectory);