Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace WP_DEBUG with more appropriate flags #173

Merged
merged 5 commits into from
Jan 28, 2020
Merged

Conversation

westonruter
Copy link
Collaborator

@westonruter westonruter commented Jun 11, 2019

Fixes #170.

  • Use SCRIPT_DEBUG to indicate that non-production sources of Workbox should be used.
  • Look at PWA_VERSION instead of WP_DEBUG to determine if it is a dev version of the plugin.

By default the Workbox dev logs are disabled. To enable them, define this constant in the wp-config.php:

define( 'WP_SERVICE_WORKER_DEBUG_LOG', true );

This only has any effect when SCRIPT_DEBUG is also enabled, as it causes the Workbox dev scripts to be used. When constant is present, the service worker will have the __WB_DISABLE_DEV_LOGS variable set which causes Workbox to not output the noisy logging messages. For more on that, GoogleChrome/workbox#1619 (comment).

@westonruter westonruter added this to the 0.4 milestone Jan 28, 2020
@westonruter westonruter marked this pull request as ready for review January 28, 2020 05:15
$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 );
$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 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't be appended - likely an oversight :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in 22605b4.

$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";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@iandunn
Copy link
Collaborator

iandunn commented Jan 28, 2020

That approach sounds good to me, thanks!

@westonruter westonruter merged commit baaf2e8 into master Jan 28, 2020
@westonruter westonruter deleted the remove/wp-debug branch January 28, 2020 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workbox debug messages clutter console
3 participants