0
0
mirror of https://github.com/tj/n.git synced 2024-11-24 19:46:56 +01:00

Add support for trailing comment in .nvmrc (#820)

This commit is contained in:
John Gee 2024-10-28 14:58:34 +13:00 committed by GitHub
parent 1a1b61967b
commit eea2a55533
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

2
bin/n
View File

@ -1147,6 +1147,8 @@ function get_nvmrc_version() {
verbose_log "found" "${filepath}"
local version
<"${filepath}" read -r version
# remove trailing comment, after #
version="$(echo "${version}" | sed 's/[[:space:]]*#.*//')"
verbose_log "read" "${version}"
# Translate from nvm aliases
case "${version}" in

View File

@ -68,3 +68,11 @@ function setup() {
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
assert_equal "${output}" "8.11.1"
}
@test "auto .nvmrc, trailing comment" {
local TARGET_VERSION="8.10.0"
cd "${MY_DIR}"
printf "${TARGET_VERSION} # comment" > .nvmrc
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
assert_equal "${output}" "${TARGET_VERSION}"
}