Skip to content

fix(ng-dev/release): update PATH after nvm install to affect subsequent commands#3659

Merged
josephperrott merged 1 commit into
angular:mainfrom
josephperrott:fix-nvm-install-context
May 12, 2026
Merged

fix(ng-dev/release): update PATH after nvm install to affect subsequent commands#3659
josephperrott merged 1 commit into
angular:mainfrom
josephperrott:fix-nvm-install-context

Conversation

@josephperrott
Copy link
Copy Markdown
Member

Updates the PATH environment variable in the parent process after running nvm install, so that subsequent commands spawned by the script use the correct Node.js version.

@josephperrott josephperrott added the action: merge The PR is ready for merge by the caretaker label May 12, 2026
@josephperrott josephperrott requested a review from alan-agius4 May 12, 2026 18:12
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the invokeNvmInstall method to automatically update the PATH environment variable with the Node.js binary location found via nvm which and adds a verification step against the .nvmrc file. Review feedback recommends using path.delimiter for cross-platform compatibility when manipulating the PATH and suggests handling NVM aliases in .nvmrc that are not valid semver ranges to prevent false validation failures.

import {existsSync} from 'fs';
import {join} from 'path';
import {existsSync, readFileSync} from 'fs';
import {dirname, join} from 'path';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Import delimiter from the path module to ensure the script remains compatible with different operating systems (e.g., Windows uses ; while Unix uses :).

Suggested change
import {dirname, join} from 'path';
import {delimiter, dirname, join} from 'path';
References
  1. ng-dev tooling is expected to be compatible with Windows.

Comment on lines +228 to +233
const pathParts = currentPath.split(':');

// Only update if the requested node directory is not already the first entry in PATH.
if (pathParts[0] !== nodeDir) {
const filteredParts = pathParts.filter((p) => p !== nodeDir);
process.env['PATH'] = [nodeDir, ...filteredParts].join(':');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Use delimiter instead of a hardcoded : to split and join the PATH environment variable. This ensures compatibility with Windows, as specified in the general rules for this repository.

Suggested change
const pathParts = currentPath.split(':');
// Only update if the requested node directory is not already the first entry in PATH.
if (pathParts[0] !== nodeDir) {
const filteredParts = pathParts.filter((p) => p !== nodeDir);
process.env['PATH'] = [nodeDir, ...filteredParts].join(':');
const pathParts = currentPath.split(delimiter);
// Only update if the requested node directory is not already the first entry in PATH.
if (pathParts[0] !== nodeDir) {
const filteredParts = pathParts.filter((p) => p !== nodeDir);
process.env['PATH'] = [nodeDir, ...filteredParts].join(delimiter);
References
  1. ng-dev tooling is expected to be compatible with Windows.

});
const detectedNodeVersion = nodeVersionOutput.trim();

if (!semver.satisfies(detectedNodeVersion, nodeVersionFromNvmrc)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The .nvmrc file can contain NVM aliases (e.g., lts/iron or node) which are not valid semver ranges. Using semver.satisfies directly on such values will return false, causing an unnecessary error. Consider checking if the value is a valid semver range before validating.

Suggested change
if (!semver.satisfies(detectedNodeVersion, nodeVersionFromNvmrc)) {
const isSemverRange = semver.validRange(nodeVersionFromNvmrc) !== null;
if (isSemverRange && !semver.satisfies(detectedNodeVersion, nodeVersionFromNvmrc)) {

@josephperrott josephperrott merged commit 96bda20 into angular:main May 12, 2026
12 checks passed
@josephperrott
Copy link
Copy Markdown
Member Author

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants