@jsenv/core 27.2.2 → 27.3.2

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/README.md CHANGED
@@ -23,7 +23,7 @@ npm create jsenv@latest
23
23
  npm install --save-dev @jsenv/core
24
24
  ```
25
25
 
26
- _@jsenv/core_ is tested on Mac, Windows, Linux on Node.js 16.14.0. Other operating systems and Node.js versions are not tested.
26
+ _@jsenv/core_ is tested on Mac, Windows, Linux on Node.js 18.5.0. Other operating systems and Node.js versions are not tested.
27
27
 
28
28
  # Documentation
29
29
 
package/dist/main.js CHANGED
@@ -9,6 +9,7 @@ import net, { createServer } from "node:net";
9
9
  import { Readable, Stream, Writable } from "node:stream";
10
10
  import { Http2ServerResponse } from "node:http2";
11
11
  import { createReadStream, readdirSync, statSync, readFile as readFile$1, chmod, stat, lstat, readdir, promises, unlink, openSync, closeSync, rmdir, readFileSync as readFileSync$1, watch, writeFile as writeFile$1, writeFileSync as writeFileSync$1, mkdirSync, existsSync, realpathSync } from "node:fs";
12
+ import { lookup } from "node:dns";
12
13
  import { performance } from "node:perf_hooks";
13
14
  import { extname, dirname, basename } from "node:path";
14
15
  import { pathToFileURL, fileURLToPath } from "node:url";
@@ -2653,15 +2654,32 @@ const statusIsClientError = status => status >= 400 && status < 500;
2653
2654
 
2654
2655
  const statusIsServerError = status => status >= 500 && status < 600;
2655
2656
 
2656
- const getServerOrigins = ({
2657
+ const applyDnsResolution = async hostname => {
2658
+ const dnsResolution = await new Promise((resolve, reject) => {
2659
+ lookup(hostname, (error, address, family) => {
2660
+ if (error) {
2661
+ reject(error);
2662
+ } else {
2663
+ resolve({
2664
+ address,
2665
+ family
2666
+ });
2667
+ }
2668
+ });
2669
+ });
2670
+ return dnsResolution;
2671
+ };
2672
+
2673
+ const getServerOrigins = async ({
2657
2674
  protocol,
2658
2675
  ip,
2659
2676
  port
2660
2677
  }) => {
2661
2678
  const isInternalIp = ip === "127.0.0.1";
2679
+ const localhostDnsResolution = await applyDnsResolution("localhost");
2662
2680
  const internalOrigin = createServerOrigin({
2663
2681
  protocol,
2664
- hostname: "localhost",
2682
+ hostname: localhostDnsResolution.address === "127.0.0.1" ? "localhost" : "127.0.0.1",
2665
2683
  port
2666
2684
  });
2667
2685
 
@@ -3536,7 +3554,7 @@ const startServer = async ({
3536
3554
  };
3537
3555
 
3538
3556
  status = "opened";
3539
- const serverOrigins = getServerOrigins({
3557
+ const serverOrigins = await getServerOrigins({
3540
3558
  protocol,
3541
3559
  ip,
3542
3560
  port
@@ -26760,7 +26778,6 @@ nodeWorkerThread.run = async ({
26760
26778
  env: envForWorkerThread,
26761
26779
  execArgv: execArgvForWorkerThread,
26762
26780
  // workerData: { options },
26763
- // trackUnmanagedFds: true,
26764
26781
  stdin: true,
26765
26782
  stdout: true,
26766
26783
  stderr: true
@@ -26778,7 +26795,13 @@ nodeWorkerThread.run = async ({
26778
26795
  onceWorkerThreadMessage(workerThread, "ready", resolve);
26779
26796
  });
26780
26797
  const stop = memoize(async () => {
26781
- await workerThreadReadyPromise;
26798
+ // read all stdout before terminating
26799
+ // (no need for stderr because it's sync)
26800
+ while (workerThread.stdout.read() !== null) {}
26801
+
26802
+ await new Promise(resolve => {
26803
+ setTimeout(resolve);
26804
+ });
26782
26805
  await workerThread.terminate();
26783
26806
  });
26784
26807
  const winnerPromise = new Promise(resolve => {
@@ -26916,25 +26939,27 @@ nodeWorkerThread.run = async ({
26916
26939
  const installWorkerThreadOutputListener = (workerThread, callback) => {
26917
26940
  // beware that we may receive ansi output here, should not be a problem but keep that in mind
26918
26941
  const stdoutDataCallback = chunk => {
26942
+ const text = String(chunk);
26919
26943
  callback({
26920
26944
  type: "log",
26921
- text: String(chunk)
26945
+ text
26922
26946
  });
26923
26947
  };
26924
26948
 
26925
26949
  workerThread.stdout.on("data", stdoutDataCallback);
26926
26950
 
26927
26951
  const stdErrorDataCallback = chunk => {
26952
+ const text = String(chunk);
26928
26953
  callback({
26929
26954
  type: "error",
26930
- text: String(chunk)
26955
+ text
26931
26956
  });
26932
26957
  };
26933
26958
 
26934
26959
  workerThread.stderr.on("data", stdErrorDataCallback);
26935
26960
  return () => {
26936
26961
  workerThread.stdout.removeListener("data", stdoutDataCallback);
26937
- workerThread.stderr.removeListener("data", stdoutDataCallback);
26962
+ workerThread.stderr.removeListener("data", stdErrorDataCallback);
26938
26963
  };
26939
26964
  };
26940
26965
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.2.2",
3
+ "version": "27.3.2",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/jsenv/jsenv-core"
14
14
  },
15
15
  "engines": {
16
- "node": ">=16.13.0"
16
+ "node": ">=18.5.0"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public",
@@ -73,7 +73,7 @@
73
73
  "@jsenv/integrity": "0.0.1",
74
74
  "@jsenv/log": "3.1.0",
75
75
  "@jsenv/node-esm-resolution": "0.1.0",
76
- "@jsenv/server": "12.7.5",
76
+ "@jsenv/server": "12.8.0",
77
77
  "@jsenv/sourcemap": "1.0.1",
78
78
  "@jsenv/uneval": "1.6.0",
79
79
  "@jsenv/url-meta": "7.0.0",
@@ -86,7 +86,6 @@ nodeWorkerThread.run = async ({
86
86
  env: envForWorkerThread,
87
87
  execArgv: execArgvForWorkerThread,
88
88
  // workerData: { options },
89
- // trackUnmanagedFds: true,
90
89
  stdin: true,
91
90
  stdout: true,
92
91
  stderr: true,
@@ -103,7 +102,12 @@ nodeWorkerThread.run = async ({
103
102
  })
104
103
 
105
104
  const stop = memoize(async () => {
106
- await workerThreadReadyPromise
105
+ // read all stdout before terminating
106
+ // (no need for stderr because it's sync)
107
+ while (workerThread.stdout.read() !== null) {}
108
+ await new Promise((resolve) => {
109
+ setTimeout(resolve)
110
+ })
107
111
  await workerThread.terminate()
108
112
  })
109
113
 
@@ -232,16 +236,18 @@ nodeWorkerThread.run = async ({
232
236
  const installWorkerThreadOutputListener = (workerThread, callback) => {
233
237
  // beware that we may receive ansi output here, should not be a problem but keep that in mind
234
238
  const stdoutDataCallback = (chunk) => {
235
- callback({ type: "log", text: String(chunk) })
239
+ const text = String(chunk)
240
+ callback({ type: "log", text })
236
241
  }
237
242
  workerThread.stdout.on("data", stdoutDataCallback)
238
243
  const stdErrorDataCallback = (chunk) => {
239
- callback({ type: "error", text: String(chunk) })
244
+ const text = String(chunk)
245
+ callback({ type: "error", text })
240
246
  }
241
247
  workerThread.stderr.on("data", stdErrorDataCallback)
242
248
  return () => {
243
249
  workerThread.stdout.removeListener("data", stdoutDataCallback)
244
- workerThread.stderr.removeListener("data", stdoutDataCallback)
250
+ workerThread.stderr.removeListener("data", stdErrorDataCallback)
245
251
  }
246
252
  }
247
253