From 134d94d0eb8e005cd14ee8d7cae63311772011d4 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 17 Jun 2026 13:51:59 +0530 Subject: [PATCH] feat: detect framework adapter from config files pre-build - Add adapter field to detection endpoint response - Read framework config files from GitHub to detect SSR/static adapter - Uses utopia-php/detector 0.2.5 getConfigFiles()/getAdapter() hooks - Falls back to framework config default when detection is inconclusive - Short-circuit package.json fetch using already-fetched packages content --- composer.lock | 12 ++--- .../Repositories/Detections/Create.php | 45 +++++++++++++++---- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index 703189e5f9..2ceccec441 100644 --- a/composer.lock +++ b/composer.lock @@ -3742,16 +3742,16 @@ }, { "name": "utopia-php/detector", - "version": "0.2.4", + "version": "0.2.5", "source": { "type": "git", "url": "https://github.com/utopia-php/detector.git", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd" + "reference": "20f7e2ea8084176fae88a473f82f410281978a3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/detector/zipball/a564381108518ce6d18b6ab441f1448bd8355afd", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd", + "url": "https://api.github.com/repos/utopia-php/detector/zipball/20f7e2ea8084176fae88a473f82f410281978a3b", + "reference": "20f7e2ea8084176fae88a473f82f410281978a3b", "shasum": "" }, "require": { @@ -3781,9 +3781,9 @@ ], "support": { "issues": "https://github.com/utopia-php/detector/issues", - "source": "https://github.com/utopia-php/detector/tree/0.2.4" + "source": "https://github.com/utopia-php/detector/tree/0.2.5" }, - "time": "2026-02-17T11:26:34+00:00" + "time": "2026-06-17T08:16:37+00:00" }, { "name": "utopia-php/di", diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Detections/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Detections/Create.php index eefae34b09..2bcdf09dc3 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Detections/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Detections/Create.php @@ -191,23 +191,51 @@ class Create extends Action $output->setAttribute('installCommand', $framework->getInstallCommand()); $output->setAttribute('buildCommand', $framework->getBuildCommand()); $output->setAttribute('outputDirectory', $framework->getOutputDirectory()); - $framework = $framework->getName(); + $frameworkName = $framework->getName(); + + $configContent = ''; + foreach ($framework->getConfigFiles() as $configFile) { + if ($configFile === 'package.json') { + $configContent = $packages; + break; + } + if (!\in_array($configFile, $files, true)) { + continue; + } + try { + $configPath = \rtrim($providerRootDirectory, '/') . '/' . $configFile; + $configResponse = $github->getRepositoryContent($owner, $repositoryName, $configPath); + $configContent = $configResponse['content'] ?? ''; + if (!empty($configContent)) { + break; + } + } catch (FileNotFound $e) { + // Try next config file + } + } + + $detectedAdapter = !empty($configContent) ? $framework->getAdapter($configContent) : ''; } else { - $framework = 'other'; + $frameworkName = 'other'; + $detectedAdapter = ''; $output->setAttribute('installCommand', ''); $output->setAttribute('buildCommand', ''); $output->setAttribute('outputDirectory', ''); } $frameworks = Config::getParam('frameworks'); - if (!\in_array($framework, \array_keys($frameworks), true)) { - $framework = 'other'; + if (!\in_array($frameworkName, \array_keys($frameworks), true)) { + $frameworkName = 'other'; } - $output->setAttribute('framework', $framework); + $output->setAttribute('framework', $frameworkName); - $frameworkConfig = $frameworks[$framework] ?? []; - $defaultAdapter = \array_key_first($frameworkConfig['adapters'] ?? []) ?? ''; - $output->setAttribute('adapter', $defaultAdapter); + $frameworkConfig = $frameworks[$frameworkName] ?? []; + if (!empty($frameworkConfig['adapters'])) { + $adapter = (!empty($detectedAdapter) && isset($frameworkConfig['adapters'][$detectedAdapter])) + ? $detectedAdapter + : \array_key_first($frameworkConfig['adapters']); + $output->setAttribute('adapter', $adapter); + } } else { $output = new Document([ 'runtime' => '', @@ -318,4 +346,5 @@ class Create extends Action $response->dynamic($output, $type === 'framework' ? Response::MODEL_DETECTION_FRAMEWORK : Response::MODEL_DETECTION_RUNTIME); } + }