Make WordPress Core

Opened 6 years ago

Last modified 5 weeks ago

#50393 new enhancement

Run `composer compat` as a part of `grunt (precommit|prerelease)`

Reported by: desrosj Owned by:
Priority: low Milestone: Future Release
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch good-first-bug
Cc: Focuses:

Description

Now that the PHPCompatibilityWP ruleset passes in Core (see #49922), composer compat should be run in grunt precommit to help prevent new potential compatibility issues from being committed.

Attachments (1)

50393.diff (791 bytes ) - added by desrosj 4 years ago.

Download all attachments as: .zip

Change History (9)

@desrosj
4 years ago

#1 @desrosj
3 months ago

  • Keywords needs-refresh has-patch good-first-bug added
  • Milestone Future Release7.1
  • Summary Run `composer compat` as a part of `grunt precommit`Run `composer compat` as a part of `grunt (precommit|prerelease)`

I noticed today that composer compat is also missing from grunt prerelease. It should be run there as well.

Adding good-first-bug for a newer contributor to grab this.

This ticket was mentioned in PR #11983 on WordPress/wordpress-develop by @karunyachavan84.


3 months ago
#2

  • Keywords needs-refresh removed

This PR wires composer compat into the Grunt build pipeline so that potential PHP compatibility regressions are caught automatically before a commit or release.

Trac ticket: https://core.trac.wordpress.org/ticket/50393

## What this changes

Gruntfile.js

  • Registers a new compat:php Grunt task that invokes composer compat (i.e. phpcs --standard=phpcompat.xml.dist) against the set of changed PHP files, consistent with how the existing lint:php and format:php tasks are structured.
  • Adds compat:php to the precommit:php task sequence (between phpstan and phpunit), so it runs automatically during both grunt precommit (when .php files are staged) and grunt prerelease (which already includes precommit:php).
  • Fixes a silent array-mutation bug in format:php and lint:php where args.unshift() was modifying the shared changedFiles.php array reference in place. Both tasks now call .slice() to operate on a copy, preventing the composer subcommand name from being prepended to the shared array between task runs.

## Use of AI Tools

AI assistance: Yes
Model(s): GPT-5-mini
Used for: Surfacing the changedFiles.php mutation bug and verifying optimality of patch.

This ticket was mentioned in Slack in #core by adrianduffell. View the logs.


5 weeks ago

#4 @adrianduffell
5 weeks ago

With the 7.1 beta approaching, this has a chance to be included if the PR can be reviewed in the coming days.

#5 @khokansardar
5 weeks ago

Patch testing report

Patch / PR tested

Environment

WordPress: 7.1-alpha-src (trunk @ 1c57961f42)
Build toolchain (this is a Build/Test Tools change; no browser/Docker involved):

Node: v22.22.3, npm: 10.9.8, Grunt (local)
Composer: 2.5.8
PHP_CodeSniffer: 3.13.5, ruleset: phpcompat.xml.dist (PHPCompatibilityWP, testVersion 7.4-)
PHP (CLI): 8.3.27

OS: macOS 26.5.2

Steps

  1. Checked out PR #11983 and confirmed the diff: compat:php registered, added to precommit:php between phpstan and phpunit; .slice() applied to format:php, lint:php, and compat:php.
  2. Ran the wrapped command scoped to one changed file: composer compat src/wp-load.php.
  3. Ran the new Grunt task end-to-end with no changed-files set (the prerelease / no-VCS path): npx grunt compat:php.
  4. Reproduced the exact task arg-handling pattern with and without .slice() to confirm the shared-array mutation fix.

Results

  • Task wiring: pass — precommit:php = [ phpstan, compat:php, phpunit ]; task registered as "Runs the PHPCompatibility ruleset on changed files."
  • Scoped changed-file run: pass — composer compat src/wp-load.php runs phpcs --standard=phpcompat.xml.dist on just that file (1/1), clean, ~90ms; file args correctly override the ruleset's <file>./src/</file>.
  • Full grunt compat:php (empty changedFiles → prerelease behavior): pass — spawns composer compat, scans all 1890 src PHP files (parallel=20), 0 PHP-compat errors, task exits Done with no error.
  • Array-mutation fix: pass — without .slice(), running compat:php before format:php in one process pollutes changedFiles.php (["compat", ...files]) so format:php spawns composer format compat ...files (subcommand treated as a filename); with .slice() each task spawns its correct subcommand and changedFiles.php is left untouched. precommit:php and format:php do share a process on the git-precommit path (taskList = ['precommit:php','format:php']), so this fix is required, not cosmetic.
  • Scope / back-compat: pass — change is limited to Gruntfile.js dev tooling; no public API, hook, signature, or return-shape change; no runtime or at-scale performance impact.

Conclusion
PR #11983 adds a compat:php Grunt task that runs composer compat (PHPCompatibility ruleset) on changed PHP files and wires it into precommit:php, so grunt precommit and grunt prerelease now catch PHP-compatibility regressions automatically — exactly what the ticket (and comment:1 re: prerelease) asks for. The accompanying .slice() change is a correct and necessary fix for a shared-array mutation that adding compat:php would otherwise expose in format:php. The change is minimal, idiomatic, and consistent with the existing format:php/lint:php tasks, with no back-compat or performance concerns. Recommend commit.

This ticket was mentioned in Slack in #core by adrianduffell. View the logs.


5 weeks ago

#7 @adrianduffell
5 weeks ago

This was discussed in today's bug scrub.

@desrosj Do you still want this in 7.1? It looks like a safe tooling change that could be added early in the beta cycle if there is appetite. Otherwise we can punt to a future release.

#8 @desrosj
5 weeks ago

  • Milestone 7.1Future Release

I won't have the time to give this any attention and it's not important for the release. Let's punt.

Note: See TracTickets for help on using tickets.