Unverified Commit 827e960b authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Run the build script by default (#628)

* Run the build script by default

This removes the opt-in behavior and defaults users into running
the "build" script by default. Users that were opted-in will see
no change
parent ecfd9a04
...@@ -100,10 +100,6 @@ fail_multiple_lockfiles "$BUILD_DIR" ...@@ -100,10 +100,6 @@ fail_multiple_lockfiles "$BUILD_DIR"
warn_prebuilt_modules "$BUILD_DIR" warn_prebuilt_modules "$BUILD_DIR"
warn_missing_package_json "$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\"]")
### Compile ### Compile
create_env() { create_env() {
...@@ -256,7 +252,6 @@ build_dependencies() { ...@@ -256,7 +252,6 @@ build_dependencies() {
mtime "modules.time.cache.$cache_status" "${start}" mtime "modules.time.cache.$cache_status" "${start}"
if [[ "$NEW_BUILD_SCRIPT_BEHAVIOR" = true ]]; then
if $YARN; then if $YARN; then
header "Build" header "Build"
else else
...@@ -264,13 +259,7 @@ build_dependencies() { ...@@ -264,13 +259,7 @@ build_dependencies() {
# without skipping the newline there's an awkward double line break # without skipping the newline there's an awkward double line break
header_skip_newline "Build" header_skip_newline "Build"
fi fi
mcount "build-script.new-behavior"
run_build_script "$BUILD_DIR" run_build_script "$BUILD_DIR"
else
mcount "build-script.legacy-behavior"
run_if_present "$BUILD_DIR" 'heroku-postbuild'
fi
log_build_scripts "$BUILD_DIR" log_build_scripts "$BUILD_DIR"
} }
...@@ -330,8 +319,4 @@ warn_no_start "$BUILD_DIR" ...@@ -330,8 +319,4 @@ warn_no_start "$BUILD_DIR"
warn_unmet_dep "$LOG_FILE" warn_unmet_dep "$LOG_FILE"
warn_old_npm_lockfile $NPM_LOCK warn_old_npm_lockfile $NPM_LOCK
warn_build_script_behavior_change "$NEW_BUILD_SCRIPT_BEHAVIOR" "$BUILD_DIR"
warn_build_script_behavior_opt_in "$NEW_BUILD_SCRIPT_BEHAVIOR" | output "$LOG_FILE"
log_build_script_opt_in "$NEW_BUILD_SCRIPT_BEHAVIOR" "$BUILD_DIR"
log_build_data >> "$BUILDPACK_LOG_FILE" log_build_data >> "$BUILDPACK_LOG_FILE"
...@@ -60,41 +60,6 @@ run_build_script() { ...@@ -60,41 +60,6 @@ run_build_script() {
fi 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 "Your app will be unaffected by the change on March 11, 2019"
echo ""
mcount "build-change-opt-in"
fi
}
warn_build_script_behavior_change() {
local opted_in="$1"
local build_dir="$2"
local has_build_script has_heroku_build_script
has_build_script=$(read_json "$build_dir/package.json" ".scripts.build")
has_heroku_build_script=$(read_json "$build_dir/package.json" ".scripts[\"heroku-postbuild\"]")
if [[ -z "$has_heroku_build_script" ]] && [[ -n "$has_build_script" ]] && [[ "$opted_in" != "true" ]]; then
bright_header "Change to Node.js build process"
echo "On March 11, 2019 Heroku will begin executing the \"build\" script defined in package.json"
echo "by default. This application may be affected by this change."
echo ""
echo "To make this transition easier, we've published a tool that will automatically"
echo "update your app for you. You can run it with one command in your app's"
echo "root directory:"
echo ""
echo "$ npx @heroku/update-node-build-script"
echo ""
echo "Please see https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq for more information"
echo ""
fi
}
log_build_scripts() { log_build_scripts() {
local build heroku_prebuild heroku_postbuild postinstall local build heroku_prebuild heroku_postbuild postinstall
local build_dir=${1:-} local build_dir=${1:-}
......
...@@ -23,31 +23,3 @@ generate_uuids() { ...@@ -23,31 +23,3 @@ generate_uuids() {
bd_set "app-uuid" "$(uuid)" bd_set "app-uuid" "$(uuid)"
fi fi
} }
log_build_script_opt_in() {
local opted_in="$1"
local build_dir="$2"
local has_build_script has_heroku_build_script
has_build_script=$(read_json "$build_dir/package.json" ".scripts.build")
has_heroku_build_script=$(read_json "$build_dir/package.json" ".scripts[\"heroku-postbuild\"]")
# if this app will be affected by the change
if [[ -z "$has_heroku_build_script" ]] && [[ -n "$has_build_script" ]]; then
mcount "affected-by-build-change"
if [[ "$opted_in" = "true" ]]; then
mcount "affected-by-build-change-opted-in"
bd_set "affected-but-opted-in" "true"
else
bd_set "affected-but-opted-in" "false"
fi
fi
if [[ "$opted_in" = true ]]; then
bd_set "build-script-opt-in" "true"
else
bd_set "build-script-opt-in" "false"
fi
}
\ No newline at end of file
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
}
...@@ -12,6 +12,5 @@ ...@@ -12,6 +12,5 @@
"scripts" : { "scripts" : {
"build": "echo build hook message", "build": "echo build hook message",
"heroku-postbuild": "echo heroku-postbuild hook message" "heroku-postbuild": "echo heroku-postbuild hook message"
}, }
"heroku-run-build-script": true
} }
...@@ -9,6 +9,5 @@ ...@@ -9,6 +9,5 @@
"scripts" : { "scripts" : {
"build" : "echo build hook message" "build" : "echo build hook message"
}, },
"heroku-run-build-script": true,
"license": "MIT" "license": "MIT"
} }
...@@ -9,6 +9,5 @@ ...@@ -9,6 +9,5 @@
"scripts" : { "scripts" : {
"build" : "echo build hook message", "build" : "echo build hook message",
"heroku-postbuild": "" "heroku-postbuild": ""
}, }
"heroku-run-build-script": true
} }
...@@ -12,6 +12,5 @@ ...@@ -12,6 +12,5 @@
"scripts" : { "scripts" : {
"build" : "echo build hook message", "build" : "echo build hook message",
"heroku-postbuild": "" "heroku-postbuild": ""
}, }
"heroku-run-build-script": true
} }
...@@ -2,17 +2,16 @@ ...@@ -2,17 +2,16 @@
"name": "node-buildpack-test-app", "name": "node-buildpack-test-app",
"version": "0.0.1", "version": "0.0.1",
"description": "node buildpack integration test app", "description": "node buildpack integration test app",
"repository" : { "repository": {
"type" : "git", "type": "git",
"url" : "http://github.com/example/example.git" "url": "http://github.com/example/example.git"
}, },
"engines": { "engines": {
"node": "10.x" "node": "10.x"
}, },
"scripts" : { "scripts": {
"build" : "echo build hook message", "build": "echo build hook message",
"heroku-postbuild": "", "heroku-postbuild": "",
"random-script-name": "" "random-script-name": ""
}, }
"heroku-run-build-script": true
} }
...@@ -15,34 +15,9 @@ testFlatmapStream() { ...@@ -15,34 +15,9 @@ testFlatmapStream() {
assertCapturedError assertCapturedError
} }
testBuildScriptWarning() {
local env_dir=$(mktmpdir)
local metrics_log=$(mktemp)
echo "$metrics_log" > $env_dir/BUILDPACK_LOG_FILE
compile "build-script" "$(mktmpdir)" $env_dir
# Without opting in, having a build script will display a warning
assertCaptured "On March 11, 2019 Heroku will begin executing the \"build\" script defined in package.json"
assertCaptured "https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq"
# make sure metrics are being captured as we expect
assertFileContains "count#buildpack.nodejs.affected-by-build-change=1" "$metrics_log"
assertFileNotContains "affected-by-build-change-opted-in" "$metrics_log"
# We shouldn't see the opt-in success message
assertNotCaptured "Opting in to new default build script behavior"
assertCapturedSuccess
}
testBuildScriptBehavior() { testBuildScriptBehavior() {
# opt in to new build script behavior
cache=$(mktmpdir)
env_dir=$(mktmpdir)
echo "true" > $env_dir/NEW_BUILD_SCRIPT_BEHAVIOR
# The 'build' script is run by default # The 'build' script is run by default
compile "build-script" $cache $env_dir compile "build-script"
assertCaptured "Running build" assertCaptured "Running build"
assertCapturedSuccess assertCapturedSuccess
...@@ -53,27 +28,8 @@ testBuildScriptBehavior() { ...@@ -53,27 +28,8 @@ testBuildScriptBehavior() {
assertCapturedSuccess assertCapturedSuccess
} }
testBuildScriptOptIn() { testBuildScriptYarn() {
local env_dir=$(mktmpdir) compile "build-script-yarn"
local metrics_log=$(mktemp)
echo "$metrics_log" > $env_dir/BUILDPACK_LOG_FILE
compile "build-script-opt-in" "$(mktmpdir)" $env_dir
assertCaptured "Running build"
assertCaptured "Opting in to new default build script behavior"
# We shouldn't see this warning once they opt-in
assertNotCaptured "Warning: On March 11, 2019 Heroku will begin executing the \"build\" script defined in package.json by default"
assertNotCaptured "https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq"
# make sure metrics are being captured as we expect
assertFileContains "count#buildpack.nodejs.affected-by-build-change=1" "$metrics_log"
assertFileContains "count#buildpack.nodejs.affected-by-build-change-opted-in=1" "$metrics_log"
assertCapturedSuccess
}
testBuildScriptOptInYarn() {
compile "build-script-opt-in-yarn"
assertCaptured "Running build (yarn)" assertCaptured "Running build (yarn)"
assertCaptured "build hook message" assertCaptured "build hook message"
assertCapturedSuccess assertCapturedSuccess
......
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