Skip to content

Commit 80f97d7

Browse files
committed
fix(install): fallback missing platform pkg to npmjs
1 parent 820a49b commit 80f97d7

6 files changed

Lines changed: 81 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.0.1] - 2026-02-06
6+
7+
### 🛠 Installation Reliability
8+
9+
- **npmjs Fallback for Platform Binary**: `install.cjs` now auto-installs the missing platform package from `https://registry.npmjs.org/` when mirror registries do not have `@dongowu/git-ai-cli-*` artifacts.
10+
- **Better Error Guidance**: Installation now prints detected registry and an explicit retry command when fallback install fails.
11+
512
## [2.0.0] - 2026-02-06
613

714
### 🦀 Rust Rewrite Upgrade (v1.0.21 -> v2.0.0)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-ai-cli"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
edition = "2021"
55
authors = ["dongowu <dongowu@gmail.com>"]
66
description = "A CLI tool to generate git commit messages using AI"

install.cjs

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require('fs');
44
const path = require('path');
55
const os = require('os');
6+
const { spawnSync } = require('child_process');
67

78
// Detect platform and architecture
89
const platform = os.platform();
@@ -17,34 +18,90 @@ const platformMap = {
1718
'win32-x64': 'win32-x64',
1819
};
1920

20-
const key = `${platform}-${arch}`;
21+
const key = platform + '-' + arch;
2122
const platformKey = platformMap[key];
23+
const npmjsRegistry = 'https://registry.npmjs.org/';
2224

2325
if (!platformKey) {
24-
console.error(`Unsupported platform: ${platform} ${arch}`);
26+
console.error('Unsupported platform: ' + platform + ' ' + arch);
2527
process.exit(1);
2628
}
2729

2830
// Try to find the binary from the platform-specific package
29-
const packageName = `@dongowu/git-ai-cli-${platformKey}`;
31+
const packageName = '@dongowu/git-ai-cli-' + platformKey;
3032
const nodeModulesPath = path.join(__dirname, 'node_modules');
3133
const binaryName = platform === 'win32' ? 'git-ai.exe' : 'git-ai';
3234
const binaryPath = path.join(nodeModulesPath, packageName, 'bin', binaryName);
3335

36+
function getRootPackageVersion() {
37+
try {
38+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
39+
return pkg.version;
40+
} catch (err) {
41+
console.warn('Warning: Failed to read package version: ' + err.message);
42+
return 'latest';
43+
}
44+
}
45+
46+
function installPlatformPackageFromNpmjs(packageSpec) {
47+
const npmExecPath = process.env.npm_execpath;
48+
let command = 'npm';
49+
const args = [];
50+
51+
if (npmExecPath && npmExecPath.endsWith('.js')) {
52+
command = process.execPath;
53+
args.push(npmExecPath);
54+
} else if (npmExecPath && fs.existsSync(npmExecPath)) {
55+
command = npmExecPath;
56+
}
57+
58+
args.push(
59+
'install',
60+
'--no-save',
61+
'--no-package-lock',
62+
'--ignore-scripts',
63+
'--registry',
64+
npmjsRegistry,
65+
packageSpec
66+
);
67+
68+
const result = spawnSync(command, args, {
69+
cwd: __dirname,
70+
stdio: 'inherit',
71+
env: process.env,
72+
});
73+
74+
return result.status === 0;
75+
}
76+
3477
// Check if binary exists
3578
if (!fs.existsSync(binaryPath)) {
36-
console.warn(`Warning: Binary not found at ${binaryPath}`);
37-
console.warn(`Please ensure the ${packageName} package is installed.`);
38-
process.exit(1);
79+
console.warn('Warning: Binary not found at ' + binaryPath);
80+
81+
const packageVersion = getRootPackageVersion();
82+
const packageSpec = packageName + '@' + packageVersion;
83+
84+
console.warn('Trying to install ' + packageSpec + ' from ' + npmjsRegistry + '...');
85+
86+
const installed = installPlatformPackageFromNpmjs(packageSpec);
87+
if (!installed || !fs.existsSync(binaryPath)) {
88+
const detectedRegistry = process.env.npm_config_registry || 'unknown';
89+
console.error('Failed to install ' + packageSpec + '.');
90+
console.error('Detected npm registry: ' + detectedRegistry);
91+
console.error('Please retry with: npm install -g @dongowu/git-ai-cli --registry=' + npmjsRegistry);
92+
process.exit(1);
93+
}
94+
95+
console.log('✅ Installed missing platform package: ' + packageSpec);
3996
}
4097

4198
// Make binary executable on Unix-like systems
4299
if (process.platform !== 'win32') {
43100
try {
44101
fs.chmodSync(binaryPath, 0o755);
45102
} catch (err) {
46-
console.warn(`Warning: Could not make binary executable: ${err.message}`);
103+
console.warn('Warning: Could not make binary executable: ' + err.message);
47104
}
48105
}
49106

50-
console.log(`✅ git-ai binary installed for ${platformKey}`);
107+
console.log('✅ git-ai binary installed for ' + platformKey);

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dongowu/git-ai-cli",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Generate git commit messages using AI - Rust Edition",
55
"main": "bin/git-ai.cjs",
66
"bin": {
@@ -43,10 +43,10 @@
4343
"LICENSE"
4444
],
4545
"optionalDependencies": {
46-
"@dongowu/git-ai-cli-linux-x64": "2.0.0",
47-
"@dongowu/git-ai-cli-linux-arm64": "2.0.0",
48-
"@dongowu/git-ai-cli-darwin-x64": "2.0.0",
49-
"@dongowu/git-ai-cli-darwin-arm64": "2.0.0",
50-
"@dongowu/git-ai-cli-win32-x64": "2.0.0"
46+
"@dongowu/git-ai-cli-linux-x64": "2.0.1",
47+
"@dongowu/git-ai-cli-linux-arm64": "2.0.1",
48+
"@dongowu/git-ai-cli-darwin-x64": "2.0.1",
49+
"@dongowu/git-ai-cli-darwin-arm64": "2.0.1",
50+
"@dongowu/git-ai-cli-win32-x64": "2.0.1"
5151
}
5252
}

src-rs/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use error::Result;
1111
#[derive(Parser)]
1212
#[command(name = "git-ai")]
1313
#[command(about = "Generate git commit messages using AI", long_about = None)]
14-
#[command(version = "2.0.0")]
14+
#[command(version = "2.0.1")]
1515
struct Cli {
1616
#[command(subcommand)]
1717
command: Option<Commands>,

0 commit comments

Comments
 (0)