Skip to content

Commit 36d988e

Browse files
authored
Merge pull request #35 from murkey/cleanup
Cleanup from JSON.sh integration
2 parents 2f94b7a + 2c43a24 commit 36d988e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ To run tests, install [bats](https://github.com/sstephenson/bats) and [nodenv](h
4242
Nodenv plugin hooks integration and tests heavily inspired by [rbenv-bundler-ruby-version](https://github.com/aripollak/rbenv-bundler-ruby-version).
4343

4444
Shell semver range support provided by [sh-semver](https://github.com/qzb/sh-semver).
45+
46+
`package.json` parsing provided by [JSON.sh](https://github.com/dominictarr/JSON.sh).

libexec/nodenv-package-json-engine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ find_package_json_path() {
3636
extract_version_from_package_json() {
3737
package_json_path="$1"
3838
version_regex='\["engines","node"\][[:space:]]*"([^"]*)"'
39+
# -b -n gives minimal output - see https://github.com/dominictarr/JSON.sh#options
3940
[[ $("$JSON_SH" -b -n < "$package_json_path") =~ $version_regex ]]
4041
echo "${BASH_REMATCH[1]}"
4142
}

test/test_helper.bash

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ assert_success() {
4949

5050
# cd_into_package nodeVersion [extraArgs]
5151
cd_into_package() {
52-
local version="$1"
53-
local packageJson="{
54-
\"engines\": {
55-
\"node\": \"${version}\"
56-
}
57-
}"
5852
mkdir -p "$EXAMPLE_PACKAGE_DIR"
5953
cd "$EXAMPLE_PACKAGE_DIR" || return 1
60-
echo "$packageJson" > "$EXAMPLE_PACKAGE_DIR/package.json"
54+
local version="$1"
55+
cat << JSON > package.json
56+
{
57+
"engines": {
58+
"node": "$version"
59+
}
60+
}
61+
JSON
6162
}
6263

6364
cd_into_babel_env_package() {

0 commit comments

Comments
 (0)