Commit 96a59649533 for woocommerce

commit 96a5964953362dd93401f5637b56af9913ec4d99
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Mon Nov 30 17:55:11 2026 +0100

    Keep Core and Analytics Composer locks current (#71405)

    * Keep Core and Analytics Composer locks current

    * Keep release preparation retryable when Composer fails

    * Stop package preparation cleanly on the first release error

    * Restore the Composer lock after a failed metadata refresh

    * Restore version files on changelog failure

    * Preserve release errors during rollback

    * Simplify release prep and refresh Analytics lock

    * Fix Analytics changelog validation

diff --git a/packages/php/woocommerce-analytics/changelog/fix-jest-node-types b/packages/php/woocommerce-analytics/changelog/fix-jest-node-types
index 22182cd8a08..59973684b91 100644
--- a/packages/php/woocommerce-analytics/changelog/fix-jest-node-types
+++ b/packages/php/woocommerce-analytics/changelog/fix-jest-node-types
@@ -1,3 +1,3 @@
 Significance: patch
-Type: dev
+Type: changed
 Comment: Declare Node types for Analytics tests so type-checking works with Jest 30.
diff --git a/packages/php/woocommerce-analytics/changelog/wooplug-8169-dependency-cleanup b/packages/php/woocommerce-analytics/changelog/wooplug-8169-dependency-cleanup
new file mode 100644
index 00000000000..1acaa533561
--- /dev/null
+++ b/packages/php/woocommerce-analytics/changelog/wooplug-8169-dependency-cleanup
@@ -0,0 +1,3 @@
+Significance: patch
+Type: changed
+Comment: Keep Composer lockfiles current across branches and package releases.
diff --git a/packages/php/woocommerce-analytics/composer.lock b/packages/php/woocommerce-analytics/composer.lock
index 306f3d86cde..3fb0e9e8712 100644
--- a/packages/php/woocommerce-analytics/composer.lock
+++ b/packages/php/woocommerce-analytics/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "98b7997fd077713bbc854b056ac16904",
+    "content-hash": "9fc46799e86d862e68f85da12c093a1f",
     "packages": [
         {
             "name": "automattic/block-delimiter",
diff --git a/plugins/woocommerce/changelog/wooplug-8169-dependency-cleanup b/plugins/woocommerce/changelog/wooplug-8169-dependency-cleanup
new file mode 100644
index 00000000000..8c72b11dae1
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-8169-dependency-cleanup
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Keep Composer lockfiles current across branches and package releases.
diff --git a/plugins/woocommerce/composer.json b/plugins/woocommerce/composer.json
index 66f036cbb16..b9922990e2f 100644
--- a/plugins/woocommerce/composer.json
+++ b/plugins/woocommerce/composer.json
@@ -16,7 +16,10 @@
 			"type": "path",
 			"url": "../../packages/php/monorepo-plugin",
 			"options": {
-				"symlink": false
+				"symlink": false,
+				"versions": {
+					"woocommerce/monorepo-plugin": "dev-trunk"
+				}
 			}
 		},
 		{
diff --git a/plugins/woocommerce/composer.lock b/plugins/woocommerce/composer.lock
index e8aff3c8e1a..abfddf4902e 100644
--- a/plugins/woocommerce/composer.lock
+++ b/plugins/woocommerce/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "02b5685a8659668eb5c6f2f5592f65b5",
+    "content-hash": "be14c341ed74b468579c064f6d4ffa2a",
     "packages": [
         {
             "name": "automattic/block-delimiter",
@@ -1217,7 +1217,7 @@
             "dist": {
                 "type": "path",
                 "url": "../../packages/php/blueprint",
-                "reference": "f996d43977196b9670d783b58c167243950876d3"
+                "reference": "06ff21a0122d280b8b46a9f188c4af283e89ce4d"
             },
             "require": {
                 "opis/json-schema": "^2.3"
@@ -5354,11 +5354,11 @@
         },
         {
             "name": "woocommerce/monorepo-plugin",
-            "version": "dev-refactor/64839-admin-blocks-build-packages",
+            "version": "dev-trunk",
             "dist": {
                 "type": "path",
                 "url": "../../packages/php/monorepo-plugin",
-                "reference": "a453d8512de88aa25c97ff84d3acebd3ea7b8a21"
+                "reference": "c2d82d3c13cd2a9c662bfce46f407b676a2f2348"
             },
             "require": {
                 "composer-plugin-api": "^2.0"
diff --git a/tools/package-release/changelog/wooplug-8169-dependency-cleanup b/tools/package-release/changelog/wooplug-8169-dependency-cleanup
new file mode 100644
index 00000000000..8c72b11dae1
--- /dev/null
+++ b/tools/package-release/changelog/wooplug-8169-dependency-cleanup
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Keep Composer lockfiles current across branches and package releases.
diff --git a/tools/package-release/src/commands/prepare/index.ts b/tools/package-release/src/commands/prepare/index.ts
index b9e712e17fe..cb08fd3a4fe 100644
--- a/tools/package-release/src/commands/prepare/index.ts
+++ b/tools/package-release/src/commands/prepare/index.ts
@@ -2,7 +2,7 @@
  * External dependencies
  */
 import { Args, Command, Flags, ux } from '@oclif/core';
-import { writeFileSync } from 'fs';
+import { existsSync, writeFileSync } from 'fs';
 import { execSync } from 'child_process';

 /**
@@ -97,29 +97,20 @@ export default class PackagePrepare extends Command {
 		packages: Array< string >,
 		initialRelease?: boolean
 	) {
-		packages.forEach( async ( name ) => {
+		for ( const name of packages ) {
 			ux.action.start( `Preparing ${ name }` );

 			try {
 				if ( hasValidChangelogs( name ) ) {
 					validateChangelogEntries( name );
-					let nextVersion = getNextVersion( name );
-					if ( nextVersion ) {
-						writeChangelog( name );
-					} else {
-						if ( initialRelease ) {
-							// @todo: When the composer.json versioning is "wordpress" as is for plugins, this value needs to be 1.0
-							nextVersion = '1.0.0';
-						} else {
-							throw new Error(
-								`Error reading version number for ${ name }. Check that a Changelog file exists and has a version number. If making an initial release, pass the --initialRelease flag.`
-							);
-						}
-
-						writeChangelog( name, nextVersion );
+					const nextVersion = getNextVersion( name );
+					if ( ! nextVersion && ! initialRelease ) {
+						throw new Error(
+							`Error reading version number for ${ name }. Check that a Changelog file exists and has a version number. If making an initial release, pass the --initialRelease flag.`
+						);
 					}

-					this.bumpPackageVersion( name, nextVersion );
+					this.preparePackage( name, nextVersion ?? undefined );

 					ux.action.stop();
 				} else {
@@ -132,16 +123,16 @@ export default class PackagePrepare extends Command {
 					this.error( e.message );
 				}
 			}
-		} );
+		}
 	}

 	/**
-	 * Update the version number in package.json.
+	 * Update a package's version files and write its changelog.
 	 *
-	 * @param {string} name    Package name.
-	 * @param {string} version Next version.
+	 * @param {string} name        Package name.
+	 * @param {string} nextVersion Next version, if the package has a prior release.
 	 */
-	private bumpPackageVersion( name: string, version: string ) {
+	private preparePackage( name: string, nextVersion?: string ) {
 		try {
 			const filepath = getFilepathFromPackageName( name );
 			const packageType = getPackageType( name );
@@ -160,12 +151,25 @@ export default class PackagePrepare extends Command {
 				);
 			}

+			// @todo: When the composer.json versioning is "wordpress" as is for plugins, this value needs to be 1.0
+			const version = nextVersion ?? '1.0.0';
 			json.version = version;
 			writeFileSync(
 				jsonFilepath,
 				JSON.stringify( json, null, '\t' ) + '\n'
 			);

+			if (
+				packageType === 'php' &&
+				existsSync( `${ filepath }/composer.lock` )
+			) {
+				execSync(
+					'composer update --lock --no-install --no-scripts --no-plugins --no-interaction',
+					{ cwd: filepath, stdio: 'inherit' }
+				);
+			}
+			writeChangelog( name, nextVersion ? undefined : version );
+
 			// if preparing a php package and the package is used in the woocommerce plugin
 			// also update the version in the plugin's composer.json and composer.lock
 			// this is done to ensure jetpack autoloader fetches the correct version of the package
@@ -192,7 +196,7 @@ export default class PackagePrepare extends Command {
 				}
 			}
 		} catch ( e ) {
-			this.error( `Can't bump version for ${ name }.` );
+			this.error( `Can't prepare ${ name }. ${ String( e ) }` );
 		}
 	}
 }