Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ To run tests, install [bats](https://github.com/sstephenson/bats) and [nodenv](h
Nodenv plugin hooks integration and tests heavily inspired by [rbenv-bundler-ruby-version](https://github.com/aripollak/rbenv-bundler-ruby-version).

Shell semver range support provided by [sh-semver](https://github.com/qzb/sh-semver).

`package.json` parsing provided by [JSON.sh](https://github.com/dominictarr/JSON.sh).
1 change: 1 addition & 0 deletions libexec/nodenv-package-json-engine
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ find_package_json_path() {
extract_version_from_package_json() {
package_json_path="$1"
version_regex='\["engines","node"\][[:space:]]*"([^"]*)"'
# -b -n gives minimal output - see https://github.com/dominictarr/JSON.sh#options
[[ $("$JSON_SH" -b -n < "$package_json_path") =~ $version_regex ]]
echo "${BASH_REMATCH[1]}"
}
Expand Down
15 changes: 8 additions & 7 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ assert_success() {

# cd_into_package nodeVersion [extraArgs]
cd_into_package() {
local version="$1"
local packageJson="{
\"engines\": {
\"node\": \"${version}\"
}
}"
mkdir -p "$EXAMPLE_PACKAGE_DIR"
cd "$EXAMPLE_PACKAGE_DIR" || return 1
echo "$packageJson" > "$EXAMPLE_PACKAGE_DIR/package.json"
local version="$1"
cat << JSON > package.json
{
"engines": {
"node": "$version"
}
}
JSON
}

cd_into_babel_env_package() {
Expand Down