Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' of github.com:heroku/heroku-buildpack-nodejs in…
Browse files Browse the repository at this point in the history
…to abtris/update
  • Loading branch information
abtris committed Feb 17, 2014
2 parents b30c981 + a096187 commit 12c20bb
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
13 changes: 13 additions & 0 deletions bin/common.sh
Expand Up @@ -35,3 +35,16 @@ indent() {
cat_npm_debug_log() {
test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log
}

export_env_dir() {
env_dir=$1
whitelist_regex=${2:-''}
blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)$'}
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
}
50 changes: 41 additions & 9 deletions bin/compile
Expand Up @@ -11,6 +11,8 @@ export APPLICATION_GIT_DIR=`pwd`
# Configure directories
build_dir=$1
cache_dir=$2
env_dir=$3

bp_dir=$(cd $(dirname $0); cd ..; pwd)

# Load some convenience functions like status(), echo(), and indent()
Expand Down Expand Up @@ -63,22 +65,52 @@ if test -d $build_dir/node_modules; then
status "Found existing node_modules directory; skipping cache"
status "Rebuilding any native dependencies"
npm rebuild 2>&1 | indent
elif test -d $cache_dir/node_modules; then
elif test -d $cache_dir/node/node_modules; then
status "Restoring node_modules directory from cache"
cp -r $cache_dir/node_modules $build_dir/
cp -r $cache_dir/node/node_modules $build_dir/

status "Pruning cached dependencies not specified in package.json"
npm prune 2>&1 | indent

if test -f $cache_dir/node/.heroku/node-version && [ $(cat $cache_dir/node/.heroku/node-version) != "$node_version" ]; then
status "Node version changed since last build; rebuilding dependencies"
npm rebuild 2>&1 | indent
fi

fi

# Make npm output to STDOUT instead of its default STDERR
status "Installing dependencies"
npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent
# Scope config var availability only to `npm install`
(
if [ -d "$env_dir" ]; then
status "Exporting config vars to environment"
export_env_dir $env_dir
fi

status "Installing dependencies"
# Make npm output to STDOUT instead of its default STDERR
npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent
)

# Persist goodies like node-version in the slug
mkdir -p $build_dir/.heroku

# Save resolved node version in the slug for later reference
echo $node_version > $build_dir/.heroku/node-version

# Purge node-related cached content, being careful not to purge the top-level
# cache, for the sake of heroku-buildpack-multi apps.
rm -rf $cache_dir/node_modules # (for apps still on the older caching strategy)
rm -rf $cache_dir/node
mkdir -p $cache_dir/node

# If app has a node_modules directory, cache it.
if test -d $build_dir/node_modules; then
status "Caching node_modules directory for future builds"
cp -r $build_dir/node_modules $cache_dir/node
fi

status "Caching node_modules directory for future builds"
rm -rf $cache_dir/node_modules
mkdir -p $cache_dir
test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
# Copy goodies to the cache
cp -r $build_dir/.heroku $cache_dir/node

status "Cleaning up node-gyp and npm artifacts"
rm -rf "$build_dir/.node-gyp"
Expand Down
24 changes: 23 additions & 1 deletion bin/test
Expand Up @@ -104,6 +104,28 @@ testProcfileAbsentNpmStartAbsent() {
assertCapturedSuccess
}

testProcfileAbsentNpmStartPresent() {
compile "procfile-absent-npm-start-present"
assertCaptured "No Procfile found; Adding npm start to new Procfile"
assertFile "web: npm start" "Procfile"
assertCapturedSuccess
}

testEnvDirNotImported() {
compile "stable-node"
assertNotCaptured "Exporting config vars to environment"
assertCapturedSuccess
}

testEnvDirExported() {
env_dir=$(mktmpdir)
echo "chicken" > $env_dir/birds
echo "koi" > $env_dir/fish
compile "stable-node" "$(mktmpdir)" $env_dir
assertCaptured "Exporting config vars to environment"
assertCapturedSuccess
}

# Utils

pushd $(dirname 0) >/dev/null
Expand All @@ -128,7 +150,7 @@ compile_dir=""
compile() {
compile_dir=$(mktmpdir)
cp -r ${bp_dir}/test/$1/. ${compile_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)} $3
}

assertFile() {
Expand Down

0 comments on commit 12c20bb

Please sign in to comment.