diff --git a/.dev-lib b/.dev-lib index 7bbbf3eb8..5f3bdb2be 100644 --- a/.dev-lib +++ b/.dev-lib @@ -5,3 +5,4 @@ SKIP_ECHO_PATHS_SCOPE=1 if [[ ! -z $TRAVIS ]]; then CHECK_SCOPE=all fi +CHECK_SCOPE=all diff --git a/wp-includes/components/class-wp-service-worker-configuration-component.php b/wp-includes/components/class-wp-service-worker-configuration-component.php index 9ea9984f6..b1e0c2547 100644 --- a/wp-includes/components/class-wp-service-worker-configuration-component.php +++ b/wp-includes/components/class-wp-service-worker-configuration-component.php @@ -54,20 +54,26 @@ public function get_script() { $current_scope = wp_service_workers()->get_current_scope(); $workbox_dir = 'wp-includes/js/workbox/'; - if ( WP_DEBUG ) { + $script = ''; + if ( SCRIPT_DEBUG ) { + $enable_debug_log = defined( 'WP_SERVICE_WORKER_DEBUG_LOG' ) && WP_SERVICE_WORKER_DEBUG_LOG; + if ( ! $enable_debug_log ) { + $script .= "self.__WB_DISABLE_DEV_LOGS = true;\n"; + } + // Load with importScripts() so that source map is available. - $script = sprintf( + $script .= sprintf( "importScripts( %s );\n", wp_service_worker_json_encode( PWA_PLUGIN_URL . $workbox_dir . 'workbox-sw.js' ) ); } else { // Inline the workbox-sw.js to avoid an additional HTTP request. - $script = file_get_contents( PWA_PLUGIN_DIR . '/' . $workbox_dir . 'workbox-sw.js' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - $script = preg_replace( '://# sourceMappingURL=.+?\.map:', '', $script ); + $wbjs = file_get_contents( PWA_PLUGIN_DIR . '/' . $workbox_dir . 'workbox-sw.js' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + $script .= preg_replace( '://# sourceMappingURL=.+?\.map\s*$:s', '', $wbjs ); } $options = array( - 'debug' => WP_DEBUG, + 'debug' => SCRIPT_DEBUG, // When true, the dev builds are loaded. Otherwise, the prod builds are used. 'modulePathPrefix' => PWA_PLUGIN_URL . $workbox_dir, ); $script .= sprintf( "workbox.setConfig( %s );\n", wp_service_worker_json_encode( $options ) ); diff --git a/wp-includes/components/class-wp-service-worker-navigation-routing-component.php b/wp-includes/components/class-wp-service-worker-navigation-routing-component.php index 5b44cd24e..19e97d6db 100644 --- a/wp-includes/components/class-wp-service-worker-navigation-routing-component.php +++ b/wp-includes/components/class-wp-service-worker-navigation-routing-component.php @@ -189,7 +189,9 @@ public function serve( WP_Service_Worker_Scripts $scripts ) { $caching_strategy = WP_Service_Worker_Caching_Routes::STRATEGY_NETWORK_ONLY; $revision = PWA_VERSION; - if ( WP_DEBUG ) { + + // Force revision to be extra fresh during development (e.g. when PWA_VERSION is x.y-alpha). + if ( false !== strpos( PWA_VERSION, '-' ) ) { $revision .= filemtime( PWA_PLUGIN_DIR . '/wp-admin/error.php' ); $revision .= filemtime( PWA_PLUGIN_DIR . '/wp-includes/service-workers.php' ); }