MCPcopy
hub / github.com/webpack/webpack-dev-server / setup

Method setup

lib/Server.js:3525–3577  ·  view source on GitHub ↗

* @private * @returns {Promise }

()

Source from the content-addressed store, hash-verified

3523 * @returns {Promise<void>}
3524 */
3525 async setup() {
3526 await this.normalizeOptions();
3527
3528 if (this.options.ipc) {
3529 const { default: net } = await import("node:net");
3530
3531 await /** @type {Promise<void>} */ (
3532 new Promise((resolve, reject) => {
3533 const socket = new net.Socket();
3534
3535 socket.on(
3536 "error",
3537 /**
3538 * @param {Error & { code?: string }} error error
3539 */
3540 (error) => {
3541 if (error.code === "ECONNREFUSED") {
3542 // No other server listening on this socket, so it can be safely removed
3543 fs.unlinkSync(/** @type {string} */ (this.options.ipc));
3544
3545 resolve();
3546
3547 return;
3548 } else if (error.code === "ENOENT") {
3549 resolve();
3550
3551 return;
3552 }
3553
3554 reject(error);
3555 },
3556 );
3557
3558 socket.connect(
3559 { path: /** @type {string} */ (this.options.ipc) },
3560 () => {
3561 throw new Error(`IPC "${this.options.ipc}" is already used`);
3562 },
3563 );
3564 })
3565 );
3566 } else {
3567 this.options.host = await Server.getHostname(
3568 /** @type {Host} */ (this.options.host),
3569 );
3570 this.options.port = await Server.getFreePort(
3571 /** @type {Port} */ (this.options.port),
3572 this.options.host,
3573 );
3574 }
3575
3576 await this.initialize();
3577 }
3578
3579 /**
3580 * @private

Callers 2

startMethod · 0.95
ensureSetupMethod · 0.95

Calls 4

normalizeOptionsMethod · 0.95
initializeMethod · 0.95
getHostnameMethod · 0.80
getFreePortMethod · 0.80

Tested by

no test coverage detected