Skip to content

Commit

Permalink
Merge pull request #173 from xwp/remove/wp-debug
Browse files Browse the repository at this point in the history
Replace WP_DEBUG with more appropriate flags
  • Loading branch information
westonruter authored Jan 28, 2020
2 parents f6800eb + 0eb58f7 commit baaf2e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ SKIP_ECHO_PATHS_SCOPE=1
if [[ ! -z $TRAVIS ]]; then
CHECK_SCOPE=all
fi
CHECK_SCOPE=all
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down

0 comments on commit baaf2e8

Please sign in to comment.