-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Script debug when version controlled #12457
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -66,6 +66,14 @@ function gutenberg_get_script_polyfill( $tests ) { | |
return $polyfill; | ||
} | ||
|
||
|
||
function gutenberg_script_debug() { | ||
return ( | ||
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || | ||
file_exists( gutenberg_dir_path() . '.git' ) | ||
); | ||
} | ||
|
||
if ( ! function_exists( 'register_tinymce_scripts' ) ) { | ||
/** | ||
* Registers the main TinyMCE scripts. | ||
|
@@ -75,11 +83,11 @@ function register_tinymce_scripts() { | |
if ( ! isset( $concatenate_scripts ) ) { | ||
script_concat_settings(); | ||
} | ||
$suffix = SCRIPT_DEBUG ? '' : '.min'; | ||
$suffix = gutenberg_script_debug() ? '' : '.min'; | ||
$compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) | ||
&& false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ); | ||
// Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production) or | ||
// tinymce.min.js (when SCRIPT_DEBUG is true). | ||
// tinymce.min.js (when gutenberg_script_debug() is true). | ||
$mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min'; | ||
if ( $compressed ) { | ||
gutenberg_override_script( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.php', array(), $tinymce_version ); | ||
|
@@ -383,7 +391,7 @@ function gutenberg_register_scripts_and_styles() { | |
$script = 'window.wpEditorL10n = { | ||
tinymce: { | ||
baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ', | ||
suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ', | ||
suffix: ' . ( gutenberg_script_debug() ? '""' : '".min"' ) . ', | ||
settings: ' . $init_obj . ', | ||
} | ||
}'; | ||
|
@@ -601,10 +609,10 @@ function gutenberg_preload_api_request( $memo, $path ) { | |
* @since 0.1.0 | ||
*/ | ||
function gutenberg_register_vendor_scripts() { | ||
$suffix = SCRIPT_DEBUG ? '' : '.min'; | ||
$suffix = gutenberg_script_debug() ? '' : '.min'; | ||
|
||
// Vendor Scripts. | ||
$react_suffix = ( SCRIPT_DEBUG ? '.development' : '.production' ) . $suffix; | ||
$react_suffix = ( gutenberg_script_debug() ? '.development' : '.production' ) . $suffix; | ||
|
||
gutenberg_register_vendor_script( | ||
'react', | ||
|
@@ -616,7 +624,7 @@ function gutenberg_register_vendor_scripts() { | |
'https://unpkg.com/[email protected]/umd/react-dom' . $react_suffix . '.js', | ||
array( 'react' ) | ||
); | ||
$moment_script = SCRIPT_DEBUG ? 'moment.js' : 'min/moment.min.js'; | ||
$moment_script = gutenberg_script_debug() ? 'moment.js' : 'min/moment.min.js'; | ||
gutenberg_register_vendor_script( | ||
'moment', | ||
'https://unpkg.com/[email protected]/' . $moment_script, | ||
|
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.
What if, in the course of development, I do want to test with minified souces? Switching on the existence of
.git
seems like a very inflexible method.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.
The same is true if we set it in the Docker config: you'd need to edit the config.
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.
An environment variable seems the best option here; why not have
MINIFY_JS
,SCRIPT_DEBUG
, or something else, be an env var we could check for?