fix: read version from cli.js bundle instead of package.json
package.json shows npm-installed version (e.g. 2.1.47) while the actual patched cli.js contains 2.1.50. Now reads "// Version: x.y.z" from the bundle first, falls back to claude --version, then package.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -265,22 +265,31 @@ def find_cli_js():
|
|||||||
|
|
||||||
|
|
||||||
def get_installed_version():
|
def get_installed_version():
|
||||||
"""Get currently installed Claude Code version."""
|
"""Get currently installed Claude Code version.
|
||||||
|
|
||||||
|
Priority: cli.js bundle version > claude --version > package.json.
|
||||||
|
After patching, cli.js contains the real version while package.json
|
||||||
|
may still reflect the older npm-installed version.
|
||||||
|
"""
|
||||||
cli_js = find_cli_js()
|
cli_js = find_cli_js()
|
||||||
if not cli_js:
|
if not cli_js:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
# Try package.json first (same directory as cli.js)
|
# 1. Extract version from cli.js bundle itself (most accurate after patching)
|
||||||
pkg_json = os.path.join(os.path.dirname(cli_js), "package.json")
|
|
||||||
if os.path.isfile(pkg_json):
|
|
||||||
try:
|
try:
|
||||||
with open(pkg_json, "r") as f:
|
with open(cli_js, "r", encoding="utf-8", errors="ignore") as f:
|
||||||
data = json.load(f)
|
# Read first 100KB where version string usually lives
|
||||||
return data.get("version"), cli_js
|
head = f.read(100_000)
|
||||||
|
# Look for "// Version: x.y.z" comment or VERSION:"x.y.z" in the bundle
|
||||||
|
m = re.search(r'//\s*Version:\s*(\d+\.\d+\.\d+)', head)
|
||||||
|
if not m:
|
||||||
|
m = re.search(r'(?:VERSION|version)\s*[:=]\s*["\'](\d+\.\d+\.\d+)["\']', head)
|
||||||
|
if m:
|
||||||
|
return m.group(1), cli_js
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Fallback: claude --version
|
# 2. claude --version
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["claude", "--version"],
|
["claude", "--version"],
|
||||||
@@ -292,6 +301,16 @@ def get_installed_version():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 3. Fallback: package.json (may be stale after cli.js replacement)
|
||||||
|
pkg_json = os.path.join(os.path.dirname(cli_js), "package.json")
|
||||||
|
if os.path.isfile(pkg_json):
|
||||||
|
try:
|
||||||
|
with open(pkg_json, "r") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
return data.get("version"), cli_js
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
return None, cli_js
|
return None, cli_js
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user