From 3ec31001959c02dd6792afb7aeea99ae6e89d2ec Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Thu, 14 Feb 2019 00:06:39 +0000 Subject: [PATCH] Build: Remove source map from `jquery.form.min.js`. Minimize jquery.form.js as part of build process to remove the source map reference. Modify source map tests to include all JavaScript files rather than testing Backbone and jQuery only. Props pento. Fixes #46218. git-svn-id: https://develop.svn.wordpress.org/trunk@44740 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 9 +++++++-- tests/phpunit/tests/dependencies/backbonejs.php | 15 --------------- tests/phpunit/tests/dependencies/jquery.php | 8 -------- tests/phpunit/tests/dependencies/scripts.php | 12 ++++++++++++ 4 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 tests/phpunit/tests/dependencies/backbonejs.php diff --git a/Gruntfile.js b/Gruntfile.js index 41c3edd2a8..a27fc2b735 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -171,7 +171,6 @@ module.exports = function(grunt) { [ WORKING_DIR + 'wp-includes/js/jquery/jquery-migrate.js' ]: [ './node_modules/jquery-migrate/dist/jquery-migrate.js' ], [ WORKING_DIR + 'wp-includes/js/jquery/jquery-migrate.min.js' ]: [ './node_modules/jquery-migrate/dist/jquery-migrate.min.js' ], [ WORKING_DIR + 'wp-includes/js/jquery/jquery.form.js' ]: [ './node_modules/jquery-form/src/jquery.form.js' ], - [ WORKING_DIR + 'wp-includes/js/jquery/jquery.form.min.js' ]: [ './node_modules/jquery-form/dist/jquery.form.min.js' ], [ WORKING_DIR + 'wp-includes/js/jquery/jquery.js' ]: [ './node_modules/jquery/dist/jquery.min.js' ], [ WORKING_DIR + 'wp-includes/js/masonry.min.js' ]: [ './node_modules/masonry-layout/dist/masonry.pkgd.min.js' ], [ WORKING_DIR + 'wp-includes/js/twemoji.js' ]: [ './node_modules/twemoji/2/twemoji.js' ], @@ -720,6 +719,10 @@ module.exports = function(grunt) { src: WORKING_DIR + 'wp-includes/js/imgareaselect/jquery.imgareaselect.js', dest: WORKING_DIR + 'wp-includes/js/imgareaselect/jquery.imgareaselect.min.js' }, + jqueryform: { + src: WORKING_DIR + 'wp-includes/js/jquery/jquery.form.js', + dest: WORKING_DIR + 'wp-includes/js/jquery/jquery.form.min.js' + }, dynamic: { expand: true, cwd: WORKING_DIR, @@ -1193,6 +1196,7 @@ module.exports = function(grunt) { 'webpack:prod', 'jshint:corejs', 'uglify:imgareaselect', + 'uglify:jqueryform', 'qunit:compiled' ] ); @@ -1332,7 +1336,8 @@ module.exports = function(grunt) { 'uglify:core', 'uglify:embed', 'uglify:jqueryui', - 'uglify:imgareaselect' + 'uglify:imgareaselect', + 'uglify:jqueryform' ] ); grunt.registerTask( 'build:js', [ diff --git a/tests/phpunit/tests/dependencies/backbonejs.php b/tests/phpunit/tests/dependencies/backbonejs.php deleted file mode 100644 index 4c276ad898..0000000000 --- a/tests/phpunit/tests/dependencies/backbonejs.php +++ /dev/null @@ -1,15 +0,0 @@ -assertFileExists( $file ); - $contents = trim( file_get_contents( $file ) ); - $this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' ); - } -} diff --git a/tests/phpunit/tests/dependencies/jquery.php b/tests/phpunit/tests/dependencies/jquery.php index 8f8bc7e1f0..30ea876e2f 100644 --- a/tests/phpunit/tests/dependencies/jquery.php +++ b/tests/phpunit/tests/dependencies/jquery.php @@ -82,14 +82,6 @@ class Tests_Dependencies_jQuery extends WP_UnitTestCase { set_current_screen( 'front' ); } - /** - * @ticket 24994 - */ - function test_exclusion_of_sourcemaps() { - $contents = trim( file_get_contents( ABSPATH . WPINC . '/js/jquery/jquery.js' ) ); - $this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' ); - } - /** * @ticket 28404 */ diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index b1e8e6c8f8..dd6ca40f31 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -1341,4 +1341,16 @@ JS; array_keys( $wp_enqueue_code_editor['htmlhint'] ) ); } + + function test_no_source_mapping() { + $all_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( dirname( ABSPATH ) . '/build/' ) ); + $js_files = new RegexIterator( $all_files, '/\.js$/' ); + foreach( $js_files as $js_file ) { + $contents = trim( file_get_contents( $js_file ) ); + + // We allow data: URLs. + $found = preg_match( '/sourceMappingURL=((?!data:).)/', $contents ); + $this->assertSame( $found, 0, "sourceMappingURL found in $js_file" ); + } + } }