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

Prevent re-bundling WordPress packages #1781

Merged
merged 6 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ASSETS_DIR=wp-assets
PROJECT_SLUG=amp
SKIP_ECHO_PATHS_SCOPE=1
README_MD_TITLE="AMP Plugin for WordPress"
DEV_LIB_SKIP="$DEV_LIB_SKIP,jshint"

function after_wp_install {
echo "Installing plugins..."
Expand Down
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

27 changes: 0 additions & 27 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-env node */
/* jshint node:true */
/* eslint-disable camelcase, no-console, no-param-reassign */

module.exports = function( grunt ) {
Expand Down
7 changes: 7 additions & 0 deletions assets/js/wp-dom-ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import domReady from '@wordpress/dom-ready';

if ( ! window.wp ) {
window.wp = {};
}

wp.domReady = domReady;
7 changes: 7 additions & 0 deletions assets/js/wp-i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as i18n from '@wordpress/i18n';

if ( ! window.wp ) {
window.wp = {};
}

wp.i18n = i18n;
7 changes: 1 addition & 6 deletions assets/src/amp-validation-detail-toggle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';

/**
* Localized data
*/
Expand Down Expand Up @@ -79,7 +74,7 @@ function addTermListTableRowClasses() {
} );
}

domReady( () => {
wp.domReady( () => {
addToggleButtons( 'th.column-details.manage-column', detailToggleBtnAriaLabel )
.forEach( ( btn ) => {
addToggleAllListener( {
Expand Down
7 changes: 1 addition & 6 deletions assets/src/amp-validation-single-error-url-details.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';

/**
* Toggles the contents of a details element as an additional table tr.
*/
Expand Down Expand Up @@ -154,6 +149,6 @@ class ErrorRows {
}
}

domReady( () => {
wp.domReady( () => {
new ErrorRows().init();
} );
10 changes: 2 additions & 8 deletions assets/src/amp-validation-tooltips.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';

// WIP Pointer function
function sourcesPointer() {
jQuery( document ).on( 'click', '.tooltip-button', function() {
Expand All @@ -17,6 +12,5 @@ function sourcesPointer() {
} );
}

domReady( () => {
sourcesPointer();
} );
// Run at DOM ready.
jQuery( sourcesPointer );
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might miss something, but shouldn't this use wp.domReady somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could use wp.domReady but this script is already depending on jQuery so we can use jQuery ready instead which does the same thing.

10 changes: 10 additions & 0 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ function amp_add_generator_metadata() {
*/
function amp_register_default_scripts( $wp_scripts ) {

// Polyfill dependencies that are registered in Gutenberg and WordPress 5.0.
if ( ! has_action( 'wp_default_scripts', 'gutenberg_register_packages_scripts' ) ) {
westonruter marked this conversation as resolved.
Show resolved Hide resolved
$handles = array( 'wp-i18n', 'wp-dom-ready' );
foreach ( $handles as $handle ) {
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
$wp_scripts->add( $handle, amp_get_asset_url( sprintf( 'js/%s-compiled.js', $handle ) ) );
}
}
}

// AMP Runtime.
$handle = 'amp-runtime';
$wp_scripts->add(
Expand Down
2 changes: 1 addition & 1 deletion includes/validation/class-amp-validated-url-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function enqueue_post_list_screen_scripts() {
wp_enqueue_script(
'amp-validation-detail-toggle',
amp_get_asset_url( 'js/amp-validation-detail-toggle-compiled.js' ),
array( 'amp-validation-tooltips' ),
array( 'wp-dom-ready', 'amp-validation-tooltips' ),
AMP__VERSION,
true
);
Expand Down
4 changes: 2 additions & 2 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public static function add_admin_hooks() {
wp_enqueue_script(
'amp-validation-detail-toggle',
amp_get_asset_url( 'js/amp-validation-detail-toggle-compiled.js' ),
array( 'amp-validation-tooltips' ),
array( 'wp-dom-ready', 'amp-validation-tooltips' ),
AMP__VERSION,
true
);
Expand All @@ -878,7 +878,7 @@ public static function add_admin_hooks() {
wp_enqueue_script(
'amp-validation-single-error-url-details',
amp_get_asset_url( 'js/amp-validation-single-error-url-details-compiled.js' ),
array(),
array( 'wp-dom-ready' ),
AMP__VERSION,
true
);
Expand Down
64 changes: 50 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"license": "GPL-2.0+",
"private": true,
"devDependencies": {
"@wordpress/i18n": "^1.1.0",
"@wordpress/dom-ready": "2.0.2",
"@wordpress/i18n": "1.2.3",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
Expand All @@ -34,8 +35,5 @@
"build": "grunt build && grunt create-build-zip",
"deploy": "grunt deploy",
"dev": "cross-env BABEL_ENV=default webpack --watch"
},
"dependencies": {
"@wordpress/dom-ready": "^2.0.0"
}
}
2 changes: 2 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const path = require( 'path' );
module.exports = {
entry: {
'./assets/js/amp-blocks-compiled': './blocks/index.js',
'./assets/js/wp-i18n-compiled': './assets/js/wp-i18n',
'./assets/js/wp-dom-ready-compiled': './assets/js/wp-dom-ready',
'./assets/js/amp-block-editor-toggle-compiled': './assets/src/amp-block-editor-toggle',
'./assets/js/amp-validation-detail-toggle-compiled': './assets/src/amp-validation-detail-toggle',
'./assets/js/amp-validation-tooltips-compiled': './assets/src/amp-validation-tooltips',
Expand Down