( source: InstallSource, version: string, platform: NodeJS.Platform, )
| 110 | } |
| 111 | |
| 112 | export function spawnForSource( |
| 113 | source: InstallSource, |
| 114 | version: string, |
| 115 | platform: NodeJS.Platform, |
| 116 | ): SpawnCommand { |
| 117 | switch (source) { |
| 118 | case 'npm-global': |
| 119 | return { cmd: withCmdSuffix('npm', platform), args: ['install', '-g', `${NPM_PACKAGE_NAME}@${version}`] }; |
| 120 | case 'pnpm-global': |
| 121 | return { cmd: withCmdSuffix('pnpm', platform), args: ['add', '-g', `${NPM_PACKAGE_NAME}@${version}`] }; |
| 122 | case 'yarn-global': |
| 123 | return { cmd: withCmdSuffix('yarn', platform), args: ['global', 'add', `${NPM_PACKAGE_NAME}@${version}`] }; |
| 124 | case 'bun-global': |
| 125 | return { cmd: bunCommand(platform), args: ['add', '-g', `${NPM_PACKAGE_NAME}@${version}`] }; |
| 126 | case 'homebrew': |
| 127 | return { cmd: 'brew', args: ['upgrade', 'kimi-code'] }; |
| 128 | case 'native': |
| 129 | // `curl … | bash` reports only the trailing bash's exit status, so a |
| 130 | // failed download (curl can't connect → empty stdin → bash exits 0) |
| 131 | // would look like a successful update. `pipefail` makes the pipeline |
| 132 | // surface curl's non-zero status so installUpdate() rejects and we warn |
| 133 | // instead of printing "Updated …". |
| 134 | return { cmd: 'bash', args: ['-c', `set -o pipefail; ${NATIVE_INSTALL_COMMAND_UNIX}`] }; |
| 135 | case 'unsupported': |
| 136 | throw new Error('unsupported install source cannot be auto-installed'); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | function formatErrorMessage(error: unknown): string { |
| 141 | return error instanceof Error ? error.message : String(error); |
no test coverage detected