gpteam 0.1.11 → 0.1.13

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.
@@ -52,7 +52,7 @@ export async function ensureClientInstalled(clientID, options = {}) {
52
52
  throw new Error(`未安装 ${spec.label},已停止配置。安装后重新运行 npx gpteam。`);
53
53
  }
54
54
 
55
- await runInstallCommand(spec, options.runCommand || defaultRunCommand);
55
+ await runInstallCommand(spec, options.runCommand || defaultRunCommand, platform);
56
56
  if (!await commandExists(spec.command)) {
57
57
  throw new Error(`安装完成但仍未检测到 ${spec.label} 命令 ${spec.command}。请检查 npm 全局 bin 是否在 PATH 中,然后运行 ${spec.versionHint}。`);
58
58
  }
@@ -76,25 +76,56 @@ async function shouldInstallMissingClient(spec, options) {
76
76
  return options.confirmInstall(spec);
77
77
  }
78
78
 
79
- async function runInstallCommand(spec, runCommand) {
79
+ async function runInstallCommand(spec, runCommand, platform) {
80
80
  const [command, args] = spec.installCommand;
81
- const result = await runCommand(command, args, { stdio: 'inherit' });
81
+ const invocation = resolveSpawnInvocation(command, args, platform);
82
+ const result = await runCommand(invocation.command, invocation.args, { stdio: 'inherit' });
82
83
  if (result.status !== 0) {
83
- throw new Error(`${spec.label} 安装失败,命令:${formatInstallCommand(spec)}`);
84
+ throw new Error(`${spec.label} 安装失败,命令:${formatInstallCommand(spec)}${formatRunError(result)}`);
84
85
  }
85
86
  }
86
87
 
88
+ export function resolveSpawnInvocation(command, args, platform = process.platform) {
89
+ if (platform === 'win32' && command === 'npm') {
90
+ return {
91
+ command: 'cmd.exe',
92
+ args: ['/d', '/s', '/c', windowsCommandLine('npm.cmd', args)]
93
+ };
94
+ }
95
+ return { command, args };
96
+ }
97
+
87
98
  export function defaultRunCommand(command, args, options = {}) {
88
99
  return new Promise((resolve) => {
89
- const child = spawn(command, args, {
90
- stdio: options.stdio || 'ignore',
91
- shell: options.shell || false
92
- });
93
- child.on('error', () => resolve({ status: 127 }));
100
+ let child;
101
+ try {
102
+ child = spawn(command, args, {
103
+ stdio: options.stdio || 'ignore',
104
+ shell: options.shell || false
105
+ });
106
+ } catch (error) {
107
+ resolve({ status: 127, error });
108
+ return;
109
+ }
110
+ child.on('error', (error) => resolve({ status: 127, error }));
94
111
  child.on('close', (status) => resolve({ status: status ?? 1 }));
95
112
  });
96
113
  }
97
114
 
115
+ function formatRunError(result) {
116
+ if (!result || !result.error) return '';
117
+ const code = result.error.code || result.error.message;
118
+ return `,底层错误:${code}`;
119
+ }
120
+
121
+ function windowsCommandLine(command, args) {
122
+ return [command, ...args].map(windowsQuoteArg).join(' ');
123
+ }
124
+
125
+ function windowsQuoteArg(value) {
126
+ return `"${String(value).replace(/"/g, '\\"')}"`;
127
+ }
128
+
98
129
  function shellQuote(value) {
99
130
  return `'${String(value).replace(/'/g, "'\\''")}'`;
100
131
  }
package/lib/help.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = 'gpteam';
2
- export const PACKAGE_VERSION = '0.1.11';
2
+ export const PACKAGE_VERSION = '0.1.13';
3
3
 
4
4
  export function getHelpText() {
5
5
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpteam",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "GPTeam API interactive client configurator and ingress benchmark CLI.",
5
5
  "type": "module",
6
6
  "bin": {