From 55220ab1f3ae9cd72d3e04b8675003cb22c4ba9e Mon Sep 17 00:00:00 2001 From: Vivek R <123vivekr@gmail.com> Date: Fri, 4 Jul 2025 14:18:56 +0530 Subject: [PATCH] feat(build): standardize Claude Code version and enhance build flexibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pin Claude Code version to 1.0.41 across all build scripts for consistency - Add version parameter support to fetch-and-build.js script - Enhance build script with improved CLI argument parsing - Add prebuild hook to automatically build current platform executables Changes made: • package.json: Add --version=1.0.41 to all build:executables scripts • package.json: Add prebuild script to run build:executables:current • scripts/fetch-and-build.js: Add parseArguments() function for CLI parsing • scripts/fetch-and-build.js: Add determineClaudeCodeVersion() for version resolution • scripts/fetch-and-build.js: Update fetchClaudeCodePackage() to accept version parameter • scripts/fetch-and-build.js: Enhance usage documentation and error messages --- package.json | 11 +++--- scripts/fetch-and-build.js | 72 ++++++++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index e23d3b8..43b295a 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", - "build:executables": "bun run scripts/fetch-and-build.js", - "build:executables:current": "bun run scripts/fetch-and-build.js current", - "build:executables:linux": "bun run scripts/fetch-and-build.js linux", - "build:executables:macos": "bun run scripts/fetch-and-build.js macos", - "build:executables:windows": "bun run scripts/fetch-and-build.js windows", + "prebuild": "bun run build:executables:current", + "build:executables": "bun run scripts/fetch-and-build.js --version=1.0.41", + "build:executables:current": "bun run scripts/fetch-and-build.js current --version=1.0.41", + "build:executables:linux": "bun run scripts/fetch-and-build.js linux --version=1.0.41", + "build:executables:macos": "bun run scripts/fetch-and-build.js macos --version=1.0.41", + "build:executables:windows": "bun run scripts/fetch-and-build.js windows --version=1.0.41", "preview": "vite preview", "tauri": "tauri" }, diff --git a/scripts/fetch-and-build.js b/scripts/fetch-and-build.js index fc42fe2..f1fb9a6 100755 --- a/scripts/fetch-and-build.js +++ b/scripts/fetch-and-build.js @@ -10,9 +10,12 @@ * 4. Cleans up temporary files * * Usage: - * bun run fetch-and-build.js [platform] + * bun run fetch-and-build.js [platform] [--version=X.X.X] * * Where platform can be: all, linux, macos, windows, current + * + * Version can be specified via: + * - CLI argument: --version=1.0.41 (defaults to 1.0.41 if not specified) */ import { spawn } from 'child_process'; @@ -65,12 +68,50 @@ async function pathExists(path) { } } +/** + * Parse command line arguments to extract version and platform + * @param {string[]} args - Command line arguments + * @returns {object} - Parsed arguments with platform and version + */ +function parseArguments(args) { + let platform = 'all'; + let version = null; + + for (const arg of args) { + if (arg.startsWith('--version=')) { + version = arg.split('=')[1]; + } else if (!arg.startsWith('--')) { + platform = arg; + } + } + + return { platform, version }; +} + +/** + * Determine the Claude Code version to use + * @param {string|null} cliVersion - Version from CLI argument + * @returns {string} - The version to use + */ +function determineClaudeCodeVersion(cliVersion) { + const defaultVersion = '1.0.41'; + + if (cliVersion) { + console.log(`\n🔍 Using Claude Code version from CLI argument: ${cliVersion}`); + return cliVersion; + } + + console.log(`\n🔍 Using default Claude Code version: ${defaultVersion}`); + return defaultVersion; +} + /** * Download and extract the Claude Code package from npm + * @param {string} version - The version of the Claude Code package to download * @returns {Promise} - Path to the extracted package directory */ -async function fetchClaudeCodePackage() { - console.log('\n📦 Fetching @anthropic-ai/claude-code package from npm...'); +async function fetchClaudeCodePackage(version) { + console.log(`\n📦 Fetching @anthropic-ai/claude-code@${version} package from npm...`); const tempDir = resolve('./temp-claude-package'); const packageDir = join(tempDir, 'package'); @@ -86,8 +127,8 @@ async function fetchClaudeCodePackage() { await mkdir(tempDir, { recursive: true }); // Download the package tarball - console.log('Downloading package tarball...'); - await runCommand('npm', ['pack', '@anthropic-ai/claude-code'], { + console.log(`Downloading package tarball for version ${version}...`); + await runCommand('npm', ['pack', `@anthropic-ai/claude-code@${version}`], { cwd: tempDir }); @@ -238,12 +279,20 @@ async function buildExecutables(platform = 'all') { * Main execution function */ async function main() { - const platform = process.argv[2] || 'all'; + // Parse command line arguments + const args = process.argv.slice(2); + const { platform, version: cliVersion } = parseArguments(args); + const validPlatforms = ['all', 'linux', 'macos', 'darwin', 'windows', 'win32', 'current']; if (!validPlatforms.includes(platform)) { console.error(`Invalid platform: ${platform}`); console.error(`Valid platforms: ${validPlatforms.join(', ')}`); + console.error('\nUsage: bun run fetch-and-build.js [platform] [--version=X.X.X]'); + console.error('Examples:'); + console.error(' bun run fetch-and-build.js'); + console.error(' bun run fetch-and-build.js linux'); + console.error(' bun run fetch-and-build.js macos --version=1.0.42'); process.exit(1); } @@ -254,13 +303,16 @@ async function main() { let packageDir; try { - // Step 1: Fetch and extract the package - packageDir = await fetchClaudeCodePackage(); + // Step 1: Determine version to use + const version = determineClaudeCodeVersion(cliVersion); - // Step 2: Copy required files + // Step 2: Fetch and extract the package + packageDir = await fetchClaudeCodePackage(version); + + // Step 3: Copy required files await copyRequiredFiles(packageDir); - // Step 3: Build executables + // Step 4: Build executables await buildExecutables(platform); const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);