Skip to content

Commit 0b86d60

Browse files
committed
Added contrib patching section to AI instructions.
1 parent 83472de commit 0b86d60

12 files changed

Lines changed: 2124 additions & 0 deletions

File tree

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

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,183 @@ ahoy composer require --dev drupal/devel
347347
ahoy drush pm:install admin_toolbar pathauto
348348
```
349349

350+
### Patching Contributed Modules
351+
352+
When contributed modules need fixes or customizations, use the proper patching workflow with `cweagans/composer-patches`.
353+
354+
#### Prerequisites for Patching
355+
356+
- Project uses `cweagans/composer-patches` package
357+
- Git is available for version control
358+
- Access to Drupal.org git repositories
359+
360+
#### Patch Storage and Configuration
361+
362+
Patches are defined in `composer.json` under the `extra.patches` section:
363+
364+
```json
365+
{
366+
"extra": {
367+
"patches": {
368+
"drupal/module_name": {
369+
"Description of fix": "patches/module-name-description.patch",
370+
"Another fix": "https://www.drupal.org/files/issues/external-patch.patch"
371+
}
372+
}
373+
}
374+
}
375+
```
376+
377+
- **Local patches**: Store in `patches/` directory in project root
378+
- **External patches**: Reference URLs directly in composer.json
379+
- **Naming convention**: Use descriptive names like `module-name-description.patch`
380+
381+
#### Creating Module Patches
382+
383+
**Step 1: Identify Module Version**
384+
385+
Always work with the exact version and state used in your project:
386+
387+
```bash
388+
# Check installed version
389+
ahoy composer show drupal/module_name
390+
391+
# Verify version in composer.lock
392+
grep -A 20 "drupal/module_name" composer.lock
393+
```
394+
395+
**Step 2: Clone Module from Git**
396+
397+
**CRITICAL**: Always use the official Drupal git repository, not tarball downloads:
398+
399+
```bash
400+
# Create working directory
401+
cd /tmp && mkdir module_patch_work && cd module_patch_work
402+
403+
# Clone the module
404+
git clone https://git.drupalcode.org/project/module_name.git
405+
406+
# Navigate to module directory
407+
cd module_name
408+
409+
# Checkout the exact version/tag used in project
410+
git checkout 1.2.3 # Replace with actual version
411+
412+
# Create working branch
413+
git checkout -b fix-description
414+
```
415+
416+
**Step 3: Apply Existing Patches**
417+
418+
If your project already has patches for this module, apply them first to match the current state:
419+
420+
```bash
421+
# Apply each existing patch in order
422+
curl -s https://example.com/patch1.patch | patch -p1
423+
curl -s https://example.com/patch2.patch | patch -p1
424+
425+
# Commit the patches to establish baseline
426+
git add .
427+
git commit -m "Apply existing patches to match project state"
428+
```
429+
430+
**Step 4: Make Required Changes**
431+
432+
Edit the necessary files to implement your fix:
433+
434+
```bash
435+
# Make your changes using your preferred editor
436+
vim path/to/file.php
437+
438+
# Or use automated tools if applicable
439+
sed -i 's/old_code/new_code/' path/to/file.php
440+
```
441+
442+
**Step 5: Generate Clean Patch**
443+
444+
Create a proper git-based patch:
445+
446+
```bash
447+
# Stage your changes
448+
git add .
449+
450+
# Generate patch from staged changes
451+
git diff --cached > /path/to/project/patches/module-name-fix-description.patch
452+
```
453+
454+
**Step 6: Test Patch Application**
455+
456+
**ALWAYS test that your patch applies cleanly**:
457+
458+
```bash
459+
# Reset to test patch application
460+
git reset --hard HEAD
461+
462+
# Test patch applies without conflicts
463+
git apply /path/to/project/patches/module-name-fix-description.patch
464+
465+
# Verify changes were applied correctly
466+
git status
467+
git diff
468+
```
469+
470+
**Step 7: Integrate into Project**
471+
472+
Add the patch to your project's composer configuration and test:
473+
474+
```bash
475+
# Update the specific module to apply patch
476+
ahoy composer require drupal/module_name
477+
478+
# Verify no patch application errors
479+
# Check that functionality works as expected
480+
```
481+
482+
**Step 8: Clean Up**
483+
484+
Remove temporary working directory:
485+
486+
```bash
487+
rm -rf /tmp/module_patch_work
488+
```
489+
490+
#### Patching Best Practices
491+
492+
**✅ Do This:**
493+
- Use descriptive patch names that explain what they fix
494+
- Keep patches focused - one fix per patch when possible
495+
- Follow Drupal coding standards in your changes
496+
- Test locally before committing patches
497+
- Document the issue being fixed in composer.json description
498+
- Include issue URLs when available from drupal.org
499+
500+
**❌ Avoid These Mistakes:**
501+
- Working with tarball downloads instead of git repositories
502+
- Creating patches from modified project files
503+
- Skipping patch application testing
504+
- Creating patches without applying existing patches first
505+
- Assuming patches work across different module versions
506+
507+
#### Troubleshooting Patch Issues
508+
509+
**Patch Won't Apply:**
510+
1. Check module version matches between patch creation and application
511+
2. Verify existing patches are applied in correct order
512+
3. Check for whitespace issues in patch file
513+
4. Ensure patch paths are correct (usually relative to module root)
514+
515+
**Patch Conflicts:**
516+
1. Identify conflicting patches by applying them individually
517+
2. Update patch order in composer.json if needed
518+
3. Recreate patches against the current patched state
519+
4. Merge patches if they modify the same areas
520+
521+
**Performance Issues:**
522+
1. Minimize external patch URLs to reduce download time
523+
2. Store frequently used patches locally in patches directory
524+
3. Keep patch files small and focused
525+
4. Remove obsolete patches when updating modules
526+
350527
### Adding JavaScript/CSS Libraries
351528

352529
For npm packages that need to be Drupal libraries, define them as inline

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

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,183 @@ ahoy composer require --dev drupal/devel
347347
ahoy drush pm:install admin_toolbar pathauto
348348
```
349349

350+
### Patching Contributed Modules
351+
352+
When contributed modules need fixes or customizations, use the proper patching workflow with `cweagans/composer-patches`.
353+
354+
#### Prerequisites for Patching
355+
356+
- Project uses `cweagans/composer-patches` package
357+
- Git is available for version control
358+
- Access to Drupal.org git repositories
359+
360+
#### Patch Storage and Configuration
361+
362+
Patches are defined in `composer.json` under the `extra.patches` section:
363+
364+
```json
365+
{
366+
"extra": {
367+
"patches": {
368+
"drupal/module_name": {
369+
"Description of fix": "patches/module-name-description.patch",
370+
"Another fix": "https://www.drupal.org/files/issues/external-patch.patch"
371+
}
372+
}
373+
}
374+
}
375+
```
376+
377+
- **Local patches**: Store in `patches/` directory in project root
378+
- **External patches**: Reference URLs directly in composer.json
379+
- **Naming convention**: Use descriptive names like `module-name-description.patch`
380+
381+
#### Creating Module Patches
382+
383+
**Step 1: Identify Module Version**
384+
385+
Always work with the exact version and state used in your project:
386+
387+
```bash
388+
# Check installed version
389+
ahoy composer show drupal/module_name
390+
391+
# Verify version in composer.lock
392+
grep -A 20 "drupal/module_name" composer.lock
393+
```
394+
395+
**Step 2: Clone Module from Git**
396+
397+
**CRITICAL**: Always use the official Drupal git repository, not tarball downloads:
398+
399+
```bash
400+
# Create working directory
401+
cd /tmp && mkdir module_patch_work && cd module_patch_work
402+
403+
# Clone the module
404+
git clone https://git.drupalcode.org/project/module_name.git
405+
406+
# Navigate to module directory
407+
cd module_name
408+
409+
# Checkout the exact version/tag used in project
410+
git checkout 1.2.3 # Replace with actual version
411+
412+
# Create working branch
413+
git checkout -b fix-description
414+
```
415+
416+
**Step 3: Apply Existing Patches**
417+
418+
If your project already has patches for this module, apply them first to match the current state:
419+
420+
```bash
421+
# Apply each existing patch in order
422+
curl -s https://example.com/patch1.patch | patch -p1
423+
curl -s https://example.com/patch2.patch | patch -p1
424+
425+
# Commit the patches to establish baseline
426+
git add .
427+
git commit -m "Apply existing patches to match project state"
428+
```
429+
430+
**Step 4: Make Required Changes**
431+
432+
Edit the necessary files to implement your fix:
433+
434+
```bash
435+
# Make your changes using your preferred editor
436+
vim path/to/file.php
437+
438+
# Or use automated tools if applicable
439+
sed -i 's/old_code/new_code/' path/to/file.php
440+
```
441+
442+
**Step 5: Generate Clean Patch**
443+
444+
Create a proper git-based patch:
445+
446+
```bash
447+
# Stage your changes
448+
git add .
449+
450+
# Generate patch from staged changes
451+
git diff --cached > /path/to/project/patches/module-name-fix-description.patch
452+
```
453+
454+
**Step 6: Test Patch Application**
455+
456+
**ALWAYS test that your patch applies cleanly**:
457+
458+
```bash
459+
# Reset to test patch application
460+
git reset --hard HEAD
461+
462+
# Test patch applies without conflicts
463+
git apply /path/to/project/patches/module-name-fix-description.patch
464+
465+
# Verify changes were applied correctly
466+
git status
467+
git diff
468+
```
469+
470+
**Step 7: Integrate into Project**
471+
472+
Add the patch to your project's composer configuration and test:
473+
474+
```bash
475+
# Update the specific module to apply patch
476+
ahoy composer require drupal/module_name
477+
478+
# Verify no patch application errors
479+
# Check that functionality works as expected
480+
```
481+
482+
**Step 8: Clean Up**
483+
484+
Remove temporary working directory:
485+
486+
```bash
487+
rm -rf /tmp/module_patch_work
488+
```
489+
490+
#### Patching Best Practices
491+
492+
**✅ Do This:**
493+
- Use descriptive patch names that explain what they fix
494+
- Keep patches focused - one fix per patch when possible
495+
- Follow Drupal coding standards in your changes
496+
- Test locally before committing patches
497+
- Document the issue being fixed in composer.json description
498+
- Include issue URLs when available from drupal.org
499+
500+
**❌ Avoid These Mistakes:**
501+
- Working with tarball downloads instead of git repositories
502+
- Creating patches from modified project files
503+
- Skipping patch application testing
504+
- Creating patches without applying existing patches first
505+
- Assuming patches work across different module versions
506+
507+
#### Troubleshooting Patch Issues
508+
509+
**Patch Won't Apply:**
510+
1. Check module version matches between patch creation and application
511+
2. Verify existing patches are applied in correct order
512+
3. Check for whitespace issues in patch file
513+
4. Ensure patch paths are correct (usually relative to module root)
514+
515+
**Patch Conflicts:**
516+
1. Identify conflicting patches by applying them individually
517+
2. Update patch order in composer.json if needed
518+
3. Recreate patches against the current patched state
519+
4. Merge patches if they modify the same areas
520+
521+
**Performance Issues:**
522+
1. Minimize external patch URLs to reduce download time
523+
2. Store frequently used patches locally in patches directory
524+
3. Keep patch files small and focused
525+
4. Remove obsolete patches when updating modules
526+
350527
### Adding JavaScript/CSS Libraries
351528

352529
For npm packages that need to be Drupal libraries, define them as inline

0 commit comments

Comments
 (0)