fnva 0.0.48 → 0.0.50

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 CHANGED
@@ -651,6 +651,31 @@ function run() {
651
651
 
652
652
  process.exit(0);
653
653
  } else {
654
+ // For env commands, capture output and write as single string to avoid
655
+ // PowerShell splitting multi-line output into Object[] (which breaks
656
+ // the standard | Out-String | Invoke-Expression profile pattern).
657
+ const isEnvOutputCommand = args[0] === 'env' && args[1] === 'env';
658
+ if (isEnvOutputCommand) {
659
+ const result = spawnSync(binaryPath, args, {
660
+ encoding: 'utf8',
661
+ shell: false,
662
+ });
663
+
664
+ if (result.error) {
665
+ console.error(`[ERROR] Failed to execute fnva: ${result.error.message}`);
666
+ process.exit(result.status ?? 1);
667
+ }
668
+
669
+ if (result.stdout) {
670
+ process.stdout.write(result.stdout);
671
+ }
672
+ if (result.stderr) {
673
+ process.stderr.write(result.stderr);
674
+ }
675
+
676
+ process.exit(result.status ?? 0);
677
+ }
678
+
654
679
  // 对于其他命令,使用原有的 stdio: 'inherit' 方式
655
680
  const result = spawnSync(binaryPath, args, {
656
681
  stdio: 'inherit',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -18,15 +18,24 @@ function detectShell() {
18
18
  return process.env.SHELL?.split('/').pop() || 'bash';
19
19
  }
20
20
 
21
+ function getPowershellProfilePath() {
22
+ const home = process.env.USERPROFILE || os.homedir();
23
+ // Check PowerShell 7 first (pwsh), then fall back to Windows PowerShell 5.x
24
+ const ps7Profile = path.join(home, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
25
+ const ps5Profile = path.join(home, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
26
+ // If PS7 profile already exists, use it; otherwise prefer PS7 path
27
+ if (fs.existsSync(ps7Profile)) return ps7Profile;
28
+ if (fs.existsSync(ps5Profile)) return ps5Profile;
29
+ // Detect which PowerShell is installed via pwsh vs powershell
30
+ const pwshResult = spawnSync('pwsh', ['-NoProfile', '-Command', 'echo true'], { timeout: 5000 });
31
+ if (pwshResult.status === 0) return ps7Profile;
32
+ return ps5Profile;
33
+ }
34
+
21
35
  function getShellConfigPath(shell) {
22
36
  switch (shell) {
23
37
  case 'powershell':
24
- return path.join(
25
- process.env.USERPROFILE || os.homedir(),
26
- 'Documents',
27
- 'WindowsPowerShell',
28
- 'Microsoft.PowerShell_profile.ps1'
29
- );
38
+ return getPowershellProfilePath();
30
39
  case 'bash':
31
40
  return path.join(os.homedir(), '.bashrc');
32
41
  case 'zsh':