unplugin-https-reverse-proxy 1.0.0-beta.17 → 1.0.0-beta.18

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
@@ -220,7 +220,17 @@ export default defineNuxtConfig({
220
220
  })
221
221
  ```
222
222
 
223
- > This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
223
+ **!important:** You need to update the `nuxt dev` script by adding `--fork=false` to enable host restoration.
224
+
225
+ ```json
226
+ // package.json
227
+
228
+ {
229
+ "scripts": {
230
+ "dev": "nuxt dev --fork=false"
231
+ }
232
+ }
233
+ ```
224
234
 
225
235
  <br></details>
226
236
 
@@ -379,6 +379,8 @@ var CaddyInstant = class {
379
379
  showCaddyLog = false,
380
380
  https = false
381
381
  } = options || {};
382
+ this._source = source;
383
+ this._target = target;
382
384
  if (!this.inited)
383
385
  await this.init();
384
386
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -407,17 +409,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
407
409
  var _a, _b;
408
410
  const setupCleanup = () => {
409
411
  process3.on("SIGINT", async () => {
410
- if (!restore || this.stoped)
412
+ if (this.stoped)
411
413
  return;
412
- await this.baseCleanup();
414
+ process3.stdin.resume();
413
415
  try {
414
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
415
- consola.success("Restore host success.\n");
416
- else
417
- consola.fail("Restore host failed.\n");
418
- } catch (e) {
419
- consola.error(e);
420
- consola.fail("Restore host failed.\n");
416
+ await this.baseCleanup(restore);
421
417
  } finally {
422
418
  this.stoped = true;
423
419
  process3.nextTick(() => {
@@ -433,24 +429,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
433
429
  const pwd = process3.cwd();
434
430
  const viteCacheDir = `${pwd}/node_modules/.vite`;
435
431
  if (existsSync(viteCacheDir))
436
- chmodRecursive(viteCacheDir, 511);
432
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
433
+ });
437
434
  const nuxtCacheDir = `${pwd}/.nuxt`;
438
435
  if (existsSync(nuxtCacheDir))
439
- await chmodRecursive(nuxtCacheDir, 511);
436
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
437
+ });
440
438
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
441
439
  if (existsSync(webpackCacheDir))
442
- chmodRecursive(webpackCacheDir, 511);
443
- if (!restore || this.stoped)
440
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
441
+ });
442
+ if (this.stoped)
444
443
  return originalExit(code);
445
- await this.baseCleanup();
444
+ process3.stdin.resume();
446
445
  try {
447
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
448
- consola.success("Restore host success.\n");
449
- else
450
- consola.fail("Restore host failed.\n");
451
- } catch (e) {
452
- consola.error(e);
453
- consola.fail("Restore host failed.\n");
446
+ await this.baseCleanup();
454
447
  } finally {
455
448
  this.stoped = true;
456
449
  process3.nextTick(() => {
@@ -460,12 +453,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
460
453
  };
461
454
  };
462
455
  if (!this.locked) {
463
- this.caddyChild = process3.platform !== "win32" ? spawn("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : spawn(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
456
+ this._caddyChild = process3.platform !== "win32" ? spawn("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : spawn(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
464
457
  lockfile.lockSync(caddyLockFilePath);
465
- this.caddyChild.on("error", (err) => {
458
+ this._caddyChild.on("error", (err) => {
466
459
  return reject(err);
467
460
  });
468
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
461
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
469
462
  const lines = data.toString().split("\n").map((line) => line.trim());
470
463
  for (const line of lines) {
471
464
  showCaddyLog && line && console.info(line);
@@ -480,7 +473,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
480
473
  return resolve();
481
474
  }
482
475
  });
483
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
476
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
484
477
  consola.info(_data.toString());
485
478
  resolve();
486
479
  });
@@ -492,15 +485,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
492
485
  }
493
486
  });
494
487
  }
495
- async baseCleanup() {
488
+ async baseCleanup(restore = true) {
496
489
  var _a;
497
- if (!this.locked) {
498
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
490
+ try {
491
+ if (restore && this._source && this._target) {
492
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
493
+ consola.success("Restore host success.\n");
494
+ else
495
+ consola.fail("Restore host failed.\n");
496
+ }
497
+ } catch (e) {
498
+ consola.error(e);
499
+ consola.fail("Restore host failed.\n");
500
+ }
501
+ if (!this.locked && !this.stoped) {
502
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
499
503
  try {
500
- await lockfile.unlock(caddyLockFilePath);
501
- await unlink(caddyFilePath);
502
- await unlink(caddyLockFilePath);
504
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
505
+ });
506
+ await unlink(caddyFilePath).catch(() => {
507
+ });
508
+ await unlink(caddyLockFilePath).catch(() => {
509
+ });
503
510
  } catch (e) {
511
+ consola.error(e);
504
512
  }
505
513
  }
506
514
  }
package/dist/esbuild.cjs CHANGED
@@ -448,6 +448,8 @@ var CaddyInstant = class {
448
448
  showCaddyLog = false,
449
449
  https = false
450
450
  } = options || {};
451
+ this._source = source;
452
+ this._target = target;
451
453
  if (!this.inited)
452
454
  await this.init();
453
455
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -476,17 +478,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
476
478
  var _a, _b;
477
479
  const setupCleanup = () => {
478
480
  import_node_process4.default.on("SIGINT", async () => {
479
- if (!restore || this.stoped)
481
+ if (this.stoped)
480
482
  return;
481
- await this.baseCleanup();
483
+ import_node_process4.default.stdin.resume();
482
484
  try {
483
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
484
- consola.success("Restore host success.\n");
485
- else
486
- consola.fail("Restore host failed.\n");
487
- } catch (e) {
488
- consola.error(e);
489
- consola.fail("Restore host failed.\n");
485
+ await this.baseCleanup(restore);
490
486
  } finally {
491
487
  this.stoped = true;
492
488
  import_node_process4.default.nextTick(() => {
@@ -502,24 +498,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
502
498
  const pwd = import_node_process4.default.cwd();
503
499
  const viteCacheDir = `${pwd}/node_modules/.vite`;
504
500
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
505
- chmodRecursive(viteCacheDir, 511);
501
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
502
+ });
506
503
  const nuxtCacheDir = `${pwd}/.nuxt`;
507
504
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
508
- await chmodRecursive(nuxtCacheDir, 511);
505
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
506
+ });
509
507
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
510
508
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
511
- chmodRecursive(webpackCacheDir, 511);
512
- if (!restore || this.stoped)
509
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
510
+ });
511
+ if (this.stoped)
513
512
  return originalExit(code);
514
- await this.baseCleanup();
513
+ import_node_process4.default.stdin.resume();
515
514
  try {
516
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
517
- consola.success("Restore host success.\n");
518
- else
519
- consola.fail("Restore host failed.\n");
520
- } catch (e) {
521
- consola.error(e);
522
- consola.fail("Restore host failed.\n");
515
+ await this.baseCleanup();
523
516
  } finally {
524
517
  this.stoped = true;
525
518
  import_node_process4.default.nextTick(() => {
@@ -529,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
529
522
  };
530
523
  };
531
524
  if (!this.locked) {
532
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
525
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
533
526
  lockfile.lockSync(caddyLockFilePath);
534
- this.caddyChild.on("error", (err) => {
527
+ this._caddyChild.on("error", (err) => {
535
528
  return reject(err);
536
529
  });
537
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
530
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
538
531
  const lines = data.toString().split("\n").map((line) => line.trim());
539
532
  for (const line of lines) {
540
533
  showCaddyLog && line && console.info(line);
@@ -549,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
549
542
  return resolve();
550
543
  }
551
544
  });
552
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
545
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
553
546
  consola.info(_data.toString());
554
547
  resolve();
555
548
  });
@@ -561,15 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
561
554
  }
562
555
  });
563
556
  }
564
- async baseCleanup() {
557
+ async baseCleanup(restore = true) {
565
558
  var _a;
566
- if (!this.locked) {
567
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
559
+ try {
560
+ if (restore && this._source && this._target) {
561
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
562
+ consola.success("Restore host success.\n");
563
+ else
564
+ consola.fail("Restore host failed.\n");
565
+ }
566
+ } catch (e) {
567
+ consola.error(e);
568
+ consola.fail("Restore host failed.\n");
569
+ }
570
+ if (!this.locked && !this.stoped) {
571
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
568
572
  try {
569
- await lockfile.unlock(caddyLockFilePath);
570
- await (0, import_promises2.unlink)(caddyFilePath);
571
- await (0, import_promises2.unlink)(caddyLockFilePath);
573
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
574
+ });
575
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
578
+ });
572
579
  } catch (e) {
580
+ consola.error(e);
573
581
  }
574
582
  }
575
583
  }
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import "./chunk-2VGRJ3QS.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -448,6 +448,8 @@ var CaddyInstant = class {
448
448
  showCaddyLog = false,
449
449
  https = false
450
450
  } = options || {};
451
+ this._source = source;
452
+ this._target = target;
451
453
  if (!this.inited)
452
454
  await this.init();
453
455
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -476,17 +478,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
476
478
  var _a, _b;
477
479
  const setupCleanup = () => {
478
480
  import_node_process4.default.on("SIGINT", async () => {
479
- if (!restore || this.stoped)
481
+ if (this.stoped)
480
482
  return;
481
- await this.baseCleanup();
483
+ import_node_process4.default.stdin.resume();
482
484
  try {
483
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
484
- consola.success("Restore host success.\n");
485
- else
486
- consola.fail("Restore host failed.\n");
487
- } catch (e) {
488
- consola.error(e);
489
- consola.fail("Restore host failed.\n");
485
+ await this.baseCleanup(restore);
490
486
  } finally {
491
487
  this.stoped = true;
492
488
  import_node_process4.default.nextTick(() => {
@@ -502,24 +498,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
502
498
  const pwd = import_node_process4.default.cwd();
503
499
  const viteCacheDir = `${pwd}/node_modules/.vite`;
504
500
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
505
- chmodRecursive(viteCacheDir, 511);
501
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
502
+ });
506
503
  const nuxtCacheDir = `${pwd}/.nuxt`;
507
504
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
508
- await chmodRecursive(nuxtCacheDir, 511);
505
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
506
+ });
509
507
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
510
508
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
511
- chmodRecursive(webpackCacheDir, 511);
512
- if (!restore || this.stoped)
509
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
510
+ });
511
+ if (this.stoped)
513
512
  return originalExit(code);
514
- await this.baseCleanup();
513
+ import_node_process4.default.stdin.resume();
515
514
  try {
516
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
517
- consola.success("Restore host success.\n");
518
- else
519
- consola.fail("Restore host failed.\n");
520
- } catch (e) {
521
- consola.error(e);
522
- consola.fail("Restore host failed.\n");
515
+ await this.baseCleanup();
523
516
  } finally {
524
517
  this.stoped = true;
525
518
  import_node_process4.default.nextTick(() => {
@@ -529,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
529
522
  };
530
523
  };
531
524
  if (!this.locked) {
532
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
525
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
533
526
  lockfile.lockSync(caddyLockFilePath);
534
- this.caddyChild.on("error", (err) => {
527
+ this._caddyChild.on("error", (err) => {
535
528
  return reject(err);
536
529
  });
537
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
530
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
538
531
  const lines = data.toString().split("\n").map((line) => line.trim());
539
532
  for (const line of lines) {
540
533
  showCaddyLog && line && console.info(line);
@@ -549,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
549
542
  return resolve();
550
543
  }
551
544
  });
552
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
545
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
553
546
  consola.info(_data.toString());
554
547
  resolve();
555
548
  });
@@ -561,15 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
561
554
  }
562
555
  });
563
556
  }
564
- async baseCleanup() {
557
+ async baseCleanup(restore = true) {
565
558
  var _a;
566
- if (!this.locked) {
567
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
559
+ try {
560
+ if (restore && this._source && this._target) {
561
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
562
+ consola.success("Restore host success.\n");
563
+ else
564
+ consola.fail("Restore host failed.\n");
565
+ }
566
+ } catch (e) {
567
+ consola.error(e);
568
+ consola.fail("Restore host failed.\n");
569
+ }
570
+ if (!this.locked && !this.stoped) {
571
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
568
572
  try {
569
- await lockfile.unlock(caddyLockFilePath);
570
- await (0, import_promises2.unlink)(caddyFilePath);
571
- await (0, import_promises2.unlink)(caddyLockFilePath);
573
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
574
+ });
575
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
578
+ });
572
579
  } catch (e) {
580
+ consola.error(e);
573
581
  }
574
582
  }
575
583
  }
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-WCFY7NJQ.js";
6
+ } from "./chunk-ZDL3GBDQ.js";
7
7
  import "./chunk-2VGRJ3QS.js";
8
8
  export {
9
9
  src_default as default,
package/dist/nuxt.cjs CHANGED
@@ -450,6 +450,8 @@ var CaddyInstant = class {
450
450
  showCaddyLog = false,
451
451
  https = false
452
452
  } = options || {};
453
+ this._source = source;
454
+ this._target = target;
453
455
  if (!this.inited)
454
456
  await this.init();
455
457
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -478,17 +480,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
478
480
  var _a, _b;
479
481
  const setupCleanup = () => {
480
482
  import_node_process4.default.on("SIGINT", async () => {
481
- if (!restore || this.stoped)
483
+ if (this.stoped)
482
484
  return;
483
- await this.baseCleanup();
485
+ import_node_process4.default.stdin.resume();
484
486
  try {
485
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
486
- consola.success("Restore host success.\n");
487
- else
488
- consola.fail("Restore host failed.\n");
489
- } catch (e) {
490
- consola.error(e);
491
- consola.fail("Restore host failed.\n");
487
+ await this.baseCleanup(restore);
492
488
  } finally {
493
489
  this.stoped = true;
494
490
  import_node_process4.default.nextTick(() => {
@@ -504,24 +500,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
504
500
  const pwd = import_node_process4.default.cwd();
505
501
  const viteCacheDir = `${pwd}/node_modules/.vite`;
506
502
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
507
- chmodRecursive(viteCacheDir, 511);
503
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
504
+ });
508
505
  const nuxtCacheDir = `${pwd}/.nuxt`;
509
506
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
510
- await chmodRecursive(nuxtCacheDir, 511);
507
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
508
+ });
511
509
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
512
510
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
513
- chmodRecursive(webpackCacheDir, 511);
514
- if (!restore || this.stoped)
511
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
512
+ });
513
+ if (this.stoped)
515
514
  return originalExit(code);
516
- await this.baseCleanup();
515
+ import_node_process4.default.stdin.resume();
517
516
  try {
518
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
519
- consola.success("Restore host success.\n");
520
- else
521
- consola.fail("Restore host failed.\n");
522
- } catch (e) {
523
- consola.error(e);
524
- consola.fail("Restore host failed.\n");
517
+ await this.baseCleanup();
525
518
  } finally {
526
519
  this.stoped = true;
527
520
  import_node_process4.default.nextTick(() => {
@@ -531,12 +524,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
531
524
  };
532
525
  };
533
526
  if (!this.locked) {
534
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
527
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
535
528
  lockfile.lockSync(caddyLockFilePath);
536
- this.caddyChild.on("error", (err) => {
529
+ this._caddyChild.on("error", (err) => {
537
530
  return reject(err);
538
531
  });
539
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
532
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
540
533
  const lines = data.toString().split("\n").map((line) => line.trim());
541
534
  for (const line of lines) {
542
535
  showCaddyLog && line && console.info(line);
@@ -551,7 +544,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
551
544
  return resolve();
552
545
  }
553
546
  });
554
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
547
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
555
548
  consola.info(_data.toString());
556
549
  resolve();
557
550
  });
@@ -563,15 +556,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
563
556
  }
564
557
  });
565
558
  }
566
- async baseCleanup() {
559
+ async baseCleanup(restore = true) {
567
560
  var _a;
568
- if (!this.locked) {
569
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
561
+ try {
562
+ if (restore && this._source && this._target) {
563
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
564
+ consola.success("Restore host success.\n");
565
+ else
566
+ consola.fail("Restore host failed.\n");
567
+ }
568
+ } catch (e) {
569
+ consola.error(e);
570
+ consola.fail("Restore host failed.\n");
571
+ }
572
+ if (!this.locked && !this.stoped) {
573
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
570
574
  try {
571
- await lockfile.unlock(caddyLockFilePath);
572
- await (0, import_promises2.unlink)(caddyFilePath);
573
- await (0, import_promises2.unlink)(caddyLockFilePath);
575
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
578
+ });
579
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
580
+ });
574
581
  } catch (e) {
582
+ consola.error(e);
575
583
  }
576
584
  }
577
585
  }
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import {
5
5
  consola,
6
6
  isAdmin
package/dist/rollup.cjs CHANGED
@@ -448,6 +448,8 @@ var CaddyInstant = class {
448
448
  showCaddyLog = false,
449
449
  https = false
450
450
  } = options || {};
451
+ this._source = source;
452
+ this._target = target;
451
453
  if (!this.inited)
452
454
  await this.init();
453
455
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -476,17 +478,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
476
478
  var _a, _b;
477
479
  const setupCleanup = () => {
478
480
  import_node_process4.default.on("SIGINT", async () => {
479
- if (!restore || this.stoped)
481
+ if (this.stoped)
480
482
  return;
481
- await this.baseCleanup();
483
+ import_node_process4.default.stdin.resume();
482
484
  try {
483
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
484
- consola.success("Restore host success.\n");
485
- else
486
- consola.fail("Restore host failed.\n");
487
- } catch (e) {
488
- consola.error(e);
489
- consola.fail("Restore host failed.\n");
485
+ await this.baseCleanup(restore);
490
486
  } finally {
491
487
  this.stoped = true;
492
488
  import_node_process4.default.nextTick(() => {
@@ -502,24 +498,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
502
498
  const pwd = import_node_process4.default.cwd();
503
499
  const viteCacheDir = `${pwd}/node_modules/.vite`;
504
500
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
505
- chmodRecursive(viteCacheDir, 511);
501
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
502
+ });
506
503
  const nuxtCacheDir = `${pwd}/.nuxt`;
507
504
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
508
- await chmodRecursive(nuxtCacheDir, 511);
505
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
506
+ });
509
507
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
510
508
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
511
- chmodRecursive(webpackCacheDir, 511);
512
- if (!restore || this.stoped)
509
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
510
+ });
511
+ if (this.stoped)
513
512
  return originalExit(code);
514
- await this.baseCleanup();
513
+ import_node_process4.default.stdin.resume();
515
514
  try {
516
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
517
- consola.success("Restore host success.\n");
518
- else
519
- consola.fail("Restore host failed.\n");
520
- } catch (e) {
521
- consola.error(e);
522
- consola.fail("Restore host failed.\n");
515
+ await this.baseCleanup();
523
516
  } finally {
524
517
  this.stoped = true;
525
518
  import_node_process4.default.nextTick(() => {
@@ -529,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
529
522
  };
530
523
  };
531
524
  if (!this.locked) {
532
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
525
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
533
526
  lockfile.lockSync(caddyLockFilePath);
534
- this.caddyChild.on("error", (err) => {
527
+ this._caddyChild.on("error", (err) => {
535
528
  return reject(err);
536
529
  });
537
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
530
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
538
531
  const lines = data.toString().split("\n").map((line) => line.trim());
539
532
  for (const line of lines) {
540
533
  showCaddyLog && line && console.info(line);
@@ -549,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
549
542
  return resolve();
550
543
  }
551
544
  });
552
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
545
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
553
546
  consola.info(_data.toString());
554
547
  resolve();
555
548
  });
@@ -561,15 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
561
554
  }
562
555
  });
563
556
  }
564
- async baseCleanup() {
557
+ async baseCleanup(restore = true) {
565
558
  var _a;
566
- if (!this.locked) {
567
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
559
+ try {
560
+ if (restore && this._source && this._target) {
561
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
562
+ consola.success("Restore host success.\n");
563
+ else
564
+ consola.fail("Restore host failed.\n");
565
+ }
566
+ } catch (e) {
567
+ consola.error(e);
568
+ consola.fail("Restore host failed.\n");
569
+ }
570
+ if (!this.locked && !this.stoped) {
571
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
568
572
  try {
569
- await lockfile.unlock(caddyLockFilePath);
570
- await (0, import_promises2.unlink)(caddyFilePath);
571
- await (0, import_promises2.unlink)(caddyLockFilePath);
573
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
574
+ });
575
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
578
+ });
572
579
  } catch (e) {
580
+ consola.error(e);
573
581
  }
574
582
  }
575
583
  }
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import "./chunk-2VGRJ3QS.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -447,6 +447,8 @@ var CaddyInstant = class {
447
447
  showCaddyLog = false,
448
448
  https = false
449
449
  } = options || {};
450
+ this._source = source;
451
+ this._target = target;
450
452
  if (!this.inited)
451
453
  await this.init();
452
454
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -475,17 +477,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
475
477
  var _a, _b;
476
478
  const setupCleanup = () => {
477
479
  import_node_process4.default.on("SIGINT", async () => {
478
- if (!restore || this.stoped)
480
+ if (this.stoped)
479
481
  return;
480
- await this.baseCleanup();
482
+ import_node_process4.default.stdin.resume();
481
483
  try {
482
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
483
- consola.success("Restore host success.\n");
484
- else
485
- consola.fail("Restore host failed.\n");
486
- } catch (e) {
487
- consola.error(e);
488
- consola.fail("Restore host failed.\n");
484
+ await this.baseCleanup(restore);
489
485
  } finally {
490
486
  this.stoped = true;
491
487
  import_node_process4.default.nextTick(() => {
@@ -501,24 +497,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
501
497
  const pwd = import_node_process4.default.cwd();
502
498
  const viteCacheDir = `${pwd}/node_modules/.vite`;
503
499
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
504
- chmodRecursive(viteCacheDir, 511);
500
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
501
+ });
505
502
  const nuxtCacheDir = `${pwd}/.nuxt`;
506
503
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
507
- await chmodRecursive(nuxtCacheDir, 511);
504
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
505
+ });
508
506
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
509
507
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
510
- chmodRecursive(webpackCacheDir, 511);
511
- if (!restore || this.stoped)
508
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
509
+ });
510
+ if (this.stoped)
512
511
  return originalExit(code);
513
- await this.baseCleanup();
512
+ import_node_process4.default.stdin.resume();
514
513
  try {
515
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
516
- consola.success("Restore host success.\n");
517
- else
518
- consola.fail("Restore host failed.\n");
519
- } catch (e) {
520
- consola.error(e);
521
- consola.fail("Restore host failed.\n");
514
+ await this.baseCleanup();
522
515
  } finally {
523
516
  this.stoped = true;
524
517
  import_node_process4.default.nextTick(() => {
@@ -528,12 +521,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
528
521
  };
529
522
  };
530
523
  if (!this.locked) {
531
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
524
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
532
525
  lockfile.lockSync(caddyLockFilePath);
533
- this.caddyChild.on("error", (err) => {
526
+ this._caddyChild.on("error", (err) => {
534
527
  return reject(err);
535
528
  });
536
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
529
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
537
530
  const lines = data.toString().split("\n").map((line) => line.trim());
538
531
  for (const line of lines) {
539
532
  showCaddyLog && line && console.info(line);
@@ -548,7 +541,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
548
541
  return resolve();
549
542
  }
550
543
  });
551
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
544
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
552
545
  consola.info(_data.toString());
553
546
  resolve();
554
547
  });
@@ -560,15 +553,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
560
553
  }
561
554
  });
562
555
  }
563
- async baseCleanup() {
556
+ async baseCleanup(restore = true) {
564
557
  var _a;
565
- if (!this.locked) {
566
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
558
+ try {
559
+ if (restore && this._source && this._target) {
560
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
561
+ consola.success("Restore host success.\n");
562
+ else
563
+ consola.fail("Restore host failed.\n");
564
+ }
565
+ } catch (e) {
566
+ consola.error(e);
567
+ consola.fail("Restore host failed.\n");
568
+ }
569
+ if (!this.locked && !this.stoped) {
570
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
567
571
  try {
568
- await lockfile.unlock(caddyLockFilePath);
569
- await (0, import_promises2.unlink)(caddyFilePath);
570
- await (0, import_promises2.unlink)(caddyLockFilePath);
572
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
573
+ });
574
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
575
+ });
576
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
577
+ });
571
578
  } catch (e) {
579
+ consola.error(e);
572
580
  }
573
581
  }
574
582
  }
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import "./chunk-2VGRJ3QS.js";
5
5
 
6
6
  // src/rspack.ts
package/dist/vite.cjs CHANGED
@@ -448,6 +448,8 @@ var CaddyInstant = class {
448
448
  showCaddyLog = false,
449
449
  https = false
450
450
  } = options || {};
451
+ this._source = source;
452
+ this._target = target;
451
453
  if (!this.inited)
452
454
  await this.init();
453
455
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -476,17 +478,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
476
478
  var _a, _b;
477
479
  const setupCleanup = () => {
478
480
  import_node_process4.default.on("SIGINT", async () => {
479
- if (!restore || this.stoped)
481
+ if (this.stoped)
480
482
  return;
481
- await this.baseCleanup();
483
+ import_node_process4.default.stdin.resume();
482
484
  try {
483
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
484
- consola.success("Restore host success.\n");
485
- else
486
- consola.fail("Restore host failed.\n");
487
- } catch (e) {
488
- consola.error(e);
489
- consola.fail("Restore host failed.\n");
485
+ await this.baseCleanup(restore);
490
486
  } finally {
491
487
  this.stoped = true;
492
488
  import_node_process4.default.nextTick(() => {
@@ -502,24 +498,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
502
498
  const pwd = import_node_process4.default.cwd();
503
499
  const viteCacheDir = `${pwd}/node_modules/.vite`;
504
500
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
505
- chmodRecursive(viteCacheDir, 511);
501
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
502
+ });
506
503
  const nuxtCacheDir = `${pwd}/.nuxt`;
507
504
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
508
- await chmodRecursive(nuxtCacheDir, 511);
505
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
506
+ });
509
507
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
510
508
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
511
- chmodRecursive(webpackCacheDir, 511);
512
- if (!restore || this.stoped)
509
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
510
+ });
511
+ if (this.stoped)
513
512
  return originalExit(code);
514
- await this.baseCleanup();
513
+ import_node_process4.default.stdin.resume();
515
514
  try {
516
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
517
- consola.success("Restore host success.\n");
518
- else
519
- consola.fail("Restore host failed.\n");
520
- } catch (e) {
521
- consola.error(e);
522
- consola.fail("Restore host failed.\n");
515
+ await this.baseCleanup();
523
516
  } finally {
524
517
  this.stoped = true;
525
518
  import_node_process4.default.nextTick(() => {
@@ -529,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
529
522
  };
530
523
  };
531
524
  if (!this.locked) {
532
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
525
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
533
526
  lockfile.lockSync(caddyLockFilePath);
534
- this.caddyChild.on("error", (err) => {
527
+ this._caddyChild.on("error", (err) => {
535
528
  return reject(err);
536
529
  });
537
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
530
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
538
531
  const lines = data.toString().split("\n").map((line) => line.trim());
539
532
  for (const line of lines) {
540
533
  showCaddyLog && line && console.info(line);
@@ -549,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
549
542
  return resolve();
550
543
  }
551
544
  });
552
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
545
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
553
546
  consola.info(_data.toString());
554
547
  resolve();
555
548
  });
@@ -561,15 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
561
554
  }
562
555
  });
563
556
  }
564
- async baseCleanup() {
557
+ async baseCleanup(restore = true) {
565
558
  var _a;
566
- if (!this.locked) {
567
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
559
+ try {
560
+ if (restore && this._source && this._target) {
561
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
562
+ consola.success("Restore host success.\n");
563
+ else
564
+ consola.fail("Restore host failed.\n");
565
+ }
566
+ } catch (e) {
567
+ consola.error(e);
568
+ consola.fail("Restore host failed.\n");
569
+ }
570
+ if (!this.locked && !this.stoped) {
571
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
568
572
  try {
569
- await lockfile.unlock(caddyLockFilePath);
570
- await (0, import_promises2.unlink)(caddyFilePath);
571
- await (0, import_promises2.unlink)(caddyLockFilePath);
573
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
574
+ });
575
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
578
+ });
572
579
  } catch (e) {
580
+ consola.error(e);
573
581
  }
574
582
  }
575
583
  }
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import "./chunk-2VGRJ3QS.js";
5
5
 
6
6
  // src/vite.ts
package/dist/webpack.cjs CHANGED
@@ -448,6 +448,8 @@ var CaddyInstant = class {
448
448
  showCaddyLog = false,
449
449
  https = false
450
450
  } = options || {};
451
+ this._source = source;
452
+ this._target = target;
451
453
  if (!this.inited)
452
454
  await this.init();
453
455
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
@@ -476,17 +478,11 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
476
478
  var _a, _b;
477
479
  const setupCleanup = () => {
478
480
  import_node_process4.default.on("SIGINT", async () => {
479
- if (!restore || this.stoped)
481
+ if (this.stoped)
480
482
  return;
481
- await this.baseCleanup();
483
+ import_node_process4.default.stdin.resume();
482
484
  try {
483
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
484
- consola.success("Restore host success.\n");
485
- else
486
- consola.fail("Restore host failed.\n");
487
- } catch (e) {
488
- consola.error(e);
489
- consola.fail("Restore host failed.\n");
485
+ await this.baseCleanup(restore);
490
486
  } finally {
491
487
  this.stoped = true;
492
488
  import_node_process4.default.nextTick(() => {
@@ -502,24 +498,21 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
502
498
  const pwd = import_node_process4.default.cwd();
503
499
  const viteCacheDir = `${pwd}/node_modules/.vite`;
504
500
  if ((0, import_node_fs2.existsSync)(viteCacheDir))
505
- chmodRecursive(viteCacheDir, 511);
501
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
502
+ });
506
503
  const nuxtCacheDir = `${pwd}/.nuxt`;
507
504
  if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
508
- await chmodRecursive(nuxtCacheDir, 511);
505
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
506
+ });
509
507
  const webpackCacheDir = `${pwd}/node_modules/.cache`;
510
508
  if ((0, import_node_fs2.existsSync)(webpackCacheDir))
511
- chmodRecursive(webpackCacheDir, 511);
512
- if (!restore || this.stoped)
509
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
510
+ });
511
+ if (this.stoped)
513
512
  return originalExit(code);
514
- await this.baseCleanup();
513
+ import_node_process4.default.stdin.resume();
515
514
  try {
516
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
517
- consola.success("Restore host success.\n");
518
- else
519
- consola.fail("Restore host failed.\n");
520
- } catch (e) {
521
- consola.error(e);
522
- consola.fail("Restore host failed.\n");
515
+ await this.baseCleanup();
523
516
  } finally {
524
517
  this.stoped = true;
525
518
  import_node_process4.default.nextTick(() => {
@@ -529,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
529
522
  };
530
523
  };
531
524
  if (!this.locked) {
532
- this.caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
525
+ this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
533
526
  lockfile.lockSync(caddyLockFilePath);
534
- this.caddyChild.on("error", (err) => {
527
+ this._caddyChild.on("error", (err) => {
535
528
  return reject(err);
536
529
  });
537
- (_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
530
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
538
531
  const lines = data.toString().split("\n").map((line) => line.trim());
539
532
  for (const line of lines) {
540
533
  showCaddyLog && line && console.info(line);
@@ -549,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
549
542
  return resolve();
550
543
  }
551
544
  });
552
- (_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
545
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
553
546
  consola.info(_data.toString());
554
547
  resolve();
555
548
  });
@@ -561,15 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
561
554
  }
562
555
  });
563
556
  }
564
- async baseCleanup() {
557
+ async baseCleanup(restore = true) {
565
558
  var _a;
566
- if (!this.locked) {
567
- (_a = this.caddyChild) == null ? void 0 : _a.kill();
559
+ try {
560
+ if (restore && this._source && this._target) {
561
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
562
+ consola.success("Restore host success.\n");
563
+ else
564
+ consola.fail("Restore host failed.\n");
565
+ }
566
+ } catch (e) {
567
+ consola.error(e);
568
+ consola.fail("Restore host failed.\n");
569
+ }
570
+ if (!this.locked && !this.stoped) {
571
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
568
572
  try {
569
- await lockfile.unlock(caddyLockFilePath);
570
- await (0, import_promises2.unlink)(caddyFilePath);
571
- await (0, import_promises2.unlink)(caddyLockFilePath);
573
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
574
+ });
575
+ await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
576
+ });
577
+ await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
578
+ });
572
579
  } catch (e) {
580
+ consola.error(e);
573
581
  }
574
582
  }
575
583
  }
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-WCFY7NJQ.js";
3
+ } from "./chunk-ZDL3GBDQ.js";
4
4
  import "./chunk-2VGRJ3QS.js";
5
5
 
6
6
  // src/webpack.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-https-reverse-proxy",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.17",
4
+ "version": "1.0.0-beta.18",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
@@ -108,7 +108,10 @@ export class CaddyInstant {
108
108
  private locked = false
109
109
  private caddyfile: string | undefined
110
110
 
111
- private caddyChild: ReturnType<typeof spawn> | undefined
111
+ private _caddyChild: ReturnType<typeof spawn> | undefined
112
+
113
+ private _source: string | undefined
114
+ private _target: string | undefined
112
115
 
113
116
  constructor() {
114
117
  testCaddy().then(async () => {
@@ -173,6 +176,9 @@ export class CaddyInstant {
173
176
  https = false,
174
177
  } = options || {}
175
178
 
179
+ this._source = source
180
+ this._target = target
181
+
176
182
  if (!this.inited)
177
183
  await this.init()
178
184
 
@@ -206,21 +212,13 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
206
212
  return new Promise<void>((resolve, reject) => {
207
213
  const setupCleanup = () => {
208
214
  process.on('SIGINT', async () => {
209
- if (!restore || this.stoped)
215
+ if (this.stoped)
210
216
  return
211
217
 
212
- await this.baseCleanup()
218
+ process.stdin.resume()
213
219
 
214
220
  try {
215
- if (await removeHost(source.split(':')[0], target.split(':')[0]))
216
- consola.success('Restore host success.\n')
217
-
218
- else
219
- consola.fail('Restore host failed.\n')
220
- }
221
- catch (e) {
222
- consola.error(e)
223
- consola.fail('Restore host failed.\n')
221
+ await this.baseCleanup(restore)
224
222
  }
225
223
  finally {
226
224
  this.stoped = true
@@ -242,30 +240,23 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
242
240
  const pwd = process.cwd()
243
241
  const viteCacheDir = `${pwd}/node_modules/.vite`
244
242
  if (existsSync(viteCacheDir))
245
- chmodRecursive(viteCacheDir, 0o777)
243
+ await chmodRecursive(viteCacheDir, 0o777).catch(() => { })
246
244
  const nuxtCacheDir = `${pwd}/.nuxt`
247
245
  if (existsSync(nuxtCacheDir))
248
- await chmodRecursive(nuxtCacheDir, 0o777)
246
+ await chmodRecursive(nuxtCacheDir, 0o777).catch(() => { })
249
247
  const webpackCacheDir = `${pwd}/node_modules/.cache`
250
248
  if (existsSync(webpackCacheDir))
251
- chmodRecursive(webpackCacheDir, 0o777)
249
+ await chmodRecursive(webpackCacheDir, 0o777).catch(() => { })
252
250
 
253
- if (!restore || this.stoped)
251
+ if (this.stoped)
254
252
  return originalExit(code)
255
253
 
256
- await this.baseCleanup()
254
+ process.stdin.resume()
257
255
 
258
256
  try {
259
- if (await removeHost(source.split(':')[0], target.split(':')[0]))
260
- consola.success('Restore host success.\n')
261
-
262
- else
263
- consola.fail('Restore host failed.\n')
264
- }
265
- catch (e) {
266
- consola.error(e)
267
- consola.fail('Restore host failed.\n')
257
+ await this.baseCleanup()
268
258
  }
259
+
269
260
  finally {
270
261
  this.stoped = true
271
262
  process.nextTick(() => {
@@ -276,17 +267,17 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
276
267
  }
277
268
 
278
269
  if (!this.locked) {
279
- this.caddyChild = process.platform !== 'win32'
270
+ this._caddyChild = process.platform !== 'win32'
280
271
  ? spawn('sudo', ['-E', caddyPath, 'run', '--config', caddyFilePath, '--watch'])
281
272
  : spawn(caddyPath, ['run', '--config', caddyFilePath, '--watch'])
282
273
 
283
274
  lockfile.lockSync(caddyLockFilePath)
284
275
 
285
- this.caddyChild!.on('error', (err) => {
276
+ this._caddyChild!.on('error', (err) => {
286
277
  return reject(err)
287
278
  })
288
279
 
289
- this.caddyChild!.stderr?.on('data', (data) => {
280
+ this._caddyChild!.stderr?.on('data', (data) => {
290
281
  const lines = (data.toString() as string).split('\n').map(line => line.trim())
291
282
  for (const line of lines) {
292
283
  // caddy log
@@ -305,7 +296,7 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
305
296
  }
306
297
  })
307
298
 
308
- this.caddyChild!.stdout?.on('data', (_data) => {
299
+ this._caddyChild!.stdout?.on('data', (_data) => {
309
300
  consola.info(_data.toString())
310
301
  resolve()
311
302
  })
@@ -322,16 +313,29 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
322
313
  })
323
314
  }
324
315
 
325
- async baseCleanup() {
326
- if (!this.locked) {
327
- this.caddyChild?.kill()
316
+ async baseCleanup(restore: boolean = true) {
317
+ try {
318
+ if (restore && this._source && this._target) {
319
+ if (await removeHost(this._source.split(':')[0], this._target.split(':')[0]))
320
+ consola.success('Restore host success.\n')
321
+
322
+ else
323
+ consola.fail('Restore host failed.\n')
324
+ }
325
+ }
326
+ catch (e) {
327
+ consola.error(e)
328
+ consola.fail('Restore host failed.\n')
329
+ }
330
+ if (!this.locked && !this.stoped) {
331
+ this._caddyChild?.kill()
328
332
  try {
329
- await lockfile.unlock(caddyLockFilePath)
330
- await unlink(caddyFilePath)
331
- await unlink(caddyLockFilePath)
333
+ await lockfile.unlock(caddyLockFilePath).catch(() => { })
334
+ await unlink(caddyFilePath).catch(() => { })
335
+ await unlink(caddyLockFilePath).catch(() => { })
332
336
  }
333
337
  catch (e) {
334
- // consola.error(e)
338
+ consola.error(e)
335
339
  }
336
340
  }
337
341
  }