fnva 0.0.19 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
package/platforms/fnva CHANGED
Binary file
Binary file
@@ -5,7 +5,7 @@ const path = require('path');
5
5
 
6
6
  /**
7
7
  * 确保fnva二进制文件有可执行权限
8
- * 这是一个轻量级的postinstall脚本,专门用来解决npm打包时权限丢失的问题
8
+ * 这是一个全面的postinstall脚本,处理本地安装和全局安装的权限问题
9
9
  */
10
10
  function ensureExecutablePermissions() {
11
11
  try {
@@ -13,8 +13,11 @@ function ensureExecutablePermissions() {
13
13
  const projectRoot = path.resolve(scriptDir, '..');
14
14
  const platformsDir = path.join(projectRoot, 'platforms');
15
15
 
16
+ console.log('🔧 Ensuring fnva binary permissions...');
17
+
16
18
  // 如果没有platforms目录,说明是开发模式,不需要处理
17
19
  if (!fs.existsSync(platformsDir)) {
20
+ console.log('ℹ️ No platforms directory found, skipping permission check');
18
21
  return;
19
22
  }
20
23
 
@@ -33,25 +36,85 @@ function ensureExecutablePermissions() {
33
36
  const stats = fs.statSync(binaryPath);
34
37
  const hasExecPermission = (stats.mode & 0o111) !== 0;
35
38
 
39
+ console.log(`📍 Checking binary: ${binaryPath}`);
40
+ console.log(` Current permissions: ${(stats.mode & 0o777).toString(8)}`);
41
+
36
42
  if (!hasExecPermission) {
43
+ console.log(`🔧 Setting executable permissions...`);
37
44
  fs.chmodSync(binaryPath, 0o755); // rwxr-xr-x
38
- // 只在实际修复了权限时才输出消息,避免在正常安装时产生噪音
39
- if (process.env.DEBUG || process.env.NPM_DEBUG) {
40
- console.log(`🔧 Fixed executable permissions for fnva binary`);
45
+
46
+ // 验证权限设置成功
47
+ const newStats = fs.statSync(binaryPath);
48
+ const newHasExecPermission = (newStats.mode & 0o111) !== 0;
49
+
50
+ if (newHasExecPermission) {
51
+ console.log(`✅ Successfully set executable permissions (${platformDir})`);
52
+ } else {
53
+ console.log(`❌ Failed to set executable permissions (${platformDir})`);
54
+ console.log(` New permissions: ${(newStats.mode & 0o777).toString(8)}`);
55
+ console.log(` Manual fix may be required: chmod +x "${binaryPath}"`);
56
+ }
57
+ } else {
58
+ console.log(`✅ fnva binary already has executable permissions (${platformDir})`);
59
+ }
60
+
61
+ // 尝试测试二进制文件是否可以执行(简单测试)
62
+ try {
63
+ const { spawnSync } = require('child_process');
64
+ const testResult = spawnSync(binaryPath, ['--version'], {
65
+ encoding: 'utf8',
66
+ timeout: 3000,
67
+ stdio: 'pipe'
68
+ });
69
+
70
+ if (testResult.status === 0 || testResult.status === 1) { // status 1 可能是正常的错误状态
71
+ console.log(`✅ fnva binary is executable and responding`);
72
+ } else if (testResult.error && testResult.error.code === 'EACCES') {
73
+ console.log(`❌ fnva binary still has permission issues`);
74
+ console.log(` Manual fix required: chmod +x "${binaryPath}"`);
41
75
  }
76
+ } catch (testError) {
77
+ // 测试失败不算严重错误,可能是因为二进制文件本身有问题
42
78
  }
79
+
43
80
  } catch (error) {
44
- // 静默处理错误,不干扰正常安装流程
45
- if (process.env.DEBUG || process.env.NPM_DEBUG) {
46
- console.warn(`⚠️ Could not fix binary permissions: ${error.message}`);
81
+ console.warn(`⚠️ Could not fix binary permissions: ${error.message}`);
82
+ console.log(` Manual fix required: chmod +x "${binaryPath}"`);
83
+ }
84
+ } else if (platform === 'win32') {
85
+ console.log(`ℹ️ Windows platform detected, skipping permission check`);
86
+ } else {
87
+ console.log(`❌ Binary not found: ${binaryPath}`);
88
+ console.log(` This might indicate an incomplete installation`);
89
+ }
90
+
91
+ // 额外检查:如果是全局安装,也检查全局路径中的fnva
92
+ if (process.env.npm_config_global === 'true') {
93
+ try {
94
+ const { execSync } = require('child_process');
95
+ const globalFnvaPath = execSync('which fnva', { encoding: 'utf8' }).trim();
96
+
97
+ if (globalFnvaPath && fs.existsSync(globalFnvaPath)) {
98
+ console.log(`📍 Checking globally installed binary: ${globalFnvaPath}`);
99
+
100
+ const globalStats = fs.statSync(globalFnvaPath);
101
+ const globalHasExecPermission = (globalStats.mode & 0o111) !== 0;
102
+
103
+ if (!globalHasExecPermission) {
104
+ console.log(`🔧 Global fnva binary lacks executable permissions`);
105
+ console.log(` Please run: sudo chmod +x "${globalFnvaPath}"`);
106
+ } else {
107
+ console.log(`✅ Global fnva binary has correct permissions`);
108
+ }
47
109
  }
110
+ } catch (globalError) {
111
+ // 无法检查全局安装,不视为错误
112
+ console.log(`ℹ️ Could not verify global installation`);
48
113
  }
49
114
  }
115
+
50
116
  } catch (error) {
51
- // 静默处理错误,不干扰正常安装流程
52
- if (process.env.DEBUG || process.env.NPM_DEBUG) {
53
- console.warn(`⚠️ Permission check failed: ${error.message}`);
54
- }
117
+ console.warn(`⚠️ Permission check failed: ${error.message}`);
55
118
  }
56
119
  }
57
120
 
@@ -0,0 +1,103 @@
1
+ #!/bin/bash
2
+
3
+ # fnva权限修复脚本 - 临时解决方案
4
+ # 适用于Mac/Linux系统的全局安装权限修复
5
+
6
+ set -e
7
+
8
+ echo "🔧 fnva权限修复工具"
9
+ echo "=================="
10
+
11
+ # 检查fnva是否已安装
12
+ if ! command -v fnva &> /dev/null; then
13
+ echo "❌ fnva未找到,请先安装: npm install -g fnva"
14
+ exit 1
15
+ fi
16
+
17
+ # 获取fnva路径
18
+ FNVA_PATH=$(which fnva)
19
+ echo "📍 找到fnva: $FNVA_PATH"
20
+
21
+ # 检查权限
22
+ if [ -x "$FNVA_PATH" ]; then
23
+ echo "✅ fnva已有可执行权限"
24
+ echo "🧪 测试fnva是否正常工作..."
25
+ if fnva --version &> /dev/null || [ $? -eq 1 ]; then
26
+ echo "✅ fnva正常工作!"
27
+ exit 0
28
+ else
29
+ echo "⚠️ fnva有权限但执行仍有问题"
30
+ fi
31
+ else
32
+ echo "❌ fnva缺少可执行权限"
33
+ fi
34
+
35
+ # 尝试修复权限
36
+ echo "🔧 修复fnva权限..."
37
+ if sudo chmod +x "$FNVA_PATH"; then
38
+ echo "✅ 权限修复成功"
39
+
40
+ # 验证修复结果
41
+ echo "🧪 验证fnva是否正常工作..."
42
+ if fnva --version &> /dev/null || [ $? -eq 1 ]; then
43
+ echo "🎉 fnva权限修复完成!现在可以使用fnva了"
44
+ exit 0
45
+ else
46
+ echo "⚠️ 权限已修复但执行仍有问题"
47
+ fi
48
+ else
49
+ echo "❌ 权限修复失败"
50
+ fi
51
+
52
+ # 如果上述方法失败,尝试其他方法
53
+ echo ""
54
+ echo "🔄 尝试其他修复方法..."
55
+
56
+ # 方法1: 查找所有fnva二进制文件
57
+ echo "🔍 查找所有fnva二进制文件..."
58
+ FNVA_FILES=$(find /usr/local /opt /home -name "fnva" -type f 2>/dev/null || true)
59
+
60
+ if [ -n "$FNVA_FILES" ]; then
61
+ echo "📁 找到以下fnva文件:"
62
+ echo "$FNVA_FILES"
63
+ echo ""
64
+
65
+ echo "🔧 修复所有fnva文件的权限..."
66
+ echo "$FNVA_FILES" | while read -r file; do
67
+ if [ -f "$file" ]; then
68
+ echo " 修复: $file"
69
+ sudo chmod +x "$file"
70
+ fi
71
+ done
72
+ else
73
+ echo "📁 未找到其他fnva文件"
74
+ fi
75
+
76
+ # 方法2: 查找npm全局目录中的fnva
77
+ echo ""
78
+ echo "🔍 检查npm全局安装目录..."
79
+ NPM_GLOBAL_ROOT=$(npm root -g 2>/dev/null || echo "")
80
+ if [ -n "$NPM_GLOBAL_ROOT" ]; then
81
+ FNVA_MODULE_PATH="$NPM_GLOBAL_ROOT/fnva"
82
+ if [ -d "$FNVA_MODULE_PATH" ]; then
83
+ echo "📁 找到fnva模块: $FNVA_MODULE_PATH"
84
+ echo "🔧 修复模块中的二进制文件权限..."
85
+
86
+ # 查找模块中的所有fnva文件
87
+ find "$FNVA_MODULE_PATH" -name "fnva" -type f -exec sudo chmod +x {} \; 2>/dev/null || true
88
+ fi
89
+ fi
90
+
91
+ # 最终测试
92
+ echo ""
93
+ echo "🧪 最终测试..."
94
+ if fnva --version &> /dev/null || [ $? -eq 1 ]; then
95
+ echo "🎉 修复成功!fnva现在可以正常使用"
96
+ exit 0
97
+ else
98
+ echo "❌ 修复失败,请尝试以下方法:"
99
+ echo " 1. 重新安装: npm uninstall -g fnva && npm install -g fnva --force"
100
+ echo " 2. 手动找到fnva文件并修复权限"
101
+ echo " 3. 使用 FNVA_AUTO_MODE=1 fnva list 使用Node.js模式"
102
+ exit 1
103
+ fi