unplugin-https-reverse-proxy 1.0.0-beta.10 → 1.0.0-beta.13

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.
@@ -351,6 +351,22 @@ var CaddyInstant = class {
351
351
  child.on("error", (err) => {
352
352
  return reject(err);
353
353
  });
354
+ child.stderr.on("data", (data) => {
355
+ const lines = data.toString().split("\n").map((line) => line.trim());
356
+ for (const line of lines) {
357
+ showCaddyLog && line && console.info(line);
358
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
359
+ consola.error(line);
360
+ return reject(line);
361
+ }
362
+ if (line.includes("caddy proxying"))
363
+ return resolve();
364
+ }
365
+ });
366
+ child.stdout.on("data", (_data) => {
367
+ consola.info(_data.toString());
368
+ resolve();
369
+ });
354
370
  process3.on("SIGINT", async () => {
355
371
  if (!restore || this.stoped)
356
372
  return;
@@ -401,20 +417,6 @@ var CaddyInstant = class {
401
417
  });
402
418
  }
403
419
  };
404
- child.stderr.on("data", (data) => {
405
- const lines = data.toString().split("\n").map((line) => line.trim());
406
- for (const line of lines) {
407
- showCaddyLog && line && console.info(line);
408
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
409
- consola.error(line);
410
- return reject(line);
411
- }
412
- }
413
- });
414
- child.stdout.on("data", (_data) => {
415
- consola.info(_data.toString());
416
- resolve();
417
- });
418
420
  });
419
421
  }
420
422
  };
package/dist/esbuild.cjs CHANGED
@@ -433,6 +433,22 @@ var CaddyInstant = class {
433
433
  child.on("error", (err) => {
434
434
  return reject(err);
435
435
  });
436
+ child.stderr.on("data", (data) => {
437
+ const lines = data.toString().split("\n").map((line) => line.trim());
438
+ for (const line of lines) {
439
+ showCaddyLog && line && console.info(line);
440
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
441
+ consola.error(line);
442
+ return reject(line);
443
+ }
444
+ if (line.includes("caddy proxying"))
445
+ return resolve();
446
+ }
447
+ });
448
+ child.stdout.on("data", (_data) => {
449
+ consola.info(_data.toString());
450
+ resolve();
451
+ });
436
452
  import_node_process4.default.on("SIGINT", async () => {
437
453
  if (!restore || this.stoped)
438
454
  return;
@@ -483,20 +499,6 @@ var CaddyInstant = class {
483
499
  });
484
500
  }
485
501
  };
486
- child.stderr.on("data", (data) => {
487
- const lines = data.toString().split("\n").map((line) => line.trim());
488
- for (const line of lines) {
489
- showCaddyLog && line && console.info(line);
490
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
491
- consola.error(line);
492
- return reject(line);
493
- }
494
- }
495
- });
496
- child.stdout.on("data", (_data) => {
497
- consola.info(_data.toString());
498
- resolve();
499
- });
500
502
  });
501
503
  }
502
504
  };
@@ -639,4 +641,4 @@ var unpluginFactory = (options) => ({
639
641
 
640
642
  // src/esbuild.ts
641
643
  var esbuild_default = (0, import_unplugin2.createEsbuildPlugin)(unpluginFactory);
642
- exports.default = module.exports;
644
+ module.exports = module.exports;exports.default = module.exports;
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -433,6 +433,22 @@ var CaddyInstant = class {
433
433
  child.on("error", (err) => {
434
434
  return reject(err);
435
435
  });
436
+ child.stderr.on("data", (data) => {
437
+ const lines = data.toString().split("\n").map((line) => line.trim());
438
+ for (const line of lines) {
439
+ showCaddyLog && line && console.info(line);
440
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
441
+ consola.error(line);
442
+ return reject(line);
443
+ }
444
+ if (line.includes("caddy proxying"))
445
+ return resolve();
446
+ }
447
+ });
448
+ child.stdout.on("data", (_data) => {
449
+ consola.info(_data.toString());
450
+ resolve();
451
+ });
436
452
  import_node_process4.default.on("SIGINT", async () => {
437
453
  if (!restore || this.stoped)
438
454
  return;
@@ -483,20 +499,6 @@ var CaddyInstant = class {
483
499
  });
484
500
  }
485
501
  };
486
- child.stderr.on("data", (data) => {
487
- const lines = data.toString().split("\n").map((line) => line.trim());
488
- for (const line of lines) {
489
- showCaddyLog && line && console.info(line);
490
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
491
- consola.error(line);
492
- return reject(line);
493
- }
494
- }
495
- });
496
- child.stdout.on("data", (_data) => {
497
- consola.info(_data.toString());
498
- resolve();
499
- });
500
502
  });
501
503
  }
502
504
  };
@@ -644,4 +646,4 @@ var src_default = unplugin;
644
646
  unpluginFactory,
645
647
  vitePrintUrls
646
648
  });
647
- exports.default = module.exports;
649
+ module.exports = module.exports;exports.default = module.exports;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-XLSIGDFU.js";
6
+ } from "./chunk-MMFIKYNA.js";
7
7
  import "./chunk-RUJE3YFB.js";
8
8
  export {
9
9
  src_default as default,
package/dist/nuxt.cjs CHANGED
@@ -435,6 +435,22 @@ var CaddyInstant = class {
435
435
  child.on("error", (err) => {
436
436
  return reject(err);
437
437
  });
438
+ child.stderr.on("data", (data) => {
439
+ const lines = data.toString().split("\n").map((line) => line.trim());
440
+ for (const line of lines) {
441
+ showCaddyLog && line && console.info(line);
442
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
443
+ consola.error(line);
444
+ return reject(line);
445
+ }
446
+ if (line.includes("caddy proxying"))
447
+ return resolve();
448
+ }
449
+ });
450
+ child.stdout.on("data", (_data) => {
451
+ consola.info(_data.toString());
452
+ resolve();
453
+ });
438
454
  import_node_process4.default.on("SIGINT", async () => {
439
455
  if (!restore || this.stoped)
440
456
  return;
@@ -485,20 +501,6 @@ var CaddyInstant = class {
485
501
  });
486
502
  }
487
503
  };
488
- child.stderr.on("data", (data) => {
489
- const lines = data.toString().split("\n").map((line) => line.trim());
490
- for (const line of lines) {
491
- showCaddyLog && line && console.info(line);
492
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
493
- consola.error(line);
494
- return reject(line);
495
- }
496
- }
497
- });
498
- child.stdout.on("data", (_data) => {
499
- consola.info(_data.toString());
500
- resolve();
501
- });
502
504
  });
503
505
  }
504
506
  };
@@ -552,4 +554,4 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
552
554
  });
553
555
  }
554
556
  });
555
- exports.default = module.exports;
557
+ module.exports = module.exports;exports.default = module.exports;
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import {
5
5
  consola,
6
6
  isAdmin
package/dist/rollup.cjs CHANGED
@@ -433,6 +433,22 @@ var CaddyInstant = class {
433
433
  child.on("error", (err) => {
434
434
  return reject(err);
435
435
  });
436
+ child.stderr.on("data", (data) => {
437
+ const lines = data.toString().split("\n").map((line) => line.trim());
438
+ for (const line of lines) {
439
+ showCaddyLog && line && console.info(line);
440
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
441
+ consola.error(line);
442
+ return reject(line);
443
+ }
444
+ if (line.includes("caddy proxying"))
445
+ return resolve();
446
+ }
447
+ });
448
+ child.stdout.on("data", (_data) => {
449
+ consola.info(_data.toString());
450
+ resolve();
451
+ });
436
452
  import_node_process4.default.on("SIGINT", async () => {
437
453
  if (!restore || this.stoped)
438
454
  return;
@@ -483,20 +499,6 @@ var CaddyInstant = class {
483
499
  });
484
500
  }
485
501
  };
486
- child.stderr.on("data", (data) => {
487
- const lines = data.toString().split("\n").map((line) => line.trim());
488
- for (const line of lines) {
489
- showCaddyLog && line && console.info(line);
490
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
491
- consola.error(line);
492
- return reject(line);
493
- }
494
- }
495
- });
496
- child.stdout.on("data", (_data) => {
497
- consola.info(_data.toString());
498
- resolve();
499
- });
500
502
  });
501
503
  }
502
504
  };
@@ -639,4 +641,4 @@ var unpluginFactory = (options) => ({
639
641
 
640
642
  // src/rollup.ts
641
643
  var rollup_default = (0, import_unplugin2.createRollupPlugin)(unpluginFactory);
642
- exports.default = module.exports;
644
+ module.exports = module.exports;exports.default = module.exports;
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -432,6 +432,22 @@ var CaddyInstant = class {
432
432
  child.on("error", (err) => {
433
433
  return reject(err);
434
434
  });
435
+ child.stderr.on("data", (data) => {
436
+ const lines = data.toString().split("\n").map((line) => line.trim());
437
+ for (const line of lines) {
438
+ showCaddyLog && line && console.info(line);
439
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
440
+ consola.error(line);
441
+ return reject(line);
442
+ }
443
+ if (line.includes("caddy proxying"))
444
+ return resolve();
445
+ }
446
+ });
447
+ child.stdout.on("data", (_data) => {
448
+ consola.info(_data.toString());
449
+ resolve();
450
+ });
435
451
  import_node_process4.default.on("SIGINT", async () => {
436
452
  if (!restore || this.stoped)
437
453
  return;
@@ -482,20 +498,6 @@ var CaddyInstant = class {
482
498
  });
483
499
  }
484
500
  };
485
- child.stderr.on("data", (data) => {
486
- const lines = data.toString().split("\n").map((line) => line.trim());
487
- for (const line of lines) {
488
- showCaddyLog && line && console.info(line);
489
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
490
- consola.error(line);
491
- return reject(line);
492
- }
493
- }
494
- });
495
- child.stdout.on("data", (_data) => {
496
- consola.info(_data.toString());
497
- resolve();
498
- });
499
501
  });
500
502
  }
501
503
  };
@@ -640,4 +642,4 @@ var src_default = unplugin;
640
642
 
641
643
  // src/rspack.ts
642
644
  var rspack_default = src_default.rspack;
643
- exports.default = module.exports;
645
+ module.exports = module.exports;exports.default = module.exports;
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/rspack.ts
package/dist/types.cjs CHANGED
@@ -16,4 +16,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  // src/types.ts
17
17
  var types_exports = {};
18
18
  module.exports = __toCommonJS(types_exports);
19
- exports.default = module.exports;
19
+ module.exports = module.exports;exports.default = module.exports;
package/dist/utils.cjs CHANGED
@@ -80,4 +80,4 @@ function isAdmin() {
80
80
  isAdmin,
81
81
  once
82
82
  });
83
- exports.default = module.exports;
83
+ module.exports = module.exports;exports.default = module.exports;
package/dist/vite.cjs CHANGED
@@ -433,6 +433,22 @@ var CaddyInstant = class {
433
433
  child.on("error", (err) => {
434
434
  return reject(err);
435
435
  });
436
+ child.stderr.on("data", (data) => {
437
+ const lines = data.toString().split("\n").map((line) => line.trim());
438
+ for (const line of lines) {
439
+ showCaddyLog && line && console.info(line);
440
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
441
+ consola.error(line);
442
+ return reject(line);
443
+ }
444
+ if (line.includes("caddy proxying"))
445
+ return resolve();
446
+ }
447
+ });
448
+ child.stdout.on("data", (_data) => {
449
+ consola.info(_data.toString());
450
+ resolve();
451
+ });
436
452
  import_node_process4.default.on("SIGINT", async () => {
437
453
  if (!restore || this.stoped)
438
454
  return;
@@ -483,20 +499,6 @@ var CaddyInstant = class {
483
499
  });
484
500
  }
485
501
  };
486
- child.stderr.on("data", (data) => {
487
- const lines = data.toString().split("\n").map((line) => line.trim());
488
- for (const line of lines) {
489
- showCaddyLog && line && console.info(line);
490
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
491
- consola.error(line);
492
- return reject(line);
493
- }
494
- }
495
- });
496
- child.stdout.on("data", (_data) => {
497
- consola.info(_data.toString());
498
- resolve();
499
- });
500
502
  });
501
503
  }
502
504
  };
@@ -639,4 +641,4 @@ var unpluginFactory = (options) => ({
639
641
 
640
642
  // src/vite.ts
641
643
  var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
642
- exports.default = module.exports;
644
+ module.exports = module.exports;exports.default = module.exports;
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/vite.ts
package/dist/webpack.cjs CHANGED
@@ -433,6 +433,22 @@ var CaddyInstant = class {
433
433
  child.on("error", (err) => {
434
434
  return reject(err);
435
435
  });
436
+ child.stderr.on("data", (data) => {
437
+ const lines = data.toString().split("\n").map((line) => line.trim());
438
+ for (const line of lines) {
439
+ showCaddyLog && line && console.info(line);
440
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
441
+ consola.error(line);
442
+ return reject(line);
443
+ }
444
+ if (line.includes("caddy proxying"))
445
+ return resolve();
446
+ }
447
+ });
448
+ child.stdout.on("data", (_data) => {
449
+ consola.info(_data.toString());
450
+ resolve();
451
+ });
436
452
  import_node_process4.default.on("SIGINT", async () => {
437
453
  if (!restore || this.stoped)
438
454
  return;
@@ -483,20 +499,6 @@ var CaddyInstant = class {
483
499
  });
484
500
  }
485
501
  };
486
- child.stderr.on("data", (data) => {
487
- const lines = data.toString().split("\n").map((line) => line.trim());
488
- for (const line of lines) {
489
- showCaddyLog && line && console.info(line);
490
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
491
- consola.error(line);
492
- return reject(line);
493
- }
494
- }
495
- });
496
- child.stdout.on("data", (_data) => {
497
- consola.info(_data.toString());
498
- resolve();
499
- });
500
502
  });
501
503
  }
502
504
  };
@@ -639,4 +641,4 @@ var unpluginFactory = (options) => ({
639
641
 
640
642
  // src/webpack.ts
641
643
  var webpack_default = (0, import_unplugin2.createWebpackPlugin)(unpluginFactory);
642
- exports.default = module.exports;
644
+ module.exports = module.exports;exports.default = module.exports;
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-XLSIGDFU.js";
3
+ } from "./chunk-MMFIKYNA.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/webpack.ts
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-https-reverse-proxy",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.10",
5
- "packageManager": "pnpm@8.15.3",
4
+ "version": "1.0.0-beta.13",
6
5
  "description": "",
7
6
  "license": "MIT",
8
7
  "homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
@@ -76,7 +75,7 @@
76
75
  },
77
76
  "files": [
78
77
  "dist",
79
- "scripts/postinstall.ts",
78
+ "scripts/postinstall.cjs",
80
79
  "src"
81
80
  ],
82
81
  "peerDependencies": {
@@ -151,7 +150,7 @@
151
150
  "webpack": "^5.90.3"
152
151
  },
153
152
  "scripts": {
154
- "postinstall": "tsx scripts/postinstall.ts",
153
+ "postinstall": "node scripts/postinstall.cjs",
155
154
  "build": "tsup",
156
155
  "dev": "tsup --watch src",
157
156
  "build:fix": "tsx scripts/postbuild.ts",
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // scripts/postinstall.ts
26
+ var import_node_fs3 = require("fs");
27
+ var import_node_process5 = __toESM(require("process"), 1);
28
+
29
+ // src/utils.ts
30
+ var import_node_process = __toESM(require("process"), 1);
31
+ var import_node_path = __toESM(require("path"), 1);
32
+ var import_promises = require("fs/promises");
33
+ var import_node_child_process = require("child_process");
34
+ var import_consola = require("consola");
35
+ var consola = (0, import_consola.createConsola)({
36
+ level: 3
37
+ }).withTag("reverse-proxy");
38
+ function once(fn) {
39
+ let called = false;
40
+ return (...args) => {
41
+ if (called)
42
+ return;
43
+ called = true;
44
+ return fn(...args);
45
+ };
46
+ }
47
+
48
+ // src/caddy/index.ts
49
+ var import_node_os2 = require("os");
50
+ var import_node_process4 = __toESM(require("process"), 1);
51
+ var import_node_fs2 = require("fs");
52
+ var import_node_child_process3 = require("child_process");
53
+ var import_got_cjs = require("got-cjs");
54
+ var import_http_proxy_agent = require("http-proxy-agent");
55
+ var import_https_proxy_agent = require("https-proxy-agent");
56
+ var import_kill_port = __toESM(require("kill-port"), 1);
57
+
58
+ // src/host/index.ts
59
+ var import_node_process2 = __toESM(require("process"), 1);
60
+ var import_node_child_process2 = require("child_process");
61
+ var import_node_fs = require("fs");
62
+ var import_hosts_so_easy = __toESM(require("hosts-so-easy"), 1);
63
+ var Hosts = import_hosts_so_easy.default.default || import_hosts_so_easy.default;
64
+ var hostInstance = new Hosts({
65
+ debounceTime: 50,
66
+ hostsFile: getPathOfSystemHostsPath()
67
+ });
68
+ function getPathOfSystemHostsPath() {
69
+ return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
70
+ }
71
+
72
+ // src/caddy/constants.ts
73
+ var import_node_path2 = require("path");
74
+ var import_node_os = __toESM(require("os"), 1);
75
+ var import_node_process3 = __toESM(require("process"), 1);
76
+ var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
77
+ import_dotenv_flow.default.config({
78
+ silent: true
79
+ });
80
+ function resolvePath(path2) {
81
+ if (path2.startsWith("~"))
82
+ return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
83
+ return path2;
84
+ }
85
+ var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
86
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
87
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
88
+ var supportList = [
89
+ {
90
+ platform: "dragonfly",
91
+ arch: "amd64"
92
+ },
93
+ {
94
+ platform: "freebsd",
95
+ arch: "amd64"
96
+ },
97
+ {
98
+ platform: "freebsd",
99
+ arch: "arm-6"
100
+ },
101
+ {
102
+ platform: "freebsd",
103
+ arch: "arm-7"
104
+ },
105
+ {
106
+ platform: "freebsd",
107
+ arch: "arm64"
108
+ },
109
+ {
110
+ platform: "linux",
111
+ arch: "amd64"
112
+ },
113
+ {
114
+ platform: "linux",
115
+ arch: "arm-5"
116
+ },
117
+ {
118
+ platform: "linux",
119
+ arch: "arm-6"
120
+ },
121
+ {
122
+ platform: "linux",
123
+ arch: "arm-7"
124
+ },
125
+ {
126
+ platform: "linux",
127
+ arch: "arm64"
128
+ },
129
+ {
130
+ platform: "linux",
131
+ arch: "mips"
132
+ },
133
+ {
134
+ platform: "linux",
135
+ arch: "mips64"
136
+ },
137
+ {
138
+ platform: "linux",
139
+ arch: "mips64le"
140
+ },
141
+ {
142
+ platform: "linux",
143
+ arch: "mipsle"
144
+ },
145
+ {
146
+ platform: "linux",
147
+ arch: "ppc64"
148
+ },
149
+ {
150
+ platform: "linux",
151
+ arch: "ppc64le"
152
+ },
153
+ {
154
+ platform: "linux",
155
+ arch: "s390x"
156
+ },
157
+ {
158
+ platform: "darwin",
159
+ arch: "amd64"
160
+ },
161
+ {
162
+ platform: "darwin",
163
+ arch: "arm64"
164
+ },
165
+ {
166
+ platform: "openbsd",
167
+ arch: "amd64"
168
+ },
169
+ {
170
+ platform: "openbsd",
171
+ arch: "arm-6"
172
+ },
173
+ {
174
+ platform: "openbsd",
175
+ arch: "arm-7"
176
+ },
177
+ {
178
+ platform: "openbsd",
179
+ arch: "arm64"
180
+ },
181
+ {
182
+ platform: "windows",
183
+ arch: "amd64"
184
+ },
185
+ {
186
+ platform: "windows",
187
+ arch: "arm-6"
188
+ },
189
+ {
190
+ platform: "windows",
191
+ arch: "arm-7"
192
+ },
193
+ {
194
+ platform: "windows",
195
+ arch: "arm64"
196
+ }
197
+ ];
198
+
199
+ // src/caddy/utils.ts
200
+ var import_node_net = require("net");
201
+ var import_ora = __toESM(require("ora"), 1);
202
+ var spinner;
203
+ function getNumber(number) {
204
+ if (number <= 0)
205
+ return "0%";
206
+ else if (number < 100)
207
+ return `${number.toFixed(2)}%`;
208
+ else
209
+ return "100%";
210
+ }
211
+ function logProgress(percent) {
212
+ if (!spinner) {
213
+ consola.log("");
214
+ spinner = (0, import_ora.default)({
215
+ text: "Start Download Caddy: 0%",
216
+ indent: 2
217
+ });
218
+ spinner.start();
219
+ } else {
220
+ spinner.text = `Download Caddy: ${getNumber(Number(percent) * 100)}`;
221
+ }
222
+ }
223
+ function logProgressOver() {
224
+ if (!spinner) {
225
+ spinner = (0, import_ora.default)({
226
+ text: "Start Download Caddy: 100%",
227
+ indent: 2
228
+ });
229
+ spinner.start();
230
+ } else {
231
+ spinner.succeed();
232
+ consola.log("");
233
+ }
234
+ }
235
+
236
+ // src/caddy/index.ts
237
+ async function download() {
238
+ if (await testCaddy())
239
+ return caddyPath;
240
+ return new Promise((resolve, reject) => {
241
+ if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
242
+ (0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
243
+ (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
244
+ }
245
+ const file = (0, import_node_fs2.createWriteStream)(caddyPath);
246
+ let _platform = (0, import_node_os2.platform)().toString();
247
+ _platform === "win32" && (_platform = "windows");
248
+ let _arch = import_node_process4.default.arch.toString();
249
+ _arch === "x64" && (_arch = "amd64");
250
+ const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
251
+ if (!support)
252
+ return reject(new Error("not support"));
253
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
254
+ (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
255
+ const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
256
+ const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
257
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
258
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
259
+ const chmodCaddyOnce = once(() => {
260
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
261
+ });
262
+ import_got_cjs.got.stream(dowmloadLink, {
263
+ agent: {
264
+ http: httpAgent,
265
+ https: httpsAgent
266
+ }
267
+ }).on("downloadProgress", (progress) => {
268
+ logProgress(progress.percent);
269
+ chmodCaddyOnce();
270
+ }).pipe(file).on("finish", () => {
271
+ logProgressOver();
272
+ if (import_node_process4.default.platform === "win32")
273
+ return resolve(caddyPath);
274
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
275
+ resolve(caddyPath);
276
+ }).on("error", (err) => {
277
+ reject(err);
278
+ });
279
+ });
280
+ }
281
+ function testCaddy() {
282
+ return new Promise((resolve, reject) => {
283
+ if (!(0, import_node_fs2.existsSync)(caddyPath))
284
+ return resolve(false);
285
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
286
+ const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process3.spawn)(caddyPath, []) : (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath]);
287
+ child.on("close", () => {
288
+ return resolve(false);
289
+ });
290
+ child.on("error", (err) => {
291
+ return reject(err);
292
+ });
293
+ child.stdout.on("data", (_data) => {
294
+ return resolve(true);
295
+ });
296
+ });
297
+ }
298
+
299
+ // scripts/postinstall.ts
300
+ async function run() {
301
+ try {
302
+ if (import_node_process5.default.env.UHRP_AUTO_INSTALL_CADDY) {
303
+ (0, import_node_fs3.existsSync)(caddyPath) && (0, import_node_fs3.unlinkSync)(caddyPath);
304
+ await download();
305
+ }
306
+ } catch (e) {
307
+ consola.error(e.code);
308
+ }
309
+ }
310
+ run();
@@ -150,6 +150,27 @@ export class CaddyInstant {
150
150
  return reject(err)
151
151
  })
152
152
 
153
+ child.stderr.on('data', (data) => {
154
+ const lines = (data.toString() as string).split('\n').map(line => line.trim())
155
+ for (const line of lines) {
156
+ // caddy log
157
+ // eslint-disable-next-line no-console
158
+ showCaddyLog && line && console.info(line)
159
+ if (line.includes('Error:') || (line && JSON.parse(line).level === 'error')) {
160
+ consola.error(line)
161
+ // child.kill()
162
+ return reject(line)
163
+ }
164
+ if (line.includes('caddy proxying'))
165
+ return resolve()
166
+ }
167
+ })
168
+
169
+ child.stdout.on('data', (_data) => {
170
+ consola.info(_data.toString())
171
+ resolve()
172
+ })
173
+
153
174
  process.on('SIGINT', async () => {
154
175
  if (!restore || this.stoped)
155
176
  return
@@ -214,25 +235,6 @@ export class CaddyInstant {
214
235
  })
215
236
  }
216
237
  }
217
-
218
- child.stderr.on('data', (data) => {
219
- const lines = (data.toString() as string).split('\n').map(line => line.trim())
220
- for (const line of lines) {
221
- // caddy log
222
- // eslint-disable-next-line no-console
223
- showCaddyLog && line && console.info(line)
224
- if (line.includes('Error:') || (line && JSON.parse(line).level === 'error')) {
225
- consola.error(line)
226
- // child.kill()
227
- return reject(line)
228
- }
229
- }
230
- })
231
-
232
- child.stdout.on('data', (_data) => {
233
- consola.info(_data.toString())
234
- resolve()
235
- })
236
238
  })
237
239
  }
238
240
  }
@@ -1,19 +0,0 @@
1
- import { existsSync, unlinkSync } from 'node:fs'
2
- import process from 'node:process'
3
- import { consola } from '../src/utils'
4
- import { download } from '../src/caddy'
5
- import { caddyPath } from '../src/caddy/constants'
6
-
7
- async function run() {
8
- try {
9
- if (process.env.UHRP_AUTO_INSTALL_CADDY) {
10
- existsSync(caddyPath) && unlinkSync(caddyPath)
11
- await download()
12
- }
13
- }
14
- catch (e: any) {
15
- consola.error(e.code)
16
- }
17
- }
18
-
19
- run()