@bonsae/nrg 0.11.0 → 0.11.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vite/index.js +36 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
package/vite/index.js CHANGED
@@ -383,7 +383,24 @@ module.exports = settings;
383
383
  this.logger.raw(line);
384
384
  }
385
385
  async start() {
386
- this.port = await getPort({ port: this.preferredPort });
386
+ const available = await detect(this.preferredPort);
387
+ if (available === this.preferredPort) {
388
+ this.port = this.preferredPort;
389
+ } else {
390
+ this.logger.warn(
391
+ `Port ${this.preferredPort} is still in use, waiting...`
392
+ );
393
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
394
+ const retryAvailable = await detect(this.preferredPort);
395
+ if (retryAvailable === this.preferredPort) {
396
+ this.port = this.preferredPort;
397
+ } else {
398
+ this.logger.warn(
399
+ `Port ${this.preferredPort} still occupied, using port ${retryAvailable}`
400
+ );
401
+ this.port = await getPort({ port: this.preferredPort });
402
+ }
403
+ }
387
404
  const startProcess = () => {
388
405
  return new Promise(async (resolve, reject) => {
389
406
  try {
@@ -498,11 +515,17 @@ module.exports = settings;
498
515
  }
499
516
  };
500
517
  try {
501
- await retry(checkPortUsage, { attempts: 5, delay: 100 });
518
+ await retry(checkPortUsage, { attempts: 10, delay: 300 });
502
519
  } catch {
503
520
  this.logger.warn(
504
- `Port ${currentPort} may still be in use. If restart fails, try again in a few seconds.`
521
+ `Port ${currentPort} still in use after stop. Force killing...`
505
522
  );
523
+ if (pid) {
524
+ await new Promise((resolve) => {
525
+ treeKill2(pid, "SIGKILL", () => resolve());
526
+ });
527
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
528
+ }
506
529
  }
507
530
  }
508
531
  this.port = null;
@@ -2270,10 +2293,14 @@ function serverPlugin(options) {
2270
2293
  changeOrigin: true,
2271
2294
  ws: true,
2272
2295
  configure: (proxy) => {
2273
- proxy.on("error", () => {
2296
+ proxy.on("error", (_err, _req, res) => {
2274
2297
  if (nodeRedPort) {
2275
2298
  proxy.options.target = `http://127.0.0.1:${nodeRedPort}`;
2276
2299
  }
2300
+ if (res && !res.headersSent && "writeHead" in res) {
2301
+ res.writeHead(502);
2302
+ res.end();
2303
+ }
2277
2304
  });
2278
2305
  }
2279
2306
  }
@@ -2288,7 +2315,11 @@ function serverPlugin(options) {
2288
2315
  info: () => {
2289
2316
  },
2290
2317
  warn: console.warn,
2291
- error: console.error,
2318
+ error: (...args) => {
2319
+ const msg = args.map(String).join(" ");
2320
+ if (isStarting && msg.includes("ECONNREFUSED")) return;
2321
+ console.error(...args);
2322
+ },
2292
2323
  warnOnce: () => {
2293
2324
  },
2294
2325
  hasWarned: false,