fix: parse comments in .nvmrc files
Description
Fixes #1119.
getNodeVersionFromFile() already handles a full-line comment followed by a version in many cases, but some valid .nvmrc comment forms are still parsed as part of the Node version. In particular, a comment-only # line can be selected as the version, and inline comments or trailing whitespace can leave an invalid version string.
This change applies .nvmrc-specific preprocessing before the existing version matcher:
- remove
#comments - trim and discard blank lines
- return
nullwhen the file contains only comments or whitespace
The behavior of .tool-versions, JSON package files, and Volta configuration is unchanged. Thanks to @sodic for documenting the failing cases in #1119.
The committed dist/setup and dist/cache-save bundles were rebuilt from the updated source.
Validation
npm run pre-checkinnpm run format-checknpm run lintnpm test— 11 suites and 235 tests passedgit diff --check
checking on this for you