diff --git a/lib/Server.js b/lib/Server.js index 3025171f75..2e28a7e13d 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -3,6 +3,7 @@ const os = require("os"); const path = require("path"); const url = require("url"); +const util = require("util"); const fs = require("graceful-fs"); const ipaddr = require("ipaddr.js"); const internalIp = require("internal-ip"); @@ -18,7 +19,16 @@ if (!process.env.WEBPACK_SERVE) { class Server { constructor(options = {}, compiler) { // TODO: remove this after plugin support is published + if (options.hooks) { + const showDeprecationWarning = util.deprecate( + () => {}, + "Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument.", + "DEP_WEBPACK_DEV_SERVER_API" + ); + + showDeprecationWarning(); + [options, compiler] = [compiler, options]; } diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 7857f25882..1839480394 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -91,10 +91,17 @@ describe("Server", () => { }); // TODO: remove this after plugin support is published - it("should create and run server with old parameters order", (done) => { + it("should create and run server with old parameters order and log deprecation warning", (done) => { const compiler = webpack(config); + const util = require("util"); + const utilSpy = jest.spyOn(util, "deprecate"); + const server = new Server(compiler, baseDevConfig); + expect(utilSpy.mock.calls[0][1]).toBe( + "Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument." + ); + compiler.hooks.done.tap("webpack-dev-server", () => { expect(entries).toMatchSnapshot("oldparam"); @@ -108,6 +115,8 @@ describe("Server", () => { getEntries(server); }); + + utilSpy.mockRestore(); }); }); @@ -772,7 +781,7 @@ describe("Server", () => { port: "9999", }; - server = new Server(compiler, options); + server = new Server(options, compiler); const warnSpy = jest.fn(); diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index 3f770b4292..5a6534675f 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -36,7 +36,7 @@ Array [ ] `; -exports[`Server DevServerPlugin should create and run server with old parameters order: oldparam 1`] = ` +exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` Array [ Array [ "client", diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index 3f770b4292..5a6534675f 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -36,7 +36,7 @@ Array [ ] `; -exports[`Server DevServerPlugin should create and run server with old parameters order: oldparam 1`] = ` +exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` Array [ Array [ "client",