Automattic / Automattic/jetpack

Runtime Composer utility `\Composer\InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' )` does not work with `jetpack-autoloader`

Open
#33,831 6 comments 0 reactions 0 assignees View on GitHub
[Package] Autoloader [Plugin] Jetpack [Pri] Low Bug Triaged
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

None / Other

### Quick summary

To load [Action Scheduler](https://actionscheduler.org/) into one of our plugins we use the following code:

```php
$action_scheduler_path = InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' );

require_once $action_scheduler_path . '/action-scheduler.php';
```

This works if we use the default Composer autoload file:

```php
require_once __DIR__ . '/vendor/autoload.php';
```

If we switch to https://github.com/automattic/jetpack-autoloader we get an error:

```
Fatal error: Uncaught Error: Class "Composer\InstalledVersions" not found
```

Or:

```
Fatal error: Uncaught OutOfBoundsException: Package "woocommerce/action-scheduler" is not installed
```

### Steps to reproduce

I have created a test plugin to reproduce the issue:
https://github.com/remcotolsma/reproduce-composer-utility-issue-with-jetpack-autoloader

### A clear and concise description of what you expected to happen.

It would be nice if the runtime Composer utilities still work with the Jetpack autoloader.

### What actually happened

The runtime Composer utilities are not available or the utility classes are not aware of the packages loaded via the Jetpack autoloader.

### Impact

Some (< 50%)

### Available workarounds?

There is no user impact

### Platform (Simple and/or Atomic)

_No response_

### Logs or notes

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the linked reproduction plugin and compare its default Composer autoload setup with jetpack-autoloader. Trace why Composer\InstalledVersions is unavailable or does not recognize woocommerce/action-scheduler; done means the runtime utility works and recognizes packages loaded through the Jetpack autoloader.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.