Skip to content

Commit bac3449

Browse files
committed
refactor!: remove deprecated listen and close methods (#4659)
1 parent 0340f59 commit bac3449

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
@@ -3356,95 +3356,6 @@ class Server {
33563356
.then(() => callback(), callback)
33573357
.catch(callback);
33583358
}
3359-
3360-
// TODO remove in the next major release
3361-
/**
3362-
* @param {Port} port
3363-
* @param {Host} hostname
3364-
* @param {(err?: Error) => void} fn
3365-
* @returns {void}
3366-
*/
3367-
listen(port, hostname, fn) {
3368-
util.deprecate(
3369-
() => {},
3370-
"'listen' is deprecated. Please use the async 'start' or 'startCallback' method.",
3371-
"DEP_WEBPACK_DEV_SERVER_LISTEN"
3372-
)();
3373-
3374-
if (typeof port === "function") {
3375-
fn = port;
3376-
}
3377-
3378-
if (
3379-
typeof port !== "undefined" &&
3380-
typeof this.options.port !== "undefined" &&
3381-
port !== this.options.port
3382-
) {
3383-
this.options.port = port;
3384-
3385-
this.logger.warn(
3386-
'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.'
3387-
);
3388-
}
3389-
3390-
if (!this.options.port) {
3391-
this.options.port = port;
3392-
}
3393-
3394-
if (
3395-
typeof hostname !== "undefined" &&
3396-
typeof this.options.host !== "undefined" &&
3397-
hostname !== this.options.host
3398-
) {
3399-
this.options.host = hostname;
3400-
3401-
this.logger.warn(
3402-
'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.'
3403-
);
3404-
}
3405-
3406-
if (!this.options.host) {
3407-
this.options.host = hostname;
3408-
}
3409-
3410-
this.start()
3411-
.then(() => {
3412-
if (fn) {
3413-
fn.call(this.server);
3414-
}
3415-
})
3416-
.catch((error) => {
3417-
// Nothing
3418-
if (fn) {
3419-
fn.call(this.server, error);
3420-
}
3421-
});
3422-
}
3423-
3424-
/**
3425-
* @param {(err?: Error) => void} [callback]
3426-
* @returns {void}
3427-
*/
3428-
// TODO remove in the next major release
3429-
close(callback) {
3430-
util.deprecate(
3431-
() => {},
3432-
"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method.",
3433-
"DEP_WEBPACK_DEV_SERVER_CLOSE"
3434-
)();
3435-
3436-
this.stop()
3437-
.then(() => {
3438-
if (callback) {
3439-
callback();
3440-
}
3441-
})
3442-
.catch((error) => {
3443-
if (callback) {
3444-
callback(error);
3445-
}
3446-
});
3447-
}
34483359
}
34493360

34503361
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
@@ -1970,18 +1970,6 @@ declare class Server {
19701970
* @param {(err?: Error) => void} [callback]
19711971
*/
19721972
stopCallback(callback?: ((err?: Error) => void) | undefined): void;
1973-
/**
1974-
* @param {Port} port
1975-
* @param {Host} hostname
1976-
* @param {(err?: Error) => void} fn
1977-
* @returns {void}
1978-
*/
1979-
listen(port: Port, hostname: Host, fn: (err?: Error) => void): void;
1980-
/**
1981-
* @param {(err?: Error) => void} [callback]
1982-
* @returns {void}
1983-
*/
1984-
close(callback?: ((err?: Error) => void) | undefined): void;
19851973
}
19861974
declare namespace Server {
19871975
export {
@@ -2120,8 +2108,8 @@ type ClientConnection = (
21202108
) & {
21212109
isAlive?: boolean;
21222110
};
2123-
type Port = number | string | "auto";
21242111
type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string;
2112+
type Port = number | string | "auto";
21252113
type MultiCompiler = import("webpack").MultiCompiler;
21262114
declare class DEFAULT_STATS {
21272115
private constructor();

0 commit comments

Comments
 (0)