diff --git a/fixtures/autoload-strategy/packages/dex/fake/composer.json b/fixtures/autoload-strategy/packages/dex/fake/composer.json index e800c2c..8f42f91 100644 --- a/fixtures/autoload-strategy/packages/dex/fake/composer.json +++ b/fixtures/autoload-strategy/packages/dex/fake/composer.json @@ -9,7 +9,8 @@ "autoload": { "psr-4": { "Dex\\Fake\\": "src/" - } + }, + "files": ["scripts/start.php"] }, "autoload-dev": { "psr-4": { diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 6f02739..a216145 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -203,6 +203,11 @@ private function definePluggedAndIgnoredPackages(IOInterface $io, array &$plugge $localConfig['autoload']['psr-4'][$namespace] = dirname($package) . DIRECTORY_SEPARATOR . $directory; } + foreach ($data['autoload']['files'] ?? [] as $file) { + $localConfig['autoload']['files'] ??= []; + $localConfig['autoload']['files'][] = dirname($package) . DIRECTORY_SEPARATOR . $file; + } + if (in_array($data['name'], $autoloadDev)) { foreach ($data['autoload-dev']['psr-4'] ?? [] as $namespace => $directory) { $localConfig['autoload-dev']['psr-4'][$namespace] = dirname($package) . DIRECTORY_SEPARATOR . $directory; @@ -239,14 +244,14 @@ private function filesystem(): Filesystem private function experimentalAutoloadStrategy(array $data): void { - $this->filesystem()->ensureDirectoryExists(PlugAndPlayInterface::PACKAGES_VENDOR . $data['name']); + $this->filesystem()->ensureDirectoryExists(PlugAndPlayInterface::PACKAGES_VENDOR . '/' . $data['name']); unset($data['autoload']); unset($data['autoload-dev']); $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL; - file_put_contents(PlugAndPlayInterface::PACKAGES_VENDOR . $data['name'] . '/composer.json', $json); + file_put_contents(PlugAndPlayInterface::PACKAGES_VENDOR . '/' . $data['name'] . '/composer.json', $json); } /** diff --git a/tests/Composer/Factory/AutoloadStrategyTest.php b/tests/Composer/Factory/AutoloadStrategyTest.php index a543620..db0c3ec 100644 --- a/tests/Composer/Factory/AutoloadStrategyTest.php +++ b/tests/Composer/Factory/AutoloadStrategyTest.php @@ -18,17 +18,20 @@ 'composer-plug-and-play' => [ 'strategy' => 'experimental:autoload', 'autoload-dev' => ['dex/fake'], - ] + ], ], 'autoload' => [ 'psr-4' => [ 'Dex\\Fake\\' => 'packages/dex/fake/src/', - ] + ], + 'files' => [ + 'packages/dex/fake/scripts/start.php', + ], ], 'autoload-dev' => [ 'psr-4' => [ 'Dex\\Fake\\Tests\\' => 'packages/dex/fake/tests/', - ] + ], ], 'require' => [ 'dex/fake' => '@dev', @@ -39,6 +42,6 @@ 'url' => './packages/vendor/dex/fake', 'symlink' => true, ], - ] + ], ]); });