unplugin-https-reverse-proxy 4.1.0-beta.4 → 4.1.0-beta.5

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.
@@ -13527,7 +13527,7 @@ function describePasswordReason(target, https) {
13527
13527
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13528
13528
  ];
13529
13529
  }
13530
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13530
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13531
13531
  if (platform() === "win32")
13532
13532
  return { ok: true };
13533
13533
  if (spawnSync(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13538,13 +13538,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13538
13538
  `);
13539
13539
  process6.stderr.write("\n");
13540
13540
  }
13541
- if (spawnSync(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13542
- return { ok: true };
13543
- return {
13544
- ok: false,
13545
- denied: true,
13546
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13541
+ let interrupted = false;
13542
+ const onSigint = () => {
13543
+ interrupted = true;
13547
13544
  };
13545
+ process6.on("SIGINT", onSigint);
13546
+ try {
13547
+ const { status, signal } = await runPrompt(sudoCommand);
13548
+ if (status === 0)
13549
+ return { ok: true };
13550
+ const cancelled = interrupted || signal === "SIGINT";
13551
+ return {
13552
+ ok: false,
13553
+ denied: true,
13554
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13555
+ };
13556
+ } finally {
13557
+ process6.off("SIGINT", onSigint);
13558
+ }
13559
+ }
13560
+ function runPrompt(sudoCommand) {
13561
+ return new Promise((resolve2) => {
13562
+ const child = spawn2(sudoCommand, ["-v"], { stdio: "inherit" });
13563
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13564
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13565
+ });
13548
13566
  }
13549
13567
  var PrivilegeDeniedError = class extends Error {
13550
13568
  constructor(message) {
@@ -13567,7 +13585,7 @@ async function startPrivilegedHelper(options) {
13567
13585
  connectTimeoutMs = 12e4
13568
13586
  } = options;
13569
13587
  if (!skipAuth && !direct) {
13570
- const auth = authenticateSudo(sudoCommand, options.reason);
13588
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13571
13589
  if (!auth.ok) {
13572
13590
  const message = auth.message ?? "administrator permission is required";
13573
13591
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/esbuild.cjs CHANGED
@@ -13626,7 +13626,7 @@ function describePasswordReason(target, https) {
13626
13626
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13627
13627
  ];
13628
13628
  }
13629
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
13630
  if ((0, import_node_os3.platform)() === "win32")
13631
13631
  return { ok: true };
13632
13632
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13637,13 +13637,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13637
13637
  `);
13638
13638
  import_node_process6.default.stderr.write("\n");
13639
13639
  }
13640
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13641
- return { ok: true };
13642
- return {
13643
- ok: false,
13644
- denied: true,
13645
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13640
+ let interrupted = false;
13641
+ const onSigint = () => {
13642
+ interrupted = true;
13646
13643
  };
13644
+ import_node_process6.default.on("SIGINT", onSigint);
13645
+ try {
13646
+ const { status, signal } = await runPrompt(sudoCommand);
13647
+ if (status === 0)
13648
+ return { ok: true };
13649
+ const cancelled = interrupted || signal === "SIGINT";
13650
+ return {
13651
+ ok: false,
13652
+ denied: true,
13653
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13654
+ };
13655
+ } finally {
13656
+ import_node_process6.default.off("SIGINT", onSigint);
13657
+ }
13658
+ }
13659
+ function runPrompt(sudoCommand) {
13660
+ return new Promise((resolve2) => {
13661
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13662
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13663
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13664
+ });
13647
13665
  }
13648
13666
  var PrivilegeDeniedError = class extends Error {
13649
13667
  constructor(message) {
@@ -13666,7 +13684,7 @@ async function startPrivilegedHelper(options) {
13666
13684
  connectTimeoutMs = 12e4
13667
13685
  } = options;
13668
13686
  if (!skipAuth && !direct) {
13669
- const auth = authenticateSudo(sudoCommand, options.reason);
13687
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13670
13688
  if (!auth.ok) {
13671
13689
  const message = auth.message ?? "administrator permission is required";
13672
13690
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/dist/index.cjs CHANGED
@@ -13626,7 +13626,7 @@ function describePasswordReason(target, https) {
13626
13626
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13627
13627
  ];
13628
13628
  }
13629
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
13630
  if ((0, import_node_os3.platform)() === "win32")
13631
13631
  return { ok: true };
13632
13632
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13637,13 +13637,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13637
13637
  `);
13638
13638
  import_node_process6.default.stderr.write("\n");
13639
13639
  }
13640
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13641
- return { ok: true };
13642
- return {
13643
- ok: false,
13644
- denied: true,
13645
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13640
+ let interrupted = false;
13641
+ const onSigint = () => {
13642
+ interrupted = true;
13646
13643
  };
13644
+ import_node_process6.default.on("SIGINT", onSigint);
13645
+ try {
13646
+ const { status, signal } = await runPrompt(sudoCommand);
13647
+ if (status === 0)
13648
+ return { ok: true };
13649
+ const cancelled = interrupted || signal === "SIGINT";
13650
+ return {
13651
+ ok: false,
13652
+ denied: true,
13653
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13654
+ };
13655
+ } finally {
13656
+ import_node_process6.default.off("SIGINT", onSigint);
13657
+ }
13658
+ }
13659
+ function runPrompt(sudoCommand) {
13660
+ return new Promise((resolve2) => {
13661
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13662
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13663
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13664
+ });
13647
13665
  }
13648
13666
  var PrivilegeDeniedError = class extends Error {
13649
13667
  constructor(message) {
@@ -13666,7 +13684,7 @@ async function startPrivilegedHelper(options) {
13666
13684
  connectTimeoutMs = 12e4
13667
13685
  } = options;
13668
13686
  if (!skipAuth && !direct) {
13669
- const auth = authenticateSudo(sudoCommand, options.reason);
13687
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13670
13688
  if (!auth.ok) {
13671
13689
  const message = auth.message ?? "administrator permission is required";
13672
13690
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-H7LIW3S4.js";
6
+ } from "./chunk-A3KSOGWY.js";
7
7
  import "./chunk-EY3HXBJ4.js";
8
8
  import "./chunk-C5A7XLKL.js";
9
9
  import "./chunk-WOMR3ZLM.js";
package/dist/nuxt.cjs CHANGED
@@ -13627,7 +13627,7 @@ function describePasswordReason(target, https) {
13627
13627
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13628
13628
  ];
13629
13629
  }
13630
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13631
13631
  if ((0, import_node_os3.platform)() === "win32")
13632
13632
  return { ok: true };
13633
13633
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13638,13 +13638,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13638
13638
  `);
13639
13639
  import_node_process6.default.stderr.write("\n");
13640
13640
  }
13641
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13642
- return { ok: true };
13643
- return {
13644
- ok: false,
13645
- denied: true,
13646
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13641
+ let interrupted = false;
13642
+ const onSigint = () => {
13643
+ interrupted = true;
13647
13644
  };
13645
+ import_node_process6.default.on("SIGINT", onSigint);
13646
+ try {
13647
+ const { status, signal } = await runPrompt(sudoCommand);
13648
+ if (status === 0)
13649
+ return { ok: true };
13650
+ const cancelled = interrupted || signal === "SIGINT";
13651
+ return {
13652
+ ok: false,
13653
+ denied: true,
13654
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13655
+ };
13656
+ } finally {
13657
+ import_node_process6.default.off("SIGINT", onSigint);
13658
+ }
13659
+ }
13660
+ function runPrompt(sudoCommand) {
13661
+ return new Promise((resolve2) => {
13662
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13663
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13664
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13665
+ });
13648
13666
  }
13649
13667
  var PrivilegeDeniedError = class extends Error {
13650
13668
  constructor(message) {
@@ -13667,7 +13685,7 @@ async function startPrivilegedHelper(options) {
13667
13685
  connectTimeoutMs = 12e4
13668
13686
  } = options;
13669
13687
  if (!skipAuth && !direct) {
13670
- const auth = authenticateSudo(sudoCommand, options.reason);
13688
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13671
13689
  if (!auth.ok) {
13672
13690
  const message = auth.message ?? "administrator permission is required";
13673
13691
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import {
5
5
  consola
6
6
  } from "./chunk-EY3HXBJ4.js";
package/dist/rollup.cjs CHANGED
@@ -13626,7 +13626,7 @@ function describePasswordReason(target, https) {
13626
13626
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13627
13627
  ];
13628
13628
  }
13629
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
13630
  if ((0, import_node_os3.platform)() === "win32")
13631
13631
  return { ok: true };
13632
13632
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13637,13 +13637,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13637
13637
  `);
13638
13638
  import_node_process6.default.stderr.write("\n");
13639
13639
  }
13640
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13641
- return { ok: true };
13642
- return {
13643
- ok: false,
13644
- denied: true,
13645
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13640
+ let interrupted = false;
13641
+ const onSigint = () => {
13642
+ interrupted = true;
13646
13643
  };
13644
+ import_node_process6.default.on("SIGINT", onSigint);
13645
+ try {
13646
+ const { status, signal } = await runPrompt(sudoCommand);
13647
+ if (status === 0)
13648
+ return { ok: true };
13649
+ const cancelled = interrupted || signal === "SIGINT";
13650
+ return {
13651
+ ok: false,
13652
+ denied: true,
13653
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13654
+ };
13655
+ } finally {
13656
+ import_node_process6.default.off("SIGINT", onSigint);
13657
+ }
13658
+ }
13659
+ function runPrompt(sudoCommand) {
13660
+ return new Promise((resolve2) => {
13661
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13662
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13663
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13664
+ });
13647
13665
  }
13648
13666
  var PrivilegeDeniedError = class extends Error {
13649
13667
  constructor(message) {
@@ -13666,7 +13684,7 @@ async function startPrivilegedHelper(options) {
13666
13684
  connectTimeoutMs = 12e4
13667
13685
  } = options;
13668
13686
  if (!skipAuth && !direct) {
13669
- const auth = authenticateSudo(sudoCommand, options.reason);
13687
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13670
13688
  if (!auth.ok) {
13671
13689
  const message = auth.message ?? "administrator permission is required";
13672
13690
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/dist/rspack.cjs CHANGED
@@ -13625,7 +13625,7 @@ function describePasswordReason(target, https) {
13625
13625
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13626
13626
  ];
13627
13627
  }
13628
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13628
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
13629
  if ((0, import_node_os3.platform)() === "win32")
13630
13630
  return { ok: true };
13631
13631
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13636,13 +13636,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13636
13636
  `);
13637
13637
  import_node_process6.default.stderr.write("\n");
13638
13638
  }
13639
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13640
- return { ok: true };
13641
- return {
13642
- ok: false,
13643
- denied: true,
13644
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13639
+ let interrupted = false;
13640
+ const onSigint = () => {
13641
+ interrupted = true;
13645
13642
  };
13643
+ import_node_process6.default.on("SIGINT", onSigint);
13644
+ try {
13645
+ const { status, signal } = await runPrompt(sudoCommand);
13646
+ if (status === 0)
13647
+ return { ok: true };
13648
+ const cancelled = interrupted || signal === "SIGINT";
13649
+ return {
13650
+ ok: false,
13651
+ denied: true,
13652
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13653
+ };
13654
+ } finally {
13655
+ import_node_process6.default.off("SIGINT", onSigint);
13656
+ }
13657
+ }
13658
+ function runPrompt(sudoCommand) {
13659
+ return new Promise((resolve2) => {
13660
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13661
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13662
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13663
+ });
13646
13664
  }
13647
13665
  var PrivilegeDeniedError = class extends Error {
13648
13666
  constructor(message) {
@@ -13665,7 +13683,7 @@ async function startPrivilegedHelper(options) {
13665
13683
  connectTimeoutMs = 12e4
13666
13684
  } = options;
13667
13685
  if (!skipAuth && !direct) {
13668
- const auth = authenticateSudo(sudoCommand, options.reason);
13686
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13669
13687
  if (!auth.ok) {
13670
13688
  const message = auth.message ?? "administrator permission is required";
13671
13689
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/dist/vite.cjs CHANGED
@@ -13626,7 +13626,7 @@ function describePasswordReason(target, https) {
13626
13626
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13627
13627
  ];
13628
13628
  }
13629
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
13630
  if ((0, import_node_os3.platform)() === "win32")
13631
13631
  return { ok: true };
13632
13632
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13637,13 +13637,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13637
13637
  `);
13638
13638
  import_node_process6.default.stderr.write("\n");
13639
13639
  }
13640
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13641
- return { ok: true };
13642
- return {
13643
- ok: false,
13644
- denied: true,
13645
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13640
+ let interrupted = false;
13641
+ const onSigint = () => {
13642
+ interrupted = true;
13646
13643
  };
13644
+ import_node_process6.default.on("SIGINT", onSigint);
13645
+ try {
13646
+ const { status, signal } = await runPrompt(sudoCommand);
13647
+ if (status === 0)
13648
+ return { ok: true };
13649
+ const cancelled = interrupted || signal === "SIGINT";
13650
+ return {
13651
+ ok: false,
13652
+ denied: true,
13653
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13654
+ };
13655
+ } finally {
13656
+ import_node_process6.default.off("SIGINT", onSigint);
13657
+ }
13658
+ }
13659
+ function runPrompt(sudoCommand) {
13660
+ return new Promise((resolve2) => {
13661
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13662
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13663
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13664
+ });
13647
13665
  }
13648
13666
  var PrivilegeDeniedError = class extends Error {
13649
13667
  constructor(message) {
@@ -13666,7 +13684,7 @@ async function startPrivilegedHelper(options) {
13666
13684
  connectTimeoutMs = 12e4
13667
13685
  } = options;
13668
13686
  if (!skipAuth && !direct) {
13669
- const auth = authenticateSudo(sudoCommand, options.reason);
13687
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13670
13688
  if (!auth.ok) {
13671
13689
  const message = auth.message ?? "administrator permission is required";
13672
13690
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/dist/webpack.cjs CHANGED
@@ -13626,7 +13626,7 @@ function describePasswordReason(target, https) {
13626
13626
  "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
13627
13627
  ];
13628
13628
  }
13629
- function authenticateSudo(sudoCommand = "sudo", options = {}) {
13629
+ async function authenticateSudo(sudoCommand = "sudo", options = {}) {
13630
13630
  if ((0, import_node_os3.platform)() === "win32")
13631
13631
  return { ok: true };
13632
13632
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
@@ -13637,13 +13637,31 @@ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13637
13637
  `);
13638
13638
  import_node_process6.default.stderr.write("\n");
13639
13639
  }
13640
- if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13641
- return { ok: true };
13642
- return {
13643
- ok: false,
13644
- denied: true,
13645
- message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13640
+ let interrupted = false;
13641
+ const onSigint = () => {
13642
+ interrupted = true;
13646
13643
  };
13644
+ import_node_process6.default.on("SIGINT", onSigint);
13645
+ try {
13646
+ const { status, signal } = await runPrompt(sudoCommand);
13647
+ if (status === 0)
13648
+ return { ok: true };
13649
+ const cancelled = interrupted || signal === "SIGINT";
13650
+ return {
13651
+ ok: false,
13652
+ denied: true,
13653
+ message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
13654
+ };
13655
+ } finally {
13656
+ import_node_process6.default.off("SIGINT", onSigint);
13657
+ }
13658
+ }
13659
+ function runPrompt(sudoCommand) {
13660
+ return new Promise((resolve2) => {
13661
+ const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
13662
+ child.on("error", () => resolve2({ status: 1, signal: null }));
13663
+ child.on("exit", (status, signal) => resolve2({ status, signal }));
13664
+ });
13647
13665
  }
13648
13666
  var PrivilegeDeniedError = class extends Error {
13649
13667
  constructor(message) {
@@ -13666,7 +13684,7 @@ async function startPrivilegedHelper(options) {
13666
13684
  connectTimeoutMs = 12e4
13667
13685
  } = options;
13668
13686
  if (!skipAuth && !direct) {
13669
- const auth = authenticateSudo(sudoCommand, options.reason);
13687
+ const auth = await authenticateSudo(sudoCommand, options.reason);
13670
13688
  if (!auth.ok) {
13671
13689
  const message = auth.message ?? "administrator permission is required";
13672
13690
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-A3KSOGWY.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-https-reverse-proxy",
3
3
  "type": "module",
4
- "version": "4.1.0-beta.4",
4
+ "version": "4.1.0-beta.5",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
@@ -70,10 +70,10 @@ export function describePasswordReason(target: string, https: boolean): string[]
70
70
  * Returns `denied` when the user dismissed the prompt, so the caller can keep
71
71
  * the dev server running instead of treating it as a crash.
72
72
  */
73
- export function authenticateSudo(
73
+ export async function authenticateSudo(
74
74
  sudoCommand = 'sudo',
75
75
  options: { target?: string, https?: boolean } = {},
76
- ): { ok: boolean, denied?: boolean, message?: string } {
76
+ ): Promise<{ ok: boolean, denied?: boolean, message?: string }> {
77
77
  if (platform() === 'win32')
78
78
  return { ok: true }
79
79
 
@@ -86,16 +86,53 @@ export function authenticateSudo(
86
86
  process.stderr.write('\n')
87
87
  }
88
88
 
89
- if (spawnSync(sudoCommand, ['-v'], { stdio: 'inherit' }).status === 0)
90
- return { ok: true }
89
+ // `sudo -v` inherits the terminal, so Ctrl+C reaches this process too. Without
90
+ // a handler the default action kills the dev server, which reads as "the
91
+ // proxy crashed my dev server" when the user only meant to skip it.
92
+ let interrupted = false
93
+ const onSigint = (): void => {
94
+ interrupted = true
95
+ }
96
+ process.on('SIGINT', onSigint)
97
+
98
+ try {
99
+ const { status, signal } = await runPrompt(sudoCommand)
100
+ if (status === 0)
101
+ return { ok: true }
91
102
 
92
- return {
93
- ok: false,
94
- denied: true,
95
- message: 'administrator permission is required to edit the hosts file and bind ports 80/443',
103
+ // `sudo` exits 1 on a wrong password and dies by the signal on Ctrl+C.
104
+ // Both are checked: a real Ctrl+C reaches this process and the child
105
+ // together, while a signal aimed at the child alone only shows up here.
106
+ const cancelled = interrupted || signal === 'SIGINT'
107
+ return {
108
+ ok: false,
109
+ denied: true,
110
+ message: cancelled
111
+ ? 'administrator permission was cancelled'
112
+ : 'administrator permission is required to edit the hosts file and bind ports 80/443',
113
+ }
114
+ }
115
+ finally {
116
+ process.off('SIGINT', onSigint)
96
117
  }
97
118
  }
98
119
 
120
+ /**
121
+ * Runs `sudo -v` with the terminal attached.
122
+ *
123
+ * Spawned asynchronously rather than with `spawnSync`: the synchronous form
124
+ * blocks the event loop, so the SIGINT handler above never runs and the exit
125
+ * looks like a plain failure instead of a cancellation.
126
+ */
127
+ function runPrompt(sudoCommand: string): Promise<{ status: number | null, signal: NodeJS.Signals | null }> {
128
+ return new Promise((resolve) => {
129
+ const child = spawn(sudoCommand, ['-v'], { stdio: 'inherit' })
130
+
131
+ child.on('error', () => resolve({ status: 1, signal: null }))
132
+ child.on('exit', (status, signal) => resolve({ status, signal }))
133
+ })
134
+ }
135
+
99
136
  /** The user dismissed the password prompt; this is a choice, not a failure. */
100
137
  export class PrivilegeDeniedError extends Error {
101
138
  constructor(message: string) {
@@ -132,7 +169,7 @@ export async function startPrivilegedHelper(options: LaunchOptions): Promise<Pri
132
169
  } = options
133
170
 
134
171
  if (!skipAuth && !direct) {
135
- const auth = authenticateSudo(sudoCommand, options.reason)
172
+ const auth = await authenticateSudo(sudoCommand, options.reason)
136
173
  if (!auth.ok) {
137
174
  const message = auth.message ?? 'administrator permission is required'
138
175
  throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message)