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