Framework: The new composer breaks autoloading

Created on 9 Apr 2020  路  9Comments  路  Source: laravel/framework


  • Laravel Version: 7.5.0
  • PHP Version: 7.4.4
  • Database Driver & Version: psql 12.2

Description:

There is a new composer version available and although it's currently a snapshot and not a stable release it breaks the artisan package:discover command, which fails on this line in the PackageManifest class.

The current structure of the installed.json has changed. Previously it was:

[
    {package1},
    {package2}
]

However, now it has changed to:

{
    "packages": [
        {package1},
        {package2}
    ],
    "dev": true
}

thus the line fails as the $packages array isn't no longer a direct array of the available packages.

A quick fix, is to append on the previously linked line after the json_decode function call ['packages'], but this would break the functionality for older versions of composer.

This change in structure is also present in the changelog for composer:

  • Added more info to vendor/composer/installed.json, a dev key stores whether dev requirements were installed, and every package now has an install-path key with its install location

Steps To Reproduce:

  1. Update composer via: composer selfupdate --snapshot
  2. I deleted composer.lock and vendor directory, however this doesn't seem to affect this
  3. Run composer update, which should fail when the postAutoloadDump scripts run, more specifically the @php artisan package:discover --ansi
bug

Most helpful comment

Thanks for reporting. Marking this as a bug even though it's for an unreleased composer version.

I guess we can easily check if the $packages variable has a packages key and use that instead.

All 9 comments

Thanks for reporting. Marking this as a bug even though it's for an unreleased composer version.

I guess we can easily check if the $packages variable has a packages key and use that instead.

I can make a PR for that, if it would help you :)

Would be cool. I think we just need to do the following adjustments:

        if ($this->files->exists($path = $this->vendorPath.'/composer/installed.json')) {
            $installed = json_decode($this->files->get($path), true);

            $packages = $installed['packages'] ?? $installed;
        }

Please send to 6.x, thanks!

Fixed in #32310

@driesvints I am getting the same issue in Plesk stable version on composer

@driesvints shouldn't this, however, also get fixed for 7.x? Or it will, but this PR will suffice for that?

@KubqoA 6.x is merged into 7.x regularly so it gets all of the fixes from 6.x

Oh sweet :+1: ! Thanks. Have a nice day :slightly_smiling_face:

New tags of Laravel 5.5, 5.6, 5.7, 5.8, 6, and 7 will go out tomorrow, so people can continue to deploy their code with Composer v2.

Was this page helpful?
0 / 5 - 0 ratings