|
| 1 | +/** |
| 2 | + * Download and prepare MinGit for Windows bundling. |
| 3 | + * |
| 4 | + * MinGit provides git + POSIX tools needed by Claude Code CLI. |
| 5 | + * MinGit's sh.exe IS GNU bash (same binary, POSIX mode by default), |
| 6 | + * so we copy it to bash.exe to satisfy Claude Code's requirement. |
| 7 | + * |
| 8 | + * Only runs on Windows. Skipped on other platforms. |
| 9 | + */ |
| 10 | + |
| 11 | +import { existsSync, mkdirSync, cpSync, copyFileSync, rmSync } from 'fs'; |
| 12 | +import { execSync } from 'child_process'; |
| 13 | +import { join } from 'path'; |
| 14 | + |
| 15 | +if (process.platform !== 'win32') { |
| 16 | + console.log('MinGit bundling skipped (not Windows)'); |
| 17 | + process.exit(0); |
| 18 | +} |
| 19 | + |
| 20 | +const MINGIT_VERSION = '2.53.0.2'; |
| 21 | +const MINGIT_URL = `https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.2/MinGit-${MINGIT_VERSION}-64-bit.zip`; |
| 22 | +const DEST_DIR = join(process.cwd(), 'build', 'mingit'); |
| 23 | +const CACHE_ZIP = join(process.cwd(), 'build', 'mingit.zip'); |
| 24 | + |
| 25 | +// Skip if already extracted |
| 26 | +if (existsSync(join(DEST_DIR, 'cmd', 'git.exe'))) { |
| 27 | + console.log('MinGit already present, skipping download'); |
| 28 | + process.exit(0); |
| 29 | +} |
| 30 | + |
| 31 | +mkdirSync(join(process.cwd(), 'build'), { recursive: true }); |
| 32 | + |
| 33 | +// Download |
| 34 | +if (!existsSync(CACHE_ZIP)) { |
| 35 | + console.log(`Downloading MinGit ${MINGIT_VERSION}...`); |
| 36 | + execSync(`curl -sL "${MINGIT_URL}" -o "${CACHE_ZIP}"`, { stdio: 'inherit' }); |
| 37 | +} |
| 38 | + |
| 39 | +// Extract |
| 40 | +console.log('Extracting MinGit...'); |
| 41 | +rmSync(DEST_DIR, { recursive: true, force: true }); |
| 42 | +mkdirSync(DEST_DIR, { recursive: true }); |
| 43 | +execSync( |
| 44 | + `powershell.exe -NoProfile -Command "Expand-Archive -Path '${CACHE_ZIP}' -DestinationPath '${DEST_DIR}' -Force"`, |
| 45 | + { stdio: 'inherit' }, |
| 46 | +); |
| 47 | + |
| 48 | +// MinGit's sh.exe is GNU bash in POSIX mode. Copy it to bash.exe so |
| 49 | +// Claude Code CLI can find it via CLAUDE_CODE_GIT_BASH_PATH. |
| 50 | +const shExe = join(DEST_DIR, 'usr', 'bin', 'sh.exe'); |
| 51 | +const bashExe = join(DEST_DIR, 'usr', 'bin', 'bash.exe'); |
| 52 | +if (existsSync(shExe) && !existsSync(bashExe)) { |
| 53 | + copyFileSync(shExe, bashExe); |
| 54 | + console.log('Copied sh.exe -> bash.exe'); |
| 55 | +} |
| 56 | + |
| 57 | +console.log(`MinGit ${MINGIT_VERSION} ready at ${DEST_DIR}`); |
0 commit comments