Make WordPress Core


Ignore:
Timestamp:
01/03/2020 01:15:33 PM (7 years ago)
Author:
gziolo
Message:

Build Tools: Integrate DependencyExtractionWebpackPlugin in the JS build.

This patch integrates DependencyExtractionWebpackPlugin which was battle-tested in Gutenberg.

This will greatly simplify the process of upgrading npm packages which change after every Gutenberg release. It might even useful during the WordPress release cycle as we might need to publish more often as we discover critical bugs and regressions.

Props jonsurrell, adamsilverstein, youknowriad, ocean90, netweb.

Fixes #48154.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes

    • Property svn:ignore
      •  

        old new  
         1assets
        12js
  • trunk/src/wp-includes/script-loader.php

    r46988 r47035  
    224224        $suffix = wp_scripts_get_suffix();
    225225
    226         $packages_versions = array(
    227                 'a11y'                               => '2.5.1',
    228                 'annotations'                        => '1.7.2',
    229                 'api-fetch'                          => '3.6.4',
    230                 'autop'                              => '2.5.1',
    231                 'blob'                               => '2.5.1',
    232                 'block-editor'                       => '3.2.5',
    233                 'block-library'                      => '2.9.6',
    234                 'block-serialization-default-parser' => '3.4.1',
    235                 'blocks'                             => '6.7.2',
    236                 'components'                         => '8.3.2',
    237                 'compose'                            => '3.7.2',
    238                 'core-data'                          => '2.7.5',
    239                 'data-controls'                      => '1.3.4',
    240                 'data'                               => '4.9.2',
    241                 'date'                               => '3.5.0',
    242                 'deprecated'                         => '2.6.1',
    243                 'dom-ready'                          => '2.5.1',
    244                 'dom'                                => '2.5.2',
    245                 'edit-post'                          => '3.8.6',
    246                 'editor'                             => '9.7.6',
    247                 'element'                            => '2.8.2',
    248                 'escape-html'                        => '1.5.1',
    249                 'format-library'                     => '1.9.5',
    250                 'hooks'                              => '2.6.0',
    251                 'html-entities'                      => '2.5.0',
    252                 'i18n'                               => '3.6.1',
    253                 'is-shallow-equal'                   => '1.6.1',
    254                 'keycodes'                           => '2.6.2',
    255                 'list-reusable-blocks'               => '1.8.4',
    256                 'media-utils'                        => '1.2.4',
    257                 'notices'                            => '1.8.2',
    258                 'nux'                                => '3.7.2',
    259                 'plugins'                            => '2.7.2',
    260                 'priority-queue'                     => '1.3.1',
    261                 'redux-routine'                      => '3.6.2',
    262                 'rich-text'                          => '3.7.2',
    263                 'shortcode'                          => '2.4.1',
    264                 'server-side-render'                 => '1.3.4',
    265                 'token-list'                         => '1.6.1',
    266                 'url'                                => '2.8.2',
    267                 'viewport'                           => '2.8.2',
    268                 'wordcount'                          => '2.6.2',
    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
     
    613273                'api-fetch',
    614274                'blocks',
     275                'block-directory',
    615276                'block-editor',
    616277                'block-library',
     
    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 ];
    630 
    631                 $scripts->add( $handle, $path, $dependencies, $version, 1 );
     287        foreach ( $packages as $package ) {
     288                $handle       = 'wp-' . $package;
     289                $path         = "/wp-includes/js/dist/$package$suffix.js";
     290                $asset_file   = include( ABSPATH . WPINC . "/assets/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                }
     302
     303                $scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 );
    632304
    633305                if ( in_array( $package, $package_translations, true ) ) {
Note: See TracChangeset for help on using the changeset viewer.