Commit c1f13bf0 authored by zeke's avatar zeke

stringify semver pattern for requested version

parent b8953749
......@@ -3,7 +3,8 @@
# fail fast
set -e
# debug
# Uncomment the line below to enable debugging when
# working on the buildpack
# set -x
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"
curl $node_url -s -o - | tar xzf - -C $build_dir
mkdir -p $build_dir/vendor
# Remove node in case we're overwriting a previously-downloaded version
rm -rf $build_dir/vendor/node
mv $build_dir/node-v$version-linux-x64 $build_dir/vendor/node
chmod +x $build_dir/vendor/node/bin/*
PATH=$PATH:$build_dir/vendor/node/bin
......@@ -46,7 +50,6 @@ status() {
echo "-----> $*"
}
# 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
# e.g. npm install | indent
......@@ -59,5 +62,5 @@ indent() {
}
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
else
# 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
status "Latest stable node v$stable_version satisfies engines.node: $requested"
node_version=$stable_version
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=""
for version in $(query_all_versions); do args="${args} -v \"${version}\""; done
args="${args} -r \"${requested_version}\""
# Determine which available versions satisfy the requested version
# https://github.com/isaacs/node-semver/blob/master/bin/semver
evaluated_versions=$(eval node $bp_dir/vendor/semver/bin/semver ${args} || echo "")
# Find all versions that satisfy.
satisfying_versions=$(eval $bp_dir/vendor/semver/bin/semver ${args})
# Use the latest of the evaluated versions
node_version=$(echo $evaluated_versions | tail -n 1)
# Use the latest one.
node_version=$(echo "$satisfying_versions" | tail -n 1)
if test $node_version; then
status "Downloading and installing node v$version"
......@@ -62,9 +64,9 @@ cache_store_dir="$cache_dir/node_modules/$node_version"
cache_target_dir="$build_dir/node_modules"
# 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"
if [ -d $cache_target_dir ]; then
if test -d $cache_target_dir; then
cp -r $cache_store_dir/* $cache_target_dir/
else
cp -r $cache_store_dir $cache_target_dir
......@@ -80,7 +82,7 @@ npm install --production | indent
npm rebuild | indent
# 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"
rm -rf $cache_store_dir
mkdir -p $(dirname $cache_store_dir)
......
#!/usr/bin/env bash
#
# 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
#
# See CONTRIBUTING.md for info on running these tests.
testDetectWithPackageJson() {
detect "package-json-stable-version"
......
......@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "5.0"
"node": ">2.0"
}
}
......@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "0.10.x"
"node": ">0.10.0"
}
}
......@@ -7,6 +7,6 @@
"url" : "http://github.com/example/example.git"
},
"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