peakroute 0.5.2 → 0.5.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.
@@ -538,33 +538,51 @@ function collectBinPaths(cwd) {
538
538
  function augmentedPath(env) {
539
539
  const base = (env ?? process.env).PATH ?? "";
540
540
  const bins = collectBinPaths(process.cwd());
541
+ if (IS_WINDOWS) {
542
+ const systemRoot = process.env.SystemRoot ?? "C:\\Windows";
543
+ const essentialPaths = [
544
+ path2.join(systemRoot, "System32"),
545
+ path2.join(systemRoot, "System32", "WindowsPowerShell", "v1.0"),
546
+ path2.join(systemRoot, "System32", "wbem")
547
+ // for WMI tools
548
+ ];
549
+ const bunPaths = [
550
+ path2.join(process.env.USERPROFILE ?? "C:\\Users\\" + process.env.USERNAME, ".bun", "bin"),
551
+ path2.join(process.env.LOCALAPPDATA ?? "", "bun", "bin")
552
+ ];
553
+ const pathEntries = base.split(path2.delimiter).filter(Boolean);
554
+ const missingSystemPaths = essentialPaths.filter(
555
+ (p) => pathEntries.every((entry) => entry.toLowerCase() !== p.toLowerCase())
556
+ );
557
+ const missingBunPaths = bunPaths.filter(
558
+ (p) => pathEntries.every((entry) => entry.toLowerCase() !== p.toLowerCase())
559
+ );
560
+ const allMissing = [...missingSystemPaths, ...missingBunPaths];
561
+ if (allMissing.length > 0) {
562
+ const newPath = allMissing.join(path2.delimiter) + path2.delimiter + base;
563
+ if (bins.length > 0) {
564
+ return bins.join(path2.delimiter) + path2.delimiter + newPath;
565
+ }
566
+ return newPath;
567
+ }
568
+ }
541
569
  return bins.length > 0 ? bins.join(path2.delimiter) + path2.delimiter + base : base;
542
570
  }
543
571
  function spawnCommand(commandArgs, options) {
544
572
  const env = { ...options?.env ?? process.env, PATH: augmentedPath(options?.env) };
545
573
  let child;
546
574
  if (IS_WINDOWS) {
547
- const isPowerShell = !!process.env.PSModulePath || process.env.TERM === "xterm-256color";
548
- if (isPowerShell) {
549
- const shellCmd = commandArgs.map((a) => {
550
- if (/[\s"'()$;|&<>@`]/.test(a)) {
551
- return `"${a.replace(/"/g, '`"')}"`;
552
- }
553
- return a;
554
- }).join(" ");
555
- child = spawn("powershell.exe", ["-Command", shellCmd + "; exit $LASTEXITCODE"], {
556
- stdio: "inherit",
557
- env,
558
- windowsHide: true
559
- });
560
- } else {
561
- child = spawn(commandArgs[0], commandArgs.slice(1), {
562
- stdio: "inherit",
563
- env,
564
- shell: true,
565
- windowsHide: true
566
- });
567
- }
575
+ const shellCmd = commandArgs.map((a) => {
576
+ if (/[\s"&<>|^]/.test(a)) {
577
+ return `"${a.replace(/"/g, '""')}"`;
578
+ }
579
+ return a;
580
+ }).join(" ");
581
+ child = spawn("cmd.exe", ["/c", shellCmd], {
582
+ stdio: "inherit",
583
+ env,
584
+ windowsHide: true
585
+ });
568
586
  } else {
569
587
  const shellCmd = commandArgs.map(shellEscape).join(" ");
570
588
  child = spawn("/bin/sh", ["-c", shellCmd], {
package/dist/cli.js CHANGED
@@ -24,13 +24,13 @@ import {
24
24
  spawnCommand,
25
25
  waitForProxy,
26
26
  writeTlsMarker
27
- } from "./chunk-ENHLKLCJ.js";
27
+ } from "./chunk-IVO6GF7V.js";
28
28
 
29
29
  // src/cli.ts
30
30
  import chalk from "chalk";
31
31
  import * as fs2 from "fs";
32
32
  import * as path2 from "path";
33
- import { spawn, spawnSync } from "child_process";
33
+ import { spawn, spawnSync, execSync } from "child_process";
34
34
 
35
35
  // src/certs.ts
36
36
  import * as fs from "fs";
@@ -435,6 +435,20 @@ var DEBOUNCE_MS = 100;
435
435
  var POLL_INTERVAL_MS = 3e3;
436
436
  var EXIT_TIMEOUT_MS = 2e3;
437
437
  var SUDO_SPAWN_TIMEOUT_MS = 3e4;
438
+ function killProcess(pid, force = false) {
439
+ if (IS_WINDOWS) {
440
+ const args = force ? ["/F", "/T", "/PID", pid.toString()] : ["/T", "/PID", pid.toString()];
441
+ try {
442
+ execSync(`taskkill ${args.join(" ")}`, { windowsHide: true });
443
+ } catch {
444
+ }
445
+ } else {
446
+ try {
447
+ process.kill(pid, force ? "SIGKILL" : "SIGTERM");
448
+ } catch {
449
+ }
450
+ }
451
+ }
438
452
  function startProxyServer(store, proxyPort, tlsOptions) {
439
453
  store.ensureDir();
440
454
  const isTls = !!tlsOptions;
@@ -540,7 +554,7 @@ async function stopProxy(store, proxyPort, tls2) {
540
554
  const pid = findPidOnPort(proxyPort);
541
555
  if (pid !== null) {
542
556
  try {
543
- process.kill(pid, "SIGTERM");
557
+ killProcess(pid);
544
558
  try {
545
559
  fs2.unlinkSync(store.portFilePath);
546
560
  } catch {
@@ -615,7 +629,7 @@ async function stopProxy(store, proxyPort, tls2) {
615
629
  fs2.unlinkSync(pidPath);
616
630
  return;
617
631
  }
618
- process.kill(pid, "SIGTERM");
632
+ killProcess(pid);
619
633
  fs2.unlinkSync(pidPath);
620
634
  try {
621
635
  fs2.unlinkSync(store.portFilePath);
@@ -884,7 +898,7 @@ ${chalk.bold("Skip peakroute:")}
884
898
  process.exit(0);
885
899
  }
886
900
  if (args[0] === "--version" || args[0] === "-v") {
887
- console.log("0.5.2");
901
+ console.log("0.5.3");
888
902
  process.exit(0);
889
903
  }
890
904
  if (args[0] === "trust") {
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  formatUrl,
15
15
  isErrnoException,
16
16
  parseHostname
17
- } from "./chunk-ENHLKLCJ.js";
17
+ } from "./chunk-IVO6GF7V.js";
18
18
  export {
19
19
  DIR_MODE,
20
20
  FILE_MODE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peakroute",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Replace port numbers with stable, named .localhost URLs. For humans and agents. (Formerly portless)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",