Problem/Motivation

When using composer's optimize-autoloader setting, this module throws warnings and is skipped.

❯ ddev composer require drupal/cloudfront_cache_path_invalidate
./composer.json has been updated
Running composer update drupal/cloudfront_cache_path_invalidate
Loading composer repositories with package information
Updating dependencies
Lock file operations: 4 installs, 0 updates, 0 removals
  - Locking aws/aws-crt-php (v1.2.7)
  - Locking aws/aws-sdk-php (3.325.3)
  - Locking drupal/cloudfront_cache_path_invalidate (3.0.9)
  - Locking mtdowling/jmespath.php (2.8.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Installing aws/aws-crt-php (v1.2.7): Extracting archive
  - Installing mtdowling/jmespath.php (2.8.0): Extracting archive
  - Installing aws/aws-sdk-php (3.325.3): Extracting archive
  - Installing drupal/cloudfront_cache_path_invalidate (3.0.9): Extracting archive
3 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
Class Drupal\cloudfront_cache_path_invalidate\Form\AutoCloudfrontCacheSettingForm located in ./web/modules/contrib/cloudfront_cache_path_invalidate/src/Form/AutoCloudfrontCacheSettingForm.php does not comply with psr-4 autoloading standard (rule: Drupal\CloudfrontCachePathInvalidate\ => ./web/modules/contrib/cloudfront_cache_path_invalidate/src). Skipping.
Class Drupal\cloudfront_cache_path_invalidate\Form\CloudfrontCacheInvalidateForm located in ./web/modules/contrib/cloudfront_cache_path_invalidate/src/Form/CloudfrontCacheInvalidateForm.php does not comply with psr-4 autoloading standard (rule: Drupal\CloudfrontCachePathInvalidate\ => ./web/modules/contrib/cloudfront_cache_path_invalidate/src). Skipping.
44 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Found 4 security vulnerability advisories affecting 3 packages.
Run "composer audit" for a full list of advisories.
Using version ^3.0 for drupal/cloudfront_cache_path_invalidate

Specifically this part:

Generating optimized autoload files
Class Drupal\cloudfront_cache_path_invalidate\Form\AutoCloudfrontCacheSettingForm located in ./web/modules/contrib/cloudfront_cache_path_invalidate/src/Form/AutoCloudfrontCacheSettingForm.php does not comply with psr-4 autoloading standard (rule: Drupal\CloudfrontCachePathInvalidate\ => ./web/modules/contrib/cloudfront_cache_path_invalidate/src). Skipping.
Class Drupal\cloudfront_cache_path_invalidate\Form\CloudfrontCacheInvalidateForm located in ./web/modules/contrib/cloudfront_cache_path_invalidate/src/Form/CloudfrontCacheInvalidateForm.php does not comply with psr-4 autoloading standard (rule: Drupal\CloudfrontCachePathInvalidate\ => ./web/modules/contrib/cloudfront_cache_path_invalidate/src). Skipping.

Steps to reproduce

  1. Set up a new Drupal site (I used Drupal 10 but 11 should reproduce the same way)
  2. Enable composer optimizer-autoloader, in composer.json under config add "optimize-autoloader": true
  3. Run composer require drupal/cloudfront_cache_path_invalidate

The expected result is no warnings and an optimized autoloader, but the actual result is the warning shown above.

Proposed resolution

Remove the unneeded and incorrect autoload section from composer.json.

Remaining tasks

  • Create MR
  • Test
  • Review
  • Commit

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

star-szr created an issue. See original summary.

star-szr’s picture

Issue summary: View changes

star-szr’s picture

Assigned: star-szr » Unassigned
Status: Active » Needs review

Tested by modifying composer.json repositories:

    "repositories": [
        {
            "type": "git",
            "url": "https://git.drupalcode.org/issue/cloudfront_cache_path_invalidate-3485969.git"
        },
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],

And ran ddev composer require drupal/cloudfront_cache_path_invalidate:dev-3485969-incorrect-composer.json-psr-4

Result (no warnings!):

❯ ddev composer require drupal/cloudfront_cache_path_invalidate:dev-3485969-incorrect-composer.json-psr-4
./composer.json has been updated
Running composer update drupal/cloudfront_cache_path_invalidate
Loading composer repositories with package information
Updating dependencies
Lock file operations: 4 installs, 0 updates, 0 removals
  - Locking aws/aws-crt-php (v1.2.7)
  - Locking aws/aws-sdk-php (3.325.3)
  - Locking drupal/cloudfront_cache_path_invalidate (dev-3485969-incorrect-composer.json-psr-4 9f57dc8)
  - Locking mtdowling/jmespath.php (2.8.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Syncing drupal/cloudfront_cache_path_invalidate (dev-3485969-incorrect-composer.json-psr-4 9f57dc8) into cache
  - Installing aws/aws-crt-php (v1.2.7): Extracting archive
  - Installing mtdowling/jmespath.php (2.8.0): Extracting archive
  - Installing aws/aws-sdk-php (3.325.3): Extracting archive
  - Installing drupal/cloudfront_cache_path_invalidate (dev-3485969-incorrect-composer.json-psr-4 9f57dc8): Cloning 9f57dc89ed from cache
3 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
44 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Found 4 security vulnerability advisories affecting 3 packages.
Run "composer audit" for a full list of advisories.
star-szr’s picture

Issue summary: View changes
mparker17’s picture

Status: Needs review » Reviewed & tested by the community

I've tested this patch on two different sites, and it works for me!

mparker17’s picture

Awesome, thanks @prashant mishra!

prashant mishra’s picture

Version: 3.0.x-dev » 3.1.0
Assigned: Unassigned » prashant mishra
Status: Reviewed & tested by the community » Fixed
star-szr’s picture

@prashant mishra Can you please update the issue credits to give us credit as well? Thanks in advance.

prashant mishra’s picture

Status: Fixed » Closed (fixed)

Credit has been given.