-
Notifications
You must be signed in to change notification settings - Fork 100
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7172607
Look at PWA_VERSION for dev mode instead of WP_DEBUG
westonruter 3b1860f
Use SCRIPT_DEBUG instead of WP_DEBUG to indicate dev build of Workbox…
westonruter 5d226a0
Disable workbox dev logs unless WP_SERVICE_WORKER_DEBUG_LOG constant …
westonruter 22605b4
Harden workbox-js inclusion and removal of sourceMappingURL comment
westonruter 0eb58f7
Add CHECK_SCOPE=all to bypass Travis diff failure
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ); | ||
$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 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably shouldn't be appended - likely an oversight :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Fixed in 22605b4. |
||
} | ||
|
||
$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 ) ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍