Unverified Commit f6d55d63 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Allow user opt in to build script default behavior (#585)

This checks the user's package.json for a heroku-run-build-script key. If it is set to true the new build step will be run instead of the old step, and a message will be printed at the beginning of the build to confirm that is the case.
parent 437b5f1c
......@@ -62,9 +62,6 @@ trap 'handle_failure' ERR
[ -f "$BUILD_DIR/yarn.lock" ] && YARN=true || YARN=false
[ -f "$BUILD_DIR/package-lock.json" ] && NPM_LOCK=true || NPM_LOCK=false
### Behavior flags
[ ! "$NEW_BUILD_SCRIPT_BEHAVIOR" ] && NEW_BUILD_SCRIPT_BEHAVIOR=false
### Failures that should be caught immediately
fail_dot_heroku "$BUILD_DIR"
......@@ -74,6 +71,10 @@ fail_multiple_lockfiles "$BUILD_DIR"
warn_prebuilt_modules "$BUILD_DIR"
warn_missing_package_json "$BUILD_DIR"
### Behavior flags
[ ! "$NEW_BUILD_SCRIPT_BEHAVIOR" ] && NEW_BUILD_SCRIPT_BEHAVIOR=$(read_json "$BUILD_DIR/package.json" ".[\"heroku-run-build-script\"]")
warn_build_script_behavior_opt_in $NEW_BUILD_SCRIPT_BEHAVIOR | output "$LOG_FILE"
### Compile
create_env() {
......
......@@ -46,6 +46,17 @@ run_build_script() {
fi
}
warn_build_script_behavior_opt_in() {
local opted_in="$1"
if [[ "$opted_in" = true ]]; then
header "Opting in to new default build script behavior"
echo "You have set \"heroku-run-build-script\" = true in your package.json"
echo ""
echo "- If a \"build\" script is defined in package.json it will be executed by default"
echo "- The \"heroku-postbuild\" script will be executed instead if present"
fi
}
log_build_scripts() {
local build=$(read_json "$BUILD_DIR/package.json" ".scripts[\"build\"]")
local heroku_prebuild=$(read_json "$BUILD_DIR/package.json" ".scripts[\"heroku-prebuild\"]")
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "10.x"
},
"scripts" : {
"build" : "echo build hook message"
},
"heroku-run-build-script": true
}
......@@ -26,6 +26,13 @@ testBuildScriptBehavior() {
assertCapturedSuccess
}
testBuildScriptOptIn() {
compile "build-script-opt-in"
assertCaptured "Running build"
assertCaptured "Opting in to new default build script behavior"
assertCapturedSuccess
}
testPrePostBuildScripts() {
compile "pre-post-build-scripts"
assertCaptured "Running heroku-prebuild"
......
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