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

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);
@@ -14212,11 +14230,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14212
14230
  try {
14213
14231
  const child = new HelperCaddyProcess(session.client);
14214
14232
  this._caddyChild = child;
14215
- await session.client.call("caddy.start");
14233
+ const started = await session.client.call("caddy.start");
14216
14234
  child.on("exit", (code) => {
14217
14235
  if (code !== null && code !== 0)
14218
14236
  reject2(new Error(`Caddy exited with code ${code}`));
14219
14237
  });
14238
+ if ((started == null ? void 0 : started.started) === false) {
14239
+ consola.info("Caddy is already running; added this route to it.");
14240
+ void resolveWhenReady();
14241
+ return;
14242
+ }
14220
14243
  child.stderr.on("data", async (data) => {
14221
14244
  const lines = data.toString().split("\n").map((line) => line.trim());
14222
14245
  for (const line of lines) {
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);
@@ -14312,11 +14330,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14312
14330
  try {
14313
14331
  const child = new HelperCaddyProcess(session.client);
14314
14332
  this._caddyChild = child;
14315
- await session.client.call("caddy.start");
14333
+ const started = await session.client.call("caddy.start");
14316
14334
  child.on("exit", (code) => {
14317
14335
  if (code !== null && code !== 0)
14318
14336
  reject2(new Error(`Caddy exited with code ${code}`));
14319
14337
  });
14338
+ if ((started == null ? void 0 : started.started) === false) {
14339
+ consola.info("Caddy is already running; added this route to it.");
14340
+ void resolveWhenReady();
14341
+ return;
14342
+ }
14320
14343
  child.stderr.on("data", async (data) => {
14321
14344
  const lines = data.toString().split("\n").map((line) => line.trim());
14322
14345
  for (const line of lines) {
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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);
@@ -14312,11 +14330,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14312
14330
  try {
14313
14331
  const child = new HelperCaddyProcess(session.client);
14314
14332
  this._caddyChild = child;
14315
- await session.client.call("caddy.start");
14333
+ const started = await session.client.call("caddy.start");
14316
14334
  child.on("exit", (code) => {
14317
14335
  if (code !== null && code !== 0)
14318
14336
  reject2(new Error(`Caddy exited with code ${code}`));
14319
14337
  });
14338
+ if ((started == null ? void 0 : started.started) === false) {
14339
+ consola.info("Caddy is already running; added this route to it.");
14340
+ void resolveWhenReady();
14341
+ return;
14342
+ }
14320
14343
  child.stderr.on("data", async (data) => {
14321
14344
  const lines = data.toString().split("\n").map((line) => line.trim());
14322
14345
  for (const line of lines) {
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-Y4TJZ6XZ.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);
@@ -14313,11 +14331,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14313
14331
  try {
14314
14332
  const child = new HelperCaddyProcess(session.client);
14315
14333
  this._caddyChild = child;
14316
- await session.client.call("caddy.start");
14334
+ const started = await session.client.call("caddy.start");
14317
14335
  child.on("exit", (code) => {
14318
14336
  if (code !== null && code !== 0)
14319
14337
  reject2(new Error(`Caddy exited with code ${code}`));
14320
14338
  });
14339
+ if ((started == null ? void 0 : started.started) === false) {
14340
+ consola.info("Caddy is already running; added this route to it.");
14341
+ void resolveWhenReady();
14342
+ return;
14343
+ }
14321
14344
  child.stderr.on("data", async (data) => {
14322
14345
  const lines = data.toString().split("\n").map((line) => line.trim());
14323
14346
  for (const line of lines) {
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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);
@@ -14312,11 +14330,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14312
14330
  try {
14313
14331
  const child = new HelperCaddyProcess(session.client);
14314
14332
  this._caddyChild = child;
14315
- await session.client.call("caddy.start");
14333
+ const started = await session.client.call("caddy.start");
14316
14334
  child.on("exit", (code) => {
14317
14335
  if (code !== null && code !== 0)
14318
14336
  reject2(new Error(`Caddy exited with code ${code}`));
14319
14337
  });
14338
+ if ((started == null ? void 0 : started.started) === false) {
14339
+ consola.info("Caddy is already running; added this route to it.");
14340
+ void resolveWhenReady();
14341
+ return;
14342
+ }
14320
14343
  child.stderr.on("data", async (data) => {
14321
14344
  const lines = data.toString().split("\n").map((line) => line.trim());
14322
14345
  for (const line of lines) {
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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);
@@ -14311,11 +14329,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14311
14329
  try {
14312
14330
  const child = new HelperCaddyProcess(session.client);
14313
14331
  this._caddyChild = child;
14314
- await session.client.call("caddy.start");
14332
+ const started = await session.client.call("caddy.start");
14315
14333
  child.on("exit", (code) => {
14316
14334
  if (code !== null && code !== 0)
14317
14335
  reject2(new Error(`Caddy exited with code ${code}`));
14318
14336
  });
14337
+ if ((started == null ? void 0 : started.started) === false) {
14338
+ consola.info("Caddy is already running; added this route to it.");
14339
+ void resolveWhenReady();
14340
+ return;
14341
+ }
14319
14342
  child.stderr.on("data", async (data) => {
14320
14343
  const lines = data.toString().split("\n").map((line) => line.trim());
14321
14344
  for (const line of lines) {
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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);
@@ -14312,11 +14330,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14312
14330
  try {
14313
14331
  const child = new HelperCaddyProcess(session.client);
14314
14332
  this._caddyChild = child;
14315
- await session.client.call("caddy.start");
14333
+ const started = await session.client.call("caddy.start");
14316
14334
  child.on("exit", (code) => {
14317
14335
  if (code !== null && code !== 0)
14318
14336
  reject2(new Error(`Caddy exited with code ${code}`));
14319
14337
  });
14338
+ if ((started == null ? void 0 : started.started) === false) {
14339
+ consola.info("Caddy is already running; added this route to it.");
14340
+ void resolveWhenReady();
14341
+ return;
14342
+ }
14320
14343
  child.stderr.on("data", async (data) => {
14321
14344
  const lines = data.toString().split("\n").map((line) => line.trim());
14322
14345
  for (const line of lines) {
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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);
@@ -14312,11 +14330,16 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14312
14330
  try {
14313
14331
  const child = new HelperCaddyProcess(session.client);
14314
14332
  this._caddyChild = child;
14315
- await session.client.call("caddy.start");
14333
+ const started = await session.client.call("caddy.start");
14316
14334
  child.on("exit", (code) => {
14317
14335
  if (code !== null && code !== 0)
14318
14336
  reject2(new Error(`Caddy exited with code ${code}`));
14319
14337
  });
14338
+ if ((started == null ? void 0 : started.started) === false) {
14339
+ consola.info("Caddy is already running; added this route to it.");
14340
+ void resolveWhenReady();
14341
+ return;
14342
+ }
14320
14343
  child.stderr.on("data", async (data) => {
14321
14344
  const lines = data.toString().split("\n").map((line) => line.trim());
14322
14345
  for (const line of lines) {
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-H7LIW3S4.js";
3
+ } from "./chunk-Y4TJZ6XZ.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.6",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
@@ -420,13 +420,22 @@ export class CaddyInstant {
420
420
  const child = new HelperCaddyProcess(session.client)
421
421
  this._caddyChild = child
422
422
 
423
- await session.client.call('caddy.start')
423
+ const started = await session.client.call('caddy.start')
424
424
 
425
425
  child.on('exit', (code: number | null) => {
426
426
  if (code !== null && code !== 0)
427
427
  reject(new Error(`Caddy exited with code ${code}`))
428
428
  })
429
429
 
430
+ // Caddy was already serving: its "serving initial" line was emitted
431
+ // when the first project started it, so waiting for it again would
432
+ // hang this instance forever.
433
+ if (started?.started === false) {
434
+ consola.info('Caddy is already running; added this route to it.')
435
+ void resolveWhenReady()
436
+ return
437
+ }
438
+
430
439
  child.stderr.on('data', async (data: Buffer) => {
431
440
  const lines = data.toString().split('\n').map((line: string) => line.trim())
432
441
  for (const line of lines) {
@@ -44,7 +44,8 @@ export interface HelperResults {
44
44
  'hosts.add': void
45
45
  'hosts.remove': void
46
46
  'port.free': { killed: number[] }
47
- 'caddy.start': { pid?: number }
47
+ /** `started: false` means Caddy was already running and was reused. */
48
+ 'caddy.start': { pid?: number, started?: boolean }
48
49
  'caddy.stop': void
49
50
  'ca.trust': { trusted: boolean, output: string }
50
51
  }
@@ -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)