Commit f492c87
Support nvm via .nvmrc file detection (#1610)
Adds support for nvm via `.nvmrc` file detection. Some projects (i.e.
bsky) use `.nvmrc` file to specify the node version. Currently, the only
way to make Radon honor that file would be to go to the project
directory, run `nvm use` and then launch code from the terminal. This
isn't ideal especially for people who work on a couple of different
projects with different node version requirements.
This change runs `nvm use` similarly to how we initialize PATH variables
to support tools like mise.
Fixes #1609
## Changes Made
Modified `packages/vscode-extension/src/utilities/subprocess.ts`:
- Added a dry-run approach to test if nvm is available and properly
configured before including it in the command chain
- Refactored command generation to use a `commands` array with `.join("
&& ")` for better readability:
- `cd` to app root is always included
- `nvm use` is conditionally added only if the dry-run succeeds
- `echo` to capture PATH is always included
- Maintains proper error handling throughout the command chain
### Implementation Details
The solution uses a dry-run approach to optimize performance and avoid
unnecessary error messages:
1. **Dry-run test**: First attempts to run `nvm use` in the application
root directory
2. **Conditional inclusion**: Only includes `nvm use` in the actual PATH
command if the dry-run succeeds
3. **Graceful handling**: If nvm is not installed, not configured, or no
`.nvmrc` file exists, the dry-run fails and nvm is skipped entirely
4. **Command chain generation**: Uses an array of commands joined with
`.join(" && ")` for clear, maintainable code
This means:
- Projects with `.nvmrc` → nvm use runs and loads the correct version ✅
- Projects without `.nvmrc` → nvm is skipped (no error messages in logs)
✅
- Systems without nvm → nvm commands are not attempted ✅
### How Has This Been Tested:
- ✅ Prettier formatting passes
- ✅ Dry-run succeeds with `.nvmrc` present → nvm use is included
- ✅ Dry-run fails without `.nvmrc` → nvm use is skipped
- ✅ Dry-run fails without nvm → command is skipped
- ✅ If `cd` fails, the entire command chain stops (correct behavior)
- ✅ If `cd` succeeds, `nvm use` runs (if available), then `echo` runs
(correct behavior)
- ✅ Proper error propagation maintained with `&&` chaining
### How Has This Change Been Documented:
N/A - This is an internal enhancement that automatically detects and
uses `.nvmrc` files when present, requiring no user documentation.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Support nvm (via .nvmrc file)</issue_title>
> <issue_description>Some projects (i.e. bsky) use .nvmrc file to
specify the node version. Currently, the only way to make Radon honor
that file would be to go to the project directory, run `nvm use` and
then launch code from the terminal. This isn't ideal especially for
people who work on a couple of different projects with different node
version requirements.
>
> We should run `nvm use` similarily to how we initialize PATH variables
to support tools like mise. </issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
Fixes #1609
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/software-mansion/radon-ide/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: kmagiera <[email protected]>
Co-authored-by: filip131311 <[email protected]>
Co-authored-by: jwajgelt <[email protected]>1 parent 3cd5ca7 commit f492c87
1 file changed
+32
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
22 | 50 | | |
23 | 51 | | |
24 | 52 | | |
25 | 53 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
39 | 58 | | |
40 | 59 | | |
41 | 60 | | |
| |||
0 commit comments