@postxl/utils 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,14 +2,22 @@ import { CapitalizedKeys, ColorFn, CompareFn, Conjugated, Debrand, DeepPartial,
2
2
 
3
3
  //#region src/check-port.d.ts
4
4
  /**
5
- * Checks if a port is available.
5
+ * Checks if a port is available by attempting to bind to it.
6
+ *
7
+ * This approach avoids outbound TCP connect timeouts that can occur with
8
+ * mirrored WSL networking, where connection attempts may hang for extended
9
+ * periods before timing out.
6
10
  *
7
11
  * The `net` module from Node.js is imported dynamically so that bundlers used in
8
12
  * browser environments (like Next.js) don't attempt to include it during
9
13
  * static analysis.
10
14
  */
11
15
  /**
12
- * Checks if a port is available.
16
+ * Checks if a port is available by attempting to bind to it.
17
+ *
18
+ * This approach avoids outbound TCP connect timeouts that can occur with
19
+ * mirrored WSL networking, where connection attempts may hang for extended
20
+ * periods before timing out.
13
21
  *
14
22
  * The `net` module from Node.js is imported dynamically so that bundlers used in
15
23
  * browser environments (like Next.js) don't attempt to include it during
package/dist/index.js CHANGED
@@ -2,28 +2,37 @@ import { DefaultMap, ExhaustiveSwitchCheck, NestedMap, Result, TypedMapping, add
2
2
 
3
3
  //#region src/check-port.ts
4
4
  /**
5
- * Checks if a port is available.
5
+ * Checks if a port is available by attempting to bind to it.
6
+ *
7
+ * This approach avoids outbound TCP connect timeouts that can occur with
8
+ * mirrored WSL networking, where connection attempts may hang for extended
9
+ * periods before timing out.
6
10
  *
7
11
  * The `net` module from Node.js is imported dynamically so that bundlers used in
8
12
  * browser environments (like Next.js) don't attempt to include it during
9
13
  * static analysis.
10
14
  */
11
- async function checkPortAvailability(port, host = "127.0.0.1") {
15
+ async function checkPortAvailability(port, host = "0.0.0.0") {
12
16
  try {
13
17
  const net = await import("net");
14
18
  return new Promise((resolve) => {
15
- const tester = net.createConnection({
16
- port,
17
- host
18
- }, () => {
19
- tester.destroy();
20
- resolve(false);
19
+ const server = net.createServer();
20
+ let settled = false;
21
+ const finish = (available) => {
22
+ if (settled) return;
23
+ settled = true;
24
+ resolve(available);
25
+ };
26
+ server.once("error", () => {
27
+ finish(false);
21
28
  });
22
- tester.on("error", () => {
23
- resolve(true);
29
+ server.once("listening", () => {
30
+ server.close(() => finish(true));
24
31
  });
25
- tester.on("close", () => {
26
- resolve(false);
32
+ server.listen({
33
+ port,
34
+ host,
35
+ exclusive: true
27
36
  });
28
37
  });
29
38
  } catch {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["port: number"],"sources":["../src/check-port.ts"],"sourcesContent":["/**\n * Checks if a port is available.\n *\n * The `net` module from Node.js is imported dynamically so that bundlers used in\n * browser environments (like Next.js) don't attempt to include it during\n * static analysis.\n */\nexport async function checkPortAvailability(port: number, host = '127.0.0.1'): Promise<boolean> {\n // Dynamically import `net` only when this function is executed in a Node.js\n // environment. This prevents tools like Next.js from trying to bundle the\n // `net` module when other utilities from this package are imported in the\n // browser.\n try {\n const net = await import('net')\n\n return new Promise((resolve) => {\n const tester = net.createConnection({ port, host }, () => {\n // Port can be connected to, so something is listening on it\n tester.destroy()\n resolve(false)\n })\n // Port cannot be connected to, so it is available\n tester.on('error', () => {\n resolve(true)\n })\n // Port is available\n tester.on('close', () => {\n resolve(false)\n })\n })\n } catch {\n throw new Error('checkPortAvailability is only available in a Node.js environment')\n }\n}\n\n// Backwards compatibility alias\nexport const checkPort = checkPortAvailability\n"],"mappings":";;;;;;;;;;AAOA,eAAsB,sBAAsBA,MAAc,OAAO,aAA+B;AAK9F,KAAI;EACF,MAAM,MAAM,MAAM,OAAO;AAEzB,SAAO,IAAI,QAAQ,CAAC,YAAY;GAC9B,MAAM,SAAS,IAAI,iBAAiB;IAAE;IAAM;GAAM,GAAE,MAAM;AAExD,WAAO,SAAS;AAChB,YAAQ,MAAM;GACf,EAAC;AAEF,UAAO,GAAG,SAAS,MAAM;AACvB,YAAQ,KAAK;GACd,EAAC;AAEF,UAAO,GAAG,SAAS,MAAM;AACvB,YAAQ,MAAM;GACf,EAAC;EACH;CACF,QAAO;AACN,QAAM,IAAI,MAAM;CACjB;AACF;AAGD,MAAa,YAAY"}
1
+ {"version":3,"file":"index.js","names":["port: number","available: boolean"],"sources":["../src/check-port.ts"],"sourcesContent":["/**\n * Checks if a port is available by attempting to bind to it.\n *\n * This approach avoids outbound TCP connect timeouts that can occur with\n * mirrored WSL networking, where connection attempts may hang for extended\n * periods before timing out.\n *\n * The `net` module from Node.js is imported dynamically so that bundlers used in\n * browser environments (like Next.js) don't attempt to include it during\n * static analysis.\n */\nexport async function checkPortAvailability(port: number, host = '0.0.0.0'): Promise<boolean> {\n // Dynamically import `net` only when this function is executed in a Node.js\n // environment. This prevents tools like Next.js from trying to bundle the\n // `net` module when other utilities from this package are imported in the\n // browser.\n try {\n const net = await import('net')\n\n return new Promise((resolve) => {\n const server = net.createServer()\n let settled = false\n\n const finish = (available: boolean) => {\n if (settled) {\n return\n }\n settled = true\n resolve(available)\n }\n\n server.once('error', () => {\n // Port is already in use or cannot be bound\n finish(false)\n })\n\n server.once('listening', () => {\n // Port is available, close the server and resolve\n server.close(() => finish(true))\n })\n\n server.listen({ port, host, exclusive: true })\n })\n } catch {\n throw new Error('checkPortAvailability is only available in a Node.js environment')\n }\n}\n\n// Backwards compatibility alias\nexport const checkPort = checkPortAvailability\n"],"mappings":";;;;;;;;;;;;;;AAWA,eAAsB,sBAAsBA,MAAc,OAAO,WAA6B;AAK5F,KAAI;EACF,MAAM,MAAM,MAAM,OAAO;AAEzB,SAAO,IAAI,QAAQ,CAAC,YAAY;GAC9B,MAAM,SAAS,IAAI,cAAc;GACjC,IAAI,UAAU;GAEd,MAAM,SAAS,CAACC,cAAuB;AACrC,QAAI,QACF;AAEF,cAAU;AACV,YAAQ,UAAU;GACnB;AAED,UAAO,KAAK,SAAS,MAAM;AAEzB,WAAO,MAAM;GACd,EAAC;AAEF,UAAO,KAAK,aAAa,MAAM;AAE7B,WAAO,MAAM,MAAM,OAAO,KAAK,CAAC;GACjC,EAAC;AAEF,UAAO,OAAO;IAAE;IAAM;IAAM,WAAW;GAAM,EAAC;EAC/C;CACF,QAAO;AACN,QAAM,IAAI,MAAM;CACjB;AACF;AAGD,MAAa,YAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/utils",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Shared utility functions for PostXL code generation framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",