gpteam 0.1.12 → 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.
@@ -78,28 +78,54 @@ async function shouldInstallMissingClient(spec, options) {
78
78
 
79
79
  async function runInstallCommand(spec, runCommand, platform) {
80
80
  const [command, args] = spec.installCommand;
81
- const result = await runCommand(resolveSpawnCommand(command, platform), 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
 
87
- export function resolveSpawnCommand(command, platform = process.platform) {
88
- if (platform === 'win32' && command === 'npm') return 'npm.cmd';
89
- return command;
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 };
90
96
  }
91
97
 
92
98
  export function defaultRunCommand(command, args, options = {}) {
93
99
  return new Promise((resolve) => {
94
- const child = spawn(command, args, {
95
- stdio: options.stdio || 'ignore',
96
- shell: options.shell || false
97
- });
98
- 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 }));
99
111
  child.on('close', (status) => resolve({ status: status ?? 1 }));
100
112
  });
101
113
  }
102
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
+
103
129
  function shellQuote(value) {
104
130
  return `'${String(value).replace(/'/g, "'\\''")}'`;
105
131
  }
package/lib/help.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = 'gpteam';
2
- export const PACKAGE_VERSION = '0.1.12';
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.12",
3
+ "version": "0.1.13",
4
4
  "description": "GPTeam API interactive client configurator and ingress benchmark CLI.",
5
5
  "type": "module",
6
6
  "bin": {