MCPcopy Index your code
hub / github.com/codeaashu/claude-code / installVersionFromPackage

Function installVersionFromPackage

src/utils/nativeInstaller/installer.ts:328–383  ·  view source on GitHub ↗
(
  stagingPath: string,
  installPath: string,
)

Source from the content-addressed store, hash-verified

326}
327
328async function installVersionFromPackage(
329 stagingPath: string,
330 installPath: string,
331) {
332 try {
333 // Extract binary from npm package structure in staging
334 const nodeModulesDir = join(stagingPath, 'node_modules', '@anthropic-ai')
335 const entries = await readdir(nodeModulesDir)
336 const nativePackage = entries.find((entry: string) =>
337 entry.startsWith('claude-cli-native-'),
338 )
339
340 if (!nativePackage) {
341 logEvent('tengu_native_install_package_failure', {
342 stage_find_package: true,
343 error_package_not_found: true,
344 })
345 const error = new Error('Could not find platform-specific native package')
346 throw error
347 }
348
349 const stagedBinaryPath = join(nodeModulesDir, nativePackage, 'cli')
350
351 try {
352 await stat(stagedBinaryPath)
353 } catch {
354 logEvent('tengu_native_install_package_failure', {
355 stage_binary_exists: true,
356 error_binary_not_found: true,
357 })
358 const error = new Error('Native binary not found in staged package')
359 throw error
360 }
361
362 await atomicMoveToInstallPath(stagedBinaryPath, installPath)
363
364 // Clean up staging directory
365 await rm(stagingPath, { recursive: true, force: true })
366
367 logEvent('tengu_native_install_package_success', {})
368 } catch (error) {
369 // Log if not already logged above
370 const msg = errorMessage(error)
371 if (
372 !msg.includes('Could not find platform-specific') &&
373 !msg.includes('Native binary not found')
374 ) {
375 logEvent('tengu_native_install_package_failure', {
376 stage_atomic_move: true,
377 error_move_failed: true,
378 })
379 }
380 logError(toError(error))
381 throw error
382 }
383}
384
385async function installVersionFromBinary(

Callers 1

installVersionFunction · 0.85

Calls 8

readdirFunction · 0.85
logEventFunction · 0.85
statFunction · 0.85
atomicMoveToInstallPathFunction · 0.85
rmFunction · 0.85
toErrorFunction · 0.85
errorMessageFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected