From 7cf37c4ea13bfdcff727ef6ef18628964ad399bb Mon Sep 17 00:00:00 2001 From: KarunyaChavan Date: Wed, 27 May 2026 12:53:39 +0530 Subject: [PATCH 1/3] build(grunt): add compat:php task in precommit. - Register a new compat:php Grunt task that invokes composer compat (PHPCompatibilityWP ruleset via phpcs) against changed PHP files. - Add it to precommit:php so it runs automatically in both grunt precommit and grunt prerelease. --- Gruntfile.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3506e6553d79d..3572185072881 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1724,6 +1724,7 @@ module.exports = function(grunt) { grunt.registerTask( 'precommit:php', [ 'phpstan', + 'compat:php', 'phpunit' ] ); @@ -2260,7 +2261,7 @@ module.exports = function(grunt) { grunt.registerTask( 'format:php', 'Runs the code formatter on changed files.', function() { var done = this.async(); var flags = this.flags; - var args = changedFiles.php; + var args = changedFiles.php.slice(); args.unshift( 'format' ); @@ -2280,7 +2281,7 @@ module.exports = function(grunt) { grunt.registerTask( 'lint:php', 'Runs the code linter on changed files.', function() { var done = this.async(); var flags = this.flags; - var args = changedFiles.php; + var args = changedFiles.php.slice(); args.unshift( 'lint' ); @@ -2297,6 +2298,21 @@ module.exports = function(grunt) { } ); } ); + grunt.registerTask( 'compat:php', 'Runs the PHPCompatibility ruleset on changed files.', function() { + var done = this.async(); + var args = changedFiles.php.slice(); + + args.unshift( 'compat' ); + + grunt.util.spawn( { + cmd: 'composer', + args: args, + opts: { stdio: 'inherit' } + }, function( error ) { + done( ! error ); + } ); + } ); + grunt.registerTask( 'wp-packages:update', 'Update WordPress packages', function() { const distTag = grunt.option('dist-tag') || 'latest'; grunt.log.writeln( `Updating WordPress packages (--dist-tag=${distTag})` ); From e548aecb1e72259b7cffc0dcbe8b12b4cfeb156e Mon Sep 17 00:00:00 2001 From: KarunyaChavan Date: Mon, 2 Nov 2026 19:33:38 +0530 Subject: [PATCH 2/3] build(grunt): fix short status regex and limit compat:php to src --- Gruntfile.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2e244ce3132d3..6bc01a253a622 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1960,11 +1960,11 @@ module.exports = function(grunt) { // Find .php files that have been modified or added. PHPfiles = PHPfiles.filter( function( file ) { - return /^\s*[MA]\s*.*\.php$/.test( file ); + return /^\s*[MA]{1,2}\s+.*\.php$/.test( file ); } ); PHPfiles = PHPfiles.map( function( file ) { - return file.replace( /^\s*[MA]\s*/, '' ); + return file.replace( /^\s*[MA]{1,2}\s+/, '' ); } ); changedFiles = { @@ -2472,9 +2472,19 @@ module.exports = function(grunt) { grunt.registerTask( 'compat:php', 'Runs the PHPCompatibility ruleset on changed files.', function() { var done = this.async(); - var args = changedFiles.php.slice(); - args.unshift( 'compat' ); + // phpcompat.xml.dist only scans src/; paths passed on the command line bypass its selection. + var files = changedFiles.php.filter( function( file ) { + return 0 === file.indexOf( 'src/' ); + } ); + + if ( changedFiles.php.length && ! files.length ) { + grunt.log.writeln( 'No changed PHP files in src/. Skipping PHP compatibility checks.' ); + done(); + return; + } + + var args = [ 'compat' ].concat( files ); grunt.util.spawn( { cmd: 'composer', From 207c1fa6c9d9c516648c10eab1f441c049e1bca6 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Mon, 2 Nov 2026 13:53:29 -0700 Subject: [PATCH 3/3] Build/Test Tools: Construct Composer task arguments consistently. --- Gruntfile.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 6bc01a253a622..d460e7c64e44b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2433,9 +2433,7 @@ module.exports = function(grunt) { grunt.registerTask( 'format:php', 'Runs the code formatter on changed files.', function() { var done = this.async(); var flags = this.flags; - var args = changedFiles.php.slice(); - - args.unshift( 'format' ); + var args = [ 'format' ].concat( changedFiles.php ); grunt.util.spawn( { cmd: 'composer', @@ -2453,9 +2451,7 @@ module.exports = function(grunt) { grunt.registerTask( 'lint:php', 'Runs the code linter on changed files.', function() { var done = this.async(); var flags = this.flags; - var args = changedFiles.php.slice(); - - args.unshift( 'lint' ); + var args = [ 'lint' ].concat( changedFiles.php ); grunt.util.spawn( { cmd: 'composer',