Skip to content

Commit eca342d

Browse files
snitin315alexander-akait
authored andcommitted
refactor!: remove deprecated listen and close methods (#4659)
1 parent 07dea78 commit eca342d

File tree

4 files changed

+1
-252
lines changed

4 files changed

+1
-252
lines changed

lib/Server.js

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,95 +3423,6 @@ class Server {
34233423
.then(() => callback(), callback)
34243424
.catch(callback);
34253425
}
3426-
3427-
// TODO remove in the next major release
3428-
/**
3429-
* @param {Port} port
3430-
* @param {Host} hostname
3431-
* @param {(err?: Error) => void} fn
3432-
* @returns {void}
3433-
*/
3434-
listen(port, hostname, fn) {
3435-
util.deprecate(
3436-
() => {},
3437-
"'listen' is deprecated. Please use the async 'start' or 'startCallback' method.",
3438-
"DEP_WEBPACK_DEV_SERVER_LISTEN"
3439-
)();
3440-
3441-
if (typeof port === "function") {
3442-
fn = port;
3443-
}
3444-
3445-
if (
3446-
typeof port !== "undefined" &&
3447-
typeof this.options.port !== "undefined" &&
3448-
port !== this.options.port
3449-
) {
3450-
this.options.port = port;
3451-
3452-
this.logger.warn(
3453-
'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.'
3454-
);
3455-
}
3456-
3457-
if (!this.options.port) {
3458-
this.options.port = port;
3459-
}
3460-
3461-
if (
3462-
typeof hostname !== "undefined" &&
3463-
typeof this.options.host !== "undefined" &&
3464-
hostname !== this.options.host
3465-
) {
3466-
this.options.host = hostname;
3467-
3468-
this.logger.warn(
3469-
'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.'
3470-
);
3471-
}
3472-
3473-
if (!this.options.host) {
3474-
this.options.host = hostname;
3475-
}
3476-
3477-
this.start()
3478-
.then(() => {
3479-
if (fn) {
3480-
fn.call(this.server);
3481-
}
3482-
})
3483-
.catch((error) => {
3484-
// Nothing
3485-
if (fn) {
3486-
fn.call(this.server, error);
3487-
}
3488-
});
3489-
}
3490-
3491-
/**
3492-
* @param {(err?: Error) => void} [callback]
3493-
* @returns {void}
3494-
*/
3495-
// TODO remove in the next major release
3496-
close(callback) {
3497-
util.deprecate(
3498-
() => {},
3499-
"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method.",
3500-
"DEP_WEBPACK_DEV_SERVER_CLOSE"
3501-
)();
3502-
3503-
this.stop()
3504-
.then(() => {
3505-
if (callback) {
3506-
callback();
3507-
}
3508-
})
3509-
.catch((error) => {
3510-
if (callback) {
3511-
callback(error);
3512-
}
3513-
});
3514-
}
35153426
}
35163427

35173428
module.exports = Server;

test/e2e/__snapshots__/api.test.js.snap.webpack5

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,6 @@ exports[`API WEBPACK_SERVE environment variable should be present: page errors 1
116116

117117
exports[`API WEBPACK_SERVE environment variable should be present: response status 1`] = `200`;
118118

119-
exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): console messages 1`] = `
120-
Array [
121-
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
122-
"[HMR] Waiting for update signal from WDS...",
123-
"Hey.",
124-
]
125-
`;
126-
127-
exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): page errors 1`] = `Array []`;
128-
129-
exports[`API deprecated API should work with deprecated API ('listen' and 'close' methods): close deprecation log 1`] = `"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method."`;
130-
131-
exports[`API deprecated API should work with deprecated API ('listen' and 'close' methods): console messages 1`] = `
132-
Array [
133-
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
134-
"[HMR] Waiting for update signal from WDS...",
135-
"Hey.",
136-
]
137-
`;
138-
139-
exports[`API deprecated API should work with deprecated API ('listen' and 'close' methods): listen deprecation log 1`] = `"'listen' is deprecated. Please use the async 'start' or 'startCallback' method."`;
140-
141-
exports[`API deprecated API should work with deprecated API ('listen' and 'close' methods): page errors 1`] = `Array []`;
142-
143119
exports[`API deprecated API should work with deprecated API (only compiler in constructor): console messages 1`] = `
144120
Array [
145121
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",

test/e2e/api.test.js

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -269,132 +269,6 @@ describe("API", () => {
269269
});
270270

271271
describe("deprecated API", () => {
272-
it("should work with deprecated API ('listen' and 'close' methods)", async () => {
273-
const compiler = webpack(config);
274-
const devServerOptions = { port };
275-
const utilSpy = jest.spyOn(util, "deprecate");
276-
const server = new Server(devServerOptions, compiler);
277-
278-
await new Promise((resolve, reject) => {
279-
server.listen(devServerOptions.port, devServerOptions.host, (error) => {
280-
if (error) {
281-
reject(error);
282-
283-
return;
284-
}
285-
286-
resolve();
287-
});
288-
});
289-
290-
const { page, browser } = await runBrowser();
291-
292-
const pageErrors = [];
293-
const consoleMessages = [];
294-
295-
page
296-
.on("console", (message) => {
297-
consoleMessages.push(message);
298-
})
299-
.on("pageerror", (error) => {
300-
pageErrors.push(error);
301-
});
302-
303-
await page.goto(`http://127.0.0.1:${port}/`, {
304-
waitUntil: "networkidle0",
305-
});
306-
307-
expect(utilSpy.mock.calls[0][1]).toMatchSnapshot(
308-
"listen deprecation log"
309-
);
310-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
311-
"console messages"
312-
);
313-
expect(pageErrors).toMatchSnapshot("page errors");
314-
315-
await browser.close();
316-
await new Promise((resolve) => {
317-
server.close(() => {
318-
resolve();
319-
});
320-
});
321-
322-
expect(
323-
utilSpy.mock.calls[utilSpy.mock.calls.length - 1][1]
324-
).toMatchSnapshot("close deprecation log");
325-
326-
utilSpy.mockRestore();
327-
});
328-
329-
it(`should log warning when the "port" and "host" options from options different from arguments ('listen' method)`, async () => {
330-
const compiler = webpack(config);
331-
const devServerOptions = { port: 9999, host: "127.0.0.2" };
332-
const warnSpy = jest.fn();
333-
const getInfrastructureLoggerSpy = jest
334-
.spyOn(compiler, "getInfrastructureLogger")
335-
.mockImplementation(() => {
336-
return {
337-
warn: warnSpy,
338-
info: () => {},
339-
log: () => {},
340-
};
341-
});
342-
const server = new Server(devServerOptions, compiler);
343-
344-
await new Promise((resolve, reject) => {
345-
server.listen(port, "127.0.0.1", (error) => {
346-
if (error) {
347-
reject(error);
348-
349-
return;
350-
}
351-
352-
resolve();
353-
});
354-
});
355-
356-
const { page, browser } = await runBrowser();
357-
358-
const pageErrors = [];
359-
const consoleMessages = [];
360-
361-
page
362-
.on("console", (message) => {
363-
consoleMessages.push(message);
364-
})
365-
.on("pageerror", (error) => {
366-
pageErrors.push(error);
367-
});
368-
369-
await page.goto(`http://127.0.0.1:${port}/`, {
370-
waitUntil: "networkidle0",
371-
});
372-
373-
expect(warnSpy).toHaveBeenNthCalledWith(
374-
1,
375-
'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.'
376-
);
377-
expect(warnSpy).toHaveBeenNthCalledWith(
378-
2,
379-
'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.'
380-
);
381-
382-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
383-
"console messages"
384-
);
385-
expect(pageErrors).toMatchSnapshot("page errors");
386-
387-
warnSpy.mockRestore();
388-
getInfrastructureLoggerSpy.mockRestore();
389-
390-
await browser.close();
391-
await new Promise((resolve) => {
392-
server.close(() => {
393-
resolve();
394-
});
395-
});
396-
});
397-
398272
it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => {
399273
const compiler = webpack(config);
400274
const devServerOptions = { port };

types/lib/Server.d.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,18 +3535,6 @@ declare class Server {
35353535
* @param {(err?: Error) => void} [callback]
35363536
*/
35373537
stopCallback(callback?: ((err?: Error) => void) | undefined): void;
3538-
/**
3539-
* @param {Port} port
3540-
* @param {Host} hostname
3541-
* @param {(err?: Error) => void} fn
3542-
* @returns {void}
3543-
*/
3544-
listen(port: Port, hostname: Host, fn: (err?: Error) => void): void;
3545-
/**
3546-
* @param {(err?: Error) => void} [callback]
3547-
* @returns {void}
3548-
*/
3549-
close(callback?: ((err?: Error) => void) | undefined): void;
35503538
}
35513539
declare namespace Server {
35523540
export {
@@ -3685,8 +3673,8 @@ type ClientConnection = (
36853673
) & {
36863674
isAlive?: boolean;
36873675
};
3688-
type Port = number | string | "auto";
36893676
type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string;
3677+
type Port = number | string | "auto";
36903678
type MultiCompiler = import("webpack").MultiCompiler;
36913679
declare class DEFAULT_STATS {
36923680
private constructor();

0 commit comments

Comments
 (0)