unplugin-https-reverse-proxy 1.0.0-beta.15 → 1.0.0-beta.17
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/chunk-2VGRJ3QS.js +45 -0
- package/dist/chunk-WCFY7NJQ.js +662 -0
- package/dist/esbuild.cjs +62 -1674
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +62 -1674
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +43 -1664
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +62 -1674
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +62 -1674
- package/dist/rspack.js +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/vite.cjs +62 -1674
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +62 -1674
- package/dist/webpack.js +2 -2
- package/package.json +6 -4
- package/scripts/postinstall.cjs +8 -12
- package/src/caddy/index.ts +14 -16
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
- package/dist/chunk-GV7Y22GZ.js +0 -2258
- package/dist/chunk-UGWFCSQS.js +0 -80
package/dist/webpack.js
CHANGED
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.
|
|
4
|
+
"version": "1.0.0-beta.17",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"@rsbuild/core": "^0.4.3",
|
|
85
85
|
"@rspack/core": "^0.5.4",
|
|
86
86
|
"esbuild": "*",
|
|
87
|
+
"proper-lockfile": "^4.1.2",
|
|
87
88
|
"rollup": "^3",
|
|
88
89
|
"vite": ">=3",
|
|
89
90
|
"webpack": "^4 || ^5"
|
|
@@ -118,10 +119,9 @@
|
|
|
118
119
|
"consola": "^3.2.3",
|
|
119
120
|
"dotenv-flow": "^4.1.0",
|
|
120
121
|
"got-cjs": "^12.5.4",
|
|
121
|
-
"
|
|
122
|
+
"hostile": "^1.4.0",
|
|
122
123
|
"http-proxy-agent": "^7.0.2",
|
|
123
124
|
"https-proxy-agent": "^7.0.4",
|
|
124
|
-
"kill-port": "^2.0.1",
|
|
125
125
|
"ora": "5",
|
|
126
126
|
"picocolors": "^1.0.0",
|
|
127
127
|
"tsx": "^4.7.1",
|
|
@@ -133,12 +133,14 @@
|
|
|
133
133
|
"@nuxt/schema": "^3.10.2",
|
|
134
134
|
"@rsbuild/core": "^0.4.3",
|
|
135
135
|
"@rspack/core": "^0.5.4",
|
|
136
|
+
"@types/hostile": "^1.3.5",
|
|
136
137
|
"@types/kill-port": "^2.0.3",
|
|
137
138
|
"@types/node": "^20.11.19",
|
|
138
139
|
"@types/proper-lockfile": "^4.1.4",
|
|
139
140
|
"@vue/cli": "^5.0.8",
|
|
140
141
|
"bumpp": "^9.3.0",
|
|
141
142
|
"chalk": "^5.3.0",
|
|
143
|
+
"cross-env": "^7.0.3",
|
|
142
144
|
"eslint": "^8.56.0",
|
|
143
145
|
"fast-glob": "^3.3.2",
|
|
144
146
|
"nodemon": "^3.0.3",
|
|
@@ -164,6 +166,6 @@
|
|
|
164
166
|
"play:vuecli4": "npm -C examples/vuecli4 run serve",
|
|
165
167
|
"release": "bumpp",
|
|
166
168
|
"start": "tsx src/index.ts",
|
|
167
|
-
"test": "UHRP_CADDY_PATH='./test/.uhrp' vitest"
|
|
169
|
+
"test": "cross-env UHRP_CADDY_PATH='./test/.uhrp' vitest"
|
|
168
170
|
}
|
|
169
171
|
}
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -49,26 +49,21 @@ function once(fn) {
|
|
|
49
49
|
var import_node_os2 = require("os");
|
|
50
50
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
51
51
|
var import_node_fs2 = require("fs");
|
|
52
|
-
var
|
|
52
|
+
var import_node_child_process4 = require("child_process");
|
|
53
53
|
var import_promises2 = require("fs/promises");
|
|
54
54
|
var import_got_cjs = require("got-cjs");
|
|
55
55
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
56
56
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
57
|
-
var
|
|
57
|
+
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
58
58
|
|
|
59
59
|
// src/host/index.ts
|
|
60
60
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
61
61
|
var import_node_child_process2 = require("child_process");
|
|
62
62
|
var import_node_fs = require("fs");
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
68
|
-
});
|
|
69
|
-
function getPathOfSystemHostsPath() {
|
|
70
|
-
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
71
|
-
}
|
|
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);
|
|
72
67
|
|
|
73
68
|
// src/caddy/constants.ts
|
|
74
69
|
var import_node_path2 = require("path");
|
|
@@ -200,6 +195,7 @@ var supportList = [
|
|
|
200
195
|
|
|
201
196
|
// src/caddy/utils.ts
|
|
202
197
|
var import_node_net = require("net");
|
|
198
|
+
var import_node_child_process3 = require("child_process");
|
|
203
199
|
var import_ora = __toESM(require("ora"), 1);
|
|
204
200
|
var spinner;
|
|
205
201
|
function getNumber(number) {
|
|
@@ -285,7 +281,7 @@ function testCaddy() {
|
|
|
285
281
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
286
282
|
return resolve(false);
|
|
287
283
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
288
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
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]);
|
|
289
285
|
child.on("close", () => {
|
|
290
286
|
return resolve(false);
|
|
291
287
|
});
|
package/src/caddy/index.ts
CHANGED
|
@@ -6,11 +6,11 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'
|
|
|
6
6
|
import { got } from 'got-cjs'
|
|
7
7
|
import { HttpProxyAgent } from 'http-proxy-agent'
|
|
8
8
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
|
9
|
-
import
|
|
9
|
+
import * as lockfile from 'proper-lockfile'
|
|
10
10
|
import { chmodRecursive, consola, once } from '../utils'
|
|
11
11
|
import { addHost, removeHost } from '../host'
|
|
12
12
|
import { TEMP_DIR, caddyFilePath, caddyLockFilePath, caddyPath, supportList } from './constants'
|
|
13
|
-
import { logProgress, logProgressOver, tryPort } from './utils'
|
|
13
|
+
import { kill, logProgress, logProgressOver, tryPort } from './utils'
|
|
14
14
|
|
|
15
15
|
export async function download() {
|
|
16
16
|
if (await testCaddy())
|
|
@@ -108,7 +108,7 @@ export class CaddyInstant {
|
|
|
108
108
|
private locked = false
|
|
109
109
|
private caddyfile: string | undefined
|
|
110
110
|
|
|
111
|
-
private
|
|
111
|
+
private caddyChild: ReturnType<typeof spawn> | undefined
|
|
112
112
|
|
|
113
113
|
constructor() {
|
|
114
114
|
testCaddy().then(async () => {
|
|
@@ -117,16 +117,13 @@ export class CaddyInstant {
|
|
|
117
117
|
this.inited = true
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
121
|
-
this.lockfile = require('proper-lockfile')
|
|
122
|
-
|
|
123
120
|
this.locked = this.checkLock()
|
|
124
121
|
}
|
|
125
122
|
|
|
126
123
|
checkLock() {
|
|
127
124
|
if (!existsSync(caddyLockFilePath))
|
|
128
125
|
writeFileSync(caddyLockFilePath, '')
|
|
129
|
-
return
|
|
126
|
+
return lockfile.checkSync(caddyLockFilePath)
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
async getCaddyfile() {
|
|
@@ -201,9 +198,9 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
|
|
|
201
198
|
|
|
202
199
|
if (!this.locked) {
|
|
203
200
|
if (await tryPort(443))
|
|
204
|
-
await kill(443
|
|
201
|
+
await kill(443)
|
|
205
202
|
if ((process.platform === 'win32' || !https) && await tryPort(80))
|
|
206
|
-
await kill(80
|
|
203
|
+
await kill(80)
|
|
207
204
|
}
|
|
208
205
|
|
|
209
206
|
return new Promise<void>((resolve, reject) => {
|
|
@@ -239,7 +236,7 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
|
|
|
239
236
|
process.exit = async (code?: number) => {
|
|
240
237
|
const port = Number(source.split(':')[1])
|
|
241
238
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
242
|
-
await kill(port
|
|
239
|
+
await kill(port)
|
|
243
240
|
|
|
244
241
|
// fix `Error: EPERM: operation not permitted`
|
|
245
242
|
const pwd = process.cwd()
|
|
@@ -279,17 +276,17 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
|
|
|
279
276
|
}
|
|
280
277
|
|
|
281
278
|
if (!this.locked) {
|
|
282
|
-
|
|
279
|
+
this.caddyChild = process.platform !== 'win32'
|
|
283
280
|
? spawn('sudo', ['-E', caddyPath, 'run', '--config', caddyFilePath, '--watch'])
|
|
284
281
|
: spawn(caddyPath, ['run', '--config', caddyFilePath, '--watch'])
|
|
285
282
|
|
|
286
|
-
|
|
283
|
+
lockfile.lockSync(caddyLockFilePath)
|
|
287
284
|
|
|
288
|
-
|
|
285
|
+
this.caddyChild!.on('error', (err) => {
|
|
289
286
|
return reject(err)
|
|
290
287
|
})
|
|
291
288
|
|
|
292
|
-
|
|
289
|
+
this.caddyChild!.stderr?.on('data', (data) => {
|
|
293
290
|
const lines = (data.toString() as string).split('\n').map(line => line.trim())
|
|
294
291
|
for (const line of lines) {
|
|
295
292
|
// caddy log
|
|
@@ -308,7 +305,7 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
|
|
|
308
305
|
}
|
|
309
306
|
})
|
|
310
307
|
|
|
311
|
-
|
|
308
|
+
this.caddyChild!.stdout?.on('data', (_data) => {
|
|
312
309
|
consola.info(_data.toString())
|
|
313
310
|
resolve()
|
|
314
311
|
})
|
|
@@ -327,8 +324,9 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
|
|
|
327
324
|
|
|
328
325
|
async baseCleanup() {
|
|
329
326
|
if (!this.locked) {
|
|
327
|
+
this.caddyChild?.kill()
|
|
330
328
|
try {
|
|
331
|
-
await
|
|
329
|
+
await lockfile.unlock(caddyLockFilePath)
|
|
332
330
|
await unlink(caddyFilePath)
|
|
333
331
|
await unlink(caddyLockFilePath)
|
|
334
332
|
}
|
package/src/caddy/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createServer } from 'node:net'
|
|
2
|
+
import { exec } from 'node:child_process'
|
|
2
3
|
import ora from 'ora'
|
|
3
4
|
import { consola } from '../utils'
|
|
4
5
|
|
|
@@ -28,6 +29,23 @@ export function tryPort(port: number) {
|
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* npx free-port :port
|
|
34
|
+
*/
|
|
35
|
+
export async function kill(port: number) {
|
|
36
|
+
return new Promise<void>((resolve, reject) => {
|
|
37
|
+
exec(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
reject(err)
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
consola.log(stdout)
|
|
43
|
+
resolve()
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
31
49
|
function getNumber(number: number) {
|
|
32
50
|
if (number <= 0)
|
|
33
51
|
return '0%'
|
package/src/host/index.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
2
|
import { exec } from 'node:child_process'
|
|
3
3
|
import { chmodSync } from 'node:fs'
|
|
4
|
+
import { promisify } from 'node:util'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
import _Hosts from 'hosts-so-easy'
|
|
6
|
+
import hostile from 'hostile'
|
|
7
7
|
import { consola } from '../utils'
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const hostInstance = new Hosts({
|
|
12
|
-
debounceTime: 50,
|
|
13
|
-
hostsFile: getPathOfSystemHostsPath(),
|
|
14
|
-
})
|
|
9
|
+
const _setHost = promisify(hostile.set)
|
|
10
|
+
const _removeHost = promisify(hostile.remove)
|
|
15
11
|
|
|
16
12
|
function getPathOfSystemHostsPath() {
|
|
17
13
|
return process.platform === 'win32'
|
|
@@ -38,20 +34,18 @@ async function syncHost() {
|
|
|
38
34
|
export async function addHost(ip: string, host: string) {
|
|
39
35
|
if (process.platform !== 'win32')
|
|
40
36
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
await _setHost('127.0.0.1', 'localhost')
|
|
38
|
+
await _setHost(ip, host)
|
|
43
39
|
if (ip === 'localhost')
|
|
44
|
-
|
|
45
|
-
await hostInstance.updateFinish()
|
|
40
|
+
await _setHost('127.0.0.1', host)
|
|
46
41
|
return await syncHost()
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
export async function removeHost(ip: string, host: string) {
|
|
50
45
|
if (process.platform !== 'win32')
|
|
51
46
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
52
|
-
|
|
47
|
+
await _removeHost(ip, host)
|
|
53
48
|
if (ip === 'localhost')
|
|
54
|
-
|
|
55
|
-
await hostInstance.updateFinish()
|
|
49
|
+
await _removeHost('127.0.0.1', host)
|
|
56
50
|
return await syncHost()
|
|
57
51
|
}
|