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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rollup.cjs CHANGED
@@ -13678,16 +13678,28 @@ var import_node_process2 = __toESM(require("process"), 1);
13678
13678
  function resolveHelperEntry(options) {
13679
13679
  const { moduleDir, nodeBin = import_node_process2.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
13680
13680
  for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
13681
- const candidate = (0, import_node_path2.join)(moduleDir, name);
13682
- if (exists2(candidate))
13681
+ const candidate = findUp(moduleDir, name, exists2);
13682
+ if (candidate)
13683
13683
  return { entry: nodeBin, args: [candidate] };
13684
13684
  }
13685
- const source = (0, import_node_path2.join)(moduleDir, "privileged-helper.ts");
13686
- const tsxCli = (0, import_node_path2.join)(moduleDir, "../node_modules/tsx/dist/cli.mjs");
13687
- if (exists2(source) && exists2(tsxCli))
13685
+ const source = findUp(moduleDir, "privileged-helper.ts", exists2);
13686
+ const tsxCli = findUp(moduleDir, "node_modules/tsx/dist/cli.mjs", exists2);
13687
+ if (source && tsxCli)
13688
13688
  return { entry: nodeBin, args: [tsxCli, source] };
13689
13689
  throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
13690
13690
  }
13691
+ function findUp(from, relative, exists2) {
13692
+ let current = from;
13693
+ while (true) {
13694
+ const candidate = (0, import_node_path2.join)(current, relative);
13695
+ if (exists2(candidate))
13696
+ return candidate;
13697
+ const parent = (0, import_node_path2.dirname)(current);
13698
+ if (parent === current)
13699
+ return void 0;
13700
+ current = parent;
13701
+ }
13702
+ }
13691
13703
 
13692
13704
  // src/privileged/session.ts
13693
13705
  var import_node_buffer = require("buffer");
@@ -13986,18 +13998,42 @@ function spawnElevatedOnWindows(options) {
13986
13998
  function createHelperToken() {
13987
13999
  return (0, import_node_crypto.randomBytes)(24).toString("hex");
13988
14000
  }
13989
- function authenticateSudo(sudoCommand = "sudo") {
14001
+ function describePasswordReason(target, https) {
14002
+ const port = https ? "443" : "80";
14003
+ return [
14004
+ `reverse proxy needs administrator permission for ${target}`,
14005
+ ` \xB7 bind port ${port}${https ? ` for https://${target}` : ""}`,
14006
+ ` \xB7 add ${target} to the hosts file`,
14007
+ "",
14008
+ "This is the only prompt; the rest of the dev server keeps running as you.",
14009
+ "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
14010
+ ];
14011
+ }
14012
+ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13990
14013
  if ((0, import_node_os3.platform)() === "win32")
13991
14014
  return { ok: true };
13992
14015
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
13993
14016
  return { ok: true };
14017
+ if (options.target) {
14018
+ for (const line of describePasswordReason(options.target, options.https ?? false))
14019
+ import_node_process5.default.stderr.write(`${line}
14020
+ `);
14021
+ import_node_process5.default.stderr.write("\n");
14022
+ }
13994
14023
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13995
14024
  return { ok: true };
13996
14025
  return {
13997
14026
  ok: false,
14027
+ denied: true,
13998
14028
  message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13999
14029
  };
14000
14030
  }
14031
+ var PrivilegeDeniedError = class extends Error {
14032
+ constructor(message) {
14033
+ super(message);
14034
+ this.name = "PrivilegeDeniedError";
14035
+ }
14036
+ };
14001
14037
  async function startPrivilegedHelper(options) {
14002
14038
  var _a4, _b3;
14003
14039
  const {
@@ -14013,9 +14049,11 @@ async function startPrivilegedHelper(options) {
14013
14049
  connectTimeoutMs = 12e4
14014
14050
  } = options;
14015
14051
  if (!skipAuth && !direct) {
14016
- const auth = authenticateSudo(sudoCommand);
14017
- if (!auth.ok)
14018
- throw new Error(auth.message);
14052
+ const auth = authenticateSudo(sudoCommand, options.reason);
14053
+ if (!auth.ok) {
14054
+ const message = auth.message ?? "administrator permission is required";
14055
+ throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
14056
+ }
14019
14057
  }
14020
14058
  const forwarded = collectForwardedEnv(env2);
14021
14059
  const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
@@ -14120,6 +14158,7 @@ async function openHelperSession(scope2) {
14120
14158
  caddyStoragePath: scope2.caddyStoragePath,
14121
14159
  caddyBin: scope2.caddyBin,
14122
14160
  caddyConfigPath: scope2.caddyConfigPath,
14161
+ reason: scope2.reason,
14123
14162
  log: scope2.log
14124
14163
  });
14125
14164
  await writeToken(scope2.runtimeDir, token);
@@ -14206,6 +14245,7 @@ function openPrivilegedSession(runtimeDir, options) {
14206
14245
  // execute a path supplied over the socket.
14207
14246
  caddyBin: options.caddyBin,
14208
14247
  caddyConfigPath: options.caddyConfigPath,
14248
+ reason: options.reason,
14209
14249
  log: options.log
14210
14250
  });
14211
14251
  }
@@ -14406,12 +14446,13 @@ function splitHostPort(addr) {
14406
14446
  return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
14407
14447
  }
14408
14448
  var defaultDependencies = {
14409
- openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
14449
+ openSession: (runtimeDir, reason) => openPrivilegedSession(runtimeDir, {
14410
14450
  log: (message) => consola.debug(message),
14411
14451
  // Both paths are fixed here, before any socket traffic: the privileged
14412
14452
  // helper must never execute something named in a request.
14413
14453
  caddyBin: caddyPath,
14414
- caddyConfigPath: caddyFilePath
14454
+ caddyConfigPath: caddyFilePath,
14455
+ reason
14415
14456
  })
14416
14457
  };
14417
14458
  var CaddyInstant = class {
@@ -14438,11 +14479,11 @@ var CaddyInstant = class {
14438
14479
  * reused across instances so a second dev server does not ask for a
14439
14480
  * password again.
14440
14481
  */
14441
- async session() {
14482
+ async session(reason) {
14442
14483
  if (this._session && !this._session.client.connected)
14443
14484
  this._session = void 0;
14444
14485
  if (!this._session)
14445
- this._session = await this.deps.openSession(TEMP_DIR);
14486
+ this._session = await this.deps.openSession(TEMP_DIR, reason);
14446
14487
  return this._session;
14447
14488
  }
14448
14489
  async getCaddyfile() {
@@ -14547,9 +14588,9 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14547
14588
  this._target = target;
14548
14589
  if (!this.inited)
14549
14590
  await this.init();
14550
- const session = await this.session();
14551
14591
  const sourceHost = splitHostPort(source).host;
14552
14592
  const targetHost = splitHostPort(target).host;
14593
+ const session = await this.session({ target: targetHost, https });
14553
14594
  await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
14554
14595
  consola.success("update host success\n");
14555
14596
  const normalizeBase = (b) => {
@@ -14981,6 +15022,15 @@ var hmrSseBridgeClientScript = `
14981
15022
  })();
14982
15023
  `;
14983
15024
 
15025
+ // src/privilege-state.ts
15026
+ var denied = false;
15027
+ function markPrivilegeDenied() {
15028
+ denied = true;
15029
+ }
15030
+ function isPrivilegeDenied() {
15031
+ return denied;
15032
+ }
15033
+
14984
15034
  // src/index.ts
14985
15035
  var config;
14986
15036
  var caddy;
@@ -15020,16 +15070,27 @@ async function printForwardProxy() {
15020
15070
  }
15021
15071
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
15022
15072
  _printUrls == null ? void 0 : _printUrls();
15073
+ if (isPrivilegeDenied())
15074
+ return;
15023
15075
  if (caddy)
15024
15076
  return;
15025
- caddy = new CaddyInstant();
15026
- caddy.run(source, target, {
15077
+ const instance = new CaddyInstant();
15078
+ caddy = instance;
15079
+ instance.run(source, target, {
15027
15080
  base,
15028
15081
  ...options
15029
15082
  }).then(async () => {
15030
15083
  await printForwardProxy();
15031
15084
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15032
15085
  }).catch((e) => {
15086
+ if (caddy === instance)
15087
+ caddy = void 0;
15088
+ if (e instanceof PrivilegeDeniedError) {
15089
+ markPrivilegeDenied();
15090
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15091
+ consola.info("Restart the dev server to enable it again.");
15092
+ return;
15093
+ }
15033
15094
  throw e;
15034
15095
  });
15035
15096
  });
@@ -15109,6 +15170,8 @@ var unpluginFactory = (options) => ({
15109
15170
  ...(_a4 = import_node_process8.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
15110
15171
  };
15111
15172
  const source = `${devServer.host}:${devServer.port}`;
15173
+ if (isPrivilegeDenied())
15174
+ return;
15112
15175
  if (caddy)
15113
15176
  return;
15114
15177
  let base = "/";
@@ -15130,8 +15193,9 @@ var unpluginFactory = (options) => ({
15130
15193
  } else {
15131
15194
  options.https = false;
15132
15195
  }
15133
- caddy = new CaddyInstant();
15134
- caddy.run(source, target, {
15196
+ const instance = new CaddyInstant();
15197
+ caddy = instance;
15198
+ instance.run(source, target, {
15135
15199
  base,
15136
15200
  ...options
15137
15201
  }).then(() => {
@@ -15140,6 +15204,14 @@ var unpluginFactory = (options) => ({
15140
15204
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15141
15205
  });
15142
15206
  }).catch((e) => {
15207
+ if (caddy === instance)
15208
+ caddy = void 0;
15209
+ if (e instanceof PrivilegeDeniedError) {
15210
+ markPrivilegeDenied();
15211
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15212
+ consola.info("Restart the dev server to enable it again.");
15213
+ return;
15214
+ }
15143
15215
  throw e;
15144
15216
  });
15145
15217
  },
@@ -15170,9 +15242,10 @@ var unpluginFactory = (options) => ({
15170
15242
  }))) == null ? void 0 : _b3.content) == null ? void 0 : _c2.server
15171
15243
  };
15172
15244
  const source = `${devServer.host}:${devServer.port}`;
15245
+ if (isPrivilegeDenied())
15246
+ return;
15173
15247
  if (caddy)
15174
15248
  return;
15175
- caddy = new CaddyInstant();
15176
15249
  let base = "/";
15177
15250
  const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
15178
15251
  if (typeof publicPath === "string" && publicPath) {
@@ -15182,13 +15255,23 @@ var unpluginFactory = (options) => ({
15182
15255
  base = `/${base}`;
15183
15256
  if (base !== "/" && !base.endsWith("/"))
15184
15257
  base = `${base}/`;
15185
- caddy.run(source, target, {
15258
+ const instance = new CaddyInstant();
15259
+ caddy = instance;
15260
+ instance.run(source, target, {
15186
15261
  base,
15187
15262
  ...options
15188
15263
  }).then(async () => {
15189
15264
  await printForwardProxy();
15190
15265
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15191
15266
  }).catch((e) => {
15267
+ if (caddy === instance)
15268
+ caddy = void 0;
15269
+ if (e instanceof PrivilegeDeniedError) {
15270
+ markPrivilegeDenied();
15271
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15272
+ consola.info("Restart the dev server to enable it again.");
15273
+ return;
15274
+ }
15192
15275
  throw e;
15193
15276
  });
15194
15277
  }
package/dist/rollup.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-7CA3EIIX.js";
3
+ } from "./chunk-HBXMM25C.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
+ import "./chunk-WOMR3ZLM.js";
6
7
  import "./chunk-RKHJN6KY.js";
7
8
 
8
9
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -13677,16 +13677,28 @@ var import_node_process2 = __toESM(require("process"), 1);
13677
13677
  function resolveHelperEntry(options) {
13678
13678
  const { moduleDir, nodeBin = import_node_process2.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
13679
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))
13680
+ const candidate = findUp(moduleDir, name, exists2);
13681
+ if (candidate)
13682
13682
  return { entry: nodeBin, args: [candidate] };
13683
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))
13684
+ const source = findUp(moduleDir, "privileged-helper.ts", exists2);
13685
+ const tsxCli = findUp(moduleDir, "node_modules/tsx/dist/cli.mjs", exists2);
13686
+ if (source && tsxCli)
13687
13687
  return { entry: nodeBin, args: [tsxCli, source] };
13688
13688
  throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
13689
13689
  }
13690
+ function findUp(from, relative, exists2) {
13691
+ let current = from;
13692
+ while (true) {
13693
+ const candidate = (0, import_node_path2.join)(current, relative);
13694
+ if (exists2(candidate))
13695
+ return candidate;
13696
+ const parent = (0, import_node_path2.dirname)(current);
13697
+ if (parent === current)
13698
+ return void 0;
13699
+ current = parent;
13700
+ }
13701
+ }
13690
13702
 
13691
13703
  // src/privileged/session.ts
13692
13704
  var import_node_buffer = require("buffer");
@@ -13985,18 +13997,42 @@ function spawnElevatedOnWindows(options) {
13985
13997
  function createHelperToken() {
13986
13998
  return (0, import_node_crypto.randomBytes)(24).toString("hex");
13987
13999
  }
13988
- function authenticateSudo(sudoCommand = "sudo") {
14000
+ function describePasswordReason(target, https) {
14001
+ const port = https ? "443" : "80";
14002
+ return [
14003
+ `reverse proxy needs administrator permission for ${target}`,
14004
+ ` \xB7 bind port ${port}${https ? ` for https://${target}` : ""}`,
14005
+ ` \xB7 add ${target} to the hosts file`,
14006
+ "",
14007
+ "This is the only prompt; the rest of the dev server keeps running as you.",
14008
+ "Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
14009
+ ];
14010
+ }
14011
+ function authenticateSudo(sudoCommand = "sudo", options = {}) {
13989
14012
  if ((0, import_node_os3.platform)() === "win32")
13990
14013
  return { ok: true };
13991
14014
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
13992
14015
  return { ok: true };
14016
+ if (options.target) {
14017
+ for (const line of describePasswordReason(options.target, options.https ?? false))
14018
+ import_node_process5.default.stderr.write(`${line}
14019
+ `);
14020
+ import_node_process5.default.stderr.write("\n");
14021
+ }
13993
14022
  if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13994
14023
  return { ok: true };
13995
14024
  return {
13996
14025
  ok: false,
14026
+ denied: true,
13997
14027
  message: "administrator permission is required to edit the hosts file and bind ports 80/443"
13998
14028
  };
13999
14029
  }
14030
+ var PrivilegeDeniedError = class extends Error {
14031
+ constructor(message) {
14032
+ super(message);
14033
+ this.name = "PrivilegeDeniedError";
14034
+ }
14035
+ };
14000
14036
  async function startPrivilegedHelper(options) {
14001
14037
  var _a4, _b3;
14002
14038
  const {
@@ -14012,9 +14048,11 @@ async function startPrivilegedHelper(options) {
14012
14048
  connectTimeoutMs = 12e4
14013
14049
  } = options;
14014
14050
  if (!skipAuth && !direct) {
14015
- const auth = authenticateSudo(sudoCommand);
14016
- if (!auth.ok)
14017
- throw new Error(auth.message);
14051
+ const auth = authenticateSudo(sudoCommand, options.reason);
14052
+ if (!auth.ok) {
14053
+ const message = auth.message ?? "administrator permission is required";
14054
+ throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
14055
+ }
14018
14056
  }
14019
14057
  const forwarded = collectForwardedEnv(env2);
14020
14058
  const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
@@ -14119,6 +14157,7 @@ async function openHelperSession(scope2) {
14119
14157
  caddyStoragePath: scope2.caddyStoragePath,
14120
14158
  caddyBin: scope2.caddyBin,
14121
14159
  caddyConfigPath: scope2.caddyConfigPath,
14160
+ reason: scope2.reason,
14122
14161
  log: scope2.log
14123
14162
  });
14124
14163
  await writeToken(scope2.runtimeDir, token);
@@ -14205,6 +14244,7 @@ function openPrivilegedSession(runtimeDir, options) {
14205
14244
  // execute a path supplied over the socket.
14206
14245
  caddyBin: options.caddyBin,
14207
14246
  caddyConfigPath: options.caddyConfigPath,
14247
+ reason: options.reason,
14208
14248
  log: options.log
14209
14249
  });
14210
14250
  }
@@ -14405,12 +14445,13 @@ function splitHostPort(addr) {
14405
14445
  return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
14406
14446
  }
14407
14447
  var defaultDependencies = {
14408
- openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
14448
+ openSession: (runtimeDir, reason) => openPrivilegedSession(runtimeDir, {
14409
14449
  log: (message) => consola.debug(message),
14410
14450
  // Both paths are fixed here, before any socket traffic: the privileged
14411
14451
  // helper must never execute something named in a request.
14412
14452
  caddyBin: caddyPath,
14413
- caddyConfigPath: caddyFilePath
14453
+ caddyConfigPath: caddyFilePath,
14454
+ reason
14414
14455
  })
14415
14456
  };
14416
14457
  var CaddyInstant = class {
@@ -14437,11 +14478,11 @@ var CaddyInstant = class {
14437
14478
  * reused across instances so a second dev server does not ask for a
14438
14479
  * password again.
14439
14480
  */
14440
- async session() {
14481
+ async session(reason) {
14441
14482
  if (this._session && !this._session.client.connected)
14442
14483
  this._session = void 0;
14443
14484
  if (!this._session)
14444
- this._session = await this.deps.openSession(TEMP_DIR);
14485
+ this._session = await this.deps.openSession(TEMP_DIR, reason);
14445
14486
  return this._session;
14446
14487
  }
14447
14488
  async getCaddyfile() {
@@ -14546,9 +14587,9 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14546
14587
  this._target = target;
14547
14588
  if (!this.inited)
14548
14589
  await this.init();
14549
- const session = await this.session();
14550
14590
  const sourceHost = splitHostPort(source).host;
14551
14591
  const targetHost = splitHostPort(target).host;
14592
+ const session = await this.session({ target: targetHost, https });
14552
14593
  await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
14553
14594
  consola.success("update host success\n");
14554
14595
  const normalizeBase = (b) => {
@@ -14980,6 +15021,15 @@ var hmrSseBridgeClientScript = `
14980
15021
  })();
14981
15022
  `;
14982
15023
 
15024
+ // src/privilege-state.ts
15025
+ var denied = false;
15026
+ function markPrivilegeDenied() {
15027
+ denied = true;
15028
+ }
15029
+ function isPrivilegeDenied() {
15030
+ return denied;
15031
+ }
15032
+
14983
15033
  // src/index.ts
14984
15034
  var config;
14985
15035
  var caddy;
@@ -15019,16 +15069,27 @@ async function printForwardProxy() {
15019
15069
  }
15020
15070
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
15021
15071
  _printUrls == null ? void 0 : _printUrls();
15072
+ if (isPrivilegeDenied())
15073
+ return;
15022
15074
  if (caddy)
15023
15075
  return;
15024
- caddy = new CaddyInstant();
15025
- caddy.run(source, target, {
15076
+ const instance = new CaddyInstant();
15077
+ caddy = instance;
15078
+ instance.run(source, target, {
15026
15079
  base,
15027
15080
  ...options
15028
15081
  }).then(async () => {
15029
15082
  await printForwardProxy();
15030
15083
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15031
15084
  }).catch((e) => {
15085
+ if (caddy === instance)
15086
+ caddy = void 0;
15087
+ if (e instanceof PrivilegeDeniedError) {
15088
+ markPrivilegeDenied();
15089
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15090
+ consola.info("Restart the dev server to enable it again.");
15091
+ return;
15092
+ }
15032
15093
  throw e;
15033
15094
  });
15034
15095
  });
@@ -15108,6 +15169,8 @@ var unpluginFactory = (options) => ({
15108
15169
  ...(_a4 = import_node_process8.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
15109
15170
  };
15110
15171
  const source = `${devServer.host}:${devServer.port}`;
15172
+ if (isPrivilegeDenied())
15173
+ return;
15111
15174
  if (caddy)
15112
15175
  return;
15113
15176
  let base = "/";
@@ -15129,8 +15192,9 @@ var unpluginFactory = (options) => ({
15129
15192
  } else {
15130
15193
  options.https = false;
15131
15194
  }
15132
- caddy = new CaddyInstant();
15133
- caddy.run(source, target, {
15195
+ const instance = new CaddyInstant();
15196
+ caddy = instance;
15197
+ instance.run(source, target, {
15134
15198
  base,
15135
15199
  ...options
15136
15200
  }).then(() => {
@@ -15139,6 +15203,14 @@ var unpluginFactory = (options) => ({
15139
15203
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15140
15204
  });
15141
15205
  }).catch((e) => {
15206
+ if (caddy === instance)
15207
+ caddy = void 0;
15208
+ if (e instanceof PrivilegeDeniedError) {
15209
+ markPrivilegeDenied();
15210
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15211
+ consola.info("Restart the dev server to enable it again.");
15212
+ return;
15213
+ }
15142
15214
  throw e;
15143
15215
  });
15144
15216
  },
@@ -15169,9 +15241,10 @@ var unpluginFactory = (options) => ({
15169
15241
  }))) == null ? void 0 : _b3.content) == null ? void 0 : _c2.server
15170
15242
  };
15171
15243
  const source = `${devServer.host}:${devServer.port}`;
15244
+ if (isPrivilegeDenied())
15245
+ return;
15172
15246
  if (caddy)
15173
15247
  return;
15174
- caddy = new CaddyInstant();
15175
15248
  let base = "/";
15176
15249
  const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
15177
15250
  if (typeof publicPath === "string" && publicPath) {
@@ -15181,13 +15254,23 @@ var unpluginFactory = (options) => ({
15181
15254
  base = `/${base}`;
15182
15255
  if (base !== "/" && !base.endsWith("/"))
15183
15256
  base = `${base}/`;
15184
- caddy.run(source, target, {
15257
+ const instance = new CaddyInstant();
15258
+ caddy = instance;
15259
+ instance.run(source, target, {
15185
15260
  base,
15186
15261
  ...options
15187
15262
  }).then(async () => {
15188
15263
  await printForwardProxy();
15189
15264
  consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
15190
15265
  }).catch((e) => {
15266
+ if (caddy === instance)
15267
+ caddy = void 0;
15268
+ if (e instanceof PrivilegeDeniedError) {
15269
+ markPrivilegeDenied();
15270
+ consola.warn("reverse proxy skipped: administrator permission was not granted.");
15271
+ consola.info("Restart the dev server to enable it again.");
15272
+ return;
15273
+ }
15191
15274
  throw e;
15192
15275
  });
15193
15276
  }
package/dist/rspack.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-7CA3EIIX.js";
3
+ } from "./chunk-HBXMM25C.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
+ import "./chunk-WOMR3ZLM.js";
6
7
  import "./chunk-RKHJN6KY.js";
7
8
 
8
9
  // src/rspack.ts