Commit 13d9f415 authored by Hunter Loftis's avatar Hunter Loftis

test for pre and postinstall scripts with checked in modules, cleanup

parent f70f0256
......@@ -59,22 +59,17 @@ cat_npm_debug_log() {
test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log
}
tail_error_log() {
echo ""
echo " ! Build failure:"
echo ""
tail -n 500 $logfile | indent
}
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
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
fi
}
......@@ -6,38 +6,27 @@ set -e # fail fast
set -o pipefail # don't ignore exit codes when piping output
# set -x # enable debugging
bp_version="63-rc"
# Configure directories
build_dir=$1
cache_dir=$2
env_dir=$3
bp_dir=$(cd $(dirname $0); cd ..; pwd)
heroku_dir=$build_dir/.heroku
logfile=/tmp/node-log.txt
mkdir -p $heroku_dir/node
# Load some convenience functions like status(), echo(), and indent()
source $bp_dir/bin/common.sh
# Output version
head "Node.js Buildpack v$bp_version"
# Avoid GIT_DIR leak from previous build steps
unset GIT_DIR
# Create directories & log file
mkdir -p $heroku_dir/node
echo "" > $logfile
# Provide hook to deal with errors
trap build_failed ERR
# Load config vars into environment; start with defaults
export NPM_CONFIG_PRODUCTION=true
export NODE_MODULES_CACHE=true
if [ -d "$env_dir" ]; then
export_env_dir $env_dir
fi
export_env_dir $env_dir
####### Determine current state
......@@ -146,7 +135,9 @@ if [ "$modules_source" == "" ]; then
elif [ $modules_source == "prebuilt" ]; then
info "Rebuilding any native modules for this architecture"
npm run preinstall
npm rebuild 2>&1
npm run postinstall
elif $use_cache; then
info "Restoring node modules from cache"
......
......@@ -105,7 +105,9 @@ testBuildWithCache() {
testModulesCheckedIn() {
compile "modules-checked-in"
assertCaptured "node_modules source: prebuilt"
assertCaptured "(preinstall script)"
assertCaptured "Rebuilding any native modules for this architecture"
assertCaptured "(postinstall script)"
assertNotCaptured "Restoring node modules"
assertNotCaptured "Pruning unused dependencies"
assertNotCaptured "Installing any new modules"
......@@ -154,6 +156,7 @@ testProcfileAbsentServerPresent() {
testServerPresentOnly() {
compile "server-present-only"
assertCaptured "PRO TIP: Use 'npm init'"
assertCaptured "Skipping dependencies"
assertCaptured "'web: node server.js' to new Procfile"
assertFile "web: node server.js" "Procfile"
assertCapturedSuccess
......
......@@ -6,6 +6,10 @@
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"scripts": {
"preinstall": "echo '(preinstall script)'",
"postinstall": "echo '(postinstall script)'"
},
"dependencies": {
"hashish": "*"
},
......
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