fnva 0.0.35 → 0.0.37

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Protagonistss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,518 +1,38 @@
1
1
  # fnva - Fast Environment Version Alter
2
2
 
3
- 跨平台环境管理工具,支持 Java、LLM Claude Code 环境,具有默认环境设置和自动加载功能。
3
+ [![npm version](https://img.shields.io/npm/v/fnva)](https://www.npmjs.com/package/fnva) [![crates.io](https://img.shields.io/crates/v/fnva)](https://crates.io/crates/fnva) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4
4
 
5
- ## 功能特性
5
+ [中文文档](README_zh.md) · [Full English](README_en.md) · [Docs](docs/)
6
6
 
7
- - **Java 环境管理**:快速切换不同版本的 JDK
8
- - ✅ **Claude Code (CC) 环境管理**:专门为 Claude Code 设计的环境切换
9
- - ✅ **默认环境支持**:支持设置默认环境
10
- - ✅ **自动加载**:新 Shell 会话自动加载默认环境
11
- - ✅ **智能扫描**:高效扫描系统 Java 安装,支持自定义路径
12
- - ✅ **跨平台支持**:Windows、macOS、Linux
13
- - ✅ **多 Shell 支持**:bash、zsh、fish、PowerShell、CMD
14
- - ✅ **配置化扫描**:支持配置文件和环境变量自定义扫描路径
15
- - ✅ **高效去重**:智能去除重复的环境条目
7
+ Cross-platform environment switcher for Java, Claude Code (CC), and LLM setups. Rust single binary with fast startup and zero runtime dependencies.
16
8
 
17
- ## 安装
9
+ ## Install
18
10
 
19
- ### 方式一:通过 npm 安装(推荐)
11
+ - npm: `npm install -g fnva`
12
+ - Cargo: `cargo install fnva`
13
+ - Binary: download from [Releases](https://github.com/Protagonistss/fnva/releases) and add to `PATH`.
20
14
 
21
- ```bash
22
- # 全局安装
23
- npm install -g fnva
15
+ ## Quick start
24
16
 
25
- # 使用 yarn
26
- yarn global add fnva
17
+ - Init shell (Bash/Zsh): `eval "$(fnva env env --shell bash)"`
18
+ PowerShell: `fnva env env --shell powershell | Out-String | Invoke-Expression`
19
+ - Scan Java: `fnva java scan`
20
+ - Switch Java for current session: `eval "$(fnva java use jdk-17)"`
21
+ - Switch CC profile: `eval "$(fnva cc use glmcc)"`
27
22
 
28
- # 使用 pnpm
29
- pnpm add -g fnva
23
+ ## What it does
30
24
 
31
- function fnva {
32
- 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")) {
33
- $tempFile = "$env:TEMP\fnva_script_$(Get-Random).ps1"
25
+ - Manages multiple Java, CC, and generic LLM configurations.
26
+ - Generates shell snippets to activate environments per session or by default.
27
+ - Stores config at `~/.fnva/config.toml` (Windows: `%USERPROFILE%\.fnva\config.toml`).
28
+ - Ships as a single binary; no background daemon.
34
29
 
35
- $env:FNVAAUTOMODE = "1"
36
- try {
37
- cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" | Out-File -FilePath $tempFile -Encoding UTF8
38
- & $tempFile
39
- } finally {
40
- $env:FNVAAUTOMODE = ""
41
- Remove-Item $tempFile -ErrorAction SilentlyContinue
42
- }
43
- } else {
44
- $env:FNVAAUTOMODE = "1"
45
- try {
46
- cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args"
47
- } finally {
48
- $env:FNVAAUTOMODE = ""
49
- }
50
- }
51
- }
52
- ```
53
-
54
- ### 方式二:从 Releases 下载二进制文件
55
-
56
- 1. 访问 [GitHub Releases](https://github.com/your-repo/fnva/releases)
57
- 2. 下载对应平台的二进制文件:
58
- - Windows: `fnva-win32-x64.exe`
59
- - macOS: `fnva-darwin-x64` 或 `fnva-darwin-arm64`
60
- - Linux: `fnva-linux-x64`
61
-
62
- 3. 将二进制文件重命名为 `fnva`(Windows 下为 `fnva.exe`)
63
-
64
- 4. 添加到 PATH 环境变量(详见下面的配置步骤)
65
-
66
- ### 方式三:从源码构建(开发者)
67
-
68
- **前置要求:**
69
- - **Rust** 1.70+
70
- - **系统依赖**:
71
- - Linux: `pkg-config`, `libssl-dev`, `build-essential`
72
- - macOS: Xcode Command Line Tools
73
- - Windows: Microsoft Visual Studio C++ Build Tools
74
-
75
- ```bash
76
- # 克隆仓库
77
- git clone git@github.com:Protagonistss/fnva.git
78
- cd fnva
79
-
80
- # 构建
81
- cargo build --release
82
-
83
- # 二进制文件位置:
84
- # Windows: target\release\fnva.exe
85
- # macOS/Linux: target/release/fnva
86
- ```
87
-
88
- ### 安装后配置
89
-
90
- #### 1. 验证安装
91
-
92
- ```bash
93
- fnva --version
94
- ```
95
-
96
- #### 2. Shell 集成
97
-
98
- 为了获得最佳体验,需要配置 Shell 集成。这会让 fnva 在新的 Shell 会话中自动加载环境。
99
-
100
- **PowerShell(推荐):**
101
- ```powershell
102
- # 添加到 PowerShell Profile
103
- fnva env env --shell powershell | Out-String | Invoke-Expression
104
-
105
- # 或手动添加到 $PROFILE
106
- echo 'fnva env env --shell powershell | Out-String | Invoke-Expression' >> $PROFILE
107
- ```
108
-
109
- **Bash/Zsh:**
110
- ```bash
111
- # 添加到 ~/.bashrc 或 ~/.zshrc
112
- echo 'eval "$(fnva env env --shell bash)"' >> ~/.bashrc
113
- # 或
114
- echo 'eval "$(fnva env env --shell zsh)"' >> ~/.zshrc
115
-
116
- # 重新加载配置
117
- source ~/.bashrc # 或 source ~/.zshrc
118
- ```
119
-
120
- **Fish:**
121
- ```fish
122
- # 添加到 ~/.config/fish/config.fish
123
- echo 'fnva env env --shell fish | source' >> ~/.config/fish/config.fish
124
- ```
125
-
126
- #### 3. 配置文件
127
-
128
- 首次运行时,fnva 会自动创建配置文件:
129
-
130
- ```bash
131
- # 配置文件位置
132
- Linux/macOS: ~/.fnva/config.toml
133
- Windows: %USERPROFILE%\.fnva\config.toml
134
- ```
135
-
136
- #### 4. 测试安装
137
-
138
- ```bash
139
- # 列出所有环境类型
140
- fnva env list-types
141
-
142
- # 查看 Java 环境
143
- fnva java list
144
-
145
- # 查看 CC 环境
146
- fnva cc list
147
-
148
- # 查看 LLM 环境
149
- fnva llm list
150
- ```
30
+ ## Build/test locally
151
31
 
152
- ## 使用方法
153
-
154
- ### Java 环境管理
155
-
156
- #### 列出所有 Java 环境
157
-
158
- ```bash
159
- fnva java list
160
- ```
161
-
162
- #### 添加 Java 环境
163
-
164
- ```bash
165
- fnva java add --name jdk-17 --home /usr/lib/jvm/java-17-openjdk --description "OpenJDK 17"
166
- ```
167
-
168
- #### 切换到 Java 环境
169
-
170
- ```bash
171
- # Bash / Zsh
172
- eval "$(fnva java use jdk-17)"
173
-
174
- # Fish
175
- fnva java use jdk-17 --shell fish | source
176
-
177
- # PowerShell
178
- fnva java use jdk-17 --shell powershell | Invoke-Expression
179
-
180
- # CMD
181
- fnva java use jdk-17 --shell cmd > %TEMP%\fnva_use.cmd && call %TEMP%\fnva_use.cmd
182
- ```
183
-
184
- #### 设置默认 Java 环境
185
-
186
- ```bash
187
- # 设置默认环境
188
- fnva java default jdk-21
189
-
190
- # 查看当前默认环境
191
- fnva java default
192
-
193
- # 清除默认设置
194
- fnva java default --unset
195
- ```
196
-
197
- #### 查看当前激活的环境
198
-
199
- ```bash
200
- fnva java current
201
- ```
202
-
203
- #### 删除 Java 环境
204
-
205
- ```bash
206
- fnva java remove jdk-17
207
32
  ```
208
-
209
- #### 扫描系统中的 Java 安装
210
-
211
- ```bash
212
- fnva java scan
213
- ```
214
-
215
- **扫描功能详解:**
216
-
217
- **基础扫描:**
218
- - 自动检测系统标准 Java 安装路径
219
- - 扫描用户主目录下的 `.fnva/java-packages`
220
- - 检查 PATH 环境变量中的 Java 可执行文件
221
-
222
- **自定义扫描路径:**
223
-
224
- 1. **配置文件方式**(推荐):
225
- ```toml
226
- # ~/.fnva/config.toml
227
- custom_java_scan_paths = [
228
- "D:\\tools\\java",
229
- "/opt/custom/java",
230
- "/home/user/my-jdks"
231
- ]
232
- ```
233
-
234
- 2. **环境变量方式**:
235
- ```bash
236
- # 临时添加扫描路径
237
- export FNVA_SCAN_PATHS="/path/to/jdk1:/path/to/jdk2"
238
- fnva java scan
239
-
240
- # Windows
241
- set FNVA_SCAN_PATHS=D:\tools\java;E:\other\java
242
- fnva java scan
243
- ```
244
-
245
- **扫描性能:**
246
- - 🔒 **安全**:只扫描指定路径,不进行全盘搜索
247
- - ⚡ **快速**:使用高效的去重算法,避免重复处理
248
- - 🎯 **精确**:智能识别 Java 安装,过滤无效路径
249
-
250
- **支持的扫描路径:**
251
- - Windows:`C:\Program Files\Java`、`C:\Program Files\Eclipse Adoptium` 等
252
- - macOS:`/Library/Java/JavaVirtualMachines`、`/opt/homebrew/Caskroom` 等
253
- - Linux:`/usr/lib/jvm`、`/opt/java`、`/usr/local/java` 等
254
-
255
- ### LLM 环境管理
256
-
257
- #### 列出所有 LLM 环境
258
-
259
- ```bash
260
- fnva llm list
261
- ```
262
-
263
- #### 查看支持的提供商
264
-
265
- ```bash
266
- fnva llm providers
267
- ```
268
-
269
- 支持的提供商:
270
- - `openai` - OpenAI API
271
- - `anthropic` - Anthropic Claude API
272
- - `azure-openai` - Azure OpenAI
273
- - `google-gemini` - Google Gemini
274
- - `cohere` - Cohere API
275
- - `mistral` - Mistral AI
276
- - `ollama` - Ollama (本地部署)
277
-
278
- #### 添加 LLM 环境
279
-
280
- ```bash
281
- # OpenAI
282
- fnva llm add \
283
- --name openai-dev \
284
- --provider openai \
285
- --api-key "${OPENAI_API_KEY}" \
286
- --model gpt-4 \
287
- --temperature 0.7
288
-
289
- # Anthropic
290
- fnva llm add \
291
- --name anthropic-prod \
292
- --provider anthropic \
293
- --api-key "${ANTHROPIC_API_KEY}" \
294
- --model claude-3-opus-20240229
295
-
296
- # Ollama (本地)
297
- fnva llm add \
298
- --name ollama-local \
299
- --provider ollama \
300
- --base-url http://localhost:11434 \
301
- --model llama2
302
- ```
303
-
304
- #### 切换到 LLM 环境
305
-
306
- ```bash
307
- # 自动检测 shell
308
- eval "$(fnva llm use openai-dev)"
309
-
310
- # 指定 shell (PowerShell)
311
- fnva llm use openai-dev --shell powershell | Invoke-Expression
312
- ```
313
-
314
- #### 删除 LLM 环境
315
-
316
- ```bash
317
- fnva llm remove openai-dev
318
- ```
319
-
320
- ### Claude Code (CC) 环境管理
321
-
322
- 专门为 Claude Code 设计的环境管理功能,支持多种 Claude Code 兼容服务的环境切换。
323
-
324
- #### 列出所有 CC 环境
325
-
326
- ```bash
327
- fnva cc list
328
- ```
329
-
330
- #### 添加 CC 环境
331
-
332
- ```bash
333
- # 方法一:使用 JSON 配置
334
- fnva cc add glmcc '{
335
- "provider": "anthropic",
336
- "api_key": "your-api-key",
337
- "base_url": "https://open.bigmodel.cn/api/anthropic",
338
- "model": "glm-4.6",
339
- "description": "GLM-4.6 Claude Code 环境"
340
- }'
341
-
342
- # 方法二:直接编辑配置文件
343
- # 编辑 ~/.fnva/config.toml,添加:
344
- # [[cc_environments]]
345
- # name = "glmcc"
346
- # provider = "anthropic"
347
- # api_key = "your-api-key"
348
- # base_url = "https://open.bigmodel.cn/api/anthropic"
349
- # model = "glm-4.6"
350
- # description = "GLM-4.6 Claude Code 环境"
351
- ```
352
-
353
- #### 切换到 CC 环境
354
-
355
- ```bash
356
- # PowerShell(推荐)
357
- fnva cc use glmcc --shell powershell | Invoke-Expression
358
-
359
- # Bash/Zsh
360
- eval "$(fnva cc use glmcc)"
361
-
362
- # Fish
363
- fnva cc use glmcc --shell fish | source
364
-
365
- # CMD
366
- fnva cc use glmcc --shell cmd > %TEMP%\fnva_cc.cmd && call %TEMP%\fnva_cc.cmd
367
- ```
368
-
369
- #### Manage default CC environment
370
-
371
- ```bash
372
- # Set default CC environment
373
- fnva cc default glmcc
374
-
375
- # Show current default CC environment
376
- fnva cc default
377
-
378
- # Unset default CC environment
379
- fnva cc default --unset
380
- ```
381
-
382
- #### 查看当前激活的 CC 环境
383
-
384
- ```bash
385
- fnva cc current
386
- ```
387
-
388
- #### 删除 CC 环境
389
-
390
- ```bash
391
- fnva cc remove glmcc
392
- ```
393
-
394
- #### 预配置的 CC 环境
395
-
396
- fnva 提供了一些常用的 CC 环境配置:
397
-
398
- - **glmcc**: GLM-4.6 智谱 AI Claude Code 兼容服务
399
- - **anycc**: AnyCC 通用 Claude Code 代理服务
400
- - **kimicc**: Kimi AI Claude Code 兼容服务
401
-
402
- #### 环境变量说明
403
-
404
- CC 环境切换会设置以下环境变量:
405
-
406
- - `ANTHROPIC_AUTH_TOKEN`: Claude Code 认证令牌
407
- - `ANTHROPIC_BASE_URL`: Claude Code API 基础 URL
408
- - `ANTHROPIC_DEFAULT_SONNET_MODEL`: 默认使用的模型
409
- - `API_TIMEOUT_MS`: API 请求超时时间
410
- - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`: 禁用非必要网络流量
411
-
412
- #### 配置示例
413
-
414
- ```toml
415
- [[cc_environments]]
416
- name = "glmcc"
417
- provider = "anthropic"
418
- api_key = "your-glm-api-key"
419
- base_url = "https://open.bigmodel.cn/api/anthropic"
420
- model = "glm-4.6"
421
- description = "GLM-4.6 Claude Code 环境"
422
-
423
- [[cc_environments]]
424
- name = "anycc"
425
- provider = "anthropic"
426
- api_key = "your-anycc-api-key"
427
- base_url = "https://your-anycc-proxy.com"
428
- model = "claude-sonnet-4-5"
429
- description = "AnyCC 代理服务"
430
-
431
- [[cc_environments]]
432
- name = "kimicc"
433
- provider = "anthropic"
434
- api_key = "your-kimi-api-key"
435
- base_url = "https://api.moonshot.cn/anthropic"
436
- model = "kimi-k2-turbo-preview"
437
- description = "Kimi AI Claude Code 环境"
438
- ```
439
-
440
- ## 配置文件
441
-
442
- 配置文件位置:
443
- - **Linux/macOS**: `~/.fnva/config.toml`
444
- - **Windows**: `%USERPROFILE%\.fnva\config.toml`
445
-
446
- 首次运行时会自动创建配置文件。
447
-
448
- ### 配置示例
449
-
450
- 查看 `config/config.toml.example` 获取完整配置示例。
451
-
452
- ```toml
453
- # Java 环境配置
454
- [[java_environments]]
455
- name = "jdk-17"
456
- java_home = "/usr/lib/jvm/java-17-openjdk"
457
- description = "OpenJDK 17"
458
-
459
- # LLM 环境配置
460
- [[llm_environments]]
461
- name = "openai-dev"
462
- provider = "openai"
463
- api_key = "${OPENAI_API_KEY}"
464
- base_url = "https://api.openai.com/v1"
465
- model = "gpt-4"
466
- temperature = 0.7
467
- max_tokens = 2000
468
- description = "OpenAI 开发环境"
469
-
470
- # Claude Code (CC) 环境配置
471
- [[cc_environments]]
472
- name = "glmcc"
473
- provider = "anthropic"
474
- api_key = "${GLM_API_KEY}"
475
- base_url = "https://open.bigmodel.cn/api/anthropic"
476
- model = "glm-4.6"
477
- description = "GLM-4.6 Claude Code 环境"
478
-
479
- [[cc_environments]]
480
- name = "anycc"
481
- provider = "anthropic"
482
- api_key = "sk-your-api-key"
483
- base_url = "https://your-proxy.com"
484
- model = "claude-sonnet-4-5"
485
- description = "AnyCC 代理服务"
486
-
487
- # 仓库配置
488
- [repositories]
489
- java = [
490
- "https://mirrors.tuna.tsinghua.edu.cn/Adoptium",
491
- "https://api.adoptium.net/v3"
492
- ]
493
- maven = [
494
- "https://maven.aliyun.com/repository/public",
495
- "https://search.maven.org/solrsearch/select"
496
- ]
33
+ cargo fmt && cargo clippy --all-targets -- -D warnings
34
+ cargo test
35
+ cargo build --release
497
36
  ```
498
37
 
499
- > Java downloads default to the Tsinghua Adoptium mirror (https://mirrors.tuna.tsinghua.edu.cn/Adoptium). For fully stable setups, manually maintain versions in ~/.fnva/config.toml [[java_environments]] and JAVA_HOME.
500
-
501
- ### 常用命令速查
502
-
503
- | 命令 | 功能 | 示例 |
504
- |------|------|------|
505
- | `fnva java list` | 列出 Java 环境 | `fnva java list` |
506
- | `fnva java use <name>` | 切换 Java 环境 | `fnva java use jdk21` |
507
- | `fnva java default <name>` | 设置默认 Java | `fnva java default jdk21` |
508
- | `fnva cc list` | 列出 CC 环境 | `fnva cc list` |
509
- | `fnva cc use <name>` | 切换 CC 环境 | `fnva cc use glmcc` |
510
- | `fnva cc default <name>` | 设置默认 CC 环境 | `fnva cc default glmcc` |
511
- | `fnva llm list` | 列出 LLM 环境 | `fnva llm list` |
512
- | `fnva llm use <name>` | 切换 LLM 环境 | `fnva llm use openai-dev` |
513
- | `fnva env switch <type> <name>` | 通用切换 | `fnva env switch java jdk17` |
514
-
515
- ## 许可证
516
-
517
- MIT License
518
-
38
+ For platform bundles: `npm run build:platforms`
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
- const npmBinaryPath = platformBinaryPath(platform);
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 || args[0] === '--help' || args[0] === '-h') {
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('⚠️ 当前运行在 Node.js 降级模式,功能有限');
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(`❌ Command '${args[0]}' requires native binary mode`);
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('Error: fnva native binary not found.');
390
+ console.error('Error: fnva native binary not found.');
480
391
  console.error('');
481
-
482
- if (showDebug) {
483
- console.error('🔍 Debug information is shown above');
484
- console.error('');
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.35",
3
+ "version": "0.0.37",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
Binary file
Binary file
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
- try { cmd.exe /c "fnva $args" } finally { }
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
- "$__fnva_bin" "$@" > "$temp_file"
99
+ FNVA_AUTO_MODE=1 "$__fnva_bin" "$@" > "$temp_file"
97
100
  source "$temp_file"
98
101
  rm -f "$temp_file"
99
102
  else
100
- "$__fnva_bin" "$@"
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 "$__fnva_bin" $argv > $temp_file
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 "$__fnva_bin" $argv
126
+ env FNVA_AUTO_MODE=1 "$__fnva_bin" $argv
124
127
  end
125
128
  end
126
129
  `;
Binary file