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.
- package/lib/client-install.js +36 -10
- package/lib/help.js +1 -1
- package/package.json +1 -1
package/lib/client-install.js
CHANGED
|
@@ -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
|
|
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
|
|
88
|
-
if (platform === 'win32' && command === 'npm')
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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