Skip to content

Commit

Permalink
Fix Path Set Up Process (software-mansion#975)
Browse files Browse the repository at this point in the history
This PR fixes a problem with extension not being able to refresh node
version after it was changed by nvm. Even when the extension was
deactivated and activated again. This would in turn lead to user
frustration when the node version they ware using was in initially
incorrect and applied user solution would not take effect.

The issue was triggered when the following conditions were met: 
- process vscode was either not restarted completely, or was opened from
terminal that would hold the old configuration
- the `$HOME/.nvm/versions/node/{NODE_VERSION}/bin` path was the first
one in vscodes path

Because we would open a new shell with vscode processes path passed as
an env variable it wouldn't start completely fresh and nvm scripts
located in `.zshrc` files responsible for aliasing seem to have an
optimization to not change the version path if it was already the newest
one, causing as receiving the old path to node still living in vscode
process.

The solution is to strip the env of a new shell process and allow it to
boot fresh.

### How Has This Been Tested: 

- run `react-native-78` and set a brakepoint after path was recived, run
it in following configurations:
    - run with a node 21 
    - reload after switching the node version in seprate terminal 
    - run from scratch
  • Loading branch information
filip131311 authored Feb 18, 2025
1 parent 9a2b6c8 commit 6c175d3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/vscode-extension/src/utilities/subprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ async function getPathEnv(appRoot: string) {
const RNIDE_PATH_DELIMITER = "{RNIDE_PATH_DELIMITER}";

const shellPath = process.env.SHELL ?? "/bin/zsh";
const { stdout } = await execa(shellPath, [
"-i",
"-c",
`cd "${appRoot}" && echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`,
]);

// Our goal is to determine the PATH variable that would be set when running commands from the application root.
// To simulate this accurately, we need to avoid inheriting the vscode process's environment variables.
// Therefore, we explicitly set the environment variable object to empty and disable automatic extension,
// which would otherwise fill missing variables with those from the currently running process.
const { stdout } = await execa(
shellPath,
["-i", "-c", `cd "${appRoot}" && echo "${RNIDE_PATH_DELIMITER}$PATH${RNIDE_PATH_DELIMITER}"`],
{
extendEnv: false,
env: {},
}
);
const path = stdout.split(RNIDE_PATH_DELIMITER)[1].trim();
Logger.debug("Obtained PATH environment variable:", path);
return path;
Expand Down

0 comments on commit 6c175d3

Please sign in to comment.