Skip to content

fix: parse comments in .nvmrc files#1586

Open
bm1016bm-svg wants to merge 1 commit into
actions:mainfrom
bm1016bm-svg:codex/support-nvmrc-comments
Open

fix: parse comments in .nvmrc files#1586
bm1016bm-svg wants to merge 1 commit into
actions:mainfrom
bm1016bm-svg:codex/support-nvmrc-comments

Conversation

@bm1016bm-svg

Copy link
Copy Markdown

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 null when 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-checkin
  • npm run format-check
  • npm run lint
  • npm test — 11 suites and 235 tests passed
  • git diff --check

@bm1016bm-svg
bm1016bm-svg marked this pull request as ready for review July 17, 2026 09:09
@bm1016bm-svg
bm1016bm-svg requested a review from a team as a code owner July 17, 2026 09:09
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.

Since nvm v0.40.0 .nvmrc may contain comments

1 participant