@tokenbuddy/tokenbuddy 1.0.23 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenbuddy/tokenbuddy",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "TokenBuddy Client CLI and Daemon",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -132,9 +132,38 @@ function isClawtipPayWalletAuthOutput(args: string[], output: string): boolean {
132
132
  || lower.includes("扫码");
133
133
  }
134
134
 
135
+ export interface ResolveNpxCommandOptions {
136
+ execPath?: string;
137
+ envPath?: string;
138
+ platform?: NodeJS.Platform;
139
+ exists?: (filePath: string) => boolean;
140
+ }
141
+
142
+ export function resolveNpxCommand(options: ResolveNpxCommandOptions = {}): string {
143
+ const platform = options.platform ?? process.platform;
144
+ const binaryName = platform === "win32" ? "npx.cmd" : "npx";
145
+ const exists = options.exists ?? ((filePath: string) => fs.existsSync(filePath));
146
+ const execPath = options.execPath ?? process.execPath;
147
+ const envPath = options.envPath ?? process.env.PATH ?? "";
148
+ const candidates = [
149
+ execPath ? path.join(path.dirname(execPath), binaryName) : undefined,
150
+ ...envPath.split(path.delimiter).map((entry) => entry ? path.join(entry, binaryName) : undefined),
151
+ "/opt/homebrew/bin/npx",
152
+ "/usr/local/bin/npx",
153
+ "/usr/bin/npx",
154
+ ].filter((candidate): candidate is string => Boolean(candidate));
155
+
156
+ for (const candidate of Array.from(new Set(candidates))) {
157
+ if (exists(candidate)) {
158
+ return candidate;
159
+ }
160
+ }
161
+ return binaryName;
162
+ }
163
+
135
164
  async function runClawtipCli(args: string[]): Promise<string> {
136
165
  return await new Promise((resolve, reject) => {
137
- const child = spawn("npx", args, {
166
+ const child = spawn(resolveNpxCommand(), args, {
138
167
  stdio: ["ignore", "pipe", "pipe"],
139
168
  });
140
169
  let stdout = "";