unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.21

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/webpack.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import {
2
- webpack_default
3
- } from "./chunk-VGLXVBHU.js";
4
- import "./chunk-N6ZBBGYD.js";
5
- import "./chunk-RUJE3YFB.js";
2
+ unpluginFactory
3
+ } from "./chunk-KVE7AVSI.js";
4
+ import "./chunk-2VGRJ3QS.js";
5
+
6
+ // src/webpack.ts
7
+ import { createWebpackPlugin } from "unplugin";
8
+ var webpack_default = createWebpackPlugin(unpluginFactory);
6
9
  export {
7
10
  webpack_default as default
8
11
  };
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.2",
5
- "packageManager": "pnpm@8.6.12",
4
+ "version": "1.0.0-beta.21",
6
5
  "description": "",
7
6
  "license": "MIT",
8
7
  "homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
@@ -36,6 +35,11 @@
36
35
  "import": "./dist/webpack.js",
37
36
  "require": "./dist/webpack.cjs"
38
37
  },
38
+ "./rspack": {
39
+ "types": "./dist/rspack.d.ts",
40
+ "import": "./dist/rspack.js",
41
+ "require": "./dist/rspack.cjs"
42
+ },
39
43
  "./rollup": {
40
44
  "types": "./dist/rollup.d.ts",
41
45
  "import": "./dist/rollup.js",
@@ -71,13 +75,16 @@
71
75
  },
72
76
  "files": [
73
77
  "dist",
74
- "scripts/postinstall.ts",
78
+ "scripts/postinstall.cjs",
75
79
  "src"
76
80
  ],
77
81
  "peerDependencies": {
78
82
  "@nuxt/kit": "^3",
79
83
  "@nuxt/schema": "^3",
84
+ "@rsbuild/core": "^0.4.3",
85
+ "@rspack/core": "^0.5.4",
80
86
  "esbuild": "*",
87
+ "proper-lockfile": "^4.1.2",
81
88
  "rollup": "^3",
82
89
  "vite": ">=3",
83
90
  "webpack": "^4 || ^5"
@@ -86,6 +93,12 @@
86
93
  "webpack": {
87
94
  "optional": true
88
95
  },
96
+ "@rspack/core": {
97
+ "optional": true
98
+ },
99
+ "@rsbuild/core": {
100
+ "optional": true
101
+ },
89
102
  "rollup": {
90
103
  "optional": true
91
104
  },
@@ -104,48 +117,55 @@
104
117
  },
105
118
  "dependencies": {
106
119
  "consola": "^3.2.3",
107
- "esno": "^0.17.0",
120
+ "dotenv-flow": "^4.1.0",
108
121
  "got-cjs": "^12.5.4",
109
- "hosts-so-easy": "^1.2.9",
110
- "http-proxy-agent": "^7.0.0",
111
- "https-proxy-agent": "^7.0.2",
112
- "kill-port": "^2.0.1",
122
+ "hostile": "^1.4.0",
123
+ "http-proxy-agent": "^7.0.2",
124
+ "https-proxy-agent": "^7.0.4",
113
125
  "ora": "5",
114
126
  "picocolors": "^1.0.0",
115
- "unplugin": "^1.4.0"
127
+ "tsx": "^4.7.1",
128
+ "unplugin": "^1.7.1"
116
129
  },
117
130
  "devDependencies": {
118
- "@antfu/eslint-config": "^0.40.2",
119
- "@nuxt/kit": "^3.6.5",
120
- "@nuxt/schema": "^3.6.5",
131
+ "@antfu/eslint-config": "^0.40.3",
132
+ "@nuxt/kit": "^3.10.2",
133
+ "@nuxt/schema": "^3.10.2",
134
+ "@rsbuild/core": "^0.4.3",
135
+ "@rspack/core": "^0.5.4",
136
+ "@types/hostile": "^1.3.5",
121
137
  "@types/kill-port": "^2.0.3",
122
- "@types/node": "^20.5.2",
138
+ "@types/node": "^20.11.19",
139
+ "@types/proper-lockfile": "^4.1.4",
123
140
  "@vue/cli": "^5.0.8",
124
- "bumpp": "^9.2.0",
141
+ "bumpp": "^9.3.0",
125
142
  "chalk": "^5.3.0",
126
- "eslint": "^8.47.0",
127
- "fast-glob": "^3.3.1",
128
- "nodemon": "^3.0.1",
129
- "rimraf": "^5.0.1",
130
- "rollup": "^3.28.1",
131
- "tsup": "^7.2.0",
132
- "typescript": "^5.1.6",
133
- "vite": "^4.4.9",
134
- "vitest": "^0.34.2",
135
- "webpack": "^5.88.2"
143
+ "cross-env": "^7.0.3",
144
+ "eslint": "^8.56.0",
145
+ "fast-glob": "^3.3.2",
146
+ "nodemon": "^3.0.3",
147
+ "proper-lockfile": "^4.1.2",
148
+ "rimraf": "^5.0.5",
149
+ "rollup": "^3.29.4",
150
+ "tsup": "^7.3.0",
151
+ "typescript": "^5.3.3",
152
+ "vite": "^4.5.2",
153
+ "vitest": "^2.0.5",
154
+ "webpack": "^5.90.3"
136
155
  },
137
156
  "scripts": {
138
- "postinstall": "esno scripts/postinstall.ts",
157
+ "postinstall": "node scripts/postinstall.cjs",
139
158
  "build": "tsup",
140
159
  "dev": "tsup --watch src",
141
- "build:fix": "esno scripts/postbuild.ts",
160
+ "build:fix": "tsx scripts/postbuild.ts",
142
161
  "lint": "eslint .",
143
162
  "play": "npm -C examples/vite run dev",
163
+ "play:rsbuild": "npm -C examples/rsbuild run dev",
144
164
  "play:nuxt": "npm -C examples/nuxt run dev",
145
165
  "play:vuecli": "npm -C examples/vuecli run serve",
146
166
  "play:vuecli4": "npm -C examples/vuecli4 run serve",
147
167
  "release": "bumpp",
148
- "start": "esno src/index.ts",
149
- "test": "vitest"
168
+ "start": "tsx src/index.ts",
169
+ "test": "cross-env UHRP_CADDY_PATH='./test/.uhrp' vitest"
150
170
  }
151
171
  }
@@ -0,0 +1,308 @@
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_process4 = require("child_process");
53
+ var import_promises2 = require("fs/promises");
54
+ var import_got_cjs = require("got-cjs");
55
+ var import_http_proxy_agent = require("http-proxy-agent");
56
+ var import_https_proxy_agent = require("https-proxy-agent");
57
+ var lockfile = __toESM(require("proper-lockfile"), 1);
58
+
59
+ // src/host/index.ts
60
+ var import_node_process2 = __toESM(require("process"), 1);
61
+ var import_node_child_process2 = require("child_process");
62
+ var import_node_fs = require("fs");
63
+ var import_node_util = require("util");
64
+ var import_hostile = __toESM(require("hostile"), 1);
65
+ var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
66
+ var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
67
+
68
+ // src/caddy/constants.ts
69
+ var import_node_path2 = require("path");
70
+ var import_node_os = __toESM(require("os"), 1);
71
+ var import_node_process3 = __toESM(require("process"), 1);
72
+ var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
73
+ import_dotenv_flow.default.config({
74
+ silent: true
75
+ });
76
+ function resolvePath(path2) {
77
+ if (path2.startsWith("~"))
78
+ return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
79
+ return path2;
80
+ }
81
+ 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");
82
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
83
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
84
+ var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
85
+ var supportList = [
86
+ {
87
+ platform: "dragonfly",
88
+ arch: "amd64"
89
+ },
90
+ {
91
+ platform: "freebsd",
92
+ arch: "amd64"
93
+ },
94
+ {
95
+ platform: "freebsd",
96
+ arch: "arm-6"
97
+ },
98
+ {
99
+ platform: "freebsd",
100
+ arch: "arm-7"
101
+ },
102
+ {
103
+ platform: "freebsd",
104
+ arch: "arm64"
105
+ },
106
+ {
107
+ platform: "linux",
108
+ arch: "amd64"
109
+ },
110
+ {
111
+ platform: "linux",
112
+ arch: "arm-5"
113
+ },
114
+ {
115
+ platform: "linux",
116
+ arch: "arm-6"
117
+ },
118
+ {
119
+ platform: "linux",
120
+ arch: "arm-7"
121
+ },
122
+ {
123
+ platform: "linux",
124
+ arch: "arm64"
125
+ },
126
+ {
127
+ platform: "linux",
128
+ arch: "mips"
129
+ },
130
+ {
131
+ platform: "linux",
132
+ arch: "mips64"
133
+ },
134
+ {
135
+ platform: "linux",
136
+ arch: "mips64le"
137
+ },
138
+ {
139
+ platform: "linux",
140
+ arch: "mipsle"
141
+ },
142
+ {
143
+ platform: "linux",
144
+ arch: "ppc64"
145
+ },
146
+ {
147
+ platform: "linux",
148
+ arch: "ppc64le"
149
+ },
150
+ {
151
+ platform: "linux",
152
+ arch: "s390x"
153
+ },
154
+ {
155
+ platform: "darwin",
156
+ arch: "amd64"
157
+ },
158
+ {
159
+ platform: "darwin",
160
+ arch: "arm64"
161
+ },
162
+ {
163
+ platform: "openbsd",
164
+ arch: "amd64"
165
+ },
166
+ {
167
+ platform: "openbsd",
168
+ arch: "arm-6"
169
+ },
170
+ {
171
+ platform: "openbsd",
172
+ arch: "arm-7"
173
+ },
174
+ {
175
+ platform: "openbsd",
176
+ arch: "arm64"
177
+ },
178
+ {
179
+ platform: "windows",
180
+ arch: "amd64"
181
+ },
182
+ {
183
+ platform: "windows",
184
+ arch: "arm-6"
185
+ },
186
+ {
187
+ platform: "windows",
188
+ arch: "arm-7"
189
+ },
190
+ {
191
+ platform: "windows",
192
+ arch: "arm64"
193
+ }
194
+ ];
195
+
196
+ // src/caddy/utils.ts
197
+ var import_node_net = require("net");
198
+ var import_node_child_process3 = require("child_process");
199
+ var import_ora = __toESM(require("ora"), 1);
200
+ var spinner;
201
+ function getNumber(number) {
202
+ if (number <= 0)
203
+ return "0%";
204
+ else if (number < 100)
205
+ return `${number.toFixed(2)}%`;
206
+ else
207
+ return "100%";
208
+ }
209
+ function logProgress(percent) {
210
+ if (!spinner) {
211
+ consola.log("");
212
+ spinner = (0, import_ora.default)({
213
+ text: "Start Download Caddy: 0%",
214
+ indent: 2
215
+ });
216
+ spinner.start();
217
+ } else {
218
+ spinner.text = `Download Caddy: ${getNumber(Number(percent) * 100)}`;
219
+ }
220
+ }
221
+ function logProgressOver() {
222
+ if (!spinner) {
223
+ spinner = (0, import_ora.default)({
224
+ text: "Start Download Caddy: 100%",
225
+ indent: 2
226
+ });
227
+ spinner.start();
228
+ } else {
229
+ spinner.succeed();
230
+ consola.log("");
231
+ }
232
+ }
233
+
234
+ // src/caddy/index.ts
235
+ async function download() {
236
+ if (await testCaddy())
237
+ return caddyPath;
238
+ return new Promise((resolve, reject) => {
239
+ if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
240
+ (0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
241
+ (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
242
+ }
243
+ const file = (0, import_node_fs2.createWriteStream)(caddyPath);
244
+ let _platform = (0, import_node_os2.platform)().toString();
245
+ _platform === "win32" && (_platform = "windows");
246
+ let _arch = import_node_process4.default.arch.toString();
247
+ _arch === "x64" && (_arch = "amd64");
248
+ const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
249
+ if (!support)
250
+ return reject(new Error("not support"));
251
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
252
+ (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
253
+ const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
254
+ const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
255
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
256
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
257
+ const chmodCaddyOnce = once(() => {
258
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
259
+ });
260
+ import_got_cjs.got.stream(dowmloadLink, {
261
+ agent: {
262
+ http: httpAgent,
263
+ https: httpsAgent
264
+ }
265
+ }).on("downloadProgress", (progress) => {
266
+ logProgress(progress.percent);
267
+ chmodCaddyOnce();
268
+ }).pipe(file).on("finish", () => {
269
+ logProgressOver();
270
+ if (import_node_process4.default.platform === "win32")
271
+ return resolve(caddyPath);
272
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
273
+ resolve(caddyPath);
274
+ }).on("error", (err) => {
275
+ reject(err);
276
+ });
277
+ });
278
+ }
279
+ function testCaddy() {
280
+ return new Promise((resolve, reject) => {
281
+ if (!(0, import_node_fs2.existsSync)(caddyPath))
282
+ return resolve(false);
283
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
284
+ const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
285
+ child.on("close", () => {
286
+ return resolve(false);
287
+ });
288
+ child.on("error", (err) => {
289
+ return reject(err);
290
+ });
291
+ child.stdout.on("data", (_data) => {
292
+ return resolve(true);
293
+ });
294
+ });
295
+ }
296
+
297
+ // scripts/postinstall.ts
298
+ async function run() {
299
+ try {
300
+ if (import_node_process5.default.env.UHRP_AUTO_INSTALL_CADDY) {
301
+ (0, import_node_fs3.existsSync)(caddyPath) && (0, import_node_fs3.unlinkSync)(caddyPath);
302
+ await download();
303
+ }
304
+ } catch (e) {
305
+ consola.error(e.code);
306
+ }
307
+ }
308
+ run();
@@ -1,9 +1,22 @@
1
1
  import { join } from 'node:path'
2
+ import os from 'node:os'
2
3
  import process from 'node:process'
4
+ import dotenvFlow from 'dotenv-flow'
3
5
 
4
- const TEMP_DIR = process.env.TEMP || process.env.TMPDIR || '/tmp'
6
+ dotenvFlow.config({
7
+ silent: true,
8
+ })
9
+
10
+ function resolvePath(path: string) {
11
+ if (path.startsWith('~'))
12
+ return join(os.homedir() || '', path.slice(1))
13
+ return path
14
+ }
15
+
16
+ export const TEMP_DIR = resolvePath(process.env.UHRP_CADDY_PATH || process.env.TEMP || process.env.TMPDIR || '/tmp')
5
17
  export const caddyPath = join(TEMP_DIR, `caddy${process.platform === 'win32' ? '.exe' : ''}`)
6
18
  export const caddyFilePath = join(TEMP_DIR, 'CADDYFILE')
19
+ export const caddyLockFilePath = join(TEMP_DIR, 'caddylock')
7
20
 
8
21
  export const supportList = [
9
22
  {