@oh-my-pi/pi-utils 9.4.0 → 9.6.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/procmgr.ts +30 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "9.4.0",
3
+ "version": "9.6.0",
4
4
  "description": "Shared utilities for pi packages",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/procmgr.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as fs from "node:fs";
2
+ import path from "node:path";
2
3
  import * as timers from "node:timers";
3
4
  import type { Subprocess } from "bun";
4
5
 
@@ -82,6 +83,30 @@ function buildConfig(shell: string): ShellConfig {
82
83
  };
83
84
  }
84
85
 
86
+ /**
87
+ * Resolve the basic shell to use if shellForceBasic is true.
88
+ */
89
+ export function resolveBasicShell(): string | undefined {
90
+ for (const name of ["bash", "bash.exe", "sh", "sh.exe"]) {
91
+ const resolved = Bun.which(name);
92
+ if (resolved) return resolved;
93
+ }
94
+
95
+ if (process.platform !== "win32") {
96
+ const searchPaths = ["/bin", "/usr/bin", "/usr/local/bin", "/opt/homebrew/bin"];
97
+ const candidates = ["bash", "sh"];
98
+
99
+ for (const name of candidates) {
100
+ for (const dir of searchPaths) {
101
+ const fullPath = path.join(dir, name);
102
+ if (fs.existsSync(fullPath)) return fullPath;
103
+ }
104
+ }
105
+ }
106
+
107
+ return undefined;
108
+ }
109
+
85
110
  /**
86
111
  * Get shell configuration based on platform.
87
112
  * Resolution order:
@@ -149,30 +174,13 @@ export function getShellConfig(customShellPath?: string): ShellConfig {
149
174
  return cachedShellConfig;
150
175
  }
151
176
 
152
- // Fallback paths (Claude's approach: check known locations)
153
- const fallbackPaths = ["/bin", "/usr/bin", "/usr/local/bin", "/opt/homebrew/bin"];
154
- const preferZsh = !userShell?.includes("bash");
155
- const shellOrder = preferZsh ? ["zsh", "bash"] : ["bash", "zsh"];
156
-
157
- for (const shellName of shellOrder) {
158
- for (const dir of fallbackPaths) {
159
- const shellPath = `${dir}/${shellName}`;
160
- if (isExecutable(shellPath)) {
161
- cachedShellConfig = buildConfig(shellPath);
162
- return cachedShellConfig;
163
- }
164
- }
165
- }
166
-
167
- // Last resort: use Bun.which
168
- const bashPath = Bun.which("bash");
169
- if (bashPath) {
170
- cachedShellConfig = buildConfig(bashPath);
177
+ // 4. Fallback: use basic shell
178
+ const basicShell = resolveBasicShell();
179
+ if (basicShell) {
180
+ cachedShellConfig = buildConfig(basicShell);
171
181
  return cachedShellConfig;
172
182
  }
173
-
174
- const shPath = Bun.which("sh");
175
- cachedShellConfig = buildConfig(shPath || "sh");
183
+ cachedShellConfig = buildConfig("sh");
176
184
  return cachedShellConfig;
177
185
  }
178
186