Skip to content

Commit f492c87

Browse files
Copilotkmagierafilip131311jwajgelt
authored
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

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

packages/vscode-extension/src/utilities/subprocess.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,42 @@ async function getPathEnv(appRoot: string) {
1919

2020
const shellPath = process.env.SHELL ?? "/bin/zsh";
2121

22+
// Build a list of commands to run in a chain.
23+
// We always have cd and echo, and conditionally include nvm use if available.
24+
const commands: string[] = [];
25+
26+
// Always start with cd to the app root
27+
commands.push(`cd "${appRoot}"`);
28+
29+
// Test if nvm is available and set up correctly with a dry-run.
30+
// Only include 'nvm use' in the command chain if this succeeds.
31+
try {
32+
await execa(
33+
shellPath,
34+
["-i", "-l", "-c", `cd "${appRoot}" && type nvm > /dev/null 2>&1 && nvm use`],
35+
{
36+
extendEnv: false,
37+
env: {},
38+
}
39+
);
40+
// If the dry-run succeeds, include nvm use in the command chain
41+
commands.push("nvm use");
42+
} catch (error) {
43+
// nvm is not available or nvm use failed, proceed without it
44+
Logger.debug("nvm is not available or not set up correctly, proceeding without nvm");
45+
}
46+
47+
// Always end with echo to capture the PATH
48+
commands.push(`echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`);
49+
2250
// Our goal is to determine the PATH variable that would be set when running commands from the application root.
2351
// To simulate this accurately, we need to avoid inheriting the vscode process's environment variables.
2452
// Therefore, we explicitly set the environment variable object to empty and disable automatic extension,
2553
// which would otherwise fill missing variables with those from the currently running process.
26-
const { stdout } = await execa(
27-
shellPath,
28-
[
29-
"-i",
30-
"-l",
31-
"-c",
32-
`cd "${appRoot}" && echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`,
33-
],
34-
{
35-
extendEnv: false,
36-
env: {},
37-
}
38-
);
54+
const { stdout } = await execa(shellPath, ["-i", "-l", "-c", commands.join(" && ")], {
55+
extendEnv: false,
56+
env: {},
57+
});
3958

4059
// The approach above is not always loading the whole path as it ignores some setup scripts,
4160
// like .zprofile for example, to mitigate the effects of that problem we append the PATH

0 commit comments

Comments
 (0)