From d272114e9452d43b29da2f818a02f6e91b2b238a Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 16 Oct 2021 15:13:48 +1300 Subject: [PATCH] Fail for blank target from auto (or engine) version file (#693) * Fail unspecified auto rather than fall back to current * Simplify wording --- bin/n | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/n b/bin/n index 27ab106..24a638e 100755 --- a/bin/n +++ b/bin/n @@ -1071,7 +1071,8 @@ function get_package_engine_version() { local range range="$(node -e "package = require('${filepath}'); if (package && package.engines && package.engines.node) console.log(package.engines.node)")" verbose_log "read" "${range}" - if [[ -z "${range}" || "*" == "${range}" ]]; then + [[ -n "${range}" ]] || return 2 + if [[ "*" == "${range}" ]]; then verbose_log "target" "current" g_target_node="current" return @@ -1142,6 +1143,7 @@ function get_engine_version() { break done [[ -n "${parent}" ]] || abort "${error_message}" + [[ -n "${g_target_node}" ]] || abort "did not find supported version of node in 'engines' field of package.json" } # @@ -1169,6 +1171,7 @@ function get_auto_version() { done # Fallback to package.json [[ -n "${parent}" ]] || get_engine_version "no file found for auto version (.n-node-version, .node-version, .nvmrc, or package.json)" + [[ -n "${g_target_node}" ]] || abort "file found for auto did not contain target version of node" } #