unplugin-https-reverse-proxy 1.0.0-beta.16 → 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-QMYDD3HL.js → chunk-WCFY7NJQ.js} +32 -21
- package/dist/esbuild.cjs +34 -23
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +34 -23
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +34 -23
- package/dist/nuxt.js +1 -1
- package/dist/rollup.cjs +34 -23
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +34 -23
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +34 -23
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +34 -23
- package/dist/webpack.js +1 -1
- package/package.json +5 -4
- package/scripts/postinstall.cjs +7 -12
- package/src/caddy/index.ts +11 -9
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
|
@@ -19,19 +19,16 @@ import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
|
19
19
|
import { got } from "got-cjs";
|
|
20
20
|
import { HttpProxyAgent } from "http-proxy-agent";
|
|
21
21
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
22
|
-
import kill from "kill-port";
|
|
23
22
|
import * as lockfile from "proper-lockfile";
|
|
24
23
|
|
|
25
24
|
// src/host/index.ts
|
|
26
25
|
import process from "node:process";
|
|
27
26
|
import { exec } from "node:child_process";
|
|
28
27
|
import { chmodSync } from "node:fs";
|
|
29
|
-
import
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
34
|
-
});
|
|
28
|
+
import { promisify } from "node:util";
|
|
29
|
+
import hostile from "hostile";
|
|
30
|
+
var _setHost = promisify(hostile.set);
|
|
31
|
+
var _removeHost = promisify(hostile.remove);
|
|
35
32
|
function getPathOfSystemHostsPath() {
|
|
36
33
|
return process.platform === "win32" ? `${process.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
37
34
|
}
|
|
@@ -52,20 +49,18 @@ async function syncHost() {
|
|
|
52
49
|
async function addHost(ip, host) {
|
|
53
50
|
if (process.platform !== "win32")
|
|
54
51
|
chmodSync(getPathOfSystemHostsPath(), 511);
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
await _setHost("127.0.0.1", "localhost");
|
|
53
|
+
await _setHost(ip, host);
|
|
57
54
|
if (ip === "localhost")
|
|
58
|
-
|
|
59
|
-
await hostInstance.updateFinish();
|
|
55
|
+
await _setHost("127.0.0.1", host);
|
|
60
56
|
return await syncHost();
|
|
61
57
|
}
|
|
62
58
|
async function removeHost(ip, host) {
|
|
63
59
|
if (process.platform !== "win32")
|
|
64
60
|
chmodSync(getPathOfSystemHostsPath(), 511);
|
|
65
|
-
|
|
61
|
+
await _removeHost(ip, host);
|
|
66
62
|
if (ip === "localhost")
|
|
67
|
-
|
|
68
|
-
await hostInstance.updateFinish();
|
|
63
|
+
await _removeHost("127.0.0.1", host);
|
|
69
64
|
return await syncHost();
|
|
70
65
|
}
|
|
71
66
|
|
|
@@ -199,6 +194,7 @@ var supportList = [
|
|
|
199
194
|
|
|
200
195
|
// src/caddy/utils.ts
|
|
201
196
|
import { createServer } from "node:net";
|
|
197
|
+
import { exec as exec2 } from "node:child_process";
|
|
202
198
|
import ora from "ora";
|
|
203
199
|
var spinner;
|
|
204
200
|
function tryPort(port) {
|
|
@@ -219,6 +215,18 @@ function tryPort(port) {
|
|
|
219
215
|
}
|
|
220
216
|
});
|
|
221
217
|
}
|
|
218
|
+
async function kill(port) {
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
exec2(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
221
|
+
if (err) {
|
|
222
|
+
reject(err);
|
|
223
|
+
} else {
|
|
224
|
+
consola.log(stdout);
|
|
225
|
+
resolve();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
222
230
|
function getNumber(number) {
|
|
223
231
|
if (number <= 0)
|
|
224
232
|
return "0%";
|
|
@@ -391,11 +399,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
391
399
|
writeFileSync(caddyLockFilePath, "");
|
|
392
400
|
if (!this.locked) {
|
|
393
401
|
if (await tryPort(443))
|
|
394
|
-
await kill(443
|
|
402
|
+
await kill(443);
|
|
395
403
|
if ((process3.platform === "win32" || !https) && await tryPort(80))
|
|
396
|
-
await kill(80
|
|
404
|
+
await kill(80);
|
|
397
405
|
}
|
|
398
406
|
return new Promise((resolve, reject) => {
|
|
407
|
+
var _a, _b;
|
|
399
408
|
const setupCleanup = () => {
|
|
400
409
|
process3.on("SIGINT", async () => {
|
|
401
410
|
if (!restore || this.stoped)
|
|
@@ -420,7 +429,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
420
429
|
process3.exit = async (code) => {
|
|
421
430
|
const port = Number(source.split(":")[1]);
|
|
422
431
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
423
|
-
await kill(port
|
|
432
|
+
await kill(port);
|
|
424
433
|
const pwd = process3.cwd();
|
|
425
434
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
426
435
|
if (existsSync(viteCacheDir))
|
|
@@ -451,12 +460,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
451
460
|
};
|
|
452
461
|
};
|
|
453
462
|
if (!this.locked) {
|
|
454
|
-
|
|
463
|
+
this.caddyChild = process3.platform !== "win32" ? spawn("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : spawn(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
|
|
455
464
|
lockfile.lockSync(caddyLockFilePath);
|
|
456
|
-
|
|
465
|
+
this.caddyChild.on("error", (err) => {
|
|
457
466
|
return reject(err);
|
|
458
467
|
});
|
|
459
|
-
|
|
468
|
+
(_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
460
469
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
461
470
|
for (const line of lines) {
|
|
462
471
|
showCaddyLog && line && console.info(line);
|
|
@@ -471,7 +480,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
471
480
|
return resolve();
|
|
472
481
|
}
|
|
473
482
|
});
|
|
474
|
-
|
|
483
|
+
(_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
475
484
|
consola.info(_data.toString());
|
|
476
485
|
resolve();
|
|
477
486
|
});
|
|
@@ -484,7 +493,9 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
484
493
|
});
|
|
485
494
|
}
|
|
486
495
|
async baseCleanup() {
|
|
496
|
+
var _a;
|
|
487
497
|
if (!this.locked) {
|
|
498
|
+
(_a = this.caddyChild) == null ? void 0 : _a.kill();
|
|
488
499
|
try {
|
|
489
500
|
await lockfile.unlock(caddyLockFilePath);
|
|
490
501
|
await unlink(caddyFilePath);
|
package/dist/esbuild.cjs
CHANGED
|
@@ -83,24 +83,21 @@ function isAdmin() {
|
|
|
83
83
|
var import_node_os2 = require("os");
|
|
84
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
85
85
|
var import_node_fs2 = require("fs");
|
|
86
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
87
|
var import_promises2 = require("fs/promises");
|
|
88
88
|
var import_got_cjs = require("got-cjs");
|
|
89
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
90
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
91
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
92
91
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
93
92
|
|
|
94
93
|
// src/host/index.ts
|
|
95
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
96
95
|
var import_node_child_process2 = require("child_process");
|
|
97
96
|
var import_node_fs = require("fs");
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
103
|
-
});
|
|
97
|
+
var import_node_util = require("util");
|
|
98
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
99
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
100
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
104
101
|
function getPathOfSystemHostsPath() {
|
|
105
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
106
103
|
}
|
|
@@ -121,20 +118,18 @@ async function syncHost() {
|
|
|
121
118
|
async function addHost(ip, host) {
|
|
122
119
|
if (import_node_process2.default.platform !== "win32")
|
|
123
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
126
123
|
if (ip === "localhost")
|
|
127
|
-
|
|
128
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
129
125
|
return await syncHost();
|
|
130
126
|
}
|
|
131
127
|
async function removeHost(ip, host) {
|
|
132
128
|
if (import_node_process2.default.platform !== "win32")
|
|
133
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
134
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
135
131
|
if (ip === "localhost")
|
|
136
|
-
|
|
137
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
138
133
|
return await syncHost();
|
|
139
134
|
}
|
|
140
135
|
|
|
@@ -268,6 +263,7 @@ var supportList = [
|
|
|
268
263
|
|
|
269
264
|
// src/caddy/utils.ts
|
|
270
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
271
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
272
268
|
var spinner;
|
|
273
269
|
function tryPort(port) {
|
|
@@ -288,6 +284,18 @@ function tryPort(port) {
|
|
|
288
284
|
}
|
|
289
285
|
});
|
|
290
286
|
}
|
|
287
|
+
async function kill(port) {
|
|
288
|
+
return new Promise((resolve, reject) => {
|
|
289
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
290
|
+
if (err) {
|
|
291
|
+
reject(err);
|
|
292
|
+
} else {
|
|
293
|
+
consola.log(stdout);
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
291
299
|
function getNumber(number) {
|
|
292
300
|
if (number <= 0)
|
|
293
301
|
return "0%";
|
|
@@ -371,7 +379,7 @@ function testCaddy() {
|
|
|
371
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
372
380
|
return resolve(false);
|
|
373
381
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
374
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
382
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
375
383
|
child.on("close", () => {
|
|
376
384
|
return resolve(false);
|
|
377
385
|
});
|
|
@@ -460,11 +468,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
460
468
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
461
469
|
if (!this.locked) {
|
|
462
470
|
if (await tryPort(443))
|
|
463
|
-
await (
|
|
471
|
+
await kill(443);
|
|
464
472
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
465
|
-
await (
|
|
473
|
+
await kill(80);
|
|
466
474
|
}
|
|
467
475
|
return new Promise((resolve, reject) => {
|
|
476
|
+
var _a, _b;
|
|
468
477
|
const setupCleanup = () => {
|
|
469
478
|
import_node_process4.default.on("SIGINT", async () => {
|
|
470
479
|
if (!restore || this.stoped)
|
|
@@ -489,7 +498,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
489
498
|
import_node_process4.default.exit = async (code) => {
|
|
490
499
|
const port = Number(source.split(":")[1]);
|
|
491
500
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
492
|
-
await (
|
|
501
|
+
await kill(port);
|
|
493
502
|
const pwd = import_node_process4.default.cwd();
|
|
494
503
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
495
504
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
@@ -520,12 +529,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
520
529
|
};
|
|
521
530
|
};
|
|
522
531
|
if (!this.locked) {
|
|
523
|
-
|
|
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"]);
|
|
524
533
|
lockfile.lockSync(caddyLockFilePath);
|
|
525
|
-
|
|
534
|
+
this.caddyChild.on("error", (err) => {
|
|
526
535
|
return reject(err);
|
|
527
536
|
});
|
|
528
|
-
|
|
537
|
+
(_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
529
538
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
530
539
|
for (const line of lines) {
|
|
531
540
|
showCaddyLog && line && console.info(line);
|
|
@@ -540,7 +549,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
540
549
|
return resolve();
|
|
541
550
|
}
|
|
542
551
|
});
|
|
543
|
-
|
|
552
|
+
(_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
544
553
|
consola.info(_data.toString());
|
|
545
554
|
resolve();
|
|
546
555
|
});
|
|
@@ -553,7 +562,9 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
553
562
|
});
|
|
554
563
|
}
|
|
555
564
|
async baseCleanup() {
|
|
565
|
+
var _a;
|
|
556
566
|
if (!this.locked) {
|
|
567
|
+
(_a = this.caddyChild) == null ? void 0 : _a.kill();
|
|
557
568
|
try {
|
|
558
569
|
await lockfile.unlock(caddyLockFilePath);
|
|
559
570
|
await (0, import_promises2.unlink)(caddyFilePath);
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -83,24 +83,21 @@ function isAdmin() {
|
|
|
83
83
|
var import_node_os2 = require("os");
|
|
84
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
85
85
|
var import_node_fs2 = require("fs");
|
|
86
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
87
|
var import_promises2 = require("fs/promises");
|
|
88
88
|
var import_got_cjs = require("got-cjs");
|
|
89
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
90
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
91
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
92
91
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
93
92
|
|
|
94
93
|
// src/host/index.ts
|
|
95
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
96
95
|
var import_node_child_process2 = require("child_process");
|
|
97
96
|
var import_node_fs = require("fs");
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
103
|
-
});
|
|
97
|
+
var import_node_util = require("util");
|
|
98
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
99
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
100
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
104
101
|
function getPathOfSystemHostsPath() {
|
|
105
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
106
103
|
}
|
|
@@ -121,20 +118,18 @@ async function syncHost() {
|
|
|
121
118
|
async function addHost(ip, host) {
|
|
122
119
|
if (import_node_process2.default.platform !== "win32")
|
|
123
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
126
123
|
if (ip === "localhost")
|
|
127
|
-
|
|
128
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
129
125
|
return await syncHost();
|
|
130
126
|
}
|
|
131
127
|
async function removeHost(ip, host) {
|
|
132
128
|
if (import_node_process2.default.platform !== "win32")
|
|
133
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
134
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
135
131
|
if (ip === "localhost")
|
|
136
|
-
|
|
137
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
138
133
|
return await syncHost();
|
|
139
134
|
}
|
|
140
135
|
|
|
@@ -268,6 +263,7 @@ var supportList = [
|
|
|
268
263
|
|
|
269
264
|
// src/caddy/utils.ts
|
|
270
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
271
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
272
268
|
var spinner;
|
|
273
269
|
function tryPort(port) {
|
|
@@ -288,6 +284,18 @@ function tryPort(port) {
|
|
|
288
284
|
}
|
|
289
285
|
});
|
|
290
286
|
}
|
|
287
|
+
async function kill(port) {
|
|
288
|
+
return new Promise((resolve, reject) => {
|
|
289
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
290
|
+
if (err) {
|
|
291
|
+
reject(err);
|
|
292
|
+
} else {
|
|
293
|
+
consola.log(stdout);
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
291
299
|
function getNumber(number) {
|
|
292
300
|
if (number <= 0)
|
|
293
301
|
return "0%";
|
|
@@ -371,7 +379,7 @@ function testCaddy() {
|
|
|
371
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
372
380
|
return resolve(false);
|
|
373
381
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
374
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
382
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
375
383
|
child.on("close", () => {
|
|
376
384
|
return resolve(false);
|
|
377
385
|
});
|
|
@@ -460,11 +468,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
460
468
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
461
469
|
if (!this.locked) {
|
|
462
470
|
if (await tryPort(443))
|
|
463
|
-
await (
|
|
471
|
+
await kill(443);
|
|
464
472
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
465
|
-
await (
|
|
473
|
+
await kill(80);
|
|
466
474
|
}
|
|
467
475
|
return new Promise((resolve, reject) => {
|
|
476
|
+
var _a, _b;
|
|
468
477
|
const setupCleanup = () => {
|
|
469
478
|
import_node_process4.default.on("SIGINT", async () => {
|
|
470
479
|
if (!restore || this.stoped)
|
|
@@ -489,7 +498,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
489
498
|
import_node_process4.default.exit = async (code) => {
|
|
490
499
|
const port = Number(source.split(":")[1]);
|
|
491
500
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
492
|
-
await (
|
|
501
|
+
await kill(port);
|
|
493
502
|
const pwd = import_node_process4.default.cwd();
|
|
494
503
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
495
504
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
@@ -520,12 +529,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
520
529
|
};
|
|
521
530
|
};
|
|
522
531
|
if (!this.locked) {
|
|
523
|
-
|
|
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"]);
|
|
524
533
|
lockfile.lockSync(caddyLockFilePath);
|
|
525
|
-
|
|
534
|
+
this.caddyChild.on("error", (err) => {
|
|
526
535
|
return reject(err);
|
|
527
536
|
});
|
|
528
|
-
|
|
537
|
+
(_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
529
538
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
530
539
|
for (const line of lines) {
|
|
531
540
|
showCaddyLog && line && console.info(line);
|
|
@@ -540,7 +549,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
540
549
|
return resolve();
|
|
541
550
|
}
|
|
542
551
|
});
|
|
543
|
-
|
|
552
|
+
(_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
544
553
|
consola.info(_data.toString());
|
|
545
554
|
resolve();
|
|
546
555
|
});
|
|
@@ -553,7 +562,9 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
553
562
|
});
|
|
554
563
|
}
|
|
555
564
|
async baseCleanup() {
|
|
565
|
+
var _a;
|
|
556
566
|
if (!this.locked) {
|
|
567
|
+
(_a = this.caddyChild) == null ? void 0 : _a.kill();
|
|
557
568
|
try {
|
|
558
569
|
await lockfile.unlock(caddyLockFilePath);
|
|
559
570
|
await (0, import_promises2.unlink)(caddyFilePath);
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -85,24 +85,21 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
85
85
|
var import_node_os2 = require("os");
|
|
86
86
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
87
87
|
var import_node_fs2 = require("fs");
|
|
88
|
-
var
|
|
88
|
+
var import_node_child_process4 = require("child_process");
|
|
89
89
|
var import_promises2 = require("fs/promises");
|
|
90
90
|
var import_got_cjs = require("got-cjs");
|
|
91
91
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
92
92
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
93
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
94
93
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
95
94
|
|
|
96
95
|
// src/host/index.ts
|
|
97
96
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
98
97
|
var import_node_child_process2 = require("child_process");
|
|
99
98
|
var import_node_fs = require("fs");
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
105
|
-
});
|
|
99
|
+
var import_node_util = require("util");
|
|
100
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
101
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
102
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
106
103
|
function getPathOfSystemHostsPath() {
|
|
107
104
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
108
105
|
}
|
|
@@ -123,20 +120,18 @@ async function syncHost() {
|
|
|
123
120
|
async function addHost(ip, host) {
|
|
124
121
|
if (import_node_process2.default.platform !== "win32")
|
|
125
122
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
await _setHost("127.0.0.1", "localhost");
|
|
124
|
+
await _setHost(ip, host);
|
|
128
125
|
if (ip === "localhost")
|
|
129
|
-
|
|
130
|
-
await hostInstance.updateFinish();
|
|
126
|
+
await _setHost("127.0.0.1", host);
|
|
131
127
|
return await syncHost();
|
|
132
128
|
}
|
|
133
129
|
async function removeHost(ip, host) {
|
|
134
130
|
if (import_node_process2.default.platform !== "win32")
|
|
135
131
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
136
|
-
|
|
132
|
+
await _removeHost(ip, host);
|
|
137
133
|
if (ip === "localhost")
|
|
138
|
-
|
|
139
|
-
await hostInstance.updateFinish();
|
|
134
|
+
await _removeHost("127.0.0.1", host);
|
|
140
135
|
return await syncHost();
|
|
141
136
|
}
|
|
142
137
|
|
|
@@ -270,6 +265,7 @@ var supportList = [
|
|
|
270
265
|
|
|
271
266
|
// src/caddy/utils.ts
|
|
272
267
|
var import_node_net = require("net");
|
|
268
|
+
var import_node_child_process3 = require("child_process");
|
|
273
269
|
var import_ora = __toESM(require("ora"), 1);
|
|
274
270
|
var spinner;
|
|
275
271
|
function tryPort(port) {
|
|
@@ -290,6 +286,18 @@ function tryPort(port) {
|
|
|
290
286
|
}
|
|
291
287
|
});
|
|
292
288
|
}
|
|
289
|
+
async function kill(port) {
|
|
290
|
+
return new Promise((resolve, reject) => {
|
|
291
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
292
|
+
if (err) {
|
|
293
|
+
reject(err);
|
|
294
|
+
} else {
|
|
295
|
+
consola.log(stdout);
|
|
296
|
+
resolve();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
293
301
|
function getNumber(number) {
|
|
294
302
|
if (number <= 0)
|
|
295
303
|
return "0%";
|
|
@@ -373,7 +381,7 @@ function testCaddy() {
|
|
|
373
381
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
374
382
|
return resolve(false);
|
|
375
383
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
376
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
384
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
377
385
|
child.on("close", () => {
|
|
378
386
|
return resolve(false);
|
|
379
387
|
});
|
|
@@ -462,11 +470,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
462
470
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
463
471
|
if (!this.locked) {
|
|
464
472
|
if (await tryPort(443))
|
|
465
|
-
await (
|
|
473
|
+
await kill(443);
|
|
466
474
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
467
|
-
await (
|
|
475
|
+
await kill(80);
|
|
468
476
|
}
|
|
469
477
|
return new Promise((resolve, reject) => {
|
|
478
|
+
var _a, _b;
|
|
470
479
|
const setupCleanup = () => {
|
|
471
480
|
import_node_process4.default.on("SIGINT", async () => {
|
|
472
481
|
if (!restore || this.stoped)
|
|
@@ -491,7 +500,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
491
500
|
import_node_process4.default.exit = async (code) => {
|
|
492
501
|
const port = Number(source.split(":")[1]);
|
|
493
502
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
494
|
-
await (
|
|
503
|
+
await kill(port);
|
|
495
504
|
const pwd = import_node_process4.default.cwd();
|
|
496
505
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
497
506
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
@@ -522,12 +531,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
522
531
|
};
|
|
523
532
|
};
|
|
524
533
|
if (!this.locked) {
|
|
525
|
-
|
|
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"]);
|
|
526
535
|
lockfile.lockSync(caddyLockFilePath);
|
|
527
|
-
|
|
536
|
+
this.caddyChild.on("error", (err) => {
|
|
528
537
|
return reject(err);
|
|
529
538
|
});
|
|
530
|
-
|
|
539
|
+
(_a = this.caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
531
540
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
532
541
|
for (const line of lines) {
|
|
533
542
|
showCaddyLog && line && console.info(line);
|
|
@@ -542,7 +551,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
542
551
|
return resolve();
|
|
543
552
|
}
|
|
544
553
|
});
|
|
545
|
-
|
|
554
|
+
(_b = this.caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
546
555
|
consola.info(_data.toString());
|
|
547
556
|
resolve();
|
|
548
557
|
});
|
|
@@ -555,7 +564,9 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
555
564
|
});
|
|
556
565
|
}
|
|
557
566
|
async baseCleanup() {
|
|
567
|
+
var _a;
|
|
558
568
|
if (!this.locked) {
|
|
569
|
+
(_a = this.caddyChild) == null ? void 0 : _a.kill();
|
|
559
570
|
try {
|
|
560
571
|
await lockfile.unlock(caddyLockFilePath);
|
|
561
572
|
await (0, import_promises2.unlink)(caddyFilePath);
|