{"version":3,"file":"get-free-port.mjs","names":[],"sources":["../src/get-free-port.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createServer } from \"node:http\";\n\n/**\n * Finds and returns a free port on the local machine by creating a temporary server that listens on port 0. The operating system assigns an available port, which is then retrieved and returned.\n *\n * @returns A promise that resolves to a free port number.\n */\nexport async function getFreePort(): Promise<number> {\n  return new Promise((resolve, reject) => {\n    const server = createServer(() => {});\n    server.listen(0, () => {\n      const address = server.address();\n      server.close();\n\n      if (address && typeof address === \"object\") {\n        resolve(address.port);\n      } else {\n        reject(\n          new Error(`invalid address from server: ${address?.toString()}`)\n        );\n      }\n    });\n  });\n}\n"],"mappings":";;;;;;;;AAyBA,eAAsB,cAA+B;AACnD,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAS,mBAAmB,GAAG;AACrC,SAAO,OAAO,SAAS;GACrB,MAAM,UAAU,OAAO,SAAS;AAChC,UAAO,OAAO;AAEd,OAAI,WAAW,OAAO,YAAY,SAChC,SAAQ,QAAQ,KAAK;OAErB,wBACE,IAAI,MAAM,gCAAgC,SAAS,UAAU,GAAG,CACjE;IAEH;GACF"}