@tokenbuddy/tokenbuddy 1.0.24 → 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
|
@@ -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(
|
|
166
|
+
const child = spawn(resolveNpxCommand(), args, {
|
|
138
167
|
stdio: ["ignore", "pipe", "pipe"],
|
|
139
168
|
});
|
|
140
169
|
let stdout = "";
|
package/tests/tokenbuddy.test.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
checkOpenClawRuntime,
|
|
14
14
|
parseClawtipCliOutput,
|
|
15
15
|
readClawtipPayCredential,
|
|
16
|
+
resolveNpxCommand,
|
|
16
17
|
resolveClawtipQrMediaPath,
|
|
17
18
|
startClawtipWalletBootstrap,
|
|
18
19
|
waitForClawtipActivationConfirmation,
|
|
@@ -1116,6 +1117,24 @@ describe("TokenBuddy init payment options", () => {
|
|
|
1116
1117
|
expect(parsed.requiresWalletAuth).toBe(true);
|
|
1117
1118
|
});
|
|
1118
1119
|
|
|
1120
|
+
test("resolves npx next to the Node executable when PATH is sparse", () => {
|
|
1121
|
+
const resolved = resolveNpxCommand({
|
|
1122
|
+
execPath: "/opt/homebrew/Cellar/node/26.0.0/bin/node",
|
|
1123
|
+
envPath: "/usr/bin:/bin",
|
|
1124
|
+
exists: (filePath) => filePath === "/opt/homebrew/Cellar/node/26.0.0/bin/npx",
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
expect(resolved).toBe("/opt/homebrew/Cellar/node/26.0.0/bin/npx");
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
test("falls back to npx command name when no absolute candidate exists", () => {
|
|
1131
|
+
expect(resolveNpxCommand({
|
|
1132
|
+
execPath: "/missing/bin/node",
|
|
1133
|
+
envPath: "/usr/bin:/bin",
|
|
1134
|
+
exists: () => false,
|
|
1135
|
+
})).toBe("npx");
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1119
1138
|
test("surfaces ClawTip upstream payment errors directly", async () => {
|
|
1120
1139
|
const parsed = parseClawtipCliOutput("ClawTip 返回错误:商家信息有误");
|
|
1121
1140
|
|