From ccecd58f97cf94f2fcb17eeb8b27f2a62e10d926 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 29 May 2018 14:20:44 +0000 Subject: [PATCH] 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 --- Gruntfile.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 85a4acfe1b..32e56cc4cc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1355,7 +1355,7 @@ module.exports = function(grunt) { * Automatically updates the `:dynamic` configurations * 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; // Only configure the dynamic tasks based on known targets. @@ -1363,6 +1363,9 @@ module.exports = function(grunt) { return; } + // Normalize filepath for Windows. + filepath = filepath.replace( /\\/g, '/' ); + // If the target is a file in the restructured js src. if ( target === 'js-enqueues' ) { var files = {}; @@ -1392,9 +1395,10 @@ module.exports = function(grunt) { grunt.config( [ 'copy', 'admin-js', 'files' ] ), grunt.config( [ 'copy', 'includes-js', 'files' ] ) ); + for ( dest in configs ) { // 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 ]; src = [ path.relative( BUILD_DIR, dest ) ]; break; @@ -1419,6 +1423,11 @@ module.exports = function(grunt) { src = [ path.relative( SOURCE_DIR, filepath ) ]; } + if ( ! src ) { + grunt.warn( 'Failed to determine the destination file.' ); + return; + } + if ( action === 'deleted' ) { // Clean up only those files that were deleted. grunt.config( [ 'clean', 'dynamic', 'src' ], src );