Commit c1f13bf0 authored by zeke's avatar zeke

stringify semver pattern for requested version

parent b8953749
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
# fail fast # fail fast
set -e set -e
# debug # Uncomment the line below to enable debugging when
# working on the buildpack
# set -x # set -x
download_and_install_node() { download_and_install_node() {
...@@ -11,7 +12,10 @@ download_and_install_node() { ...@@ -11,7 +12,10 @@ download_and_install_node() {
node_url="http://s3pository.heroku.com/node/v$version/node-v$version-linux-x64.tar.gz" node_url="http://s3pository.heroku.com/node/v$version/node-v$version-linux-x64.tar.gz"
curl $node_url -s -o - | tar xzf - -C $build_dir curl $node_url -s -o - | tar xzf - -C $build_dir
mkdir -p $build_dir/vendor mkdir -p $build_dir/vendor
# Remove node in case we're overwriting a previously-downloaded version
rm -rf $build_dir/vendor/node rm -rf $build_dir/vendor/node
mv $build_dir/node-v$version-linux-x64 $build_dir/vendor/node mv $build_dir/node-v$version-linux-x64 $build_dir/vendor/node
chmod +x $build_dir/vendor/node/bin/* chmod +x $build_dir/vendor/node/bin/*
PATH=$PATH:$build_dir/vendor/node/bin PATH=$PATH:$build_dir/vendor/node/bin
...@@ -46,7 +50,6 @@ status() { ...@@ -46,7 +50,6 @@ status() {
echo "-----> $*" echo "-----> $*"
} }
# sed -l basically makes sed replace and buffer through stdin to stdout # sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end # so you get updates while the command runs and dont wait for the end
# e.g. npm install | indent # e.g. npm install | indent
...@@ -59,5 +62,5 @@ indent() { ...@@ -59,5 +62,5 @@ indent() {
} }
function cat_npm_debug_log() { function cat_npm_debug_log() {
[ -f $build_dir/npm-debug.log ] && cat $build_dir/npm-debug.log test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log
} }
...@@ -30,23 +30,25 @@ if ! test $requested_version; then ...@@ -30,23 +30,25 @@ if ! test $requested_version; then
else else
# Does the already-downloaded stable version of node satisfy the requested version? # Does the already-downloaded stable version of node satisfy the requested version?
default_satisfies=$(node $bp_dir/vendor/semver/bin/semver -v "${stable_version}" -r "${requested_version}" || echo "") default_satisfies=$(node $bp_dir/vendor/semver/bin/semver -v "$stable_version" -r "$requested_version" || echo "")
if test $default_satisfies; then if test $default_satisfies; then
status "Latest stable node v$stable_version satisfies engines.node: $requested" status "Latest stable node v$stable_version satisfies engines.node: $requested"
node_version=$stable_version node_version=$stable_version
else else
# Find all available versions from nodejs.org/dist # Fetch all versions of node from nodejs.org/dist and format them into
# a string that the semver binary will appreciate.
# e.g. semver -v "0.10.0" -v "0.10.1" -v "0.10.2" -r ">0.8"
# See https://github.com/isaacs/node-semver/blob/master/bin/semver
args="" args=""
for version in $(query_all_versions); do args="${args} -v \"${version}\""; done for version in $(query_all_versions); do args="${args} -v \"${version}\""; done
args="${args} -r \"${requested_version}\"" args="${args} -r \"${requested_version}\""
# Determine which available versions satisfy the requested version # Find all versions that satisfy.
# https://github.com/isaacs/node-semver/blob/master/bin/semver satisfying_versions=$(eval $bp_dir/vendor/semver/bin/semver ${args})
evaluated_versions=$(eval node $bp_dir/vendor/semver/bin/semver ${args} || echo "")
# Use the latest of the evaluated versions # Use the latest one.
node_version=$(echo $evaluated_versions | tail -n 1) node_version=$(echo "$satisfying_versions" | tail -n 1)
if test $node_version; then if test $node_version; then
status "Downloading and installing node v$version" status "Downloading and installing node v$version"
...@@ -62,9 +64,9 @@ cache_store_dir="$cache_dir/node_modules/$node_version" ...@@ -62,9 +64,9 @@ cache_store_dir="$cache_dir/node_modules/$node_version"
cache_target_dir="$build_dir/node_modules" cache_target_dir="$build_dir/node_modules"
# Restore node_modules from cache, if present # Restore node_modules from cache, if present
if [ -d $cache_store_dir ]; then if test -d $cache_store_dir; then
status "Restoring node_modules cache" status "Restoring node_modules cache"
if [ -d $cache_target_dir ]; then if test -d $cache_target_dir; then
cp -r $cache_store_dir/* $cache_target_dir/ cp -r $cache_store_dir/* $cache_target_dir/
else else
cp -r $cache_store_dir $cache_target_dir cp -r $cache_store_dir $cache_target_dir
...@@ -80,7 +82,7 @@ npm install --production | indent ...@@ -80,7 +82,7 @@ npm install --production | indent
npm rebuild | indent npm rebuild | indent
# Cache node_modules for future builds # Cache node_modules for future builds
if [ -d $cache_target_dir ]; then if test -d $cache_target_dir; then
status "Caching node_modules for future builds" status "Caching node_modules for future builds"
rm -rf $cache_store_dir rm -rf $cache_store_dir
mkdir -p $(dirname $cache_store_dir) mkdir -p $(dirname $cache_store_dir)
......
#!/usr/bin/env bash #!/usr/bin/env bash
# See CONTRIBUTING.md for info on running these tests.
#
# Create a Heroku app with the following buildpack:
# https://github.com/ddollar/buildpack-test
#
# Push this Node.js buildpack to that Heroku app to
# run the tests
#
testDetectWithPackageJson() { testDetectWithPackageJson() {
detect "package-json-stable-version" detect "package-json-stable-version"
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git" "url" : "http://github.com/example/example.git"
}, },
"engines": { "engines": {
"node": "5.0" "node": ">2.0"
} }
} }
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git" "url" : "http://github.com/example/example.git"
}, },
"engines": { "engines": {
"node": "0.10.x" "node": ">0.10.0"
} }
} }
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git" "url" : "http://github.com/example/example.git"
}, },
"engines": { "engines": {
"node": "0.11.5" "node": ">0.11.0"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment