fnva 0.0.43 → 0.0.44

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/README.md CHANGED
@@ -14,11 +14,12 @@ Cross-platform environment switcher for Java, Claude Code (CC), and LLM setups.
14
14
 
15
15
  ## Quick start
16
16
 
17
- - Init shell (Bash/Zsh): `eval "$(fnva env env --shell bash)"`
18
- PowerShell: `fnva env env --shell powershell | Out-String | Invoke-Expression`
17
+ - Init shell (Bash/Zsh): `eval "$(fnva env --shell bash)"`
18
+ PowerShell: `fnva env --shell powershell | Out-String | Invoke-Expression`
19
+ Fish: `fnva env --shell fish | source`
19
20
  - 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)"`
21
+ - Switch Java for current session: `fnva java use jdk-17` (with shell integration)
22
+ - Switch CC profile: `fnva cc use glmcc` (with shell integration)
22
23
  - New terminals auto-restore your last active environment
23
24
 
24
25
  ## What it does
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Shell integration installer for fnva (npm postinstall helper).
4
- // Uses fnva's built-in template system for shell integration scripts.
4
+ // Writes a single line into the shell profile: eval "$(fnva env --shell <shell>)"
5
+ // The fnva binary generates the full init script (autoload + wrapper).
5
6
 
6
7
  const fs = require('fs');
7
8
  const path = require('path');
8
9
  const os = require('os');
9
10
  const { spawnSync } = require('child_process');
10
11
 
11
- // Absolute path to the packaged fnva shim (bin/fnva.js)
12
12
  const FNVA_SHIM = path.resolve(__dirname, '..', 'bin', 'fnva.js');
13
13
 
14
14
  function detectShell() {
@@ -38,141 +38,26 @@ function getShellConfigPath(shell) {
38
38
  }
39
39
  }
40
40
 
41
- // Get integration script from fnva command (uses Rust templates)
42
- function getIntegrationScript(shell) {
43
- try {
44
- const result = spawnSync('node', [FNVA_SHIM, 'env', 'shell-integration', '-s', shell], {
45
- encoding: 'utf8',
46
- cwd: path.resolve(__dirname, '..')
47
- });
48
-
49
- if (result.status === 0 && result.stdout) {
50
- return result.stdout;
51
- }
52
-
53
- console.log(`Warning: Failed to get integration script from fnva (exit code: ${result.status})`);
54
- if (result.stderr) {
55
- console.log(`stderr: ${result.stderr}`);
56
- }
57
- return '';
58
- } catch (error) {
59
- console.log(`Warning: Failed to call fnva for integration script: ${error.message}`);
60
- return '';
61
- }
62
- }
63
-
64
- function getPowerShellFunction() {
65
- // Get integration script from Rust template
66
- const integrationScript = getIntegrationScript('powershell');
67
-
68
- return `
69
- ${integrationScript}
70
-
71
- # fnva auto integration (added by npm install)
72
- function fnva {
73
- 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")) {
74
- $tempFile = Join-Path $env:TEMP ("fnva_script_" + (Get-Random) + ".ps1")
75
-
76
- try {
77
- # Directly pipe output to temp file to avoid encoding issues
78
- & fnva.cmd @args 2>&1 | Out-File -FilePath $tempFile -Encoding UTF8
79
-
80
- # Check if file contains environment variables
81
- $content = Get-Content $tempFile -Raw -Encoding UTF8
82
- if ($content -match '\\$env:' -or $content -match 'Write-Host') {
83
- # Use dot sourcing to execute in current scope
84
- . $tempFile
85
- } else {
86
- $content
87
- }
88
- } finally {
89
- if (Test-Path $tempFile) { Remove-Item $tempFile -ErrorAction SilentlyContinue }
90
- }
91
- } else {
92
- & fnva.cmd @args
93
- }
94
- }
95
- `;
96
- }
97
-
98
- function getBashFunction() {
99
- // Get integration script from Rust template
100
- const integrationScript = getIntegrationScript('bash');
101
-
102
- return `
103
- ${integrationScript}
104
-
105
- # fnva auto integration (added by npm install)
106
- fnva() {
107
- local __fnva_bin="${FNVA_SHIM}"
108
- if [[ ! -x "$__fnva_bin" ]]; then
109
- echo "fnva: binary not found in PATH" >&2
110
- return 127
111
- fi
112
-
113
- if [[ $# -ge 2 && ("$1" == "java" || "$1" == "llm" || "$1" == "cc") && "$2" == "use" ]]; then
114
- local temp_file
115
- temp_file="$(mktemp)"
116
- chmod +x "$temp_file"
117
-
118
- "$__fnva_bin" "$@" > "$temp_file"
119
- source "$temp_file"
120
- rm -f "$temp_file"
121
- else
122
- "$__fnva_bin" "$@"
123
- fi
124
- }
125
- `;
126
- }
127
-
128
- function getFishFunction() {
129
- // Get integration script from Rust template
130
- const integrationScript = getIntegrationScript('fish');
131
-
132
- return `
133
- ${integrationScript}
134
-
135
- # fnva auto integration (added by npm install)
136
- function fnva
137
- set __fnva_bin "${FNVA_SHIM}"
138
- if test ! -x "$__fnva_bin"
139
- echo "fnva: binary not found in PATH" >&2
140
- return 127
141
- end
142
-
143
- if test (count $argv) -ge 2; and string match -q -r "^(java|llm|cc)$" $argv[1]; and test $argv[2] = "use"
144
- set temp_file (mktemp)
145
- chmod +x $temp_file
146
- env "$__fnva_bin" $argv > $temp_file
147
- source $temp_file
148
- rm -f $temp_file
149
- else
150
- env "$__fnva_bin" $argv
151
- end
152
- end
153
- `;
154
- }
155
-
156
- function getShellFunction(shell) {
41
+ function getIntegrationLine(shell) {
157
42
  switch (shell) {
158
43
  case 'powershell':
159
- return getPowerShellFunction();
44
+ return 'fnva env --shell powershell | Out-String | Invoke-Expression';
160
45
  case 'bash':
161
46
  case 'zsh':
162
- return getBashFunction(); // zsh 使用和 bash 相同的语法
47
+ return 'eval "$(fnva env --shell bash)"';
163
48
  case 'fish':
164
- return getFishFunction();
49
+ return 'fnva env --shell fish | source';
165
50
  default:
166
- return '';
51
+ return null;
167
52
  }
168
53
  }
169
54
 
170
- function isFunctionInstalled(configPath) {
55
+ function isInstalled(configPath) {
171
56
  if (!fs.existsSync(configPath)) {
172
57
  return false;
173
58
  }
174
59
  const content = fs.readFileSync(configPath, 'utf8');
175
- return content.includes('fnva auto integration (added by npm install)');
60
+ return content.includes('fnva env --shell');
176
61
  }
177
62
 
178
63
  function installShellIntegration() {
@@ -185,29 +70,30 @@ function installShellIntegration() {
185
70
  return false;
186
71
  }
187
72
 
188
- if (isFunctionInstalled(configPath)) {
73
+ if (isInstalled(configPath)) {
189
74
  console.log(`fnva shell integration already present: ${configPath}`);
190
75
  return true;
191
76
  }
192
77
 
78
+ const line = getIntegrationLine(shell);
79
+ if (!line) {
80
+ console.log(`Unsupported shell: ${shell}`);
81
+ return false;
82
+ }
83
+
193
84
  try {
194
85
  const dir = path.dirname(configPath);
195
86
  if (!fs.existsSync(dir)) {
196
87
  fs.mkdirSync(dir, { recursive: true });
197
88
  }
198
89
 
199
- const functionCode = getShellFunction(shell);
200
-
201
- if (!functionCode) {
202
- console.log('Failed to generate shell integration script');
203
- return false;
204
- }
90
+ const marker = `\n# fnva shell integration\n${line}\n`;
205
91
 
206
92
  if (fs.existsSync(configPath)) {
207
93
  const content = fs.readFileSync(configPath, 'utf8');
208
- fs.writeFileSync(configPath, content + '\n' + functionCode);
94
+ fs.writeFileSync(configPath, content + marker);
209
95
  } else {
210
- fs.writeFileSync(configPath, functionCode);
96
+ fs.writeFileSync(configPath, marker);
211
97
  }
212
98
 
213
99
  console.log(`fnva shell integration installed at: ${configPath}`);
@@ -267,7 +153,7 @@ if (require.main === module) {
267
153
  module.exports = {
268
154
  detectShell,
269
155
  getShellConfigPath,
270
- getShellFunction,
271
- isFunctionInstalled,
156
+ getIntegrationLine,
157
+ isInstalled,
272
158
  installShellIntegration,
273
159
  };