From ff16087b2825dc46bbe30b311121360fb06eb4b2 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 24 May 2019 13:48:30 -0500 Subject: [PATCH] Compser: Read once, fail gracefully (and more) (#12442) * Read once, fail gracefully * Improve inline comment * Adding more inline documentation on the loading process. * run composer install on build scripts * Remove extra slash `JETPACK__PLUGIN_DIR` already has a trailing slash. * Restore @jeherve's original soft fallback for unbuilt Jetpack. This reverts commit 77ee45f9643c4280ccd0efb15d28774ff76e8d12. * Update inline docs at 0238eab32222d21deda286d55b3551c2af48ee7b --- jetpack.php | 20 ++++++++++++++++++-- tools/build-jetpack.sh | 9 +++++++++ tools/build-release-branch.sh | 9 +++++++++ tools/deploy-to-master-stable-branch.sh | 9 +++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/jetpack.php b/jetpack.php index 695b37db5211c..2036ecb672e52 100644 --- a/jetpack.php +++ b/jetpack.php @@ -149,6 +149,17 @@ function jetpack_admin_missing_autoloader() { ?> return; } -// Load all the packages. -$jetpack_autoloader = JETPACK__PLUGIN_DIR . '/vendor/autoload.php'; +/** + * Load all the packages. + * + * We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader. + * If the autoloader is not present, let's log the failure, pause Jetpack, and display a nice admin notice. + */ +$jetpack_autoloader = JETPACK__PLUGIN_DIR . 'vendor/autoload.php'; if ( is_readable( $jetpack_autoloader ) ) { require $jetpack_autoloader; } else { diff --git a/tools/build-jetpack.sh b/tools/build-jetpack.sh index 3088299d6ce84..974c810dc2003 100755 --- a/tools/build-jetpack.sh +++ b/tools/build-jetpack.sh @@ -56,6 +56,15 @@ if [[ $ADD_BETA_VERSION -eq 1 ]]; then echo "Now at version $CURRENT_VERSION!" fi +# Checking for composer +hash composer 2>/dev/null || { + echo >&2 "This script requires you to have composer package manager installed." + echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting."; + exit 1; +} + +composer --cwd $TARGET_DIR install + # Checking for yarn hash yarn 2>/dev/null || { echo >&2 "This script requires you to have yarn package manager installed." diff --git a/tools/build-release-branch.sh b/tools/build-release-branch.sh index cc0634681e33f..d448a23c44766 100755 --- a/tools/build-release-branch.sh +++ b/tools/build-release-branch.sh @@ -204,6 +204,15 @@ echo "" echo "Building Jetpack" +# Checking for composer +hash composer 2>/dev/null || { + echo >&2 "This script requires you to have composer package manager installed." + echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting."; + exit 1; +} + +composer install + # Checking for yarn hash yarn 2>/dev/null || { echo >&2 "This script requires you to have yarn package manager installed." diff --git a/tools/deploy-to-master-stable-branch.sh b/tools/deploy-to-master-stable-branch.sh index 5d9ba4fdc23f9..b73fce90bb7b9 100755 --- a/tools/deploy-to-master-stable-branch.sh +++ b/tools/deploy-to-master-stable-branch.sh @@ -41,6 +41,15 @@ echo "" echo "Building Jetpack" +# Checking for composer +hash composer 2>/dev/null || { + echo >&2 "This script requires you to have composer package manager installed." + echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting."; + exit 1; +} + +composer install + # Checking for yarn hash yarn 2>/dev/null || { echo >&2 "This script requires you to have yarn package manager installed."