( channel: ReleaseChannel, specificVersion?: string | null, )
| 111 | * @param specificVersion - Optional specific version to install (overrides channel) |
| 112 | */ |
| 113 | export async function installOrUpdateClaudePackage( |
| 114 | channel: ReleaseChannel, |
| 115 | specificVersion?: string | null, |
| 116 | ): Promise<'in_progress' | 'success' | 'install_failed'> { |
| 117 | try { |
| 118 | // First ensure the environment is set up |
| 119 | if (!(await ensureLocalPackageEnvironment())) { |
| 120 | return 'install_failed' |
| 121 | } |
| 122 | |
| 123 | // Use specific version if provided, otherwise use channel tag |
| 124 | const versionSpec = specificVersion |
| 125 | ? specificVersion |
| 126 | : channel === 'stable' |
| 127 | ? 'stable' |
| 128 | : 'latest' |
| 129 | const result = await execFileNoThrowWithCwd( |
| 130 | 'npm', |
| 131 | ['install', `${MACRO.PACKAGE_URL}@${versionSpec}`], |
| 132 | { cwd: getLocalInstallDir(), maxBuffer: 1000000 }, |
| 133 | ) |
| 134 | |
| 135 | if (result.code !== 0) { |
| 136 | const error = new Error( |
| 137 | `Failed to install NCode CLI package: ${result.stderr}`, |
| 138 | ) |
| 139 | logError(error) |
| 140 | return result.code === 190 ? 'in_progress' : 'install_failed' |
| 141 | } |
| 142 | |
| 143 | // Set installMethod to 'local' to prevent npm permission warnings |
| 144 | saveGlobalConfig(current => ({ |
| 145 | ...current, |
| 146 | installMethod: 'local', |
| 147 | })) |
| 148 | |
| 149 | return 'success' |
| 150 | } catch (error) { |
| 151 | logError(error) |
| 152 | return 'install_failed' |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Check if local installation exists. |
no test coverage detected