unplugin-https-reverse-proxy 4.0.4 → 4.1.0-beta.2

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.
Files changed (47) hide show
  1. package/README.md +30 -6
  2. package/dist/{chunk-5R33PUJP.js → chunk-7CA3EIIX.js} +681 -223
  3. package/dist/{chunk-2P7SUCQ3.js → chunk-EY3HXBJ4.js} +0 -26
  4. package/dist/chunk-RKHJN6KY.js +53 -0
  5. package/dist/esbuild.cjs +781 -300
  6. package/dist/esbuild.js +3 -2
  7. package/dist/index.cjs +781 -300
  8. package/dist/index.js +3 -2
  9. package/dist/nuxt.cjs +779 -290
  10. package/dist/nuxt.js +5 -9
  11. package/dist/privileged-helper.cjs +668 -0
  12. package/dist/privileged-helper.d.cts +2 -0
  13. package/dist/privileged-helper.d.ts +2 -0
  14. package/dist/privileged-helper.js +641 -0
  15. package/dist/rollup.cjs +781 -300
  16. package/dist/rollup.js +3 -2
  17. package/dist/rspack.cjs +781 -300
  18. package/dist/rspack.js +3 -2
  19. package/dist/utils.cjs +0 -28
  20. package/dist/utils.d.cts +1 -3
  21. package/dist/utils.d.ts +1 -3
  22. package/dist/utils.js +1 -5
  23. package/dist/vite.cjs +781 -300
  24. package/dist/vite.js +3 -2
  25. package/dist/webpack.cjs +781 -300
  26. package/dist/webpack.js +3 -2
  27. package/package.json +1 -4
  28. package/src/caddy/caddyfile.ts +1 -0
  29. package/src/caddy/index.ts +183 -110
  30. package/src/caddy/privileged.ts +118 -0
  31. package/src/caddy/utils.ts +0 -43
  32. package/src/index.ts +1 -15
  33. package/src/nuxt.ts +1 -6
  34. package/src/privileged/bootstrap.ts +174 -0
  35. package/src/privileged/client.ts +287 -0
  36. package/src/privileged/entry.ts +45 -0
  37. package/src/privileged/hosts-file.ts +142 -0
  38. package/src/privileged/launch.ts +193 -0
  39. package/src/privileged/ports.ts +45 -0
  40. package/src/privileged/protocol.ts +111 -0
  41. package/src/privileged/server.ts +465 -0
  42. package/src/privileged/session.ts +114 -0
  43. package/src/privileged/validation.ts +38 -0
  44. package/src/privileged/windows-elevation.ts +80 -0
  45. package/src/privileged-helper.ts +109 -0
  46. package/src/utils.ts +0 -28
  47. package/src/host/index.ts +0 -52
package/dist/index.cjs CHANGED
@@ -36,18 +36,18 @@ __export(src_exports, {
36
36
  vitePrintUrls: () => vitePrintUrls
37
37
  });
38
38
  module.exports = __toCommonJS(src_exports);
39
- var import_node_process5 = __toESM(require("process"), 1);
39
+ var import_node_process8 = __toESM(require("process"), 1);
40
40
  var import_console_table_printer = require("console-table-printer");
41
41
  var import_picocolors2 = __toESM(require("picocolors"), 1);
42
42
  var import_unplugin = require("unplugin");
43
43
 
44
44
  // src/caddy/index.ts
45
- var import_node_child_process4 = require("child_process");
46
- var import_node_fs3 = require("fs");
45
+ var import_node_child_process3 = require("child_process");
46
+ var import_node_fs4 = require("fs");
47
47
  var import_promises3 = require("fs/promises");
48
- var import_node_os3 = require("os");
49
- var import_node_path3 = require("path");
50
- var import_node_process4 = __toESM(require("process"), 1);
48
+ var import_node_os5 = require("os");
49
+ var import_node_path5 = require("path");
50
+ var import_node_process7 = __toESM(require("process"), 1);
51
51
 
52
52
  // node_modules/.pnpm/alien-signals@2.0.7/node_modules/alien-signals/esm/system.mjs
53
53
  var ReactiveFlags;
@@ -489,33 +489,14 @@ var import_http_proxy_agent = require("http-proxy-agent");
489
489
  var import_https_proxy_agent = require("https-proxy-agent");
490
490
  var lockfile = __toESM(require("proper-lockfile"), 1);
491
491
 
492
- // src/host/index.ts
493
- var import_node_child_process2 = require("child_process");
494
- var import_node_fs = require("fs");
495
- var import_node_process2 = __toESM(require("process"), 1);
496
- var import_node_util = require("util");
497
- var import_hostile = __toESM(require("hostile"), 1);
498
-
499
492
  // src/utils.ts
500
- var import_node_child_process = require("child_process");
501
- var import_promises = require("fs/promises");
502
493
  var import_node_os = require("os");
503
- var import_node_path = __toESM(require("path"), 1);
504
- var import_node_process = __toESM(require("process"), 1);
505
494
  var import_consola = require("consola");
506
495
  var import_picocolors = __toESM(require("picocolors"), 1);
507
496
  var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
508
497
  var consola = (0, import_consola.createConsola)({
509
498
  level: 3
510
499
  }).withTag("reverse-proxy");
511
- async function chmodRecursive(_path, mode) {
512
- await (0, import_promises.chmod)(_path, mode);
513
- if ((await (0, import_promises.stat)(_path)).isDirectory()) {
514
- const children = await (0, import_promises.readdir)(_path);
515
- for (const child of children)
516
- await chmodRecursive(import_node_path.default.join(_path, child), mode);
517
- }
518
- }
519
500
  function once(fn) {
520
501
  let called = false;
521
502
  return (...args2) => {
@@ -525,18 +506,6 @@ function once(fn) {
525
506
  return fn(...args2);
526
507
  };
527
508
  }
528
- function isAdmin() {
529
- if (import_node_process.default.platform === "win32") {
530
- try {
531
- (0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
532
- return true;
533
- } catch {
534
- return false;
535
- }
536
- } else {
537
- return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
538
- }
539
- }
540
509
  function getIpv4List() {
541
510
  const interfaces = (0, import_node_os.networkInterfaces)();
542
511
  return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
@@ -551,44 +520,6 @@ async function generateQrcode(input) {
551
520
  });
552
521
  }
553
522
 
554
- // src/host/index.ts
555
- var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
556
- var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
557
- function getPathOfSystemHostsPath() {
558
- return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
559
- }
560
- async function syncHost() {
561
- return new Promise((resolve2, _reject) => {
562
- (0, import_node_child_process2.exec)(
563
- import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
564
- (error, _stdout, _stderr) => {
565
- if (error) {
566
- consola.error(`exec error: ${error}`);
567
- return resolve2(false);
568
- }
569
- return resolve2(true);
570
- }
571
- );
572
- });
573
- }
574
- async function addHost(ip2, host) {
575
- if (import_node_process2.default.platform !== "win32")
576
- (0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
577
- await _setHost("127.0.0.1", "localhost");
578
- await _setHost(ip2, host);
579
- if (ip2 === "localhost")
580
- await _setHost("127.0.0.1", host);
581
- return await syncHost();
582
- }
583
- async function removeHost(ip2, host) {
584
- if (import_node_process2.default.platform !== "win32")
585
- (0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
586
- await _removeHost(ip2, host);
587
- if (ip2 === "localhost")
588
- await _removeHost("127.0.0.1", host);
589
- return await syncHost();
590
- }
591
-
592
523
  // node_modules/.pnpm/@ark+util@0.46.0/node_modules/@ark/util/out/arrays.js
593
524
  var liftArray = (data) => Array.isArray(data) ? data : [data];
594
525
  var spliterate = (arr, predicate) => {
@@ -1216,29 +1147,29 @@ var timeWithUnnecessarySeconds = /:\d\d:00$/;
1216
1147
  var pad = (value2, length) => String(value2).padStart(length, "0");
1217
1148
 
1218
1149
  // node_modules/.pnpm/@ark+util@0.46.0/node_modules/@ark/util/out/path.js
1219
- var appendStringifiedKey = (path2, prop, ...[opts]) => {
1150
+ var appendStringifiedKey = (path, prop, ...[opts]) => {
1220
1151
  const stringifySymbol = (opts == null ? void 0 : opts.stringifySymbol) ?? printable;
1221
- let propAccessChain = path2;
1152
+ let propAccessChain = path;
1222
1153
  switch (typeof prop) {
1223
1154
  case "string":
1224
- propAccessChain = isDotAccessible(prop) ? path2 === "" ? prop : `${path2}.${prop}` : `${path2}[${JSON.stringify(prop)}]`;
1155
+ propAccessChain = isDotAccessible(prop) ? path === "" ? prop : `${path}.${prop}` : `${path}[${JSON.stringify(prop)}]`;
1225
1156
  break;
1226
1157
  case "number":
1227
- propAccessChain = `${path2}[${prop}]`;
1158
+ propAccessChain = `${path}[${prop}]`;
1228
1159
  break;
1229
1160
  case "symbol":
1230
- propAccessChain = `${path2}[${stringifySymbol(prop)}]`;
1161
+ propAccessChain = `${path}[${stringifySymbol(prop)}]`;
1231
1162
  break;
1232
1163
  default:
1233
1164
  if (opts == null ? void 0 : opts.stringifyNonKey)
1234
- propAccessChain = `${path2}[${opts.stringifyNonKey(prop)}]`;
1165
+ propAccessChain = `${path}[${opts.stringifyNonKey(prop)}]`;
1235
1166
  else {
1236
1167
  throwParseError(`${printable(prop)} must be a PropertyKey or stringifyNonKey must be passed to options`);
1237
1168
  }
1238
1169
  }
1239
1170
  return propAccessChain;
1240
1171
  };
1241
- var stringifyPath = (path2, ...opts) => path2.reduce((s, k) => appendStringifiedKey(s, k, ...opts), "");
1172
+ var stringifyPath = (path, ...opts) => path.reduce((s, k) => appendStringifiedKey(s, k, ...opts), "");
1242
1173
  var ReadonlyPath = class extends ReadonlyArray {
1243
1174
  // alternate strategy for caching since the base object is frozen
1244
1175
  cache = {};
@@ -1265,8 +1196,8 @@ var ReadonlyPath = class extends ReadonlyArray {
1265
1196
  return this.cache.stringifyAncestors;
1266
1197
  let propString = "";
1267
1198
  const result = [propString];
1268
- for (const path2 of this) {
1269
- propString = appendStringifiedKey(propString, path2);
1199
+ for (const path of this) {
1200
+ propString = appendStringifiedKey(propString, path);
1270
1201
  result.push(propString);
1271
1202
  }
1272
1203
  return this.cache.stringifyAncestors = result;
@@ -1859,15 +1790,15 @@ var ArkErrors = class _ArkErrors extends ReadonlyArray {
1859
1790
  /**
1860
1791
  * @internal
1861
1792
  */
1862
- affectsPath(path2) {
1793
+ affectsPath(path) {
1863
1794
  if (this.length === 0)
1864
1795
  return false;
1865
1796
  return (
1866
1797
  // this would occur if there is an existing error at a prefix of path
1867
1798
  // e.g. the path is ["foo", "bar"] and there is an error at ["foo"]
1868
- path2.stringifyAncestors().some((s) => s in this.byPath) || // this would occur if there is an existing error at a suffix of path
1799
+ path.stringifyAncestors().some((s) => s in this.byPath) || // this would occur if there is an existing error at a suffix of path
1869
1800
  // e.g. the path is ["foo"] and there is an error at ["foo", "bar"]
1870
- path2.stringify() in this.byAncestorPath
1801
+ path.stringify() in this.byAncestorPath
1871
1802
  );
1872
1803
  }
1873
1804
  /**
@@ -2074,22 +2005,22 @@ var Traversal = class {
2074
2005
  while (this.queuedMorphs.length) {
2075
2006
  const queuedMorphs = this.queuedMorphs;
2076
2007
  this.queuedMorphs = [];
2077
- for (const { path: path2, morphs } of queuedMorphs) {
2078
- if (this.errors.affectsPath(path2))
2008
+ for (const { path, morphs } of queuedMorphs) {
2009
+ if (this.errors.affectsPath(path))
2079
2010
  continue;
2080
- this.applyMorphsAtPath(path2, morphs);
2011
+ this.applyMorphsAtPath(path, morphs);
2081
2012
  }
2082
2013
  }
2083
2014
  }
2084
- applyMorphsAtPath(path2, morphs) {
2085
- const key = path2.at(-1);
2015
+ applyMorphsAtPath(path, morphs) {
2016
+ const key = path.at(-1);
2086
2017
  let parent;
2087
2018
  if (key !== void 0) {
2088
2019
  parent = this.root;
2089
- for (let pathIndex = 0; pathIndex < path2.length - 1; pathIndex++)
2090
- parent = parent[path2[pathIndex]];
2020
+ for (let pathIndex = 0; pathIndex < path.length - 1; pathIndex++)
2021
+ parent = parent[path[pathIndex]];
2091
2022
  }
2092
- this.path = [...path2];
2023
+ this.path = [...path];
2093
2024
  for (const morph of morphs) {
2094
2025
  const morphIsNode = isNode(morph);
2095
2026
  const result = morph(parent === void 0 ? this.root : parent[key], this);
@@ -2459,15 +2390,15 @@ var NodeSelector = {
2459
2390
  normalize: (selector) => typeof selector === "function" ? { boundary: "references", method: "filter", where: selector } : typeof selector === "string" ? isKeyOf(selector, NodeSelector.applyBoundary) ? { method: "filter", boundary: selector } : { boundary: "references", method: "filter", kind: selector } : { boundary: "references", method: "filter", ...selector }
2460
2391
  };
2461
2392
  var writeSelectAssertionMessage = (from, selector) => `${from} had no references matching ${printable(selector)}.`;
2462
- var typePathToPropString = (path2) => stringifyPath(path2, {
2393
+ var typePathToPropString = (path) => stringifyPath(path, {
2463
2394
  stringifyNonKey: (node2) => node2.expression
2464
2395
  });
2465
2396
  var referenceMatcher = /"(\$ark\.[^"]+)"/g;
2466
2397
  var compileMeta = (metaJson) => JSON.stringify(metaJson).replaceAll(referenceMatcher, "$1");
2467
- var flatRef = (path2, node2) => ({
2468
- path: path2,
2398
+ var flatRef = (path, node2) => ({
2399
+ path,
2469
2400
  node: node2,
2470
- propString: typePathToPropString(path2)
2401
+ propString: typePathToPropString(path)
2471
2402
  });
2472
2403
  var flatRefsAreEqual = (l, r) => l.propString === r.propString && l.node.equals(r.node);
2473
2404
  var appendUniqueFlatRefs = (existing, refs) => appendUnique(existing, refs, {
@@ -2503,12 +2434,12 @@ var Disjoint = class _Disjoint extends Array {
2503
2434
  }
2504
2435
  describeReasons() {
2505
2436
  if (this.length === 1) {
2506
- const { path: path2, l, r } = this[0];
2507
- const pathString = stringifyPath(path2);
2437
+ const { path, l, r } = this[0];
2438
+ const pathString = stringifyPath(path);
2508
2439
  return writeUnsatisfiableExpressionError(`Intersection${pathString && ` at ${pathString}`} of ${describeReasons(l, r)}`);
2509
2440
  }
2510
2441
  return `The following intersections result in unsatisfiable types:
2511
- \u2022 ${this.map(({ path: path2, l, r }) => `${path2}: ${describeReasons(l, r)}`).join("\n\u2022 ")}`;
2442
+ \u2022 ${this.map(({ path, l, r }) => `${path}: ${describeReasons(l, r)}`).join("\n\u2022 ")}`;
2512
2443
  }
2513
2444
  throw() {
2514
2445
  return throwParseError(this.describeReasons());
@@ -3868,10 +3799,10 @@ var BaseRoot = class extends BaseNode {
3868
3799
  });
3869
3800
  });
3870
3801
  }
3871
- get(...path2) {
3872
- if (path2[0] === void 0)
3802
+ get(...path) {
3803
+ if (path[0] === void 0)
3873
3804
  return this;
3874
- return this.$.schema(this.applyStructuralOperation("get", path2));
3805
+ return this.$.schema(this.applyStructuralOperation("get", path));
3875
3806
  }
3876
3807
  extract(r) {
3877
3808
  const rNode = this.$.parseDefinition(r);
@@ -4806,13 +4737,13 @@ var implementation17 = implementNode({
4806
4737
  description: (node2) => node2.distribute((branch) => branch.description, describeBranches),
4807
4738
  expected: (ctx) => {
4808
4739
  const byPath = groupBy(ctx.errors, "propString");
4809
- const pathDescriptions = Object.entries(byPath).map(([path2, errors]) => {
4740
+ const pathDescriptions = Object.entries(byPath).map(([path, errors]) => {
4810
4741
  const branchesAtPath = [];
4811
4742
  for (const errorAtPath of errors)
4812
4743
  appendUnique(branchesAtPath, errorAtPath.expected);
4813
4744
  const expected = describeBranches(branchesAtPath);
4814
4745
  const actual = errors.every((e) => e.actual === errors[0].actual) ? errors[0].actual : printable(errors[0].data);
4815
- return `${path2 && `${path2} `}must be ${expected}${actual && ` (was ${actual})`}`;
4746
+ return `${path && `${path} `}must be ${expected}${actual && ` (was ${actual})`}`;
4816
4747
  });
4817
4748
  return describeBranches(pathDescriptions);
4818
4749
  },
@@ -5176,10 +5107,10 @@ var orderCandidates = (candidates, originalBranches) => {
5176
5107
  });
5177
5108
  return viableCandidates;
5178
5109
  };
5179
- var discriminantCaseToNode = (caseDiscriminant, path2, $) => {
5110
+ var discriminantCaseToNode = (caseDiscriminant, path, $) => {
5180
5111
  let node2 = caseDiscriminant === "undefined" ? $.node("unit", { unit: void 0 }) : caseDiscriminant === "null" ? $.node("unit", { unit: null }) : caseDiscriminant === "boolean" ? $.units([true, false]) : caseDiscriminant;
5181
- for (let i = path2.length - 1; i >= 0; i--) {
5182
- const key = path2[i];
5112
+ for (let i = path.length - 1; i >= 0; i--) {
5113
+ const key = path[i];
5183
5114
  node2 = $.node("intersection", typeof key === "number" ? {
5184
5115
  proto: "Array",
5185
5116
  // create unknown for preceding elements (could be optimized with safe imports)
@@ -5191,7 +5122,7 @@ var discriminantCaseToNode = (caseDiscriminant, path2, $) => {
5191
5122
  }
5192
5123
  return node2;
5193
5124
  };
5194
- var optionallyChainPropString = (path2) => path2.reduce((acc, k) => acc + compileLiteralPropAccess(k, true), "data");
5125
+ var optionallyChainPropString = (path) => path.reduce((acc, k) => acc + compileLiteralPropAccess(k, true), "data");
5195
5126
  var serializedTypeOfDescriptions = registeredReference(jsTypeOfDescriptions);
5196
5127
  var serializedPrintable = registeredReference(printable);
5197
5128
  var Union = {
@@ -6149,7 +6080,7 @@ var StructureNode = class extends BaseConstraint {
6149
6080
  return throwParseError(writeInvalidKeysMessage(this.expression, invalidKeys));
6150
6081
  }
6151
6082
  }
6152
- get(indexer, ...path2) {
6083
+ get(indexer, ...path) {
6153
6084
  var _a4;
6154
6085
  let value2;
6155
6086
  let required = false;
@@ -6186,7 +6117,7 @@ var StructureNode = class extends BaseConstraint {
6186
6117
  }
6187
6118
  return throwParseError(writeInvalidKeysMessage(this.expression, [key]));
6188
6119
  }
6189
- const result = value2.get(...path2);
6120
+ const result = value2.get(...path);
6190
6121
  return required ? result : result.or($ark.intrinsic.undefined);
6191
6122
  }
6192
6123
  pick(...keys) {
@@ -8912,7 +8843,7 @@ function isIterator(val) {
8912
8843
  function escapeRegex(str) {
8913
8844
  return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
8914
8845
  }
8915
- function promisify2(fn) {
8846
+ function promisify(fn) {
8916
8847
  return function(...args2) {
8917
8848
  return new Promise((resolve2, reject2) => {
8918
8849
  fn(...args2, (err, result) => {
@@ -10248,8 +10179,8 @@ function requireResolve(file) {
10248
10179
  const require2 = (0, import_module3.createRequire)(process.cwd() + "/");
10249
10180
  return require2.resolve(file);
10250
10181
  }
10251
- var statAsync = promisify2(import_fs.stat);
10252
- var readFileAsync = promisify2(import_fs.readFile);
10182
+ var statAsync = promisify(import_fs.stat);
10183
+ var readFileAsync = promisify(import_fs.readFile);
10253
10184
  function exists(filepath) {
10254
10185
  return __awaiter(this, void 0, void 0, function* () {
10255
10186
  try {
@@ -11491,10 +11422,10 @@ var Loader = class {
11491
11422
  yield filepath;
11492
11423
  }
11493
11424
  }
11494
- dirname(path2) {
11425
+ dirname(path) {
11495
11426
  const fs2 = this.options.fs;
11496
11427
  assert(fs2.dirname, "`fs.dirname` is required for relative reference");
11497
- return fs2.dirname(path2);
11428
+ return fs2.dirname(path);
11498
11429
  }
11499
11430
  lookupError(file, roots) {
11500
11431
  const err = new Error("ENOENT");
@@ -13456,6 +13387,7 @@ function validateTemplateContext(ctx) {
13456
13387
  var caddyTemplate = `{
13457
13388
  debug
13458
13389
  auto_https disable_redirects ignore_loaded_certs
13390
+ skip_install_trust
13459
13391
  }
13460
13392
 
13461
13393
  :7601 {
@@ -13536,27 +13468,27 @@ async function genCaddyfile(ctx) {
13536
13468
  }
13537
13469
 
13538
13470
  // src/caddy/config.ts
13539
- var import_node_fs2 = require("fs");
13540
- var import_promises2 = require("fs/promises");
13471
+ var import_node_fs = require("fs");
13472
+ var import_promises = require("fs/promises");
13541
13473
 
13542
13474
  // src/caddy/constants.ts
13543
13475
  var import_node_os2 = __toESM(require("os"), 1);
13544
- var import_node_path2 = require("path");
13545
- var import_node_process3 = __toESM(require("process"), 1);
13476
+ var import_node_path = require("path");
13477
+ var import_node_process = __toESM(require("process"), 1);
13546
13478
  var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
13547
13479
  import_dotenv_flow.default.config({
13548
13480
  silent: true
13549
13481
  });
13550
- function resolvePath(path2) {
13551
- if (path2.startsWith("~"))
13552
- return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
13553
- return path2;
13554
- }
13555
- 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");
13556
- var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
13557
- var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
13558
- var caddyConfigPath = (0, import_node_path2.join)(TEMP_DIR, ".CADDYFILE.config.json");
13559
- var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
13482
+ function resolvePath(path) {
13483
+ if (path.startsWith("~"))
13484
+ return (0, import_node_path.join)(import_node_os2.default.homedir() || "", path.slice(1));
13485
+ return path;
13486
+ }
13487
+ var TEMP_DIR = resolvePath(import_node_process.default.env.UHRP_CADDY_PATH || import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp");
13488
+ var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
13489
+ var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
13490
+ var caddyConfigPath = (0, import_node_path.join)(TEMP_DIR, ".CADDYFILE.config.json");
13491
+ var caddyLockFilePath = (0, import_node_path.join)(TEMP_DIR, "caddylock");
13560
13492
  var supportList = [
13561
13493
  {
13562
13494
  platform: "dragonfly",
@@ -13679,19 +13611,19 @@ function useCaddyConfig() {
13679
13611
  }
13680
13612
  });
13681
13613
  function setConfigContent() {
13682
- if (!(0, import_node_fs2.existsSync)(caddyConfigPath)) {
13683
- (0, import_node_fs2.writeFileSync)(caddyConfigPath, "{}");
13614
+ if (!(0, import_node_fs.existsSync)(caddyConfigPath)) {
13615
+ (0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
13684
13616
  }
13685
13617
  try {
13686
- configContentRef((0, import_node_fs2.readFileSync)(caddyConfigPath, "utf-8"));
13618
+ configContentRef((0, import_node_fs.readFileSync)(caddyConfigPath, "utf-8"));
13687
13619
  } catch {
13688
13620
  configContentRef("");
13689
13621
  }
13690
13622
  }
13691
- if (!(0, import_node_fs2.existsSync)(caddyConfigPath)) {
13692
- (0, import_node_fs2.writeFileSync)(caddyConfigPath, "{}");
13623
+ if (!(0, import_node_fs.existsSync)(caddyConfigPath)) {
13624
+ (0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
13693
13625
  }
13694
- const watchCaddyConfig = (0, import_node_fs2.watch)(caddyConfigPath, () => {
13626
+ const watchCaddyConfig = (0, import_node_fs.watch)(caddyConfigPath, () => {
13695
13627
  setConfigContent();
13696
13628
  });
13697
13629
  function writeCaddyConfig(_proxies) {
@@ -13707,10 +13639,10 @@ function useCaddyConfig() {
13707
13639
  });
13708
13640
  const content = JSON.stringify(proxies, null, 2);
13709
13641
  configContentRef(content);
13710
- return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
13642
+ return (0, import_node_fs.writeFileSync)(caddyConfigPath, content);
13711
13643
  }
13712
13644
  async function cleanUp() {
13713
- await (0, import_promises2.unlink)(caddyConfigPath).catch(() => {
13645
+ await (0, import_promises.unlink)(caddyConfigPath).catch(() => {
13714
13646
  });
13715
13647
  configContentRef("{}");
13716
13648
  watchCaddyConfig.close();
@@ -13732,6 +13664,552 @@ function isCaddyReloadCancellation(line) {
13732
13664
  }
13733
13665
  }
13734
13666
 
13667
+ // src/caddy/privileged.ts
13668
+ var import_node_buffer2 = require("buffer");
13669
+ var import_node_events = require("events");
13670
+ var import_node_path4 = require("path");
13671
+ var import_node_process6 = __toESM(require("process"), 1);
13672
+ var import_node_url = require("url");
13673
+
13674
+ // src/privileged/entry.ts
13675
+ var import_node_fs2 = require("fs");
13676
+ var import_node_path2 = require("path");
13677
+ var import_node_process2 = __toESM(require("process"), 1);
13678
+ function resolveHelperEntry(options) {
13679
+ const { moduleDir, nodeBin = import_node_process2.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
13680
+ for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
13681
+ const candidate = (0, import_node_path2.join)(moduleDir, name);
13682
+ if (exists2(candidate))
13683
+ return { entry: nodeBin, args: [candidate] };
13684
+ }
13685
+ const source = (0, import_node_path2.join)(moduleDir, "privileged-helper.ts");
13686
+ const tsxCli = (0, import_node_path2.join)(moduleDir, "../node_modules/tsx/dist/cli.mjs");
13687
+ if (exists2(source) && exists2(tsxCli))
13688
+ return { entry: nodeBin, args: [tsxCli, source] };
13689
+ throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
13690
+ }
13691
+
13692
+ // src/privileged/session.ts
13693
+ var import_node_buffer = require("buffer");
13694
+ var import_node_fs3 = require("fs");
13695
+ var import_promises2 = require("fs/promises");
13696
+ var import_node_os4 = require("os");
13697
+ var import_node_path3 = require("path");
13698
+
13699
+ // src/privileged/launch.ts
13700
+ var import_node_child_process2 = require("child_process");
13701
+ var import_node_crypto = require("crypto");
13702
+ var import_node_os3 = require("os");
13703
+ var import_node_process5 = __toESM(require("process"), 1);
13704
+
13705
+ // src/privileged/client.ts
13706
+ var import_node_net = require("net");
13707
+ var import_node_process3 = __toESM(require("process"), 1);
13708
+
13709
+ // src/privileged/protocol.ts
13710
+ function serializeMessage(message) {
13711
+ return `${JSON.stringify(message)}
13712
+ `;
13713
+ }
13714
+ function splitLines(buffer, chunk) {
13715
+ const parts = (buffer + chunk).split("\n");
13716
+ const rest = parts.pop() ?? "";
13717
+ return { lines: parts.filter((line) => line.trim() !== ""), rest };
13718
+ }
13719
+ function isRecord(value2) {
13720
+ return typeof value2 === "object" && value2 !== null;
13721
+ }
13722
+ function decodeMessage(line) {
13723
+ let parsed2;
13724
+ try {
13725
+ parsed2 = JSON.parse(line);
13726
+ } catch (error) {
13727
+ return { ok: false, error: `invalid JSON: ${error.message}` };
13728
+ }
13729
+ if (!isRecord(parsed2))
13730
+ return { ok: false, error: "message must be an object" };
13731
+ if (parsed2.type === "event") {
13732
+ if (typeof parsed2.kind !== "string")
13733
+ return { ok: false, error: "event.kind must be a string" };
13734
+ return { ok: true, message: parsed2 };
13735
+ }
13736
+ if (typeof parsed2.id !== "number")
13737
+ return { ok: false, error: "response.id must be a number" };
13738
+ if (parsed2.ok === true)
13739
+ return { ok: true, message: { id: parsed2.id, ok: true, result: parsed2.result } };
13740
+ if (parsed2.ok === false) {
13741
+ const error = isRecord(parsed2.error) ? parsed2.error : {};
13742
+ return {
13743
+ ok: true,
13744
+ message: {
13745
+ id: parsed2.id,
13746
+ ok: false,
13747
+ error: {
13748
+ message: typeof error.message === "string" ? error.message : "helper request failed",
13749
+ code: typeof error.code === "string" ? error.code : void 0
13750
+ }
13751
+ }
13752
+ };
13753
+ }
13754
+ return { ok: false, error: "response.ok must be a boolean" };
13755
+ }
13756
+
13757
+ // src/privileged/client.ts
13758
+ var FORWARDED_ENV_KEYS = [
13759
+ "HOME",
13760
+ "USER",
13761
+ "LOGNAME",
13762
+ "TMPDIR",
13763
+ "HTTP_PROXY",
13764
+ "HTTPS_PROXY",
13765
+ "http_proxy",
13766
+ "https_proxy",
13767
+ "NO_PROXY",
13768
+ "no_proxy"
13769
+ ];
13770
+ function collectForwardedEnv(source = import_node_process3.default.env) {
13771
+ const result = {};
13772
+ for (const key of FORWARDED_ENV_KEYS) {
13773
+ const value2 = source[key];
13774
+ if (typeof value2 === "string" && value2 !== "")
13775
+ result[key] = value2;
13776
+ }
13777
+ return result;
13778
+ }
13779
+ var HelperConnectionError = class extends Error {
13780
+ constructor(message) {
13781
+ super(message);
13782
+ this.name = "HelperConnectionError";
13783
+ }
13784
+ };
13785
+ function openSocket(socketPath) {
13786
+ return new Promise((resolve2, reject2) => {
13787
+ const socket = (0, import_node_net.connect)(socketPath);
13788
+ function onConnect() {
13789
+ socket.removeListener("error", onError);
13790
+ resolve2(socket);
13791
+ }
13792
+ function onError(error) {
13793
+ socket.removeListener("connect", onConnect);
13794
+ reject2(error);
13795
+ }
13796
+ socket.once("error", onError);
13797
+ socket.once("connect", onConnect);
13798
+ });
13799
+ }
13800
+ async function connectClient(options) {
13801
+ const {
13802
+ socketPath,
13803
+ token,
13804
+ timeoutMs = 12e4,
13805
+ retryIntervalMs = 100,
13806
+ callTimeoutMs = 3e4
13807
+ } = options;
13808
+ const deadline = Date.now() + timeoutMs;
13809
+ let lastError;
13810
+ while (Date.now() < deadline) {
13811
+ try {
13812
+ return await handshake(socketPath, token, callTimeoutMs);
13813
+ } catch (error) {
13814
+ lastError = error;
13815
+ const code = lastError.code;
13816
+ if (code === "EACCES" || lastError instanceof HelperConnectionError)
13817
+ throw lastError;
13818
+ await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
13819
+ }
13820
+ }
13821
+ throw new HelperConnectionError(
13822
+ `privileged helper is not reachable at ${socketPath}: ${(lastError == null ? void 0 : lastError.message) ?? "timed out"}`
13823
+ );
13824
+ }
13825
+ function handshake(socketPath, token, callTimeoutMs) {
13826
+ return new Promise((resolve2, reject2) => {
13827
+ void openSocket(socketPath).then((socket) => {
13828
+ let buffer = "";
13829
+ let settled = false;
13830
+ const fail = (error) => {
13831
+ if (settled)
13832
+ return;
13833
+ settled = true;
13834
+ socket.destroy();
13835
+ reject2(error);
13836
+ };
13837
+ const onData = (chunk) => {
13838
+ if (settled)
13839
+ return;
13840
+ const split2 = splitLines(buffer, chunk.toString("utf8"));
13841
+ buffer = split2.rest;
13842
+ const line = split2.lines[0];
13843
+ if (line === void 0)
13844
+ return;
13845
+ let hello;
13846
+ try {
13847
+ hello = JSON.parse(line);
13848
+ } catch (error) {
13849
+ return fail(new HelperConnectionError(`invalid handshake reply: ${error.message}`));
13850
+ }
13851
+ if (hello.type !== "handshake")
13852
+ return fail(new HelperConnectionError("helper did not answer the handshake"));
13853
+ if (!hello.ok)
13854
+ return fail(new HelperConnectionError(hello.reason ?? "helper rejected the handshake"));
13855
+ settled = true;
13856
+ socket.removeListener("data", onData);
13857
+ socket.removeListener("error", onError);
13858
+ const remaining = split2.lines.slice(1);
13859
+ resolve2(createClient(socket, [split2.rest, ...remaining].filter(Boolean).join("\n"), callTimeoutMs));
13860
+ };
13861
+ function onError(error) {
13862
+ fail(error);
13863
+ }
13864
+ socket.on("data", onData);
13865
+ socket.on("error", onError);
13866
+ const greeting = { type: "handshake", token };
13867
+ socket.write(serializeMessage(greeting));
13868
+ }, reject2);
13869
+ });
13870
+ }
13871
+ function createClient(socket, initialBuffer, callTimeoutMs) {
13872
+ let buffer = initialBuffer;
13873
+ let connected = true;
13874
+ let nextId = 1;
13875
+ const pending = /* @__PURE__ */ new Map();
13876
+ const listeners = /* @__PURE__ */ new Set();
13877
+ socket.on("data", (chunk) => {
13878
+ const split2 = splitLines(buffer, chunk.toString("utf8"));
13879
+ buffer = split2.rest;
13880
+ for (const line of split2.lines) {
13881
+ const decoded = decodeMessage(line);
13882
+ if (!decoded.ok)
13883
+ continue;
13884
+ const message = decoded.message;
13885
+ if (!("id" in message)) {
13886
+ for (const listener of listeners)
13887
+ listener(message);
13888
+ continue;
13889
+ }
13890
+ const entry = pending.get(message.id);
13891
+ if (!entry)
13892
+ continue;
13893
+ pending.delete(message.id);
13894
+ clearTimeout(entry.timer);
13895
+ if (message.ok)
13896
+ entry.resolve(message.result);
13897
+ else
13898
+ entry.reject(new Error(message.error.message));
13899
+ }
13900
+ });
13901
+ const disconnect = () => {
13902
+ if (!connected)
13903
+ return;
13904
+ connected = false;
13905
+ for (const [id, entry] of pending) {
13906
+ clearTimeout(entry.timer);
13907
+ pending.delete(id);
13908
+ entry.reject(new HelperConnectionError("privileged helper connection closed"));
13909
+ }
13910
+ };
13911
+ socket.on("close", disconnect);
13912
+ socket.on("error", disconnect);
13913
+ function call(method, params) {
13914
+ if (!connected)
13915
+ return Promise.reject(new HelperConnectionError("privileged helper is not connected"));
13916
+ const id = nextId++;
13917
+ const request = { id, method, params };
13918
+ return new Promise((resolve2, reject2) => {
13919
+ const timer = setTimeout(() => {
13920
+ pending.delete(id);
13921
+ reject2(new HelperConnectionError(`privileged helper did not answer "${method}" in time`));
13922
+ }, callTimeoutMs);
13923
+ pending.set(id, { resolve: resolve2, reject: reject2, timer });
13924
+ socket.write(serializeMessage(request));
13925
+ });
13926
+ }
13927
+ return {
13928
+ get connected() {
13929
+ return connected;
13930
+ },
13931
+ call,
13932
+ onEvent(listener) {
13933
+ listeners.add(listener);
13934
+ return () => {
13935
+ listeners.delete(listener);
13936
+ };
13937
+ },
13938
+ async close() {
13939
+ disconnect();
13940
+ socket.destroy();
13941
+ }
13942
+ };
13943
+ }
13944
+
13945
+ // src/privileged/windows-elevation.ts
13946
+ var import_node_child_process = require("child_process");
13947
+ var import_node_process4 = __toESM(require("process"), 1);
13948
+ function quotePowerShell(value2) {
13949
+ return `'${value2.replace(/'/g, "''")}'`;
13950
+ }
13951
+ function buildElevationCommand(options) {
13952
+ const argumentList = options.args.map(quotePowerShell).join(",");
13953
+ const parts = [
13954
+ "Start-Process",
13955
+ "-FilePath",
13956
+ quotePowerShell(options.file)
13957
+ ];
13958
+ if (argumentList)
13959
+ parts.push("-ArgumentList", argumentList);
13960
+ if (options.cwd)
13961
+ parts.push("-WorkingDirectory", quotePowerShell(options.cwd));
13962
+ parts.push("-Verb", "RunAs");
13963
+ parts.push("-WindowStyle", "Hidden");
13964
+ return parts.join(" ");
13965
+ }
13966
+ function spawnElevatedOnWindows(options) {
13967
+ return new Promise((resolve2, reject2) => {
13968
+ const script = buildElevationCommand(options);
13969
+ const child = (0, import_node_child_process.spawn)(
13970
+ "powershell.exe",
13971
+ ["-NoProfile", "-NonInteractive", "-Command", script],
13972
+ { stdio: "ignore", windowsHide: true }
13973
+ );
13974
+ child.once("error", reject2);
13975
+ child.once("exit", (code) => {
13976
+ if (code === 0)
13977
+ return resolve2(child);
13978
+ reject2(new Error(
13979
+ `administrator permission was not granted (PowerShell exited with ${code}). Accept the UAC prompt to let the plugin edit the hosts file and bind ports 80/443.`
13980
+ ));
13981
+ });
13982
+ });
13983
+ }
13984
+
13985
+ // src/privileged/launch.ts
13986
+ function createHelperToken() {
13987
+ return (0, import_node_crypto.randomBytes)(24).toString("hex");
13988
+ }
13989
+ function authenticateSudo(sudoCommand = "sudo") {
13990
+ if ((0, import_node_os3.platform)() === "win32")
13991
+ return { ok: true };
13992
+ if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
13993
+ return { ok: true };
13994
+ if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13995
+ return { ok: true };
13996
+ return {
13997
+ ok: false,
13998
+ message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13999
+ };
14000
+ }
14001
+ async function startPrivilegedHelper(options) {
14002
+ var _a4, _b3;
14003
+ const {
14004
+ socketPath,
14005
+ token,
14006
+ helperEntry,
14007
+ helperArgs = [],
14008
+ sudoCommand = "sudo",
14009
+ skipAuth = false,
14010
+ direct = false,
14011
+ env: env2 = import_node_process5.default.env,
14012
+ log,
14013
+ connectTimeoutMs = 12e4
14014
+ } = options;
14015
+ if (!skipAuth && !direct) {
14016
+ const auth = authenticateSudo(sudoCommand);
14017
+ if (!auth.ok)
14018
+ throw new Error(auth.message);
14019
+ }
14020
+ const forwarded = collectForwardedEnv(env2);
14021
+ const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
14022
+ const childArgv = [
14023
+ ...helperArgs,
14024
+ "--socket",
14025
+ socketPath,
14026
+ "--token",
14027
+ token,
14028
+ ...typeof import_node_process5.default.getuid === "function" ? ["--owner-uid", String(import_node_process5.default.getuid())] : [],
14029
+ ...typeof import_node_process5.default.getgid === "function" ? ["--owner-gid", String(import_node_process5.default.getgid())] : [],
14030
+ ...options.caddyStoragePath ? ["--caddy-storage", options.caddyStoragePath] : [],
14031
+ "--caddy",
14032
+ options.caddyBin,
14033
+ "--caddy-config",
14034
+ options.caddyConfigPath
14035
+ ];
14036
+ let child;
14037
+ if (!direct && (0, import_node_os3.platform)() === "win32") {
14038
+ await spawnElevatedOnWindows({ file: helperEntry, args: childArgv, cwd: import_node_process5.default.cwd() });
14039
+ } else {
14040
+ const command = direct ? helperEntry : sudoCommand;
14041
+ const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
14042
+ child = (0, import_node_child_process2.spawn)(command, spawnArgs, {
14043
+ stdio: ["ignore", "pipe", "pipe"]
14044
+ });
14045
+ (_a4 = child.stdout) == null ? void 0 : _a4.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
14046
+ (_b3 = child.stderr) == null ? void 0 : _b3.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
14047
+ const exited = new Promise((resolve2) => child.once("exit", (code) => resolve2(code)));
14048
+ const earlyExit = await Promise.race([
14049
+ exited,
14050
+ new Promise((resolve2) => setTimeout(() => resolve2(void 0), 500))
14051
+ ]);
14052
+ if (earlyExit !== void 0 && earlyExit !== 0) {
14053
+ throw new Error(
14054
+ `privileged helper exited with code ${earlyExit}. Administrator permission was refused, or sudo is not available.`
14055
+ );
14056
+ }
14057
+ }
14058
+ try {
14059
+ const client = await connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
14060
+ return {
14061
+ client,
14062
+ async close() {
14063
+ await client.close().catch(() => {
14064
+ });
14065
+ child == null ? void 0 : child.unref();
14066
+ }
14067
+ };
14068
+ } catch (error) {
14069
+ try {
14070
+ child == null ? void 0 : child.kill();
14071
+ } catch {
14072
+ }
14073
+ throw error;
14074
+ }
14075
+ }
14076
+ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
14077
+ try {
14078
+ return await connectClient({ socketPath, token, timeoutMs });
14079
+ } catch {
14080
+ return void 0;
14081
+ }
14082
+ }
14083
+
14084
+ // src/privileged/session.ts
14085
+ function tokenPath(runtimeDir) {
14086
+ return (0, import_node_path3.join)(runtimeDir, "helper.token");
14087
+ }
14088
+ function sessionSocketPath(runtimeDir) {
14089
+ if ((0, import_node_os4.platform)() === "win32")
14090
+ return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
14091
+ return (0, import_node_path3.join)(runtimeDir, "helper.sock");
14092
+ }
14093
+ async function openHelperSession(scope2) {
14094
+ const socketPath = sessionSocketPath(scope2.runtimeDir);
14095
+ if ((0, import_node_fs3.existsSync)(socketPath) || (0, import_node_os4.platform)() === "win32") {
14096
+ const token2 = await readToken(scope2.runtimeDir);
14097
+ if (token2) {
14098
+ const reused = await connectExistingHelper(socketPath, token2);
14099
+ if (reused) {
14100
+ return {
14101
+ client: reused,
14102
+ reused: true,
14103
+ close: async () => {
14104
+ await reused.close();
14105
+ }
14106
+ };
14107
+ }
14108
+ }
14109
+ }
14110
+ const token = createHelperToken();
14111
+ const started = await startPrivilegedHelper({
14112
+ socketPath,
14113
+ token,
14114
+ helperEntry: scope2.helperEntry,
14115
+ helperArgs: scope2.helperArgs,
14116
+ sudoCommand: scope2.sudoCommand,
14117
+ skipAuth: scope2.skipAuth,
14118
+ direct: scope2.direct,
14119
+ env: scope2.env,
14120
+ caddyStoragePath: scope2.caddyStoragePath,
14121
+ caddyBin: scope2.caddyBin,
14122
+ caddyConfigPath: scope2.caddyConfigPath,
14123
+ log: scope2.log
14124
+ });
14125
+ await writeToken(scope2.runtimeDir, token);
14126
+ return {
14127
+ client: started.client,
14128
+ reused: false,
14129
+ close: async () => {
14130
+ await started.close();
14131
+ }
14132
+ };
14133
+ }
14134
+ async function readToken(runtimeDir) {
14135
+ try {
14136
+ const content = await (0, import_promises2.readFile)(tokenPath(runtimeDir), "utf8");
14137
+ const token = content.trim();
14138
+ return token === "" ? void 0 : token;
14139
+ } catch {
14140
+ return void 0;
14141
+ }
14142
+ }
14143
+ async function writeToken(runtimeDir, token) {
14144
+ try {
14145
+ await (0, import_promises2.writeFile)(tokenPath(runtimeDir), token, { mode: 384 });
14146
+ } catch {
14147
+ }
14148
+ }
14149
+
14150
+ // src/caddy/privileged.ts
14151
+ var import_meta = {};
14152
+ function resolvePrivilegedEnv() {
14153
+ const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path4.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
14154
+ const resolved = resolveHelperEntry({ moduleDir });
14155
+ return { helperEntry: resolved.entry, helperArgs: resolved.args };
14156
+ }
14157
+ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
14158
+ constructor(client) {
14159
+ super();
14160
+ this.client = client;
14161
+ this.stdout = new import_node_events.EventEmitter();
14162
+ this.stderr = new import_node_events.EventEmitter();
14163
+ this.finished = false;
14164
+ this.unsubscribe = client.onEvent((event) => this.handleEvent(event));
14165
+ }
14166
+ handleEvent(event) {
14167
+ if (event.type !== "event")
14168
+ return;
14169
+ if (event.kind === "caddy.stdout") {
14170
+ this.stdout.emit("data", import_node_buffer2.Buffer.from(event.data));
14171
+ return;
14172
+ }
14173
+ if (event.kind === "caddy.stderr") {
14174
+ this.stderr.emit("data", import_node_buffer2.Buffer.from(event.data));
14175
+ return;
14176
+ }
14177
+ if (event.kind === "caddy.exit") {
14178
+ this.finished = true;
14179
+ this.emit("exit", event.code, event.signal);
14180
+ }
14181
+ }
14182
+ /** Asks the helper to stop Caddy; the helper also stops it on disconnect. */
14183
+ kill() {
14184
+ this.unsubscribe();
14185
+ if (this.finished)
14186
+ return;
14187
+ this.finished = true;
14188
+ void this.client.call("caddy.stop").catch(() => {
14189
+ });
14190
+ }
14191
+ };
14192
+ function caddyStoragePath() {
14193
+ return import_node_process6.default.platform === "win32" ? (0, import_node_path4.join)(import_node_process6.default.env.AppData ?? "", "Caddy") : (0, import_node_path4.join)(import_node_process6.default.env.HOME ?? "", "Library/Application Support/Caddy");
14194
+ }
14195
+ function openPrivilegedSession(runtimeDir, options) {
14196
+ const env2 = resolvePrivilegedEnv();
14197
+ return openHelperSession({
14198
+ runtimeDir,
14199
+ helperEntry: env2.helperEntry,
14200
+ helperArgs: env2.helperArgs,
14201
+ direct: options.direct,
14202
+ // Caddy keeps its PKI under the user's home; the helper runs it as root, so
14203
+ // it must know which tree to hand back afterwards.
14204
+ caddyStoragePath: caddyStoragePath(),
14205
+ // The binary and Caddyfile are fixed here: the privileged helper must never
14206
+ // execute a path supplied over the socket.
14207
+ caddyBin: options.caddyBin,
14208
+ caddyConfigPath: options.caddyConfigPath,
14209
+ log: options.log
14210
+ });
14211
+ }
14212
+
13735
14213
  // src/caddy/tls-health.ts
13736
14214
  var import_node_tls = require("tls");
13737
14215
  function assessTlsCertificate(certificate, hostname, now = Date.now(), verifyHostname = import_node_tls.checkServerIdentity) {
@@ -13814,40 +14292,8 @@ function formatTlsHealthFailure(hostname, result) {
13814
14292
  }
13815
14293
 
13816
14294
  // src/caddy/utils.ts
13817
- var import_node_child_process3 = require("child_process");
13818
- var import_node_net = require("net");
13819
14295
  var import_ora = __toESM(require("ora"), 1);
13820
14296
  var spinner;
13821
- function tryPort(port) {
13822
- return new Promise((resolve2, _reject) => {
13823
- try {
13824
- const server = (0, import_node_net.createServer)().listen(port);
13825
- server.on("listening", () => {
13826
- server.close();
13827
- resolve2(false);
13828
- });
13829
- server.on("error", (err) => {
13830
- if (err.code === "EADDRINUSE")
13831
- resolve2(true);
13832
- server.close();
13833
- });
13834
- } catch {
13835
- resolve2(true);
13836
- }
13837
- });
13838
- }
13839
- async function kill(port) {
13840
- return new Promise((resolve2, reject2) => {
13841
- (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
13842
- if (err) {
13843
- reject2(err);
13844
- } else {
13845
- consola.log(stdout);
13846
- resolve2();
13847
- }
13848
- });
13849
- });
13850
- }
13851
14297
  function getNumber(number2) {
13852
14298
  if (number2 <= 0)
13853
14299
  return "0%";
@@ -13886,26 +14332,26 @@ async function download() {
13886
14332
  if (await testCaddy())
13887
14333
  return caddyPath;
13888
14334
  return new Promise((resolve2, reject2) => {
13889
- if (!(0, import_node_fs3.existsSync)(TEMP_DIR)) {
13890
- (0, import_node_fs3.mkdirSync)(TEMP_DIR, { recursive: true });
13891
- (0, import_node_fs3.chmodSync)(TEMP_DIR, 511);
14335
+ if (!(0, import_node_fs4.existsSync)(TEMP_DIR)) {
14336
+ (0, import_node_fs4.mkdirSync)(TEMP_DIR, { recursive: true });
14337
+ (0, import_node_fs4.chmodSync)(TEMP_DIR, 448);
13892
14338
  }
13893
- const file = (0, import_node_fs3.createWriteStream)(caddyPath);
13894
- let _platform = (0, import_node_os3.platform)().toString();
14339
+ const file = (0, import_node_fs4.createWriteStream)(caddyPath);
14340
+ let _platform = (0, import_node_os5.platform)().toString();
13895
14341
  _platform === "win32" && (_platform = "windows");
13896
- let _arch = import_node_process4.default.arch.toString();
14342
+ let _arch = import_node_process7.default.arch.toString();
13897
14343
  _arch === "x64" && (_arch = "amd64");
13898
14344
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
13899
14345
  if (!support)
13900
14346
  return reject2(new Error("not support"));
13901
14347
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
13902
- (0, import_node_fs3.existsSync)(caddyPath) && (0, import_node_fs3.unlinkSync)(caddyPath);
13903
- const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
13904
- const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
14348
+ (0, import_node_fs4.existsSync)(caddyPath) && (0, import_node_fs4.unlinkSync)(caddyPath);
14349
+ const httpProxy = import_node_process7.default.env.HTTP_PROXY || import_node_process7.default.env.http_proxy;
14350
+ const httpsProxy = import_node_process7.default.env.HTTPS_PROXY || import_node_process7.default.env.https_proxy;
13905
14351
  const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
13906
14352
  const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
13907
14353
  const chmodCaddyOnce = once(() => {
13908
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
14354
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
13909
14355
  });
13910
14356
  import_got_cjs.got.stream(dowmloadLink, {
13911
14357
  agent: {
@@ -13917,9 +14363,9 @@ async function download() {
13917
14363
  chmodCaddyOnce();
13918
14364
  }).pipe(file).on("finish", () => {
13919
14365
  logProgressOver();
13920
- if (import_node_process4.default.platform === "win32")
14366
+ if (import_node_process7.default.platform === "win32")
13921
14367
  return resolve2(caddyPath);
13922
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
14368
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
13923
14369
  resolve2(caddyPath);
13924
14370
  }).on("error", (err) => {
13925
14371
  reject2(err);
@@ -13927,19 +14373,17 @@ async function download() {
13927
14373
  });
13928
14374
  }
13929
14375
  function testCaddy() {
13930
- return new Promise((resolve2, reject2) => {
13931
- if (!(0, import_node_fs3.existsSync)(caddyPath))
13932
- return resolve2(false);
13933
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
13934
- const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
13935
- child.on("close", () => {
14376
+ return new Promise((resolve2) => {
14377
+ if (!(0, import_node_fs4.existsSync)(caddyPath))
13936
14378
  return resolve2(false);
13937
- });
13938
- child.on("error", (err) => {
13939
- return reject2(err);
13940
- });
13941
- child.stdout.on("data", (_data) => {
13942
- return resolve2(true);
14379
+ try {
14380
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
14381
+ } catch {
14382
+ }
14383
+ (0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
14384
+ if (error && !stdout)
14385
+ return resolve2(false);
14386
+ resolve2(stdout.length > 0);
13943
14387
  });
13944
14388
  });
13945
14389
  }
@@ -13961,25 +14405,48 @@ function splitHostPort(addr) {
13961
14405
  }
13962
14406
  return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
13963
14407
  }
14408
+ var defaultDependencies = {
14409
+ openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
14410
+ log: (message) => consola.debug(message),
14411
+ // Both paths are fixed here, before any socket traffic: the privileged
14412
+ // helper must never execute something named in a request.
14413
+ caddyBin: caddyPath,
14414
+ caddyConfigPath: caddyFilePath
14415
+ })
14416
+ };
13964
14417
  var CaddyInstant = class {
13965
- constructor() {
14418
+ constructor(deps = {}) {
13966
14419
  this.inited = false;
13967
14420
  this.stoped = false;
13968
14421
  /** has locked when start */
13969
14422
  this.locked = false;
13970
14423
  this._stopEffects = [];
13971
- testCaddy().then(async () => {
13972
- this.inited = true;
13973
- });
14424
+ this.deps = { ...defaultDependencies, ...deps };
13974
14425
  this.locked = this.checkLock();
13975
14426
  }
13976
14427
  checkLock() {
13977
- if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
13978
- (0, import_node_fs3.writeFileSync)(caddyLockFilePath, "");
13979
- return lockfile.checkSync(caddyLockFilePath);
14428
+ if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
14429
+ (0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
14430
+ try {
14431
+ return lockfile.checkSync(caddyLockFilePath);
14432
+ } catch {
14433
+ return false;
14434
+ }
14435
+ }
14436
+ /**
14437
+ * Connects to the privileged helper, starting it once if needed. It is
14438
+ * reused across instances so a second dev server does not ask for a
14439
+ * password again.
14440
+ */
14441
+ async session() {
14442
+ if (this._session && !this._session.client.connected)
14443
+ this._session = void 0;
14444
+ if (!this._session)
14445
+ this._session = await this.deps.openSession(TEMP_DIR);
14446
+ return this._session;
13980
14447
  }
13981
14448
  async getCaddyfile() {
13982
- if (!(0, import_node_fs3.existsSync)(caddyFilePath)) {
14449
+ if (!(0, import_node_fs4.existsSync)(caddyFilePath)) {
13983
14450
  this.caddyfile = "";
13984
14451
  return "";
13985
14452
  }
@@ -13987,8 +14454,8 @@ var CaddyInstant = class {
13987
14454
  return this.caddyfile;
13988
14455
  }
13989
14456
  get caddyRoot() {
13990
- return (0, import_node_path3.join)(
13991
- import_node_process4.default.platform === "win32" ? `${import_node_process4.default.env.AppData}/Caddy` : `${import_node_process4.default.env.HOME}/Library/Application Support/Caddy`,
14457
+ return (0, import_node_path5.join)(
14458
+ import_node_process7.default.platform === "win32" ? `${import_node_process7.default.env.AppData}/Caddy` : `${import_node_process7.default.env.HOME}/Library/Application Support/Caddy`,
13992
14459
  "./pki/authorities/local"
13993
14460
  );
13994
14461
  }
@@ -14002,6 +14469,33 @@ var CaddyInstant = class {
14002
14469
  await download();
14003
14470
  this.inited = true;
14004
14471
  }
14472
+ /**
14473
+ * Hands the Caddy storage directory back to the developer. Local CA data
14474
+ * created by an earlier root-owned run must stay readable for `tls internal`
14475
+ * to keep serving the same certificate the browser already trusts.
14476
+ */
14477
+ /**
14478
+ * Installs Caddy's local root CA so the browser stops warning about
14479
+ * `tls internal` certificates. Generating the CA and trusting it are separate
14480
+ * steps: a new CA appears whenever the previous one expires or the storage is
14481
+ * replaced, so this runs on every start instead of once.
14482
+ *
14483
+ * The helper owns both the binary path and the command, so nothing here can
14484
+ * be turned into an arbitrary root execution.
14485
+ */
14486
+ async trustLocalCa(session) {
14487
+ try {
14488
+ const result = await session.client.call("ca.trust");
14489
+ if (result.trusted)
14490
+ consola.debug(`Caddy local CA is trusted
14491
+ ${result.output}`);
14492
+ } catch (error) {
14493
+ consola.warn(
14494
+ `could not install the Caddy root certificate automatically: ${error.message}
14495
+ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14496
+ );
14497
+ }
14498
+ }
14005
14499
  async ensureTlsReady(targetHost) {
14006
14500
  const health = await waitForLocalTls(targetHost);
14007
14501
  if (!health.healthy)
@@ -14053,10 +14547,10 @@ var CaddyInstant = class {
14053
14547
  this._target = target;
14054
14548
  if (!this.inited)
14055
14549
  await this.init();
14550
+ const session = await this.session();
14056
14551
  const sourceHost = splitHostPort(source).host;
14057
14552
  const targetHost = splitHostPort(target).host;
14058
- if (!await addHost(sourceHost, targetHost))
14059
- throw new Error("update host failed");
14553
+ await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
14060
14554
  consola.success("update host success\n");
14061
14555
  const normalizeBase = (b) => {
14062
14556
  let out = b || "/";
@@ -14091,24 +14585,24 @@ var CaddyInstant = class {
14091
14585
  void this.updateCaddyfile();
14092
14586
  })
14093
14587
  );
14094
- if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
14095
- (0, import_node_fs3.writeFileSync)(caddyLockFilePath, "");
14588
+ if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
14589
+ (0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
14096
14590
  if (!this.locked) {
14097
- if (await tryPort(443))
14098
- await kill(443);
14099
- if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
14100
- await kill(80);
14591
+ await session.client.call("port.free", { port: 443 });
14592
+ if (import_node_process7.default.platform === "win32" || !https)
14593
+ await session.client.call("port.free", { port: 80 });
14101
14594
  }
14102
14595
  return new Promise((resolve2, reject2) => {
14103
- var _a4, _b3;
14104
14596
  let startupCheckStarted = false;
14105
14597
  const resolveWhenReady = async () => {
14106
14598
  if (startupCheckStarted)
14107
14599
  return;
14108
14600
  startupCheckStarted = true;
14109
14601
  try {
14110
- if (https)
14602
+ if (https) {
14603
+ await this.trustLocalCa(session);
14111
14604
  await this.ensureTlsReady(targetHost);
14605
+ }
14112
14606
  resolve2();
14113
14607
  } catch (error) {
14114
14608
  if (!this.locked)
@@ -14117,96 +14611,87 @@ var CaddyInstant = class {
14117
14611
  }
14118
14612
  };
14119
14613
  const setupCleanup = () => {
14120
- import_node_process4.default.on("SIGINT", async () => {
14614
+ import_node_process7.default.on("SIGINT", async () => {
14121
14615
  if (this.stoped)
14122
14616
  return;
14123
- import_node_process4.default.stdin.resume();
14617
+ import_node_process7.default.stdin.resume();
14124
14618
  try {
14125
14619
  await this.baseCleanup(restore);
14126
14620
  } finally {
14127
14621
  this.stoped = true;
14128
- import_node_process4.default.nextTick(() => {
14129
- import_node_process4.default.exit();
14622
+ import_node_process7.default.nextTick(() => {
14623
+ import_node_process7.default.exit();
14130
14624
  });
14131
14625
  }
14132
14626
  });
14133
- const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
14134
- import_node_process4.default.exit = async (code) => {
14135
- const port = Number(splitHostPort(source).port);
14136
- if (!Number.isNaN(port) && await tryPort(port))
14137
- await kill(port);
14138
- const pwd = import_node_process4.default.cwd();
14139
- const viteCacheDir = `${pwd}/node_modules/.vite`;
14140
- if ((0, import_node_fs3.existsSync)(viteCacheDir))
14141
- await chmodRecursive(viteCacheDir, 511).catch(() => {
14142
- });
14143
- const viteTempCacheDir = `${pwd}/node_modules/.vite-temp`;
14144
- if ((0, import_node_fs3.existsSync)(viteTempCacheDir))
14145
- await chmodRecursive(viteTempCacheDir, 511).catch(() => {
14146
- });
14147
- const nuxtCacheDir = `${pwd}/.nuxt`;
14148
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
14149
- await chmodRecursive(nuxtCacheDir, 511).catch(() => {
14150
- });
14151
- const webpackCacheDir = `${pwd}/node_modules/.cache`;
14152
- if ((0, import_node_fs3.existsSync)(webpackCacheDir))
14153
- await chmodRecursive(webpackCacheDir, 511).catch(() => {
14154
- });
14627
+ const originalExit = import_node_process7.default.exit.bind(import_node_process7.default);
14628
+ import_node_process7.default.exit = async (code) => {
14155
14629
  if (this.stoped)
14156
14630
  return originalExit(code);
14157
- import_node_process4.default.stdin.resume();
14631
+ import_node_process7.default.stdin.resume();
14158
14632
  try {
14159
14633
  await this.baseCleanup();
14160
14634
  } finally {
14161
14635
  this.stoped = true;
14162
- import_node_process4.default.nextTick(() => {
14636
+ import_node_process7.default.nextTick(() => {
14163
14637
  originalExit(code);
14164
14638
  });
14165
14639
  }
14166
14640
  };
14167
14641
  };
14168
14642
  if (!this.locked) {
14169
- 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"]);
14170
14643
  lockfile.lockSync(caddyLockFilePath);
14171
- this._caddyChild.on("error", (err) => {
14172
- return reject2(err);
14173
- });
14174
- (_a4 = this._caddyChild.stderr) == null ? void 0 : _a4.on("data", async (data) => {
14175
- const lines = data.toString().split("\n").map((line) => line.trim());
14176
- for (const line of lines) {
14177
- showCaddyLog && line && console.info(line);
14178
- if (isCaddyReloadCancellation(line)) {
14179
- consola.info("Caddy restarted before TLS issuance completed; retrying.\n");
14180
- continue;
14181
- }
14182
- try {
14183
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
14184
- if (line.includes("parsing caddyfile tokens")) {
14185
- consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
14644
+ setupCleanup();
14645
+ void (async () => {
14646
+ try {
14647
+ const child = new HelperCaddyProcess(session.client);
14648
+ this._caddyChild = child;
14649
+ await session.client.call("caddy.start");
14650
+ child.on("exit", (code) => {
14651
+ if (code !== null && code !== 0)
14652
+ reject2(new Error(`Caddy exited with code ${code}`));
14653
+ });
14654
+ child.stderr.on("data", async (data) => {
14655
+ const lines = data.toString().split("\n").map((line) => line.trim());
14656
+ for (const line of lines) {
14657
+ showCaddyLog && line && console.info(line);
14658
+ if (isCaddyReloadCancellation(line)) {
14659
+ consola.info("Caddy restarted before TLS issuance completed; retrying.\n");
14660
+ continue;
14661
+ }
14662
+ try {
14663
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
14664
+ if (line.includes("parsing caddyfile tokens")) {
14665
+ consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
14186
14666
 
14187
14667
  ${line}
14188
14668
  `);
14189
- await this.baseCleanup();
14190
- import_node_process4.default.exit();
14191
- } else {
14192
- consola.error(`${line}
14669
+ await this.baseCleanup();
14670
+ import_node_process7.default.exit();
14671
+ } else {
14672
+ consola.error(`${line}
14193
14673
  `);
14194
- return reject2(line);
14674
+ return reject2(line);
14675
+ }
14676
+ }
14677
+ } catch {
14195
14678
  }
14679
+ if (line.includes("config file changed"))
14680
+ consola.success("Detect added a new reverse proxy config, restarted.\n");
14681
+ if (line.includes("caddy proxying") || line.includes("serving initial"))
14682
+ void resolveWhenReady();
14196
14683
  }
14197
- } catch {
14198
- }
14199
- if (line.includes("config file changed"))
14200
- consola.success("Detect added a new reverse proxy config, restarted.\n");
14201
- if (line.includes("caddy proxying") || line.includes("serving initial"))
14684
+ });
14685
+ child.stdout.on("data", (data) => {
14686
+ consola.info(data.toString());
14202
14687
  void resolveWhenReady();
14688
+ });
14689
+ } catch (error) {
14690
+ if (!this.locked)
14691
+ await this.baseCleanup(restore);
14692
+ reject2(error);
14203
14693
  }
14204
- });
14205
- (_b3 = this._caddyChild.stdout) == null ? void 0 : _b3.on("data", (_data) => {
14206
- consola.info(_data.toString());
14207
- void resolveWhenReady();
14208
- });
14209
- setupCleanup();
14694
+ })();
14210
14695
  } else {
14211
14696
  consola.info("Caddy is running in another process.");
14212
14697
  void (async () => {
@@ -14223,17 +14708,25 @@ ${line}
14223
14708
  });
14224
14709
  }
14225
14710
  async baseCleanup(restore = true) {
14711
+ var _a4;
14226
14712
  this._stopEffects.forEach((fn) => fn());
14713
+ this._stopEffects.length = 0;
14227
14714
  try {
14228
- if (restore && this._source && this._target) {
14229
- if (await removeHost(splitHostPort(this._source).host, splitHostPort(this._target).host))
14230
- consola.success("Restore host success.\n");
14231
- else
14232
- consola.fail("Restore host failed.\n");
14715
+ if (restore && this._source && this._target && this._session) {
14716
+ const sourceHost = splitHostPort(this._source).host;
14717
+ const targetHost = splitHostPort(this._target).host;
14718
+ await this._session.client.call("hosts.remove", { ip: sourceHost, host: targetHost });
14719
+ if (sourceHost === "localhost")
14720
+ await this._session.client.call("hosts.remove", { ip: "127.0.0.1", host: targetHost });
14721
+ consola.success("Restore host success.\n");
14233
14722
  }
14234
14723
  } catch (e) {
14235
- consola.error(e);
14236
- consola.fail("Restore host failed.\n");
14724
+ if (((_a4 = this._session) == null ? void 0 : _a4.client.connected) === false) {
14725
+ consola.debug("hosts entries are restored by the privileged helper on disconnect");
14726
+ } else {
14727
+ consola.error(e);
14728
+ consola.fail("Restore host failed.\n");
14729
+ }
14237
14730
  }
14238
14731
  if (!this.locked && !this.stoped) {
14239
14732
  await this.stopCaddy();
@@ -14492,7 +14985,7 @@ var hmrSseBridgeClientScript = `
14492
14985
  var config;
14493
14986
  var caddy;
14494
14987
  var hmrSseBridgeActive = false;
14495
- var cwd = import_node_process5.default.cwd();
14988
+ var cwd = import_node_process8.default.cwd();
14496
14989
  function colorUrl(url2) {
14497
14990
  return import_picocolors2.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
14498
14991
  }
@@ -14557,10 +15050,6 @@ var unpluginFactory = (options) => ({
14557
15050
  } = options;
14558
15051
  if (!enable)
14559
15052
  return;
14560
- if (!isAdmin()) {
14561
- consola.warn("please run as administrator");
14562
- return;
14563
- }
14564
15053
  if (!target) {
14565
15054
  consola.fail("please provide target");
14566
15055
  return;
@@ -14596,7 +15085,7 @@ var unpluginFactory = (options) => ({
14596
15085
  },
14597
15086
  webpack(compiler) {
14598
15087
  var _a4, _b3, _c2;
14599
- if (import_node_process5.default.env.NODE_ENV !== "development")
15088
+ if (import_node_process8.default.env.NODE_ENV !== "development")
14600
15089
  return;
14601
15090
  const {
14602
15091
  enable = true,
@@ -14604,10 +15093,6 @@ var unpluginFactory = (options) => ({
14604
15093
  } = options;
14605
15094
  if (!enable)
14606
15095
  return;
14607
- if (!isAdmin()) {
14608
- consola.warn("please run as administrator");
14609
- return;
14610
- }
14611
15096
  if (!target) {
14612
15097
  consola.fail("please provide target");
14613
15098
  return;
@@ -14621,7 +15106,7 @@ var unpluginFactory = (options) => ({
14621
15106
  port: 8080,
14622
15107
  ...compiler.options.devServer,
14623
15108
  // @ts-expect-error vuecli
14624
- ...(_a4 = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
15109
+ ...(_a4 = import_node_process8.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
14625
15110
  };
14626
15111
  const source = `${devServer.host}:${devServer.port}`;
14627
15112
  if (caddy)
@@ -14638,7 +15123,7 @@ var unpluginFactory = (options) => ({
14638
15123
  const _close = (_c2 = compiler.close) == null ? void 0 : _c2.bind(compiler);
14639
15124
  if (_close) {
14640
15125
  compiler.close = async (callback) => {
14641
- import_node_process5.default.on("exit", () => {
15126
+ import_node_process8.default.on("exit", () => {
14642
15127
  _close && _close(callback);
14643
15128
  });
14644
15129
  };
@@ -14660,7 +15145,7 @@ var unpluginFactory = (options) => ({
14660
15145
  },
14661
15146
  async rspack(compiler) {
14662
15147
  var _a4, _b3, _c2, _d2;
14663
- if (import_node_process5.default.env.NODE_ENV !== "development")
15148
+ if (import_node_process8.default.env.NODE_ENV !== "development")
14664
15149
  return;
14665
15150
  const {
14666
15151
  enable = true,
@@ -14668,10 +15153,6 @@ var unpluginFactory = (options) => ({
14668
15153
  } = options;
14669
15154
  if (!enable)
14670
15155
  return;
14671
- if (!isAdmin()) {
14672
- consola.warn("please run as administrator");
14673
- return;
14674
- }
14675
15156
  if (!target) {
14676
15157
  consola.fail("please provide target");
14677
15158
  return;