Commit cdedbf03 authored by zeke's avatar zeke

pass engines.node to node-semver-service.heroku.com

parent d72d36f9
...@@ -3,99 +3,66 @@ ...@@ -3,99 +3,66 @@
build_dir=$1 build_dir=$1
cache_basedir=$2 cache_basedir=$2
bp_dir=$(cd $(dirname $0); cd ..; pwd) bp_dir=$(cd $(dirname $0); cd ..; pwd)
stable_version="0.10.18"
source $bp_dir/bin/common.sh source $bp_dir/bin/common.sh
# Output npm debug info on error # Output npm debug info on error
trap cat_npm_debug_log ERR trap cat_npm_debug_log ERR
# Bootstrap the build process with latest stable version of node
# We'll use it to parse package.json and do semver detection
status "Bootstrapping node"
download_and_install_node $stable_version
# Is a node version specified in package.json? # Is a node version specified in package.json?
# https://github.com/trentm/json semver_range=$(cat $build_dir/package.json | $bp_dir/vendor/json engines.node)
requested_version=$(cat $build_dir/package.json | $bp_dir/vendor/json engines.node)
# Resolve node version using a service
node_version=$(curl --silent https://node-semver-service.heroku.com/${semver_range})
# Give a warning if engines.node is unspecified # Warn if engines.node is unspecified
if ! test $requested_version; then if ! test $semver_range; then
node_version=$stable_version
echo echo
echo "WARNING: No node version specified in package.json, see:" | indent echo "WARNING: No node version specified in package.json, see:" | indent
echo "https://devcenter.heroku.com/articles/nodejs-support#versions" | indent echo "https://devcenter.heroku.com/articles/nodejs-support#versions" | indent
echo echo
status "Defaulting to latest stable node, v$stable_version" status "Defaulting to latest stable node, v$node_version"
else
# Does the already-downloaded stable version of node satisfy the requested version?
default_satisfies=$($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_version"
node_version=$stable_version
else
# 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}\""
# Find all versions that satisfy.
satisfying_versions=$(eval $bp_dir/vendor/semver/bin/semver ${args} || echo "")
# Use the latest one.
node_version=$(echo "$satisfying_versions" | tail -n 1)
# Bail if no matching version was found
if ! test $node_version; then
error "node ${requested_version} not found among available versions on nodejs.org/dist"
fi
fi
fi fi
# TODO: Warn if engines.node is "*" or ">foo"
# Download and install node
status "Downloading and installing node v$node_version"
download_and_install_node $node_version
# Run subsequent node/npm commands from the build path # Run subsequent node/npm commands from the build path
cd $build_dir cd $build_dir
# Configure cache directory # Configure cache directory
package_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}') package_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}')
cache_dir="$cache_basedir/$node_version/$package_checksum" cache_dir="$cache_basedir/$package_checksum"
# Restore from cache if node and package.json haven't changed # Restore from cache package.json hasn't changed
if test -d $cache_dir; then if test -d $cache_dir; then
status "package.json and node version unchanged since last build" status "package.json unchanged since last build"
status "Restoring node v$node_version and node_modules from cache" status "Restoring node_modules from cache"
test -d $cache_dir/node_modules && cp -r $cache_dir/node_modules $build_dir/ test -d $cache_dir/node_modules && cp -r $cache_dir/node_modules $build_dir/
cp -r $cache_dir/vendor/node $build_dir/vendor/ # cp -r $cache_dir/vendor/node $build_dir/vendor/
else else
if [ $stable_version != $node_version ]; then
status "Downloading and installing node v$node_version"
download_and_install_node $node_version
fi
status "Installing dependencies" status "Installing dependencies"
npm install --production | indent npm install --production | indent
status "Rebuilding dependencies" status "Rebuilding dependencies"
npm rebuild | indent npm rebuild | indent
status "Caching node and node_modules for future builds" status "Caching node_modules for future builds"
rm -rf $cache_dir rm -rf $cache_dir
mkdir -p $cache_dir mkdir -p $cache_dir
mkdir -p $cache_dir/vendor mkdir -p $cache_dir/vendor
test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/ test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
cp -r $build_dir/vendor/node $cache_dir/vendor/ # cp -r $build_dir/vendor/node $cache_dir/vendor/
fi fi
# Update the PATH # Update the PATH
status "Building runtime environment" status "Building runtime environment"
mkdir -p $build_dir/.profile.d mkdir -p $build_dir/.profile.d
echo "export PATH=\"\$HOME/vendor/node/bin:$HOME/bin:\$HOME/node_modules/.bin:\$PATH\"" > $build_dir/.profile.d/nodejs.sh echo "export PATH=\"\$HOME/vendor/node/bin:\$HOME/bin:\$HOME/node_modules/.bin:\$PATH\"" > $build_dir/.profile.d/nodejs.sh
# Post to nomnom # Post to nomnom
curl \ curl \
......
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