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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


// 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