Skip to content

Commit 72e4ea8

Browse files
committed
[#2096] Updated to use cweagans/composer-patches v2.
1 parent a34110d commit 72e4ea8

24 files changed

Lines changed: 670 additions & 112 deletions

File tree

.vortex/CLAUDE.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,32 @@ The installer uses a **baseline + diff** system for managing test fixtures:
330330

331331
### Updating Fixtures
332332

333-
**Critical**: Use the proper fixture update mechanism:
333+
**CRITICAL - Use the Unified Ahoy Command**:
334+
335+
The correct way to update fixtures is to use the unified `ahoy update-fixtures` command from the `.vortex` directory:
334336

335337
```bash
336-
cd .vortex/installer
338+
cd .vortex
337339

338-
# Update all fixtures
339-
UPDATE_FIXTURES=1 composer test
340+
# This is the CORRECT way to update all fixtures
341+
ahoy update-fixtures
342+
```
343+
344+
**What this command does**:
345+
- Updates template test fixtures in `tests/` directory
346+
- Updates installer test fixtures in `installer/` directory
347+
- Handles baseline fixtures first
348+
- Updates all scenario-specific fixtures
349+
- Runs tests twice to properly handle fixture updates (first run may fail, second should pass)
350+
351+
**DO NOT manually run `UPDATE_FIXTURES=1` commands** - the `ahoy update-fixtures` command handles everything automatically.
352+
353+
### Alternative: Manual Fixture Updates (Advanced)
354+
355+
For specific fixture updates or debugging, you can use manual commands:
356+
357+
```bash
358+
cd .vortex/installer
340359

341360
# Update specific test fixtures
342361
UPDATE_FIXTURES=1 ./vendor/bin/phpunit --filter "testInstall.*baseline"
@@ -352,9 +371,10 @@ UPDATE_FIXTURES=1 ./vendor/bin/phpunit --filter 'testInstall.*"services.*no.*cla
352371

353372
### Fixture Update Process
354373

355-
1. **Baseline First**: Update baseline fixtures first
356-
2. **Scenario Diffs**: Run individual scenario tests to update their diffs
357-
3. **Validation**: Verify tests pass without UPDATE_FIXTURES flag
374+
1. **Use ahoy update-fixtures**: This is the standard and recommended approach
375+
2. **Alternative - Baseline First**: Update baseline fixtures manually if needed
376+
3. **Alternative - Scenario Diffs**: Run individual scenario tests to update specific diffs
377+
4. **Validation**: Verify tests pass without UPDATE_FIXTURES flag
358378

359379
## Script Output Formatters
360380

@@ -397,7 +417,7 @@ info "Finished executing example operations in non-production environment."
397417

398418
1. **Update Main Script**: Modify the script in the template (outside .vortex/)
399419
2. **Update BATS Tests**: Update test assertions in `.vortex/tests/bats/`
400-
3. **Update Installer Fixtures**: Use `UPDATE_FIXTURES=1` process
420+
3. **Update Installer Fixtures**: Run `ahoy update-fixtures` from `.vortex/` directory
401421

402422
### Provision Script BATS Test Logic
403423

@@ -712,12 +732,13 @@ Each system:
712732
713733
### 2. Installer System (.vortex/installer/)
714734
715-
**Fixture Updates Can Be Finicky**:
735+
**Fixture Updates**:
716736
717-
- The `UPDATE_FIXTURES=1` mechanism can have defects
718-
- Try updating baseline first, then individual scenarios
719-
- Use filtered test runs for specific scenarios
737+
- **Use `ahoy update-fixtures`** from `.vortex/` directory - this is the standard approach
738+
- The unified command updates all fixtures automatically
739+
- Runs tests twice to handle fixture updates properly (first run may fail, second should pass)
720740
- Be patient - full test suite can take several minutes
741+
- For debugging specific scenarios, manual `UPDATE_FIXTURES=1` commands can be used
721742
722743
**Handler Development**:
723744
@@ -771,10 +792,13 @@ yarn test --updateSnapshot # Update component snapshots
771792
**Fixture Update Issues**:
772793
773794
```bash
774-
# Try baseline first
775-
UPDATE_FIXTURES=1 ./vendor/bin/phpunit --filter "testInstall.*baseline"
795+
# RECOMMENDED: Use the unified command
796+
cd .vortex
797+
ahoy update-fixtures
776798
777-
# Then individual scenarios
799+
# ALTERNATIVE: Manual updates for specific scenarios
800+
cd .vortex/installer
801+
UPDATE_FIXTURES=1 ./vendor/bin/phpunit --filter "testInstall.*baseline"
778802
UPDATE_FIXTURES=1 ./vendor/bin/phpunit --filter 'testInstall.*"scenario_name"'
779803
780804
# Check for test timeouts - increase if needed
@@ -1209,7 +1233,9 @@ $this->cmd('ahoy export-db', '! Containers are not running.', arg: $args);
12091233
**Installer System** (`.vortex/installer/`):
12101234
12111235
- **CRITICAL**: NEVER directly modify files under `.vortex/installer/tests/Fixtures/`
1212-
- These are test fixtures that must be updated via `UPDATE_FIXTURES=1` mechanism
1236+
- These are test fixtures that must be updated via `ahoy update-fixtures` command from `.vortex/` directory
1237+
- The unified `ahoy update-fixtures` command handles all fixture updates automatically
1238+
- For debugging, manual `UPDATE_FIXTURES=1` commands can be used from `.vortex/installer/`
12131239
- Always test with baseline scenario first, then individual scenarios
12141240
- Preserve handler execution order and batching patterns
12151241

.vortex/docs/content/drupal/composer.mdx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,10 @@ The [`repositories`](https://getcomposer.org/doc/04-schema.md#repositories)
7979
section defines custom package repositories, essential for accessing packages
8080
outside the default Packagist repository.
8181

82-
See [Working with packages](../workflows/development#working-with-composer-packages) for more information on
83-
how to provide custom and override existing packages in your project.
84-
8582
- [`drupal`](https://www.drupal.org/docs/develop/using-composer/using-packagesdrupalorg):
8683
Serves as the official source for Drupal modules, themes, and distributions.
8784
It's crucial for a Drupal project using Composer, as it allows access to
8885
Drupal-specific packages not available on Packagist.
89-
- [`asset-packagist`](https://asset-packagist.org/): Enables the installation of
90-
Bower and NodeJs packages via Composer. This is especially important for Drupal
91-
projects needing front-end libraries and tools, bridging the gap between
92-
Composer's PHP-centric ecosystem and the broader world of front-end package
93-
management.
9486

9587
### `require`
9688

@@ -104,9 +96,11 @@ specifies the essential packages and libraries your project needs.
10496
install packages to the correct location based on the specified package type
10597
such as `drupal-module`, `drupal-theme`, `drupal-profile`, etc.
10698
- [`cweagans/composer-patches`](https://github.com/cweagans/composer-patches):
107-
Allows applying patches to Composer packages, useful for incorporating fixes
108-
not yet in official releases.
109-
See [Working with packages](../workflows/development#patching) for more
99+
Enables git-based patching of Composer packages, useful for incorporating fixes
100+
not yet in official releases. Version 2.x uses `git apply` for cross-platform
101+
consistency and generates a `patches.lock.json` file to ensure reproducible
102+
builds with SHA-256 checksums.
103+
See [Patching](../workflows/development#patching) for more
110104
information on how to work with patches.
111105
- `drupal/admin_toolbar`, `drupal/clamav`, `drupal/coffee`, etc. - Drupal
112106
modules that provide various site administration and development helping
@@ -266,9 +260,11 @@ a source of custom configuration for various packages. These packages read
266260
settings from this section to tailor their behavior according to the specific
267261
needs and structure of your Drupal project.
268262

269-
- [`composer-exit-on-patch-failure`](https://github.com/cweagans/composer-patches):
270-
This setting, when enabled, causes Composer to exit if a patch from
271-
the `cweagans/composer-patches` plugin fails to apply.
263+
- **patches.lock.json**: Automatically generated by `cweagans/composer-patches`
264+
v2.x. This file contains patch metadata and SHA-256 checksums, and must be
265+
committed to version control (like `composer.lock`). It ensures reproducible
266+
builds across teams and CI/CD environments by verifying patch integrity and
267+
making the patch state explicit and trackable.
272268
- [`drupal-scaffold`](https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold):
273269
This setting controls which files should be scaffolded:
274270
- `locations`: Specifies the location of the web root (the directory

.vortex/docs/content/workflows/development.mdx

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,93 @@ To override package installation paths, modify `composer.json`:
217217

218218
### Patching
219219

220-
If you need to apply patches to included dependencies, use the `composer-patches` plugin. Add the patch definition in `composer.json` under the `extra.patches` section:
220+
Vortex uses [`cweagans/composer-patches`](https://github.com/cweagans/composer-patches) v2.x for applying patches to Composer dependencies. Version 2.x uses git-based patching with `git apply` for better cross-platform consistency.
221221

222-
```json
223-
"extra": {
224-
"patches": {
225-
"drupal/foobar": {
226-
"Patch description": "URL or local path to patch"
222+
:::tip
223+
224+
For official documentation, visit: [Composer Patches Recommended Workflows](https://docs.cweagans.net/composer-patches/usage/recommended-workflows/)
225+
226+
:::
227+
228+
#### Understanding `patches.lock.json`
229+
230+
Composer Patches v2.x automatically generates a `patches.lock.json` file that contains:
231+
232+
- Patch metadata (URLs, descriptions, target packages)
233+
- SHA-256 checksums for patch verification
234+
235+
**This file must be committed to version control** (like `composer.lock`).
236+
237+
**Benefits:**
238+
239+
- Ensures reproducible builds across teams and CI/CD environments
240+
- Verifies patch integrity with checksums
241+
- Prevents "works on my machine" issues with patches
242+
- Makes the patch state explicit and trackable
243+
244+
#### Adding a New Patch
245+
246+
1. Define the patch in `composer.json` under `extra.patches`:
247+
248+
```json
249+
"extra": {
250+
"patches": {
251+
"drupal/foobar": {
252+
"Fix for issue #123": "https://www.drupal.org/files/issues/fix-123.patch"
253+
}
227254
}
228255
}
229-
}
230-
```
256+
```
257+
258+
2. Regenerate `patches.lock.json`:
259+
260+
```bash
261+
composer patches-relock
262+
```
263+
264+
3. Remove and reinstall patched packages:
265+
266+
```bash
267+
composer patches-repatch
268+
```
269+
270+
:::warning
271+
`composer patches-repatch` removes patched dependencies from `vendor/` and reinstalls them. Ensure you have no unsaved changes in those directories.
272+
:::
273+
274+
4. Update `composer.lock`:
275+
276+
```bash
277+
composer update --lock
278+
```
279+
280+
#### Removing a Patch
281+
282+
1. Delete the patch definition from `composer.json`
283+
284+
2. Regenerate `patches.lock.json`:
285+
286+
```bash
287+
composer patches-relock
288+
```
289+
290+
3. Manually delete the affected dependency:
291+
292+
```bash
293+
rm -rf vendor/drupal/foobar
294+
```
295+
296+
4. Reinstall without the patch:
297+
298+
```bash
299+
composer patches-repatch
300+
```
301+
302+
5. Update `composer.lock`:
231303

232-
Run `composer update drupal/foobar` after adding patches to apply them.
304+
```bash
305+
composer update --lock
306+
```
233307

234308
## Resetting the codebase
235309

.vortex/docs/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"ddev",
2929
"dealerdirect",
3030
"drevops",
31+
"drupalcode",
3132
"drush",
3233
"ergebnis",
3334
"gherkinlint",

.vortex/installer/composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"alexskrypnyk/file": "^0.13",
2222
"alexskrypnyk/str2name": "^1.4",
2323
"composer/composer": "^2.8",
24-
"cweagans/composer-patches": "^1.7",
24+
"cweagans/composer-patches": "^2.0",
2525
"czproject/git-php": "^4.3",
2626
"laravel/prompts": "^0.3.7",
2727
"nikic/iter": "^2.4",
@@ -77,9 +77,6 @@
7777
},
7878
"sort-packages": true
7979
},
80-
"extra": {
81-
"composer-exit-on-patch-failure": true
82-
},
8380
"scripts": {
8481
"build": [
8582
"@composer bin box require --dev humbug/box",

.vortex/installer/tests/Fixtures/install/_baseline/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"sort-packages": true
9292
},
9393
"extra": {
94-
"composer-exit-on-patch-failure": true,
9594
"drupal-scaffold": {
9695
"file-mapping": {
9796
"[project-root]/.editorconfig": false,

.vortex/installer/tests/Fixtures/install/ai_instructions_claude/CLAUDE.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,37 @@ ahoy drush pm:install admin_toolbar pathauto
351351

352352
When contributed modules need fixes or customizations, use the proper patching workflow with `cweagans/composer-patches`.
353353

354+
Vortex uses **composer-patches v2.x** which provides git-based patching with improved reliability and reproducibility.
355+
356+
#### Key Features of v2
357+
358+
- **Git-based patching**: Uses `git apply` exclusively for cross-platform consistency
359+
- **patches.lock.json**: Automatically generated file with patch metadata and SHA-256 checksums
360+
- **New commands**:
361+
- `composer patches-relock` - Regenerate patches.lock.json after adding/removing patches
362+
- `composer patches-repatch` - Remove and reinstall patched dependencies
363+
- **Automatic failure on patch errors**: Patches must apply successfully or installation fails
364+
365+
#### Understanding patches.lock.json
366+
367+
This file is automatically generated and **must be committed to version control** (like composer.lock).
368+
369+
**What it contains:**
370+
- Patch metadata (URLs, descriptions, target packages)
371+
- SHA-256 checksums for patch verification
372+
373+
**Why it matters:**
374+
- Ensures reproducible builds across teams and CI/CD
375+
- Verifies patch integrity with checksums
376+
- Prevents "works on my machine" issues
377+
- Makes patch state explicit and trackable
378+
379+
**Always commit this file** after adding or removing patches.
380+
354381
#### Prerequisites for Patching
355382

356-
- Project uses `cweagans/composer-patches` package
357-
- Git is available for version control
383+
- Project uses `cweagans/composer-patches` package (v2.x)
384+
- Git is available for version control (required by v2)
358385
- Access to Drupal.org git repositories
359386

360387
#### Patch Storage and Configuration
@@ -469,14 +496,26 @@ git diff
469496

470497
Step 7: Integrate into Project
471498

472-
Add the patch to your project's composer configuration and test:
499+
Add the patch to your project's composer configuration and apply it using v2 commands:
473500

474501
```bash
475-
# Update the specific module to apply patch
476-
ahoy composer require drupal/module_name
502+
# Add patch definition to composer.json extra.patches section
503+
504+
# Regenerate patches.lock.json
505+
ahoy composer patches-relock
506+
507+
# Remove and reinstall patched package
508+
ahoy composer patches-repatch
509+
510+
# Update composer.lock
511+
ahoy composer update --lock
477512

478513
# Verify no patch application errors
479514
# Check that functionality works as expected
515+
516+
# Commit all changes
517+
git add composer.json composer.lock patches.lock.json patches/
518+
git commit -m "Added patch for drupal/module_name."
480519
```
481520

482521
Step 8: Clean Up

0 commit comments

Comments
 (0)