Skip to content

Commit

Permalink
include root package extra when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Sep 17, 2024
1 parent 3205a1c commit ca93716
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions bin/auradi
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ $args = $argv;
$scriptDir = array_shift($args);
$command = array_shift($args);

if ($command === 'scan') {
if (!file_exists($currentCwd . '/vendor/composer/installed.json')) {
throw new RuntimeException('Could not include ./vendor/composer/installed.json in path ' . $currentCwd . '/vendor/composer/installed.json');
}

echo 'Using ./vendor/composer/installed.json to detect which paths to scan:' . PHP_EOL;

$installedJsonFile = $currentCwd . '/vendor/composer/installed.json';
function extractJson(string $file): array {
$installedJsonFile = $file;
$installedJsonContents = file_get_contents($installedJsonFile);
if (!$installedJsonContents) {
throw new RuntimeException('Could not read json from ./vendor/composer/installed.json');
Expand All @@ -46,6 +40,26 @@ if ($command === 'scan') {
throw new RuntimeException('Could not parse json from ./vendor/composer/installed.json');
}

return $installedJson;
}

if ($command === 'scan') {
$installedJsonFile = $currentCwd . '/vendor/composer/installed.json';
$composerJsonFile = $currentCwd . '/composer.json';

if (!file_exists($installedJsonFile)) {
throw new RuntimeException('Could not find ./vendor/composer/installed.json in path ' . $currentCwd);
}

if (!file_exists($composerJsonFile)) {
throw new RuntimeException('Could not find ./composer.json in path ' . $currentCwd);
}

echo 'Using ./composer.json and ./vendor/composer/installed.json to detect which paths to scan:' . PHP_EOL;

$installedJson = extractJson($installedJsonFile);
$composerJson = extractJson($composerJsonFile);

$classMapPaths = [];
foreach ($installedJson['packages'] as $package) {
foreach (($package['extra']['aura/di']['classmap-paths'] ?? []) as $classMapPath) {
Expand All @@ -55,6 +69,12 @@ if ($command === 'scan') {
}
}

foreach (($composerJson['extra']['aura/di']['classmap-paths'] ?? []) as $classMapPath) {
$fullPath = realpath(dirname($composerJsonFile) . '/' . $classMapPath);
$classMapPaths[] = $fullPath;
echo '- ' . $fullPath . PHP_EOL;
}

echo 'Found ' . count($classMapPaths) . ' classmap paths' . PHP_EOL;
echo PHP_EOL;

Expand Down

0 comments on commit ca93716

Please sign in to comment.