Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

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.

Original prompt

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)

Fixes #1609

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Oct 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
radon-ide Ready Ready Preview Comment Dec 12, 2025 4:18pm

Copilot AI changed the title [WIP] Support nvm (via .nvmrc file) Support nvm via .nvmrc file detection Oct 3, 2025
Copilot AI requested a review from kmagiera October 3, 2025 09:44
// If .nvmrc exists, run 'nvm use' to load the correct Node.js version.
// We use a conditional command that only runs 'nvm use' if nvm is available,
// preventing errors in environments where nvm is not installed.
const nvmCommand = hasNvmrc ? "type nvm > /dev/null 2>&1 && nvm use; " : "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason we only call nvm use when the file is present? given we can handle the case the commend throws, maybe it'd be better to just call it here instead of testing agains the .nvmrc file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. I've removed the .nvmrc file check since nvm use itself handles the case gracefully when the file is not present. The command now always runs type nvm > /dev/null 2>&1 && nvm use; which is simpler and works correctly in all scenarios.

Changes in commit 1a53e76

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what is the reason we only call nvm use when the file is present? given we can handle the case the commend throws, maybe it'd be better to just call it here instead of testing agains the .nvmrc file

// If .nvmrc exists, run 'nvm use' to load the correct Node.js version.
// We use a conditional command that only runs 'nvm use' if nvm is available,
// preventing errors in environments where nvm is not installed.
const nvmCommand = hasNvmrc ? "type nvm > /dev/null 2>&1 && nvm use; " : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I think it'd be better to dry-run nvm use once to check if it's set up correctly, and then add it to the execa call below only if successful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I've implemented the dry-run approach. Now nvm use is tested first with an execa call, and only included in the actual PATH command if it succeeds. This means projects without .nvmrc won't see error messages, and systems without nvm won't attempt to use it.

Changes in commit c0ef927

Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot what is the reason we only call nvm use when the file is present? given we can handle the case the commend throws, maybe it'd be better to just call it here instead of testing agains the .nvm...

Good point! I've simplified the implementation to always call nvm use without checking for the .nvmrc file first. The nvm use command handles missing files gracefully, so the extra filesystem check wasn't necessary.

Changes in commit 1a53e76

"-l",
"-c",
`cd "${appRoot}" && echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`,
`cd "${appRoot}" && ${nvmCommand}echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot since the nvmCommand ends with ;, won't that change the behavior to not fail if cd appRoot didn't succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! The semicolon breaks the error chain. With ;, the echo command would run even if cd fails. I've changed it to use && instead, so the entire command chain properly fails if cd doesn't succeed.

Changes in commit 07a1cf8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you change this so that

  • you generate a list of commands to run in the chain
  • you always have cd and echo commands on the list
  • you only include nvm use if nvm is available
  • you generate the final command chain by calling .join(" && ") on that list?
    I think it would be more readable that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Refactored to use a commands array that always includes cd and echo, conditionally adds nvm use if available, and generates the final command with .join(" && ").

Changes in commit e52ae3c

@jwajgelt
Copy link
Contributor

jwajgelt commented Dec 2, 2025

@copilot can you rebase this branch onto main?

Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot can you rebase this branch onto main?

I'm unable to rebase this branch as I don't have the ability to perform git rebase operations or force push. You'll need to rebase this branch manually, or I can help with other changes if needed.

@jwajgelt
Copy link
Contributor

jwajgelt commented Dec 2, 2025

@copilot can you rebase this branch onto main?

I'm unable to rebase this branch as I don't have the ability to perform git rebase operations or force push. You'll need to rebase this branch manually, or I can help with other changes if needed.

@copilot merge main into this branch then

Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot can you rebase this branch onto main?

I'm unable to rebase this branch as I don't have the ability to perform git rebase operations or force push. You'll need to rebase this branch...

Done. Merged main into this branch in commit 853377b.

jwajgelt
jwajgelt previously approved these changes Dec 2, 2025
Copy link
Contributor

@jwajgelt jwajgelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@filip131311 filip131311 dismissed their stale review December 2, 2025 20:16

I don't have an up to date assesment of this PR but it seems to be blocked by my old review so i dismiss it

@jwajgelt jwajgelt dismissed kmagiera’s stale review December 3, 2025 08:05

The request has been addressed.

@jwajgelt jwajgelt self-requested a review December 3, 2025 08:38
@jwajgelt jwajgelt dismissed their stale review December 3, 2025 08:38

Found some issues, will fix them manually

@jwajgelt jwajgelt marked this pull request as draft December 3, 2025 09:12
@jwajgelt jwajgelt force-pushed the copilot/fix-d8ea27f3-5f01-43da-bc77-79fafb89d962 branch from 853377b to 3d3cfb8 Compare December 12, 2025 16:17
@jwajgelt jwajgelt marked this pull request as ready for review December 12, 2025 16:18
Copy link
Contributor

@jwajgelt jwajgelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine now.

@jwajgelt jwajgelt merged commit f492c87 into main Dec 15, 2025
9 checks passed
@jwajgelt jwajgelt deleted the copilot/fix-d8ea27f3-5f01-43da-bc77-79fafb89d962 branch December 15, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nvm (via .nvmrc file)

4 participants