0

When deploying Drupal, there are a lot of files in test directories, none of which are needed in a production environment. There's an ongoing issue to Exclude test files from release packages, but how can I get rid of the test files now?

2 Answers 2

1

After trying to configure drupal-core-vendor-hardening to do this, I realized that it's too much of a pain to add each individual module.

So I wrote a simple bash script instead.

cd "$my_git_root"
# Delete Drupal test directories.
# https://unix.stackexchange.com/a/89937
find . -type d -name tests -exec rm -rf {} +
# Delete testing and demo profiles.
find web/core/profiles -type d -name 'testing*' -exec rm -rf {} +
find web/core/profiles -type d -name 'nightwatch_testing' -exec rm -rf {} +
find web/core/profiles -type d -name 'demo_umami' -exec rm -rf {} +
# Delete README files.
find . -type f -name 'README*' -delete
find . -type f -name 'CHANGELOG*' -delete
# Delete patch records.
find . -type f -name 'PATCHES.txt' -delete
# Delete markdown files except licenses.
find web -type f -name "*.md" -not -name "LICENSE*" -delete
# Delete txt files except licenses.
find web -type f -name "*.txt" -not -name "LICENSE*" -not -name "COPYRIGHT*" -delete

Doing this, I managed to reduce my build size from 213 MB to 172 MB.

0

core-vendor-hardening can clean up test files and any other directories you want.

The only downside is that you have to make an entry per module in composer.json.

"extra": {
    "drupal-core-vendor-hardening": {
        "drupal/core": ["tests","profiles/demo_umami"],
        "drupal/json_field": ["tests"]
    },
}

The above example also shows how to delete the umami profile-- you need to insert the directory path. So, if you want to delete tests from all modules of core, you are looking at a very extensive list.

Note: To actually delete the files after modifying composer.json, you can delete the relevant directory and then run composer.install. If you change composer.json and then run composer update, the files will remain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.