fnva 0.0.41 → 0.0.42
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/bin/fnva.js +20 -115
- package/package.json +2 -2
- package/platforms/darwin-arm64/fnva +0 -0
- package/platforms/darwin-x64/fnva +0 -0
- package/platforms/linux-arm64/fnva +0 -0
- package/platforms/linux-x64/fnva +0 -0
- package/platforms/win32-x64/fnva.exe +0 -0
- package/scripts/install-shell-integration.js +9 -6
- package/scripts/uninstall-shell-integration.js +0 -15
package/bin/fnva.js
CHANGED
|
@@ -44,12 +44,16 @@ function buildBinaryPath() {
|
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// 如果设置了 FNVA_AUTO_MODE,自动使用 Node.js 模式
|
|
48
|
+
if (process.env.FNVA_AUTO_MODE === '1') {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
const platform = resolvePlatform();
|
|
48
53
|
const binaryCandidates = [];
|
|
49
54
|
|
|
50
55
|
// 1. Prebuilt binary shipped with the npm package
|
|
51
|
-
|
|
52
|
-
binaryCandidates.push(npmBinaryPath);
|
|
56
|
+
binaryCandidates.push(platformBinaryPath(platform));
|
|
53
57
|
|
|
54
58
|
// 2. User-provided override via environment variable
|
|
55
59
|
if (process.env.FNVA_NATIVE_PATH) {
|
|
@@ -66,32 +70,12 @@ function buildBinaryPath() {
|
|
|
66
70
|
binaryCandidates.push(path.join(targetDir, 'debug', 'fnva'));
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
// Debug: Show all candidates and their existence
|
|
70
|
-
if (process.env.FNVA_DEBUG === '1') {
|
|
71
|
-
console.log('[DEBUG] Looking for fnva binary...');
|
|
72
|
-
console.log('[DEBUG] Platform:', platform, 'Arch:', resolveArch());
|
|
73
|
-
console.log('[DEBUG] Binary candidates:');
|
|
74
|
-
binaryCandidates.forEach((candidate, index) => {
|
|
75
|
-
const exists = candidate && fs.existsSync(candidate);
|
|
76
|
-
console.log(` ${index + 1}. ${candidate} - ${exists ? 'EXISTS' : 'MISSING'}`);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
73
|
for (const candidate of binaryCandidates) {
|
|
81
74
|
if (candidate && fs.existsSync(candidate)) {
|
|
82
|
-
if (process.env.FNVA_DEBUG === '1') {
|
|
83
|
-
console.log(`[DEBUG] Found binary at: ${candidate}`);
|
|
84
|
-
}
|
|
85
75
|
return candidate;
|
|
86
76
|
}
|
|
87
77
|
}
|
|
88
78
|
|
|
89
|
-
if (process.env.FNVA_DEBUG === '1') {
|
|
90
|
-
console.log('[DEBUG] No binary found, falling back to Node.js mode');
|
|
91
|
-
console.log('[DEBUG] Expected npm package binary path:', npmBinaryPath);
|
|
92
|
-
console.log('[DEBUG] npmBinaryPath exists:', fs.existsSync(npmBinaryPath));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
79
|
return null;
|
|
96
80
|
}
|
|
97
81
|
|
|
@@ -296,20 +280,15 @@ function handleNodeOnlyMode(args) {
|
|
|
296
280
|
const path = require('path');
|
|
297
281
|
const os = require('os');
|
|
298
282
|
|
|
299
|
-
//
|
|
300
|
-
if (args.length === 0
|
|
301
|
-
console.log('fnva - 环境管理工具 (Node.js
|
|
283
|
+
// 简单的命令处理
|
|
284
|
+
if (args.length === 0) {
|
|
285
|
+
console.log('fnva - 环境管理工具 (Node.js 模式)');
|
|
302
286
|
console.log('');
|
|
303
|
-
console.log('
|
|
304
|
-
console.log('');
|
|
305
|
-
console.log('解决方法:');
|
|
306
|
-
console.log('1. 确保 npm 包包含平台二进制文件');
|
|
307
|
-
console.log('2. 重新安装: npm install -g fnva --force');
|
|
308
|
-
console.log('3. 或者直接下载原生二进制文件');
|
|
309
|
-
console.log('');
|
|
310
|
-
console.log('临时可用功能:');
|
|
287
|
+
console.log('支持的命令:');
|
|
311
288
|
console.log(' java list - 列出 Java 环境');
|
|
312
289
|
console.log(' java use <n> - 切换 Java 环境');
|
|
290
|
+
console.log('');
|
|
291
|
+
console.log('注意: Node.js 模式功能有限,建议使用原生二进制版本。');
|
|
313
292
|
return;
|
|
314
293
|
}
|
|
315
294
|
|
|
@@ -389,14 +368,7 @@ function handleNodeOnlyMode(args) {
|
|
|
389
368
|
process.exit(1);
|
|
390
369
|
}
|
|
391
370
|
} else {
|
|
392
|
-
console.error(
|
|
393
|
-
console.error('');
|
|
394
|
-
console.error('当前运行在 Node.js 降级模式,不支持此命令');
|
|
395
|
-
console.error('');
|
|
396
|
-
console.error('解决方案:');
|
|
397
|
-
console.error('1. 重新安装 npm 包: npm install -g fnva --force');
|
|
398
|
-
console.error('2. 从 GitHub Release 下载原生二进制文件');
|
|
399
|
-
console.error('3. 或者设置 FNVA_SKIP_NATIVE=1 强制使用此模式(功能受限)');
|
|
371
|
+
console.error(`Command '${args[0]}' not supported in Node.js mode`);
|
|
400
372
|
process.exit(1);
|
|
401
373
|
}
|
|
402
374
|
}
|
|
@@ -405,90 +377,23 @@ function run() {
|
|
|
405
377
|
// 设置Windows控制台编码
|
|
406
378
|
EncodingUtils.setWindowsConsoleEncoding();
|
|
407
379
|
|
|
408
|
-
// 强制显示调试信息
|
|
409
|
-
const showDebug = process.env.FNVA_DEBUG === '1' || process.argv.includes('--debug');
|
|
410
|
-
|
|
411
|
-
if (showDebug) {
|
|
412
|
-
console.log('=== FNVA DEBUG INFORMATION ===');
|
|
413
|
-
console.log('Node.js version:', process.version);
|
|
414
|
-
console.log('Platform:', process.platform);
|
|
415
|
-
console.log('Architecture:', process.arch);
|
|
416
|
-
console.log('Node binary:', process.execPath);
|
|
417
|
-
console.log('Script directory:', __dirname);
|
|
418
|
-
console.log('Working directory:', process.cwd());
|
|
419
|
-
console.log('Environment variables:');
|
|
420
|
-
console.log(' FNVA_DEBUG:', process.env.FNVA_DEBUG);
|
|
421
|
-
console.log(' FNVA_SKIP_NATIVE:', process.env.FNVA_SKIP_NATIVE);
|
|
422
|
-
console.log('Command line args:', process.argv);
|
|
423
|
-
console.log('');
|
|
424
|
-
}
|
|
425
|
-
|
|
426
380
|
const binaryPath = buildBinaryPath();
|
|
427
381
|
|
|
428
|
-
if (showDebug) {
|
|
429
|
-
console.log('=== BINARY SEARCH RESULTS ===');
|
|
430
|
-
console.log('Binary path found:', binaryPath);
|
|
431
|
-
|
|
432
|
-
// 手动检查所有可能的路径
|
|
433
|
-
const fs = require('fs');
|
|
434
|
-
const path = require('path');
|
|
435
|
-
|
|
436
|
-
const scriptDir = __dirname;
|
|
437
|
-
const projectRoot = path.resolve(scriptDir, '..');
|
|
438
|
-
const platform = process.platform;
|
|
439
|
-
const arch = process.arch;
|
|
440
|
-
const platformDir = `${platform}-${arch}`;
|
|
441
|
-
const binaryName = platform === 'win32' ? 'fnva.exe' : 'fnva';
|
|
442
|
-
const expectedPath = path.join(projectRoot, 'platforms', platformDir, binaryName);
|
|
443
|
-
|
|
444
|
-
console.log('Expected binary path:', expectedPath);
|
|
445
|
-
console.log('Expected path exists:', fs.existsSync(expectedPath));
|
|
446
|
-
|
|
447
|
-
// 检查platforms目录结构
|
|
448
|
-
console.log('');
|
|
449
|
-
console.log('=== PLATFORMS DIRECTORY ===');
|
|
450
|
-
const platformsDir = path.join(projectRoot, 'platforms');
|
|
451
|
-
if (fs.existsSync(platformsDir)) {
|
|
452
|
-
const platforms = fs.readdirSync(platformsDir, { withFileTypes: true });
|
|
453
|
-
platforms.forEach(item => {
|
|
454
|
-
if (item.isDirectory()) {
|
|
455
|
-
const platformPath = path.join(platformsDir, item.name);
|
|
456
|
-
const files = fs.readdirSync(platformPath);
|
|
457
|
-
console.log(`platforms/${item.name}/:`, files);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
} else {
|
|
461
|
-
console.log('platforms directory does not exist');
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
console.log('=== END DEBUG ===');
|
|
465
|
-
console.log('');
|
|
466
|
-
}
|
|
467
|
-
|
|
468
382
|
if (!binaryPath) {
|
|
469
|
-
if (process.env.FNVA_SKIP_NATIVE === '1') {
|
|
470
|
-
if (showDebug) {
|
|
471
|
-
console.log('Falling back to Node.js mode (FNVA_SKIP_NATIVE set)');
|
|
472
|
-
}
|
|
383
|
+
if (process.env.FNVA_SKIP_NATIVE === '1' || process.env.FNVA_AUTO_MODE === '1') {
|
|
473
384
|
// 纯 Node.js 模式 - 实现基本的环境切换功能
|
|
474
385
|
const args = process.argv.slice(2);
|
|
475
386
|
handleNodeOnlyMode(args);
|
|
476
387
|
return;
|
|
477
388
|
}
|
|
478
389
|
|
|
479
|
-
console.error('
|
|
390
|
+
console.error('Error: fnva native binary not found.');
|
|
480
391
|
console.error('');
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
console.error("💡 Solutions:");
|
|
488
|
-
console.error(" 1) Reinstall npm package: npm install -g fnva --force");
|
|
489
|
-
console.error(" 2) Download binary from GitHub Release");
|
|
490
|
-
console.error(" 3) Set FNVA_SKIP_NATIVE=1 to use Node.js mode (limited functionality)");
|
|
491
|
-
console.error(" 4) Set FNVA_DEBUG=1 to show debug information");
|
|
392
|
+
console.error("Please either:");
|
|
393
|
+
console.error(" 1) Run 'npm run build' (or 'npm run build:all') to produce platform binaries,");
|
|
394
|
+
console.error(" 2) Install a release package that includes the platforms directory, or");
|
|
395
|
+
console.error(" 3) Set FNVA_NATIVE_PATH to the full path of an existing fnva executable.");
|
|
396
|
+
console.error(" 4) Set FNVA_SKIP_NATIVE=1 to use Node.js mode (limited functionality).");
|
|
492
397
|
process.exit(1);
|
|
493
398
|
}
|
|
494
399
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnva",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
|
|
5
5
|
"author": "protagonistss",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build:platforms:sh": "bash scripts/build-platforms.sh",
|
|
18
18
|
"build:all": "scripts/build-all.sh",
|
|
19
19
|
"check-permissions": "node scripts/check-permissions.js",
|
|
20
|
-
"postuninstall": "node scripts/uninstall-shell-integration.js"
|
|
20
|
+
"postuninstall": "echo 'Uninstalling fnva shell integration...' && node scripts/uninstall-shell-integration.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"bin/",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/platforms/linux-x64/fnva
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -44,8 +44,9 @@ function fnva {
|
|
|
44
44
|
if ($args.Count -ge 2 -and ($args[0] -eq "java" -or $args[0] -eq "llm" -or $args[0] -eq "cc") -and ($args[1] -eq "use")) {
|
|
45
45
|
$tempFile = Join-Path $env:TEMP ("fnva_script_" + (Get-Random) + ".ps1")
|
|
46
46
|
|
|
47
|
+
$env:FNVAAUTOMODE = "1"
|
|
47
48
|
try {
|
|
48
|
-
$output = cmd.exe /c "fnva $args" 2>&1
|
|
49
|
+
$output = cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" 2>&1
|
|
49
50
|
|
|
50
51
|
if ($output -match '\\$env:' -or $output -match 'Write-Host') {
|
|
51
52
|
$output | Out-File -FilePath $tempFile -Encoding UTF8
|
|
@@ -54,10 +55,12 @@ function fnva {
|
|
|
54
55
|
$output
|
|
55
56
|
}
|
|
56
57
|
} finally {
|
|
58
|
+
$env:FNVAAUTOMODE = ""
|
|
57
59
|
if (Test-Path $tempFile) { Remove-Item $tempFile -ErrorAction SilentlyContinue }
|
|
58
60
|
}
|
|
59
61
|
} else {
|
|
60
|
-
|
|
62
|
+
$env:FNVAAUTOMODE = "1"
|
|
63
|
+
try { cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" } finally { $env:FNVAAUTOMODE = "" }
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
`;
|
|
@@ -93,11 +96,11 @@ fnva() {
|
|
|
93
96
|
temp_file="$(mktemp)"
|
|
94
97
|
chmod +x "$temp_file"
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
FNVA_AUTO_MODE=1 "$__fnva_bin" "$@" > "$temp_file"
|
|
97
100
|
source "$temp_file"
|
|
98
101
|
rm -f "$temp_file"
|
|
99
102
|
else
|
|
100
|
-
|
|
103
|
+
FNVA_AUTO_MODE=1 "$__fnva_bin" "$@"
|
|
101
104
|
fi
|
|
102
105
|
}
|
|
103
106
|
`;
|
|
@@ -116,11 +119,11 @@ function fnva
|
|
|
116
119
|
if test (count $argv) -ge 2; and string match -q -r "^(java|llm|cc)$" $argv[1]; and test $argv[2] = "use"
|
|
117
120
|
set temp_file (mktemp)
|
|
118
121
|
chmod +x $temp_file
|
|
119
|
-
env
|
|
122
|
+
env FNVA_AUTO_MODE=1 "$__fnva_bin" $argv > $temp_file
|
|
120
123
|
source $temp_file
|
|
121
124
|
rm -f $temp_file
|
|
122
125
|
else
|
|
123
|
-
env
|
|
126
|
+
env FNVA_AUTO_MODE=1 "$__fnva_bin" $argv
|
|
124
127
|
end
|
|
125
128
|
end
|
|
126
129
|
`;
|
|
@@ -113,48 +113,33 @@ function removeShellIntegration(configPath, shell) {
|
|
|
113
113
|
|
|
114
114
|
function main() {
|
|
115
115
|
console.log('🧹 fnva shell integration uninstaller');
|
|
116
|
-
console.log('npm install location:', __dirname);
|
|
117
|
-
console.log('Current platform:', process.platform);
|
|
118
|
-
console.log('Detected shell:', process.env.SHELL || 'unknown');
|
|
119
116
|
|
|
120
117
|
const shell = detectShell();
|
|
121
118
|
const paths = getShellConfigPaths(shell);
|
|
122
119
|
|
|
123
|
-
console.log(`Config paths for ${shell}:`, paths);
|
|
124
|
-
|
|
125
120
|
if (!paths.length) {
|
|
126
121
|
console.log(`⚠️ Unsupported shell: ${shell}`);
|
|
127
|
-
console.log('No config files found for this shell');
|
|
128
122
|
return;
|
|
129
123
|
}
|
|
130
124
|
|
|
131
|
-
console.log(`Attempting to clean config files...`);
|
|
132
125
|
const success = removeShellIntegration(null, shell);
|
|
133
126
|
|
|
134
127
|
if (success) {
|
|
135
|
-
console.log('✅ Shell integration successfully removed');
|
|
136
128
|
console.log('🔄 Reload your shell config:');
|
|
137
129
|
switch (shell) {
|
|
138
130
|
case 'powershell':
|
|
139
131
|
console.log(' . $PROFILE');
|
|
140
|
-
console.log(' Or start new PowerShell instance');
|
|
141
132
|
break;
|
|
142
133
|
case 'bash':
|
|
143
134
|
console.log(' source ~/.bashrc');
|
|
144
|
-
console.log(' Or: exec bash');
|
|
145
135
|
break;
|
|
146
136
|
case 'zsh':
|
|
147
137
|
console.log(' source ~/.zshrc');
|
|
148
|
-
console.log(' Or: exec zsh');
|
|
149
138
|
break;
|
|
150
139
|
case 'fish':
|
|
151
140
|
console.log(' source ~/.config/fish/config.fish');
|
|
152
|
-
console.log(' Or: exec fish');
|
|
153
141
|
break;
|
|
154
142
|
}
|
|
155
|
-
} else {
|
|
156
|
-
console.log('⚠️ No fnva shell integration found in any config files');
|
|
157
|
-
console.log(' (This is normal if shell integration was never installed)');
|
|
158
143
|
}
|
|
159
144
|
}
|
|
160
145
|
|