Skip to content

docker: resolve monorepo plugins_url via composer.json name#48542

Merged
dhasilva merged 2 commits intotrunkfrom
fix/monorepo-plugins-url
May 6, 2026
Merged

docker: resolve monorepo plugins_url via composer.json name#48542
dhasilva merged 2 commits intotrunkfrom
fix/monorepo-plugins-url

Conversation

@dhasilva
Copy link
Copy Markdown
Contributor

@dhasilva dhasilva commented May 5, 2026

Fixes #

Proposed changes

  • In the Docker dev environment, fix plugins_url translation for monorepo packages whose Composer name diverges from their directory name.
  • Read the package's composer.json to determine the canonical vendor symlink name (e.g. packages/scan/automattic/jetpack-scan-page), instead of hard-coding automattic/jetpack-{dirname}.
  • Cache the lookup per-request so a single page load doesn't re-read the same composer.json for every URL the package generates.
  • Keep the old directory-name convention as a defensive fallback when composer.json is missing/malformed.

Without this, realpath() matching in the filter never succeeds for divergent packages, so plugins_url returns the unresolved monorepo path and asset URLs 404. The most visible symptom is the gated Scan page (wp-admin/admin.php?page=jetpack-scan) failing to load its React app.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  1. Boot the Jetpack Docker dev environment (jetpack docker up -d) on trunk (i.e. without this fix).
  2. Enable the gated Scan page (feature flag for the new Scan UI in the Jetpack plugin):
add_filter( 'rsm_jetpack_ui_modernization_scan', '__return_true' );
  1. Visit wp-admin/admin.php?page=jetpack-scan and confirm the page fails to render (blank container / 404s on the package's assets in DevTools → Network).
  2. Check out this branch and reload the Scan page — the React app should now render correctly with assets loading from /wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-scan-page/....
  3. Spot-check other monorepo-package-driven admin pages (e.g. anything using packages/* assets in dev) to confirm there are no regressions in plugins_url resolution.

The plugins_url filter assumed every monorepo package's vendor symlink
was automattic/jetpack-{dirname}, which doesn't hold for packages whose
composer name diverges (e.g. packages/scan is automattic/jetpack-scan-page).
Read composer.json for the canonical name so realpath matching succeeds
and gated pages like Scan can load assets in the Docker dev environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dhasilva dhasilva requested a review from a team as a code owner May 5, 2026 22:24
@dhasilva dhasilva self-assigned this May 5, 2026
@github-actions github-actions Bot added the Docker label May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@dhasilva dhasilva added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels May 5, 2026
@dhasilva
Copy link
Copy Markdown
Contributor Author

dhasilva commented May 5, 2026

From a Claude review done locally:

This isn't unique to scan either. A quick scan of  projects/packages/*/composer.json shows other divergences:
  - packages/scheduled-updates → automattic/scheduled-updates (no jetpack- prefix at all)
  - packages/block-delimiter → automattic/block-delimiter (same)

  So the old heuristic was a leaky abstraction; the new code reads   composer.json for the canonical name, which is exactly what Composer used   to create the symlink

tbradsha
tbradsha previously approved these changes May 6, 2026
Copy link
Copy Markdown
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One non-blocking comment. Thanks for the fix!

Comment on lines +80 to +83
static $cache = array();
if ( array_key_exists( $package_dir, $cache ) ) {
return $cache[ $package_dir ];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

$composer_path = $package_dir . '/composer.json';
if ( is_readable( $composer_path ) ) {
$contents = json_decode( file_get_contents( $composer_path ), true );
if ( is_array( $contents ) && isset( $contents['name'] ) && is_string( $contents['name'] ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the is_array() check, as the isset() on a string key handles that. You could take it one step further and guard against an empty key too (this'd include "0", which is fine in this scenario):

Suggested change
if ( is_array( $contents ) && isset( $contents['name'] ) && is_string( $contents['name'] ) ) {
if ( ! empty( $contents['name'] ) && is_string( $contents['name'] ) ) {

Drop the redundant is_array() check — isset() with a string key already
short-circuits when the variable isn't an array — and switch to !empty()
so a missing key, null, or empty string all fail the same guard. Per
review feedback from @tbradsha.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dhasilva dhasilva merged commit 3633c01 into trunk May 6, 2026
91 checks passed
@dhasilva dhasilva deleted the fix/monorepo-plugins-url branch May 6, 2026 16:16
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label May 6, 2026
LiamSarsfield pushed a commit that referenced this pull request May 6, 2026
* docker: resolve monorepo plugins_url via composer.json name

The plugins_url filter assumed every monorepo package's vendor symlink
was automattic/jetpack-{dirname}, which doesn't hold for packages whose
composer name diverges (e.g. packages/scan is automattic/jetpack-scan-page).
Read composer.json for the canonical name so realpath matching succeeds
and gated pages like Scan can load assets in the Docker dev environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docker: simplify composer name guard

Drop the redundant is_array() check — isset() with a string key already
short-circuits when the variable isn't an array — and switch to !empty()
so a missing key, null, or empty string all fail the same guard. Per
review feedback from @tbradsha.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants