Skip to content

Commit 77dbd49

Browse files
fix: rebase
1 parent 6d5ce11 commit 77dbd49

File tree

1 file changed

+71
-137
lines changed

1 file changed

+71
-137
lines changed

lib/Server.js

Lines changed: 71 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,17 @@ class Server {
742742
this.app = new express();
743743
}
744744

745+
getStats(statsObj) {
746+
const stats = Server.DEFAULT_STATS;
747+
const compilerOptions = this.getCompilerOptions();
748+
749+
if (compilerOptions.stats && compilerOptions.stats.warningsFilter) {
750+
stats.warningsFilter = compilerOptions.stats.warningsFilter;
751+
}
752+
753+
return statsObj.toJson(stats);
754+
}
755+
745756
setupHooks() {
746757
const addHooks = (compiler) => {
747758
compiler.hooks.invalid.tap("webpack-dev-server", () => {
@@ -1455,143 +1466,6 @@ class Server {
14551466
}
14561467
}
14571468

1458-
listen(port, hostname, fn) {
1459-
this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server");
1460-
this.normalizeOptions(this.options);
1461-
1462-
if (typeof port === "function") {
1463-
fn = port;
1464-
}
1465-
1466-
if (
1467-
typeof port !== "undefined" &&
1468-
typeof this.options.port !== "undefined" &&
1469-
port !== this.options.port
1470-
) {
1471-
this.options.port = port;
1472-
1473-
this.logger.warn(
1474-
'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.'
1475-
);
1476-
}
1477-
1478-
if (!this.options.port) {
1479-
this.options.port = port;
1480-
}
1481-
1482-
if (
1483-
typeof hostname !== "undefined" &&
1484-
typeof this.options.host !== "undefined" &&
1485-
hostname !== this.options.host
1486-
) {
1487-
this.options.host = hostname;
1488-
1489-
this.logger.warn(
1490-
'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.'
1491-
);
1492-
}
1493-
1494-
if (!this.options.host) {
1495-
this.options.host = hostname;
1496-
}
1497-
1498-
this.options.host = Server.getHostname(this.options.host);
1499-
1500-
const resolveFreePortOrIPC = () => {
1501-
if (this.options.ipc) {
1502-
return new Promise((resolve, reject) => {
1503-
const net = require("net");
1504-
const socket = new net.Socket();
1505-
1506-
socket.on("error", (error) => {
1507-
if (error.code === "ECONNREFUSED") {
1508-
fs.unlinkSync(this.options.ipc);
1509-
1510-
resolve(this.options.ipc);
1511-
1512-
return;
1513-
} else if (error.code === "ENOENT") {
1514-
resolve(this.options.ipc);
1515-
1516-
return;
1517-
}
1518-
1519-
reject(error);
1520-
});
1521-
1522-
socket.connect({ path: this.options.ipc }, () => {
1523-
throw new Error(`IPC "${this.options.ipc}" is already used`);
1524-
});
1525-
});
1526-
}
1527-
1528-
return Server.getFreePort(this.options.port).then((foundPort) => {
1529-
this.options.port = foundPort;
1530-
});
1531-
};
1532-
1533-
return resolveFreePortOrIPC()
1534-
.then(() => {
1535-
this.initialize();
1536-
1537-
const listenOptions = this.options.ipc
1538-
? { path: this.options.ipc }
1539-
: {
1540-
host: this.options.host,
1541-
port: this.options.port,
1542-
};
1543-
1544-
return this.server.listen(listenOptions, (error) => {
1545-
if (this.options.ipc) {
1546-
// chmod 666 (rw rw rw)
1547-
const READ_WRITE = 438;
1548-
1549-
fs.chmodSync(this.options.ipc, READ_WRITE);
1550-
}
1551-
1552-
if (this.options.webSocketServer) {
1553-
try {
1554-
this.createWebSocketServer();
1555-
} catch (webSocketServerError) {
1556-
fn.call(this.server, webSocketServerError);
1557-
1558-
return;
1559-
}
1560-
}
1561-
1562-
if (this.options.bonjour) {
1563-
this.runBonjour();
1564-
}
1565-
1566-
this.logStatus();
1567-
1568-
if (fn) {
1569-
fn.call(this.server, error);
1570-
}
1571-
1572-
if (typeof this.options.onListening === "function") {
1573-
this.options.onListening(this);
1574-
}
1575-
});
1576-
})
1577-
.catch((error) => {
1578-
if (fn) {
1579-
fn.call(this.server, error);
1580-
}
1581-
});
1582-
}
1583-
1584-
getStats(statsObj) {
1585-
const stats = Server.DEFAULT_STATS;
1586-
const compilerOptions = this.getCompilerOptions();
1587-
1588-
if (compilerOptions.stats && compilerOptions.stats.warningsFilter) {
1589-
stats.warningsFilter = compilerOptions.stats.warningsFilter;
1590-
}
1591-
1592-
return statsObj.toJson(stats);
1593-
}
1594-
15951469
setHeaders(req, res, next) {
15961470
let { headers } = this.options;
15971471

@@ -1920,6 +1794,66 @@ class Server {
19201794
this.stop().then(() => callback(null), callback);
19211795
}
19221796

1797+
// TODO remove in the next major release
1798+
listen(port, hostname, fn) {
1799+
util.deprecate(
1800+
() => {},
1801+
"'listen' is deprecated. Please use async 'start' or 'startCallback' methods.",
1802+
"DEP_WEBPACK_DEV_SERVER_LISTEN"
1803+
)();
1804+
1805+
this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server");
1806+
1807+
if (typeof port === "function") {
1808+
fn = port;
1809+
}
1810+
1811+
if (
1812+
typeof port !== "undefined" &&
1813+
typeof this.options.port !== "undefined" &&
1814+
port !== this.options.port
1815+
) {
1816+
this.options.port = port;
1817+
1818+
this.logger.warn(
1819+
'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.'
1820+
);
1821+
}
1822+
1823+
if (!this.options.port) {
1824+
this.options.port = port;
1825+
}
1826+
1827+
if (
1828+
typeof hostname !== "undefined" &&
1829+
typeof this.options.host !== "undefined" &&
1830+
hostname !== this.options.host
1831+
) {
1832+
this.options.host = hostname;
1833+
1834+
this.logger.warn(
1835+
'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.'
1836+
);
1837+
}
1838+
1839+
if (!this.options.host) {
1840+
this.options.host = hostname;
1841+
}
1842+
1843+
return this.start()
1844+
.then(() => {
1845+
if (fn) {
1846+
fn.call(this.server);
1847+
}
1848+
})
1849+
.catch((error) => {
1850+
// Nothing
1851+
if (fn) {
1852+
fn.call(this.server, error);
1853+
}
1854+
});
1855+
}
1856+
19231857
// TODO remove in the next major release
19241858
close(callback) {
19251859
util.deprecate(

0 commit comments

Comments
 (0)