@@ -1584,10 +1584,69 @@ module.exports = function(grunt) {
15841584 'usebanner'
15851585 ] ) ;
15861586
1587- grunt . registerTask ( 'certificates:update ' , 'Updates the Composer package responsible for root certificate updates .' , function ( ) {
1587+ grunt . registerTask ( 'certificates:upgrade-package ' , 'Upgrades the package responsible for supplying the certificate authority certificate store bundled with WordPress .' , function ( ) {
15881588 var done = this . async ( ) ;
15891589 var flags = this . flags ;
1590- var args = [ 'update' ] ;
1590+ var spawn = require ( 'child_process' ) . spawnSync ;
1591+ var fs = require ( 'fs' ) ;
1592+
1593+ // Ensure that `composer update` has been run and the dependency is installed.
1594+ if ( ! fs . existsSync ( 'vendor' ) || ! fs . existsSync ( 'vendor/composer' ) || ! fs . existsSync ( 'vendor/composer/ca-bundle' ) ) {
1595+ grunt . log . error ( 'composer/ca-bundle dependency is missing. Please run `composer update` before attempting to upgrade the certificate bundle.' ) ;
1596+ done ( false ) ;
1597+ return ;
1598+ }
1599+
1600+ /*
1601+ * Because the `composer/ca-bundle` is pinned to an exact version to ensure upgrades are applied intentionally,
1602+ * the `composer update` command will not upgrade the dependency. Instead, `composer require` must be called,
1603+ * but the specific version being upgraded to must be known and passed to the command.
1604+ */
1605+ var outdatedResult = spawn ( 'composer' , [ 'outdated' , 'composer/ca-bundle' , '--format=json' ] ) ;
1606+
1607+ if ( outdatedResult . status !== 0 ) {
1608+ grunt . log . error ( 'Failed to get the package information for composer/ca-bundle.' ) ;
1609+ done ( false ) ;
1610+ return ;
1611+ }
1612+
1613+ var packageInfo ;
1614+ try {
1615+ var stdout = outdatedResult . stdout . toString ( ) . trim ( ) ;
1616+ if ( ! stdout ) {
1617+ grunt . log . writeln ( 'The latest version is already installed.' ) ;
1618+ done ( true ) ;
1619+ return ;
1620+ }
1621+ packageInfo = JSON . parse ( stdout ) ;
1622+ } catch ( e ) {
1623+ grunt . log . error ( 'Failed to parse the package information for composer/ca-bundle.' ) ;
1624+ done ( false ) ;
1625+ return ;
1626+ }
1627+
1628+ // Check for the version information needed to perform the necessary comparisons.
1629+ if ( ! packageInfo . versions || ! packageInfo . versions [ 0 ] || ! packageInfo . latest ) {
1630+ grunt . log . error ( 'Could not determine version information for composer/ca-bundle.' ) ;
1631+ done ( false ) ;
1632+ return ;
1633+ }
1634+
1635+ var currentVersion = packageInfo . versions [ 0 ] ;
1636+ var latestVersion = packageInfo . latest ;
1637+
1638+ // Compare versions to ensure we actually need to update
1639+ if ( currentVersion === latestVersion ) {
1640+ grunt . log . writeln ( 'The latest version is already installed: ' + latestVersion + '.' ) ;
1641+ done ( true ) ;
1642+ return ;
1643+ }
1644+
1645+ grunt . log . writeln ( 'Installed version: ' + currentVersion ) ;
1646+ grunt . log . writeln ( 'New version found: ' + latestVersion ) ;
1647+
1648+ // Upgrade to the latest version and change the pinned version in composer.json.
1649+ var args = [ 'require' , 'composer/ca-bundle:' + latestVersion , '--dev' ] ;
15911650
15921651 grunt . util . spawn ( {
15931652 cmd : 'composer' ,
@@ -1597,6 +1656,7 @@ module.exports = function(grunt) {
15971656 if ( flags . error && error ) {
15981657 done ( false ) ;
15991658 } else {
1659+ grunt . log . writeln ( 'Successfully updated composer/ca-bundle to ' + latestVersion ) ;
16001660 done ( true ) ;
16011661 }
16021662 } ) ;
@@ -1607,7 +1667,7 @@ module.exports = function(grunt) {
16071667 ] ) ;
16081668
16091669 grunt . registerTask ( 'certificates:upgrade' , [
1610- 'certificates:update ' ,
1670+ 'certificates:upgrade-package ' ,
16111671 'copy:certificates' ,
16121672 'build:certificates'
16131673 ] ) ;
0 commit comments