-
-
Notifications
You must be signed in to change notification settings - Fork 29
[#2014] Allow to select modules in the installer. #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| }, | ||
| "require": { | ||
| "php": ">=8.3", | ||
| "alexskrypnyk/file": "^0.13.1", | ||
| "alexskrypnyk/file": "^0.14", | ||
| "alexskrypnyk/str2name": "^1.4", | ||
| "composer/composer": "^2.9.1", | ||
| "cweagans/composer-patches": "^2", | ||
|
|
@@ -88,10 +88,10 @@ | |
| "lint": [ | ||
| "phpcs", | ||
| "phpstan", | ||
| "rector --clear-cache --dry-run" | ||
| "rector --dry-run" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify removal of The Run the following to verify Rector behavior without the flag: Also applies to: 94-94 🏁 Script executed: #!/bin/bash
# Description: Test Rector lint commands to ensure they work correctly without --clear-cache
# Check if rector runs successfully without --clear-cache
cd .vortex/installer
composer install --quiet
echo "=== Testing rector --dry-run (lint) ==="
./vendor/bin/rector --dry-run || echo "Rector dry-run failed"
echo ""
echo "=== Check Rector documentation for caching behavior ==="
./vendor/bin/rector --help | grep -i cacheLength of output: 341 🏁 Script executed: #!/bin/bash
# Examine the composer.json file to see the rector version and changes
echo "=== Checking rector version in composer.json ==="
cat .vortex/installer/composer.json | grep -A 2 -B 2 '"rector'
echo ""
echo "=== Viewing lines 85-100 to see the lint scripts ==="
sed -n '85,100p' .vortex/installer/composer.json
echo ""
echo "=== Full composer.json for context ==="
cat .vortex/installer/composer.jsonLength of output: 4320 🌐 Web query: 💡 Result: Short answer: Yes — Rector caches processed files, so to force a full re-run (e.g., after changing rules/config or when files were previously skipped) you must clear the cache (use --clear-cache). Many docs and reports recommend always running with --clear-cache when changing rules or running on a full codebase; Rector’s behaviour also includes kaizen/cache rules that enforce clearing when files or rules change. [1][2][3] Sources:
Restore Rector caches processed files and recommends using Restore
Also applies to: 94-94 🤖 Prompt for AI Agents |
||
| ], | ||
| "lint-fix": [ | ||
| "rector --clear-cache", | ||
| "rector", | ||
| "phpcbf" | ||
| ], | ||
| "reset": "rm -Rf vendor vendor-bin", | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DrevOps\VortexInstaller\Prompts\Handlers; | ||
|
|
||
| use DrevOps\VortexInstaller\Utils\File; | ||
| use DrevOps\VortexInstaller\Utils\JsonManipulator; | ||
|
|
||
| class Modules extends AbstractHandler { | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function label(): string { | ||
| return 'Modules'; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function hint(array $responses): ?string { | ||
| return 'Use ⬆, ⬇ and Space bar to select one or more modules.'; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function options(array $responses): ?array { | ||
| return static::getAvailableModules(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function default(array $responses): null|string|bool|array { | ||
| // Default to all modules selected (meaning none will be removed). | ||
| return array_keys(static::getAvailableModules()); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function discover(): null|string|bool|array { | ||
| if (!$this->isInstalled()) { | ||
| return NULL; | ||
| } | ||
|
|
||
| $composer_file = $this->dstDir . '/composer.json'; | ||
| $discovered_modules = $this->getModulesFromComposerFile($composer_file); | ||
|
|
||
| if ($discovered_modules === NULL) { | ||
| return NULL; | ||
| } | ||
|
|
||
| // Filter discovered modules to only include those in our available list. | ||
| $available_modules = array_keys(static::getAvailableModules()); | ||
| $modules = array_intersect($discovered_modules, $available_modules); | ||
|
|
||
| sort($modules); | ||
|
|
||
| return $modules; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function process(): void { | ||
| $selected_modules = $this->getResponseAsArray(); | ||
| $all_modules = static::getAvailableModules(); | ||
|
|
||
| $t = $this->tmpDir; | ||
| $w = $this->webroot; | ||
|
|
||
| // Process each module that was NOT selected (remove them). | ||
| foreach (array_keys($all_modules) as $module_name) { | ||
| if (!in_array($module_name, $selected_modules)) { | ||
| // Remove from composer.json. | ||
| $pattern = '/\s*"drupal\/' . preg_quote($module_name, '/') . '":\s*"[^\"]+",?\n/'; | ||
| File::replaceContentInFile($t . '/composer.json', $pattern, "\n"); | ||
|
|
||
|
Comment on lines
+75
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Make composer.json removal regex resilient to CRLF line endings (optional) The pattern: $pattern = '/\s*"drupal\/' . preg_quote($module_name, '/') . '":\s*"[^\"]+",?\n/';assumes - $pattern = '/\s*"drupal\/' . preg_quote($module_name, '/') . '":\s*"[^\"]+",?\n/';
+ $pattern = '/\s*"drupal\/' . preg_quote($module_name, '/') . '":\s*"[^\"]+",?(\r?\n)/';and keep the replacement consistent (e.g., 🤖 Prompt for AI Agents |
||
| // Remove module from settings file. | ||
| File::remove($t . '/' . $w . '/sites/default/includes/modules/settings.' . $module_name . '.php'); | ||
|
|
||
| // Remove module from the provision example file. | ||
| File::replaceContentCallbackInFile($t . '/scripts/custom/provision-10-example.sh', function (string $content) use ($module_name): string { | ||
| $pattern = '/^(\s*)(drush\s+pm:install.*\b' . preg_quote($module_name, '/') . '\b.*)$/m'; | ||
| $content = preg_replace_callback($pattern, function (array $matches) use ($module_name): string { | ||
| $indent = $matches[1]; | ||
| $line = $matches[2]; | ||
| $line = preg_replace('/\s+\b' . preg_quote($module_name, '/') . '\b/', '', $line); | ||
| $line = preg_replace('/\s{2,}/', ' ', $line) ?? $line; | ||
| return $indent . $line; | ||
| }, $content); | ||
| return $content ?? ''; | ||
| }); | ||
|
|
||
| // Remove module from the Behat tests. | ||
| File::remove($t . '/tests/behat/features/' . $module_name . '.feature'); | ||
|
|
||
| // Remove module from the config tests. | ||
| $pattern = '/\s*\$config\[\'' . preg_quote($module_name, '/') . '\..*;(\r?\n)?/'; | ||
| File::removeLine($t . '/tests/phpunit/Drupal/EnvironmentSettingsTest.php', $pattern); | ||
|
|
||
| // Remove module tokens. | ||
| File::removeTokenAsync('MODULE_' . strtoupper($module_name)); | ||
| } | ||
| } | ||
|
|
||
| if (count($selected_modules) === 0) { | ||
| File::removeTokenAsync('MODULE'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the full list of available Drupal contributed modules. | ||
| * | ||
| * This list excludes Drupal core modules and service modules. | ||
| * | ||
| * @return array<string, string> | ||
| * Array of module machine names as keys and labels as values. | ||
| */ | ||
| public static function getAvailableModules(): array { | ||
| return [ | ||
| 'admin_toolbar' => 'Admin toolbar', | ||
| 'coffee' => 'Coffee', | ||
| 'config_split' => 'Config split', | ||
| 'config_update' => 'Config update', | ||
| 'environment_indicator' => 'Environment indicator', | ||
| 'pathauto' => 'Pathauto', | ||
| 'redirect' => 'Redirect', | ||
| 'robotstxt' => 'Robots.txt', | ||
| 'seckit' => 'Seckit', | ||
| 'shield' => 'Shield', | ||
| 'stage_file_proxy' => 'Stage file proxy', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Extract Drupal contributed module names from a composer.json file. | ||
| * | ||
| * @param string $composer_file | ||
| * Path to the composer.json file. | ||
| * | ||
| * @return array|null | ||
| * Array of module machine names (without drupal/ prefix), or NULL on error. | ||
| */ | ||
| protected function getModulesFromComposerFile(string $composer_file): ?array { | ||
| if (!file_exists($composer_file)) { | ||
| return NULL; | ||
| } | ||
|
|
||
| $cj = JsonManipulator::fromFile($composer_file); | ||
|
|
||
| if (!$cj instanceof JsonManipulator) { | ||
| return NULL; | ||
| } | ||
|
|
||
| $require = $cj->getProperty('require'); | ||
|
|
||
| if (!is_array($require)) { | ||
| return NULL; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| $modules = []; | ||
| foreach (array_keys($require) as $package) { | ||
| // Only include drupal/* packages, excluding core packages. | ||
| if (str_starts_with((string) $package, 'drupal/') && !str_starts_with((string) $package, 'drupal/core-')) { | ||
| // Extract module name (remove drupal/ prefix). | ||
| $module_name = substr((string) $package, 7); | ||
| $modules[] = $module_name; | ||
| } | ||
| } | ||
|
|
||
| return $modules; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @@ -7,7 +7,6 @@ | ||
| "php": "__VERSION__", | ||
| "composer/installers": "__VERSION__", | ||
| "cweagans/composer-patches": "__VERSION__", | ||
| - "drupal/admin_toolbar": "__VERSION__", | ||
| "drupal/clamav": "__VERSION__", | ||
| "drupal/coffee": "__VERSION__", | ||
| "drupal/config_split": "__VERSION__", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @@ -38,7 +38,7 @@ | ||
| drush php:eval "\Drupal::service('config.factory')->getEditable('system.site')->set('name', 'star wars')->save();" | ||
|
|
||
| task "Installing contrib modules." | ||
| - drush pm:install admin_toolbar coffee config_split config_update media environment_indicator pathauto redirect robotstxt shield stage_file_proxy | ||
| + drush pm:install coffee config_split config_update media environment_indicator pathauto redirect robotstxt shield stage_file_proxy | ||
|
|
||
| task "Installing Redis module." | ||
| drush pm:install redis || true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @@ -9,7 +9,6 @@ | ||
| "cweagans/composer-patches": "__VERSION__", | ||
| "drupal/admin_toolbar": "__VERSION__", | ||
| "drupal/clamav": "__VERSION__", | ||
| - "drupal/coffee": "__VERSION__", | ||
| "drupal/config_split": "__VERSION__", | ||
| "drupal/config_update": "__VERSION__", | ||
| "drupal/core-composer-scaffold": "__VERSION__", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @@ -38,7 +38,7 @@ | ||
| drush php:eval "\Drupal::service('config.factory')->getEditable('system.site')->set('name', 'star wars')->save();" | ||
|
|
||
| task "Installing contrib modules." | ||
| - drush pm:install admin_toolbar coffee config_split config_update media environment_indicator pathauto redirect robotstxt shield stage_file_proxy | ||
| + drush pm:install admin_toolbar config_split config_update media environment_indicator pathauto redirect robotstxt shield stage_file_proxy | ||
|
|
||
| task "Installing Redis module." | ||
| drush pm:install redis || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider removing the extra blank line.
Static analysis detected an extra blank line at line 64. While not functionally problematic, removing it would improve consistency with the rest of the file.
Apply this diff:
DRUPAL_MAINTENANCE_THEME=your_site_theme - #;< MODULE_STAGE_FILE_PROXY📝 Committable suggestion
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 64-64: [ExtraBlankLine] Extra blank line detected
(ExtraBlankLine)
🤖 Prompt for AI Agents