Configuring composer scaffold

Drupal 8.8 added https://github.com/drupal/core-composer-scaffold, replacing https://github.com/drupal-composer/drupal-scaffold.

It will get files like index.php and .htaccess from core/assets/scaffold/files/ and copy them to specified directories.

When these files are updated by drupal, they will replace them in your project when performing updates. In order to merge your custom changes, you need to add them as a patch. With the default file loaded and changes applied, run git diff > scaffold-custom.patch. This will export your customizations to a patch file (make sure you only have these changes to avoid adding other things to the patch). Then add this to your composer.json:

    "scripts": {
        "post-drupal-scaffold-cmd": [
            "patch -p1 < scaffold-custom.patch"
        ]
    },

When you run composer install, any new files will get scaffolded and your changes will be applied.

To skip certain files like README.txt, add this to composer.json:

    "extra": {
        "drupal-scaffold": {
            "file-mapping": {
                "[web-root]/INSTALL.txt": false,
                "[web-root]/README.txt": false
            }
        },
    }

 

Tags
Composer