Build tools: Grunt:

- Normalize `filepath` in the the `watch` event.
- Throw a warning when `watch` fails to process a file because the destination path cannot be determined.

Fixes #44262.

git-svn-id: https://develop.svn.wordpress.org/trunk@43327 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2018-05-29 14:20:44 +00:00
parent 50cd98012e
commit ccecd58f97

View File

@ -1355,7 +1355,7 @@ module.exports = function(grunt) {
* Automatically updates the `:dynamic` configurations * Automatically updates the `:dynamic` configurations
* so that only the changed files are updated. * so that only the changed files are updated.
*/ */
grunt.event.on('watch', function( action, filepath, target ) { grunt.event.on( 'watch', function( action, filepath, target ) {
var src; var src;
// Only configure the dynamic tasks based on known targets. // Only configure the dynamic tasks based on known targets.
@ -1363,6 +1363,9 @@ module.exports = function(grunt) {
return; return;
} }
// Normalize filepath for Windows.
filepath = filepath.replace( /\\/g, '/' );
// If the target is a file in the restructured js src. // If the target is a file in the restructured js src.
if ( target === 'js-enqueues' ) { if ( target === 'js-enqueues' ) {
var files = {}; var files = {};
@ -1392,9 +1395,10 @@ module.exports = function(grunt) {
grunt.config( [ 'copy', 'admin-js', 'files' ] ), grunt.config( [ 'copy', 'admin-js', 'files' ] ),
grunt.config( [ 'copy', 'includes-js', 'files' ] ) grunt.config( [ 'copy', 'includes-js', 'files' ] )
); );
for ( dest in configs ) { for ( dest in configs ) {
// If a file in the mapping matches then set the variables for our dynamic tasks. // If a file in the mapping matches then set the variables for our dynamic tasks.
if ( configs.hasOwnProperty( dest ) && configs[ dest ][0] === './' + filepath ) { if ( dest && configs.hasOwnProperty( dest ) && configs[ dest ][0] === './' + filepath ) {
files[ dest ] = configs[ dest ]; files[ dest ] = configs[ dest ];
src = [ path.relative( BUILD_DIR, dest ) ]; src = [ path.relative( BUILD_DIR, dest ) ];
break; break;
@ -1419,6 +1423,11 @@ module.exports = function(grunt) {
src = [ path.relative( SOURCE_DIR, filepath ) ]; src = [ path.relative( SOURCE_DIR, filepath ) ];
} }
if ( ! src ) {
grunt.warn( 'Failed to determine the destination file.' );
return;
}
if ( action === 'deleted' ) { if ( action === 'deleted' ) {
// Clean up only those files that were deleted. // Clean up only those files that were deleted.
grunt.config( [ 'clean', 'dynamic', 'src' ], src ); grunt.config( [ 'clean', 'dynamic', 'src' ], src );