( channel: ReleaseChannel, specificVersion?: string | null, )
| 95 | * @param specificVersion - Optional specific version to install (overrides channel) |
| 96 | */ |
| 97 | export 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. |
no test coverage detected