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