Skip to content

Commit

Permalink
Merge pull request #1781 from ampproject/remove/redundant-dependencie…
Browse files Browse the repository at this point in the history
…s-1.0

Prevent re-bundling WordPress packages
  • Loading branch information
westonruter authored Jan 3, 2019
2 parents 4ad849f + 8e2090e commit c96e3cd
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 73 deletions.
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 );
10 changes: 10 additions & 0 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,16 @@ function amp_add_generator_metadata() {
* @param WP_Scripts $wp_scripts Scripts.
*/
function amp_register_default_scripts( $wp_scripts ) {
/*
* Polyfill dependencies that are registered in Gutenberg and WordPress 5.0.
* Note that Gutenberg will override these at wp_enqueue_scripts if it is active.
*/
$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';
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 @@ -33,8 +34,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

0 comments on commit c96e3cd

Please sign in to comment.