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

Script debug when version controlled #12457

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 14 additions & 6 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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?

);
}

if ( ! function_exists( 'register_tinymce_scripts' ) ) {
/**
* Registers the main TinyMCE scripts.
Expand All @@ -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 );
Expand Down Expand Up @@ -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 . ',
}
}';
Expand Down Expand Up @@ -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',
Expand All @@ -616,7 +624,7 @@ function gutenberg_register_vendor_scripts() {
'https://unpkg.com/react-dom@16.6.3/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/moment@2.22.1/' . $moment_script,
Expand Down