Skip to content

Commit 67e2a15

Browse files
committed
fix: handle undefined options in Server constructor
1 parent e90221c commit 67e2a15

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

lib/Server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,12 @@ const pluginName = "webpack-dev-server";
337337
*/
338338
class Server {
339339
/**
340-
* @param {Configuration<A, S>} options options
340+
* @param {Configuration<A, S> | undefined} options options
341341
* @param {(Compiler | MultiCompiler)=} compiler compiler, omitted when the server is used as a plugin via `apply()`
342342
*/
343343
constructor(options, compiler) {
344+
options ??= {};
345+
344346
validate(/** @type {Schema} */ (schema), options, {
345347
name: "Dev Server",
346348
baseDataPath: "options",

test/e2e/api.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ describe("API", () => {
7474
});
7575
});
7676

77+
describe("constructor options", () => {
78+
it("should default `undefined` options to `{}`", async () => {
79+
const compiler = webpack(config);
80+
const server = new Server(undefined, compiler);
81+
82+
expect(server.options).toEqual({});
83+
84+
await server.start();
85+
await server.stop();
86+
});
87+
});
88+
7789
describe("latest async API", () => {
7890
it("should work with async API", async (t) => {
7991
const compiler = webpack(config);

types/lib/Server.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,11 +1495,11 @@ declare class Server<
14951495
*/
14961496
private static isWebTarget;
14971497
/**
1498-
* @param {Configuration<A, S>} options options
1498+
* @param {Configuration<A, S> | undefined} options options
14991499
* @param {(Compiler | MultiCompiler)=} compiler compiler, omitted when the server is used as a plugin via `apply()`
15001500
*/
15011501
constructor(
1502-
options: Configuration<A, S>,
1502+
options: Configuration<A, S> | undefined,
15031503
compiler?: (Compiler | MultiCompiler) | undefined,
15041504
);
15051505
compiler:

0 commit comments

Comments
 (0)