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)
Change History (9)
#1
@
3 months ago
- Keywords needs-refresh has-patch good-first-bug added
- Milestone Future Release → 7.1
- Summary Run `composer compat` as a part of `grunt precommit` → Run `composer compat` as a part of `grunt (precommit|prerelease)`
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:phpGrunt task that invokescomposer compat(i.e.phpcs --standard=phpcompat.xml.dist) against the set of changed PHP files, consistent with how the existinglint:phpandformat:phptasks are structured. - Adds
compat:phpto theprecommit:phptask sequence (betweenphpstanandphpunit), so it runs automatically during bothgrunt precommit(when.phpfiles are staged) andgrunt prerelease(which already includesprecommit:php). - Fixes a silent array-mutation bug in
format:phpandlint:phpwhereargs.unshift()was modifying the sharedchangedFiles.phparray 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
@
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
@
5 weeks ago
Patch testing report
Patch / PR tested
- https://github.com/WordPress/wordpress-develop/pull/11983
- trunk @ 1c57961f42 with PR #11983 merged in (branch test/49922-phpcompat-precommit)
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
- Checked out PR #11983 and confirmed the diff:
compat:phpregistered, added toprecommit:phpbetweenphpstanandphpunit;.slice()applied toformat:php,lint:php, andcompat:php. - Ran the wrapped command scoped to one changed file:
composer compat src/wp-load.php. - Ran the new Grunt task end-to-end with no changed-files set (the prerelease / no-VCS path):
npx grunt compat:php. - 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.phprunsphpcs --standard=phpcompat.xml.diston 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 exitsDonewith no error. - Array-mutation fix: pass — without
.slice(), runningcompat:phpbeforeformat:phpin one process polluteschangedFiles.php(["compat", ...files]) soformat:phpspawnscomposer format compat ...files(subcommand treated as a filename); with.slice()each task spawns its correct subcommand andchangedFiles.phpis left untouched.precommit:phpandformat:phpdo 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I noticed today that
composer compatis also missing fromgrunt prerelease. It should be run there as well.Adding
good-first-bugfor a newer contributor to grab this.