MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / spawnForSource

Function spawnForSource

apps/kimi-code/src/cli/update/preflight.ts:112–138  ·  view source on GitHub ↗
(
  source: InstallSource,
  version: string,
  platform: NodeJS.Platform,
)

Source from the content-addressed store, hash-verified

110}
111
112export 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
140function formatErrorMessage(error: unknown): string {
141 return error instanceof Error ? error.message : String(error);

Callers 3

preflight.test.tsFile · 0.90
installUpdateFunction · 0.85
startBackgroundInstallFunction · 0.85

Calls 2

withCmdSuffixFunction · 0.85
bunCommandFunction · 0.85

Tested by

no test coverage detected