Skip to content
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
2 changes: 1 addition & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ rm -f gutenberg.zip
php bin/generate-gutenberg-php.php > gutenberg.tmp.php
mv gutenberg.tmp.php gutenberg.php

build_files=$(ls **/build/*.{js,css})
build_files=$(ls build/*/*.{js,css})

# Generate the plugin zip file
status "Creating archive..."
Expand Down
29 changes: 12 additions & 17 deletions edit-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { get, isString, some } from 'lodash';
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/core-blocks';
import domReady from '@wordpress/dom-ready';
import { render, unmountComponentAtNode } from '@wordpress/element';
import { deprecated } from '@wordpress/utils';

Expand Down Expand Up @@ -83,25 +82,21 @@ export function initializeEditor( id, post, settings ) {
);
}

return new Promise( ( resolve ) => {
domReady( () => {
const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );
const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );

registerCoreBlocks();
registerCoreBlocks();

render(
<Editor settings={ migratedSettings || settings } onError={ reboot } post={ post } />,
target
);
render(
<Editor settings={ migratedSettings || settings } onError={ reboot } post={ post } />,
target
);

resolve( {
initializeMetaBoxes( metaBoxes ) {
store.dispatch( initializeMetaBoxState( metaBoxes ) );
},
} );
} );
} );
return {
initializeMetaBoxes( metaBoxes ) {
store.dispatch( initializeMetaBoxState( metaBoxes ) );
},
};
}

export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function gutenberg_build_files_notice() {
* @since 1.5.0
*/
function gutenberg_pre_init() {
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/blocks/build' ) ) {
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
add_action( 'admin_notices', 'gutenberg_build_files_notice' );
return;
}
Expand Down
177 changes: 112 additions & 65 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,72 @@ function gutenberg_get_script_polyfill( $tests ) {
function gutenberg_register_scripts_and_styles() {
gutenberg_register_vendor_scripts();

// Editor Scripts.
// WordPress packages.
wp_register_script(
'wp-dom-ready',
gutenberg_url( 'build/dom-ready/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/dom-ready/index.js' ),
true
);
wp_register_script(
'wp-a11y',
gutenberg_url( 'build/a11y/index.js' ),
array( 'wp-dom-ready' ),
filemtime( gutenberg_dir_path() . 'build/a11y/index.js' ),
true
);
wp_register_script(
'wp-hooks',
gutenberg_url( 'build/hooks/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/hooks/index.js' ),
true
);
wp_register_script(
'wp-i18n',
gutenberg_url( 'build/i18n/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/i18n/index.js' ),
true
);
wp_register_script(
'wp-is-shallow-equal',
gutenberg_url( 'is-shallow-equal/build/index.js' ),
gutenberg_url( 'build/is-shallow-equal/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'is-shallow-equal/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/is-shallow-equal/index.js' ),
true
);

// Editor Scripts.
wp_register_script(
'wp-data',
gutenberg_url( 'data/build/index.js' ),
gutenberg_url( 'build/data/index.js' ),
array( 'wp-element', 'wp-utils', 'wp-is-shallow-equal', 'lodash' ),
filemtime( gutenberg_dir_path() . 'data/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/data/index.js' ),
true
);
wp_register_script(
'wp-core-data',
gutenberg_url( 'core-data/build/index.js' ),
gutenberg_url( 'build/core-data/index.js' ),
array( 'wp-data', 'wp-api-request', 'lodash' ),
filemtime( gutenberg_dir_path() . 'core-data/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/core-data/index.js' ),
true
);
wp_register_script(
'wp-utils',
gutenberg_url( 'utils/build/index.js' ),
gutenberg_url( 'build/utils/index.js' ),
array( 'tinymce-latest', 'lodash' ),
filemtime( gutenberg_dir_path() . 'utils/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/utils/index.js' ),
true
);
wp_add_inline_script( 'wp-utils', 'var originalUtils = window.wp && window.wp.utils ? window.wp.utils : {};', 'before' );
wp_add_inline_script( 'wp-utils', 'for ( var key in originalUtils ) wp.utils[ key ] = originalUtils[ key ];' );
wp_register_script(
'wp-hooks',
gutenberg_url( 'hooks/build/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'hooks/build/index.js' ),
true
);
wp_register_script(
'wp-date',
gutenberg_url( 'date/build/index.js' ),
gutenberg_url( 'build/date/index.js' ),
array( 'moment' ),
filemtime( gutenberg_dir_path() . 'date/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/date/index.js' ),
true
);
global $wp_locale;
Expand Down Expand Up @@ -146,30 +169,33 @@ function gutenberg_register_scripts_and_styles() {
'string' => get_option( 'timezone_string', 'UTC' ),
),
) ), 'before' );
wp_register_script(
'wp-i18n',
gutenberg_url( 'i18n/build/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'i18n/build/index.js' ),
true
);
wp_register_script(
'wp-element',
gutenberg_url( 'element/build/index.js' ),
gutenberg_url( 'build/element/index.js' ),
array( 'react', 'react-dom', 'wp-utils', 'wp-is-shallow-equal', 'lodash' ),
filemtime( gutenberg_dir_path() . 'element/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/element/index.js' ),
true
);
wp_register_script(
'wp-components',
gutenberg_url( 'components/build/index.js' ),
array( 'wp-element', 'wp-i18n', 'wp-utils', 'wp-hooks', 'wp-api-request', 'wp-is-shallow-equal', 'moment', 'lodash' ),
filemtime( gutenberg_dir_path() . 'components/build/index.js' ),
gutenberg_url( 'build/components/index.js' ),
array(
'lodash',
'moment',
'wp-a11y',
'wp-api-request',
'wp-element',
'wp-hooks',
'wp-i18n',
'wp-is-shallow-equal',
'wp-utils',
),
filemtime( gutenberg_dir_path() . 'build/components/index.js' ),
true
);
wp_register_script(
'wp-blocks',
gutenberg_url( 'blocks/build/index.js' ),
gutenberg_url( 'build/blocks/index.js' ),
array(
'wp-element',
'wp-components',
Expand All @@ -185,7 +211,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-core-data',
'lodash',
),
filemtime( gutenberg_dir_path() . 'blocks/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/blocks/index.js' ),
true
);
wp_add_inline_script(
Expand All @@ -198,16 +224,16 @@ function gutenberg_register_scripts_and_styles() {
);
wp_register_script(
'wp-viewport',
gutenberg_url( 'viewport/build/index.js' ),
gutenberg_url( 'build/viewport/index.js' ),
array( 'wp-element', 'wp-data', 'wp-components', 'lodash' ),
filemtime( gutenberg_dir_path() . 'viewport/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/viewport/index.js' ),
true
);
wp_register_script(
'wp-core-blocks',
gutenberg_url( 'core-blocks/build/index.js' ),
gutenberg_url( 'build/core-blocks/index.js' ),
array( 'wp-element', 'wp-components', 'wp-utils', 'wp-blocks', 'wp-i18n', 'editor', 'wp-core-data', 'lodash' ),
filemtime( gutenberg_dir_path() . 'core-blocks/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/core-blocks/index.js' ),
true
);
// Loading the old editor and its config to ensure the classic block works as expected.
Expand Down Expand Up @@ -281,33 +307,52 @@ function gutenberg_register_scripts_and_styles() {

wp_register_script(
'wp-editor',
gutenberg_url( 'editor/build/index.js' ),
gutenberg_url( 'build/editor/index.js' ),
array(
'postbox',
'editor',
'jquery',
'lodash',
'postbox',
'wp-a11y',
'wp-api',
'wp-blocks',
'wp-components',
'wp-core-data',
'wp-data',
'wp-date',
'wp-i18n',
'wp-blocks',
'wp-element',
'wp-components',
'wp-plugins',
'wp-utils',
'wp-viewport',
'wp-plugins',
'wp-core-data',
'editor',
'lodash',
),
filemtime( gutenberg_dir_path() . 'editor/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/editor/index.js' ),
true
);

wp_register_script(
'wp-edit-post',
gutenberg_url( 'edit-post/build/index.js' ),
array( 'jquery', 'media-views', 'media-models', 'wp-element', 'wp-components', 'wp-editor', 'wp-i18n', 'wp-date', 'wp-utils', 'wp-data', 'wp-embed', 'wp-viewport', 'wp-plugins', 'wp-core-blocks', 'lodash' ),
filemtime( gutenberg_dir_path() . 'edit-post/build/index.js' ),
gutenberg_url( 'build/edit-post/index.js' ),
array(
'jquery',
'lodash',
'media-models',
'media-views',
'wp-a11y',
'wp-components',
'wp-core-blocks',
'wp-date',
'wp-data',
'wp-dom-ready',
'wp-editor',
'wp-element',
'wp-embed',
'wp-i18n',
'wp-plugins',
'wp-viewport',
'wp-utils',
),
filemtime( gutenberg_dir_path() . 'build/edit-post/index.js' ),
true
);
wp_add_inline_script(
Expand All @@ -324,57 +369,57 @@ function gutenberg_register_scripts_and_styles() {

wp_register_style(
'wp-editor',
gutenberg_url( 'editor/build/style.css' ),
gutenberg_url( 'build/editor/style.css' ),
array( 'wp-components', 'wp-blocks', 'wp-editor-font' ),
filemtime( gutenberg_dir_path() . 'editor/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
);
wp_style_add_data( 'wp-editor', 'rtl', 'replace' );

wp_register_style(
'wp-edit-post',
gutenberg_url( 'edit-post/build/style.css' ),
gutenberg_url( 'build/edit-post/style.css' ),
array( 'wp-components', 'wp-editor', 'wp-edit-blocks', 'wp-core-blocks' ),
filemtime( gutenberg_dir_path() . 'edit-post/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/edit-post/style.css' )
);
wp_style_add_data( 'wp-edit-post', 'rtl', 'replace' );

wp_register_style(
'wp-components',
gutenberg_url( 'components/build/style.css' ),
gutenberg_url( 'build/components/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'components/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/components/style.css' )
);
wp_style_add_data( 'wp-components', 'rtl', 'replace' );

wp_register_style(
'wp-blocks',
gutenberg_url( 'blocks/build/style.css' ),
gutenberg_url( 'build/blocks/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'blocks/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/blocks/style.css' )
);
wp_style_add_data( 'wp-blocks', 'rtl', 'replace' );

wp_register_style(
'wp-core-blocks',
gutenberg_url( 'core-blocks/build/style.css' ),
gutenberg_url( 'build/core-blocks/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'core-blocks/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/core-blocks/style.css' )
);
wp_style_add_data( 'wp-core-blocks', 'rtl', 'replace' );

wp_register_style(
'wp-edit-blocks',
gutenberg_url( 'core-blocks/build/edit-blocks.css' ),
gutenberg_url( 'build/core-blocks/edit-blocks.css' ),
array( 'wp-components', 'wp-blocks' ),
filemtime( gutenberg_dir_path() . 'core-blocks/build/edit-blocks.css' )
filemtime( gutenberg_dir_path() . 'build/core-blocks/edit-blocks.css' )
);
wp_style_add_data( 'wp-edit-blocks', 'rtl', 'replace' );

wp_register_script(
'wp-plugins',
gutenberg_url( 'plugins/build/index.js' ),
gutenberg_url( 'build/plugins/index.js' ),
array( 'wp-element', 'wp-components', 'wp-utils', 'wp-data' ),
filemtime( gutenberg_dir_path() . 'plugins/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/plugins/index.js' )
);
}
add_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5 );
Expand Down Expand Up @@ -1002,9 +1047,11 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
$script .= sprintf( 'var editorSettings = %s;', wp_json_encode( $editor_settings ) );
$script .= <<<JS
window._wpLoadGutenbergEditor = new Promise( function( resolve ) {
wp.api.init().then( resolve );
} ).then( function() {
return wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings );
wp.api.init().then( function() {
wp.domReady.default( function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we calling default ? Is this an ES2015 module issue ? This should be called on as wp.domReady( fn );. Seems like a bug.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's the issue with how Webpack is configured. wp.domReady is an object with the current setup:

screen shot 2018-05-11 at 09 02 08

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dug into this a bit, and it's trickier than it appears on the surface.

This is what Webpack's output.libraryExport configuration is meant to support: Setting a specific property as the value assigned on the library target (window).

However, we have mixed needs: For something like wp.editor or wp.i18n, we want named exports to be respected, and assigned as nested properties within. For dom-ready though, the default export function should be assigned as wp.domReady.

In my head, it's as though we want libraryExport: 'default' when there are no other named exports, otherwise using the default _entry_return_.

So far as implementation, we might need to get our hands dirty with a custom Webpack plugin to achieve this. It probably needs to extend (whether via classical inheritance or just dynamically instantiating during apply, I'm uncertain) Webpack's ExportPropertyMainTemplatePlugin.js. Where I started having trouble was determining the exports of a module to decide what to assign as libraryExport.

@aduth aduth May 14, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alternative: have separate output configurations for specific edge-case modules like dom-ready, where we can assign libraryExport: 'default'. This too is not made very simple in an all-in-one Webpack configuration like we have.

Alternative alternative: Don't allow default exports on packages.

Alternative alternative alternative: Use CommonJS module.exports instead of export default from the packages implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alternative Alternative Alternative, assign the globals manually in "enqueues" importing things from the regular built modules :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Moving task to #6748 for further discussion.

resolve( wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings ) );
} );
} );
} );
JS;
$script .= '} )();';
Expand Down
Loading