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
This commit is contained in:
Peter Wilson 2019-02-14 00:06:39 +00:00
parent e7e42efe18
commit 3ec3100195
4 changed files with 19 additions and 25 deletions

View File

@ -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', [

View File

@ -1,15 +0,0 @@
<?php
/**
* @group dependencies
* @group scripts
*/
class Tests_Dependencies_Backbonejs extends WP_UnitTestCase {
function test_exclusion_of_sourcemaps() {
$file = ABSPATH . WPINC . '/js/backbone.min.js';
$this->assertFileExists( $file );
$contents = trim( file_get_contents( $file ) );
$this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' );
}
}

View File

@ -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
*/

View File

@ -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" );
}
}
}