Permalink
Browse files

Merge pull request #89 from heroku/env-file

Make config vars available to npm install
  • Loading branch information...
2 parents c962f1e + 8b280a2 commit 26c18bcef9c8429d70176ce14f4d9d208bffbd9f @zeke zeke committed Jan 7, 2014
Showing with 35 additions and 4 deletions.
  1. +13 −3 bin/compile
  2. +22 −1 bin/test
View
@@ -7,6 +7,8 @@ set -o pipefail # don't ignore exit codes when piping output
# Configure directories
build_dir=$1
cache_dir=$2
+env_file=$3
+
bp_dir=$(cd $(dirname $0); cd ..; pwd)
# Load some convenience functions like status(), echo(), and indent()
@@ -67,9 +69,17 @@ elif test -d $cache_dir/node_modules; then
npm prune 2>&1 | indent
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 [ "$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"
rm -rf $cache_dir/node_modules
View
@@ -104,6 +104,27 @@ 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
+}
+
+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
pushd $(dirname 0) >/dev/null
@@ -128,7 +149,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() {

0 comments on commit 26c18bc

Please sign in to comment.