Skip to content

Commit

Permalink
Merge pull request #61 from edersoares/autoload-files
Browse files Browse the repository at this point in the history
Autoload `files`
  • Loading branch information
edersoares authored Aug 4, 2024
2 parents e50d9f6 + abccf40 commit 1791511
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion fixtures/autoload-strategy/packages/dex/fake/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"autoload": {
"psr-4": {
"Dex\\Fake\\": "src/"
}
},
"files": ["scripts/start.php"]
},
"autoload-dev": {
"psr-4": {
Expand Down
9 changes: 7 additions & 2 deletions src/Composer/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions tests/Composer/Factory/AutoloadStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -39,6 +42,6 @@
'url' => './packages/vendor/dex/fake',
'symlink' => true,
],
]
],
]);
});

0 comments on commit 1791511

Please sign in to comment.