Unverified Commit 545b330b authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Improve bin/detect error messages (#575)

parent 549a36a9
#!/usr/bin/env bash #!/usr/bin/env bash
# bin/detect <build-dir> # bin/detect <build-dir>
error() {
local c="2,999 s/^/ ! /"
# send all of our output to stderr
exec 1>&2
echo -e "\033[1;31m" # bold; red
echo -n " ! ERROR: "
# this will be fed from stdin
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
echo -e "\033[0m" # reset style
exit 1
}
if [ -f $1/package.json ]; then if [ -f $1/package.json ]; then
echo 'Node.js' echo 'Node.js'
exit 0 exit 0
fi fi
>&2 echo 'Node.js: package.json not found in application root' if [[ -f "$1/.slugignore" ]] && grep -Fxq "package.json" "$1/.slugignore"; then
error << EOF
'package.json' listed in '.slugignore' file
The 'heroku/nodejs' buildpack is set on this application, but was
unable to detect a 'package.json' file. This is likely because
the '.slugignore' file is removing it before the build begins.
For more information, refer to the following documentation:
https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore
EOF
elif [[ -f "$1/.gitignore" ]] && grep -Fxq "package.json" "$1/.gitignore"; then
error << EOF
'package.json' listed in '.gitignore' file
The 'heroku/nodejs' buildpack is set on this application, but was
unable to detect a 'package.json' file. This is likely because
the '.gitignore' file is preventing it from being checked in to
the git repo.
For more information, refer to the following documentation:
https://devcenter.heroku.com/articles/gitignore
EOF
else
error <<- EOF
Application not supported by 'heroku/nodejs' buildpack
The 'heroku/nodejs' buildpack is set on this application, but was
unable to detect a Node.js codebase.
A Node.js app on Heroku requires a 'package.json' at the root of
the directory structure.
If you are trying to deploy a Node.js application, ensure that this
file is present at the top level directory. This directory has the
following files:
$(ls -1p $1)
If you are trying to deploy an application written in another
language, you need to change the list of buildpacks set on your
Heroku app using the 'heroku buildpacks' command.
For more information, refer to the following documentation:
https://devcenter.heroku.com/articles/buildpacks
https://devcenter.heroku.com/articles/nodejs-support#activation
EOF
fi
exit 1 exit 1
...@@ -990,6 +990,22 @@ testMemoryMetrics() { ...@@ -990,6 +990,22 @@ testMemoryMetrics() {
assertFileNotContains "measure#buildpack.nodejs.exec.heroku-postbuild.memory=" $metrics_log assertFileNotContains "measure#buildpack.nodejs.exec.heroku-postbuild.memory=" $metrics_log
} }
testBinDetectWarnings() {
detect "slugignore-package-json"
assertCapturedError "'package.json' listed in '.slugignore' file"
assertCapturedError "https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore"
detect "gitignore-package-json"
assertCapturedError "'package.json' listed in '.gitignore' file"
assertCapturedError "https://devcenter.heroku.com/articles/gitignore"
detect "node-project-missing-package-json"
assertCapturedError "Application not supported by 'heroku/nodejs' buildpack"
assertCapturedError "https://devcenter.heroku.com/articles/nodejs-support#activation"
assertCapturedError "index.js"
assertCapturedError "src/"
}
# Utils # Utils
pushd "$(dirname 0)" >/dev/null pushd "$(dirname 0)" >/dev/null
...@@ -1018,6 +1034,15 @@ default_process_types_cleanup() { ...@@ -1018,6 +1034,15 @@ default_process_types_cleanup() {
fi fi
} }
detect() {
default_process_types_cleanup
bp_dir=$(mktmpdir)
compile_dir=$(mktmpdir)
cp -a "$(pwd)"/* ${bp_dir}
cp -a ${bp_dir}/test/fixtures/$1/. ${compile_dir}
capture ${bp_dir}/bin/detect ${compile_dir}
}
compile() { compile() {
default_process_types_cleanup default_process_types_cleanup
bp_dir=$(mktmpdir) bp_dir=$(mktmpdir)
......
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