|
119 | 119 | " try:\n", |
120 | 120 | " # For npm, ensure we have proper environment (especially for nvm)\n", |
121 | 121 | " env = os.environ.copy()\n", |
122 | | - " # If npm is in nvm path, ensure NODE_PATH is set\n", |
123 | | - " if 'nvm' in command_path and command == 'npm':\n", |
124 | | - " nvm_dir = os.path.dirname(os.path.dirname(command_path))\n", |
125 | | - " if 'NODE_PATH' not in env:\n", |
126 | | - " env['NODE_PATH'] = nvm_dir\n", |
| 122 | + " # If npm is in nvm path, ensure node is in PATH (npm's shebang needs it)\n", |
| 123 | + " if command == 'npm':\n", |
| 124 | + " # Find where node is located\n", |
| 125 | + " node_path = shutil.which('node')\n", |
| 126 | + " if not node_path:\n", |
| 127 | + " # Try to find node in the same directory as npm\n", |
| 128 | + " node_dir = os.path.dirname(command_path)\n", |
| 129 | + " node_candidate = os.path.join(node_dir, 'node')\n", |
| 130 | + " if os.path.exists(node_candidate):\n", |
| 131 | + " node_path = node_candidate\n", |
| 132 | + " else:\n", |
| 133 | + " # Try nvm paths\n", |
| 134 | + " nvm_paths = [\n", |
| 135 | + " os.path.expanduser(\"~/.nvm/versions/node\"),\n", |
| 136 | + " os.path.expanduser(\"~/.config/nvm/versions/node\"),\n", |
| 137 | + " ]\n", |
| 138 | + " for nvm_base in nvm_paths:\n", |
| 139 | + " if os.path.exists(nvm_base):\n", |
| 140 | + " try:\n", |
| 141 | + " versions = sorted([d for d in os.listdir(nvm_base) if os.path.isdir(os.path.join(nvm_base, d))])\n", |
| 142 | + " if versions:\n", |
| 143 | + " latest = versions[-1]\n", |
| 144 | + " node_candidate = os.path.join(nvm_base, latest, \"bin\", \"node\")\n", |
| 145 | + " if os.path.exists(node_candidate):\n", |
| 146 | + " node_path = node_candidate\n", |
| 147 | + " break\n", |
| 148 | + " except:\n", |
| 149 | + " pass\n", |
| 150 | + " \n", |
| 151 | + " # If we found node, add its directory to PATH\n", |
| 152 | + " if node_path:\n", |
| 153 | + " node_dir = os.path.dirname(node_path)\n", |
| 154 | + " current_path = env.get('PATH', '')\n", |
| 155 | + " # Add node directory to PATH if not already there\n", |
| 156 | + " if node_dir not in current_path:\n", |
| 157 | + " env['PATH'] = f\"{node_dir}:{current_path}\"\n", |
| 158 | + " \n", |
| 159 | + " # Also set NODE_PATH for npm modules\n", |
| 160 | + " if 'nvm' in command_path:\n", |
| 161 | + " nvm_dir = os.path.dirname(os.path.dirname(command_path))\n", |
| 162 | + " if 'NODE_PATH' not in env:\n", |
| 163 | + " env['NODE_PATH'] = nvm_dir\n", |
127 | 164 | " \n", |
128 | 165 | " result = subprocess.run(\n", |
129 | 166 | " [command_path, version_flag],\n", |
|
0 commit comments