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

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/esbuild.cjs CHANGED
@@ -639,4 +639,4 @@ var unpluginFactory = (options) => ({
639
639
 
640
640
  // src/esbuild.ts
641
641
  var esbuild_default = (0, import_unplugin2.createEsbuildPlugin)(unpluginFactory);
642
- exports.default = module.exports;
642
+ module.exports = module.exports;exports.default = module.exports;
package/dist/index.cjs CHANGED
@@ -644,4 +644,4 @@ var src_default = unplugin;
644
644
  unpluginFactory,
645
645
  vitePrintUrls
646
646
  });
647
- exports.default = module.exports;
647
+ module.exports = module.exports;exports.default = module.exports;
package/dist/nuxt.cjs CHANGED
@@ -552,4 +552,4 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
552
552
  });
553
553
  }
554
554
  });
555
- exports.default = module.exports;
555
+ module.exports = module.exports;exports.default = module.exports;
package/dist/rollup.cjs CHANGED
@@ -639,4 +639,4 @@ var unpluginFactory = (options) => ({
639
639
 
640
640
  // src/rollup.ts
641
641
  var rollup_default = (0, import_unplugin2.createRollupPlugin)(unpluginFactory);
642
- exports.default = module.exports;
642
+ module.exports = module.exports;exports.default = module.exports;
package/dist/rspack.cjs CHANGED
@@ -640,4 +640,4 @@ var src_default = unplugin;
640
640
 
641
641
  // src/rspack.ts
642
642
  var rspack_default = src_default.rspack;
643
- exports.default = module.exports;
643
+ module.exports = module.exports;exports.default = module.exports;
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
@@ -639,4 +639,4 @@ var unpluginFactory = (options) => ({
639
639
 
640
640
  // src/vite.ts
641
641
  var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
642
- exports.default = module.exports;
642
+ module.exports = module.exports;exports.default = module.exports;
package/dist/webpack.cjs CHANGED
@@ -639,4 +639,4 @@ var unpluginFactory = (options) => ({
639
639
 
640
640
  // src/webpack.ts
641
641
  var webpack_default = (0, import_unplugin2.createWebpackPlugin)(unpluginFactory);
642
- exports.default = module.exports;
642
+ module.exports = module.exports;exports.default = module.exports;
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.10",
4
+ "version": "1.0.0-beta.12",
5
5
  "packageManager": "pnpm@8.15.3",
6
6
  "description": "",
7
7
  "license": "MIT",
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "files": [
78
78
  "dist",
79
- "scripts/postinstall.ts",
79
+ "scripts/postinstall.cjs",
80
80
  "src"
81
81
  ],
82
82
  "peerDependencies": {
@@ -151,7 +151,7 @@
151
151
  "webpack": "^5.90.3"
152
152
  },
153
153
  "scripts": {
154
- "postinstall": "tsx scripts/postinstall.ts",
154
+ "postinstall": "node scripts/postinstall.cjs",
155
155
  "build": "tsup",
156
156
  "dev": "tsup --watch src",
157
157
  "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();
@@ -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()