Incorrect composer.json psr-4 autoload directive

Created on 6 November 2024, 28 days ago

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

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada star-szr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @star-szr
  • @star-szr opened merge request.
  • 🇨🇦Canada star-szr

    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.
    
  • 🇨🇦Canada mparker17 UTC-4

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

Production build 0.71.5 2024