fnva 0.0.50 → 0.0.51

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.ps1 CHANGED
@@ -1,37 +1,31 @@
1
- # fnva - Windows PowerShell 启动脚本
1
+ #!/usr/bin/env pwsh
2
+ # fnva PowerShell wrapper - calls native binary directly
3
+ # PowerShell prefers .ps1 over .cmd, avoiding Object[] output splitting
2
4
 
3
- param(
4
- [Parameter(ValueFromRemainingArguments=$true)]
5
- [string[]]$Arguments
6
- )
7
-
8
- # 检测平台和架构
9
- $os = "win32"
10
- $arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
11
-
12
- # 构建二进制文件路径
13
- $platformDir = "$os-$arch"
14
5
  $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
15
- $binaryPath = Join-Path $scriptDir ".." "platforms" $platformDir "fnva.exe"
6
+ $arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
7
+ $platformDir = "win32-$arch"
16
8
 
17
- # 如果分层结构不存在,尝试扁平结构
18
- if (-not (Test-Path $binaryPath)) {
19
- $binaryPath = Join-Path $scriptDir ".." "platforms" "fnva.exe"
9
+ # Try native binary in npm package
10
+ $binaryPath = Join-Path $scriptDir "..\platforms\$platformDir\fnva.exe"
11
+ if (Test-Path $binaryPath) {
12
+ & $binaryPath @args
13
+ exit $LASTEXITCODE
20
14
  }
21
15
 
22
- # 检查二进制文件是否存在
23
- if (-not (Test-Path $binaryPath)) {
24
- Write-Host "错误: 未找到二进制文件" -ForegroundColor Red
25
- Write-Host "尝试的路径: " -ForegroundColor Yellow
26
- Write-Host " 1. $(Join-Path $scriptDir ".." "platforms" $platformDir "fnva.exe")" -ForegroundColor Yellow
27
- Write-Host " 2. $(Join-Path $scriptDir ".." "platforms" "fnva.exe")" -ForegroundColor Yellow
28
- Write-Host "请运行 'npm run build' 构建二进制文件" -ForegroundColor Yellow
29
- exit 1
16
+ # Fallback: local dev build
17
+ $devPath = Join-Path $scriptDir "..\target\release\fnva.exe"
18
+ if (Test-Path $devPath) {
19
+ & $devPath @args
20
+ exit $LASTEXITCODE
30
21
  }
31
22
 
32
- # 执行二进制文件
33
- & $binaryPath $Arguments
34
-
35
- if ($LASTEXITCODE) {
23
+ # Last resort: node wrapper
24
+ $nodeScript = Join-Path $scriptDir "fnva.js"
25
+ if (Test-Path $nodeScript) {
26
+ & node $nodeScript @args
36
27
  exit $LASTEXITCODE
37
- }
28
+ }
29
+
30
+ Write-Error "fnva: native binary not found. Reinstall with: npm install -g fnva --force"
31
+ exit 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -142,12 +142,46 @@ function promptInstallation() {
142
142
  });
143
143
  }
144
144
 
145
+ function getNpmGlobalBinDir() {
146
+ // Try npm_config_prefix first (set by npm during install)
147
+ if (process.env.npm_config_prefix) {
148
+ return process.env.npm_config_prefix;
149
+ }
150
+ // Fallback: find where fnva.cmd lives
151
+ try {
152
+ const result = spawnSync('npm', ['prefix', '-g'], { encoding: 'utf8', timeout: 10000 });
153
+ if (result.status === 0 && result.stdout.trim()) {
154
+ return result.stdout.trim();
155
+ }
156
+ } catch (_) {}
157
+ // Last resort: derive from node executable path
158
+ return path.dirname(process.execPath);
159
+ }
160
+
161
+ function installPowershellWrapper() {
162
+ if (process.platform !== 'win32') return;
163
+
164
+ const srcPs1 = path.resolve(__dirname, '..', 'bin', 'fnva.ps1');
165
+ if (!fs.existsSync(srcPs1)) return;
166
+
167
+ const npmBinDir = getNpmGlobalBinDir();
168
+ const destPs1 = path.join(npmBinDir, 'fnva.ps1');
169
+
170
+ try {
171
+ fs.copyFileSync(srcPs1, destPs1);
172
+ console.log(`PowerShell wrapper installed: ${destPs1}`);
173
+ } catch (error) {
174
+ console.log(`PowerShell wrapper install skipped: ${error.message}`);
175
+ }
176
+ }
177
+
145
178
  function main() {
146
179
  console.log('fnva shell integration installer');
147
180
  console.log(`Node.js version: ${process.version}`);
148
181
  console.log(`CWD: ${process.cwd()}`);
149
182
 
150
183
  if (process.argv.includes('--auto') || process.argv.includes('--yes')) {
184
+ installPowershellWrapper();
151
185
  const result = installShellIntegration();
152
186
  console.log(`Install result: ${result ? 'success' : 'failed'}`);
153
187
  } else {