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

Function installOrUpdateClaudePackage

src/utils/localInstaller.ts:97–138  ·  view source on GitHub ↗
(
  channel: ReleaseChannel,
  specificVersion?: string | null,
)

Source from the content-addressed store, hash-verified

95 * @param specificVersion - Optional specific version to install (overrides channel)
96 */
97export async function installOrUpdateClaudePackage(
98 channel: ReleaseChannel,
99 specificVersion?: string | null,
100): Promise<'in_progress' | 'success' | 'install_failed'> {
101 try {
102 // First ensure the environment is set up
103 if (!(await ensureLocalPackageEnvironment())) {
104 return 'install_failed'
105 }
106
107 // Use specific version if provided, otherwise use channel tag
108 const versionSpec = specificVersion
109 ? specificVersion
110 : channel === 'stable'
111 ? 'stable'
112 : 'latest'
113 const result = await execFileNoThrowWithCwd(
114 'npm',
115 ['install', `${MACRO.PACKAGE_URL}@${versionSpec}`],
116 { cwd: getLocalInstallDir(), maxBuffer: 1000000 },
117 )
118
119 if (result.code !== 0) {
120 const error = new Error(
121 `Failed to install Claude CLI package: ${result.stderr}`,
122 )
123 logError(error)
124 return result.code === 190 ? 'in_progress' : 'install_failed'
125 }
126
127 // Set installMethod to 'local' to prevent npm permission warnings
128 saveGlobalConfig(current => ({
129 ...current,
130 installMethod: 'local',
131 }))
132
133 return 'success'
134 } catch (error) {
135 logError(error)
136 return 'install_failed'
137 }
138}
139
140/**
141 * Check if local installation exists.

Callers 2

AutoUpdaterFunction · 0.85
updateFunction · 0.85

Calls 5

execFileNoThrowWithCwdFunction · 0.85
getLocalInstallDirFunction · 0.85
saveGlobalConfigFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected