unplugin-https-reverse-proxy 1.0.0-beta.0 → 1.0.0-beta.10
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/README.md +94 -1
- package/dist/{chunk-3RTK3FSZ.js → chunk-RUJE3YFB.js} +21 -0
- package/dist/{chunk-KYMRDRAJ.js → chunk-XLSIGDFU.js} +135 -77
- package/dist/esbuild.cjs +153 -79
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +157 -81
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -4
- package/dist/nuxt.cjs +101 -134
- package/dist/nuxt.js +29 -9
- package/dist/rollup.cjs +153 -79
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +643 -0
- package/dist/rspack.d.cts +5 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.js +10 -0
- package/dist/utils.cjs +25 -2
- package/dist/utils.d.cts +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +7 -3
- package/dist/vite.cjs +153 -79
- package/dist/vite.d.cts +1 -2
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +7 -4
- package/dist/webpack.cjs +153 -79
- package/dist/webpack.js +7 -4
- package/package.json +42 -24
- package/src/caddy/constants.ts +13 -1
- package/src/caddy/index.ts +32 -5
- package/src/host/index.ts +4 -1
- package/src/index.ts +128 -85
- package/src/nuxt.ts +33 -6
- package/src/rspack.ts +5 -0
- package/src/utils.ts +21 -0
- package/dist/chunk-AXBUFN6T.js +0 -11
- package/dist/chunk-MDJOTQRD.js +0 -11
package/dist/webpack.cjs
CHANGED
|
@@ -51,17 +51,35 @@ var import_unplugin2 = require("unplugin");
|
|
|
51
51
|
|
|
52
52
|
// src/index.ts
|
|
53
53
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
54
|
-
var import_node_fs3 = require("fs");
|
|
55
54
|
var import_unplugin = require("unplugin");
|
|
56
55
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
56
|
|
|
58
57
|
// src/utils.ts
|
|
59
58
|
var import_node_process = __toESM(require("process"), 1);
|
|
59
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
60
|
+
var import_promises = require("fs/promises");
|
|
60
61
|
var import_node_child_process = require("child_process");
|
|
61
62
|
var import_consola = require("consola");
|
|
62
63
|
var consola = (0, import_consola.createConsola)({
|
|
63
64
|
level: 3
|
|
64
65
|
}).withTag("reverse-proxy");
|
|
66
|
+
async function chmodRecursive(_path, mode) {
|
|
67
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
68
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
69
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
70
|
+
for (const child of children)
|
|
71
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function once(fn) {
|
|
75
|
+
let called = false;
|
|
76
|
+
return (...args) => {
|
|
77
|
+
if (called)
|
|
78
|
+
return;
|
|
79
|
+
called = true;
|
|
80
|
+
return fn(...args);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
65
83
|
function isAdmin() {
|
|
66
84
|
if (import_node_process.default.platform === "win32") {
|
|
67
85
|
try {
|
|
@@ -76,7 +94,7 @@ function isAdmin() {
|
|
|
76
94
|
}
|
|
77
95
|
|
|
78
96
|
// src/caddy/index.ts
|
|
79
|
-
var
|
|
97
|
+
var import_node_os2 = require("os");
|
|
80
98
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
81
99
|
var import_node_fs2 = require("fs");
|
|
82
100
|
var import_node_child_process3 = require("child_process");
|
|
@@ -104,7 +122,7 @@ async function syncHost() {
|
|
|
104
122
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
123
|
(error, stdout, stderr) => {
|
|
106
124
|
if (error) {
|
|
107
|
-
|
|
125
|
+
consola.error(`exec error: ${error}`);
|
|
108
126
|
return resolve(false);
|
|
109
127
|
}
|
|
110
128
|
return resolve(true);
|
|
@@ -117,6 +135,8 @@ async function addHost(ip, host) {
|
|
|
117
135
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
136
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
137
|
hostInstance.add(ip, host);
|
|
138
|
+
if (ip === "localhost")
|
|
139
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
140
|
await hostInstance.updateFinish();
|
|
121
141
|
return await syncHost();
|
|
122
142
|
}
|
|
@@ -131,11 +151,21 @@ async function removeHost(ip, host) {
|
|
|
131
151
|
}
|
|
132
152
|
|
|
133
153
|
// src/caddy/constants.ts
|
|
134
|
-
var
|
|
154
|
+
var import_node_path2 = require("path");
|
|
155
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
135
156
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
157
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
158
|
+
import_dotenv_flow.default.config({
|
|
159
|
+
silent: true
|
|
160
|
+
});
|
|
161
|
+
function resolvePath(path2) {
|
|
162
|
+
if (path2.startsWith("~"))
|
|
163
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
164
|
+
return path2;
|
|
165
|
+
}
|
|
166
|
+
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");
|
|
167
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
168
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
139
169
|
var supportList = [
|
|
140
170
|
{
|
|
141
171
|
platform: "dragonfly",
|
|
@@ -307,8 +337,12 @@ async function download() {
|
|
|
307
337
|
if (await testCaddy())
|
|
308
338
|
return caddyPath;
|
|
309
339
|
return new Promise((resolve, reject) => {
|
|
340
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
341
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
342
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
343
|
+
}
|
|
310
344
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
311
|
-
let _platform = (0,
|
|
345
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
312
346
|
_platform === "win32" && (_platform = "windows");
|
|
313
347
|
let _arch = import_node_process4.default.arch.toString();
|
|
314
348
|
_arch === "x64" && (_arch = "amd64");
|
|
@@ -321,6 +355,9 @@ async function download() {
|
|
|
321
355
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
322
356
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
323
357
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
358
|
+
const chmodCaddyOnce = once(() => {
|
|
359
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
360
|
+
});
|
|
324
361
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
325
362
|
agent: {
|
|
326
363
|
http: httpAgent,
|
|
@@ -328,11 +365,12 @@ async function download() {
|
|
|
328
365
|
}
|
|
329
366
|
}).on("downloadProgress", (progress) => {
|
|
330
367
|
logProgress(progress.percent);
|
|
368
|
+
chmodCaddyOnce();
|
|
331
369
|
}).pipe(file).on("finish", () => {
|
|
332
370
|
logProgressOver();
|
|
333
371
|
if (import_node_process4.default.platform === "win32")
|
|
334
372
|
return resolve(caddyPath);
|
|
335
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
373
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
336
374
|
resolve(caddyPath);
|
|
337
375
|
}).on("error", (err) => {
|
|
338
376
|
reject(err);
|
|
@@ -343,7 +381,7 @@ function testCaddy() {
|
|
|
343
381
|
return new Promise((resolve, reject) => {
|
|
344
382
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
345
383
|
return resolve(false);
|
|
346
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
384
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
347
385
|
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process3.spawn)(caddyPath, []) : (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath]);
|
|
348
386
|
child.on("close", () => {
|
|
349
387
|
return resolve(false);
|
|
@@ -415,6 +453,19 @@ var CaddyInstant = class {
|
|
|
415
453
|
});
|
|
416
454
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
417
455
|
import_node_process4.default.exit = async (code) => {
|
|
456
|
+
const port = Number(source.split(":")[1]);
|
|
457
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
458
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
459
|
+
const pwd = import_node_process4.default.cwd();
|
|
460
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
461
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
462
|
+
chmodRecursive(viteCacheDir, 511);
|
|
463
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
464
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
465
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
466
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
467
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
468
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
418
469
|
if (!restore || this.stoped)
|
|
419
470
|
return originalExit(code);
|
|
420
471
|
try {
|
|
@@ -453,7 +504,21 @@ var CaddyInstant = class {
|
|
|
453
504
|
// src/index.ts
|
|
454
505
|
var config;
|
|
455
506
|
var caddy;
|
|
456
|
-
var
|
|
507
|
+
var cwd = import_node_process5.default.cwd();
|
|
508
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
509
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
510
|
+
if (caddy)
|
|
511
|
+
return;
|
|
512
|
+
caddy = new CaddyInstant();
|
|
513
|
+
caddy.run(source, target, __spreadValues({
|
|
514
|
+
base
|
|
515
|
+
}, options)).then(() => {
|
|
516
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
517
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
518
|
+
}).catch((e) => {
|
|
519
|
+
throw e;
|
|
520
|
+
});
|
|
521
|
+
});
|
|
457
522
|
var unpluginFactory = (options) => ({
|
|
458
523
|
name: "unplugin-https-reverse-proxy",
|
|
459
524
|
enforce: "pre",
|
|
@@ -462,11 +527,8 @@ var unpluginFactory = (options) => ({
|
|
|
462
527
|
config = _config;
|
|
463
528
|
},
|
|
464
529
|
configureServer(server) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
if (config.command === "build")
|
|
530
|
+
var _a;
|
|
531
|
+
if (config.command !== "serve")
|
|
470
532
|
return;
|
|
471
533
|
const {
|
|
472
534
|
enable = true,
|
|
@@ -474,50 +536,72 @@ var unpluginFactory = (options) => ({
|
|
|
474
536
|
} = options;
|
|
475
537
|
if (!enable)
|
|
476
538
|
return;
|
|
539
|
+
if (!isAdmin()) {
|
|
540
|
+
consola.warn("please run as administrator");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
477
543
|
if (!target) {
|
|
478
544
|
consola.fail("please provide target");
|
|
479
545
|
return;
|
|
480
546
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let source = `localhost:${config.server.port}`;
|
|
491
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
492
|
-
if (url) {
|
|
493
|
-
const u = new URL(url);
|
|
494
|
-
source = u.host;
|
|
495
|
-
}
|
|
496
|
-
const base = server.config.base || "/";
|
|
497
|
-
try {
|
|
498
|
-
if (caddy)
|
|
499
|
-
return;
|
|
500
|
-
caddy = new CaddyInstant();
|
|
501
|
-
caddy.run(source, target, __spreadValues({
|
|
502
|
-
base
|
|
503
|
-
}, options)).then(() => {
|
|
504
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
505
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
506
|
-
}).catch((e) => {
|
|
507
|
-
throw e;
|
|
508
|
-
});
|
|
509
|
-
} catch (e) {
|
|
510
|
-
consola.error(e);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
547
|
+
const _printUrls = server.printUrls.bind(server);
|
|
548
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
549
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
550
|
+
if (url) {
|
|
551
|
+
const u = new URL(url);
|
|
552
|
+
source = u.host;
|
|
553
|
+
}
|
|
554
|
+
const base = server.config.base || "/";
|
|
555
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
513
556
|
}
|
|
514
557
|
},
|
|
515
558
|
webpack(compiler) {
|
|
516
|
-
var _a;
|
|
559
|
+
var _a, _b;
|
|
560
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
561
|
+
return;
|
|
562
|
+
const {
|
|
563
|
+
enable = true,
|
|
564
|
+
target = ""
|
|
565
|
+
} = options;
|
|
566
|
+
if (!enable)
|
|
567
|
+
return;
|
|
517
568
|
if (!isAdmin()) {
|
|
518
569
|
consola.warn("please run as administrator");
|
|
519
570
|
return;
|
|
520
571
|
}
|
|
572
|
+
if (!target) {
|
|
573
|
+
consola.fail("please provide target");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const devServer = __spreadValues(__spreadValues({
|
|
577
|
+
host: "localhost",
|
|
578
|
+
port: 8080
|
|
579
|
+
}, compiler.options.devServer), (_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
|
|
580
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
581
|
+
if (caddy)
|
|
582
|
+
return;
|
|
583
|
+
const _close = (_b = compiler.close) == null ? void 0 : _b.bind(compiler);
|
|
584
|
+
if (_close) {
|
|
585
|
+
compiler.close = async (callback) => {
|
|
586
|
+
import_node_process5.default.on("exit", () => {
|
|
587
|
+
_close && _close(callback);
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
} else {
|
|
591
|
+
options.https = false;
|
|
592
|
+
}
|
|
593
|
+
caddy = new CaddyInstant();
|
|
594
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
595
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
596
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
597
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
598
|
+
});
|
|
599
|
+
}).catch((e) => {
|
|
600
|
+
throw e;
|
|
601
|
+
});
|
|
602
|
+
},
|
|
603
|
+
async rspack(compiler) {
|
|
604
|
+
var _a, _b, _c;
|
|
521
605
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
522
606
|
return;
|
|
523
607
|
const {
|
|
@@ -526,40 +610,30 @@ var unpluginFactory = (options) => ({
|
|
|
526
610
|
} = options;
|
|
527
611
|
if (!enable)
|
|
528
612
|
return;
|
|
613
|
+
if (!isAdmin()) {
|
|
614
|
+
consola.warn("please run as administrator");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
529
617
|
if (!target) {
|
|
530
618
|
consola.fail("please provide target");
|
|
531
619
|
return;
|
|
532
620
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
options.https = false;
|
|
550
|
-
}
|
|
551
|
-
caddy = new CaddyInstant();
|
|
552
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
553
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
554
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
555
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
556
|
-
});
|
|
557
|
-
}).catch((e) => {
|
|
558
|
-
throw e;
|
|
559
|
-
});
|
|
560
|
-
} catch (e) {
|
|
561
|
-
consola.error(e);
|
|
562
|
-
}
|
|
621
|
+
const devServer = __spreadValues(__spreadValues({
|
|
622
|
+
host: "localhost",
|
|
623
|
+
port: 8080
|
|
624
|
+
}, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
625
|
+
cwd
|
|
626
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
|
|
627
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
628
|
+
if (caddy)
|
|
629
|
+
return;
|
|
630
|
+
caddy = new CaddyInstant();
|
|
631
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
632
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
633
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
634
|
+
}).catch((e) => {
|
|
635
|
+
throw e;
|
|
636
|
+
});
|
|
563
637
|
}
|
|
564
638
|
});
|
|
565
639
|
|
package/dist/webpack.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
|
|
2
|
+
unpluginFactory
|
|
3
|
+
} from "./chunk-XLSIGDFU.js";
|
|
4
|
+
import "./chunk-RUJE3YFB.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,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-https-reverse-proxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
5
|
-
"packageManager": "pnpm@8.
|
|
4
|
+
"version": "1.0.0-beta.10",
|
|
5
|
+
"packageManager": "pnpm@8.15.3",
|
|
6
6
|
"description": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
"import": "./dist/webpack.js",
|
|
37
37
|
"require": "./dist/webpack.cjs"
|
|
38
38
|
},
|
|
39
|
+
"./rspack": {
|
|
40
|
+
"types": "./dist/rspack.d.ts",
|
|
41
|
+
"import": "./dist/rspack.js",
|
|
42
|
+
"require": "./dist/rspack.cjs"
|
|
43
|
+
},
|
|
39
44
|
"./rollup": {
|
|
40
45
|
"types": "./dist/rollup.d.ts",
|
|
41
46
|
"import": "./dist/rollup.js",
|
|
@@ -77,6 +82,8 @@
|
|
|
77
82
|
"peerDependencies": {
|
|
78
83
|
"@nuxt/kit": "^3",
|
|
79
84
|
"@nuxt/schema": "^3",
|
|
85
|
+
"@rsbuild/core": "^0.4.3",
|
|
86
|
+
"@rspack/core": "^0.5.4",
|
|
80
87
|
"esbuild": "*",
|
|
81
88
|
"rollup": "^3",
|
|
82
89
|
"vite": ">=3",
|
|
@@ -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,47 +117,52 @@
|
|
|
104
117
|
},
|
|
105
118
|
"dependencies": {
|
|
106
119
|
"consola": "^3.2.3",
|
|
107
|
-
"
|
|
120
|
+
"dotenv-flow": "^4.1.0",
|
|
108
121
|
"got-cjs": "^12.5.4",
|
|
109
122
|
"hosts-so-easy": "^1.2.9",
|
|
110
|
-
"http-proxy-agent": "^7.0.
|
|
111
|
-
"https-proxy-agent": "^7.0.
|
|
123
|
+
"http-proxy-agent": "^7.0.2",
|
|
124
|
+
"https-proxy-agent": "^7.0.4",
|
|
112
125
|
"kill-port": "^2.0.1",
|
|
113
126
|
"ora": "5",
|
|
114
127
|
"picocolors": "^1.0.0",
|
|
115
|
-
"
|
|
128
|
+
"tsx": "^4.7.1",
|
|
129
|
+
"unplugin": "^1.7.1"
|
|
116
130
|
},
|
|
117
131
|
"devDependencies": {
|
|
118
|
-
"@antfu/eslint-config": "^0.40.
|
|
119
|
-
"@nuxt/kit": "^3.
|
|
120
|
-
"@nuxt/schema": "^3.
|
|
132
|
+
"@antfu/eslint-config": "^0.40.3",
|
|
133
|
+
"@nuxt/kit": "^3.10.2",
|
|
134
|
+
"@nuxt/schema": "^3.10.2",
|
|
135
|
+
"@rsbuild/core": "^0.4.3",
|
|
136
|
+
"@rspack/core": "^0.5.4",
|
|
121
137
|
"@types/kill-port": "^2.0.3",
|
|
122
|
-
"@types/node": "^20.
|
|
138
|
+
"@types/node": "^20.11.19",
|
|
123
139
|
"@vue/cli": "^5.0.8",
|
|
124
|
-
"bumpp": "^9.
|
|
140
|
+
"bumpp": "^9.3.0",
|
|
125
141
|
"chalk": "^5.3.0",
|
|
126
|
-
"eslint": "^8.
|
|
127
|
-
"fast-glob": "^3.3.
|
|
128
|
-
"nodemon": "^3.0.
|
|
129
|
-
"rimraf": "^5.0.
|
|
130
|
-
"rollup": "^3.
|
|
131
|
-
"tsup": "^7.
|
|
132
|
-
"typescript": "^5.
|
|
133
|
-
"vite": "^4.
|
|
134
|
-
"vitest": "^0.34.
|
|
135
|
-
"webpack": "^5.
|
|
142
|
+
"eslint": "^8.56.0",
|
|
143
|
+
"fast-glob": "^3.3.2",
|
|
144
|
+
"nodemon": "^3.0.3",
|
|
145
|
+
"rimraf": "^5.0.5",
|
|
146
|
+
"rollup": "^3.29.4",
|
|
147
|
+
"tsup": "^7.3.0",
|
|
148
|
+
"typescript": "^5.3.3",
|
|
149
|
+
"vite": "^4.5.2",
|
|
150
|
+
"vitest": "^0.34.6",
|
|
151
|
+
"webpack": "^5.90.3"
|
|
136
152
|
},
|
|
137
153
|
"scripts": {
|
|
138
|
-
"postinstall": "
|
|
154
|
+
"postinstall": "tsx scripts/postinstall.ts",
|
|
139
155
|
"build": "tsup",
|
|
140
156
|
"dev": "tsup --watch src",
|
|
141
|
-
"build:fix": "
|
|
157
|
+
"build:fix": "tsx scripts/postbuild.ts",
|
|
142
158
|
"lint": "eslint .",
|
|
143
159
|
"play": "npm -C examples/vite run dev",
|
|
160
|
+
"play:rsbuild": "npm -C examples/rsbuild run dev",
|
|
161
|
+
"play:nuxt": "npm -C examples/nuxt run dev",
|
|
144
162
|
"play:vuecli": "npm -C examples/vuecli run serve",
|
|
145
163
|
"play:vuecli4": "npm -C examples/vuecli4 run serve",
|
|
146
164
|
"release": "bumpp",
|
|
147
|
-
"start": "
|
|
165
|
+
"start": "tsx src/index.ts",
|
|
148
166
|
"test": "vitest"
|
|
149
167
|
}
|
|
150
168
|
}
|
package/src/caddy/constants.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
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
|
-
|
|
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')
|
|
7
19
|
|
package/src/caddy/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { platform } from 'node:os'
|
|
2
2
|
import process from 'node:process'
|
|
3
|
-
import { chmodSync, createWriteStream, existsSync, unlinkSync } from 'node:fs'
|
|
3
|
+
import { chmodSync, createWriteStream, existsSync, mkdirSync, unlinkSync } from 'node:fs'
|
|
4
4
|
import { spawn } from 'node:child_process'
|
|
5
5
|
import { got } from 'got-cjs'
|
|
6
6
|
import { HttpProxyAgent } from 'http-proxy-agent'
|
|
7
7
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
|
8
8
|
import kill from 'kill-port'
|
|
9
|
-
import { consola } from '../utils'
|
|
9
|
+
import { chmodRecursive, consola, once } from '../utils'
|
|
10
10
|
import { addHost, removeHost } from '../host'
|
|
11
|
-
import { caddyPath, supportList } from './constants'
|
|
11
|
+
import { TEMP_DIR, caddyPath, supportList } from './constants'
|
|
12
12
|
import { logProgress, logProgressOver, tryPort } from './utils'
|
|
13
13
|
|
|
14
14
|
export async function download() {
|
|
@@ -18,6 +18,11 @@ export async function download() {
|
|
|
18
18
|
return new Promise<string>((resolve, reject) => {
|
|
19
19
|
// https://caddyserver.com/api/download?os=darwin&arch=amd64
|
|
20
20
|
|
|
21
|
+
if (!existsSync(TEMP_DIR)) {
|
|
22
|
+
mkdirSync(TEMP_DIR, { recursive: true })
|
|
23
|
+
chmodSync(TEMP_DIR, 0o777)
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
const file = createWriteStream(caddyPath)
|
|
22
27
|
|
|
23
28
|
let _platform = platform().toString()
|
|
@@ -42,6 +47,11 @@ export async function download() {
|
|
|
42
47
|
const httpAgent = httpProxy ? new HttpProxyAgent(httpProxy) : undefined
|
|
43
48
|
const httpsAgent = httpsProxy ? new HttpsProxyAgent(httpsProxy) : undefined
|
|
44
49
|
|
|
50
|
+
const chmodCaddyOnce = once(() => {
|
|
51
|
+
// chmod +x
|
|
52
|
+
chmodSync(caddyPath, 0o777)
|
|
53
|
+
})
|
|
54
|
+
|
|
45
55
|
got.stream(dowmloadLink, {
|
|
46
56
|
agent: {
|
|
47
57
|
http: httpAgent,
|
|
@@ -49,12 +59,13 @@ export async function download() {
|
|
|
49
59
|
},
|
|
50
60
|
}).on('downloadProgress', (progress) => {
|
|
51
61
|
logProgress(progress.percent)
|
|
62
|
+
chmodCaddyOnce()
|
|
52
63
|
}).pipe(file).on('finish', () => {
|
|
53
64
|
logProgressOver()
|
|
54
65
|
if (process.platform === 'win32')
|
|
55
66
|
return resolve(caddyPath)
|
|
56
67
|
// chmod +x
|
|
57
|
-
chmodSync(caddyPath,
|
|
68
|
+
chmodSync(caddyPath, 0o777)
|
|
58
69
|
resolve(caddyPath)
|
|
59
70
|
}).on('error', (err) => {
|
|
60
71
|
// consola.error(err)
|
|
@@ -67,7 +78,7 @@ function testCaddy() {
|
|
|
67
78
|
return new Promise((resolve, reject) => {
|
|
68
79
|
if (!existsSync(caddyPath))
|
|
69
80
|
return resolve(false)
|
|
70
|
-
chmodSync(caddyPath,
|
|
81
|
+
chmodSync(caddyPath, 0o777)
|
|
71
82
|
const child = process.platform === 'win32' ? spawn(caddyPath, []) : spawn('sudo', ['-E', caddyPath])
|
|
72
83
|
child.on('close', () => {
|
|
73
84
|
return resolve(false)
|
|
@@ -166,6 +177,22 @@ export class CaddyInstant {
|
|
|
166
177
|
|
|
167
178
|
// @ts-expect-error override
|
|
168
179
|
process.exit = async (code?: number) => {
|
|
180
|
+
const port = Number(source.split(':')[1])
|
|
181
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
182
|
+
await kill(port, 'tcp')
|
|
183
|
+
|
|
184
|
+
// fix `Error: EPERM: operation not permitted`
|
|
185
|
+
const pwd = process.cwd()
|
|
186
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`
|
|
187
|
+
if (existsSync(viteCacheDir))
|
|
188
|
+
chmodRecursive(viteCacheDir, 0o777)
|
|
189
|
+
const nuxtCacheDir = `${pwd}/.nuxt`
|
|
190
|
+
if (existsSync(nuxtCacheDir))
|
|
191
|
+
await chmodRecursive(nuxtCacheDir, 0o777)
|
|
192
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`
|
|
193
|
+
if (existsSync(webpackCacheDir))
|
|
194
|
+
chmodRecursive(webpackCacheDir, 0o777)
|
|
195
|
+
|
|
169
196
|
if (!restore || this.stoped)
|
|
170
197
|
return originalExit(code)
|
|
171
198
|
|
package/src/host/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { chmodSync } from 'node:fs'
|
|
|
4
4
|
|
|
5
5
|
// @ts-expect-error no type
|
|
6
6
|
import _Hosts from 'hosts-so-easy'
|
|
7
|
+
import { consola } from '../utils'
|
|
7
8
|
|
|
8
9
|
const Hosts = _Hosts.default || _Hosts
|
|
9
10
|
|
|
@@ -26,7 +27,7 @@ async function syncHost() {
|
|
|
26
27
|
: 'sudo -E killall -HUP mDNSResponder',
|
|
27
28
|
(error, stdout, stderr) => {
|
|
28
29
|
if (error) {
|
|
29
|
-
|
|
30
|
+
consola.error(`exec error: ${error}`)
|
|
30
31
|
return resolve(false)
|
|
31
32
|
}
|
|
32
33
|
return resolve(true)
|
|
@@ -39,6 +40,8 @@ export async function addHost(ip: string, host: string) {
|
|
|
39
40
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
40
41
|
hostInstance.add('127.0.0.1', 'localhost')
|
|
41
42
|
hostInstance.add(ip, host)
|
|
43
|
+
if (ip === 'localhost')
|
|
44
|
+
hostInstance.add('127.0.0.1', host)
|
|
42
45
|
await hostInstance.updateFinish()
|
|
43
46
|
return await syncHost()
|
|
44
47
|
}
|