Files
pollux/scripts/patch-package-manifest.php

39 lines
1.4 KiB
PHP

<?php
/*
* Laravel 5.6's PackageManifest predates Composer 2. Composer 2 stores the
* installed package list under a "packages" key, which makes Laravel's
* package:discover command fail with "Undefined index: name".
*
* This script adds support for both formats to the vendored framework file.
* Composer runs it before package:discover, so it is safe to run repeatedly.
*
* TODO(compat): Once the upgraded Laravel supports Composer 2's installed
* package format itself, delete this script AND its post-autoload-dump entry
* in composer.json. Verify composer install and artisan package:discover
* succeed with a clean vendor directory and without this patch.
*/
$file = __DIR__.'/../vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php';
if (! file_exists($file)) {
fwrite(STDERR, "PackageManifest.php not found; skipping Composer 2 patch.\n");
exit(0);
}
$contents = file_get_contents($file);
if (strpos($contents, "\$packages = \$packages['packages'] ?? \$packages;") !== false) {
exit(0);
}
$needle = '$packages = json_decode($this->files->get($path), true);';
$replacement = $needle."\n\n \$packages = \$packages['packages'] ?? \$packages;";
if (strpos($contents, $needle) === false) {
fwrite(STDERR, "Could not find PackageManifest build() snippet; skipping patch.\n");
exit(0);
}
file_put_contents($file, str_replace($needle, $replacement, $contents));