unplugin-https-reverse-proxy 4.1.0-beta.7 → 4.1.0-beta.9

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.
@@ -13149,29 +13149,31 @@ function writeConfig(proxies) {
13149
13149
  writeFileSync(temp, content);
13150
13150
  renameSync(temp, caddyConfigPath);
13151
13151
  }
13152
- async function mutateConfig(lock3, mutate) {
13153
- const release = await lock3.acquire();
13154
- try {
13155
- const proxies = readConfig();
13156
- mutate(proxies);
13157
- writeConfig(proxies);
13158
- return proxies;
13159
- } finally {
13160
- release();
13161
- }
13162
- }
13163
13152
  function useCaddyConfig(options = {}) {
13164
13153
  const lock3 = options.lock ?? createFileLock();
13154
+ async function mutate(apply) {
13155
+ var _a4;
13156
+ const release = await lock3.acquire();
13157
+ try {
13158
+ const proxies = readConfig();
13159
+ apply(proxies);
13160
+ writeConfig(proxies);
13161
+ await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
13162
+ return proxies;
13163
+ } finally {
13164
+ release();
13165
+ }
13166
+ }
13165
13167
  return {
13166
13168
  configJsonRef: () => existsSync2(caddyConfigPath) ? readConfig() : void 0,
13167
13169
  async writeCaddyConfig(_proxies, key) {
13168
- await mutateConfig(lock3, (proxies) => {
13170
+ await mutate((proxies) => {
13169
13171
  for (const p of _proxies)
13170
13172
  proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: process3.pid };
13171
13173
  });
13172
13174
  },
13173
13175
  async removeProxy(key) {
13174
- const proxies = await mutateConfig(lock3, (current) => {
13176
+ const proxies = await mutate((current) => {
13175
13177
  for (const route of Object.keys(current)) {
13176
13178
  if (route.endsWith(`#${key}`))
13177
13179
  delete current[route];
@@ -13575,19 +13577,22 @@ function takeBackTerminal() {
13575
13577
  return () => {
13576
13578
  };
13577
13579
  const wasRaw = stdin.isRaw === true;
13580
+ stdin.pause();
13578
13581
  try {
13579
13582
  stdin.setRawMode(false);
13580
13583
  } catch {
13584
+ stdin.resume();
13581
13585
  return () => {
13582
13586
  };
13583
13587
  }
13584
13588
  return () => {
13585
- if (!wasRaw)
13586
- return;
13587
- try {
13588
- stdin.setRawMode(true);
13589
- } catch {
13589
+ if (wasRaw) {
13590
+ try {
13591
+ stdin.setRawMode(true);
13592
+ } catch {
13593
+ }
13590
13594
  }
13595
+ stdin.resume();
13591
13596
  };
13592
13597
  }
13593
13598
  var PrivilegeDeniedError = class extends Error {
@@ -14017,10 +14022,23 @@ function testCaddy() {
14017
14022
  });
14018
14023
  });
14019
14024
  }
14025
+ function caddyRootPath() {
14026
+ return join6(
14027
+ process8.platform === "win32" ? `${process8.env.AppData}/Caddy` : `${process8.env.HOME}/Library/Application Support/Caddy`,
14028
+ "./pki/authorities/local"
14029
+ );
14030
+ }
14031
+ async function renderCaddyfile(proxies) {
14032
+ const ctx = validateTemplateContext({
14033
+ caddy_root: caddyRootPath(),
14034
+ proxies: Object.values(proxies)
14035
+ });
14036
+ await writeFile2(caddyFilePath, await genCaddyfile(ctx));
14037
+ }
14020
14038
  var caddyConfig;
14021
14039
  function getCaddyConfig() {
14022
14040
  if (!caddyConfig) {
14023
- caddyConfig = useCaddyConfig();
14041
+ caddyConfig = useCaddyConfig({ renderCaddyfile });
14024
14042
  }
14025
14043
  return caddyConfig;
14026
14044
  }
@@ -14076,10 +14094,7 @@ var CaddyInstant = class {
14076
14094
  return this.caddyfile;
14077
14095
  }
14078
14096
  get caddyRoot() {
14079
- return join6(
14080
- process8.platform === "win32" ? `${process8.env.AppData}/Caddy` : `${process8.env.HOME}/Library/Application Support/Caddy`,
14081
- "./pki/authorities/local"
14082
- );
14097
+ return caddyRootPath();
14083
14098
  }
14084
14099
  async writeCaddyfile() {
14085
14100
  return await writeFile2(caddyFilePath, this.caddyfile || "");
package/dist/esbuild.cjs CHANGED
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
13197
13197
  (0, import_node_fs.writeFileSync)(temp, content);
13198
13198
  (0, import_node_fs.renameSync)(temp, caddyConfigPath);
13199
13199
  }
13200
- async function mutateConfig(lock3, mutate) {
13201
- const release = await lock3.acquire();
13202
- try {
13203
- const proxies = readConfig();
13204
- mutate(proxies);
13205
- writeConfig(proxies);
13206
- return proxies;
13207
- } finally {
13208
- release();
13209
- }
13210
- }
13211
13200
  function useCaddyConfig(options = {}) {
13212
13201
  const lock3 = options.lock ?? createFileLock();
13202
+ async function mutate(apply) {
13203
+ var _a4;
13204
+ const release = await lock3.acquire();
13205
+ try {
13206
+ const proxies = readConfig();
13207
+ apply(proxies);
13208
+ writeConfig(proxies);
13209
+ await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
13210
+ return proxies;
13211
+ } finally {
13212
+ release();
13213
+ }
13214
+ }
13213
13215
  return {
13214
13216
  configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
13215
13217
  async writeCaddyConfig(_proxies, key) {
13216
- await mutateConfig(lock3, (proxies) => {
13218
+ await mutate((proxies) => {
13217
13219
  for (const p of _proxies)
13218
13220
  proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
13219
13221
  });
13220
13222
  },
13221
13223
  async removeProxy(key) {
13222
- const proxies = await mutateConfig(lock3, (current) => {
13224
+ const proxies = await mutate((current) => {
13223
13225
  for (const route of Object.keys(current)) {
13224
13226
  if (route.endsWith(`#${key}`))
13225
13227
  delete current[route];
@@ -13674,19 +13676,22 @@ function takeBackTerminal() {
13674
13676
  return () => {
13675
13677
  };
13676
13678
  const wasRaw = stdin.isRaw === true;
13679
+ stdin.pause();
13677
13680
  try {
13678
13681
  stdin.setRawMode(false);
13679
13682
  } catch {
13683
+ stdin.resume();
13680
13684
  return () => {
13681
13685
  };
13682
13686
  }
13683
13687
  return () => {
13684
- if (!wasRaw)
13685
- return;
13686
- try {
13687
- stdin.setRawMode(true);
13688
- } catch {
13688
+ if (wasRaw) {
13689
+ try {
13690
+ stdin.setRawMode(true);
13691
+ } catch {
13692
+ }
13689
13693
  }
13694
+ stdin.resume();
13690
13695
  };
13691
13696
  }
13692
13697
  var PrivilegeDeniedError = class extends Error {
@@ -14117,10 +14122,23 @@ function testCaddy() {
14117
14122
  });
14118
14123
  });
14119
14124
  }
14125
+ function caddyRootPath() {
14126
+ return (0, import_node_path5.join)(
14127
+ import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14128
+ "./pki/authorities/local"
14129
+ );
14130
+ }
14131
+ async function renderCaddyfile(proxies) {
14132
+ const ctx = validateTemplateContext({
14133
+ caddy_root: caddyRootPath(),
14134
+ proxies: Object.values(proxies)
14135
+ });
14136
+ await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
14137
+ }
14120
14138
  var caddyConfig;
14121
14139
  function getCaddyConfig() {
14122
14140
  if (!caddyConfig) {
14123
- caddyConfig = useCaddyConfig();
14141
+ caddyConfig = useCaddyConfig({ renderCaddyfile });
14124
14142
  }
14125
14143
  return caddyConfig;
14126
14144
  }
@@ -14176,10 +14194,7 @@ var CaddyInstant = class {
14176
14194
  return this.caddyfile;
14177
14195
  }
14178
14196
  get caddyRoot() {
14179
- return (0, import_node_path5.join)(
14180
- import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14181
- "./pki/authorities/local"
14182
- );
14197
+ return caddyRootPath();
14183
14198
  }
14184
14199
  async writeCaddyfile() {
14185
14200
  return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-FNF6HQJB.js";
3
+ } from "./chunk-3NHJSYFO.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";
package/dist/index.cjs CHANGED
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
13197
13197
  (0, import_node_fs.writeFileSync)(temp, content);
13198
13198
  (0, import_node_fs.renameSync)(temp, caddyConfigPath);
13199
13199
  }
13200
- async function mutateConfig(lock3, mutate) {
13201
- const release = await lock3.acquire();
13202
- try {
13203
- const proxies = readConfig();
13204
- mutate(proxies);
13205
- writeConfig(proxies);
13206
- return proxies;
13207
- } finally {
13208
- release();
13209
- }
13210
- }
13211
13200
  function useCaddyConfig(options = {}) {
13212
13201
  const lock3 = options.lock ?? createFileLock();
13202
+ async function mutate(apply) {
13203
+ var _a4;
13204
+ const release = await lock3.acquire();
13205
+ try {
13206
+ const proxies = readConfig();
13207
+ apply(proxies);
13208
+ writeConfig(proxies);
13209
+ await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
13210
+ return proxies;
13211
+ } finally {
13212
+ release();
13213
+ }
13214
+ }
13213
13215
  return {
13214
13216
  configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
13215
13217
  async writeCaddyConfig(_proxies, key) {
13216
- await mutateConfig(lock3, (proxies) => {
13218
+ await mutate((proxies) => {
13217
13219
  for (const p of _proxies)
13218
13220
  proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
13219
13221
  });
13220
13222
  },
13221
13223
  async removeProxy(key) {
13222
- const proxies = await mutateConfig(lock3, (current) => {
13224
+ const proxies = await mutate((current) => {
13223
13225
  for (const route of Object.keys(current)) {
13224
13226
  if (route.endsWith(`#${key}`))
13225
13227
  delete current[route];
@@ -13674,19 +13676,22 @@ function takeBackTerminal() {
13674
13676
  return () => {
13675
13677
  };
13676
13678
  const wasRaw = stdin.isRaw === true;
13679
+ stdin.pause();
13677
13680
  try {
13678
13681
  stdin.setRawMode(false);
13679
13682
  } catch {
13683
+ stdin.resume();
13680
13684
  return () => {
13681
13685
  };
13682
13686
  }
13683
13687
  return () => {
13684
- if (!wasRaw)
13685
- return;
13686
- try {
13687
- stdin.setRawMode(true);
13688
- } catch {
13688
+ if (wasRaw) {
13689
+ try {
13690
+ stdin.setRawMode(true);
13691
+ } catch {
13692
+ }
13689
13693
  }
13694
+ stdin.resume();
13690
13695
  };
13691
13696
  }
13692
13697
  var PrivilegeDeniedError = class extends Error {
@@ -14117,10 +14122,23 @@ function testCaddy() {
14117
14122
  });
14118
14123
  });
14119
14124
  }
14125
+ function caddyRootPath() {
14126
+ return (0, import_node_path5.join)(
14127
+ import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14128
+ "./pki/authorities/local"
14129
+ );
14130
+ }
14131
+ async function renderCaddyfile(proxies) {
14132
+ const ctx = validateTemplateContext({
14133
+ caddy_root: caddyRootPath(),
14134
+ proxies: Object.values(proxies)
14135
+ });
14136
+ await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
14137
+ }
14120
14138
  var caddyConfig;
14121
14139
  function getCaddyConfig() {
14122
14140
  if (!caddyConfig) {
14123
- caddyConfig = useCaddyConfig();
14141
+ caddyConfig = useCaddyConfig({ renderCaddyfile });
14124
14142
  }
14125
14143
  return caddyConfig;
14126
14144
  }
@@ -14176,10 +14194,7 @@ var CaddyInstant = class {
14176
14194
  return this.caddyfile;
14177
14195
  }
14178
14196
  get caddyRoot() {
14179
- return (0, import_node_path5.join)(
14180
- import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14181
- "./pki/authorities/local"
14182
- );
14197
+ return caddyRootPath();
14183
14198
  }
14184
14199
  async writeCaddyfile() {
14185
14200
  return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-FNF6HQJB.js";
6
+ } from "./chunk-3NHJSYFO.js";
7
7
  import "./chunk-EY3HXBJ4.js";
8
8
  import "./chunk-C5A7XLKL.js";
9
9
  import "./chunk-WOMR3ZLM.js";
package/dist/nuxt.cjs CHANGED
@@ -13198,29 +13198,31 @@ function writeConfig(proxies) {
13198
13198
  (0, import_node_fs.writeFileSync)(temp, content);
13199
13199
  (0, import_node_fs.renameSync)(temp, caddyConfigPath);
13200
13200
  }
13201
- async function mutateConfig(lock3, mutate) {
13202
- const release = await lock3.acquire();
13203
- try {
13204
- const proxies = readConfig();
13205
- mutate(proxies);
13206
- writeConfig(proxies);
13207
- return proxies;
13208
- } finally {
13209
- release();
13210
- }
13211
- }
13212
13201
  function useCaddyConfig(options = {}) {
13213
13202
  const lock3 = options.lock ?? createFileLock();
13203
+ async function mutate(apply) {
13204
+ var _a4;
13205
+ const release = await lock3.acquire();
13206
+ try {
13207
+ const proxies = readConfig();
13208
+ apply(proxies);
13209
+ writeConfig(proxies);
13210
+ await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
13211
+ return proxies;
13212
+ } finally {
13213
+ release();
13214
+ }
13215
+ }
13214
13216
  return {
13215
13217
  configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
13216
13218
  async writeCaddyConfig(_proxies, key) {
13217
- await mutateConfig(lock3, (proxies) => {
13219
+ await mutate((proxies) => {
13218
13220
  for (const p of _proxies)
13219
13221
  proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
13220
13222
  });
13221
13223
  },
13222
13224
  async removeProxy(key) {
13223
- const proxies = await mutateConfig(lock3, (current) => {
13225
+ const proxies = await mutate((current) => {
13224
13226
  for (const route of Object.keys(current)) {
13225
13227
  if (route.endsWith(`#${key}`))
13226
13228
  delete current[route];
@@ -13675,19 +13677,22 @@ function takeBackTerminal() {
13675
13677
  return () => {
13676
13678
  };
13677
13679
  const wasRaw = stdin.isRaw === true;
13680
+ stdin.pause();
13678
13681
  try {
13679
13682
  stdin.setRawMode(false);
13680
13683
  } catch {
13684
+ stdin.resume();
13681
13685
  return () => {
13682
13686
  };
13683
13687
  }
13684
13688
  return () => {
13685
- if (!wasRaw)
13686
- return;
13687
- try {
13688
- stdin.setRawMode(true);
13689
- } catch {
13689
+ if (wasRaw) {
13690
+ try {
13691
+ stdin.setRawMode(true);
13692
+ } catch {
13693
+ }
13690
13694
  }
13695
+ stdin.resume();
13691
13696
  };
13692
13697
  }
13693
13698
  var PrivilegeDeniedError = class extends Error {
@@ -14118,10 +14123,23 @@ function testCaddy() {
14118
14123
  });
14119
14124
  });
14120
14125
  }
14126
+ function caddyRootPath() {
14127
+ return (0, import_node_path5.join)(
14128
+ import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14129
+ "./pki/authorities/local"
14130
+ );
14131
+ }
14132
+ async function renderCaddyfile(proxies) {
14133
+ const ctx = validateTemplateContext({
14134
+ caddy_root: caddyRootPath(),
14135
+ proxies: Object.values(proxies)
14136
+ });
14137
+ await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
14138
+ }
14121
14139
  var caddyConfig;
14122
14140
  function getCaddyConfig() {
14123
14141
  if (!caddyConfig) {
14124
- caddyConfig = useCaddyConfig();
14142
+ caddyConfig = useCaddyConfig({ renderCaddyfile });
14125
14143
  }
14126
14144
  return caddyConfig;
14127
14145
  }
@@ -14177,10 +14195,7 @@ var CaddyInstant = class {
14177
14195
  return this.caddyfile;
14178
14196
  }
14179
14197
  get caddyRoot() {
14180
- return (0, import_node_path5.join)(
14181
- import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14182
- "./pki/authorities/local"
14183
- );
14198
+ return caddyRootPath();
14184
14199
  }
14185
14200
  async writeCaddyfile() {
14186
14201
  return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-FNF6HQJB.js";
3
+ } from "./chunk-3NHJSYFO.js";
4
4
  import {
5
5
  consola
6
6
  } from "./chunk-EY3HXBJ4.js";
@@ -381,7 +381,8 @@ function createHelperRuntime(deps) {
381
381
  await dispose();
382
382
  },
383
383
  dispose,
384
- sweepStaleEntries
384
+ sweepStaleEntries,
385
+ clientCount: () => clients.size
385
386
  };
386
387
  }
387
388
  async function reclaimTree(target, uid, gid) {
@@ -432,6 +433,14 @@ function createNodeHelperDeps(options) {
432
433
  const log = options.log ?? ((message) => import_node_process.default.stdout.write(`${message}
433
434
  `));
434
435
  let caddy;
436
+ import_node_process.default.on("exit", () => {
437
+ if ((caddy == null ? void 0 : caddy.pid) === void 0)
438
+ return;
439
+ try {
440
+ import_node_process.default.kill(caddy.pid, "SIGTERM");
441
+ } catch {
442
+ }
443
+ });
435
444
  return {
436
445
  readHosts: () => (0, import_node_fs.readFileSync)(hostsPath, "utf8"),
437
446
  writeHosts: (content) => {
@@ -476,7 +485,8 @@ function createNodeHelperDeps(options) {
476
485
  const child = (0, import_node_child_process.spawn)(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
477
486
  cwd: options.caddyCwd ?? import_node_process.default.cwd(),
478
487
  env: { ...import_node_process.default.env, ...options.caddyEnv },
479
- stdio: ["ignore", "pipe", "pipe"]
488
+ stdio: ["ignore", "pipe", "pipe"],
489
+ detached: (0, import_node_os.platform)() !== "win32"
480
490
  });
481
491
  const handle = {
482
492
  pid: child.pid,
@@ -750,13 +760,14 @@ async function main() {
750
760
  XDG_DATA_HOME: import_node_process3.default.env.XDG_DATA_HOME ?? ""
751
761
  }
752
762
  });
753
- import_node_process3.default.on("SIGINT", () => {
754
- });
755
- const shutdown = () => {
763
+ for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
764
+ import_node_process3.default.on(signal, () => {
765
+ });
766
+ import_node_process3.default.on("SIGTERM", () => {
767
+ if (helper.runtime.clientCount() > 0)
768
+ return;
756
769
  void helper.runtime.dispose().finally(() => import_node_process3.default.exit(0));
757
- };
758
- import_node_process3.default.on("SIGTERM", shutdown);
759
- import_node_process3.default.on("SIGHUP", shutdown);
770
+ });
760
771
  import_node_process3.default.stdout.on("error", () => {
761
772
  });
762
773
  import_node_process3.default.stderr.on("error", () => {
@@ -355,7 +355,8 @@ function createHelperRuntime(deps) {
355
355
  await dispose();
356
356
  },
357
357
  dispose,
358
- sweepStaleEntries
358
+ sweepStaleEntries,
359
+ clientCount: () => clients.size
359
360
  };
360
361
  }
361
362
  async function reclaimTree(target, uid, gid) {
@@ -406,6 +407,14 @@ function createNodeHelperDeps(options) {
406
407
  const log = options.log ?? ((message) => process.stdout.write(`${message}
407
408
  `));
408
409
  let caddy;
410
+ process.on("exit", () => {
411
+ if ((caddy == null ? void 0 : caddy.pid) === void 0)
412
+ return;
413
+ try {
414
+ process.kill(caddy.pid, "SIGTERM");
415
+ } catch {
416
+ }
417
+ });
409
418
  return {
410
419
  readHosts: () => readFileSync(hostsPath, "utf8"),
411
420
  writeHosts: (content) => {
@@ -450,7 +459,8 @@ function createNodeHelperDeps(options) {
450
459
  const child = spawn(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
451
460
  cwd: options.caddyCwd ?? process.cwd(),
452
461
  env: { ...process.env, ...options.caddyEnv },
453
- stdio: ["ignore", "pipe", "pipe"]
462
+ stdio: ["ignore", "pipe", "pipe"],
463
+ detached: platform() !== "win32"
454
464
  });
455
465
  const handle = {
456
466
  pid: child.pid,
@@ -724,13 +734,14 @@ async function main() {
724
734
  XDG_DATA_HOME: process3.env.XDG_DATA_HOME ?? ""
725
735
  }
726
736
  });
727
- process3.on("SIGINT", () => {
728
- });
729
- const shutdown = () => {
737
+ for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
738
+ process3.on(signal, () => {
739
+ });
740
+ process3.on("SIGTERM", () => {
741
+ if (helper.runtime.clientCount() > 0)
742
+ return;
730
743
  void helper.runtime.dispose().finally(() => process3.exit(0));
731
- };
732
- process3.on("SIGTERM", shutdown);
733
- process3.on("SIGHUP", shutdown);
744
+ });
734
745
  process3.stdout.on("error", () => {
735
746
  });
736
747
  process3.stderr.on("error", () => {
package/dist/rollup.cjs CHANGED
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
13197
13197
  (0, import_node_fs.writeFileSync)(temp, content);
13198
13198
  (0, import_node_fs.renameSync)(temp, caddyConfigPath);
13199
13199
  }
13200
- async function mutateConfig(lock3, mutate) {
13201
- const release = await lock3.acquire();
13202
- try {
13203
- const proxies = readConfig();
13204
- mutate(proxies);
13205
- writeConfig(proxies);
13206
- return proxies;
13207
- } finally {
13208
- release();
13209
- }
13210
- }
13211
13200
  function useCaddyConfig(options = {}) {
13212
13201
  const lock3 = options.lock ?? createFileLock();
13202
+ async function mutate(apply) {
13203
+ var _a4;
13204
+ const release = await lock3.acquire();
13205
+ try {
13206
+ const proxies = readConfig();
13207
+ apply(proxies);
13208
+ writeConfig(proxies);
13209
+ await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
13210
+ return proxies;
13211
+ } finally {
13212
+ release();
13213
+ }
13214
+ }
13213
13215
  return {
13214
13216
  configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
13215
13217
  async writeCaddyConfig(_proxies, key) {
13216
- await mutateConfig(lock3, (proxies) => {
13218
+ await mutate((proxies) => {
13217
13219
  for (const p of _proxies)
13218
13220
  proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
13219
13221
  });
13220
13222
  },
13221
13223
  async removeProxy(key) {
13222
- const proxies = await mutateConfig(lock3, (current) => {
13224
+ const proxies = await mutate((current) => {
13223
13225
  for (const route of Object.keys(current)) {
13224
13226
  if (route.endsWith(`#${key}`))
13225
13227
  delete current[route];
@@ -13674,19 +13676,22 @@ function takeBackTerminal() {
13674
13676
  return () => {
13675
13677
  };
13676
13678
  const wasRaw = stdin.isRaw === true;
13679
+ stdin.pause();
13677
13680
  try {
13678
13681
  stdin.setRawMode(false);
13679
13682
  } catch {
13683
+ stdin.resume();
13680
13684
  return () => {
13681
13685
  };
13682
13686
  }
13683
13687
  return () => {
13684
- if (!wasRaw)
13685
- return;
13686
- try {
13687
- stdin.setRawMode(true);
13688
- } catch {
13688
+ if (wasRaw) {
13689
+ try {
13690
+ stdin.setRawMode(true);
13691
+ } catch {
13692
+ }
13689
13693
  }
13694
+ stdin.resume();
13690
13695
  };
13691
13696
  }
13692
13697
  var PrivilegeDeniedError = class extends Error {
@@ -14117,10 +14122,23 @@ function testCaddy() {
14117
14122
  });
14118
14123
  });
14119
14124
  }
14125
+ function caddyRootPath() {
14126
+ return (0, import_node_path5.join)(
14127
+ import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14128
+ "./pki/authorities/local"
14129
+ );
14130
+ }
14131
+ async function renderCaddyfile(proxies) {
14132
+ const ctx = validateTemplateContext({
14133
+ caddy_root: caddyRootPath(),
14134
+ proxies: Object.values(proxies)
14135
+ });
14136
+ await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
14137
+ }
14120
14138
  var caddyConfig;
14121
14139
  function getCaddyConfig() {
14122
14140
  if (!caddyConfig) {
14123
- caddyConfig = useCaddyConfig();
14141
+ caddyConfig = useCaddyConfig({ renderCaddyfile });
14124
14142
  }
14125
14143
  return caddyConfig;
14126
14144
  }
@@ -14176,10 +14194,7 @@ var CaddyInstant = class {
14176
14194
  return this.caddyfile;
14177
14195
  }
14178
14196
  get caddyRoot() {
14179
- return (0, import_node_path5.join)(
14180
- import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14181
- "./pki/authorities/local"
14182
- );
14197
+ return caddyRootPath();
14183
14198
  }
14184
14199
  async writeCaddyfile() {
14185
14200
  return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");