Make WordPress Core

Ticket #48154: 49154.diff

File 49154.diff, 14.6 KB (added by gziolo, 5 years ago)
  • package.json

    diff --git a/package.json b/package.json
    index 3c11f67a55..11d556d0a6 100644
    a b  
    1414        "license": "GPL-2.0-or-later",
    1515        "devDependencies": {
    1616                "@wordpress/custom-templated-path-webpack-plugin": "1.5.0",
     17                "@wordpress/dependency-extraction-webpack-plugin": "2.0.0",
    1718                "@wordpress/e2e-test-utils": "2.4.0",
    1819                "@wordpress/library-export-default-webpack-plugin": "1.4.0",
    1920                "@wordpress/scripts": "5.0.0",
     
    6465                "@wordpress/api-fetch": "3.6.0",
    6566                "@wordpress/autop": "2.5.0",
    6667                "@wordpress/blob": "2.5.0",
     68                "@wordpress/block-directory": "1.0.0",
    6769                "@wordpress/block-editor": "3.2.0",
    6870                "@wordpress/block-library": "2.9.0",
    6971                "@wordpress/block-serialization-default-parser": "3.4.0",
  • src/wp-includes/script-loader.php

    diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
    index e203c26503..d477536377 100644
    a b function wp_get_script_polyfill( &$scripts, $tests ) { 
    223223function wp_default_packages_scripts( &$scripts ) {
    224224        $suffix = wp_scripts_get_suffix();
    225225
    226         $packages_versions = array(
    227                 'a11y'                               => '2.5.0',
    228                 'annotations'                        => '1.7.0',
    229                 'api-fetch'                          => '3.6.0',
    230                 'autop'                              => '2.5.0',
    231                 'blob'                               => '2.5.0',
    232                 'block-editor'                       => '3.2.0',
    233                 'block-library'                      => '2.9.0',
    234                 'block-serialization-default-parser' => '3.4.0',
    235                 'blocks'                             => '6.7.0',
    236                 'components'                         => '8.3.0',
    237                 'compose'                            => '3.7.0',
    238                 'core-data'                          => '2.7.0',
    239                 'data'                               => '4.9.0',
    240                 'data-controls'                      => '1.3.0',
    241                 'date'                               => '3.5.0',
    242                 'deprecated'                         => '2.6.0',
    243                 'dom'                                => '2.5.0',
    244                 'dom-ready'                          => '2.5.0',
    245                 'edit-post'                          => '3.8.0',
    246                 'editor'                             => '9.7.0',
    247                 'element'                            => '2.8.0',
    248                 'escape-html'                        => '1.5.0',
    249                 'format-library'                     => '1.9.0',
    250                 'hooks'                              => '2.6.0',
    251                 'html-entities'                      => '2.5.0',
    252                 'i18n'                               => '3.6.0',
    253                 'is-shallow-equal'                   => '1.6.0',
    254                 'keycodes'                           => '2.6.0',
    255                 'list-reusable-blocks'               => '1.8.0',
    256                 'media-utils'                        => '1.2.0',
    257                 'notices'                            => '1.8.0',
    258                 'nux'                                => '3.7.0',
    259                 'plugins'                            => '2.7.0',
    260                 'priority-queue'                     => '1.3.0',
    261                 'redux-routine'                      => '3.6.0',
    262                 'rich-text'                          => '3.7.0',
    263                 'shortcode'                          => '2.4.0',
    264                 'server-side-render'                 => '1.3.0',
    265                 'token-list'                         => '1.6.0',
    266                 'url'                                => '2.8.0',
    267                 'viewport'                           => '2.8.0',
    268                 'wordcount'                          => '2.6.0',
    269         );
    270 
    271         $packages_dependencies = array(
    272                 'a11y'                               => array(
    273                         'wp-dom-ready',
    274                         'wp-polyfill',
    275                 ),
    276                 'annotations'                        => array(
    277                         'lodash',
    278                         'wp-data',
    279                         'wp-hooks',
    280                         'wp-i18n',
    281                         'wp-polyfill',
    282                         'wp-rich-text',
    283                 ),
    284                 'api-fetch'                          => array(
    285                         'wp-i18n',
    286                         'wp-polyfill',
    287                         'wp-url',
    288                 ),
    289                 'autop'                              => array(
    290                         'wp-polyfill',
    291                 ),
    292                 'blob'                               => array(
    293                         'wp-polyfill',
    294                 ),
    295                 'block-editor'                       => array(
    296                         'lodash',
    297                         'wp-a11y',
    298                         'wp-blob',
    299                         'wp-blocks',
    300                         'wp-components',
    301                         'wp-compose',
    302                         'wp-data',
    303                         'wp-deprecated',
    304                         'wp-dom',
    305                         'wp-element',
    306                         'wp-hooks',
    307                         'wp-html-entities',
    308                         'wp-i18n',
    309                         'wp-is-shallow-equal',
    310                         'wp-keycodes',
    311                         'wp-polyfill',
    312                         'wp-rich-text',
    313                         'wp-token-list',
    314                         'wp-url',
    315                         'wp-viewport',
    316                         'wp-wordcount',
    317                 ),
    318                 'block-library'                      => array(
    319                         'editor',
    320                         'lodash',
    321                         'moment',
    322                         'wp-a11y',
    323                         'wp-api-fetch',
    324                         'wp-autop',
    325                         'wp-blob',
    326                         'wp-block-editor',
    327                         'wp-blocks',
    328                         'wp-components',
    329                         'wp-compose',
    330                         'wp-core-data',
    331                         'wp-data',
    332                         'wp-date',
    333                         'wp-deprecated',
    334                         'wp-editor',
    335                         'wp-element',
    336                         'wp-i18n',
    337                         'wp-is-shallow-equal',
    338                         'wp-keycodes',
    339                         'wp-polyfill',
    340                         'wp-rich-text',
    341                         'wp-server-side-render',
    342                         'wp-url',
    343                         'wp-viewport',
    344                 ),
    345                 'block-serialization-default-parser' => array(
    346                         'wp-polyfill',
    347                 ),
    348                 'blocks'                             => array(
    349                         'lodash',
    350                         'wp-autop',
    351                         'wp-blob',
    352                         'wp-block-serialization-default-parser',
    353                         'wp-compose',
    354                         'wp-data',
    355                         'wp-dom',
    356                         'wp-element',
    357                         'wp-hooks',
    358                         'wp-html-entities',
    359                         'wp-i18n',
    360                         'wp-is-shallow-equal',
    361                         'wp-polyfill',
    362                         'wp-shortcode',
    363                 ),
    364                 'components'                         => array(
    365                         'lodash',
    366                         'moment',
    367                         'wp-a11y',
    368                         'wp-compose',
    369                         'wp-deprecated',
    370                         'wp-dom',
    371                         'wp-element',
    372                         'wp-hooks',
    373                         'wp-i18n',
    374                         'wp-is-shallow-equal',
    375                         'wp-keycodes',
    376                         'wp-polyfill',
    377                         'wp-rich-text',
    378                 ),
    379                 'compose'                            => array(
    380                         'lodash',
    381                         'wp-element',
    382                         'wp-is-shallow-equal',
    383                         'wp-polyfill',
    384                 ),
    385                 'core-data'                          => array(
    386                         'lodash',
    387                         'wp-api-fetch',
    388                         'wp-data',
    389                         'wp-deprecated',
    390                         'wp-is-shallow-equal',
    391                         'wp-polyfill',
    392                         'wp-url',
    393                 ),
    394                 'data'                               => array(
    395                         'lodash',
    396                         'wp-compose',
    397                         'wp-deprecated',
    398                         'wp-element',
    399                         'wp-is-shallow-equal',
    400                         'wp-polyfill',
    401                         'wp-priority-queue',
    402                         'wp-redux-routine',
    403                 ),
    404                 'data-controls'                      => array(
    405                         'wp-api-fetch',
    406                         'wp-data',
    407                         'wp-polyfill',
    408                 ),
    409                 'date'                               => array(
    410                         'moment',
    411                         'wp-polyfill',
    412                 ),
    413                 'deprecated'                         => array(
    414                         'wp-hooks',
    415                         'wp-polyfill',
    416                 ),
    417                 'dom'                                => array(
    418                         'lodash',
    419                         'wp-polyfill',
    420                 ),
    421                 'dom-ready'                          => array(
    422                         'wp-polyfill',
    423                 ),
    424                 'edit-post'                          => array(
    425                         'lodash',
    426                         'postbox',
    427                         'media-models',
    428                         'media-views',
    429                         'wp-a11y',
    430                         'wp-api-fetch',
    431                         'wp-block-editor',
    432                         'wp-block-library',
    433                         'wp-blocks',
    434                         'wp-components',
    435                         'wp-compose',
    436                         'wp-core-data',
    437                         'wp-data',
    438                         'wp-dom-ready',
    439                         'wp-editor',
    440                         'wp-element',
    441                         'wp-hooks',
    442                         'wp-i18n',
    443                         'wp-keycodes',
    444                         'wp-media-utils',
    445                         'wp-notices',
    446                         'wp-nux',
    447                         'wp-plugins',
    448                         'wp-polyfill',
    449                         'wp-url',
    450                         'wp-viewport',
    451                 ),
    452                 'editor'                             => array(
    453                         'lodash',
    454                         'wp-api-fetch',
    455                         'wp-autop',
    456                         'wp-block-editor',
    457                         'wp-blocks',
    458                         'wp-components',
    459                         'wp-compose',
    460                         'wp-core-data',
    461                         'wp-data',
    462                         'wp-data-controls',
    463                         'wp-date',
    464                         'wp-deprecated',
    465                         'wp-element',
    466                         'wp-hooks',
    467                         'wp-html-entities',
    468                         'wp-i18n',
    469                         'wp-is-shallow-equal',
    470                         'wp-keycodes',
    471                         'wp-media-utils',
    472                         'wp-notices',
    473                         'wp-nux',
    474                         'wp-polyfill',
    475                         'wp-rich-text',
    476                         'wp-server-side-render',
    477                         'wp-url',
    478                         'wp-viewport',
    479                         'wp-wordcount',
    480                 ),
    481                 'element'                            => array(
    482                         'lodash',
    483                         'react',
    484                         'react-dom',
    485                         'wp-escape-html',
    486                         'wp-polyfill',
    487                 ),
    488                 'escape-html'                        => array(
    489                         'wp-polyfill',
    490                 ),
    491                 'format-library'                     => array(
    492                         'lodash',
    493                         'wp-block-editor',
    494                         'wp-components',
    495                         'wp-dom',
    496                         'wp-element',
    497                         'wp-html-entities',
    498                         'wp-i18n',
    499                         'wp-keycodes',
    500                         'wp-polyfill',
    501                         'wp-rich-text',
    502                         'wp-url',
    503                 ),
    504                 'hooks'                              => array(
    505                         'wp-polyfill',
    506                 ),
    507                 'html-entities'                      => array(
    508                         'wp-polyfill',
    509                 ),
    510                 'i18n'                               => array(
    511                         'wp-polyfill',
    512                 ),
    513                 'is-shallow-equal'                   => array(
    514                         'wp-polyfill',
    515                 ),
    516                 'keycodes'                           => array(
    517                         'lodash',
    518                         'wp-i18n',
    519                         'wp-polyfill',
    520                 ),
    521                 'list-reusable-blocks'               => array(
    522                         'lodash',
    523                         'wp-api-fetch',
    524                         'wp-components',
    525                         'wp-compose',
    526                         'wp-element',
    527                         'wp-i18n',
    528                         'wp-polyfill',
    529                 ),
    530                 'media-utils'                        => array(
    531                         'lodash',
    532                         'wp-api-fetch',
    533                         'wp-blob',
    534                         'wp-element',
    535                         'wp-i18n',
    536                         'wp-polyfill',
    537                 ),
    538                 'notices'                            => array(
    539                         'lodash',
    540                         'wp-a11y',
    541                         'wp-data',
    542                         'wp-polyfill',
    543                 ),
    544                 'nux'                                => array(
    545                         'lodash',
    546                         'wp-components',
    547                         'wp-compose',
    548                         'wp-data',
    549                         'wp-element',
    550                         'wp-i18n',
    551                         'wp-polyfill',
    552                 ),
    553                 'plugins'                            => array(
    554                         'lodash',
    555                         'wp-compose',
    556                         'wp-element',
    557                         'wp-hooks',
    558                         'wp-polyfill',
    559                 ),
    560                 'priority-queue'                     => array(
    561                         'wp-polyfill',
    562                 ),
    563                 'redux-routine'                      => array(
    564                         'lodash',
    565                         'wp-polyfill',
    566                 ),
    567                 'rich-text'                          => array(
    568                         'lodash',
    569                         'wp-compose',
    570                         'wp-data',
    571                         'wp-element',
    572                         'wp-escape-html',
    573                         'wp-hooks',
    574                         'wp-is-shallow-equal',
    575                         'wp-keycodes',
    576                         'wp-polyfill',
    577                 ),
    578                 'server-side-render'                 => array(
    579                         'lodash',
    580                         'wp-api-fetch',
    581                         'wp-components',
    582                         'wp-data',
    583                         'wp-deprecated',
    584                         'wp-element',
    585                         'wp-i18n',
    586                         'wp-polyfill',
    587                         'wp-url',
    588                 ),
    589                 'shortcode'                          => array(
    590                         'lodash',
    591                         'wp-polyfill',
    592                 ),
    593                 'token-list'                         => array(
    594                         'lodash',
    595                         'wp-polyfill',
    596                 ),
    597                 'url'                                => array(
    598                         'wp-polyfill',
    599                 ),
    600                 'viewport'                           => array(
    601                         'lodash',
    602                         'wp-compose',
    603                         'wp-data',
    604                         'wp-polyfill',
    605                 ),
    606                 'wordcount'                          => array(
    607                         'lodash',
    608                         'wp-polyfill',
    609                 ),
     226        $packages = array(
     227                'a11y',
     228                'annotations',
     229                'api-fetch',
     230                'autop',
     231                'blob',
     232                'block-directory',
     233                'block-editor',
     234                'block-library',
     235                'block-serialization-default-parser',
     236                'blocks',
     237                'components',
     238                'compose',
     239                'core-data',
     240                'data',
     241                'data-controls',
     242                'date',
     243                'deprecated',
     244                'dom',
     245                'dom-ready',
     246                'edit-post',
     247                'editor',
     248                'element',
     249                'escape-html',
     250                'format-library',
     251                'hooks',
     252                'html-entities',
     253                'i18n',
     254                'is-shallow-equal',
     255                'keycodes',
     256                'list-reusable-blocks',
     257                'media-utils',
     258                'notices',
     259                'nux',
     260                'plugins',
     261                'priority-queue',
     262                'redux-routine',
     263                'rich-text',
     264                'shortcode',
     265                'server-side-render',
     266                'token-list',
     267                'url',
     268                'viewport',
     269                'wordcount',
    610270        );
    611271
    612272        $package_translations = array(
    613273                'api-fetch',
    614274                'blocks',
     275                'block-directory',
    615276                'block-editor',
    616277                'block-library',
    617278                'components',
    function wp_default_packages_scripts( &$scripts ) { 
    623284                'nux',
    624285        );
    625286
    626         foreach ( $packages_dependencies as $package => $dependencies ) {
    627                 $handle  = 'wp-' . $package;
    628                 $path    = "/wp-includes/js/dist/$package$suffix.js";
    629                 $version = $packages_versions[ $package ];
     287        foreach ( $packages as $package ) {
     288                $handle       = 'wp-' . $package;
     289                $path         = "/wp-includes/js/dist/$package$suffix.js";
     290                $asset_file   = include( ABSPATH . WPINC . "/js/dist/$package$suffix.asset.php" );
     291                $dependencies = $asset_file['dependencies'];
     292
     293                // Add dependencies that cannot be detected and generated by build tools.
     294                switch ( $handle ) {
     295                        case 'wp-block-library':
     296                                array_push( $dependencies, 'editor' );
     297                                break;
     298                        case 'wp-edit-post':
     299                                array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' );
     300                                break;
     301                }
    630302
    631                 $scripts->add( $handle, $path, $dependencies, $version, 1 );
     303                $scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 );
    632304
    633305                if ( in_array( $package, $package_translations, true ) ) {
    634306                        $scripts->set_translations( $handle );
  • tools/webpack/packages.js

    diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js
    index a64bbb1337..94aa3d87f7 100644
    a b  
    11/**
    22 * External dependencies
    33 */
    4 const LiveReloadPlugin = require( 'webpack-livereload-plugin' );
     4const { DefinePlugin } = require( 'webpack' );
    55const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
     6const LiveReloadPlugin = require( 'webpack-livereload-plugin' );
    67const postcss = require( 'postcss' );
    78const UglifyJS = require( 'uglify-js' );
    89
    const { get } = require( 'lodash' ); 
    1314 * WordPress dependencies
    1415 */
    1516const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );
     17const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
    1618const LibraryExportDefaultPlugin = require( '@wordpress/library-export-default-webpack-plugin' );
    1719
    1820/**
    module.exports = function( env = { environment: 'production', watch: false, buil 
    107109                'block-library/src/tag-cloud/index.php': 'wp-includes/blocks/tag-cloud.php',
    108110        };
    109111
    110         const externals = {
    111                 react: 'React',
    112                 'react-dom': 'ReactDOM',
    113                 tinymce: 'tinymce',
    114                 moment: 'moment',
    115                 jquery: 'jQuery',
    116                 lodash: 'lodash',
    117                 'lodash-es': 'lodash',
    118         };
    119 
    120         packages.forEach( ( name ) => {
    121                 externals[ `@wordpress/${ name }` ] = {
    122                         this: [ 'wp', camelCaseDash( name ) ],
    123                 };
    124         } );
    125 
    126112        const developmentCopies = mapVendorCopies( vendors, buildTarget );
    127113        const minifiedCopies = mapVendorCopies( minifiedVendors, buildTarget );
    128114        const minifyCopies = mapVendorCopies( minifyVendors, buildTarget ).map( ( copyCommand ) => {
    module.exports = function( env = { environment: 'production', watch: false, buil 
    184170                        },
    185171                        libraryTarget: 'this',
    186172                },
    187                 externals,
    188173                resolve: {
    189174                        modules: [
    190175                                baseDir,
    module.exports = function( env = { environment: 'production', watch: false, buil 
    204189                        ],
    205190                },
    206191                plugins: [
     192                        new DefinePlugin( {
     193                                // Inject the `GUTENBERG_PHASE` global, used for feature flagging.
     194                                'process.env.GUTENBERG_PHASE': JSON.stringify( parseInt( process.env.npm_package_config_GUTENBERG_PHASE, 10 ) || 1 ),
     195                        } ),
    207196                        new LibraryExportDefaultPlugin( [
    208197                                'api-fetch',
    209198                                'deprecated',
    module.exports = function( env = { environment: 'production', watch: false, buil 
    242231                                        ...phpCopies,
    243232                                ],
    244233                        ),
     234                        new DependencyExtractionPlugin( { injectPolyfill: true } ),
    245235                ],
    246236                stats: {
    247237                        children: false,