setup-node icon indicating copy to clipboard operation
setup-node copied to clipboard

fix: parse comments in .nvmrc files

Open bm1016bm-svg opened this issue 4 months ago • 1 comments

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 avatar Jul 17 '26 09:07 bm1016bm-svg

checking on this for you

tplusm0510-source avatar Jul 18 '26 06:07 tplusm0510-source