Commit 26c18bce authored by Zeke Sikelianos's avatar Zeke Sikelianos

Merge pull request #89 from heroku/env-file

Make config vars available to npm install
parents c962f1e4 8b280a26
...@@ -7,6 +7,8 @@ set -o pipefail # don't ignore exit codes when piping output ...@@ -7,6 +7,8 @@ set -o pipefail # don't ignore exit codes when piping output
# Configure directories # Configure directories
build_dir=$1 build_dir=$1
cache_dir=$2 cache_dir=$2
env_file=$3
bp_dir=$(cd $(dirname $0); cd ..; pwd) bp_dir=$(cd $(dirname $0); cd ..; pwd)
# Load some convenience functions like status(), echo(), and indent() # Load some convenience functions like status(), echo(), and indent()
...@@ -67,9 +69,17 @@ elif test -d $cache_dir/node_modules; then ...@@ -67,9 +69,17 @@ elif test -d $cache_dir/node_modules; then
npm prune 2>&1 | indent npm prune 2>&1 | indent
fi fi
# Make npm output to STDOUT instead of its default STDERR # Scope config var availability only to `npm install`
status "Installing dependencies" (
npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent if [ "$env_file" ]; then
status "Importing application config vars"
export $(egrep -v "^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)" "$env_file")
fi
status "Installing dependencies"
# Make npm output to STDOUT instead of its default STDERR
npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent
)
status "Caching node_modules directory for future builds" status "Caching node_modules directory for future builds"
rm -rf $cache_dir/node_modules rm -rf $cache_dir/node_modules
......
...@@ -104,6 +104,27 @@ testProcfileAbsentNpmStartAbsent() { ...@@ -104,6 +104,27 @@ testProcfileAbsentNpmStartAbsent() {
assertCapturedSuccess assertCapturedSuccess
} }
testProcfileAbsentNpmStartPresent() {
compile "procfile-absent-npm-start-present"
assertCaptured "No Procfile found; Adding npm start to new Procfile"
assertFile "web: npm start" "Procfile"
assertCapturedSuccess
}
testEnvfileNotImported() {
compile "stable-node"
assertNotCaptured "Importing application config vars"
assertCapturedSuccess
}
testEnvfileImported() {
env_file=$(mktemp)
echo "FOO=1" > $env_file
compile "stable-node" "$(mktmpdir)" $env_file
assertCaptured "Importing application config vars"
assertCapturedSuccess
}
# Utils # Utils
pushd $(dirname 0) >/dev/null pushd $(dirname 0) >/dev/null
...@@ -128,7 +149,7 @@ compile_dir="" ...@@ -128,7 +149,7 @@ compile_dir=""
compile() { compile() {
compile_dir=$(mktmpdir) compile_dir=$(mktmpdir)
cp -r ${bp_dir}/test/$1/. ${compile_dir} 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() { assertFile() {
......
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