Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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[],
Expand All @@ -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) {
Expand All @@ -1542,7 +1539,7 @@ class Server<
);
} else {
// Apply the HMR plugin
const plugin = new webpack.HotModuleReplacementPlugin();
const plugin = new HotModuleReplacementPlugin();

plugin.apply(compiler);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('API', () => {

beforeEach(async () => {
// this is important - it clears the cache
rstest.resetModules();
rs.resetModules();

process.env = { ...OLD_ENV };

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/history-api-fallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/hot-and-live-reload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ describe('hot and live reload', () => {
// plugins: [...config.plugins, new webpack.HotModuleReplacementPlugin()],
// });

// loggerWarnSpy = rstest.fn();
// loggerWarnSpy = rs.fn();

// getInfrastructureLoggerSpy = rstest
// getInfrastructureLoggerSpy = rs
// .spyOn(compiler, "getInfrastructureLogger")
// .mockImplementation(() => {
// return {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/overlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
28 changes: 14 additions & 14 deletions tests/e2e/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
{
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/setup-exit-signals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ describe('setupExitSignals option', () => {
consoleMessages = [];
doExit = false;

exitSpy = rstest.spyOn(process, 'exit').mockImplementation(() => {
exitSpy = rs.spyOn(process, 'exit').mockImplementation(() => {
doExit = true;
});

stdinResumeSpy = rstest
stdinResumeSpy = rs
.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');
}
});

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/static-directory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/static-public-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ describe('static.publicPath option', () => {
let consoleMessages;

beforeEach(async () => {
cwdSpy = rstest
cwdSpy = rs
.spyOn(process, 'cwd')
.mockImplementation(() => staticDirectory);

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/watch-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/web-socket-communication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/html-generator-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/trusted-types-html-generator-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down