Skip to content

Commit 9e10845

Browse files
authored
fix: removed require webpack (#89)
1 parent 1a67898 commit 9e10845

16 files changed

Lines changed: 46 additions & 49 deletions

src/server.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,9 @@ class Server<
577577
additionalEntries.push(clientHotEntry);
578578
}
579579

580-
const webpack = compiler.webpack || require('webpack');
581-
582580
// use a hook to add entries if available
583581
for (const additionalEntry of additionalEntries) {
584-
new webpack.EntryPlugin(compiler.context, additionalEntry, {
582+
new compiler.rspack.EntryPlugin(compiler.context, additionalEntry, {
585583
name: undefined,
586584
}).apply(compiler);
587585
}
@@ -1521,9 +1519,9 @@ class Server<
15211519

15221520
this.addAdditionalEntries(compiler);
15231521

1524-
const webpack = compiler.webpack || require('webpack');
1522+
const { ProvidePlugin, HotModuleReplacementPlugin } = compiler.rspack;
15251523

1526-
new webpack.ProvidePlugin({
1524+
new ProvidePlugin({
15271525
__webpack_dev_server_client__: this.getClientTransport() as
15281526
| string
15291527
| string[],
@@ -1532,8 +1530,7 @@ class Server<
15321530
if (this.options.hot) {
15331531
const HMRPluginExists = compiler.options.plugins.find(
15341532
(plugin) =>
1535-
plugin &&
1536-
plugin.constructor === webpack.HotModuleReplacementPlugin,
1533+
plugin && plugin.constructor === HotModuleReplacementPlugin,
15371534
);
15381535

15391536
if (HMRPluginExists) {
@@ -1542,7 +1539,7 @@ class Server<
15421539
);
15431540
} else {
15441541
// Apply the HMR plugin
1545-
const plugin = new webpack.HotModuleReplacementPlugin();
1542+
const plugin = new HotModuleReplacementPlugin();
15461543

15471544
plugin.apply(compiler);
15481545
}

tests/e2e/api.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('API', () => {
1717

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

2222
process.env = { ...OLD_ENV };
2323

@@ -307,7 +307,7 @@ describe('API', () => {
307307
});
308308

309309
it('should use the default `noop` callback when invalidate is called without any callback', async () => {
310-
const callback = rstest.fn();
310+
const callback = rs.fn();
311311

312312
server.invalidate();
313313
server.middleware.context.callbacks[0] = callback;
@@ -326,7 +326,7 @@ describe('API', () => {
326326
});
327327

328328
it('should use the provided `callback` function', async () => {
329-
const callback = rstest.fn();
329+
const callback = rs.fn();
330330

331331
server.invalidate(callback);
332332

tests/e2e/history-api-fallback.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ describe('historyApiFallback option', () => {
436436
let consoleSpy;
437437

438438
beforeEach(async () => {
439-
consoleSpy = rstest.spyOn(global.console, 'log');
439+
consoleSpy = rs.spyOn(global.console, 'log');
440440

441441
compiler = webpack(config);
442442

@@ -512,7 +512,7 @@ describe('historyApiFallback option', () => {
512512
let consoleSpy;
513513

514514
beforeEach(async () => {
515-
consoleSpy = rstest.spyOn(global.console, 'log');
515+
consoleSpy = rs.spyOn(global.console, 'log');
516516

517517
compiler = webpack(config);
518518

tests/e2e/hot-and-live-reload.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,9 @@ describe('hot and live reload', () => {
711711
// plugins: [...config.plugins, new webpack.HotModuleReplacementPlugin()],
712712
// });
713713

714-
// loggerWarnSpy = rstest.fn();
714+
// loggerWarnSpy = rs.fn();
715715

716-
// getInfrastructureLoggerSpy = rstest
716+
// getInfrastructureLoggerSpy = rs
717717
// .spyOn(compiler, "getInfrastructureLogger")
718718
// .mockImplementation(() => {
719719
// return {

tests/e2e/overlay.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ let prettierHTML;
6969
let prettierCSS;
7070

7171
describe('overlay', () => {
72-
const mockLaunchEditorCb = rstest.fn();
72+
const mockLaunchEditorCb = rs.fn();
7373
rs.doMockRequire('launch-editor', () => mockLaunchEditorCb);
7474

7575
beforeAll(async () => {

tests/e2e/server.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ describe('server option', () => {
285285
beforeEach(async () => {
286286
compiler = webpack(config);
287287

288-
createServerSpy = rstest.spyOn(https, 'createServer');
288+
createServerSpy = rs.spyOn(https, 'createServer');
289289

290290
server = new Server(
291291
{
@@ -368,7 +368,7 @@ describe('server option', () => {
368368
beforeEach(async () => {
369369
compiler = webpack(config);
370370

371-
createServerSpy = rstest.spyOn(https, 'createServer');
371+
createServerSpy = rs.spyOn(https, 'createServer');
372372

373373
server = new Server(
374374
{
@@ -459,7 +459,7 @@ describe('server option', () => {
459459
beforeEach(async () => {
460460
compiler = webpack(config);
461461

462-
createServerSpy = rstest.spyOn(https, 'createServer');
462+
createServerSpy = rs.spyOn(https, 'createServer');
463463

464464
server = new Server(
465465
{
@@ -548,7 +548,7 @@ describe('server option', () => {
548548
beforeEach(async () => {
549549
compiler = webpack(config);
550550

551-
createServerSpy = rstest.spyOn(https, 'createServer');
551+
createServerSpy = rs.spyOn(https, 'createServer');
552552

553553
server = new Server(
554554
{
@@ -646,7 +646,7 @@ describe('server option', () => {
646646
beforeEach(async () => {
647647
compiler = webpack(config);
648648

649-
createServerSpy = rstest.spyOn(https, 'createServer');
649+
createServerSpy = rs.spyOn(https, 'createServer');
650650

651651
server = new Server(
652652
{
@@ -721,7 +721,7 @@ describe('server option', () => {
721721
beforeEach(async () => {
722722
compiler = webpack(config);
723723

724-
createServerSpy = rstest.spyOn(https, 'createServer');
724+
createServerSpy = rs.spyOn(https, 'createServer');
725725

726726
server = new Server(
727727
{
@@ -800,7 +800,7 @@ describe('server option', () => {
800800
beforeEach(async () => {
801801
compiler = webpack(config);
802802

803-
createServerSpy = rstest.spyOn(https, 'createServer');
803+
createServerSpy = rs.spyOn(https, 'createServer');
804804

805805
server = new Server(
806806
{
@@ -873,7 +873,7 @@ describe('server option', () => {
873873
beforeEach(async () => {
874874
compiler = webpack(config);
875875

876-
createServerSpy = rstest.spyOn(https, 'createServer');
876+
createServerSpy = rs.spyOn(https, 'createServer');
877877

878878
server = new Server(
879879
{
@@ -956,7 +956,7 @@ describe('server option', () => {
956956
beforeEach(async () => {
957957
compiler = webpack(config);
958958

959-
createServerSpy = rstest.spyOn(https, 'createServer');
959+
createServerSpy = rs.spyOn(https, 'createServer');
960960

961961
server = new Server(
962962
{
@@ -1047,7 +1047,7 @@ describe('server option', () => {
10471047
beforeEach(async () => {
10481048
compiler = webpack(config);
10491049

1050-
createServerSpy = rstest.spyOn(https, 'createServer');
1050+
createServerSpy = rs.spyOn(https, 'createServer');
10511051

10521052
server = new Server(
10531053
{
@@ -1143,7 +1143,7 @@ describe('server option', () => {
11431143
beforeEach(async () => {
11441144
compiler = webpack(config);
11451145

1146-
createServerSpy = rstest.spyOn(https, 'createServer');
1146+
createServerSpy = rs.spyOn(https, 'createServer');
11471147

11481148
server = new Server(
11491149
{
@@ -1225,7 +1225,7 @@ describe('server option', () => {
12251225
beforeEach(async () => {
12261226
compiler = webpack(config);
12271227

1228-
createServerSpy = rstest.spyOn(https, 'createServer');
1228+
createServerSpy = rs.spyOn(https, 'createServer');
12291229

12301230
server = new Server(
12311231
{
@@ -1291,7 +1291,7 @@ describe('server option', () => {
12911291
beforeEach(async () => {
12921292
compiler = webpack(config);
12931293

1294-
createServerSpy = rstest.spyOn(spdy, 'createServer');
1294+
createServerSpy = rs.spyOn(spdy, 'createServer');
12951295

12961296
server = new Server(
12971297
{
@@ -1372,7 +1372,7 @@ describe('server option', () => {
13721372
beforeEach(async () => {
13731373
compiler = webpack(config);
13741374

1375-
createServerSpy = rstest.spyOn(customHTTP, 'createServer');
1375+
createServerSpy = rs.spyOn(customHTTP, 'createServer');
13761376

13771377
server = new Server(
13781378
{

tests/e2e/setup-exit-signals.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ describe('setupExitSignals option', () => {
3939
consoleMessages = [];
4040
doExit = false;
4141

42-
exitSpy = rstest.spyOn(process, 'exit').mockImplementation(() => {
42+
exitSpy = rs.spyOn(process, 'exit').mockImplementation(() => {
4343
doExit = true;
4444
});
4545

46-
stdinResumeSpy = rstest
46+
stdinResumeSpy = rs
4747
.spyOn(process.stdin, 'resume')
4848
.mockImplementation(() => {});
4949

50-
stopCallbackSpy = rstest.spyOn(server, 'stopCallback');
50+
stopCallbackSpy = rs.spyOn(server, 'stopCallback');
5151

5252
if (server.compiler.close) {
53-
closeCallbackSpy = rstest.spyOn(server.compiler, 'close');
53+
closeCallbackSpy = rs.spyOn(server.compiler, 'close');
5454
}
5555
});
5656

tests/e2e/static-directory.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ describe('static.directory option', () => {
609609
let consoleMessages;
610610

611611
beforeEach(async () => {
612-
cwdSpy = rstest
612+
cwdSpy = rs
613613
.spyOn(process, 'cwd')
614614
.mockImplementation(() => path.resolve(staticDirectory));
615615
compiler = webpack(config);
@@ -673,7 +673,7 @@ describe('static.directory option', () => {
673673
beforeEach(async () => {
674674
// This is a somewhat weird test, but it is important that we mock
675675
// the PWD here, and test if /other.html in our "fake" PWD really is not requested.
676-
rstest.spyOn(process, 'cwd').mockImplementation(() => publicDirectory);
676+
rs.spyOn(process, 'cwd').mockImplementation(() => publicDirectory);
677677

678678
compiler = webpack(config);
679679

tests/e2e/static-public-path.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ describe('static.publicPath option', () => {
485485
let consoleMessages;
486486

487487
beforeEach(async () => {
488-
cwdSpy = rstest
488+
cwdSpy = rs
489489
.spyOn(process, 'cwd')
490490
.mockImplementation(() => staticDirectory);
491491

tests/e2e/stats.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const HTMLGeneratorPlugin = require('../helpers/html-generator-plugin');
55
const runBrowser = require('../helpers/run-browser');
66
const port = require('../helpers/ports-map').stats;
77

8-
global.console.log = rstest.fn();
8+
global.console.log = rs.fn();
99

1010
describe('stats', () => {
1111
const cases = [

0 commit comments

Comments
 (0)